implement copy tags button
This commit is contained in:
parent
018e6291c8
commit
7bddf2fdbc
2 changed files with 34 additions and 0 deletions
|
@ -3,10 +3,13 @@ package dev.nuculabs.imagetagger.ui.controls
|
|||
import dev.nuculabs.imagetagger.ui.alerts.ErrorAlert
|
||||
import javafx.fxml.FXML
|
||||
import javafx.fxml.FXMLLoader
|
||||
import javafx.scene.control.Button
|
||||
import javafx.scene.control.Label
|
||||
import javafx.scene.control.TextArea
|
||||
import javafx.scene.image.Image
|
||||
import javafx.scene.image.ImageView
|
||||
import javafx.scene.input.Clipboard
|
||||
import javafx.scene.input.ClipboardContent
|
||||
import javafx.scene.input.MouseEvent
|
||||
import javafx.scene.layout.HBox
|
||||
import java.awt.Desktop
|
||||
|
@ -39,6 +42,12 @@ class ImageTagsEntryControl(private val imagePath: String, predictions: List<Str
|
|||
@FXML
|
||||
private lateinit var fileNameLabel: Label
|
||||
|
||||
/**
|
||||
* The copy tags button.
|
||||
*/
|
||||
@FXML
|
||||
private lateinit var copyTagsButton: Button
|
||||
|
||||
init {
|
||||
val resource = ImageTagsEntryControl::class.java.getResource("image-tags-entry.fxml")
|
||||
logger.fine("Using resource URL: $resource")
|
||||
|
@ -67,6 +76,10 @@ class ImageTagsEntryControl(private val imagePath: String, predictions: List<Str
|
|||
}
|
||||
it.consume()
|
||||
}
|
||||
// Copy Tags Button
|
||||
copyTagsButton.setOnMouseClicked {
|
||||
onCopyTagsClick()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,4 +118,14 @@ class ImageTagsEntryControl(private val imagePath: String, predictions: List<Str
|
|||
ErrorAlert("Can't open file: $imagePath\nOperation is not supported!")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the image tags to the system clipboard.
|
||||
*/
|
||||
fun onCopyTagsClick() {
|
||||
val clipboard: Clipboard = Clipboard.getSystemClipboard()
|
||||
val content = ClipboardContent()
|
||||
content.putString(predictedImageTags.text)
|
||||
clipboard.setContent(content)
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
<?import javafx.geometry.Insets?>
|
||||
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import org.kordamp.ikonli.javafx.FontIcon?>
|
||||
<fx:root type="javafx.scene.layout.HBox" xmlns:fx="http://javafx.com/fxml">
|
||||
<StackPane style="-fx-background-color: lightgray;" prefWidth="244" prefHeight="244">
|
||||
<ImageView fx:id="imageView"/>
|
||||
|
@ -16,6 +17,16 @@
|
|||
<Label fx:id="fileNameLabel"/>
|
||||
<Label text="Predicted tags:"/>
|
||||
<TextArea fx:id="predictedImageTags" editable="false" wrapText="true" prefColumnCount="20"/>
|
||||
<HBox>
|
||||
<padding>
|
||||
<Insets top="5.0"/>
|
||||
</padding>
|
||||
<Button fx:id="copyTagsButton" text="Copy Tags">
|
||||
<graphic>
|
||||
<FontIcon iconLiteral="far-clipboard" iconSize="16"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
</fx:root>
|
Loading…
Reference in a new issue