Skip to content

Commit

Permalink
fixes #122 (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-claw authored Sep 14, 2023
1 parent d8cba97 commit 1c239d4
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class VripperGuiApplication : App(

private lateinit var context: ConfigurableApplicationContext //We are going to set application context here
private var initialized = false

init {
APP_INSTANCE = this
}
override fun start(stage: Stage) {
with(stage) {
width = 1200.0
Expand Down Expand Up @@ -73,6 +77,10 @@ class VripperGuiApplication : App(
}
exitProcess(0)
}

companion object {
lateinit var APP_INSTANCE: Application
}
}

fun main(args: Array<String>) {
Expand Down
20 changes: 20 additions & 0 deletions vripper-gui/src/main/kotlin/me/mnlr/vripper/view/CommonUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.mnlr.vripper.view

import com.sun.jna.WString
import me.mnlr.vripper.VripperGuiApplication
import me.mnlr.vripper.utils.Shell32

fun openFileDirectory(path: String) {
val os = System.getProperty("os.name")
if(os.contains("Windows")) {
Shell32.INSTANCE.ShellExecuteW(null, WString("open"), WString(path), null, null, 1)
} else if(os.contains("Linux")) {
Runtime.getRuntime().exec("xdg-open $path")
} else if(os.contains("Mac")) {
Runtime.getRuntime().exec("open -R $path")
}
}

fun openLink(path: String) {
VripperGuiApplication.APP_INSTANCE.hostServices.showDocument(path)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.mnlr.vripper.view

import javafx.beans.value.ObservableValue
import javafx.event.EventHandler
import javafx.scene.control.ProgressBar
import javafx.scene.control.TableCell
import javafx.scene.control.TableColumn
import javafx.scene.input.MouseEvent

class ProgressTableCell<S> : TableCell<S, Double>() {

/* *************************************************************************
* *
* Fields *
* *
**************************************************************************/
private var progressBar: ProgressBar

private var observable: ObservableValue<Double>? = null

init {
styleClass.add("progress-bar-table-cell")
progressBar = ProgressBar()
progressBar.maxWidth = Double.MAX_VALUE
}

fun setOnMouseClick(clickEvent: EventHandler<in MouseEvent>) {
progressBar.onMouseClicked = clickEvent
}

override fun updateItem(item: Double?, empty: Boolean) {
super.updateItem(item, empty)
if (empty) {
setGraphic(null)
} else {
progressBar.progressProperty().unbind()
val column: TableColumn<S, Double>? = tableColumn
observable = column?.getCellObservableValue(index)
if (observable != null) {
progressBar.progressProperty().bind(observable)
} else if (item != null) {
progressBar.progress = item
}
setGraphic(progressBar)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package me.mnlr.vripper.view.tables
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.geometry.Pos
import javafx.scene.control.TableView
import javafx.scene.control.*
import javafx.scene.image.ImageView
import javafx.scene.input.MouseButton
import javafx.util.Callback
import me.mnlr.vripper.controller.ImageController
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.model.ImageModel
import me.mnlr.vripper.view.ProgressTableCell
import me.mnlr.vripper.view.openLink
import me.mnlr.vripper.view.FxScheduler
import tornadofx.*

Expand Down Expand Up @@ -58,38 +62,45 @@ class ImagesTableView : Fragment("Photos") {

override val root = vbox(alignment = Pos.CENTER_RIGHT) {
tableView = tableview(items) {
setRowFactory {
val tableRow = TableRow<ImageModel>()
val urlItem = MenuItem("Open link").apply {
setOnAction {
openLink(tableRow.item.url)
}
graphic = ImageView("open-in-browser.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}
val contextMenu = ContextMenu()
contextMenu.items.addAll(urlItem)
tableRow.contextMenuProperty().bind(tableRow.emptyProperty()
.map { empty -> if (empty) null else contextMenu })
tableRow
}
column("Index", ImageModel::indexProperty) {
sortOrder.add(this)
}
column("Link", ImageModel::urlProperty) {
prefWidth = 200.0
}
column("Progress", ImageModel::progressProperty) {
cellFormat {
addClass(Stylesheet.progressBarTableCell)
graphic = cache {
progressbar(itemProperty().doubleBinding { it?.toDouble() ?: 0.0 }) {
setOnMouseClicked {
when (it.clickCount) {
1 -> {
this@tableview.requestFocus()
this@tableview.focusModel.focus(this@cellFormat.tableRow.index)
if (it.isControlDown && it.button.equals(MouseButton.PRIMARY)) {
if (this@tableview.selectionModel.isSelected(this@cellFormat.tableRow.index)) {
this@tableview.selectionModel.clearSelection(this@cellFormat.tableRow.index)
} else {
this@tableview.selectionModel.select(this@cellFormat.tableRow.index)
}
} else if (it.button.equals(MouseButton.PRIMARY)) {
this@tableview.selectionModel.clearSelection()
this@tableview.selectionModel.select(this@cellFormat.tableRow.index)
}
}
cellFactory = Callback {
val cell = ProgressTableCell<ImageModel>()
cell.setOnMouseClick {
when (it.clickCount) {
1 -> {
this@tableview.requestFocus()
this@tableview.focusModel.focus(cell.tableRow.index)
if (it.button.equals(MouseButton.PRIMARY)) {
this@tableview.selectionModel.clearSelection()
this@tableview.selectionModel.select(cell.tableRow.index)
}
}
useMaxWidth = true
}
}
cell as TableCell<ImageModel, Number>
}
}
column("Status", ImageModel::statusProperty)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package me.mnlr.vripper.view.tables

import com.sun.jna.WString
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.control.*
import javafx.scene.image.ImageView
import javafx.scene.input.MouseButton
import javafx.util.Callback
import me.mnlr.vripper.controller.PostController
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.model.PostModel
import me.mnlr.vripper.utils.Shell32
import me.mnlr.vripper.view.ProgressTableCell
import me.mnlr.vripper.view.openFileDirectory
import me.mnlr.vripper.view.openLink
import me.mnlr.vripper.view.FxScheduler
import tornadofx.*

Expand Down Expand Up @@ -81,54 +83,69 @@ class PostsTableView : View() {
}
}

val contextMenu = ContextMenu()
val startItem = MenuItem("Start")
startItem.setOnAction {
startSelected()
val startItem = MenuItem("Start").apply {
setOnAction {
startSelected()
}
graphic = ImageView("play.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}
val playIcon = ImageView("play.png")
playIcon.fitWidth = 18.0
playIcon.fitHeight = 18.0
startItem.graphic = playIcon

val stopItem = MenuItem("Stop")
stopItem.setOnAction {
stopSelected()

val stopItem = MenuItem("Stop").apply {
setOnAction {
stopSelected()
}
graphic = ImageView("pause.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}
val stopIcon = ImageView("pause.png")
stopIcon.fitWidth = 18.0
stopIcon.fitHeight = 18.0
stopItem.graphic = stopIcon

val deleteItem = MenuItem("Delete")
deleteItem.setOnAction {
deleteSelected()

val deleteItem = MenuItem("Delete").apply {
setOnAction {
deleteSelected()
}
graphic = ImageView("trash.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}

val detailsItem = MenuItem("Images").apply {
setOnAction {
openPhotos(tableRow.item.postId)
}
graphic = ImageView("details.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}
val deleteIcon = ImageView("trash.png")
deleteIcon.fitWidth = 18.0
deleteIcon.fitHeight = 18.0
deleteItem.graphic = deleteIcon

val detailsItem = MenuItem("Images")
detailsItem.setOnAction {
openPhotos(tableRow.item.postId)

val locationItem = MenuItem("Open containing folder").apply {
setOnAction {
openFileDirectory(tableRow.item.path)
}
graphic = ImageView("file-explorer.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}
val detailsIcon = ImageView("details.png")
detailsIcon.fitWidth = 18.0
detailsIcon.fitHeight = 18.0
detailsItem.graphic = detailsIcon

val locationItem = MenuItem("Open Download Directory")
locationItem.setOnAction {
openFileDirectory(tableRow.item.path)

val urlItem = MenuItem("Open link").apply {
setOnAction {
openLink(tableRow.item.url)
}
graphic = ImageView("open-in-browser.png").apply {
fitWidth = 18.0
fitHeight = 18.0
}
}
val locationIcon = ImageView("file-explorer.png")
locationIcon.fitWidth = 18.0
locationIcon.fitHeight = 18.0
locationItem.graphic = locationIcon

val contextMenu = ContextMenu()
contextMenu.items.addAll(
startItem, stopItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem
startItem, stopItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem, urlItem
)
tableRow.contextMenuProperty()
.bind(tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu })
Expand All @@ -138,32 +155,41 @@ class PostsTableView : View() {
prefWidth = 300.0
}
column("Progress", PostModel::progressProperty) {
cellFormat {
addClass(Stylesheet.progressBarTableCell)
graphic = cache {
progressbar(itemProperty().doubleBinding { it?.toDouble() ?: 0.0 }) {
setOnMouseClicked {
cellFactory = Callback {
val cell = ProgressTableCell<PostModel>()
cell.setOnMouseClick {
when (it.button) {
MouseButton.SECONDARY -> {
this@tableview.requestFocus()
this@tableview.focusModel.focus(cell.tableRow.index)
if (!this@tableview.selectionModel.isSelected(cell.tableRow.index)) {
this@tableview.selectionModel.clearSelection()
this@tableview.selectionModel.select(cell.tableRow.index)
}
}
MouseButton.PRIMARY -> {
when (it.clickCount) {
1 -> {
this@tableview.requestFocus()
this@tableview.focusModel.focus(this@cellFormat.tableRow.index)
this@tableview.focusModel.focus(cell.tableRow.index)
if (it.isControlDown && it.button.equals(MouseButton.PRIMARY)) {
if (this@tableview.selectionModel.isSelected(this@cellFormat.tableRow.index)) {
this@tableview.selectionModel.clearSelection(this@cellFormat.tableRow.index)
if (this@tableview.selectionModel.isSelected(cell.tableRow.index)) {
this@tableview.selectionModel.clearSelection(cell.tableRow.index)
} else {
this@tableview.selectionModel.select(this@cellFormat.tableRow.index)
this@tableview.selectionModel.select(cell.tableRow.index)
}
} else if (it.button.equals(MouseButton.PRIMARY)) {
this@tableview.selectionModel.clearSelection()
this@tableview.selectionModel.select(this@cellFormat.tableRow.index)
this@tableview.selectionModel.select(cell.tableRow.index)
}
}
2 -> openPhotos(this@cellFormat.tableRow.item.postId)
2 -> openPhotos(cell.tableRow.item.postId)
}
}
useMaxWidth = true
else -> {}
}
}
cell as TableCell<PostModel, Number>
}
}
column("Status", PostModel::statusProperty)
Expand All @@ -177,17 +203,6 @@ class PostsTableView : View() {
}
}

private fun openFileDirectory(path: String) {
val os = System.getProperty("os.name")
if(os.contains("Windows")) {
Shell32.INSTANCE.ShellExecuteW(null, WString("open"), WString(path), null, null, 1)
} else if(os.contains("Linux")) {
Runtime.getRuntime().exec("xdg-open $path")
} else if(os.contains("Mac")) {
Runtime.getRuntime().exec("open -R $path")
}
}

fun deleteSelected() {
val postIdList = tableView.selectionModel.selectedItems.map { it.postId }
confirm(
Expand Down
Loading

0 comments on commit 1c239d4

Please sign in to comment.