1 package com.mxgraph.examples.swing.editor; 2 3 import java.awt.BorderLayout; 4 import java.awt.Color; 5 import java.awt.FlowLayout; 6 import java.awt.Font; 7 import java.awt.Frame; 8 import java.awt.GradientPaint; 9 import java.awt.Graphics; 10 import java.awt.Graphics2D; 11 import java.awt.event.ActionEvent; 12 import java.awt.event.ActionListener; 13 import java.awt.event.KeyEvent; 14 15 import javax.swing.BorderFactory; 16 import javax.swing.BoxLayout; 17 import javax.swing.JButton; 18 import javax.swing.JComponent; 19 import javax.swing.JDialog; 20 import javax.swing.JLabel; 21 import javax.swing.JPanel; 22 import javax.swing.JRootPane; 23 import javax.swing.KeyStroke; 24 25 import com.mxgraph.util.mxResources; 26 import com.mxgraph.view.mxGraph; 27 28 public class EditorAboutFrame extends JDialog 29 { 30 31 /** 32 * 33 */ 34 private static final long serialVersionUID = -3378029138434324390L; 35 36 /** 37 * 38 */ EditorAboutFrame(Frame owner)39 public EditorAboutFrame(Frame owner) 40 { 41 super(owner); 42 setTitle(mxResources.get("aboutGraphEditor")); 43 setLayout(new BorderLayout()); 44 45 // Creates the gradient panel 46 JPanel panel = new JPanel(new BorderLayout()) 47 { 48 49 /** 50 * 51 */ 52 private static final long serialVersionUID = -5062895855016210947L; 53 54 /** 55 * 56 */ 57 public void paintComponent(Graphics g) 58 { 59 super.paintComponent(g); 60 61 // Paint gradient background 62 Graphics2D g2d = (Graphics2D) g; 63 g2d.setPaint(new GradientPaint(0, 0, Color.WHITE, getWidth(), 64 0, getBackground())); 65 g2d.fillRect(0, 0, getWidth(), getHeight()); 66 } 67 68 }; 69 70 panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory 71 .createMatteBorder(0, 0, 1, 0, Color.GRAY), BorderFactory 72 .createEmptyBorder(8, 8, 12, 8))); 73 74 // Adds title 75 JLabel titleLabel = new JLabel(mxResources.get("aboutGraphEditor")); 76 titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD)); 77 titleLabel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); 78 titleLabel.setOpaque(false); 79 panel.add(titleLabel, BorderLayout.NORTH); 80 81 // Adds optional subtitle 82 JLabel subtitleLabel = new JLabel( 83 "For more information visit http://www.mxgraph.com/"); 84 subtitleLabel.setBorder(BorderFactory.createEmptyBorder(4, 18, 0, 0)); 85 subtitleLabel.setOpaque(false); 86 panel.add(subtitleLabel, BorderLayout.CENTER); 87 88 getContentPane().add(panel, BorderLayout.NORTH); 89 90 JPanel content = new JPanel(); 91 content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); 92 content.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 93 94 content.add(new JLabel("JGraph X - The Swing Portion of mxGraph")); 95 content.add(new JLabel(" ")); 96 97 content.add(new JLabel("mxGraph Version " + mxGraph.VERSION)); 98 content.add(new JLabel("Copyright (C) 2009 by JGraph Ltd.")); 99 content.add(new JLabel("All rights reserved.")); 100 content.add(new JLabel(" ")); 101 102 // try 103 // { 104 // content.add(new JLabel("Operating System Name: " 105 // + System.getProperty("os.name"))); 106 // content.add(new JLabel("Operating System Version: " 107 // + System.getProperty("os.version"))); 108 // content.add(new JLabel(" ")); 109 // 110 // content.add(new JLabel("Java Vendor: " 111 // + System.getProperty("java.vendor", "undefined"))); 112 // content.add(new JLabel("Java Version: " 113 // + System.getProperty("java.version", "undefined"))); 114 // content.add(new JLabel(" ")); 115 // 116 // content.add(new JLabel("Total Memory: " 117 // + Runtime.getRuntime().totalMemory())); 118 // content.add(new JLabel("Free Memory: " 119 // + Runtime.getRuntime().freeMemory())); 120 // } 121 // catch (Exception e) 122 // { 123 // // ignore 124 // } 125 126 getContentPane().add(content, BorderLayout.CENTER); 127 128 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 129 buttonPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory 130 .createMatteBorder(1, 0, 0, 0, Color.GRAY), BorderFactory 131 .createEmptyBorder(16, 8, 8, 8))); 132 getContentPane().add(buttonPanel, BorderLayout.SOUTH); 133 134 // Adds OK button to close window 135 JButton closeButton = new JButton("Close"); 136 closeButton.addActionListener(new ActionListener() 137 { 138 public void actionPerformed(ActionEvent e) 139 { 140 setVisible(false); 141 } 142 }); 143 144 buttonPanel.add(closeButton); 145 146 // Sets default button for enter key 147 getRootPane().setDefaultButton(closeButton); 148 149 setResizable(false); 150 setSize(400, 400); 151 } 152 153 /** 154 * Overrides {@link JDialog#createRootPane()} to return a root pane that 155 * hides the window when the user presses the ESCAPE key.O 156 */ createRootPane()157 protected JRootPane createRootPane() 158 { 159 KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); 160 JRootPane rootPane = new JRootPane(); 161 rootPane.registerKeyboardAction(new ActionListener() 162 { 163 public void actionPerformed(ActionEvent actionEvent) 164 { 165 setVisible(false); 166 } 167 }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); 168 return rootPane; 169 } 170 171 } 172