New J2K: Improve UI
This commit is contained in:
committed by
Ilya Kirillov
parent
3dbdb2b64d
commit
15981fed17
@@ -21,6 +21,7 @@ import java.awt.event.KeyListener
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
|
import javax.swing.SwingUtilities.invokeLater
|
||||||
|
|
||||||
object NewJ2KTestView {
|
object NewJ2KTestView {
|
||||||
|
|
||||||
@@ -72,7 +73,9 @@ object NewJ2KTestView {
|
|||||||
actionMap.put("COMPARE", object : AbstractAction() {
|
actionMap.put("COMPARE", object : AbstractAction() {
|
||||||
override fun actionPerformed(e: ActionEvent) {
|
override fun actionPerformed(e: ActionEvent) {
|
||||||
val index = tabs.tabCount
|
val index = tabs.tabCount
|
||||||
tabs.addTab("Select", CompareSelectTab(tabs, results))
|
val tab = CompareSelectTab(tabs, results)
|
||||||
|
tab.fillData()
|
||||||
|
tabs.addTab("Select", tab)
|
||||||
tabs.selectedIndex = index
|
tabs.selectedIndex = index
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -80,16 +83,8 @@ object NewJ2KTestView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private open class IndexTab(val tabs: JBTabbedPane) : JPanel() {
|
private open class IndexTab(val tabs: JBTabbedPane) : JPanel() {
|
||||||
val list = JBList(object : AbstractListModel<String>() {
|
val model = DefaultListModel<String>()
|
||||||
override fun getElementAt(index: Int): String {
|
val list = JBList(model)
|
||||||
val (date, results) = variants[index]
|
|
||||||
return "$index -> $date (${results.shortStat()})"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSize(): Int {
|
|
||||||
return variants.size
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
open fun action() {
|
open fun action() {
|
||||||
val (date, report) = variants[list.selectedIndex]
|
val (date, report) = variants[list.selectedIndex]
|
||||||
@@ -98,6 +93,14 @@ object NewJ2KTestView {
|
|||||||
tabs.selectedIndex = tabIndex
|
tabs.selectedIndex = tabIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fillData() {
|
||||||
|
model.clear()
|
||||||
|
for ((index, variant) in variants.withIndex()) {
|
||||||
|
val (date, results) = variant
|
||||||
|
model.addElement("$index -> $date (${results.shortStat()})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
layout = GridLayoutManager(1, 1)
|
layout = GridLayoutManager(1, 1)
|
||||||
add(list, GridConstraints().apply { fill = GridConstraints.FILL_BOTH })
|
add(list, GridConstraints().apply { fill = GridConstraints.FILL_BOTH })
|
||||||
@@ -156,51 +159,55 @@ object NewJ2KTestView {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
load()
|
invokeLater {
|
||||||
|
val frame = object : JFrame("New J2K Test View") {
|
||||||
|
|
||||||
|
val tabs = JBTabbedPane()
|
||||||
|
val index = IndexTab(tabs)
|
||||||
|
|
||||||
|
init {
|
||||||
|
tabs.addTab("Index", index)
|
||||||
|
|
||||||
|
this.rootPane.actionMap.put("ESCAPE", object : AbstractAction() {
|
||||||
|
override fun actionPerformed(e: ActionEvent) {
|
||||||
|
tabs.selectedIndex = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.rootPane.actionMap.put("CLOSE_TAB", object : AbstractAction() {
|
||||||
|
override fun actionPerformed(e: ActionEvent) {
|
||||||
|
if (tabs.selectedIndex != 0) {
|
||||||
|
tabs.removeTabAt(tabs.selectedIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.rootPane.actionMap.put("RELOAD", object : AbstractAction() {
|
||||||
|
override fun actionPerformed(e: ActionEvent) {
|
||||||
|
load()
|
||||||
|
index.fillData()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
val frame = JFrame().apply {
|
this.rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||||
val tabs = JBTabbedPane()
|
.put(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.META_DOWN_MASK), "CLOSE_TAB")
|
||||||
|
this.rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||||
|
.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.META_DOWN_MASK), "RELOAD")
|
||||||
|
this.rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ESCAPE")
|
||||||
|
|
||||||
fun addIndexTab() {
|
contentPane = tabs
|
||||||
tabs.addTab("Index", IndexTab(tabs))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addIndexTab()
|
frame.pack()
|
||||||
|
frame.setSize(800, 800)
|
||||||
|
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
||||||
|
frame.isVisible = true
|
||||||
|
|
||||||
|
|
||||||
this.rootPane.actionMap.put("ESCAPE", object : AbstractAction() {
|
load()
|
||||||
override fun actionPerformed(e: ActionEvent) {
|
frame.index.fillData()
|
||||||
tabs.selectedIndex = 0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.rootPane.actionMap.put("CLOSE_TAB", object : AbstractAction() {
|
|
||||||
override fun actionPerformed(e: ActionEvent) {
|
|
||||||
if (tabs.selectedIndex != 0) {
|
|
||||||
tabs.removeTabAt(tabs.selectedIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.rootPane.actionMap.put("RELOAD", object : AbstractAction() {
|
|
||||||
override fun actionPerformed(e: ActionEvent) {
|
|
||||||
tabs.removeAll()
|
|
||||||
load()
|
|
||||||
addIndexTab()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
this.rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.META_DOWN_MASK), "CLOSE_TAB")
|
|
||||||
this.rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.META_DOWN_MASK), "RELOAD")
|
|
||||||
this.rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ESCAPE")
|
|
||||||
|
|
||||||
contentPane = tabs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.setSize(800, 800)
|
|
||||||
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
|
||||||
frame.isVisible = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user