KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > echo2example > chatclient > 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.chatclient;
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.Row;
39 import nextapp.echo2.app.SplitPane;
40 import nextapp.echo2.app.TextField;
41 import nextapp.echo2.app.WindowPane;
42 import nextapp.echo2.app.event.ActionEvent;
43 import nextapp.echo2.app.event.ActionListener;
44 import nextapp.echo2.app.layout.GridLayoutData;
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 nameField;
54     
55     /**
56      * Creates a new <code>LoginScreen</code>.
57      */

58     public LoginScreen() {
59         super();
60         setStyleName("LoginScreen.ContentPane");
61         
62         Label label;
63
64         Column column = new Column();
65         column.setStyleName("LoginScreen.Column");
66         add(column);
67         
68         label = new Label(Styles.NEXTAPP_LOG_IMAGE);
69         column.add(label);
70         
71         label = new Label(Styles.ECHO2_IMAGE);
72         column.add(label);
73         
74         label = new Label(Styles.CHAT_EXAMPLE_IMAGE);
75         column.add(label);
76         
77         WindowPane loginWindow = new WindowPane();
78         loginWindow.setTitle(Messages.getString("LoginScreen.LoginWindowTitle"));
79         loginWindow.setStyleName("LoginScreen.LoginWindow");
80         loginWindow.setClosable(false);
81         add(loginWindow);
82         
83         SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
84         loginWindow.add(splitPane);
85         
86         Row controlRow = new Row();
87         controlRow.setStyleName("ControlPane");
88         splitPane.add(controlRow);
89         
90         Button button = new Button(Messages.getString("LoginScreen.Continue"), Styles.ICON_24_YES);
91         button.setStyleName("ControlPane.Button");
92         button.addActionListener(new ActionListener() {
93             public void actionPerformed(ActionEvent e) {
94                 processLogin();
95             }
96         });
97         controlRow.add(button);
98
99         Grid layoutGrid = new Grid();
100         layoutGrid.setStyleName("LoginScreen.LayoutGrid");
101         splitPane.add(layoutGrid);
102
103         Column warningColumn = new Column();
104         GridLayoutData gridLayoutData = new GridLayoutData();
105         gridLayoutData.setColumnSpan(2);
106         warningColumn.setLayoutData(gridLayoutData);
107         layoutGrid.add(warningColumn);
108         
109         label = new Label(Messages.getString("LoginScreen.WarningTitle"));
110         label.setStyleName("LoginScreen.WarningTitle");
111         warningColumn.add(label);
112         
113         label = new Label(Messages.getString("LoginScreen.WarningMessage"));
114         label.setStyleName("LoginScreen.WarningMessage");
115         warningColumn.add(label);
116
117         label = new Label(Messages.getString("LoginScreen.PromptUserName"));
118         label.setStyleName("LoginScreen.Prompt");
119         layoutGrid.add(label);
120         
121         nameField = new TextField();
122         nameField.setWidth(PX_300);
123         nameField.setStyleName("Default");
124         nameField.addActionListener(new ActionListener() {
125             public void actionPerformed(ActionEvent e) {
126                 processLogin();
127             }
128         });
129         layoutGrid.add(nameField);
130         
131         ChatApp.getActive().setFocusedComponent(nameField);
132     }
133     
134     /**
135      * Processes a user log-in request.
136      */

137     private void processLogin() {
138         if (!ChatApp.getApp().connect(nameField.getText())) {
139             MessageDialog messageDialog = new MessageDialog(Messages.getString("LoginScreen.InvalidLogin.Title"),
140                     Messages.getString("LoginScreen.InvalidLogin.Message"), MessageDialog.TYPE_ERROR, MessageDialog.CONTROLS_OK);
141             getApplicationInstance().getDefaultWindow().getContent().add(messageDialog);
142         }
143     }
144 }
Popular Tags