1 /* 2 * Copyright (c) 2008-2019 Emmanuel Dupuy. 3 * This project is distributed under the GPLv3 license. 4 * This is a Copyleft license that gives the user the right to use, 5 * copy and modify the code freely for non-commercial purposes. 6 */ 7 8 package org.jd.gui.view; 9 10 import org.jd.gui.util.exception.ExceptionUtil; 11 import org.jd.gui.util.swing.SwingUtil; 12 13 import javax.swing.*; 14 import java.awt.*; 15 import java.awt.event.ActionEvent; 16 import java.awt.event.KeyEvent; 17 import java.io.IOException; 18 import java.io.InputStream; 19 import java.net.URL; 20 import java.util.Enumeration; 21 import java.util.jar.Attributes; 22 import java.util.jar.Manifest; 23 24 public class AboutView { 25 protected JDialog aboutDialog; 26 protected JButton aboutOkButton; 27 AboutView(JFrame mainFrame)28 public AboutView(JFrame mainFrame) { 29 // Build GUI 30 SwingUtil.invokeLater(() -> { 31 aboutDialog = new JDialog(mainFrame, "About Java Decompiler", false); 32 aboutDialog.setResizable(false); 33 34 JPanel panel = new JPanel(); 35 panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); 36 panel.setLayout(new BorderLayout()); 37 aboutDialog.add(panel); 38 39 Box vbox = Box.createVerticalBox(); 40 panel.add(vbox, BorderLayout.NORTH); 41 JPanel subpanel = new JPanel(); 42 vbox.add(subpanel); 43 subpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); 44 subpanel.setBackground(Color.WHITE); 45 subpanel.setLayout(new BorderLayout()); 46 JLabel logo = new JLabel(new ImageIcon(SwingUtil.getImage("/org/jd/gui/images/jd_icon_64.png"))); 47 logo.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); 48 subpanel.add(logo, BorderLayout.WEST); 49 Box subvbox = Box.createVerticalBox(); 50 subvbox.setBorder(BorderFactory.createEmptyBorder(15,0,15,15)); 51 subpanel.add(subvbox, BorderLayout.EAST); 52 Box hbox = Box.createHorizontalBox(); 53 subvbox.add(hbox); 54 JLabel mainLabel = new JLabel("Java Decompiler"); 55 mainLabel.setFont(UIManager.getFont("Label.font").deriveFont(Font.BOLD, 14)); 56 hbox.add(mainLabel); 57 hbox.add(Box.createHorizontalGlue()); 58 hbox = Box.createHorizontalBox(); 59 subvbox.add(hbox); 60 JPanel subsubpanel = new JPanel(); 61 hbox.add(subsubpanel); 62 subsubpanel.setLayout(new GridLayout(2,2)); 63 subsubpanel.setOpaque(false); 64 subsubpanel.setBorder(BorderFactory.createEmptyBorder(5,10,5,5)); 65 66 String jdGuiVersion = "SNAPSHOT"; 67 String jdCoreVersion = "SNAPSHOT"; 68 69 try { 70 Enumeration<URL> enumeration = AboutView.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); 71 72 while (enumeration.hasMoreElements()) { 73 try (InputStream is = enumeration.nextElement().openStream()) { 74 Attributes attributes = new Manifest(is).getMainAttributes(); 75 String attribute = attributes.getValue("JD-GUI-Version"); 76 77 if (attribute != null) { 78 jdGuiVersion = attribute; 79 } 80 81 attribute = attributes.getValue("JD-Core-Version"); 82 83 if (attribute != null) { 84 jdCoreVersion = attribute; 85 } 86 } 87 } 88 } catch (IOException e) { 89 assert ExceptionUtil.printStackTrace(e); 90 } 91 92 subsubpanel.add(new JLabel("JD-GUI")); 93 subsubpanel.add(new JLabel("version " + jdGuiVersion)); 94 subsubpanel.add(new JLabel("JD-Core")); 95 subsubpanel.add(new JLabel("version " + jdCoreVersion)); 96 97 hbox.add(Box.createHorizontalGlue()); 98 99 hbox = Box.createHorizontalBox(); 100 hbox.add(new JLabel("Copyright © 2008, 2019 Emmanuel Dupuy")); 101 hbox.add(Box.createHorizontalGlue()); 102 subvbox.add(hbox); 103 104 vbox.add(Box.createVerticalStrut(10)); 105 106 hbox = Box.createHorizontalBox(); 107 panel.add(hbox, BorderLayout.SOUTH); 108 hbox.add(Box.createHorizontalGlue()); 109 aboutOkButton = new JButton(" Ok "); 110 Action aboutOkActionListener = new AbstractAction() { 111 @Override public void actionPerformed(ActionEvent actionEvent) { aboutDialog.setVisible(false); } 112 }; 113 aboutOkButton.addActionListener(aboutOkActionListener); 114 hbox.add(aboutOkButton); 115 hbox.add(Box.createHorizontalGlue()); 116 117 // Last setup 118 JRootPane rootPane = aboutDialog.getRootPane(); 119 rootPane.setDefaultButton(aboutOkButton); 120 rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "AboutView.ok"); 121 rootPane.getActionMap().put("AboutView.ok", aboutOkActionListener); 122 123 // Prepare to display 124 aboutDialog.pack(); 125 }); 126 } 127 show()128 public void show() { 129 SwingUtil.invokeLater(() -> { 130 // Show 131 aboutDialog.setLocationRelativeTo(aboutDialog.getParent()); 132 aboutDialog.setVisible(true); 133 aboutOkButton.requestFocus(); 134 }); 135 } 136 } 137