001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.authentication.gui;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Color;
023: import java.awt.Component;
024: import java.awt.Container;
025: import java.awt.Dialog;
026: import java.awt.Dimension;
027: import java.awt.Font;
028: import java.awt.Frame;
029: import java.awt.GraphicsConfiguration;
030: import java.awt.HeadlessException;
031: import java.awt.LayoutManager;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.awt.event.KeyEvent;
035: import java.awt.event.KeyListener;
036:
037: import javax.swing.BorderFactory;
038: import javax.swing.ImageIcon;
039: import javax.swing.JButton;
040: import javax.swing.JDialog;
041: import javax.swing.JFrame;
042: import javax.swing.JLabel;
043: import javax.swing.JPanel;
044: import javax.swing.border.LineBorder;
045: import javax.swing.border.TitledBorder;
046:
047: import org.openharmonise.vfs.gui.*;
048:
049: /**
050: * Dialog to collect login information from the user.
051: *
052: * @author Matthew Large
053: * @version $Revision: 1.1 $
054: *
055: */
056: public class LoginDialog extends JDialog implements KeyListener,
057: LayoutManager, ActionListener {
058:
059: /**
060: * Simulacra logo.
061: */
062: private JLabel m_logo = null;
063:
064: /**
065: * Simulacra buildings coporate image.
066: */
067: private JLabel m_logoBuildings = null;
068:
069: /**
070: * Simulacra people coporate image.
071: */
072: private JLabel m_logoPeople = null;
073:
074: /**
075: * Simulacra files coporate image.
076: */
077: private JLabel m_logoFiles = null;
078:
079: /**
080: * Username/password entry panel.
081: */
082: private LoginUsernamePasswordPanel m_entryPanel = null;
083:
084: /**
085: * OK button.
086: */
087: private JButton m_okButton = null;
088:
089: /**
090: * Cancel button.
091: */
092: private JButton m_cancelButton = null;
093:
094: /**
095: * Change password button.
096: */
097: private JButton m_passwordButton = null;
098:
099: /**
100: * true if the change password button was pressed.
101: */
102: private boolean m_bChangePassword = false;
103:
104: /**
105: * Label for message to appear on the dialog.
106: */
107: private JLabel m_Message = null;
108:
109: /**
110: * Main panel.
111: */
112: private JPanel m_mainPanel = null;
113:
114: /**
115: * Constructs a new login dialog.
116: *
117: * @param frame Owning frame
118: * @throws HeadlessException
119: */
120: public LoginDialog(Frame frame) throws HeadlessException {
121: super (frame, true);
122: this .setup();
123: }
124:
125: /**
126: * Configures this login dialog.
127: *
128: */
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
143: - this .getSize().width / 2;
144: int y = this .getGraphicsConfiguration().getBounds().height / 2
145: - this .getSize().height / 2;
146:
147: this .setLocation(x, y);
148:
149: m_logo = new JLabel();
150: m_logo
151: .setToolTipText("Connecting people and information to create knowledge");
152: m_logo.setIcon(IconManager.getInstance().getIcon(
153: "login-sim-logo.png"));
154: m_mainPanel.add(m_logo);
155:
156: m_logoBuildings = new JLabel();
157: m_logoBuildings.setToolTipText("Conecting organisations");
158: m_logoBuildings.setIcon(IconManager.getInstance().getIcon(
159: "login-sim-buildings.png"));
160: m_mainPanel.add(m_logoBuildings);
161:
162: m_logoPeople = new JLabel();
163: m_logoPeople.setToolTipText("Conecting people");
164: m_logoPeople.setIcon(IconManager.getInstance().getIcon(
165: "login-sim-people.png"));
166: m_mainPanel.add(m_logoPeople);
167:
168: m_logoFiles = new JLabel();
169: m_logoFiles.setToolTipText("Conecting information");
170: m_logoFiles.setIcon(IconManager.getInstance().getIcon(
171: "login-sim-files.png"));
172: m_mainPanel.add(m_logoFiles);
173:
174: m_entryPanel = new LoginUsernamePasswordPanel(this );
175: String fontName = "Dialog";
176: int fontSize = 11;
177: Font font = new Font(fontName, Font.PLAIN, fontSize);
178: m_entryPanel.setBackground(new Color(224, 224, 224));
179:
180: LineBorder lineBorder = (LineBorder) BorderFactory
181: .createLineBorder(Color.BLACK);
182: TitledBorder border = BorderFactory.createTitledBorder(
183: lineBorder, "Enter your log in details",
184: TitledBorder.DEFAULT_JUSTIFICATION,
185: TitledBorder.DEFAULT_POSITION, font, Color.BLACK);
186:
187: m_entryPanel.setBorder(border);
188: m_mainPanel.add(m_entryPanel);
189:
190: m_okButton = new JButton("OK");
191: m_okButton.setActionCommand("OK");
192: m_okButton.setFont(font);
193: m_okButton.addActionListener(this );
194: m_mainPanel.add(m_okButton);
195:
196: m_cancelButton = new JButton("Cancel");
197: m_cancelButton.setActionCommand("CANCEL");
198: m_cancelButton.setFont(font);
199: m_cancelButton.addActionListener(this );
200: m_mainPanel.add(m_cancelButton);
201:
202: m_passwordButton = new JButton("Change Password...");
203: m_passwordButton.setActionCommand("PASSWORD");
204: m_passwordButton.setFont(font);
205: m_passwordButton.addActionListener(this );
206: m_mainPanel.add(m_passwordButton);
207: }
208:
209: public static void main(String[] args) {
210: JFrame tempFrame = new JFrame();
211: tempFrame.setIconImage(((ImageIcon) IconManager.getInstance()
212: .getIcon("32-sim-logo.gif")).getImage());
213: LoginDialog login = new LoginDialog(tempFrame);
214: login.show();
215: }
216:
217: /**
218: * Sets the message text to appear on this dialog.
219: *
220: * @param sMessage Message text
221: */
222: public void setMessage(String sMessage) {
223: this .m_Message = new JLabel(sMessage);
224: this .m_mainPanel.add(m_Message);
225: this .setSize(this .getSize().width, this .getSize().height + 20);
226: }
227:
228: /**
229: * @param arg0
230: * @throws java.awt.HeadlessException
231: */
232: private LoginDialog(Dialog arg0) throws HeadlessException {
233: super (arg0);
234: }
235:
236: /**
237: * @param arg0
238: * @param arg1
239: * @throws java.awt.HeadlessException
240: */
241: private LoginDialog(Dialog arg0, boolean arg1)
242: throws HeadlessException {
243: super (arg0, arg1);
244: }
245:
246: /**
247: * @param arg0
248: * @throws java.awt.HeadlessException
249: */
250: private LoginDialog() throws HeadlessException {
251: super ();
252: }
253:
254: /**
255: * @param arg0
256: * @param arg1
257: * @throws java.awt.HeadlessException
258: */
259: private LoginDialog(Frame arg0, boolean arg1)
260: throws HeadlessException {
261: super (arg0, arg1);
262: }
263:
264: /**
265: * @param arg0
266: * @param arg1
267: * @throws java.awt.HeadlessException
268: */
269: private LoginDialog(Dialog arg0, String arg1)
270: throws HeadlessException {
271: super (arg0, arg1);
272: }
273:
274: /**
275: * @param arg0
276: * @param arg1
277: * @param arg2
278: * @throws java.awt.HeadlessException
279: */
280: private LoginDialog(Dialog arg0, String arg1, boolean arg2)
281: throws HeadlessException {
282: super (arg0, arg1, arg2);
283: }
284:
285: /**
286: * @param arg0
287: * @param arg1
288: * @throws java.awt.HeadlessException
289: */
290: private LoginDialog(Frame arg0, String arg1)
291: throws HeadlessException {
292: super (arg0, arg1);
293: }
294:
295: /**
296: * @param arg0
297: * @param arg1
298: * @param arg2
299: * @throws java.awt.HeadlessException
300: */
301: private LoginDialog(Frame arg0, String arg1, boolean arg2)
302: throws HeadlessException {
303: super (arg0, arg1, arg2);
304: }
305:
306: /**
307: * @param arg0
308: * @param arg1
309: * @param arg2
310: * @param arg3
311: * @throws java.awt.HeadlessException
312: */
313: private LoginDialog(Dialog arg0, String arg1, boolean arg2,
314: GraphicsConfiguration arg3) throws HeadlessException {
315: super (arg0, arg1, arg2, arg3);
316: }
317:
318: /**
319: * @param arg0
320: * @param arg1
321: * @param arg2
322: * @param arg3
323: */
324: private LoginDialog(Frame arg0, String arg1, boolean arg2,
325: GraphicsConfiguration arg3) {
326: super (arg0, arg1, arg2, arg3);
327: }
328:
329: /* (non-Javadoc)
330: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
331: */
332: public void removeLayoutComponent(Component arg0) {
333:
334: }
335:
336: /* (non-Javadoc)
337: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
338: */
339: public void layoutContainer(Container arg0) {
340: int nHeight = 10;
341:
342: m_logo.setLocation(10, nHeight);
343: m_logo.setSize(new Dimension(200, 50));
344:
345: m_logoBuildings.setLocation(320, nHeight);
346: m_logoBuildings.setSize(new Dimension(50, 50));
347:
348: m_logoPeople.setLocation(375, nHeight);
349: m_logoPeople.setSize(new Dimension(50, 50));
350:
351: m_logoFiles.setLocation(430, nHeight);
352: m_logoFiles.setSize(new Dimension(50, 50));
353:
354: nHeight = nHeight + 60;
355:
356: if (this .m_Message != null) {
357: this .m_Message.setLocation(10, nHeight);
358: this .m_Message.setSize(this .m_Message.getPreferredSize());
359: nHeight = nHeight + 20;
360: }
361:
362: m_entryPanel.setLocation(10, nHeight);
363: m_entryPanel.setSize(new Dimension(470, 150));
364:
365: nHeight = nHeight + 170;
366:
367: m_okButton.setLocation(180, nHeight);
368: m_okButton.setSize(70, 20);
369:
370: m_cancelButton.setLocation(260, nHeight);
371: m_cancelButton.setSize(70, 20);
372:
373: m_passwordButton.setLocation(340, nHeight);
374: m_passwordButton.setSize(140, 20);
375: }
376:
377: /**
378: * Returns the username.
379: *
380: * @return Username
381: */
382: public String getUsername() {
383: return this .m_entryPanel.getUsername();
384: }
385:
386: /**
387: * Sets the username, pre-populates username field.
388: *
389: * @param sUsername Username
390: */
391: public void setUsername(String sUsername) {
392: this .m_entryPanel.setUsername(sUsername);
393: }
394:
395: /**
396: * Returns the password.
397: *
398: * @return Password
399: */
400: public String getPassword() {
401: return this .m_entryPanel.getPassword();
402: }
403:
404: /**
405: * Sets the password, pre-populates the password field.
406: *
407: * @param sPassword Password
408: */
409: public void setPassword(String sPassword) {
410: this .m_entryPanel.setPassword(sPassword);
411: }
412:
413: /* (non-Javadoc)
414: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
415: */
416: public void addLayoutComponent(String arg0, Component arg1) {
417:
418: }
419:
420: /* (non-Javadoc)
421: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
422: */
423: public Dimension minimumLayoutSize(Container arg0) {
424: return new Dimension(500, 250);
425: }
426:
427: /* (non-Javadoc)
428: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
429: */
430: public Dimension preferredLayoutSize(Container arg0) {
431: return new Dimension(500, 250);
432: }
433:
434: public boolean changePassword() {
435: return this .m_bChangePassword;
436: }
437:
438: /* (non-Javadoc)
439: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
440: */
441: public void actionPerformed(ActionEvent ae) {
442: if (ae.getActionCommand().equals("OK")) {
443: // hide frame
444: this .getOwner().setVisible(false);
445: } else if (ae.getActionCommand().equals("PASSWORD")) {
446: this .getOwner().setVisible(false);
447: this .m_bChangePassword = true;
448:
449: } else if (ae.getActionCommand().equals("CANCEL")) {
450: this .setUsername("");
451: this .setPassword("");
452: }
453: this .hide();
454: }
455:
456: /* (non-Javadoc)
457: * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
458: */
459: public void keyPressed(KeyEvent ke) {
460: if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
461: // hide frame
462: this .getOwner().setVisible(false);
463: this .hide();
464: }
465: }
466:
467: /* (non-Javadoc)
468: * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
469: */
470: public void keyReleased(KeyEvent arg0) {
471: }
472:
473: /* (non-Javadoc)
474: * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
475: */
476: public void keyTyped(KeyEvent arg0) {
477: }
478:
479: }
|