1 19 package org.openharmonise.swing; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dialog ; 25 import java.awt.Dimension ; 26 import java.awt.Font ; 27 import java.awt.Frame ; 28 import java.awt.GraphicsConfiguration ; 29 import java.awt.HeadlessException ; 30 import java.awt.LayoutManager ; 31 import java.awt.event.ActionEvent ; 32 import java.awt.event.ActionListener ; 33 import java.awt.event.KeyEvent ; 34 import java.awt.event.KeyListener ; 35 36 import javax.swing.ImageIcon ; 37 import javax.swing.JButton ; 38 import javax.swing.JDialog ; 39 import javax.swing.JFrame ; 40 import javax.swing.JLabel ; 41 import javax.swing.JTextField ; 42 43 import org.openharmonise.vfs.context.*; 44 import org.openharmonise.vfs.gui.*; 45 46 47 52 public class SingleTextEntryDialog extends JDialog implements KeyListener , LayoutManager , ActionListener , ContextListener { 53 54 private JButton m_okButton = null; 55 private JButton m_cancelButton = null; 56 57 private JTextField m_textfield = null; 58 59 private JLabel m_label = null; 60 61 64 private void setup() { 65 ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this); 66 67 this.setResizable(false); 68 69 this.getContentPane().setLayout(this); 70 71 this.setSize(300,100); 72 int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2; 73 int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2; 74 75 this.setLocation(x, y); 76 77 this.m_textfield = new JTextField (); 78 this.m_textfield.addKeyListener(this); 79 this.getContentPane().add(this.m_textfield); 80 81 String fontName = "Dialog"; 82 int fontSize = 11; 83 Font font = new Font (fontName, Font.PLAIN, fontSize); 84 this.getContentPane().setBackground(new Color (224,224,224)); 85 86 m_okButton = new JButton ("OK"); 87 m_okButton.setActionCommand("OK"); 88 m_okButton.setFont(font); 89 m_okButton.addActionListener(this); 90 this.getContentPane().add(m_okButton); 91 92 m_cancelButton = new JButton ("Cancel"); 93 m_cancelButton.setActionCommand("CANCEL"); 94 m_cancelButton.setFont(font); 95 m_cancelButton.addActionListener(this); 96 this.getContentPane().add(m_cancelButton); 97 } 98 99 public void setLabelText(String sLabel) { 100 String fontName = "Dialog"; 101 int fontSize = 11; 102 Font font = new Font (fontName, Font.PLAIN, fontSize); 103 104 this.m_label = new JLabel (sLabel); 105 this.m_label.setFont(font); 106 this.getContentPane().add(this.m_label); 107 this.setSize(300,120); 108 } 109 110 public void setLabelColor(Color color) { 111 if(this.m_label!=null) { 112 this.m_label.setForeground(color); 113 } 114 } 115 116 public static void main(String [] args) { 117 118 JFrame frame = new JFrame (); 119 frame.setIconImage( ((ImageIcon )IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 120 121 SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame, "Rename"); 122 dialog.show(); 123 124 dialog = new SingleTextEntryDialog(frame, "Warning"); 125 dialog.setLabelText("Some label text sd fsd ds fsd fs dfds dsfs dfs fds dfsd fds fsd sd sd ."); 126 dialog.show(); 127 } 128 129 133 private SingleTextEntryDialog(Frame arg0) throws HeadlessException { 134 super(arg0, true); 135 } 136 137 140 private SingleTextEntryDialog() throws HeadlessException { 141 super(); 142 } 143 144 148 private SingleTextEntryDialog(Dialog arg0) throws HeadlessException { 149 super(arg0); 150 } 151 152 157 private SingleTextEntryDialog(Dialog arg0, boolean arg1) 158 throws HeadlessException { 159 super(arg0, arg1); 160 } 161 162 167 private SingleTextEntryDialog(Frame arg0, boolean arg1) 168 throws HeadlessException { 169 super(arg0, arg1); 170 } 171 172 177 private SingleTextEntryDialog(Dialog arg0, String arg1) 178 throws HeadlessException { 179 super(arg0, arg1); 180 } 181 182 188 private SingleTextEntryDialog(Dialog arg0, String arg1, boolean arg2) 189 throws HeadlessException { 190 super(arg0, arg1, arg2); 191 } 192 193 198 public SingleTextEntryDialog(Frame arg0, String arg1) 199 throws HeadlessException { 200 super(arg0, arg1, true); 201 this.setup(); 202 } 203 204 210 private SingleTextEntryDialog(Frame arg0, String arg1, boolean arg2) 211 throws HeadlessException { 212 super(arg0, arg1, arg2); 213 } 214 215 222 private SingleTextEntryDialog( 223 Dialog arg0, 224 String arg1, 225 boolean arg2, 226 GraphicsConfiguration arg3) 227 throws HeadlessException { 228 super(arg0, arg1, arg2, arg3); 229 } 230 231 237 private SingleTextEntryDialog( 238 Frame arg0, 239 String arg1, 240 boolean arg2, 241 GraphicsConfiguration arg3) { 242 super(arg0, arg1, arg2, arg3); 243 } 244 245 248 public void removeLayoutComponent(Component arg0) { 249 250 } 251 252 255 public void layoutContainer(Container arg0) { 256 int nHeight = 10; 257 258 if(this.m_label!=null) { 259 this.m_label.setLocation(10, nHeight); 260 this.m_label.setSize(280,20); 261 nHeight = nHeight+20; 262 } 263 264 m_textfield.setLocation(10, nHeight); 265 m_textfield.setSize(280,20); 266 nHeight = nHeight+30; 267 268 m_okButton.setLocation(130, nHeight); 269 m_okButton.setSize(70,20); 270 271 m_cancelButton.setLocation(210, nHeight); 272 m_cancelButton.setSize(70,20); 273 } 274 275 278 public void addLayoutComponent(String arg0, Component arg1) { 279 280 } 281 282 285 public Dimension minimumLayoutSize(Container arg0) { 286 return this.getSize(); 287 } 288 289 292 public Dimension preferredLayoutSize(Container arg0) { 293 return this.getSize(); 294 } 295 296 299 public void actionPerformed(ActionEvent ae) { 300 if(ae.getActionCommand().equals("OK")) { 301 } else if(ae.getActionCommand().equals("CANCEL")) { 303 this.setTextValue(""); 304 } 305 ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this); 306 this.hide(); 307 } 308 309 312 public void setTextValue(String string) { 313 this.m_textfield.setText(string); 314 } 315 316 public String getTextValue() { 317 return this.m_textfield.getText().trim(); 318 } 319 320 323 public void keyPressed(KeyEvent ke) { 324 if(ke.getKeyCode()==KeyEvent.VK_ENTER) { 325 this.hide(); 326 } 327 } 328 329 332 public void keyReleased(KeyEvent arg0) { 333 } 334 335 338 public void keyTyped(KeyEvent arg0) { 339 } 340 341 344 public void contextMessage(ContextEvent ce) { 345 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) { 346 this.toFront(); 347 } 348 } 349 350 } 351 | Popular Tags |