From 55187e211c28eef7200ab2a053011f59abc9c0e3 Mon Sep 17 00:00:00 2001 From: PryosCode Date: Thu, 2 Jun 2022 23:33:26 +0200 Subject: [PATCH] Update Menu Items --- build.gradle.kts | 2 +- .../net/pryoscode/decompiler/window/Window.kt | 1 + .../decompiler/window/container/Code.kt | 66 +++++++++---------- .../decompiler/window/menu/edit/items/Copy.kt | 7 +- .../decompiler/window/menu/edit/items/Find.kt | 7 +- .../window/menu/edit/items/SelectAll.kt | 7 +- .../window/menu/file/items/CloseFile.kt | 7 +- .../decompiler/window/menu/file/items/Exit.kt | 7 +- .../window/menu/file/items/NewWindow.kt | 9 +-- .../window/menu/file/items/OpenFile.kt | 7 +- .../window/menu/help/items/About.kt | 7 +- .../window/menu/view/items/ZoomIn.kt | 7 +- .../window/menu/view/items/ZoomOut.kt | 7 +- .../window/menu/view/items/ZoomReset.kt | 7 +- .../decompiler/window/sidebar/Cell.kt | 9 --- 15 files changed, 80 insertions(+), 77 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 40fc641..9a0de13 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "net.pryoscode" -version = "0.4.0" +version = "0.4.1" kotlin { jvmToolchain { diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/Window.kt b/src/main/kotlin/net/pryoscode/decompiler/window/Window.kt index 620b4fe..b5fba2e 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/Window.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/Window.kt @@ -42,6 +42,7 @@ object Window : JFrame() { val panel = JFXPanel() val root = SplitPane(Sidebar, Container) root.setDividerPositions(Sidebar.minWidth / (Sidebar.minWidth + Container.minWidth), Container.minWidth / (Sidebar.minWidth + Container.minWidth)) + SplitPane.setResizableWithParent(Sidebar, false) for (font in fonts) Font.loadFont(javaClass.classLoader.getResourceAsStream("fonts/${font.split("-")[0]}/$font.ttf"), Toolkit.getToolkit().fontLoader.systemFontSize.toDouble()) diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/container/Code.kt b/src/main/kotlin/net/pryoscode/decompiler/window/container/Code.kt index be928fa..672cfd6 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/container/Code.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/container/Code.kt @@ -19,36 +19,40 @@ import java.util.regex.Pattern class Code(val entry: Entry, private val code: String) : Tab() { - private val keywords = arrayOf( - "abstract", "assert", "boolean", "break", "byte", - "case", "catch", "char", "class", "const", - "continue", "default", "do", "double", "else", - "enum", "extends", "final", "finally", "float", - "for", "goto", "if", "implements", "import", - "instanceof", "int", "interface", "long", "native", - "new", "package", "private", "protected", "public", - "return", "short", "static", "strictfp", "super", - "switch", "synchronized", "this", "throw", "throws", - "transient", "try", "void", "volatile", "while" - ) + companion object { - private val keyword = "\\b(${keywords.joinToString("|")})\\b" - private val paren = "\\(|\\)" - private val brace = "\\{|\\}" - private val bracket = "\\[|\\]" - private val semicolon = "\\;" - private val string = "\"([^\"\\\\]|\\\\.)*\"" - private val comment = "//[^\\n]*|/\\\\*(.|\\\\R)*?\\\\*/|/\\\\*[^\\\\v]*|^\\\\h*\\\\*([^\\\\v]*|/)" + private val keywords = arrayOf( + "abstract", "assert", "boolean", "break", "byte", + "case", "catch", "char", "class", "const", + "continue", "default", "do", "double", "else", + "enum", "extends", "final", "finally", "float", + "for", "goto", "if", "implements", "import", + "instanceof", "int", "interface", "long", "native", + "new", "package", "private", "protected", "public", + "return", "short", "static", "strictfp", "super", + "switch", "synchronized", "this", "throw", "throws", + "transient", "try", "void", "volatile", "while" + ) - private val pattern = Pattern.compile( - "(?$keyword)" + - "|(?$paren)" + - "|(?$brace)" + - "|(?$bracket)" + - "|(?$semicolon)" + - "|(?$string)" + - "|(?$comment)" - ) + private val keyword = "\\b(${keywords.joinToString("|")})\\b" + private val paren = "\\(|\\)" + private val brace = "\\{|\\}" + private val bracket = "\\[|\\]" + private val semicolon = "\\;" + private val string = "\"([^\"\\\\]|\\\\.)*\"" + private val comment = "//[^\\n]*|/\\\\*(.|\\\\R)*?\\\\*/|/\\\\*[^\\\\v]*|^\\\\h*\\\\*([^\\\\v]*|/)" + + private val pattern = Pattern.compile( + "(?$keyword)" + + "|(?$paren)" + + "|(?$brace)" + + "|(?$bracket)" + + "|(?$semicolon)" + + "|(?$string)" + + "|(?$comment)" + ) + + } init { text = entry.name @@ -74,11 +78,7 @@ class Code(val entry: Entry, private val code: String) : Tab() { val close = MenuItem("Close") val closeOthers = MenuItem("Close Others") val closeAll = MenuItem("Close All") - Container.tabs.addListener(ListChangeListener { - val multiple = Container.tabs.size == 1 - closeOthers.isDisable = multiple - closeAll.isDisable = multiple - }) + Container.tabs.addListener(ListChangeListener { closeOthers.isDisable = Container.tabs.size == 1 }) close.setOnAction { Container.tabs.remove(this) } closeOthers.setOnAction { val tabs = Container.tabs.iterator() diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Copy.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Copy.kt index d637eda..27a1da4 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Copy.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Copy.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.edit.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class Copy : JMenuItem("Copy", KeyEvent.VK_C) { +class Copy : JMenuItem("Copy", KeyEvent.VK_C), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Find.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Find.kt index 4f657f7..9c175c6 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Find.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/Find.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.edit.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class Find : JMenuItem("Find", KeyEvent.VK_F) { +class Find : JMenuItem("Find", KeyEvent.VK_F), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/SelectAll.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/SelectAll.kt index 1bcb3fd..4d94b2b 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/SelectAll.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/edit/items/SelectAll.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.edit.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class SelectAll : JMenuItem("Select All", KeyEvent.VK_A) { +class SelectAll : JMenuItem("Select All", KeyEvent.VK_A), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/CloseFile.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/CloseFile.kt index a73a847..73a0ba8 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/CloseFile.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/CloseFile.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.file.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class CloseFile : JMenuItem("Close File", KeyEvent.VK_W) { +class CloseFile : JMenuItem("Close File", KeyEvent.VK_W), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/Exit.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/Exit.kt index f77316c..59a246c 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/Exit.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/Exit.kt @@ -2,18 +2,19 @@ package net.pryoscode.decompiler.window.menu.file.items import net.pryoscode.decompiler.window.Window import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class Exit : JMenuItem("Exit", KeyEvent.VK_Q) { +class Exit : JMenuItem("Exit", KeyEvent.VK_Q), ActionListener { init { accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) { + override fun actionPerformed(e: ActionEvent?) { Window.dispose() } diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/NewWindow.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/NewWindow.kt index 5f9665f..99ac7cb 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/NewWindow.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/NewWindow.kt @@ -2,22 +2,23 @@ package net.pryoscode.decompiler.window.menu.file.items import net.pryoscode.decompiler.Main import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import java.lang.management.ManagementFactory import javax.swing.JMenuItem import javax.swing.KeyStroke -class NewWindow : JMenuItem("New Window", KeyEvent.VK_N) { +class NewWindow : JMenuItem("New Window", KeyEvent.VK_N), ActionListener { init { accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) { + override fun actionPerformed(e: ActionEvent?) { val java = ProcessHandle.current().info().command().get() val classPath = ManagementFactory.getRuntimeMXBean().classPath - val main = Main.javaClass.declaringClass.canonicalName + val main = Main::class.java.canonicalName ProcessBuilder(java, "-cp", classPath, main).start() } diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/OpenFile.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/OpenFile.kt index aed0c66..fba0ca6 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/OpenFile.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/file/items/OpenFile.kt @@ -4,20 +4,21 @@ import javafx.application.Platform import net.pryoscode.decompiler.window.Window import net.pryoscode.decompiler.window.sidebar.Sidebar import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JFileChooser import javax.swing.JMenuItem import javax.swing.KeyStroke import javax.swing.filechooser.FileNameExtensionFilter -class OpenFile : JMenuItem("Open File", KeyEvent.VK_O) { +class OpenFile : JMenuItem("Open File", KeyEvent.VK_O), ActionListener { init { accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) { + override fun actionPerformed(e: ActionEvent?) { val fileChooser = JFileChooser() fileChooser.dialogTitle = text fileChooser.fileFilter = FileNameExtensionFilter("Java Archive", "jar") diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/help/items/About.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/help/items/About.kt index 80a56d1..5ca6425 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/help/items/About.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/help/items/About.kt @@ -1,16 +1,17 @@ package net.pryoscode.decompiler.window.menu.help.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem -class About : JMenuItem("About", KeyEvent.VK_A) { +class About : JMenuItem("About", KeyEvent.VK_A), ActionListener { init { - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) { + override fun actionPerformed(e: ActionEvent?) { net.pryoscode.decompiler.window.popup.About() } diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomIn.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomIn.kt index b1b8d82..f0e83bf 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomIn.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomIn.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.view.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class ZoomIn : JMenuItem("Zoom In", KeyEvent.VK_PLUS) { +class ZoomIn : JMenuItem("Zoom In", KeyEvent.VK_PLUS), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomOut.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomOut.kt index 029e10d..bbc66b7 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomOut.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomOut.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.view.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class ZoomOut : JMenuItem("Zoom Out", KeyEvent.VK_MINUS) { +class ZoomOut : JMenuItem("Zoom Out", KeyEvent.VK_MINUS), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomReset.kt b/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomReset.kt index ba8ba19..5aa3e2a 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomReset.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/menu/view/items/ZoomReset.kt @@ -1,18 +1,19 @@ package net.pryoscode.decompiler.window.menu.view.items import java.awt.event.ActionEvent +import java.awt.event.ActionListener import java.awt.event.KeyEvent import javax.swing.JMenuItem import javax.swing.KeyStroke -class ZoomReset : JMenuItem("Zoom Reset", KeyEvent.VK_0) { +class ZoomReset : JMenuItem("Zoom Reset", KeyEvent.VK_0), ActionListener { init { isEnabled = false accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_0, KeyEvent.CTRL_DOWN_MASK) - addActionListener(::actionListener) + addActionListener(this) } - private fun actionListener(event: ActionEvent) {} + override fun actionPerformed(e: ActionEvent?) {} } \ No newline at end of file diff --git a/src/main/kotlin/net/pryoscode/decompiler/window/sidebar/Cell.kt b/src/main/kotlin/net/pryoscode/decompiler/window/sidebar/Cell.kt index 7ea026b..0b03f31 100644 --- a/src/main/kotlin/net/pryoscode/decompiler/window/sidebar/Cell.kt +++ b/src/main/kotlin/net/pryoscode/decompiler/window/sidebar/Cell.kt @@ -1,7 +1,5 @@ package net.pryoscode.decompiler.window.sidebar -import javafx.scene.control.ContextMenu -import javafx.scene.control.MenuItem import javafx.scene.control.TreeCell import javafx.scene.image.ImageView import javafx.scene.input.MouseButton @@ -20,16 +18,9 @@ class Cell : TreeCell() { if (empty || item == null) { text = "" graphic = null - contextMenu = null } else { text = item.name graphic = ImageView(item.type.icon) - if (item.type != Type.ARCHIVE && item.type != Type.PACKAGE && item.type != Type.FILE) { - contextMenu = ContextMenu() - val open = MenuItem("Open") - open.setOnAction { Container.open(item) } - contextMenu.items.add(open) - } } }