Skip to content

Commit

Permalink
Add basic about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedyaseen committed Aug 1, 2024
1 parent 07aaf34 commit 57ccde4
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 deletions.
17 changes: 12 additions & 5 deletions gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "<html><a href=\"$url\">$text</a></html>"
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
}
}

0 comments on commit 57ccde4

Please sign in to comment.