1 19 package org.openharmonise.swing; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.vfs.context.*; 27 import org.openharmonise.vfs.gui.*; 28 29 35 public class DualTextEntryDialog extends JDialog implements KeyListener, LayoutManager, ActionListener, ContextListener { 36 37 private JButton m_okButton = null; 38 private JButton m_cancelButton = null; 39 40 private JTextField m_textfield1 = null; 41 private JLabel m_caption1 = null; 42 43 private JTextField m_textfield2 = null; 44 private JLabel m_caption2 = null; 45 46 private JLabel m_label = null; 47 48 51 private void setup() { 52 ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this); 53 54 this.setResizable(false); 55 56 this.getContentPane().setLayout(this); 57 58 this.setSize(400,170); 59 int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2; 60 int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2; 61 62 this.setLocation(x, y); 63 64 this.m_textfield1 = new JTextField(); 65 this.m_textfield1.addKeyListener(this); 66 this.getContentPane().add(this.m_textfield1); 67 68 this.m_caption1 = new JLabel(); 69 this.getContentPane().add(this.m_caption1); 70 71 this.m_textfield2 = new JTextField(); 72 this.m_textfield2.addKeyListener(this); 73 this.getContentPane().add(this.m_textfield2); 74 75 this.m_caption2 = new JLabel(); 76 this.getContentPane().add(this.m_caption2); 77 78 String fontName = "Dialog"; 79 int fontSize = 11; 80 Font font = new Font(fontName, Font.PLAIN, fontSize); 81 this.getContentPane().setBackground(new Color(224,224,224)); 82 83 m_okButton = new JButton("OK"); 84 m_okButton.setActionCommand("OK"); 85 m_okButton.setFont(font); 86 m_okButton.addActionListener(this); 87 this.getContentPane().add(m_okButton); 88 89 m_cancelButton = new JButton("Cancel"); 90 m_cancelButton.setActionCommand("CANCEL"); 91 m_cancelButton.setFont(font); 92 m_cancelButton.addActionListener(this); 93 this.getContentPane().add(m_cancelButton); 94 } 95 96 public void setLabelText(String sLabel) { 97 String fontName = "Dialog"; 98 int fontSize = 11; 99 Font font = new Font(fontName, Font.PLAIN, fontSize); 100 101 this.m_label = new JLabel(sLabel); 102 this.m_label.setFont(font); 103 this.getContentPane().add(this.m_label); 104 this.setSize(300,190); 105 } 106 107 public void setLabelColor(Color color) { 108 if(this.m_label!=null) { 109 this.m_label.setForeground(color); 110 } 111 } 112 113 public static void main(String [] args) { 114 115 JFrame frame = new JFrame(); 116 frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 117 118 SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame, "Rename"); 119 dialog.show(); 120 121 dialog = new SingleTextEntryDialog(frame, "Warning"); 122 dialog.setLabelText("Some label text sd fsd ds fsd fs dfds dsfs dfs fds dfsd fds fsd sd sd ."); 123 dialog.show(); 124 } 125 126 130 private DualTextEntryDialog(Frame arg0) throws HeadlessException { 131 super(arg0, true); 132 } 133 134 137 private DualTextEntryDialog() throws HeadlessException { 138 super(); 139 } 140 141 145 private DualTextEntryDialog(Dialog arg0) throws HeadlessException { 146 super(arg0); 147 } 148 149 154 private DualTextEntryDialog(Dialog arg0, boolean arg1) 155 throws HeadlessException { 156 super(arg0, arg1); 157 } 158 159 164 private DualTextEntryDialog(Frame arg0, boolean arg1) 165 throws HeadlessException { 166 super(arg0, arg1); 167 } 168 169 174 private DualTextEntryDialog(Dialog arg0, String arg1) 175 throws HeadlessException { 176 super(arg0, arg1); 177 } 178 179 185 private DualTextEntryDialog(Dialog arg0, String arg1, boolean arg2) 186 throws HeadlessException { 187 super(arg0, arg1, arg2); 188 } 189 190 195 public DualTextEntryDialog(Frame arg0, String arg1) 196 throws HeadlessException { 197 super(arg0, arg1, true); 198 this.setup(); 199 } 200 201 207 private DualTextEntryDialog(Frame arg0, String arg1, boolean arg2) 208 throws HeadlessException { 209 super(arg0, arg1, arg2); 210 } 211 212 219 private DualTextEntryDialog( 220 Dialog arg0, 221 String arg1, 222 boolean arg2, 223 GraphicsConfiguration arg3) 224 throws HeadlessException { 225 super(arg0, arg1, arg2, arg3); 226 } 227 228 234 private DualTextEntryDialog( 235 Frame arg0, 236 String arg1, 237 boolean arg2, 238 GraphicsConfiguration arg3) { 239 super(arg0, arg1, arg2, arg3); 240 } 241 242 245 public void removeLayoutComponent(Component arg0) { 246 247 } 248 249 252 public void layoutContainer(Container arg0) { 253 int nHeight = 10; 254 255 if(this.m_label!=null) { 256 this.m_label.setLocation(10, nHeight); 257 this.m_label.setSize(280,20); 258 nHeight = nHeight+20; 259 } 260 261 m_caption1.setLocation(10, nHeight); 262 m_caption1.setSize(280,20); 263 nHeight = nHeight+20; 264 265 m_textfield1.setLocation(10, nHeight); 266 m_textfield1.setSize(280,20); 267 nHeight = nHeight+20; 268 269 m_caption2.setLocation(10, nHeight); 270 m_caption2.setSize(280,20); 271 nHeight = nHeight+20; 272 273 m_textfield2.setLocation(10, nHeight); 274 m_textfield2.setSize(280,20); 275 nHeight = nHeight+30; 276 277 m_okButton.setLocation(130, nHeight); 278 m_okButton.setSize(70,20); 279 280 m_cancelButton.setLocation(210, nHeight); 281 m_cancelButton.setSize(70,20); 282 } 283 284 287 public void addLayoutComponent(String arg0, Component arg1) { 288 289 } 290 291 294 public Dimension minimumLayoutSize(Container arg0) { 295 return this.getSize(); 296 } 297 298 301 public Dimension preferredLayoutSize(Container arg0) { 302 return this.getSize(); 303 } 304 305 308 public void actionPerformed(ActionEvent ae) { 309 if(ae.getActionCommand().equals("OK")) { 310 } else if(ae.getActionCommand().equals("CANCEL")) { 312 this.setText1Value(""); 313 this.setText2Value(""); 314 } 315 ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this); 316 this.hide(); 317 } 318 319 public void setCaption1(String string) { 320 this.m_caption1.setText(string); 321 } 322 323 public void setCaption2(String string) { 324 this.m_caption2.setText(string); 325 } 326 327 330 public void setText2Value(String string) { 331 this.m_textfield2.setText(string); 332 } 333 334 public String getText2Value() { 335 return this.m_textfield2.getText().trim(); 336 } 337 338 341 public void setText1Value(String string) { 342 this.m_textfield1.setText(string); 343 } 344 345 public String getText1Value() { 346 return this.m_textfield1.getText().trim(); 347 } 348 349 352 public void keyPressed(KeyEvent ke) { 353 if(ke.getKeyCode()==KeyEvent.VK_ENTER) { 354 this.hide(); 355 } 356 } 357 358 361 public void keyReleased(KeyEvent arg0) { 362 } 363 364 367 public void keyTyped(KeyEvent arg0) { 368 } 369 370 373 public void contextMessage(ContextEvent ce) { 374 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) { 375 this.toFront(); 376 } 377 } 378 379 } 380 | Popular Tags |