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.chatclient;
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.Row;
039: import nextapp.echo2.app.SplitPane;
040: import nextapp.echo2.app.TextField;
041: import nextapp.echo2.app.WindowPane;
042: import nextapp.echo2.app.event.ActionEvent;
043: import nextapp.echo2.app.event.ActionListener;
044: import nextapp.echo2.app.layout.GridLayoutData;
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 nameField;
054:
055: /**
056: * Creates a new <code>LoginScreen</code>.
057: */
058: public LoginScreen() {
059: super ();
060: setStyleName("LoginScreen.ContentPane");
061:
062: Label label;
063:
064: Column column = new Column();
065: column.setStyleName("LoginScreen.Column");
066: add(column);
067:
068: label = new Label(Styles.NEXTAPP_LOG_IMAGE);
069: column.add(label);
070:
071: label = new Label(Styles.ECHO2_IMAGE);
072: column.add(label);
073:
074: label = new Label(Styles.CHAT_EXAMPLE_IMAGE);
075: column.add(label);
076:
077: WindowPane loginWindow = new WindowPane();
078: loginWindow.setTitle(Messages
079: .getString("LoginScreen.LoginWindowTitle"));
080: loginWindow.setStyleName("LoginScreen.LoginWindow");
081: loginWindow.setClosable(false);
082: add(loginWindow);
083:
084: SplitPane splitPane = new SplitPane(
085: SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(
086: 32));
087: loginWindow.add(splitPane);
088:
089: Row controlRow = new Row();
090: controlRow.setStyleName("ControlPane");
091: splitPane.add(controlRow);
092:
093: Button button = new Button(Messages
094: .getString("LoginScreen.Continue"), Styles.ICON_24_YES);
095: button.setStyleName("ControlPane.Button");
096: button.addActionListener(new ActionListener() {
097: public void actionPerformed(ActionEvent e) {
098: processLogin();
099: }
100: });
101: controlRow.add(button);
102:
103: Grid layoutGrid = new Grid();
104: layoutGrid.setStyleName("LoginScreen.LayoutGrid");
105: splitPane.add(layoutGrid);
106:
107: Column warningColumn = new Column();
108: GridLayoutData gridLayoutData = new GridLayoutData();
109: gridLayoutData.setColumnSpan(2);
110: warningColumn.setLayoutData(gridLayoutData);
111: layoutGrid.add(warningColumn);
112:
113: label = new Label(Messages
114: .getString("LoginScreen.WarningTitle"));
115: label.setStyleName("LoginScreen.WarningTitle");
116: warningColumn.add(label);
117:
118: label = new Label(Messages
119: .getString("LoginScreen.WarningMessage"));
120: label.setStyleName("LoginScreen.WarningMessage");
121: warningColumn.add(label);
122:
123: label = new Label(Messages
124: .getString("LoginScreen.PromptUserName"));
125: label.setStyleName("LoginScreen.Prompt");
126: layoutGrid.add(label);
127:
128: nameField = new TextField();
129: nameField.setWidth(PX_300);
130: nameField.setStyleName("Default");
131: nameField.addActionListener(new ActionListener() {
132: public void actionPerformed(ActionEvent e) {
133: processLogin();
134: }
135: });
136: layoutGrid.add(nameField);
137:
138: ChatApp.getActive().setFocusedComponent(nameField);
139: }
140:
141: /**
142: * Processes a user log-in request.
143: */
144: private void processLogin() {
145: if (!ChatApp.getApp().connect(nameField.getText())) {
146: MessageDialog messageDialog = new MessageDialog(
147: Messages
148: .getString("LoginScreen.InvalidLogin.Title"),
149: Messages
150: .getString("LoginScreen.InvalidLogin.Message"),
151: MessageDialog.TYPE_ERROR, MessageDialog.CONTROLS_OK);
152: getApplicationInstance().getDefaultWindow().getContent()
153: .add(messageDialog);
154: }
155: }
156: }
|