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