diff --git a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt index be661cee..4c444d4f 100644 --- a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt +++ b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt @@ -5,14 +5,12 @@ import com.formdev.flatlaf.extras.components.FlatMenuBar import com.formdev.flatlaf.util.UIScale import io.netty.buffer.UnpooledByteBufAllocator import net.miginfocom.swing.MigLayout +import net.rsprox.gui.dialogs.AboutDialog import net.rsprox.gui.sessions.SessionsPanel import net.rsprox.gui.sidebar.SideBar import net.rsprox.proxy.ProxyService import java.awt.Dimension -import javax.swing.BorderFactory -import javax.swing.JFrame -import javax.swing.JMenu -import javax.swing.JPanel +import javax.swing.* public class App { @@ -53,7 +51,16 @@ public class App { private fun setupMenuBar() { val menuBar = FlatMenuBar() menuBar.add(JMenu("RSProx")) - menuBar.add(JMenu("Help")) + menuBar.add(JMenu("Help").apply { + val aboutItem = JMenuItem("About") + aboutItem.accelerator = KeyStroke.getKeyStroke("F1") + aboutItem.mnemonic = 'A'.code + aboutItem.addActionListener { + val dialog = AboutDialog(frame) + dialog.isVisible = true + } + add(aboutItem) + }) frame.jMenuBar = menuBar } diff --git a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/dialogs/AboutDialog.kt b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/dialogs/AboutDialog.kt new file mode 100644 index 00000000..6ac71b37 --- /dev/null +++ b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/dialogs/AboutDialog.kt @@ -0,0 +1,73 @@ +package net.rsprox.gui.dialogs + +import com.formdev.flatlaf.extras.FlatSVGUtils +import com.formdev.flatlaf.extras.components.FlatButton +import com.formdev.flatlaf.extras.components.FlatLabel +import net.miginfocom.swing.MigLayout +import net.rsprox.gui.AppProperties +import java.awt.Cursor +import java.awt.Desktop +import java.awt.event.MouseAdapter +import java.awt.event.MouseEvent +import java.net.URI +import javax.swing.* + +public class AboutDialog(parent: JFrame) : JDialog() { + + init { + title = "About RSProx" + setSize(400, 320) + setLocationRelativeTo(parent) + isResizable = false + isModal = true + modalityType = ModalityType.APPLICATION_MODAL + iconImages = FlatSVGUtils.createWindowIconImages("/favicon.svg") + + val panel = JPanel(MigLayout("insets 30 30 n n, wrap 2", "[left]20[grow,fill]", "[][][]15[]15[][]push[]")) + + panel.add(JLabel(ImageIcon(FlatSVGUtils.svg2image("/favicon.svg", 48, 48)))) + panel.add(FlatLabel().apply { + text = "RSProx v${AppProperties.version}" + labelType = FlatLabel.LabelType.h1 + }) + + panel.add(FlatLabel().apply { + text = "RSProx is a free and open-source project." + labelType = FlatLabel.LabelType.regular + }, "skip 1, wrap") + panel.add(FlatLabel().apply { + text = "It is licensed under the MIT License." + labelType = FlatLabel.LabelType.regular + }, "skip 1, wrap") + + panel.add(FlatLabel().apply { + text = "Java Version: ${System.getProperty("java.version")}" + labelType = FlatLabel.LabelType.regular + }, "skip 1, wrap") + + panel.add(createLinkLabel("GitHub Repository", "https://github.com/blurite/rsprox"), "skip 1, wrap") + panel.add(createLinkLabel("Join us at Discord", "https://discord.gg/blurite"), "skip 1, wrap") + + panel.add(FlatButton().apply { + text = "Close" + addActionListener { dispose() } + }, "skip 1, align right") + + add(panel) + } + + private fun createLinkLabel(text: String, url: String): FlatLabel { + val label = FlatLabel() + label.text = "$text" + label.labelType = FlatLabel.LabelType.regular + label.cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) + label.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { + if (Desktop.isDesktopSupported()) { + Desktop.getDesktop().browse(URI(url)) + } + } + }) + return label + } +}