Skip to content

Commit

Permalink
Update Menu Items
Browse files Browse the repository at this point in the history
  • Loading branch information
sotasan committed Jun 2, 2022
1 parent 805c9c3 commit 55187e2
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 77 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "net.pryoscode"
version = "0.4.0"
version = "0.4.1"

kotlin {
jvmToolchain {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/net/pryoscode/decompiler/window/Window.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
66 changes: 33 additions & 33 deletions src/main/kotlin/net/pryoscode/decompiler/window/container/Code.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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>$keyword)" +
"|(?<PAREN>$paren)" +
"|(?<BRACE>$brace)" +
"|(?<BRACKET>$bracket)" +
"|(?<SEMICOLON>$semicolon)" +
"|(?<STRING>$string)" +
"|(?<COMMENT>$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>$keyword)" +
"|(?<PAREN>$paren)" +
"|(?<BRACE>$brace)" +
"|(?<BRACKET>$bracket)" +
"|(?<SEMICOLON>$semicolon)" +
"|(?<STRING>$string)" +
"|(?<COMMENT>$comment)"
)

}

init {
text = entry.name
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
@@ -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?) {}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,16 +18,9 @@ class Cell : TreeCell<Entry>() {
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)
}
}
}

Expand Down

0 comments on commit 55187e2

Please sign in to comment.