Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliu2016 committed Jan 13, 2020
1 parent 91777be commit 7b66c74
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
21 changes: 21 additions & 0 deletions src/main/kotlin/ca/warp7/desktop/qrscanner/MatchCell.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ca.warp7.desktop.qrscanner

import javafx.scene.control.TableCell
import kb.core.fx.label

class MatchCell : TableCell<V5Entry, String>() {
override fun updateItem(item: String?, empty: Boolean) {
super.updateItem(item, empty)
if (item == null || empty) {
graphic = null
return
}
graphic = label {
text = item
style = when (item.last()) {
'1', '3', '5', '7', '9' -> "-fx-font-weight: bold; -fx-text-fill: #080"
else -> "-fx-font-weight: bold; -fx-text-fill: #808 "
}
}
}
}
55 changes: 41 additions & 14 deletions src/main/kotlin/ca/warp7/desktop/qrscanner/ScannerScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import javafx.geometry.Insets
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.*
import javafx.scene.control.Alert.AlertType
import javafx.scene.image.Image
import javafx.scene.input.KeyCode
import javafx.stage.FileChooser
import javafx.stage.Stage
Expand Down Expand Up @@ -40,16 +40,22 @@ class ScannerScreen {
fun alert(t: String, s: String) {
val dialog = Dialog<ButtonType>()
val pane = dialog.dialogPane
dialog.initOwner(stage)
pane.buttonTypes.addAll(ButtonType.OK)
dialog.dialogPane.content = label(s)
pane.contentText = s
dialog.title = t
dialog.showAndWait()
}

fun confirm(s: String): Boolean {
val alert = Alert(AlertType.CONFIRMATION, s, ButtonType.YES, ButtonType.NO)
alert.showAndWait()
return alert.result == ButtonType.YES
val dialog = Dialog<ButtonType>()
val pane = dialog.dialogPane
dialog.initOwner(stage)
dialog.title = "Confirmation"
pane.buttonTypes.addAll(ButtonType.YES, ButtonType.NO)
pane.contentText = s
dialog.showAndWait()
return dialog.result == ButtonType.YES
}

fun save() {
Expand Down Expand Up @@ -80,7 +86,7 @@ class ScannerScreen {

fun updateTitle() {
val path = savePath
stage.title = if (path == null) "Scouting App Scanner" else "Scouting App Scanner | $path"
stage.title = if (path == null) "WARP7 Scouting Scan Tool" else "WARP7 Scouting Scan Tool | $path"
}

fun updateCameras() {
Expand All @@ -93,18 +99,26 @@ class ScannerScreen {
}

fun openFile() {
if (textEntries.isNotEmpty() && !confirm("Override all current entries?")) return
if (textEntries.isNotEmpty() && !confirm("Override all current entries?")) {
return
}

val chooser = FileChooser()

chooser.title = "Save As"
chooser.initialDirectory = File(System.getProperty("user.home"), "Desktop")
val path = chooser.showOpenDialog(stage)?.toPath() ?: return

savePath = path
saveState.text = "Loading"
updateTitle()
textEntries.clear()
unsortedEntries.clear()

executor.submit {

val data = Files.readAllLines(path)

var i = 0
val items = ArrayList<V5Entry>()
val entries = ArrayList<String>()
Expand All @@ -117,7 +131,9 @@ class ScannerScreen {
} catch (e: Exception) {
}
}

entriesLock.withLock { textEntries.addAll(entries) }

Platform.runLater {
unsortedEntries.addAll(items)
updateSorted(sortByMatch.isSelected)
Expand All @@ -137,12 +153,16 @@ class ScannerScreen {
}

fun closeSaveFile() {
savePath = null
textEntries.clear()
unsortedEntries.clear()
tv.items.clear()
updateTitle()
saveState.text = "Save File Closed"
if (savePath != null) {
savePath = null
textEntries.clear()
unsortedEntries.clear()
tv.items.clear()
updateTitle()
saveState.text = "Save File Closed"
} else {
saveState.text = "No Save File To Close"
}
}

fun showComment() {
Expand Down Expand Up @@ -175,6 +195,7 @@ class ScannerScreen {

fun showWarnings() {
val map = HashMap<String, MutableList<Board>>()

unsortedEntries.forEach {
val matchNum = it.match.split("_").last()
if (matchNum in map) {
Expand All @@ -183,12 +204,16 @@ class ScannerScreen {
map[matchNum] = mutableListOf(it.board)
}
}

val order = map.keys.sortedWith(comparator)
val w = StringBuilder()
val v = Board.values().toMutableList()

v.remove(Board.RX)
v.remove(Board.BX)

val missing = mutableListOf<Board>()

order.forEach { key ->
missing.clear()
val md = map[key]!!
Expand All @@ -199,6 +224,7 @@ class ScannerScreen {
w.append(missing.last()).append("\n")
}
}

alert("Warnings", w.toString())
}

Expand Down Expand Up @@ -369,8 +395,9 @@ class ScannerScreen {
}

init {
stage.title = "Scouting App Scanner"
stage.title = "WARP7 Scouting Scan Tool"
stage.scene = scene
stage.icons.add(Image(ScannerScreen::class.java.getResourceAsStream("/icon.png")))
scene.onKeyPressed = EventHandler {
if (it.code == KeyCode.K) {
streaming.isSelected = !streaming.isSelected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,4 @@ class TeamCell : TableCell<V5Entry, String>() {
}
}
}
}

class MatchCell : TableCell<V5Entry, String>() {
override fun updateItem(item: String?, empty: Boolean) {
super.updateItem(item, empty)
if (item == null || empty) {
graphic = null
return
}
graphic = label {
text = item
style = when (item.last()) {
'1', '3', '5', '7', '9' -> "-fx-font-weight: bold; -fx-text-fill: #080"
else -> "-fx-font-weight: bold; -fx-text-fill: #808 "
}
}
}
}
Binary file added src/main/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7b66c74

Please sign in to comment.