1 19 package org.openharmonise.him.authentication.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Container ; 25 import java.awt.Dialog ; 26 import java.awt.Dimension ; 27 import java.awt.Font ; 28 import java.awt.Frame ; 29 import java.awt.GraphicsConfiguration ; 30 import java.awt.HeadlessException ; 31 import java.awt.LayoutManager ; 32 import java.awt.event.ActionEvent ; 33 import java.awt.event.ActionListener ; 34 import java.awt.event.KeyEvent ; 35 import java.awt.event.KeyListener ; 36 37 import javax.swing.BorderFactory ; 38 import javax.swing.ImageIcon ; 39 import javax.swing.JButton ; 40 import javax.swing.JDialog ; 41 import javax.swing.JFrame ; 42 import javax.swing.JLabel ; 43 import javax.swing.JPanel ; 44 import javax.swing.border.LineBorder ; 45 import javax.swing.border.TitledBorder ; 46 47 import org.openharmonise.vfs.gui.*; 48 49 50 57 public class LoginDialog extends JDialog implements KeyListener , LayoutManager , ActionListener { 58 59 62 private JLabel m_logo = null; 63 64 67 private JLabel m_logoBuildings = null; 68 69 72 private JLabel m_logoPeople = null; 73 74 77 private JLabel m_logoFiles = null; 78 79 82 private LoginUsernamePasswordPanel m_entryPanel = null; 83 84 87 private JButton m_okButton = null; 88 89 92 private JButton m_cancelButton = null; 93 94 97 private JButton m_passwordButton = null; 98 99 102 private boolean m_bChangePassword = false; 103 104 107 private JLabel m_Message = null; 108 109 112 private JPanel m_mainPanel = null; 113 114 120 public LoginDialog(Frame frame) throws HeadlessException { 121 super(frame, true); 122 this.setup(); 123 } 124 125 129 private void setup() { 130 131 this.setResizable(false); 132 133 m_mainPanel = new JPanel (); 134 m_mainPanel.setLayout(this); 135 this.getContentPane().setLayout(new BorderLayout ()); 136 this.getContentPane().add(m_mainPanel); 137 138 this.setTitle("Harmonise Information Manager"); 139 this.setSize(500,300); 140 m_mainPanel.setBackground(new Color (224,224,224)); 141 142 int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2; 143 int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2; 144 145 this.setLocation(x, y); 146 147 m_logo = new JLabel (); 148 m_logo.setToolTipText("Connecting people and information to create knowledge"); 149 m_logo.setIcon( IconManager.getInstance().getIcon("login-sim-logo.png") ); 150 m_mainPanel.add(m_logo); 151 152 m_logoBuildings = new JLabel (); 153 m_logoBuildings.setToolTipText("Conecting organisations"); 154 m_logoBuildings.setIcon( IconManager.getInstance().getIcon("login-sim-buildings.png") ); 155 m_mainPanel.add(m_logoBuildings); 156 157 m_logoPeople = new JLabel (); 158 m_logoPeople.setToolTipText("Conecting people"); 159 m_logoPeople.setIcon( IconManager.getInstance().getIcon("login-sim-people.png") ); 160 m_mainPanel.add(m_logoPeople); 161 162 m_logoFiles = new JLabel (); 163 m_logoFiles.setToolTipText("Conecting information"); 164 m_logoFiles.setIcon( IconManager.getInstance().getIcon("login-sim-files.png") ); 165 m_mainPanel.add(m_logoFiles); 166 167 m_entryPanel = new LoginUsernamePasswordPanel(this); 168 String fontName = "Dialog"; 169 int fontSize = 11; 170 Font font = new Font (fontName, Font.PLAIN, fontSize); 171 m_entryPanel.setBackground(new Color (224,224,224)); 172 173 LineBorder lineBorder = (LineBorder ) BorderFactory.createLineBorder(Color.BLACK); 174 TitledBorder border = BorderFactory.createTitledBorder(lineBorder, 175 "Enter your log in details", 176 TitledBorder.DEFAULT_JUSTIFICATION, 177 TitledBorder.DEFAULT_POSITION, 178 font, 179 Color.BLACK); 180 181 m_entryPanel.setBorder( border ); 182 m_mainPanel.add(m_entryPanel); 183 184 m_okButton = new JButton ("OK"); 185 m_okButton.setActionCommand("OK"); 186 m_okButton.setFont(font); 187 m_okButton.addActionListener(this); 188 m_mainPanel.add(m_okButton); 189 190 m_cancelButton = new JButton ("Cancel"); 191 m_cancelButton.setActionCommand("CANCEL"); 192 m_cancelButton.setFont(font); 193 m_cancelButton.addActionListener(this); 194 m_mainPanel.add(m_cancelButton); 195 196 m_passwordButton = new JButton ("Change Password..."); 197 m_passwordButton.setActionCommand("PASSWORD"); 198 m_passwordButton.setFont(font); 199 m_passwordButton.addActionListener(this); 200 m_mainPanel.add(m_passwordButton); 201 } 202 203 public static void main(String [] args) { 204 JFrame tempFrame = new JFrame (); 205 tempFrame.setIconImage( ((ImageIcon )IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 206 LoginDialog login = new LoginDialog(tempFrame); 207 login.show(); 208 } 209 210 215 public void setMessage(String sMessage) { 216 this.m_Message = new JLabel (sMessage); 217 this.m_mainPanel.add(m_Message); 218 this.setSize( this.getSize().width, this.getSize().height+20 ); 219 } 220 221 222 226 private LoginDialog(Dialog arg0) throws HeadlessException { 227 super(arg0); 228 } 229 230 235 private LoginDialog(Dialog arg0, boolean arg1) throws HeadlessException { 236 super(arg0, arg1); 237 } 238 239 243 private LoginDialog() throws HeadlessException { 244 super(); 245 } 246 247 252 private LoginDialog(Frame arg0, boolean arg1) throws HeadlessException { 253 super(arg0, arg1); 254 } 255 256 261 private LoginDialog(Dialog arg0, String arg1) throws HeadlessException { 262 super(arg0, arg1); 263 } 264 265 271 private LoginDialog(Dialog arg0, String arg1, boolean arg2) 272 throws HeadlessException { 273 super(arg0, arg1, arg2); 274 } 275 276 281 private LoginDialog(Frame arg0, String arg1) throws HeadlessException { 282 super(arg0, arg1); 283 } 284 285 291 private LoginDialog(Frame arg0, String arg1, boolean arg2) 292 throws HeadlessException { 293 super(arg0, arg1, arg2); 294 } 295 296 303 private LoginDialog( 304 Dialog arg0, 305 String arg1, 306 boolean arg2, 307 GraphicsConfiguration arg3) 308 throws HeadlessException { 309 super(arg0, arg1, arg2, arg3); 310 } 311 312 318 private LoginDialog( 319 Frame arg0, 320 String arg1, 321 boolean arg2, 322 GraphicsConfiguration arg3) { 323 super(arg0, arg1, arg2, arg3); 324 } 325 326 329 public void removeLayoutComponent(Component arg0) { 330 331 } 332 333 336 public void layoutContainer(Container arg0) { 337 int nHeight = 10; 338 339 m_logo.setLocation(10,nHeight); 340 m_logo.setSize(new Dimension (200,50)); 341 342 m_logoBuildings.setLocation(320,nHeight); 343 m_logoBuildings.setSize(new Dimension (50,50)); 344 345 m_logoPeople.setLocation(375,nHeight); 346 m_logoPeople.setSize(new Dimension (50,50)); 347 348 m_logoFiles.setLocation(430,nHeight); 349 m_logoFiles.setSize(new Dimension (50,50)); 350 351 nHeight = nHeight + 60; 352 353 if(this.m_Message!=null) { 354 this.m_Message.setLocation(10, nHeight); 355 this.m_Message.setSize(this.m_Message.getPreferredSize()); 356 nHeight = nHeight + 20; 357 } 358 359 m_entryPanel.setLocation(10, nHeight); 360 m_entryPanel.setSize(new Dimension (470, 150)); 361 362 nHeight = nHeight + 170; 363 364 m_okButton.setLocation(180, nHeight); 365 m_okButton.setSize(70,20); 366 367 m_cancelButton.setLocation(260, nHeight); 368 m_cancelButton.setSize(70,20); 369 370 m_passwordButton.setLocation(340, nHeight); 371 m_passwordButton.setSize(140,20); 372 } 373 374 379 public String getUsername() { 380 return this.m_entryPanel.getUsername(); 381 } 382 383 388 public void setUsername(String sUsername) { 389 this.m_entryPanel.setUsername(sUsername); 390 } 391 392 397 public String getPassword() { 398 return this.m_entryPanel.getPassword(); 399 } 400 401 406 public void setPassword(String sPassword) { 407 this.m_entryPanel.setPassword(sPassword); 408 } 409 410 413 public void addLayoutComponent(String arg0, Component arg1) { 414 415 } 416 417 420 public Dimension minimumLayoutSize(Container arg0) { 421 return new Dimension (500,250); 422 } 423 424 427 public Dimension preferredLayoutSize(Container arg0) { 428 return new Dimension (500,250); 429 } 430 431 public boolean changePassword() { 432 return this.m_bChangePassword; 433 } 434 435 438 public void actionPerformed(ActionEvent ae) { 439 if(ae.getActionCommand().equals("OK")) { 440 this.getOwner().setVisible(false); 442 } else if(ae.getActionCommand().equals("PASSWORD")) { 443 this.getOwner().setVisible(false); 444 this.m_bChangePassword = true; 445 446 } else if(ae.getActionCommand().equals("CANCEL")) { 447 this.setUsername(""); 448 this.setPassword(""); 449 } 450 this.hide(); 451 } 452 453 456 public void keyPressed(KeyEvent ke) { 457 if(ke.getKeyCode()==KeyEvent.VK_ENTER) { 458 this.getOwner().setVisible(false); 460 this.hide(); 461 } 462 } 463 464 467 public void keyReleased(KeyEvent arg0) { 468 } 469 470 473 public void keyTyped(KeyEvent arg0) { 474 } 475 476 } 477 | Popular Tags |