summaryrefslogtreecommitdiff
path: root/src/YalpClients/SwtClient/GUI/StartDialog.java
blob: 11ecc7f39c4d9ec7c35d37e5c35129a8eb3d3344 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * Copyright (c) 2006 Manuel Traut and Volker Dahnke
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors: Manuel Traut and Volker Dahnke
 */

package YalpClients.SwtClient.GUI;

import YalpClients.SwtClient.Model;
import YalpInterfaces.AccessRights;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/*
 * Class StartDialog
 *
 * <em></em>
 *
 * @author Volker Dahnke / Manuel Traut
 *
 * @version 1 02-04-2006<br>
 */
public class StartDialog extends Composite {

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}
	private Display display;
	private CLabel cLabel1;
	private CLabel LogoLabel;
	private Model model;
	private Composite parent;
	private Composite composite;
	private CLabel logonLable;
	private Button ok;
	private Text passwd;
	private Text username;
	private CLabel passwdLable;
	private CLabel usernameLable;
	
	
	public StartDialog(Composite parent,Model model, int style) {
		super(parent, style);
		
		this.parent=parent;
        this.model=model;
        this.display=Display.getDefault();
		initStartDialog();
	}
	
	private void initStartDialog(){
		GridLayout thisLayout = new GridLayout();
		thisLayout.makeColumnsEqualWidth = true;
		this.setLayout(thisLayout);
		this.setSize(300,150);
		Listener listener =new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event evt) {
				if (evt.character==SWT.CR){
					OkPressed();
				}
			}
		};
		addListener(SWT.KeyDown,listener);
		{
			composite = new Composite(this, SWT.NONE);
			FormLayout compositeLayout = new FormLayout();
			composite.setLayout(compositeLayout);
			GridData compositeLData = new GridData();
			compositeLData.widthHint = 287;
			compositeLData.heightHint = 140;
			composite.setLayoutData(compositeLData);
			composite.setVisible(true);
			composite.addKeyListener(new KeyAdapter() {
				public void keyPressed(KeyEvent evt) {
					if (evt.character==SWT.CR){
						OkPressed();
					}
				}
			});
			{
				cLabel1 = new CLabel(composite, SWT.NONE);
				FormData cLabel1LData = new FormData();
				cLabel1LData.width = 120;
				cLabel1LData.height = 20;
				cLabel1LData.left =  new FormAttachment(0, 1000, 93);
				cLabel1LData.top =  new FormAttachment(0, 1000, 40);
				cLabel1.setLayoutData(cLabel1LData);
				Color col =display.getSystemColor(SWT.COLOR_RED);
				cLabel1.setForeground(col);
				cLabel1.setFont(SWTResourceManager.getFont("Times", 10, 1, false, false));
			}
			{
				LogoLabel = new CLabel(composite, SWT.NONE);
				FormData LogoLabelLData = new FormData();
				LogoLabelLData.width = 70;
				LogoLabelLData.height = 42;
				LogoLabelLData.left =  new FormAttachment(0, 1000, 77);
				LogoLabelLData.top =  new FormAttachment(0, 1000, 0);
				LogoLabelLData.right =  new FormAttachment(1000, 1000, -140);
				LogoLabelLData.bottom =  new FormAttachment(1000, 1000, -98);
				LogoLabel.setLayoutData(LogoLabelLData);
				LogoLabel.setImage(new Image(this.getDisplay(),"img/yalpV2_mittel.gif"));
			}
			{
				logonLable = new CLabel(composite, SWT.BEGINNING);
				logonLable.setText("Login");
				FormData logonLableLData = new FormData();
				logonLableLData.width = 70;
				logonLableLData.height = 28;
				logonLableLData.left =  new FormAttachment(0, 1000, 147);
				logonLableLData.top =  new FormAttachment(0, 1000, 5);
				logonLable.setLayoutData(logonLableLData);
				logonLable.setFont(SWTResourceManager.getFont("Times", 14, 1, false, false));
			}
			{
				username = new Text(composite, SWT.NONE);
				FormData usernameLData = new FormData();
				usernameLData.width = 117;
				usernameLData.height = 15;
				usernameLData.left =  new FormAttachment(0, 1000, 120);
				usernameLData.top =  new FormAttachment(0, 1000, 65);
				username.setLayoutData(usernameLData);
				username.setFocus();
				username.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent evt) {
						if (evt.character==SWT.CR){
							OkPressed();
						}
					}
				});
			}
			{
				passwd = new Text(composite, SWT.PASSWORD);
				FormData passwdLData = new FormData();
				passwdLData.width = 117;
				passwdLData.height = 15;
				passwdLData.left =  new FormAttachment(0, 1000, 120);
				passwdLData.top =  new FormAttachment(0, 1000, 88);
				passwd.setLayoutData(passwdLData);
				passwd.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent evt) {
						if (evt.character==SWT.CR){
							OkPressed();
						}
					}
				});
			}
			{
				ok = new Button(composite, SWT.PUSH | SWT.CENTER);
				ok.setText("OK");
				FormData okLData = new FormData();
				okLData.width = 65;
				okLData.height = 21;
				okLData.left =  new FormAttachment(0, 1000, 110);
				okLData.top =  new FormAttachment(0, 1000, 115);
				ok.setLayoutData(okLData);
				ok.setFont(SWTResourceManager.getFont("Times", 10, 1, false, false));
				ok.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						OkPressed();
					}
				});
			}
			{
				passwdLable = new CLabel(composite, SWT.NONE);
				passwdLable.setText("Password:");
				FormData passwdLableLData = new FormData();
				passwdLableLData.width = 70;
				passwdLableLData.height = 20;
				passwdLableLData.left =  new FormAttachment(0, 1000, 35);
				passwdLableLData.top =  new FormAttachment(0, 1000, 83);
				passwdLable.setLayoutData(passwdLableLData);
				passwdLable.setFont(SWTResourceManager.getFont("Times", 10, 0, false, false));
			}
			{
				usernameLable = new CLabel(composite, SWT.NONE);
				usernameLable.setText("Username:");
				FormData usernameLableLData = new FormData();
				usernameLableLData.width = 70;
				usernameLableLData.height = 20;
				usernameLableLData.left =  new FormAttachment(0, 1000, 35);
				usernameLableLData.top =  new FormAttachment(0, 1000, 60);
				usernameLable.setLayoutData(usernameLableLData);
				usernameLable.setFont(SWTResourceManager.getFont("Times", 10, 0, false, false));
			}
		}
		this.layout();

	}
	private void OkPressed(){
		AccessRights kind;
		kind = model.userVerify(username.getText(), passwd.getText());

		if (kind.value() == AccessRights._NO_YALP_SERVER ) {
			cLabel1.setText("Server offline");
		} else if (kind.value() == AccessRights._DENY ){
			cLabel1.setText("Access Denied");
			username.setText("");
			passwd.setText("");
			username.setFocus();
		} else {
			display.close();
			InitGUI gui = new InitGUI(model, kind);
		}

	}
	
	public void show(){
		((Shell)this.parent).setImage(new Image(display,"img/yalpV2_klein.gif"));
		((Shell)this.parent).setText("yalp");
		Point size = this.getSize();
		java.awt.Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		Rectangle shellBounds = this.parent.computeTrim((screen.width-size.x)/2,(screen.height-size.y)/2,size.x,size.y);
        this.parent.setLayout(new FillLayout());
        this.parent.layout();
        this.parent.setBounds(shellBounds);
        ((Shell)this.parent).open();
        while (!this.parent.isDisposed()) {
            if (!display.readAndDispatch())
            	display.sleep();
        }
	}
	

}