Skip to content

Commit b5565d9

Browse files
committed
redesigned ui
added modal window
1 parent e211578 commit b5565d9

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/main/kotlin/ch/bildspur/annotator/Main.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ class Main : Application() {
2626
controller.stage = primaryStage
2727
primaryStage.addEventHandler(WindowEvent.WINDOW_SHOWN) { controller.handleWindowShownEvent() }
2828

29-
primaryStage.title = "OpenCV Sample Annotator"
29+
primaryStage.title = "OpenCV Sample Annotator - ${Main.VERSION}"
3030
primaryStage.scene = Scene(root)
3131
primaryStage.show()
3232
System.out.println()
3333
}
3434

3535
companion object {
36+
const val VERSION = "0.1"
37+
3638
@JvmStatic
3739
fun main(args: Array<String>) {
3840
launch(Main::class.java)

src/main/kotlin/ch/bildspur/annotator/ui/MainViewController.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import javafx.scene.Scene
1212
import javafx.scene.canvas.Canvas
1313
import javafx.scene.canvas.GraphicsContext
1414
import javafx.scene.control.Alert
15+
import javafx.scene.control.Label
1516
import javafx.scene.input.KeyCode
1617
import javafx.scene.input.KeyEvent
1718
import javafx.scene.input.MouseEvent
@@ -31,6 +32,9 @@ class MainViewController {
3132
@FXML
3233
var canvas: Canvas? = null
3334

35+
@FXML
36+
var infoText: Label? = null
37+
3438
var positivesFile: File by Delegates.notNull()
3539

3640
var annotationImages: List<AnnotationImage> by Delegates.notNull()
@@ -45,6 +49,8 @@ class MainViewController {
4549

4650
var scaleFactor = 1.0
4751

52+
var imageCounter = 0
53+
4854
fun handleWindowShownEvent() {
4955
showSettingsView()
5056
}
@@ -55,6 +61,7 @@ class MainViewController {
5561
val controller = loader.getController<SettingsViewController>()
5662

5763
val settingStage = Stage()
64+
settingStage.initOwner(stage)
5865
settingStage.initModality(Modality.WINDOW_MODAL)
5966
settingStage.title = "OpenCV Sample Annotator Settings"
6067
settingStage.scene = Scene(root)
@@ -80,6 +87,7 @@ class MainViewController {
8087
canvas!!.onMouseReleased = EventHandler<MouseEvent> { handleMouseReleased(it) }
8188

8289
canvas!!.isFocusTraversable = true
90+
canvas!!.requestFocus()
8391

8492
gc = canvas!!.graphicsContext2D
8593
resizeCanvas()
@@ -93,10 +101,10 @@ class MainViewController {
93101
}
94102

95103
fun loadNextImage() {
96-
if (!imageIterator.hasNext()) {
104+
imageCounter++
105+
106+
if (!imageIterator.hasNext())
97107
saveAndClose()
98-
exitProcess(0)
99-
}
100108

101109
activeImage = imageIterator.next()
102110
initImage()
@@ -111,6 +119,7 @@ class MainViewController {
111119
alert.showAndWait()
112120

113121
stage.close()
122+
exitProcess(0)
114123
}
115124

116125
fun resizeCanvas() {
@@ -119,6 +128,8 @@ class MainViewController {
119128
}
120129

121130
fun initImage() {
131+
infoText!!.text = "$imageCounter of ${annotationImages.size}"
132+
122133
calculateScaleFactor()
123134
redrawCanvas()
124135
}
@@ -182,8 +193,6 @@ class MainViewController {
182193
}
183194

184195
fun handleMouseReleased(e: MouseEvent) {
185-
val m = Vector2(e.x, e.y)
186-
187196
if (dragged) {
188197
println("dragged!")
189198
} else {
@@ -201,6 +210,10 @@ class MainViewController {
201210
loadNextImage()
202211
}
203212

213+
fun finishClicked(e: ActionEvent) {
214+
saveAndClose()
215+
}
216+
204217
fun vectorToScreen(v: Vector2): Vector2 {
205218
return v.scale(scaleFactor)
206219
}

src/main/resources/view/MainView.fxml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
<?import ch.bildspur.annotator.ui.control.ResizableCanvas?>
44
<?import javafx.scene.control.Button?>
5-
<?import javafx.scene.control.ButtonBar?>
5+
<?import javafx.scene.control.Label?>
66
<?import javafx.scene.layout.*?>
77
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0"
88
prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1"
99
fx:controller="ch.bildspur.annotator.ui.MainViewController">
1010
<children>
11-
<ButtonBar nodeOrientation="RIGHT_TO_LEFT" prefHeight="40.0" prefWidth="408.0"
12-
style="-fx-background-color: #696969;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
13-
AnchorPane.topAnchor="0.0">
14-
<buttons>
15-
<Button mnemonicParsing="false" onAction="#nextClicked" text="Next"/>
16-
<Button mnemonicParsing="false" onAction="#clearClicked" text="Clear"/>
17-
</buttons>
18-
</ButtonBar>
11+
<AnchorPane prefHeight="40.0" prefWidth="408.0" style="-fx-background-color: #ecf0f1;"
12+
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
13+
<children>
14+
<Button layoutX="15.0" layoutY="7.0" mnemonicParsing="false" onAction="#clearClicked" text="Clear"
15+
AnchorPane.leftAnchor="15.0"/>
16+
<Button layoutX="75.0" layoutY="7.0" mnemonicParsing="false" onAction="#nextClicked" text="Next"
17+
AnchorPane.leftAnchor="75.0"/>
18+
<Label fx:id="infoText" alignment="CENTER_RIGHT" layoutX="360.0" layoutY="12.0" prefHeight="17.0"
19+
prefWidth="130.0" text="1 of 1" AnchorPane.rightAnchor="16.0"/>
20+
<Button layoutX="132.0" layoutY="7.0" mnemonicParsing="false" onAction="#finishClicked" text="Finish"/>
21+
</children>
22+
</AnchorPane>
1923
<ResizableCanvas fx:id="canvas" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
2024
AnchorPane.rightAnchor="0.0"
2125
AnchorPane.topAnchor="40.0"/>

0 commit comments

Comments
 (0)