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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
/*
* File: ginteractors.h
* --------------------
* This file exports a hierarchy of graphical interactors similar to those
* provided in the Java Swing libraries.
* <include src="pictures/ClassHierarchies/GInteractorHierarchy-h.html">
*/
#ifndef _ginteractors_h
#define _ginteractors_h
#include "gobjects.h"
#include "gtypes.h"
#include "gwindow.h"
#include "vector.h"
/*
* Class: GInteractor
* ------------------
* This abstract class is the superclass for all graphical interactors.
* In most applications, interactors will be added to a control strip
* along one of the sides of the <code>GWindow</code>, but they can
* also be placed in specific positions just like any other
* <code>GObject</code>.
* <include src="pictures/ClassHierarchies/GInteractorHierarchy.html">
*/
class GInteractor : public GObject {
public:
/*
* Method: setActionCommand
* Usage: interactor.setActionCommand(cmd);
* ----------------------------------------
* Sets the action command to the indicated string. If the string is not
* empty, activating the interactor generates a <code>GActionEvent</code>.
*/
void setActionCommand(std::string cmd);
/*
* Method: getActionCommand
* Usage: string cmd = interactor.getActionCommand();
* --------------------------------------------------
* Returns the action command associated with the interactor.
*/
std::string getActionCommand();
/*
* Method: setSize
* Usage: interactor.setSize(size);
* interactor.setSize(width, height);
* -----------------------------------------
* Changes the size of the interactor to the specified width and height.
*/
void setSize(const GDimension & size);
void setSize(double width, double height);
/*
* Method: setBounds
* Usage: interactor.setBounds(rect);
* interactor.setBounds(x, y, width, height);
* -------------------------------------------------
* Changes the bounds of the interactor to the specified values.
*/
void setBounds(const GRectangle & size);
void setBounds(double x, double y, double width, double height);
/* Prototypes for the virtual methods */
virtual GRectangle getBounds() const;
protected:
GInteractor();
std::string actionCommand;
};
/*
* Class: GButton
* --------------
* This interactor subclass represents an onscreen button. The following
* program displays a button that, when pressed, generates the message
* “Please do not press this button again”
* (with thanks to Douglas Adams’s <i>Hitchhiker’s
* Guide to the Galaxy</i>):
*
*<pre>
* int main() {
* GWindow gw;
* GButton *button = new GButton("RED");
* gw.addToRegion(button, "SOUTH");
* while (true) {
* GEvent e = waitForEvent(ACTION_EVENT | CLICK_EVENT);
* if (e.getEventType() == MOUSE_CLICKED) break;
* cout << "Please do not press this button again." << endl;
* }
* return 0;
* }
*</pre>
*/
class GButton : public GInteractor {
public:
/*
* Constructor: GButton
* Usage: GButton *button = new GButton(label);
* --------------------------------------------
* Creates a <code>GButton</code> with the specified label. This
* constructor also sets the action command for the button to the
* label string.
*/
GButton(std::string label);
/* Prototypes for the virtual methods */
virtual std::string getType() const;
virtual std::string toString() const;
private:
std::string label;
};
/*
* Class: GCheckBox
* ----------------
* This interactor subclass represents an onscreen check box. Clicking
* once on the check box selects it; clicking again removes the selection.
* If a <code>GCheckBox</code> has an action command, clicking on the box
* generates a <code>GActionEvent</code>.
* <include src="pictures/GInteractorDiagrams/GCheckBox.html">
*/
class GCheckBox : public GInteractor {
public:
/*
* Constructor: GCheckBox
* Usage: GCheckBox *chkbox = new GCheckBox(label);
* ------------------------------------------------
* Creates a <code>GCheckBox</code> with the specified label. In contrast
* to the <code>GButton</code> constructor, this constructor does not set
* an action command.
*/
GCheckBox(std::string label);
/*
* Method: setSelected
* Usage: chkbox->setSelected(state);
* ----------------------------------
* Sets the state of the check box.
*/
void setSelected(bool state);
/*
* Method: isSelected
* Usage: if (chkbox->isSelected()) ...
* ------------------------------------
* Returns <code>true</code> if the check box is selected.
*/
bool isSelected();
/* Prototypes for the virtual methods */
virtual std::string getType() const;
virtual std::string toString() const;
private:
std::string label;
};
/*
* Class: GSlider
* --------------
* This interactor subclass represents an onscreen slider. Dragging
* the slider control generates an <code>ActionEvent</code> if the
* slider has a nonempty action command.
* <include src="pictures/GInteractorDiagrams/GSlider.html">
*/
class GSlider : public GInteractor {
public:
/*
* Constructor: GSlider
* Usage: GSlider *slider = new GSlider();
* GSlider *slider = new GSlider(min, max, value);
* ------------------------------------------------------
* Creates a horizontal <code>GSlider</code>. The second form allows
* the client to specify the minimum value, maximum value, and current
* value of the slider. The first form is equivalent to calling
* <code>GSlider(0, 100, 50)</code>. Assigning an action command
* to the slider causes the slider to generate an action event whenever
* the slider value changes.
*/
GSlider();
GSlider(int min, int max, int value);
/*
* Method: setValue
* Usage: slider->setValue(value);
* -------------------------------
* Sets the current value of the slider.
*/
void setValue(int value);
/*
* Method: getValue
* Usage: int value = slider->getValue();
* --------------------------------------
* Returns the current value of the slider.
*/
int getValue();
/* Prototypes for the virtual methods */
virtual std::string getType() const;
virtual std::string toString() const;
private:
void create(int min, int max, int value);
int min;
int max;
};
/*
* Class: GTextField
* -----------------
* This interactor subclass represents a text field for entering short
* text strings. Hitting enter in a text field generates a
* <code>GActionEvent</code> if the text field has a nonempty action command.
*/
class GTextField : public GInteractor {
public:
/*
* Constructor: GTextField
* Usage: GTextField *field = new GTextField();
* GTextField *field = new GTextField(nChars);
* --------------------------------------------------
* Creates a text field capable of holding <code>nChars</code> characters,
* which defaults to 10. Assigning an action command to the text field
* causes it to generate an action event whenever the user types the
* ENTER key.
*/
GTextField();
GTextField(int nChars);
/*
* Method: setText
* Usage: field->setText(str);
* ---------------------------
* Sets the text of the field to the specified string.
*/
void setText(std::string str);
/*
* Method: getText
* Usage: string str = field->getText();
* -------------------------------------
* Returns the contents of the text field.
*/
std::string getText();
/* Prototypes for the virtual methods */
virtual std::string getType() const;
virtual std::string toString() const;
};
/*
* Class: GChooser
* ---------------
* This interactor subclass represents a selectable list. The
* <code>GChooser</code> constructor creates an empty chooser.
* Once the chooser has been created, clients can use <code>addItem</code>
* to add the options. For example, the following code creates a
* <code>GChooser</code> containing the four strings
* <code>"Small"</code>, <code>"Medium"</code>, <code>"Large"</code>,
* and <code>"X-Large"</code>:
*
*<pre>
* GChooser *sizeChooser = new GChooser();
* sizeChooser->addItem("Small");
* sizeChooser->addItem("Medium");
* sizeChooser->addItem("Large");
* sizeChooser->addItem("X-Large");
*</pre>
*<include src="pictures/GInteractorDiagrams/GChooser.html">
*/
class GChooser : public GInteractor {
public:
/*
* Constructor: GChooser
* Usage: GChooser *chooser = new GChooser();
* ------------------------------------------
* Creates a chooser that initially contains no items, which are added
* using the <code>addItem</code> method. Assigning an action command
* to the chooser causes it to generate an action event whenever the
* user selects an item.
*/
GChooser();
/*
* Method: addItem
* Usage: chooser->addItem(item);
* ------------------------------
* Adds a new item consisting of the specified string.
*/
void addItem(std::string item);
/*
* Method: setSelectedItem
* Usage: chooser->setSelectedItem(item);
* --------------------------------------
* Sets the chooser so that it shows the specified item. If the item
* does not exist in the chooser, no change occurs.
*/
void setSelectedItem(std::string item);
/*
* Method: getSelectedItem
* Usage: string item = chooser->getSelectedItem();
* ------------------------------------------------
* Returns the current item selected in the chooser.
*/
std::string getSelectedItem();
/* Prototypes for the virtual methods */
virtual std::string getType() const;
virtual std::string toString() const;
};
#endif
|