1 22 package org.enhydra.multiServer.launch; 23 import javax.swing.BorderFactory ; 24 import javax.swing.ImageIcon ; 25 import javax.swing.JDialog ; 26 import javax.swing.JButton ; 27 import javax.swing.JLabel ; 28 import javax.swing.JPanel ; 29 import javax.swing.JTextArea ; 30 import javax.swing.SwingConstants ; 31 import java.awt.event.ActionEvent ; 32 import java.awt.event.ActionListener ; 33 import java.awt.event.WindowEvent ; 34 import java.awt.AWTEvent ; 35 import java.awt.BorderLayout ; 36 import java.awt.Dialog ; 37 import java.awt.Dimension ; 38 import java.awt.GridBagConstraints ; 39 import java.awt.GridBagLayout ; 40 import java.awt.Insets ; 41 import java.awt.Frame ; 42 import java.awt.Point ; 43 import java.awt.SystemColor ; 44 import java.beans.Beans ; 45 public class AboutBox extends JDialog { 46 private JPanel panelMain; 47 private JPanel panelButton; 48 private JPanel panelLabel; 49 private JLabel labelTitle; 50 private JTextArea textArea; 51 private JLabel labelSmall; 52 private JButton buttonOK; 53 private JButton buttonInfo; 54 private GridBagLayout layoutMain; 55 private GridBagLayout layoutButton; 56 private GridBagLayout layoutLabel; 57 private boolean standalone = false; 58 private LocalActionListener actionListener = null; 59 60 public AboutBox(Frame owner) { 61 super(owner, null, true); 62 construct(); 63 } 64 65 public AboutBox(Dialog owner) { 66 super(owner, null, true); 67 construct(); 68 } 69 70 private void construct() { 71 try { 72 jbInit(); 73 pmInit(); 74 pack(); 75 setResizable(true); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 } 79 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 80 } 81 82 protected void clearAll() { 84 buttonOK.removeAll(); 85 buttonOK.removeActionListener(actionListener); 86 buttonInfo.removeAll(); 87 buttonInfo.removeActionListener(actionListener); 88 labelTitle.removeAll(); 89 textArea.removeAll(); 90 labelSmall.removeAll(); 91 panelButton.removeAll(); 92 panelLabel.removeAll(); 93 panelMain.removeAll(); 94 removeAll(); 95 getContentPane().removeAll(); 96 actionListener = null; 97 buttonOK = null; 98 buttonInfo = null; 99 labelSmall = null; 100 layoutButton = null; 101 layoutLabel = null; 102 layoutMain = null; 103 panelButton = null; 104 panelLabel = null; 105 panelMain = null; 106 setTitle(null); 107 } 108 109 public void show() { 111 Point centeringPoint; 112 113 pack(); 114 centeringPoint = SwingUtil.getCenteringPoint(getSize()); 115 setLocation(centeringPoint); 116 buttonOK.requestFocus(); 117 super.show(); 118 } 119 120 public static void main(String [] args) { 121 SwingUtil.setLookAndFeelToSystem(); 122 AboutBox dlg; 123 124 dlg = new AboutBox(new Frame ()); 125 dlg.standalone = true; 126 dlg.show(); 127 } 128 129 public String getTitleText() { 130 return labelTitle.getText(); 131 } 132 133 public String getTextAreaText() { 134 return textArea.getText(); 135 } 136 137 public void setTitleText(String p) { 138 labelTitle.setText(p); 139 setTitle("About " + p); 140 } 141 142 public void setTextAreaText(String s) { 143 textArea.setText(s); 144 } 145 146 public String getSmallText() { 147 return labelSmall.getText(); 148 } 149 150 public void setSmallText(String v) { 151 labelSmall.setText(v); 152 } 153 154 protected void processWindowEvent(WindowEvent e) { 157 if (e.getID() == WindowEvent.WINDOW_CLOSING) { 158 closeDialog(); 159 } 160 super.processWindowEvent(e); 161 } 162 163 protected void disposeDialog() { 164 setVisible(false); 165 removeAll(); 166 dispose(); 167 } 168 169 private void closeDialog() { 172 disposeDialog(); 173 if (standalone) { 174 System.exit(0); 175 } 176 } 177 178 private void pmInit() { 179 actionListener = new LocalActionListener(); 180 buttonOK.addActionListener(actionListener); 181 buttonInfo.addActionListener(actionListener); 182 } 183 184 private void jbInit() throws Exception { 185 panelMain = (JPanel ) Beans.instantiate(getClass().getClassLoader(), 186 JPanel .class.getName()); 187 panelLabel = (JPanel ) Beans.instantiate(getClass().getClassLoader(), 188 JPanel .class.getName()); 189 panelButton = (JPanel ) Beans.instantiate(getClass().getClassLoader(), 190 JPanel .class.getName()); 191 labelTitle = (JLabel ) Beans.instantiate(getClass().getClassLoader(), 192 JLabel .class.getName()); 193 textArea = (JTextArea ) Beans.instantiate(getClass().getClassLoader(), 194 JTextArea .class.getName()); 195 labelSmall = (JLabel ) Beans.instantiate(getClass().getClassLoader(), 196 JLabel .class.getName()); 197 buttonOK = (JButton ) Beans.instantiate(getClass().getClassLoader(), 198 JButton .class.getName()); 199 buttonInfo = (JButton ) Beans.instantiate(getClass().getClassLoader(), 200 JButton .class.getName()); 201 layoutMain = 202 (GridBagLayout ) Beans.instantiate(getClass().getClassLoader(), 203 GridBagLayout .class.getName()); 204 layoutButton = 205 (GridBagLayout ) Beans.instantiate(getClass().getClassLoader(), 206 GridBagLayout .class.getName()); 207 layoutLabel = 208 (GridBagLayout ) Beans.instantiate(getClass().getClassLoader(), 209 GridBagLayout .class.getName()); 210 buttonOK.setText("OK"); 211 buttonOK.setMaximumSize(new Dimension (100, 30)); 212 buttonOK.setMinimumSize(new Dimension (60, 15)); 213 buttonOK.setPreferredSize(new Dimension (75, 20)); 214 buttonOK.setMargin(new Insets (2, 12, 2, 12)); 215 buttonOK.setMnemonic('0'); 216 buttonInfo.setText("Info"); 217 buttonInfo.setMaximumSize(new Dimension (100, 30)); 218 buttonInfo.setMinimumSize(new Dimension (60, 15)); 219 buttonInfo.setPreferredSize(new Dimension (75, 20)); 220 buttonInfo.setMargin(new Insets (2, 12, 2, 12)); 221 buttonInfo.setMnemonic('I'); 222 panelLabel.setLayout(layoutLabel); 223 labelTitle.setBackground(SystemColor.controlLtHighlight); 224 labelTitle.setFont(new java.awt.Font ("Dialog", 3, 18)); 225 labelTitle.setForeground(SystemColor.infoText); 226 labelTitle.setToolTipText(""); 227 labelTitle.setText("Primary"); 228 textArea.setFont(new java.awt.Font ("Dialog", 0, 16)); 229 textArea.setDisabledTextColor(SystemColor.infoText); 230 textArea.setBackground(SystemColor.controlLtHighlight); 231 textArea.setEnabled(false); 232 textArea.setText("Text Area"); 233 textArea.setForeground(SystemColor.infoText); 234 textArea.setEditable(false); 235 labelSmall.setBackground(SystemColor.controlLtHighlight); 236 labelSmall.setForeground(SystemColor.infoText); 237 labelSmall.setMaximumSize(new Dimension (200, 17)); 238 labelSmall.setText("Version"); 239 panelLabel.setBackground(SystemColor.controlLtHighlight); 240 panelLabel.setBorder(BorderFactory.createLoweredBevelBorder()); 241 panelLabel.add(labelTitle, 242 new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0, 243 GridBagConstraints.CENTER, 244 GridBagConstraints.BOTH, 245 new Insets (10, 10, 5, 10), 40, 246 0)); 247 panelLabel.add(textArea, 248 new GridBagConstraints (0, 1, 1, 1, 0.5, 0.5, 249 GridBagConstraints.CENTER, 250 GridBagConstraints.BOTH, 251 new Insets (5, 10, 5, 10), 40, 252 0)); 253 panelLabel.add(labelSmall, 254 new GridBagConstraints (0, 2, 1, 1, 0.0, 0.0, 255 GridBagConstraints.WEST, 256 GridBagConstraints.HORIZONTAL, 257 new Insets (5, 10, 10, 10), 40, 258 0)); 259 panelButton.setLayout(layoutButton); 260 panelButton.add(buttonOK, 261 new GridBagConstraints (0, 0, 1, 1, 0.5, 0.5, 262 GridBagConstraints.CENTER, 263 GridBagConstraints.NONE, 264 new Insets (5, 0, 10, 0), 0, 265 11)); 266 panelButton.add(buttonInfo, 267 new GridBagConstraints (1, 0, 1, 1, 0.5, 0.5, 268 GridBagConstraints.CENTER, 269 GridBagConstraints.NONE, 270 new Insets (5, 0, 10, 0), 0, 271 11)); 272 panelMain.setLayout(layoutMain); 273 panelMain.setMaximumSize(new Dimension (500, 400)); 274 panelMain.setMinimumSize(new Dimension (300, 150)); 275 panelMain.setPreferredSize(new Dimension (450, 250)); 276 panelMain.add(panelLabel, 277 new GridBagConstraints (0, 1, 1, 1, 0.1, 0.1, 278 GridBagConstraints.CENTER, 279 GridBagConstraints.BOTH, 280 new Insets (0, 0, 0, 0), 0, 0)); 281 panelMain.add(panelButton, 282 new GridBagConstraints (0, 2, 1, 1, 0.1, 0.1, 283 GridBagConstraints.CENTER, 284 GridBagConstraints.BOTH, 285 new Insets (0, 0, 0, 0), 0, 0)); 286 this.getContentPane().add(panelMain); 287 } 288 289 class LocalActionListener implements ActionListener { 290 public void actionPerformed(ActionEvent event) { 291 Object source = event.getSource(); 292 293 if (source == buttonOK) { 294 closeDialog(); 295 } else if (source == buttonInfo) { 296 JDialog info = new JDialog (); 297 298 info.getContentPane().setLayout(new BorderLayout ()); 299 info.getContentPane().add(new InfoPanel(), 300 BorderLayout.CENTER); 301 info.pack(); 302 info.setTitle("System Information"); 303 info.show(); 304 } 305 } 306 307 } 308 } 309 | Popular Tags |