diff options
| author | 2020-07-23 19:39:50 +0200 | |
|---|---|---|
| committer | 2020-07-23 19:39:50 +0200 | |
| commit | c9c0bcf6ebf1e120ea47a6bf7ebf8917b8716db5 (patch) | |
| tree | 35c5df16b49bb821c4ddbd2bd1d2927f1ad6292e | |
| parent | Fix losing current cursor position when renaming entries (#297) (diff) | |
| download | enigma-c9c0bcf6ebf1e120ea47a6bf7ebf8917b8716db5.tar.gz enigma-c9c0bcf6ebf1e120ea47a6bf7ebf8917b8716db5.tar.xz enigma-c9c0bcf6ebf1e120ea47a6bf7ebf8917b8716db5.zip | |
Revamp About dialog
5 files changed, 58 insertions, 52 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java index fff755d3..18510602 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java | |||
| @@ -11,60 +11,46 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.gui.dialog; | 12 | package cuchaz.enigma.gui.dialog; |
| 13 | 13 | ||
| 14 | import java.awt.Container; | ||
| 15 | import java.awt.GridBagConstraints; | ||
| 16 | import java.awt.GridBagLayout; | ||
| 17 | |||
| 18 | import javax.swing.*; | ||
| 19 | |||
| 14 | import cuchaz.enigma.Enigma; | 20 | import cuchaz.enigma.Enigma; |
| 21 | import cuchaz.enigma.gui.util.GridBagConstraintsBuilder; | ||
| 15 | import cuchaz.enigma.gui.util.GuiUtil; | 22 | import cuchaz.enigma.gui.util.GuiUtil; |
| 16 | import cuchaz.enigma.utils.I18n; | 23 | import cuchaz.enigma.utils.I18n; |
| 17 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 18 | import cuchaz.enigma.utils.Utils; | ||
| 19 | |||
| 20 | import javax.swing.*; | ||
| 21 | import java.awt.*; | ||
| 22 | import java.io.IOException; | ||
| 23 | 24 | ||
| 24 | public class AboutDialog { | 25 | public class AboutDialog { |
| 25 | 26 | ||
| 26 | public static void show(JFrame parent) { | 27 | public static void show(JFrame parent) { |
| 27 | // init frame | 28 | JDialog frame = new JDialog(parent, String.format(I18n.translate("menu.help.about.title"), Enigma.NAME), true); |
| 28 | final JFrame frame = new JFrame(String.format(I18n.translate("menu.help.about.title"), Enigma.NAME)); | 29 | Container pane = frame.getContentPane(); |
| 29 | final Container pane = frame.getContentPane(); | 30 | pane.setLayout(new GridBagLayout()); |
| 30 | pane.setLayout(new FlowLayout()); | ||
| 31 | 31 | ||
| 32 | // load the content | 32 | GridBagConstraintsBuilder cb = GridBagConstraintsBuilder.create() |
| 33 | try { | 33 | .insets(2) |
| 34 | String html = Utils.readResourceToString("/about.html"); | 34 | .weight(1.0, 0.0) |
| 35 | html = String.format(html, Enigma.NAME, Enigma.VERSION); | 35 | .anchor(GridBagConstraints.WEST); |
| 36 | JLabel label = new JLabel(html); | ||
| 37 | label.setHorizontalAlignment(JLabel.CENTER); | ||
| 38 | pane.add(label); | ||
| 39 | } catch (IOException ex) { | ||
| 40 | throw new Error(ex); | ||
| 41 | } | ||
| 42 | 36 | ||
| 43 | // show the link | 37 | JLabel title = new JLabel(Enigma.NAME); |
| 44 | String html = "<html><a href=\"%s\">%s</a></html>"; | 38 | title.setFont(title.getFont().deriveFont(title.getFont().getSize2D() * 1.5f)); |
| 45 | html = String.format(html, Enigma.URL, Enigma.URL); | ||
| 46 | JButton link = new JButton(html); | ||
| 47 | link.addActionListener(event -> GuiUtil.openUrl(Enigma.URL)); | ||
| 48 | link.setBorderPainted(false); | ||
| 49 | link.setOpaque(false); | ||
| 50 | link.setBackground(Color.WHITE); | ||
| 51 | link.setCursor(new Cursor(Cursor.HAND_CURSOR)); | ||
| 52 | link.setFocusable(false); | ||
| 53 | JPanel linkPanel = new JPanel(); | ||
| 54 | linkPanel.add(link); | ||
| 55 | pane.add(linkPanel); | ||
| 56 | 39 | ||
| 57 | // show ok button | ||
| 58 | JButton okButton = new JButton(I18n.translate("menu.help.about.ok")); | 40 | JButton okButton = new JButton(I18n.translate("menu.help.about.ok")); |
| 59 | pane.add(okButton); | 41 | okButton.addActionListener(e -> frame.dispose()); |
| 60 | okButton.addActionListener(arg0 -> frame.dispose()); | ||
| 61 | 42 | ||
| 62 | // show the frame | 43 | pane.add(title, cb.pos(0, 0).build()); |
| 63 | pane.doLayout(); | 44 | pane.add(new JLabel(I18n.translate("menu.help.about.description")), cb.pos(0, 1).width(2).build()); |
| 64 | frame.setSize(ScaleUtil.getDimension(400, 220)); | 45 | pane.add(new JLabel(I18n.translateFormatted("menu.help.about.version", Enigma.VERSION)), cb.pos(0, 2).width(2).build()); |
| 46 | pane.add(GuiUtil.createLink(Enigma.URL, () -> GuiUtil.openUrl(Enigma.URL)), cb.pos(0, 3).build()); | ||
| 47 | pane.add(okButton, cb.pos(1, 3).anchor(GridBagConstraints.SOUTHEAST).build()); | ||
| 48 | |||
| 49 | frame.pack(); | ||
| 65 | frame.setResizable(false); | 50 | frame.setResizable(false); |
| 66 | frame.setLocationRelativeTo(parent); | 51 | frame.setLocationRelativeTo(parent); |
| 67 | frame.setVisible(true); | ||
| 68 | frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | 52 | frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
| 53 | frame.setVisible(true); | ||
| 69 | } | 54 | } |
| 55 | |||
| 70 | } | 56 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java index 3b8df611..631e065c 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java | |||
| @@ -1,15 +1,20 @@ | |||
| 1 | package cuchaz.enigma.gui.util; | 1 | package cuchaz.enigma.gui.util; |
| 2 | 2 | ||
| 3 | import javax.swing.*; | 3 | import java.awt.Color; |
| 4 | import javax.swing.text.BadLocationException; | 4 | import java.awt.Cursor; |
| 5 | import javax.swing.text.JTextComponent; | 5 | import java.awt.Desktop; |
| 6 | import java.awt.*; | 6 | import java.awt.Font; |
| 7 | import java.awt.event.MouseAdapter; | ||
| 7 | import java.awt.event.MouseEvent; | 8 | import java.awt.event.MouseEvent; |
| 9 | import java.awt.font.TextAttribute; | ||
| 8 | import java.io.IOException; | 10 | import java.io.IOException; |
| 9 | import java.net.URI; | 11 | import java.net.URI; |
| 10 | import java.net.URISyntaxException; | 12 | import java.net.URISyntaxException; |
| 11 | import java.util.Locale; | 13 | import java.util.Map; |
| 12 | import java.util.StringJoiner; | 14 | |
| 15 | import javax.swing.JComponent; | ||
| 16 | import javax.swing.JLabel; | ||
| 17 | import javax.swing.ToolTipManager; | ||
| 13 | 18 | ||
| 14 | public class GuiUtil { | 19 | public class GuiUtil { |
| 15 | public static void openUrl(String url) { | 20 | public static void openUrl(String url) { |
| @@ -40,4 +45,21 @@ public class GuiUtil { | |||
| 40 | manager.setInitialDelay(oldDelay); | 45 | manager.setInitialDelay(oldDelay); |
| 41 | } | 46 | } |
| 42 | 47 | ||
| 48 | public static JLabel createLink(String text, Runnable action) { | ||
| 49 | JLabel link = new JLabel(text); | ||
| 50 | link.setForeground(Color.BLUE.darker()); | ||
| 51 | link.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); | ||
| 52 | @SuppressWarnings("unchecked") | ||
| 53 | Map<TextAttribute, Object> attributes = (Map<TextAttribute, Object>) link.getFont().getAttributes(); | ||
| 54 | attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); | ||
| 55 | link.setFont(link.getFont().deriveFont(attributes)); | ||
| 56 | link.addMouseListener(new MouseAdapter() { | ||
| 57 | @Override | ||
| 58 | public void mousePressed(MouseEvent e) { | ||
| 59 | action.run(); | ||
| 60 | } | ||
| 61 | }); | ||
| 62 | return link; | ||
| 63 | } | ||
| 64 | |||
| 43 | } | 65 | } |
diff --git a/enigma-swing/src/main/resources/about.html b/enigma-swing/src/main/resources/about.html deleted file mode 100644 index b75c1bf0..00000000 --- a/enigma-swing/src/main/resources/about.html +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | <html> | ||
| 2 | <h1>%s</h1> | ||
| 3 | <p>A tool for debofuscation of Java code</p> | ||
| 4 | <p> | ||
| 5 | <p>Version: %s</p> | ||
| 6 | </html> \ No newline at end of file | ||
diff --git a/enigma/src/main/resources/lang/de_de.json b/enigma/src/main/resources/lang/de_de.json index 7a2f385c..31acb5c2 100644 --- a/enigma/src/main/resources/lang/de_de.json +++ b/enigma/src/main/resources/lang/de_de.json | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | "menu.file.stats.title": "Mapping-Statistiken", | 6 | "menu.file.stats.title": "Mapping-Statistiken", |
| 7 | "menu.file.stats.generate": "Diagramm generieren", | 7 | "menu.file.stats.generate": "Diagramm generieren", |
| 8 | "menu.help.about.description": "Ein Tool zur Dekompilierung von Java-Code", | ||
| 9 | "menu.help.about.version": "Version: %s", | ||
| 8 | 10 | ||
| 9 | "popup_menu.editor_tab.close": "Schließen", | 11 | "popup_menu.editor_tab.close": "Schließen", |
| 10 | "popup_menu.editor_tab.close_all": "Alle schließen", | 12 | "popup_menu.editor_tab.close_all": "Alle schließen", |
diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index debe9d15..ca0b007c 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json | |||
| @@ -58,6 +58,8 @@ | |||
| 58 | "menu.help.about": "About", | 58 | "menu.help.about": "About", |
| 59 | "menu.help.about.title": "%s - About", | 59 | "menu.help.about.title": "%s - About", |
| 60 | "menu.help.about.ok": "Ok", | 60 | "menu.help.about.ok": "Ok", |
| 61 | "menu.help.about.description": "A tool for deobfuscation of Java code", | ||
| 62 | "menu.help.about.version": "Version: %s", | ||
| 61 | "menu.help.github": "Github Page", | 63 | "menu.help.github": "Github Page", |
| 62 | 64 | ||
| 63 | "popup_menu.rename": "Rename", | 65 | "popup_menu.rename": "Rename", |