KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > echo2example > email > LoginScreen


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package echo2example.email;
31
32 import nextapp.echo2.app.Button;
33 import nextapp.echo2.app.Column;
34 import nextapp.echo2.app.ContentPane;
35 import nextapp.echo2.app.Extent;
36 import nextapp.echo2.app.Grid;
37 import nextapp.echo2.app.Label;
38 import nextapp.echo2.app.PasswordField;
39 import nextapp.echo2.app.Row;
40 import nextapp.echo2.app.SplitPane;
41 import nextapp.echo2.app.TextField;
42 import nextapp.echo2.app.WindowPane;
43 import nextapp.echo2.app.event.ActionEvent;
44 import nextapp.echo2.app.event.ActionListener;
45
46 /**
47  * Login screen <code>ContentPane</code>.
48  */

49 public class LoginScreen extends ContentPane {
50
51     private static final Extent PX_300 = new Extent(300, Extent.PX);
52
53     private TextField emailAddressField;
54     private PasswordField passwordField;
55     
56     /**
57      * Creates a new <code>LoginScreen</code>.
58      */

59     public LoginScreen() {
60         super();
61         setStyleName("LoginScreen.ContentPane");
62         
63         Label label;
64
65         Column column = new Column();
66         column.setStyleName("LoginScreen.Column");
67         add(column);
68         
69         label = new Label(Styles.NEXTAPP_LOG_IMAGE);
70         column.add(label);
71         
72         label = new Label(Styles.ECHO2_IMAGE);
73         column.add(label);
74         
75         label = new Label(Styles.WEBMAIL_EXAMPLE_IMAGE);
76         column.add(label);
77         
78         WindowPane loginWindow = new WindowPane();
79         loginWindow.setTitle(Messages.getString("LoginScreen.LoginWindowTitle"));
80         loginWindow.setStyleName("LoginScreen.LoginWindow");
81         loginWindow.setDefaultCloseOperation(WindowPane.DO_NOTHING_ON_CLOSE);
82         add(loginWindow);
83         
84         SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
85         loginWindow.add(splitPane);
86         
87         Row controlRow = new Row();
88         controlRow.setStyleName("ControlPane");
89         splitPane.add(controlRow);
90         
91         Button button = new Button(Messages.getString("LoginScreen.Continue"), Styles.ICON_24_YES);
92         button.setStyleName("ControlPane.Button");
93         button.addActionListener(new ActionListener() {
94             public void actionPerformed(ActionEvent e) {
95                 processLogin();
96             }
97         });
98         controlRow.add(button);
99
100         Grid layoutGrid = new Grid();
101         layoutGrid.setStyleName("LoginScreen.LayoutGrid");
102         splitPane.add(layoutGrid);
103
104         label = new Label(Messages.getString("LoginScreen.PromptEmailAddress"));
105         label.setStyleName("LoginScreen.Prompt");
106         layoutGrid.add(label);
107
108         emailAddressField = new TextField();
109         emailAddressField.setWidth(PX_300);
110         emailAddressField.setStyleName("Default");
111         emailAddressField.addActionListener(new ActionListener() {
112             public void actionPerformed(ActionEvent e) {
113                 EmailApp.getActive().setFocusedComponent(passwordField);
114             }
115         });
116         layoutGrid.add(emailAddressField);
117         
118         label = new Label(Messages.getString("LoginScreen.PromptPassword"));
119         label.setStyleName("LoginScreen.Prompt");
120         layoutGrid.add(label);
121         
122         passwordField = new PasswordField();
123         passwordField.setWidth(PX_300);
124         passwordField.setStyleName("Default");
125         layoutGrid.add(passwordField);
126         passwordField.addActionListener(new ActionListener() {
127             public void actionPerformed(ActionEvent e) {
128                 processLogin();
129             }
130         });
131         
132         if (EmailApp.FAUX_MODE) {
133             emailAddressField.setText("joe.smith@test.nextapp.com");
134             passwordField.setText("Joshua");
135         }
136         
137         EmailApp.getActive().setFocusedComponent(emailAddressField);
138     }
139     
140     /**
141      * Processes a user log-in request.
142      */

143     private void processLogin() {
144         if (!EmailApp.getApp().connect(emailAddressField.getText(), passwordField.getText())) {
145             MessageDialog messageDialog = new MessageDialog(Messages.getString("LoginScreen.InvalidLogin.Title"),
146                     Messages.getString("LoginScreen.InvalidLogin.Message"), MessageDialog.TYPE_ERROR, MessageDialog.CONTROLS_OK);
147             getApplicationInstance().getDefaultWindow().getContent().add(messageDialog);
148         }
149     }
150 }
Popular Tags