001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package echo2example.email;
031:
032: import nextapp.echo2.app.Button;
033: import nextapp.echo2.app.Column;
034: import nextapp.echo2.app.ContentPane;
035: import nextapp.echo2.app.Extent;
036: import nextapp.echo2.app.Grid;
037: import nextapp.echo2.app.Label;
038: import nextapp.echo2.app.PasswordField;
039: import nextapp.echo2.app.Row;
040: import nextapp.echo2.app.SplitPane;
041: import nextapp.echo2.app.TextField;
042: import nextapp.echo2.app.WindowPane;
043: import nextapp.echo2.app.event.ActionEvent;
044: import nextapp.echo2.app.event.ActionListener;
045:
046: /**
047: * Login screen <code>ContentPane</code>.
048: */
049: public class LoginScreen extends ContentPane {
050:
051: private static final Extent PX_300 = new Extent(300, Extent.PX);
052:
053: private TextField emailAddressField;
054: private PasswordField passwordField;
055:
056: /**
057: * Creates a new <code>LoginScreen</code>.
058: */
059: public LoginScreen() {
060: super ();
061: setStyleName("LoginScreen.ContentPane");
062:
063: Label label;
064:
065: Column column = new Column();
066: column.setStyleName("LoginScreen.Column");
067: add(column);
068:
069: label = new Label(Styles.NEXTAPP_LOG_IMAGE);
070: column.add(label);
071:
072: label = new Label(Styles.ECHO2_IMAGE);
073: column.add(label);
074:
075: label = new Label(Styles.WEBMAIL_EXAMPLE_IMAGE);
076: column.add(label);
077:
078: WindowPane loginWindow = new WindowPane();
079: loginWindow.setTitle(Messages
080: .getString("LoginScreen.LoginWindowTitle"));
081: loginWindow.setStyleName("LoginScreen.LoginWindow");
082: loginWindow
083: .setDefaultCloseOperation(WindowPane.DO_NOTHING_ON_CLOSE);
084: add(loginWindow);
085:
086: SplitPane splitPane = new SplitPane(
087: SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(
088: 32));
089: loginWindow.add(splitPane);
090:
091: Row controlRow = new Row();
092: controlRow.setStyleName("ControlPane");
093: splitPane.add(controlRow);
094:
095: Button button = new Button(Messages
096: .getString("LoginScreen.Continue"), Styles.ICON_24_YES);
097: button.setStyleName("ControlPane.Button");
098: button.addActionListener(new ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: processLogin();
101: }
102: });
103: controlRow.add(button);
104:
105: Grid layoutGrid = new Grid();
106: layoutGrid.setStyleName("LoginScreen.LayoutGrid");
107: splitPane.add(layoutGrid);
108:
109: label = new Label(Messages
110: .getString("LoginScreen.PromptEmailAddress"));
111: label.setStyleName("LoginScreen.Prompt");
112: layoutGrid.add(label);
113:
114: emailAddressField = new TextField();
115: emailAddressField.setWidth(PX_300);
116: emailAddressField.setStyleName("Default");
117: emailAddressField.addActionListener(new ActionListener() {
118: public void actionPerformed(ActionEvent e) {
119: EmailApp.getActive().setFocusedComponent(passwordField);
120: }
121: });
122: layoutGrid.add(emailAddressField);
123:
124: label = new Label(Messages
125: .getString("LoginScreen.PromptPassword"));
126: label.setStyleName("LoginScreen.Prompt");
127: layoutGrid.add(label);
128:
129: passwordField = new PasswordField();
130: passwordField.setWidth(PX_300);
131: passwordField.setStyleName("Default");
132: layoutGrid.add(passwordField);
133: passwordField.addActionListener(new ActionListener() {
134: public void actionPerformed(ActionEvent e) {
135: processLogin();
136: }
137: });
138:
139: if (EmailApp.FAUX_MODE) {
140: emailAddressField.setText("joe.smith@test.nextapp.com");
141: passwordField.setText("Joshua");
142: }
143:
144: EmailApp.getActive().setFocusedComponent(emailAddressField);
145: }
146:
147: /**
148: * Processes a user log-in request.
149: */
150: private void processLogin() {
151: if (!EmailApp.getApp().connect(emailAddressField.getText(),
152: passwordField.getText())) {
153: MessageDialog messageDialog = new MessageDialog(
154: Messages
155: .getString("LoginScreen.InvalidLogin.Title"),
156: Messages
157: .getString("LoginScreen.InvalidLogin.Message"),
158: MessageDialog.TYPE_ERROR, MessageDialog.CONTROLS_OK);
159: getApplicationInstance().getDefaultWindow().getContent()
160: .add(messageDialog);
161: }
162: }
163: }
|