-
Notifications
You must be signed in to change notification settings - Fork 1
/
IntelliBellGUI.java
279 lines (237 loc) · 7.54 KB
/
IntelliBellGUI.java
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package intelliBell;
import java.util.ArrayList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.widgets.Spinner;
/**
* GUI for main program.
* @author varshaneya
*/
public class IntelliBellGUI implements Runnable{
protected Shell shlIntellibell;
protected Shell newProfileShell;
private Text txtCreate;
private String newProfile = "";
private boolean createProfile;
private int delay;
private BellProfile bellProfile;
private String selectedIP;
private Thread t;
private AutomaticScheduler as;
/**
* Constructor launches the application.
* @param createProfile
* @param bprofile
* @param as
*/
public IntelliBellGUI(boolean createProfile,BellProfile bprofile,AutomaticScheduler as) {
this.createProfile = createProfile;
this.bellProfile = bprofile;
this.as=as;
String tname = new String("IntelliBellGUI");
if(!createProfile)
tname= tname+" - "+bprofile.getName();
t = new Thread(this,tname);
t.start();
}
public IntelliBellGUI(boolean createProfile) {
this.createProfile = createProfile;
this.bellProfile = null;
t = new Thread(this, "IntelliBellGUI");
t.start();
}
/**
* @wbp.parser.entryPoint
*/
/**
* Open the window.
*
*/
public void run() {
Display display = Display.getDefault();
createContents();
shlIntellibell.open();
shlIntellibell.layout();
//minimize the window when the daemon is running on pre-defined profile
shlIntellibell.setMinimized(!createProfile);
while (!shlIntellibell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Creates the GUI.
*/
protected void createContents() {
shlIntellibell = new Shell();
shlIntellibell.setSize(450, 300);
if(createProfile)
shlIntellibell.setText("IntelliBell - Create Profile");
else
shlIntellibell.setText("IntelliBell - "+ bellProfile.getName());
shlIntellibell.addShellListener(new ShellListener() {
@Override
public void shellClosed(ShellEvent event) {
shlIntellibell.dispose();
if(as != null)
as.stopAutoScheduler();
t.interrupt();
System.out.println("IntelliBell services are quitting. Bye.");
}
@Override
public void shellActivated(ShellEvent e) {
// TODO Auto-generated method stub
}
@Override
public void shellDeactivated(ShellEvent e) {
// TODO Auto-generated method stub
}
@Override
public void shellDeiconified(ShellEvent e) {
// TODO Auto-generated method stub
}
@Override
public void shellIconified(ShellEvent e) {
// TODO Auto-generated method stub
}
});
/*
* Labels section start
*/
Label lblCreateProfile = new Label(shlIntellibell, SWT.SEPARATOR | SWT.HORIZONTAL);
lblCreateProfile.setText("create profile");
lblCreateProfile.setBounds(0, 31, 434, 7);
Label label = new Label(shlIntellibell, SWT.SEPARATOR | SWT.HORIZONTAL);
label.setBounds(0, 69, 434, 14);
Label label_1 = new Label(shlIntellibell, SWT.SEPARATOR | SWT.HORIZONTAL);
label_1.setText("create profile");
label_1.setBounds(0, 112, 434, 7);
Label lblStatus = new Label(shlIntellibell, SWT.NONE);
lblStatus.setBounds(10, 120, 55, 15);
lblStatus.setText("Status:");
/*
* Labels section end
*/
/*
* Create new profile start
*/
Button btnCreate = new Button(shlIntellibell, SWT.NONE);
btnCreate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new CreateNewProfile(newProfile);
shlIntellibell.close();
}
});
btnCreate.setBounds(341, 8, 83, 21);
btnCreate.setText("Create Profile");
btnCreate.setEnabled(createProfile);
txtCreate = new Text(shlIntellibell, SWT.BORDER);
txtCreate.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text text = (Text) e.widget;
newProfile=text.getText();
}
});
txtCreate.setText("Profile Name");
txtCreate.setBounds(10, 8, 83, 21);
txtCreate.setEnabled(createProfile);
/*
* Create new profile end
*/
/*
* Manual ring design start
*/
Button btnRingManually = new Button(shlIntellibell, SWT.NONE);
btnRingManually.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new ManualControl(selectedIP,"s");
MessageBox dialog = new MessageBox(shlIntellibell, SWT.ICON_INFORMATION | SWT.OK);
dialog.setText("Info");
dialog.setMessage("Short ring signal manually sent to bell at IP "+selectedIP);
dialog.open();
}
});
btnRingManually.setText("Manual short ring");
btnRingManually.setBounds(318, 42, 106, 21);
btnRingManually.setEnabled(!createProfile);
Combo combo = new Combo(shlIntellibell, SWT.NONE);
if(!createProfile) {
ArrayList<String> IP = bellProfile.getIP();
for(String s:IP)
combo.add(s);
}
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int index;
if((index = combo.getSelectionIndex()) != -1)
selectedIP = combo.getItem(index);
}
});
combo.setBounds(10, 44, 91, 14);
combo.setText("Choose IP");
combo.setEnabled(!createProfile);
Button btnManualLongRing = new Button(shlIntellibell, SWT.NONE);
btnManualLongRing.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new ManualControl(selectedIP,"l");
MessageBox dialog = new MessageBox(shlIntellibell, SWT.ICON_INFORMATION | SWT.OK);
dialog.setText("Info");
dialog.setMessage("Long ring signal manually sent to bell at IP "+selectedIP);
dialog.open();
}
});
btnManualLongRing.setText("Manual long ring");
btnManualLongRing.setEnabled(true);
btnManualLongRing.setBounds(182, 42, 106, 21);
btnManualLongRing.setEnabled(!createProfile);
/*
* Manual ring design end
*/
/*
* Delayed ring design start
*/
Button btnDelayRing = new Button(shlIntellibell, SWT.NONE);
btnDelayRing.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
bellProfile.rescheduleRing(delay);
MessageBox dialog = new MessageBox(shlIntellibell, SWT.ICON_INFORMATION | SWT.OK);
dialog.setText("Info");
dialog.setMessage("All the bells are rescheduled to ring after " + delay +" min.");
dialog.open();
}
});
btnDelayRing.setText("Delay Ring");
btnDelayRing.setBounds(341, 89, 83, 21);
btnDelayRing.setEnabled(!createProfile);
Spinner spinner = new Spinner(shlIntellibell, SWT.BORDER);
spinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
delay=spinner.getSelection();
}
});
spinner.setBounds(10, 89, 47, 22);
spinner.setEnabled(!createProfile);
/*
* Delayed ring design end
*/
}
}