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
|
/*
* Copyright:
* (C) 2006 by Derrell Lipman
* All rights reserved
*
* License:
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
*/
/**
* The graphical user interface for the main menu
*/
qx.OO.defineClass("swat.main.Gui");
qx.Class.currentCanvas = null;
qx.Class.buildGui = function(moduleList)
{
var o;
// Header colors
var topColor = new qx.renderer.color.Color("#ffff64");
var bottomColor = new qx.renderer.color.Color("#3878cd");
// Create the yellow bar at the top
o = new qx.ui.basic.Terminator();
o.set({
top: 0,
left: 0,
right: 0,
height: 40
});
o.setBackgroundColor(topColor);
o.addToDocument();
// Create the tag line
var title = new qx.ui.basic.Label("Samba Web Administration Tool");
title.set({
top: 12,
left: 20
});
title.setBackgroundColor(topColor);
title.setFont("bold");
title.addToDocument();
// Create a small black separator between the yellow and blue bars
o = new qx.ui.basic.Terminator();
o.set({
top: 40,
left: 0,
right: 0,
height: 1
});
o.setBackgroundColor("black");
o.addToDocument();
// Create the yellow bar at the top
o = new qx.ui.basic.Terminator();
o.set({
top: 41,
left: 0,
right: 0,
height: 60
});
o.setBackgroundColor(bottomColor);
o.addToDocument();
// Create the "Samba" image
o = new qx.ui.basic.Image("../../../images/logo.png");
o.set({
top: 16,
right: 20
});
o.setZIndex(100000000);
o.addToDocument();
// Create a menu bar
var menubar = new qx.ui.toolbar.ToolBar();
menubar.set({
top: 100,
height: 20,
left: 0,
right: 0
});
menubar.addToDocument();
// Create a menu item for selecting the requested module
var menubutton = new qx.ui.toolbar.MenuButton("Modules");
menubar.add(menubutton);
// Create a Command to be executed upon any menu selection
var command = new qx.client.Command();
// command.addEventListener("execute", fsm.eventListener, fsm);
// Create a radio manager for selecting one of the modules
var moduleManager = new qx.manager.selection.RadioManager("main.gui.Module");
// Create a menu containing the subitems
var menu = new qx.ui.menu.Menu();
// We'll also track the current module's canvas in the modules object
swat.main.Gui.currentCanvas = null;
// For each menu item...
for (moduleName in moduleList)
{
// create a radio button menu item
o = new qx.ui.menu.RadioButton(moduleName, null, command);
// Associate this button menu item with the module list
o.moduleName = moduleName;
// Associate the menu item with the radio manager
moduleManager.add(o);
// Create this module's canvas
var canvas = new qx.ui.layout.CanvasLayout();
canvas.set({
top: 120,
bottom: 0,
left: 0,
right: 0
});
canvas.setBackgroundColor("white");
canvas.setDisplay(false); // initially not displayed
var fsm = moduleList[moduleName].fsm;
fsm.addObject("swat.main.canvas", canvas);
canvas.addEventListener("appear", fsm.eventListener, fsm);
canvas.addEventListener("disappear", fsm.eventListener, fsm);
// Save the canvas
moduleList[moduleName].canvas = canvas;
// Add the canvas to the document
canvas.addToDocument();
// When a Module menu item is selected:
o.addEventListener("changeChecked", function(e)
{
var canvas = moduleList[this.moduleName].canvas;
// If there's a current canvas, ...
if (swat.main.Gui.currentCanvas)
{
// ... then remove display of it.
swat.main.Gui.currentCanvas.setDisplay(false);
// Dispatch an event on the canvas to notify old
// module it's coming into disuse.
canvas.createDispatchEvent("disappear");
}
// If we are being selected...
if (e.getData())
{
// then display our canvas
var canvas = moduleList[this.moduleName].canvas;
canvas.setDisplay(true);
// Track the current canvas (now ours)
swat.main.Gui.currentCanvas = canvas;
// Dispatch an event on the canvas to notify new
// module it's coming into use.
canvas.createDispatchEvent("appear");
// Set the application title
title.setHtml("<span>" +
"Samba Web Administration Tool" +
" » " +
this.moduleName +
"</span>");
// Set the browser title as well
document.title =
"Swat: " + this.moduleName;
}
});
// Add the menu item to the menu
menu.add(o);
}
// We've built a complete menu. Add it to the document.
menu.addToDocument();
// Specify that the menu is to be displayed upon menu button selection
menubutton.setMenu(menu);
// Create a menu item for selecting debug options
var menubutton = new qx.ui.toolbar.MenuButton("Debug");
menubar.add(menubutton);
// Create a menu containing the subitems
var menu = new qx.ui.menu.Menu;
var menu_01 = new qx.ui.menu.Button("Show Debug Window", null, command);
menu.add(menu_01);
menu.addToDocument();
// Specify that the menu is to be displayed upon menu button selection
menubutton.setMenu(menu);
};
|