|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.swt.examples.mirroringTest; |
| 12 |
|
| 13 |
|
| 14 |
import org.eclipse.swt.*; |
| 15 |
import org.eclipse.swt.graphics.*; |
| 16 |
import org.eclipse.swt.widgets.*; |
| 17 |
import org.eclipse.swt.layout.*; |
| 18 |
import org.eclipse.swt.events.*; |
| 19 |
|
| 20 |
/** |
| 21 |
* <code>Tab</code> is the abstract superclass of every page |
| 22 |
* in the example's tab folder. Each page in the tab folder |
| 23 |
* describes a control. |
| 24 |
* |
| 25 |
* A Tab itself is not a control but instead provides a |
| 26 |
* hierarchy with which to share code that is common to |
| 27 |
* every page in the folder. |
| 28 |
* |
| 29 |
* A typical page in a Tab contains a two column composite. |
| 30 |
* The left column contains the "Example" group. The right |
| 31 |
* column contains "Control" group. The "Control" group |
| 32 |
* contains controls that allow the user to interact with |
| 33 |
* the example control. The "Control" group typically |
| 34 |
* contains a "Style", "Other" and "Size" group. Subclasses |
| 35 |
* can override these defaults to augment a group or stop |
| 36 |
* a group from being created. |
| 37 |
*/ |
| 38 |
abstract class Tab { |
| 39 |
Shell shell; |
| 40 |
Display display; |
| 41 |
|
| 42 |
/* Common control buttons */ |
| 43 |
Button borderButton, enabledButton, visibleButton, backgroundImageButton, popupMenuButton; |
| 44 |
Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton; |
| 45 |
|
| 46 |
/* Common groups and composites */ |
| 47 |
Composite tabFolderPage; |
| 48 |
Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup; |
| 49 |
|
| 50 |
/* Controlling instance */ |
| 51 |
final ControlExample instance; |
| 52 |
|
| 53 |
/* Sizing constants for the "Size" group */ |
| 54 |
static final int TOO_SMALL_SIZE = 10; |
| 55 |
static final int SMALL_SIZE = 50; |
| 56 |
static final int LARGE_SIZE = 100; |
| 57 |
|
| 58 |
/* Right-to-left support */ |
| 59 |
static final boolean RTL_SUPPORT_ENABLE = "win32".equals(SWT.getPlatform()) || "gtk".equals(SWT.getPlatform()); |
| 60 |
Group orientationGroup; |
| 61 |
Button rtlButtonRecreate, rtlButtonSet, ltrButtonRecreate, ltrButtonSet, defaultOrietationButton; |
| 62 |
|
| 63 |
/* Controls and resources for the "Colors & Fonts" group */ |
| 64 |
static final int IMAGE_SIZE = 12; |
| 65 |
static final int FOREGROUND_COLOR = 0; |
| 66 |
static final int BACKGROUND_COLOR = 1; |
| 67 |
static final int FONT = 2; |
| 68 |
Table colorAndFontTable; |
| 69 |
ColorDialog colorDialog; |
| 70 |
FontDialog fontDialog; |
| 71 |
Color foregroundColor, backgroundColor; |
| 72 |
Font font; |
| 73 |
|
| 74 |
/* Controls and resources for the "Background Mode" group */ |
| 75 |
Combo backgroundModeCombo; |
| 76 |
Button backgroundModeImageButton, backgroundModeColorButton; |
| 77 |
|
| 78 |
boolean samplePopup = false; |
| 79 |
|
| 80 |
/* Set/Get API controls */ |
| 81 |
Combo nameCombo; |
| 82 |
Label returnTypeLabel; |
| 83 |
Button getButton, setButton; |
| 84 |
Text setText, getText; |
| 85 |
Shell setGetDialog; |
| 86 |
|
| 87 |
/* Event logging variables and controls */ |
| 88 |
Text eventConsole; |
| 89 |
boolean logging = false; |
| 90 |
boolean [] eventsFilter; |
| 91 |
int setFieldsMask = 0; |
| 92 |
Event setFieldsEvent = new Event (); |
| 93 |
boolean ignore = false; |
| 94 |
|
| 95 |
/* Event logging constants */ |
| 96 |
static final int DOIT = 0x0100; |
| 97 |
static final int DETAIL = 0x0200; |
| 98 |
static final int TEXT = 0x0400; |
| 99 |
static final int X = 0x0800; |
| 100 |
static final int Y = 0x1000; |
| 101 |
static final int WIDTH = 0x2000; |
| 102 |
static final int HEIGHT = 0x4000; |
| 103 |
|
| 104 |
static final int DETAIL_IME = 0; |
| 105 |
static final int DETAIL_ERASE_ITEM = 1; |
| 106 |
static final int DETAIL_TRAVERSE = 2; |
| 107 |
|
| 108 |
static class EventInfo { |
| 109 |
String name; |
| 110 |
int type; |
| 111 |
int settableFields; |
| 112 |
int setFields; |
| 113 |
Event event; |
| 114 |
EventInfo (String name, int type, int settableFields, int setFields, Event event) { |
| 115 |
this.name = name; |
| 116 |
this.type = type; |
| 117 |
this.settableFields = settableFields; |
| 118 |
this.setFields = setFields; |
| 119 |
this.event = event; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
final EventInfo [] EVENT_INFO = { |
| 124 |
new EventInfo ("Activate", SWT.Activate, 0, 0, new Event()), |
| 125 |
new EventInfo ("Arm", SWT.Arm, 0, 0, new Event()), |
| 126 |
new EventInfo ("Close", SWT.Close, DOIT, 0, new Event()), |
| 127 |
new EventInfo ("Collapse", SWT.Collapse, 0, 0, new Event()), |
| 128 |
new EventInfo ("Deactivate", SWT.Deactivate, 0, 0, new Event()), |
| 129 |
new EventInfo ("DefaultSelection", SWT.DefaultSelection, 0, 0, new Event()), |
| 130 |
new EventInfo ("Deiconify", SWT.Deiconify, 0, 0, new Event()), |
| 131 |
new EventInfo ("Dispose", SWT.Dispose, 0, 0, new Event()), |
| 132 |
new EventInfo ("DragDetect", SWT.DragDetect, 0, 0, new Event()), |
| 133 |
new EventInfo ("EraseItem", SWT.EraseItem, DETAIL | DETAIL_ERASE_ITEM, 0, new Event()), |
| 134 |
new EventInfo ("Expand", SWT.Expand, 0, 0, new Event()), |
| 135 |
new EventInfo ("FocusIn", SWT.FocusIn, 0, 0, new Event()), |
| 136 |
new EventInfo ("FocusOut", SWT.FocusOut, 0, 0, new Event()), |
| 137 |
new EventInfo ("HardKeyDown", SWT.HardKeyDown, 0, 0, new Event()), |
| 138 |
new EventInfo ("HardKeyUp", SWT.HardKeyUp, 0, 0, new Event()), |
| 139 |
new EventInfo ("Help", SWT.Help, 0, 0, new Event()), |
| 140 |
new EventInfo ("Hide", SWT.Hide, 0, 0, new Event()), |
| 141 |
new EventInfo ("Iconify", SWT.Iconify, 0, 0, new Event()), |
| 142 |
new EventInfo ("KeyDown", SWT.KeyDown, DOIT, 0, new Event()), |
| 143 |
new EventInfo ("KeyUp", SWT.KeyUp, DOIT, 0, new Event()), |
| 144 |
new EventInfo ("MeasureItem", SWT.MeasureItem, 0, 0, new Event()), |
| 145 |
new EventInfo ("MenuDetect", SWT.MenuDetect, X | Y | DOIT, 0, new Event()), |
| 146 |
new EventInfo ("Modify", SWT.Modify, 0, 0, new Event()), |
| 147 |
new EventInfo ("MouseDoubleClick", SWT.MouseDoubleClick, 0, 0, new Event()), |
| 148 |
new EventInfo ("MouseDown", SWT.MouseDown, 0, 0, new Event()), |
| 149 |
new EventInfo ("MouseEnter", SWT.MouseEnter, 0, 0, new Event()), |
| 150 |
new EventInfo ("MouseExit", SWT.MouseExit, 0, 0, new Event()), |
| 151 |
new EventInfo ("MouseHover", SWT.MouseHover, 0, 0, new Event()), |
| 152 |
new EventInfo ("MouseMove", SWT.MouseMove, 0, 0, new Event()), |
| 153 |
new EventInfo ("MouseUp", SWT.MouseUp, 0, 0, new Event()), |
| 154 |
new EventInfo ("MouseWheel", SWT.MouseWheel, 0, 0, new Event()), |
| 155 |
new EventInfo ("Move", SWT.Move, 0, 0, new Event()), |
| 156 |
new EventInfo ("Paint", SWT.Paint, 0, 0, new Event()), |
| 157 |
new EventInfo ("PaintItem", SWT.PaintItem, 0, 0, new Event()), |
| 158 |
new EventInfo ("Resize", SWT.Resize, 0, 0, new Event()), |
| 159 |
new EventInfo ("Selection", SWT.Selection, X | Y | DOIT, 0, new Event()), // sash |
| 160 |
new EventInfo ("SetData", SWT.SetData, 0, 0, new Event()), |
| 161 |
// new EventInfo ("Settings", SWT.Settings, 0, 0, new Event()), // note: this event only goes to Display |
| 162 |
new EventInfo ("Show", SWT.Show, 0, 0, new Event()), |
| 163 |
new EventInfo ("Traverse", SWT.Traverse, DETAIL | DETAIL_TRAVERSE | DOIT, 0, new Event()), |
| 164 |
new EventInfo ("Verify", SWT.Verify, TEXT | DOIT, 0, new Event()), |
| 165 |
new EventInfo ("ImeComposition", SWT.ImeComposition, DETAIL | DETAIL_IME | TEXT | DOIT, 0, new Event()), |
| 166 |
}; |
| 167 |
|
| 168 |
static final String [][] DETAIL_CONSTANTS = { |
| 169 |
{ // DETAIL_IME = 0 |
| 170 |
"SWT.COMPOSITION_CHANGED", |
| 171 |
"SWT.COMPOSITION_OFFSET", |
| 172 |
"SWT.COMPOSITION_SELECTION", |
| 173 |
}, |
| 174 |
{ // DETAIL_ERASE_ITEM = 1 |
| 175 |
"SWT.SELECTED", |
| 176 |
"SWT.FOCUSED", |
| 177 |
"SWT.BACKGROUND", |
| 178 |
"SWT.FOREGROUND", |
| 179 |
"SWT.HOT", |
| 180 |
}, |
| 181 |
{ // DETAIL_TRAVERSE = 2 |
| 182 |
"SWT.TRAVERSE_NONE", |
| 183 |
"SWT.TRAVERSE_ESCAPE", |
| 184 |
"SWT.TRAVERSE_RETURN", |
| 185 |
"SWT.TRAVERSE_TAB_PREVIOUS", |
| 186 |
"SWT.TRAVERSE_TAB_NEXT", |
| 187 |
"SWT.TRAVERSE_ARROW_PREVIOUS", |
| 188 |
"SWT.TRAVERSE_ARROW_NEXT", |
| 189 |
"SWT.TRAVERSE_MNEMONIC", |
| 190 |
"SWT.TRAVERSE_PAGE_PREVIOUS", |
| 191 |
"SWT.TRAVERSE_PAGE_NEXT", |
| 192 |
}, |
| 193 |
}; |
| 194 |
|
| 195 |
static final Object [] DETAIL_VALUES = { |
| 196 |
"SWT.COMPOSITION_CHANGED", new Integer(SWT.COMPOSITION_CHANGED), |
| 197 |
"SWT.COMPOSITION_OFFSET", new Integer(SWT.COMPOSITION_OFFSET), |
| 198 |
"SWT.COMPOSITION_SELECTION", new Integer(SWT.COMPOSITION_SELECTION), |
| 199 |
"SWT.SELECTED", new Integer(SWT.SELECTED), |
| 200 |
"SWT.FOCUSED", new Integer(SWT.FOCUSED), |
| 201 |
"SWT.BACKGROUND", new Integer(SWT.BACKGROUND), |
| 202 |
"SWT.FOREGROUND", new Integer(SWT.FOREGROUND), |
| 203 |
"SWT.HOT", new Integer(SWT.HOT), |
| 204 |
"SWT.TRAVERSE_NONE", new Integer(SWT.TRAVERSE_NONE), |
| 205 |
"SWT.TRAVERSE_ESCAPE", new Integer(SWT.TRAVERSE_ESCAPE), |
| 206 |
"SWT.TRAVERSE_RETURN", new Integer(SWT.TRAVERSE_RETURN), |
| 207 |
"SWT.TRAVERSE_TAB_PREVIOUS", new Integer(SWT.TRAVERSE_TAB_PREVIOUS), |
| 208 |
"SWT.TRAVERSE_TAB_NEXT", new Integer(SWT.TRAVERSE_TAB_NEXT), |
| 209 |
"SWT.TRAVERSE_ARROW_PREVIOUS", new Integer(SWT.TRAVERSE_ARROW_PREVIOUS), |
| 210 |
"SWT.TRAVERSE_ARROW_NEXT", new Integer(SWT.TRAVERSE_ARROW_NEXT), |
| 211 |
"SWT.TRAVERSE_MNEMONIC", new Integer(SWT.TRAVERSE_MNEMONIC), |
| 212 |
"SWT.TRAVERSE_PAGE_PREVIOUS", new Integer(SWT.TRAVERSE_PAGE_PREVIOUS), |
| 213 |
"SWT.TRAVERSE_PAGE_NEXT", new Integer(SWT.TRAVERSE_PAGE_NEXT), |
| 214 |
}; |
| 215 |
|
| 216 |
/** |
| 217 |
* Creates the Tab within a given instance of ControlExample. |
| 218 |
*/ |
| 219 |
Tab(ControlExample instance) { |
| 220 |
this.instance = instance; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Creates the "Control" group. The "Control" group |
| 225 |
* is typically the right hand column in the tab. |
| 226 |
*/ |
| 227 |
void createControlGroup () { |
| 228 |
|
| 229 |
/* |
| 230 |
* Create the "Control" group. This is the group on the |
| 231 |
* right half of each example tab. It consists of the |
| 232 |
* "Style" group, the "Other" group and the "Size" group. |
| 233 |
*/ |
| 234 |
controlGroup = new Group (tabFolderPage, SWT.NONE); |
| 235 |
controlGroup.setLayout (new GridLayout (2, true)); |
| 236 |
controlGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false)); |
| 237 |
controlGroup.setText (ControlExample.getResourceString("Parameters")); |
| 238 |
|
| 239 |
/* Create individual groups inside the "Control" group */ |
| 240 |
createStyleGroup (); |
| 241 |
createOtherGroup (); |
| 242 |
createSetGetGroup(); |
| 243 |
createSizeGroup (); |
| 244 |
createColorAndFontGroup (); |
| 245 |
if (rtlSupport()) { |
| 246 |
createOrientationGroup (); |
| 247 |
} |
| 248 |
// createBackgroundModeGroup (); |
| 249 |
|
| 250 |
/* |
| 251 |
* For each Button child in the style group, add a selection |
| 252 |
* listener that will recreate the example controls. If the |
| 253 |
* style group button is a RADIO button, ensure that the radio |
| 254 |
* button is selected before recreating the example controls. |
| 255 |
* When the user selects a RADIO button, the current RADIO |
| 256 |
* button in the group is deselected and the new RADIO button |
| 257 |
* is selected automatically. The listeners are notified for |
| 258 |
* both these operations but typically only do work when a RADIO |
| 259 |
* button is selected. |
| 260 |
*/ |
| 261 |
SelectionListener selectionListener = new SelectionAdapter () { |
| 262 |
public void widgetSelected (SelectionEvent event) { |
| 263 |
if ((event.widget.getStyle () & SWT.RADIO) != 0) { |
| 264 |
if (!((Button) event.widget).getSelection ()) return; |
| 265 |
} |
| 266 |
recreateExampleWidgets (); |
| 267 |
} |
| 268 |
}; |
| 269 |
Control [] children = styleGroup.getChildren (); |
| 270 |
for (int i=0; i<children.length; i++) { |
| 271 |
if (children [i] instanceof Button) { |
| 272 |
Button button = (Button) children [i]; |
| 273 |
button.addSelectionListener (selectionListener); |
| 274 |
} else { |
| 275 |
if (children [i] instanceof Composite) { |
| 276 |
/* Look down one more level of children in the style group. */ |
| 277 |
Composite composite = (Composite) children [i]; |
| 278 |
Control [] grandchildren = composite.getChildren (); |
| 279 |
for (int j=0; j<grandchildren.length; j++) { |
| 280 |
if (grandchildren [j] instanceof Button) { |
| 281 |
Button button = (Button) grandchildren [j]; |
| 282 |
button.addSelectionListener (selectionListener); |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
} |
| 288 |
if (rtlSupport()) { |
| 289 |
rtlButtonRecreate.addSelectionListener (selectionListener); |
| 290 |
ltrButtonRecreate.addSelectionListener (selectionListener); |
| 291 |
defaultOrietationButton.addSelectionListener (selectionListener); |
| 292 |
|
| 293 |
SelectionListener bidiListener = new SelectionAdapter () { |
| 294 |
public void widgetSelected (SelectionEvent event) { |
| 295 |
Control [] controls = getExampleControls (); |
| 296 |
int flag = event.widget == rtlButtonSet ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; |
| 297 |
for (int i=0; i<controls.length; i++) { |
| 298 |
controls [i].setOrientation(flag); |
| 299 |
//controls [i].setTextDirectionRTL(); |
| 300 |
} |
| 301 |
} |
| 302 |
}; |
| 303 |
rtlButtonSet.addSelectionListener (bidiListener); |
| 304 |
ltrButtonSet.addSelectionListener (bidiListener); |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Append the Set/Get API controls to the "Other" group. |
| 310 |
*/ |
| 311 |
void createSetGetGroup() { |
| 312 |
/* |
| 313 |
* Create the button to access set/get API functionality. |
| 314 |
*/ |
| 315 |
final String [] methodNames = getMethodNames (); |
| 316 |
if (methodNames != null) { |
| 317 |
final Button setGetButton = new Button (otherGroup, SWT.PUSH); |
| 318 |
setGetButton.setText (ControlExample.getResourceString ("Set_Get")); |
| 319 |
setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 320 |
setGetButton.addSelectionListener (new SelectionAdapter() { |
| 321 |
public void widgetSelected (SelectionEvent e) { |
| 322 |
if (getExampleWidgets().length > 0) { |
| 323 |
if (setGetDialog == null) { |
| 324 |
setGetDialog = createSetGetDialog(methodNames); |
| 325 |
} |
| 326 |
Point pt = setGetButton.getLocation(); |
| 327 |
pt = display.map(setGetButton.getParent(), null, pt); |
| 328 |
setGetDialog.setLocation(pt.x, pt.y); |
| 329 |
setGetDialog.open(); |
| 330 |
} |
| 331 |
} |
| 332 |
}); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
/** |
| 337 |
* Creates the "Control" widget children. |
| 338 |
* Subclasses override this method to augment |
| 339 |
* the standard controls created in the "Style", |
| 340 |
* "Other" and "Size" groups. |
| 341 |
*/ |
| 342 |
void createControlWidgets () { |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Creates the "Colors and Fonts" group. This is typically |
| 347 |
* a child of the "Control" group. Subclasses override |
| 348 |
* this method to customize color and font settings. |
| 349 |
*/ |
| 350 |
void createColorAndFontGroup () { |
| 351 |
/* Create the group. */ |
| 352 |
colorGroup = new Group(controlGroup, SWT.NONE); |
| 353 |
colorGroup.setLayout (new GridLayout (2, true)); |
| 354 |
colorGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false)); |
| 355 |
colorGroup.setText (ControlExample.getResourceString ("Colors")); |
| 356 |
colorAndFontTable = new Table(colorGroup, SWT.BORDER | SWT.V_SCROLL); |
| 357 |
colorAndFontTable.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1)); |
| 358 |
TableItem item = new TableItem(colorAndFontTable, SWT.None); |
| 359 |
item.setText(ControlExample.getResourceString ("Foreground_Color")); |
| 360 |
colorAndFontTable.setSelection(0); |
| 361 |
item = new TableItem(colorAndFontTable, SWT.None); |
| 362 |
item.setText(ControlExample.getResourceString ("Background_Color")); |
| 363 |
item = new TableItem(colorAndFontTable, SWT.None); |
| 364 |
item.setText(ControlExample.getResourceString ("Font")); |
| 365 |
Button changeButton = new Button (colorGroup, SWT.PUSH); |
| 366 |
changeButton.setText(ControlExample.getResourceString("Change")); |
| 367 |
changeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 368 |
Button defaultsButton = new Button (colorGroup, SWT.PUSH); |
| 369 |
defaultsButton.setText(ControlExample.getResourceString("Defaults")); |
| 370 |
defaultsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 371 |
|
| 372 |
/* Add listeners to set/reset colors and fonts. */ |
| 373 |
colorDialog = new ColorDialog (shell); |
| 374 |
fontDialog = new FontDialog (shell); |
| 375 |
colorAndFontTable.addSelectionListener(new SelectionAdapter() { |
| 376 |
public void widgetDefaultSelected(SelectionEvent event) { |
| 377 |
changeFontOrColor (colorAndFontTable.getSelectionIndex()); |
| 378 |
} |
| 379 |
}); |
| 380 |
changeButton.addSelectionListener(new SelectionAdapter() { |
| 381 |
public void widgetSelected(SelectionEvent event) { |
| 382 |
changeFontOrColor (colorAndFontTable.getSelectionIndex()); |
| 383 |
} |
| 384 |
}); |
| 385 |
defaultsButton.addSelectionListener(new SelectionAdapter () { |
| 386 |
public void widgetSelected (SelectionEvent e) { |
| 387 |
resetColorsAndFonts (); |
| 388 |
} |
| 389 |
}); |
| 390 |
shell.addDisposeListener(new DisposeListener() { |
| 391 |
public void widgetDisposed(DisposeEvent event) { |
| 392 |
if (foregroundColor != null) foregroundColor.dispose(); |
| 393 |
if (backgroundColor != null) backgroundColor.dispose(); |
| 394 |
if (font != null) font.dispose(); |
| 395 |
foregroundColor = null; |
| 396 |
backgroundColor = null; |
| 397 |
font = null; |
| 398 |
if (colorAndFontTable != null && !colorAndFontTable.isDisposed()) { |
| 399 |
TableItem [] items = colorAndFontTable.getItems(); |
| 400 |
for (int i = 0; i < items.length; i++) { |
| 401 |
Image image = items[i].getImage(); |
| 402 |
if (image != null) image.dispose(); |
| 403 |
} |
| 404 |
} |
| 405 |
} |
| 406 |
}); |
| 407 |
} |
| 408 |
|
| 409 |
void changeFontOrColor(int index) { |
| 410 |
switch (index) { |
| 411 |
case FOREGROUND_COLOR: { |
| 412 |
Color oldColor = foregroundColor; |
| 413 |
if (oldColor == null) { |
| 414 |
Control [] controls = getExampleControls (); |
| 415 |
if (controls.length > 0) oldColor = controls [0].getForeground (); |
| 416 |
} |
| 417 |
if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color |
| 418 |
RGB rgb = colorDialog.open(); |
| 419 |
if (rgb == null) return; |
| 420 |
oldColor = foregroundColor; // save old foreground color to dispose when done |
| 421 |
foregroundColor = new Color (display, rgb); |
| 422 |
setExampleWidgetForeground (); |
| 423 |
if (oldColor != null) oldColor.dispose (); |
| 424 |
} |
| 425 |
break; |
| 426 |
case BACKGROUND_COLOR: { |
| 427 |
Color oldColor = backgroundColor; |
| 428 |
if (oldColor == null) { |
| 429 |
Control [] controls = getExampleControls (); |
| 430 |
if (controls.length > 0) oldColor = controls [0].getBackground (); // seed dialog with current color |
| 431 |
} |
| 432 |
if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); |
| 433 |
RGB rgb = colorDialog.open(); |
| 434 |
if (rgb == null) return; |
| 435 |
oldColor = backgroundColor; // save old background color to dispose when done |
| 436 |
backgroundColor = new Color (display, rgb); |
| 437 |
setExampleWidgetBackground (); |
| 438 |
if (oldColor != null) oldColor.dispose (); |
| 439 |
} |
| 440 |
break; |
| 441 |
case FONT: { |
| 442 |
Font oldFont = font; |
| 443 |
if (oldFont == null) { |
| 444 |
Control [] controls = getExampleControls (); |
| 445 |
if (controls.length > 0) oldFont = controls [0].getFont (); |
| 446 |
} |
| 447 |
if (oldFont != null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font |
| 448 |
FontData fontData = fontDialog.open (); |
| 449 |
if (fontData == null) return; |
| 450 |
oldFont = font; // dispose old font when done |
| 451 |
font = new Font (display, fontData); |
| 452 |
setExampleWidgetFont (); |
| 453 |
setExampleWidgetSize (); |
| 454 |
if (oldFont != null) oldFont.dispose (); |
| 455 |
} |
| 456 |
break; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* Creates the "Other" group. This is typically |
| 462 |
* a child of the "Control" group. |
| 463 |
*/ |
| 464 |
void createOtherGroup () { |
| 465 |
/* Create the group */ |
| 466 |
otherGroup = new Group (controlGroup, SWT.NONE); |
| 467 |
otherGroup.setLayout (new GridLayout ()); |
| 468 |
otherGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false)); |
| 469 |
otherGroup.setText (ControlExample.getResourceString("Other")); |
| 470 |
|
| 471 |
/* Create the controls */ |
| 472 |
enabledButton = new Button(otherGroup, SWT.CHECK); |
| 473 |
enabledButton.setText(ControlExample.getResourceString("Enabled")); |
| 474 |
visibleButton = new Button(otherGroup, SWT.CHECK); |
| 475 |
visibleButton.setText(ControlExample.getResourceString("Visible")); |
| 476 |
backgroundImageButton = new Button(otherGroup, SWT.CHECK); |
| 477 |
backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage")); |
| 478 |
popupMenuButton = new Button(otherGroup, SWT.CHECK); |
| 479 |
popupMenuButton.setText(ControlExample.getResourceString("PopupMenu")); |
| 480 |
|
| 481 |
/* Add the listeners */ |
| 482 |
enabledButton.addSelectionListener (new SelectionAdapter () { |
| 483 |
public void widgetSelected (SelectionEvent event) { |
| 484 |
setExampleWidgetEnabled (); |
| 485 |
} |
| 486 |
}); |
| 487 |
visibleButton.addSelectionListener (new SelectionAdapter () { |
| 488 |
public void widgetSelected (SelectionEvent event) { |
| 489 |
setExampleWidgetVisibility (); |
| 490 |
} |
| 491 |
}); |
| 492 |
backgroundImageButton.addSelectionListener (new SelectionAdapter () { |
| 493 |
public void widgetSelected (SelectionEvent event) { |
| 494 |
setExampleWidgetBackgroundImage (); |
| 495 |
} |
| 496 |
}); |
| 497 |
popupMenuButton.addSelectionListener (new SelectionAdapter () { |
| 498 |
public void widgetSelected (SelectionEvent event) { |
| 499 |
setExampleWidgetPopupMenu (); |
| 500 |
} |
| 501 |
}); |
| 502 |
|
| 503 |
/* Set the default state */ |
| 504 |
enabledButton.setSelection(true); |
| 505 |
visibleButton.setSelection(true); |
| 506 |
backgroundImageButton.setSelection(false); |
| 507 |
popupMenuButton.setSelection(false); |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* Creates the "Background Mode" group. |
| 512 |
*/ |
| 513 |
void createBackgroundModeGroup () { |
| 514 |
/* Create the group */ |
| 515 |
backgroundModeGroup = new Group (controlGroup, SWT.NONE); |
| 516 |
backgroundModeGroup.setLayout (new GridLayout ()); |
| 517 |
backgroundModeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false)); |
| 518 |
backgroundModeGroup.setText (ControlExample.getResourceString("Background_Mode")); |
| 519 |
|
| 520 |
/* Create the controls */ |
| 521 |
backgroundModeCombo = new Combo(backgroundModeGroup, SWT.READ_ONLY); |
| 522 |
backgroundModeCombo.setItems(new String[] {"SWT.INHERIT_NONE", "SWT.INHERIT_DEFAULT", "SWT.INHERIT_FORCE"}); |
| 523 |
backgroundModeImageButton = new Button(backgroundModeGroup, SWT.CHECK); |
| 524 |
backgroundModeImageButton.setText(ControlExample.getResourceString("BackgroundImage")); |
| 525 |
backgroundModeColorButton = new Button(backgroundModeGroup, SWT.CHECK); |
| 526 |
backgroundModeColorButton.setText(ControlExample.getResourceString("BackgroundColor")); |
| 527 |
|
| 528 |
/* Add the listeners */ |
| 529 |
backgroundModeCombo.addSelectionListener (new SelectionAdapter () { |
| 530 |
public void widgetSelected (SelectionEvent event) { |
| 531 |
setExampleGroupBackgroundMode (); |
| 532 |
} |
| 533 |
}); |
| 534 |
backgroundModeImageButton.addSelectionListener (new SelectionAdapter () { |
| 535 |
public void widgetSelected (SelectionEvent event) { |
| 536 |
setExampleGroupBackgroundImage (); |
| 537 |
} |
| 538 |
}); |
| 539 |
backgroundModeColorButton.addSelectionListener (new SelectionAdapter () { |
| 540 |
public void widgetSelected (SelectionEvent event) { |
| 541 |
setExampleGroupBackgroundColor (); |
| 542 |
} |
| 543 |
}); |
| 544 |
|
| 545 |
/* Set the default state */ |
| 546 |
backgroundModeCombo.setText(backgroundModeCombo.getItem(0)); |
| 547 |
backgroundModeImageButton.setSelection(false); |
| 548 |
backgroundModeColorButton.setSelection(false); |
| 549 |
} |
| 550 |
|
| 551 |
void createEditEventDialog(Shell parent, int x, int y, final int index) { |
| 552 |
final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); |
| 553 |
dialog.setLayout(new GridLayout()); |
| 554 |
dialog.setText(ControlExample.getResourceString ("Edit_Event")); |
| 555 |
Label label = new Label (dialog, SWT.NONE); |
| 556 |
label.setText (ControlExample.getResourceString ("Edit_Event_Fields", new String [] {EVENT_INFO[index].name})); |
| 557 |
|
| 558 |
Group group = new Group (dialog, SWT.NONE); |
| 559 |
group.setLayout(new GridLayout(2, false)); |
| 560 |
group.setLayoutData(new GridData (SWT.FILL, SWT.FILL, true, true)); |
| 561 |
|
| 562 |
final int fields = EVENT_INFO[index].settableFields; |
| 563 |
final int eventType = EVENT_INFO[index].type; |
| 564 |
setFieldsMask = EVENT_INFO[index].setFields; |
| 565 |
setFieldsEvent = EVENT_INFO[index].event; |
| 566 |
|
| 567 |
if ((fields & DOIT) != 0) { |
| 568 |
new Label (group, SWT.NONE).setText ("doit"); |
| 569 |
final Combo doitCombo = new Combo (group, SWT.READ_ONLY); |
| 570 |
doitCombo.setItems (new String [] {"", "true", "false"}); |
| 571 |
if ((setFieldsMask & DOIT) != 0) doitCombo.setText(Boolean.toString(setFieldsEvent.doit)); |
| 572 |
doitCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 573 |
doitCombo.addSelectionListener(new SelectionAdapter () { |
| 574 |
public void widgetSelected(SelectionEvent e) { |
| 575 |
String newValue = doitCombo.getText(); |
| 576 |
if (newValue.length() == 0) { |
| 577 |
setFieldsMask &= ~DOIT; |
| 578 |
} else { |
| 579 |
setFieldsEvent.type = eventType; |
| 580 |
setFieldsEvent.doit = newValue.equals("true"); |
| 581 |
setFieldsMask |= DOIT; |
| 582 |
} |
| 583 |
} |
| 584 |
}); |
| 585 |
} |
| 586 |
|
| 587 |
if ((fields & DETAIL) != 0) { |
| 588 |
new Label (group, SWT.NONE).setText ("detail"); |
| 589 |
int detailType = fields & 0xFF; |
| 590 |
final Combo detailCombo = new Combo (group, SWT.READ_ONLY); |
| 591 |
detailCombo.setItems (DETAIL_CONSTANTS[detailType]); |
| 592 |
detailCombo.add ("", 0); |
| 593 |
detailCombo.setVisibleItemCount(detailCombo.getItemCount()); |
| 594 |
if ((setFieldsMask & DETAIL) != 0) detailCombo.setText (DETAIL_CONSTANTS[detailType][setFieldsEvent.detail]); |
| 595 |
detailCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 596 |
detailCombo.addSelectionListener(new SelectionAdapter () { |
| 597 |
public void widgetSelected(SelectionEvent e) { |
| 598 |
String newValue = detailCombo.getText(); |
| 599 |
if (newValue.length() == 0) { |
| 600 |
setFieldsMask &= ~DETAIL; |
| 601 |
} else { |
| 602 |
setFieldsEvent.type = eventType; |
| 603 |
for (int i = 0; i < DETAIL_VALUES.length; i += 2) { |
| 604 |
if (newValue.equals (DETAIL_VALUES [i])) { |
| 605 |
setFieldsEvent.detail = ((Integer) DETAIL_VALUES [i + 1]).intValue(); |
| 606 |
break; |
| 607 |
} |
| 608 |
} |
| 609 |
setFieldsMask |= DETAIL; |
| 610 |
} |
| 611 |
} |
| 612 |
}); |
| 613 |
} |
| 614 |
|
| 615 |
if ((fields & TEXT) != 0) { |
| 616 |
new Label (group, SWT.NONE).setText ("text"); |
| 617 |
final Text textText = new Text (group, SWT.BORDER); |
| 618 |
if ((setFieldsMask & TEXT) != 0) textText.setText(setFieldsEvent.text); |
| 619 |
textText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 620 |
textText.addModifyListener(new ModifyListener () { |
| 621 |
public void modifyText(ModifyEvent e) { |
| 622 |
String newValue = textText.getText(); |
| 623 |
if (newValue.length() == 0) { |
| 624 |
setFieldsMask &= ~TEXT; |
| 625 |
} else { |
| 626 |
setFieldsEvent.type = eventType; |
| 627 |
setFieldsEvent.text = newValue; |
| 628 |
setFieldsMask |= TEXT; |
| 629 |
} |
| 630 |
} |
| 631 |
}); |
| 632 |
} |
| 633 |
|
| 634 |
if ((fields & X) != 0) { |
| 635 |
new Label (group, SWT.NONE).setText ("x"); |
| 636 |
final Text xText = new Text (group, SWT.BORDER); |
| 637 |
if ((setFieldsMask & X) != 0) xText.setText(Integer.toString(setFieldsEvent.x)); |
| 638 |
xText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 639 |
xText.addModifyListener(new ModifyListener () { |
| 640 |
public void modifyText(ModifyEvent e) { |
| 641 |
String newValue = xText.getText (); |
| 642 |
try { |
| 643 |
int newIntValue = Integer.parseInt (newValue); |
| 644 |
setFieldsEvent.type = eventType; |
| 645 |
setFieldsEvent.x = newIntValue; |
| 646 |
setFieldsMask |= X; |
| 647 |
} catch (NumberFormatException ex) { |
| 648 |
setFieldsMask &= ~X; |
| 649 |
} |
| 650 |
} |
| 651 |
}); |
| 652 |
} |
| 653 |
|
| 654 |
if ((fields & Y) != 0) { |
| 655 |
new Label (group, SWT.NONE).setText ("y"); |
| 656 |
final Text yText = new Text (group, SWT.BORDER); |
| 657 |
if ((setFieldsMask & Y) != 0) yText.setText(Integer.toString(setFieldsEvent.y)); |
| 658 |
yText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 659 |
yText.addModifyListener(new ModifyListener () { |
| 660 |
public void modifyText(ModifyEvent e) { |
| 661 |
String newValue = yText.getText (); |
| 662 |
try { |
| 663 |
int newIntValue = Integer.parseInt (newValue); |
| 664 |
setFieldsEvent.type = eventType; |
| 665 |
setFieldsEvent.y = newIntValue; |
| 666 |
setFieldsMask |= Y; |
| 667 |
} catch (NumberFormatException ex) { |
| 668 |
setFieldsMask &= ~Y; |
| 669 |
} |
| 670 |
} |
| 671 |
}); |
| 672 |
} |
| 673 |
|
| 674 |
if ((fields & WIDTH) != 0) { |
| 675 |
new Label (group, SWT.NONE).setText ("width"); |
| 676 |
final Text widthText = new Text (group, SWT.BORDER); |
| 677 |
if ((setFieldsMask & WIDTH) != 0) widthText.setText(Integer.toString(setFieldsEvent.width)); |
| 678 |
widthText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 679 |
widthText.addModifyListener(new ModifyListener () { |
| 680 |
public void modifyText(ModifyEvent e) { |
| 681 |
String newValue = widthText.getText (); |
| 682 |
try { |
| 683 |
int newIntValue = Integer.parseInt (newValue); |
| 684 |
setFieldsEvent.type = eventType; |
| 685 |
setFieldsEvent.width = newIntValue; |
| 686 |
setFieldsMask |= WIDTH; |
| 687 |
} catch (NumberFormatException ex) { |
| 688 |
setFieldsMask &= ~WIDTH; |
| 689 |
} |
| 690 |
} |
| 691 |
}); |
| 692 |
} |
| 693 |
|
| 694 |
if ((fields & HEIGHT) != 0) { |
| 695 |
new Label (group, SWT.NONE).setText ("height"); |
| 696 |
final Text heightText = new Text (group, SWT.BORDER); |
| 697 |
if ((setFieldsMask & HEIGHT) != 0) heightText.setText(Integer.toString(setFieldsEvent.height)); |
| 698 |
heightText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false)); |
| 699 |
heightText.addModifyListener(new ModifyListener () { |
| 700 |
public void modifyText(ModifyEvent e) { |
| 701 |
String newValue = heightText.getText (); |
| 702 |
try { |
| 703 |
int newIntValue = Integer.parseInt (newValue); |
| 704 |
setFieldsEvent.type = eventType; |
| 705 |
setFieldsEvent.height = newIntValue; |
| 706 |
setFieldsMask |= HEIGHT; |
| 707 |
} catch (NumberFormatException ex) { |
| 708 |
setFieldsMask &= ~HEIGHT; |
| 709 |
} |
| 710 |
} |
| 711 |
}); |
| 712 |
} |
| 713 |
|
| 714 |
Button ok = new Button (dialog, SWT.PUSH); |
| 715 |
ok.setText (ControlExample.getResourceString("OK")); |
| 716 |
GridData data = new GridData (70, SWT.DEFAULT); |
| 717 |
data.horizontalAlignment = SWT.RIGHT; |
| 718 |
ok.setLayoutData (data); |
| 719 |
ok.addSelectionListener (new SelectionAdapter() { |
| 720 |
public void widgetSelected(SelectionEvent e) { |
| 721 |
EVENT_INFO[index].setFields = setFieldsMask; |
| 722 |
EVENT_INFO[index].event = setFieldsEvent; |
| 723 |
dialog.dispose(); |
| 724 |
} |
| 725 |
}); |
| 726 |
|
| 727 |
dialog.setDefaultButton(ok); |
| 728 |
dialog.pack(); |
| 729 |
dialog.setLocation(x, y); |
| 730 |
dialog.open(); |
| 731 |
} |
| 732 |
|
| 733 |
/** |
| 734 |
* Create the event console popup menu. |
| 735 |
*/ |
| 736 |
void createEventConsolePopup () { |
| 737 |
Menu popup = new Menu (shell, SWT.POP_UP); |
| 738 |
eventConsole.setMenu (popup); |
| 739 |
|
| 740 |
MenuItem cut = new MenuItem (popup, SWT.PUSH); |
| 741 |
cut.setText (ControlExample.getResourceString("MenuItem_Cut")); |
| 742 |
cut.addListener (SWT.Selection, new Listener () { |
| 743 |
public void handleEvent (Event event) { |
| 744 |
eventConsole.cut (); |
| 745 |
} |
| 746 |
}); |
| 747 |
MenuItem copy = new MenuItem (popup, SWT.PUSH); |
| 748 |
copy.setText (ControlExample.getResourceString("MenuItem_Copy")); |
| 749 |
copy.addListener (SWT.Selection, new Listener () { |
| 750 |
public void handleEvent (Event event) { |
| 751 |
eventConsole.copy (); |
| 752 |
} |
| 753 |
}); |
| 754 |
MenuItem paste = new MenuItem (popup, SWT.PUSH); |
| 755 |
paste.setText (ControlExample.getResourceString("MenuItem_Paste")); |
| 756 |
paste.addListener (SWT.Selection, new Listener () { |
| 757 |
public void handleEvent (Event event) { |
| 758 |
eventConsole.paste (); |
| 759 |
} |
| 760 |
}); |
| 761 |
new MenuItem (popup, SWT.SEPARATOR); |
| 762 |
MenuItem selectAll = new MenuItem (popup, SWT.PUSH); |
| 763 |
selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll")); |
| 764 |
selectAll.addListener (SWT.Selection, new Listener () { |
| 765 |
public void handleEvent (Event event) { |
| 766 |
eventConsole.selectAll (); |
| 767 |
} |
| 768 |
}); |
| 769 |
} |
| 770 |
|
| 771 |
/** |
| 772 |
* Creates the "Example" group. The "Example" group |
| 773 |
* is typically the left hand column in the tab. |
| 774 |
*/ |
| 775 |
void createExampleGroup () { |
| 776 |
exampleGroup = new Group (tabFolderPage, SWT.NONE); |
| 777 |
exampleGroup.setLayout (new GridLayout ()); |
| 778 |
exampleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true)); |
| 779 |
} |
| 780 |
|
| 781 |
/** |
| 782 |
* Creates the "Example" widget children of the "Example" group. |
| 783 |
* Subclasses override this method to create the particular |
| 784 |
* example control. |
| 785 |
*/ |
| 786 |
void createExampleWidgets () { |
| 787 |
/* Do nothing */ |
| 788 |
} |
| 789 |
|
| 790 |
/** |
| 791 |
* Creates and opens the "Listener selection" dialog. |
| 792 |
*/ |
| 793 |
void createListenerSelectionDialog () { |
| 794 |
final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); |
| 795 |
dialog.setText (ControlExample.getResourceString ("Select_Listeners")); |
| 796 |
dialog.setLayout (new GridLayout (2, false)); |
| 797 |
final Table table = new Table (dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK); |
| 798 |
GridData data = new GridData(GridData.FILL_BOTH); |
| 799 |
data.verticalSpan = 3; |
| 800 |
table.setLayoutData(data); |
| 801 |
for (int i = 0; i < EVENT_INFO.length; i++) { |
| 802 |
TableItem item = new TableItem (table, SWT.NONE); |
| 803 |
item.setText (EVENT_INFO[i].name); |
| 804 |
item.setChecked (eventsFilter[i]); |
| 805 |
} |
| 806 |
final String [] customNames = getCustomEventNames (); |
| 807 |
for (int i = 0; i < customNames.length; i++) { |
| 808 |
TableItem item = new TableItem (table, SWT.NONE); |
| 809 |
item.setText (customNames[i]); |
| 810 |
item.setChecked (eventsFilter[EVENT_INFO.length + i]); |
| 811 |
} |
| 812 |
Button selectAll = new Button (dialog, SWT.PUSH); |
| 813 |
selectAll.setText(ControlExample.getResourceString ("Select_All")); |
| 814 |
selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); |
| 815 |
selectAll.addSelectionListener (new SelectionAdapter() { |
| 816 |
public void widgetSelected(SelectionEvent e) { |
| 817 |
TableItem [] items = table.getItems(); |
| 818 |
for (int i = 0; i < EVENT_INFO.length; i++) { |
| 819 |
items[i].setChecked(true); |
| 820 |
} |
| 821 |
for (int i = 0; i < customNames.length; i++) { |
| 822 |
items[EVENT_INFO.length + i].setChecked(true); |
| 823 |
} |
| 824 |
} |
| 825 |
}); |
| 826 |
Button deselectAll = new Button (dialog, SWT.PUSH); |
| 827 |
deselectAll.setText(ControlExample.getResourceString ("Deselect_All")); |
| 828 |
deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); |
| 829 |
deselectAll.addSelectionListener (new SelectionAdapter() { |
| 830 |
public void widgetSelected(SelectionEvent e) { |
| 831 |
TableItem [] items = table.getItems(); |
| 832 |
for (int i = 0; i < EVENT_INFO.length; i++) { |
| 833 |
items[i].setChecked(false); |
| 834 |
} |
| 835 |
for (int i = 0; i < customNames.length; i++) { |
| 836 |
items[EVENT_INFO.length + i].setChecked(false); |
| 837 |
} |
| 838 |
} |
| 839 |
}); |
| 840 |
final Button editEvent = new Button (dialog, SWT.PUSH); |
| 841 |
editEvent.setText (ControlExample.getResourceString ("Edit_Event")); |
| 842 |
editEvent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); |
| 843 |
editEvent.addSelectionListener (new SelectionAdapter() { |
| 844 |
public void widgetSelected (SelectionEvent e) { |
| 845 |
Point pt = editEvent.getLocation(); |
| 846 |
pt = e.display.map(editEvent, null, pt); |
| 847 |
int index = table.getSelectionIndex(); |
| 848 |
if (getExampleWidgets().length > 0 && index != -1) { |
| 849 |
createEditEventDialog(dialog, pt.x, pt.y, index); |
| 850 |
} |
| 851 |
} |
| 852 |
}); |
| 853 |
editEvent.setEnabled(false); |
| 854 |
table.addSelectionListener(new SelectionAdapter() { |
| 855 |
public void widgetSelected(SelectionEvent e) { |
| 856 |
int fields = 0; |
| 857 |
int index = table.getSelectionIndex(); |
| 858 |
if (index != -1 && index < EVENT_INFO.length) { // TODO: Allow custom widgets to specify event info |
| 859 |
fields = (EVENT_INFO[index].settableFields); |
| 860 |
} |
| 861 |
editEvent.setEnabled(fields != 0); |
| 862 |
} |
| 863 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 864 |
if (editEvent.getEnabled()) { |
| 865 |
Point pt = editEvent.getLocation(); |
| 866 |
pt = e.display.map(editEvent, null, pt); |
| 867 |
int index = table.getSelectionIndex(); |
| 868 |
if (getExampleWidgets().length > 0 && index != -1 && index < EVENT_INFO.length) { |
| 869 |
createEditEventDialog(dialog, pt.x, pt.y, index); |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
}); |
| 874 |
|
| 875 |
new Label(dialog, SWT.NONE); /* Filler */ |
| 876 |
Button ok = new Button (dialog, SWT.PUSH); |
| 877 |
ok.setText(ControlExample.getResourceString ("OK")); |
| 878 |
dialog.setDefaultButton(ok); |
| 879 |
ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); |
| 880 |
ok.addSelectionListener (new SelectionAdapter() { |
| 881 |
public void widgetSelected(SelectionEvent e) { |
| 882 |
TableItem [] items = table.getItems(); |
| 883 |
for (int i = 0; i < EVENT_INFO.length; i++) { |
| 884 |
eventsFilter[i] = items[i].getChecked(); |
| 885 |
} |
| 886 |
for (int i = 0; i < customNames.length; i++) { |
| 887 |
eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked(); |
| 888 |
} |
| 889 |
dialog.dispose(); |
| 890 |
} |
| 891 |
}); |
| 892 |
dialog.pack (); |
| 893 |
/* |
| 894 |
* If the preferred size of the dialog is too tall for the display, |
| 895 |
* then reduce the height, so that the vertical scrollbar will appear. |
| 896 |
*/ |
| 897 |
Rectangle bounds = dialog.getBounds(); |
| 898 |
Rectangle trim = dialog.computeTrim(0, 0, 0, 0); |
| 899 |
Rectangle clientArea = display.getClientArea(); |
| 900 |
if (bounds.height > clientArea.height) { |
| 901 |
dialog.setSize(bounds.width, clientArea.height - trim.height); |
| 902 |
} |
| 903 |
dialog.setLocation(bounds.x, clientArea.y); |
| 904 |
dialog.open (); |
| 905 |
while (! dialog.isDisposed()) { |
| 906 |
if (! display.readAndDispatch()) display.sleep(); |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
/** |
| 911 |
* Creates the "Listeners" group. The "Listeners" group |
| 912 |
* goes below the "Example" and "Control" groups. |
| 913 |
*/ |
| 914 |
void createListenersGroup () { |
| 915 |
listenersGroup = new Group (tabFolderPage, SWT.NONE); |
| 916 |
listenersGroup.setLayout (new GridLayout (3, false)); |
| 917 |
listenersGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true, 2, 1)); |
| 918 |
listenersGroup.setText (ControlExample.getResourceString ("Listeners")); |
| 919 |
|
| 920 |
/* |
| 921 |
* Create the button to access the 'Listeners' dialog. |
| 922 |
*/ |
| 923 |
Button listenersButton = new Button (listenersGroup, SWT.PUSH); |
| 924 |
listenersButton.setText (ControlExample.getResourceString ("Select_Listeners")); |
| 925 |
listenersButton.addSelectionListener (new SelectionAdapter() { |
| 926 |
public void widgetSelected (SelectionEvent e) { |
| 927 |
createListenerSelectionDialog (); |
| 928 |
recreateExampleWidgets (); |
| 929 |
} |
| 930 |
}); |
| 931 |
|
| 932 |
/* |
| 933 |
* Create the checkbox to add/remove listeners to/from the example widgets. |
| 934 |
*/ |
| 935 |
final Button listenCheckbox = new Button (listenersGroup, SWT.CHECK); |
| 936 |
listenCheckbox.setText (ControlExample.getResourceString ("Listen")); |
| 937 |
listenCheckbox.addSelectionListener (new SelectionAdapter () { |
| 938 |
public void widgetSelected(SelectionEvent e) { |
| 939 |
logging = listenCheckbox.getSelection (); |
| 940 |
recreateExampleWidgets (); |
| 941 |
} |
| 942 |
}); |
| 943 |
|
| 944 |
/* |
| 945 |
* Create the button to clear the text. |
| 946 |
*/ |
| 947 |
Button clearButton = new Button (listenersGroup, SWT.PUSH); |
| 948 |
clearButton.setText (ControlExample.getResourceString ("Clear")); |
| 949 |
clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
| 950 |
clearButton.addSelectionListener (new SelectionAdapter() { |
| 951 |
public void widgetSelected (SelectionEvent e) { |
| 952 |
eventConsole.setText (""); |
| 953 |
} |
| 954 |
}); |
| 955 |
|
| 956 |
/* Initialize the eventsFilter to log all events. */ |
| 957 |
int customEventCount = getCustomEventNames ().length; |
| 958 |
eventsFilter = new boolean [EVENT_INFO.length + customEventCount]; |
| 959 |
for (int i = 0; i < EVENT_INFO.length + customEventCount; i++) { |
| 960 |
eventsFilter [i] = true; |
| 961 |
} |
| 962 |
|
| 963 |
/* Create the event console Text. */ |
| 964 |
eventConsole = new Text (listenersGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); |
| 965 |
GridData data = new GridData (GridData.FILL_BOTH); |
| 966 |
data.horizontalSpan = 3; |
| 967 |
data.heightHint = 80; |
| 968 |
eventConsole.setLayoutData (data); |
| 969 |
createEventConsolePopup (); |
| 970 |
eventConsole.addKeyListener (new KeyAdapter () { |
| 971 |
public void keyPressed (KeyEvent e) { |
| 972 |
if ((e.keyCode == 'A' || e.keyCode == 'a') && (e.stateMask & SWT.MOD1) != 0) { |
| 973 |
eventConsole.selectAll (); |
| 974 |
e.doit = false; |
| 975 |
} |
| 976 |
} |
| 977 |
}); |
| 978 |
} |
| 979 |
|
| 980 |
/** |
| 981 |
* Returns a list of set/get API method names (without the set/get prefix) |
| 982 |
* that can be used to set/get values in the example control(s). |
| 983 |
*/ |
| 984 |
String[] getMethodNames() { |
| 985 |
return null; |
| 986 |
} |
| 987 |
|
| 988 |
Shell createSetGetDialog(String[] methodNames) { |
| 989 |
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MODELESS); |
| 990 |
dialog.setLayout(new GridLayout(2, false)); |
| 991 |
dialog.setText(getTabText() + " " + ControlExample.getResourceString ("Set_Get")); |
| 992 |
nameCombo = new Combo(dialog, SWT.READ_ONLY); |
| 993 |
nameCombo.setItems(methodNames); |
| 994 |
nameCombo.setText(methodNames[0]); |
| 995 |
nameCombo.setVisibleItemCount(methodNames.length); |
| 996 |
nameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 997 |
nameCombo.addSelectionListener(new SelectionAdapter() { |
| 998 |
public void widgetSelected(SelectionEvent e) { |
| 999 |
resetLabels(); |
| 1000 |
} |
| 1001 |
}); |
| 1002 |
returnTypeLabel = new Label(dialog, SWT.NONE); |
| 1003 |
returnTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); |
| 1004 |
setButton = new Button(dialog, SWT.PUSH); |
| 1005 |
setButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); |
| 1006 |
setButton.addSelectionListener(new SelectionAdapter() { |
| 1007 |
public void widgetSelected(SelectionEvent e) { |
| 1008 |
setValue(); |
| 1009 |
setText.selectAll(); |
| 1010 |
setText.setFocus(); |
| 1011 |
} |
| 1012 |
}); |
| 1013 |
setText = new Text(dialog, SWT.SINGLE | SWT.BORDER); |
| 1014 |
setText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 1015 |
getButton = new Button(dialog, SWT.PUSH); |
| 1016 |
getButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); |
| 1017 |
getButton.addSelectionListener(new SelectionAdapter() { |
| 1018 |
public void widgetSelected(SelectionEvent e) { |
| 1019 |
getValue(); |
| 1020 |
} |
| 1021 |
}); |
| 1022 |
getText = new Text(dialog, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); |
| 1023 |
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); |
| 1024 |
data.widthHint = 240; |
| 1025 |
data.heightHint = 200; |
| 1026 |
getText.setLayoutData(data); |
| 1027 |
resetLabels(); |
| 1028 |
dialog.setDefaultButton(setButton); |
| 1029 |
dialog.pack(); |
| 1030 |
dialog.addDisposeListener(new DisposeListener() { |
| 1031 |
public void widgetDisposed(DisposeEvent e) { |
| 1032 |
setGetDialog = null; |
| 1033 |
} |
| 1034 |
}); |
| 1035 |
return dialog; |
| 1036 |
} |
| 1037 |
|
| 1038 |
void resetLabels() { |
| 1039 |
String methodRoot = nameCombo.getText(); |
| 1040 |
returnTypeLabel.setText(parameterInfo(methodRoot)); |
| 1041 |
setButton.setText(setMethodName(methodRoot)); |
| 1042 |
getButton.setText("get" + methodRoot); |
| 1043 |
setText.setText(""); |
| 1044 |
getText.setText(""); |
| 1045 |
getValue(); |
| 1046 |
setText.setFocus(); |
| 1047 |
} |
| 1048 |
|
| 1049 |
String setMethodName(String methodRoot) { |
| 1050 |
return "set" + methodRoot; |
| 1051 |
} |
| 1052 |
|
| 1053 |
String parameterInfo(String methodRoot) { |
| 1054 |
String typeName = null; |
| 1055 |
Class returnType = getReturnType(methodRoot); |
| 1056 |
boolean isArray = returnType.isArray(); |
| 1057 |
if (isArray) { |
| 1058 |
typeName = returnType.getComponentType().getName(); |
| 1059 |
} else { |
| 1060 |
typeName = returnType.getName(); |
| 1061 |
} |
| 1062 |
String typeNameString = typeName; |
| 1063 |
int index = typeName.lastIndexOf('.'); |
| 1064 |
if (index != -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1); |
| 1065 |
String info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : "")); |
| 1066 |
if (isArray) { |
| 1067 |
typeNameString += "[]"; |
| 1068 |
} |
| 1069 |
return ControlExample.getResourceString("Parameter_Info", new Object[] {typeNameString, info}); |
| 1070 |
} |
| 1071 |
|
| 1072 |
void getValue() { |
| 1073 |
String methodName = "get" + nameCombo.getText(); |
| 1074 |
getText.setText(""); |
| 1075 |
Widget[] widgets = getExampleWidgets(); |
| 1076 |
for (int i = 0; i < widgets.length; i++) { |
| 1077 |
try { |
| 1078 |
java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, null); |
| 1079 |
Object result = method.invoke(widgets[i], null); |
| 1080 |
if (result == null) { |
| 1081 |
getText.append("null"); |
| 1082 |
} else if (result.getClass().isArray()) { |
| 1083 |
int length = java.lang.reflect.Array.getLength(result); |
| 1084 |
if (length == 0) { |
| 1085 |
getText.append(result.getClass().getComponentType() + "[0]"); |
| 1086 |
} |
| 1087 |
for (int j = 0; j < length; j++) { |
| 1088 |
getText.append(java.lang.reflect.Array.get(result,j).toString() + "\n"); |
| 1089 |
} |
| 1090 |
} else { |
| 1091 |
getText.append(result.toString()); |
| 1092 |
} |
| 1093 |
} catch (Exception e) { |
| 1094 |
getText.append(e.toString()); |
| 1095 |
} |
| 1096 |
if (i + 1 < widgets.length) { |
| 1097 |
getText.append("\n\n"); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
Class getReturnType(String methodRoot) { |
| 1103 |
Class returnType = null; |
| 1104 |
String methodName = "get" + methodRoot; |
| 1105 |
Widget[] widgets = getExampleWidgets(); |
| 1106 |
try { |
| 1107 |
java.lang.reflect.Method method = widgets[0].getClass().getMethod(methodName, null); |
| 1108 |
returnType = method.getReturnType(); |
| 1109 |
} catch (Exception e) { |
| 1110 |
} |
| 1111 |
return returnType; |
| 1112 |
} |
| 1113 |
|
| 1114 |
void setValue() { |
| 1115 |
/* The parameter type must be the same as the get method's return type */ |
| 1116 |
String methodRoot = nameCombo.getText(); |
| 1117 |
Class returnType = getReturnType(methodRoot); |
| 1118 |
String methodName = setMethodName(methodRoot); |
| 1119 |
String value = setText.getText(); |
| 1120 |
Widget[] widgets = getExampleWidgets(); |
| 1121 |
for (int i = 0; i < widgets.length; i++) { |
| 1122 |
try { |
| 1123 |
java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, new Class[] {returnType}); |
| 1124 |
String typeName = returnType.getName(); |
| 1125 |
Object[] parameter = null; |
| 1126 |
if (value.equals("null")) { |
| 1127 |
parameter = new Object[] {null}; |
| 1128 |
} else if (typeName.equals("int")) { |
| 1129 |
parameter = new Object[] {new Integer(value)}; |
| 1130 |
} else if (typeName.equals("long")) { |
| 1131 |
parameter = new Object[] {new Long(value)}; |
| 1132 |
} else if (typeName.equals("char")) { |
| 1133 |
parameter = new Object[] {value.length() == 1 ? new Character(value.charAt(0)) : new Character('\0')}; |
| 1134 |
} else if (typeName.equals("boolean")) { |
| 1135 |
parameter = new Object[] {new Boolean(value)}; |
| 1136 |
} else if (typeName.equals("java.lang.String")) { |
| 1137 |
parameter = new Object[] {value}; |
| 1138 |
} else if (typeName.equals("org.eclipse.swt.graphics.Point")) { |
| 1139 |
String xy[] = split(value, ','); |
| 1140 |
parameter = new Object[] {new Point(new Integer(xy[0]).intValue(),new Integer(xy[1]).intValue())}; |
| 1141 |
} else if (typeName.equals("[I")) { |
| 1142 |
String strings[] = split(value, ','); |
| 1143 |
int[] ints = new int[strings.length]; |
| 1144 |
for (int j = 0; j < strings.length; j++) { |
| 1145 |
ints[j] = new Integer(strings[j]).intValue(); |
| 1146 |
} |
| 1147 |
parameter = new Object[] {ints}; |
| 1148 |
} else if (typeName.equals("[Ljava.lang.String;")) { |
| 1149 |
parameter = new Object[] {split(value, ',')}; |
| 1150 |
} else { |
| 1151 |
parameter = parameterForType(typeName, value, widgets[i]); |
| 1152 |
} |
| 1153 |
method.invoke(widgets[i], parameter); |
| 1154 |
} catch (Exception e) { |
| 1155 |
Throwable cause = e.getCause(); |
| 1156 |
String message = e.getMessage(); |
| 1157 |
getText.setText(e.toString()); |
| 1158 |
if (cause != null) getText.append(", cause=\n" + cause.toString()); |
| 1159 |
if (message != null) getText.append(", message=\n" + message); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
Object[] parameterForType(String typeName, String value, Widget widget) { |
| 1165 |
return new Object[] {value}; |
| 1166 |
} |
| 1167 |
|
| 1168 |
void createOrientationGroup () { |
| 1169 |
/* Create Orientation group*/ |
| 1170 |
orientationGroup = new Group (controlGroup, SWT.NONE); |
| 1171 |
orientationGroup.setLayout (new GridLayout()); |
| 1172 |
orientationGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false)); |
| 1173 |
orientationGroup.setText (ControlExample.getResourceString("Orientation")); |
| 1174 |
defaultOrietationButton = new Button (orientationGroup, SWT.RADIO); |
| 1175 |
defaultOrietationButton.setText (ControlExample.getResourceString("Default")); |
| 1176 |
defaultOrietationButton.setSelection (true); |
| 1177 |
ltrButtonRecreate = new Button (orientationGroup, SWT.RADIO); |
| 1178 |
ltrButtonRecreate.setText ("create new SWT.LEFT_TO_RIGHT"); |
| 1179 |
rtlButtonRecreate = new Button (orientationGroup, SWT.RADIO); |
| 1180 |
rtlButtonRecreate.setText ("create new SWT.RIGHT_TO_LEFT"); |
| 1181 |
ltrButtonSet= new Button (orientationGroup, SWT.RADIO); |
| 1182 |
ltrButtonSet.setText ("set orientation SWT.LEFT_TO_RIGHT"); |
| 1183 |
rtlButtonSet = new Button (orientationGroup, SWT.RADIO); |
| 1184 |
rtlButtonSet.setText ("set orientation SWT.RIGHT_TO_LEFT"); |
| 1185 |
|
| 1186 |
|
| 1187 |
} |
| 1188 |
|
| 1189 |
/** |
| 1190 |
* Creates the "Size" group. The "Size" group contains |
| 1191 |
* controls that allow the user to change the size of |
| 1192 |
* the example widgets. |
| 1193 |
*/ |
| 1194 |
void createSizeGroup () { |
| 1195 |
/* Create the group */ |
| 1196 |
sizeGroup = new Group (controlGroup, SWT.NONE); |
| 1197 |
sizeGroup.setLayout (new GridLayout()); |
| 1198 |
sizeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false)); |
| 1199 |
sizeGroup.setText (ControlExample.getResourceString("Size")); |
| 1200 |
|
| 1201 |
/* Create the controls */ |
| 1202 |
|
| 1203 |
/* |
| 1204 |
* The preferred size of a widget is the size returned |
| 1205 |
* by widget.computeSize (SWT.DEFAULT, SWT.DEFAULT). |
| 1206 |
* This size is defined on a widget by widget basis. |
| 1207 |
* Many widgets will attempt to display their contents. |
| 1208 |
*/ |
| 1209 |
preferredButton = new Button (sizeGroup, SWT.RADIO); |
| 1210 |
preferredButton.setText (ControlExample.getResourceString("Preferred")); |
| 1211 |
tooSmallButton = new Button (sizeGroup, SWT.RADIO); |
| 1212 |
tooSmallButton.setText (TOO_SMALL_SIZE + " X " + TOO_SMALL_SIZE); |
| 1213 |
smallButton = new Button(sizeGroup, SWT.RADIO); |
| 1214 |
smallButton.setText (SMALL_SIZE + " X " + SMALL_SIZE); |
| 1215 |
largeButton = new Button (sizeGroup, SWT.RADIO); |
| 1216 |
largeButton.setText (LARGE_SIZE + " X " + LARGE_SIZE); |
| 1217 |
fillHButton = new Button (sizeGroup, SWT.CHECK); |
| 1218 |
fillHButton.setText (ControlExample.getResourceString("Fill_X")); |
| 1219 |
fillVButton = new Button (sizeGroup, SWT.CHECK); |
| 1220 |
fillVButton.setText (ControlExample.getResourceString("Fill_Y")); |
| 1221 |
|
| 1222 |
/* Add the listeners */ |
| 1223 |
SelectionAdapter selectionListener = new SelectionAdapter () { |
| 1224 |
public void widgetSelected (SelectionEvent event) { |
| 1225 |
setExampleWidgetSize (); |
| 1226 |
} |
| 1227 |
}; |
| 1228 |
preferredButton.addSelectionListener(selectionListener); |
| 1229 |
tooSmallButton.addSelectionListener(selectionListener); |
| 1230 |
smallButton.addSelectionListener(selectionListener); |
| 1231 |
largeButton.addSelectionListener(selectionListener); |
| 1232 |
fillHButton.addSelectionListener(selectionListener); |
| 1233 |
fillVButton.addSelectionListener(selectionListener); |
| 1234 |
|
| 1235 |
/* Set the default state */ |
| 1236 |
preferredButton.setSelection (true); |
| 1237 |
} |
| 1238 |
|
| 1239 |
/** |
| 1240 |
* Creates the "Style" group. The "Style" group contains |
| 1241 |
* controls that allow the user to change the style of |
| 1242 |
* the example widgets. Changing a widget "Style" causes |
| 1243 |
* the widget to be destroyed and recreated. |
| 1244 |
*/ |
| 1245 |
void createStyleGroup () { |
| 1246 |
styleGroup = new Group (controlGroup, SWT.NONE); |
| 1247 |
styleGroup.setLayout (new GridLayout ()); |
| 1248 |
styleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false)); |
| 1249 |
styleGroup.setText (ControlExample.getResourceString("Styles")); |
| 1250 |
} |
| 1251 |
|
| 1252 |
/** |
| 1253 |
* Creates the tab folder page. |
| 1254 |
* |
| 1255 |
* @param tabFolder org.eclipse.swt.widgets.TabFolder |
| 1256 |
* @return the new page for the tab folder |
| 1257 |
*/ |
| 1258 |
Composite createTabFolderPage (TabFolder tabFolder) { |
| 1259 |
/* Cache the shell and display. */ |
| 1260 |
shell = tabFolder.getShell (); |
| 1261 |
display = shell.getDisplay (); |
| 1262 |
|
| 1263 |
/* Create a two column page. */ |
| 1264 |
tabFolderPage = new Composite (tabFolder, SWT.NONE); |
| 1265 |
tabFolderPage.setLayout (new GridLayout (2, false)); |
| 1266 |
|
| 1267 |
/* Create the "Example" and "Control" groups. */ |
| 1268 |
createExampleGroup (); |
| 1269 |
createControlGroup (); |
| 1270 |
|
| 1271 |
/* Create the "Listeners" group under the "Control" group. */ |
| 1272 |
createListenersGroup (); |
| 1273 |
|
| 1274 |
/* Create and initialize the example and control widgets. */ |
| 1275 |
createExampleWidgets (); |
| 1276 |
hookExampleWidgetListeners (); |
| 1277 |
createControlWidgets (); |
| 1278 |
setExampleWidgetState (); |
| 1279 |
|
| 1280 |
return tabFolderPage; |
| 1281 |
} |
| 1282 |
|
| 1283 |
void setExampleWidgetPopupMenu() { |
| 1284 |
Control[] controls = getExampleControls(); |
| 1285 |
for (int i = 0; i < controls.length; i++) { |
| 1286 |
final Control control = controls [i]; |
| 1287 |
control.addListener(SWT.MenuDetect, new Listener() { |
| 1288 |
public void handleEvent(Event event) { |
| 1289 |
Menu menu = control.getMenu(); |
| 1290 |
if (menu != null && samplePopup) { |
| 1291 |
menu.dispose(); |
| 1292 |
menu = null; |
| 1293 |
} |
| 1294 |
if (menu == null && popupMenuButton.getSelection()) { |
| 1295 |
menu = new Menu(shell, SWT.POP_UP | (control.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT))); |
| 1296 |
MenuItem item = new MenuItem(menu, SWT.PUSH); |
| 1297 |
item.setText("Sample popup menu item"); |
| 1298 |
specialPopupMenuItems(menu, event); |
| 1299 |
control.setMenu(menu); |
| 1300 |
samplePopup = true; |
| 1301 |
} |
| 1302 |
} |
| 1303 |
}); |
| 1304 |
} |
| 1305 |
} |
| 1306 |
|
| 1307 |
protected void specialPopupMenuItems(final Menu menu, final Event event) { |
| 1308 |
} |
| 1309 |
|
| 1310 |
/** |
| 1311 |
* Disposes the "Example" widgets. |
| 1312 |
*/ |
| 1313 |
void disposeExampleWidgets () { |
| 1314 |
Widget [] widgets = getExampleWidgets (); |
| 1315 |
for (int i=0; i<widgets.length; i++) { |
| 1316 |
widgets [i].dispose (); |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
Image colorImage (Color color) { |
| 1321 |
Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE); |
| 1322 |
GC gc = new GC(image); |
| 1323 |
gc.setBackground(color); |
| 1324 |
Rectangle bounds = image.getBounds(); |
| 1325 |
gc.fillRectangle(0, 0, bounds.width, bounds.height); |
| 1326 |
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); |
| 1327 |
gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1); |
| 1328 |
gc.dispose(); |
| 1329 |
return image; |
| 1330 |
} |
| 1331 |
|
| 1332 |
Image fontImage (Font font) { |
| 1333 |
Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE); |
| 1334 |
GC gc = new GC(image); |
| 1335 |
Rectangle bounds = image.getBounds(); |
| 1336 |
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); |
| 1337 |
gc.fillRectangle(0, 0, bounds.width, bounds.height); |
| 1338 |
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); |
| 1339 |
gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1); |
| 1340 |
FontData data[] = font.getFontData(); |
| 1341 |
int style = data[0].getStyle(); |
| 1342 |
switch (style) { |
| 1343 |
case SWT.NORMAL: |
| 1344 |
gc.drawLine(3, 3, 3, 8); |
| 1345 |
gc.drawLine(4, 3, 7, 8); |
| 1346 |
gc.drawLine(8, 3, 8, 8); |
| 1347 |
break; |
| 1348 |
case SWT.BOLD: |
| 1349 |
gc.drawLine(3, 2, 3, 9); |
| 1350 |
gc.drawLine(4, 2, 4, 9); |
| 1351 |
gc.drawLine(5, 2, 7, 2); |
| 1352 |
gc.drawLine(5, 3, 8, 3); |
| 1353 |
gc.drawLine(5, 5, 7, 5); |
| 1354 |
gc.drawLine(5, 6, 7, 6); |
| 1355 |
gc.drawLine(5, 8, 8, 8); |
| 1356 |
gc.drawLine(5, 9, 7, 9); |
| 1357 |
gc.drawLine(7, 4, 8, 4); |
| 1358 |
gc.drawLine(7, 7, 8, 7); |
| 1359 |
break; |
| 1360 |
case SWT.ITALIC: |
| 1361 |
gc.drawLine(6, 2, 8, 2); |
| 1362 |
gc.drawLine(7, 3, 4, 8); |
| 1363 |
gc.drawLine(3, 9, 5, 9); |
| 1364 |
break; |
| 1365 |
case SWT.BOLD | SWT.ITALIC: |
| 1366 |
gc.drawLine(5, 2, 8, 2); |
| 1367 |
gc.drawLine(5, 3, 8, 3); |
| 1368 |
gc.drawLine(6, 4, 4, 7); |
| 1369 |
gc.drawLine(7, 4, 5, 7); |
| 1370 |
gc.drawLine(3, 8, 6, 8); |
| 1371 |
gc.drawLine(3, 9, 6, 9); |
| 1372 |
break; |
| 1373 |
} |
| 1374 |
gc.dispose(); |
| 1375 |
return image; |
| 1376 |
} |
| 1377 |
|
| 1378 |
/** |
| 1379 |
* Gets the list of custom event names. |
| 1380 |
* Subclasses override this method to allow adding of custom events. |
| 1381 |
* |
| 1382 |
* @return an array containing custom event names |
| 1383 |
* @see hookCustomListener |
| 1384 |
*/ |
| 1385 |
String [] getCustomEventNames () { |
| 1386 |
return new String [0]; |
| 1387 |
} |
| 1388 |
|
| 1389 |
/** |
| 1390 |
* Gets the default style for a widget |
| 1391 |
* |
| 1392 |
* @return the default style bit |
| 1393 |
*/ |
| 1394 |
int getDefaultStyle () { |
| 1395 |
if (ltrButtonRecreate != null && ltrButtonRecreate.getSelection()) { |
| 1396 |
return SWT.LEFT_TO_RIGHT; |
| 1397 |
} |
| 1398 |
if (rtlButtonRecreate != null && rtlButtonRecreate.getSelection()) { |
| 1399 |
return SWT.RIGHT_TO_LEFT; |
| 1400 |
} |
| 1401 |
if (rtlButtonSet != null && rtlButtonSet.getSelection()) { |
| 1402 |
return SWT.RIGHT_TO_LEFT; |
| 1403 |
} |
| 1404 |
if (ltrButtonSet != null && ltrButtonSet.getSelection()) { |
| 1405 |
return SWT.LEFT_TO_RIGHT; |
| 1406 |
} |
| 1407 |
return SWT.NONE; |
| 1408 |
} |
| 1409 |
|
| 1410 |
/** |
| 1411 |
* Gets the "Example" widgets. |
| 1412 |
* |
| 1413 |
* @return an array containing the example widgets |
| 1414 |
*/ |
| 1415 |
Widget [] getExampleWidgets () { |
| 1416 |
return new Widget [0]; |
| 1417 |
} |
| 1418 |
|
| 1419 |
/** |
| 1420 |
* Gets the "Example" controls. |
| 1421 |
* This is the subset of "Example" widgets that are controls. |
| 1422 |
* |
| 1423 |
* @return an array containing the example controls |
| 1424 |
*/ |
| 1425 |
Control [] getExampleControls () { |
| 1426 |
Widget [] widgets = getExampleWidgets (); |
| 1427 |
Control [] controls = new Control [0]; |
| 1428 |
for (int i = 0; i < widgets.length; i++) { |
| 1429 |
if (widgets[i] instanceof Control) { |
| 1430 |
Control[] newControls = new Control[controls.length + 1]; |
| 1431 |
System.arraycopy(controls, 0, newControls, 0, controls.length); |
| 1432 |
controls = newControls; |
| 1433 |
controls[controls.length - 1] = (Control)widgets[i]; |
| 1434 |
} |
| 1435 |
} |
| 1436 |
return controls; |
| 1437 |
} |
| 1438 |
|
| 1439 |
/** |
| 1440 |
* Gets the "Example" widget's items, if any. |
| 1441 |
* |
| 1442 |
* @return an array containing the example widget's items |
| 1443 |
*/ |
| 1444 |
Item [] getExampleWidgetItems () { |
| 1445 |
return new Item [0]; |
| 1446 |
} |
| 1447 |
|
| 1448 |
/** |
| 1449 |
* Gets the short text for the tab folder item. |
| 1450 |
* |
| 1451 |
* @return the short text for the tab item |
| 1452 |
*/ |
| 1453 |
String getShortTabText() { |
| 1454 |
return getTabText(); |
| 1455 |
} |
| 1456 |
|
| 1457 |
/** |
| 1458 |
* Gets the text for the tab folder item. |
| 1459 |
* |
| 1460 |
* @return the text for the tab item |
| 1461 |
*/ |
| 1462 |
String getTabText () { |
| 1463 |
return ""; |
| 1464 |
} |
| 1465 |
|
| 1466 |
/** |
| 1467 |
* Hooks all listeners to all example controls |
| 1468 |
* and example control items. |
| 1469 |
*/ |
| 1470 |
void hookExampleWidgetListeners () { |
| 1471 |
if (logging) { |
| 1472 |
Widget[] widgets = getExampleWidgets (); |
| 1473 |
for (int i = 0; i < widgets.length; i++) { |
| 1474 |
hookListeners (widgets [i]); |
| 1475 |
} |
| 1476 |
Item[] exampleItems = getExampleWidgetItems (); |
| 1477 |
for (int i = 0; i < exampleItems.length; i++) { |
| 1478 |
hookListeners (exampleItems [i]); |
| 1479 |
} |
| 1480 |
String [] customNames = getCustomEventNames (); |
| 1481 |
for (int i = 0; i < customNames.length; i++) { |
| 1482 |
if (eventsFilter [EVENT_INFO.length + i]) { |
| 1483 |
hookCustomListener (customNames[i]); |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} |
| 1487 |
} |
| 1488 |
|
| 1489 |
/** |
| 1490 |
* Hooks the custom listener specified by eventName. |
| 1491 |
* Subclasses override this method to add custom listeners. |
| 1492 |
* @see getCustomEventNames |
| 1493 |
*/ |
| 1494 |
void hookCustomListener (String eventName) { |
| 1495 |
} |
| 1496 |
|
| 1497 |
/** |
| 1498 |
* Hooks all listeners to the specified widget. |
| 1499 |
*/ |
| 1500 |
void hookListeners (Widget widget) { |
| 1501 |
if (logging) { |
| 1502 |
Listener listener = new Listener() { |
| 1503 |
public void handleEvent (Event event) { |
| 1504 |
log (event); |
| 1505 |
} |
| 1506 |
}; |
| 1507 |
for (int i = 0; i < EVENT_INFO.length; i++) { |
| 1508 |
if (eventsFilter [i]) { |
| 1509 |
widget.addListener (EVENT_INFO[i].type, listener); |
| 1510 |
} |
| 1511 |
} |
| 1512 |
} |
| 1513 |
} |
| 1514 |
|
| 1515 |
/** |
| 1516 |
* Logs an untyped event to the event console. |
| 1517 |
*/ |
| 1518 |
void log(Event event) { |
| 1519 |
int i = 0; |
| 1520 |
while (i < EVENT_INFO.length) { |
| 1521 |
if (EVENT_INFO[i].type == event.type) break; |
| 1522 |
i++; |
| 1523 |
} |
| 1524 |
String toString = EVENT_INFO[i].name + " [" + event.type + "]: "; |
| 1525 |
switch (event.type) { |
| 1526 |
case SWT.KeyDown: |
| 1527 |
case SWT.KeyUp: toString += new KeyEvent (event).toString (); break; |
| 1528 |
case SWT.MouseDown: |
| 1529 |
case SWT.MouseUp: |
| 1530 |
case SWT.MouseMove: |
| 1531 |
case SWT.MouseEnter: |
| 1532 |
case SWT.MouseExit: |
| 1533 |
case SWT.MouseDoubleClick: |
| 1534 |
case SWT.MouseWheel: |
| 1535 |
case SWT.MouseHover: toString += new MouseEvent (event).toString (); break; |
| 1536 |
case SWT.Paint: toString += new PaintEvent (event).toString (); break; |
| 1537 |
case SWT.Move: |
| 1538 |
case SWT.Resize: toString += new ControlEvent (event).toString (); break; |
| 1539 |
case SWT.Dispose: toString += new DisposeEvent (event).toString (); break; |
| 1540 |
case SWT.Selection: |
| 1541 |
case SWT.DefaultSelection: toString += new SelectionEvent (event).toString (); break; |
| 1542 |
case SWT.FocusIn: |
| 1543 |
case SWT.FocusOut: toString += new FocusEvent (event).toString (); break; |
| 1544 |
case SWT.Expand: |
| 1545 |
case SWT.Collapse: toString += new TreeEvent (event).toString (); break; |
| 1546 |
case SWT.Iconify: |
| 1547 |
case SWT.Deiconify: |
| 1548 |
case SWT.Close: |
| 1549 |
case SWT.Activate: |
| 1550 |
case SWT.Deactivate: toString += new ShellEvent (event).toString (); break; |
| 1551 |
case SWT.Show: |
| 1552 |
case SWT.Hide: toString += (event.widget instanceof Menu) ? new MenuEvent (event).toString () : event.toString(); break; |
| 1553 |
case SWT.Modify: toString += new ModifyEvent (event).toString (); break; |
| 1554 |
case SWT.Verify: toString += new VerifyEvent (event).toString (); break; |
| 1555 |
case SWT.Help: toString += new HelpEvent (event).toString (); break; |
| 1556 |
case SWT.Arm: toString += new ArmEvent (event).toString (); break; |
| 1557 |
case SWT.Traverse: toString += new TraverseEvent (event).toString (); break; |
| 1558 |
case SWT.HardKeyDown: |
| 1559 |
case SWT.HardKeyUp: |
| 1560 |
case SWT.DragDetect: |
| 1561 |
case SWT.MenuDetect: |
| 1562 |
case SWT.SetData: |
| 1563 |
default: toString += event.toString (); |
| 1564 |
} |
| 1565 |
log (toString); |
| 1566 |
|
| 1567 |
/* Return values for event fields. */ |
| 1568 |
int mask = EVENT_INFO[i].setFields; |
| 1569 |
if (!ignore && mask != 0) { |
| 1570 |
Event setFieldsEvent = EVENT_INFO[i].event; |
| 1571 |
if ((mask & DOIT) != 0) event.doit = setFieldsEvent.doit; |
| 1572 |
if ((mask & DETAIL) != 0) event.detail = setFieldsEvent.detail; |
| 1573 |
if ((mask & TEXT) != 0) event.text = setFieldsEvent.text; |
| 1574 |
if ((mask & X) != 0) event.x = setFieldsEvent.x; |
| 1575 |
if ((mask & Y) != 0) event.y = setFieldsEvent.y; |
| 1576 |
if ((mask & WIDTH) != 0) event.width = setFieldsEvent.width; |
| 1577 |
if ((mask & HEIGHT) != 0) event.height = setFieldsEvent.height; |
| 1578 |
eventConsole.append (ControlExample.getResourceString("Returning")); |
| 1579 |
ignore = true; |
| 1580 |
log (event); |
| 1581 |
ignore = false; |
| 1582 |
} |
| 1583 |
} |
| 1584 |
|
| 1585 |
/** |
| 1586 |
* Logs a string to the event console. |
| 1587 |
*/ |
| 1588 |
void log (String string) { |
| 1589 |
if (!eventConsole.isDisposed()) { |
| 1590 |
eventConsole.append (string); |
| 1591 |
eventConsole.append ("\n"); |
| 1592 |
} |
| 1593 |
} |
| 1594 |
|
| 1595 |
/** |
| 1596 |
* Logs a typed event to the event console. |
| 1597 |
*/ |
| 1598 |
void log (String eventName, TypedEvent event) { |
| 1599 |
log (eventName + ": " + event.toString ()); |
| 1600 |
} |
| 1601 |
|
| 1602 |
/** |
| 1603 |
* Recreates the "Example" widgets. |
| 1604 |
*/ |
| 1605 |
void recreateExampleWidgets () { |
| 1606 |
disposeExampleWidgets (); |
| 1607 |
createExampleWidgets (); |
| 1608 |
hookExampleWidgetListeners (); |
| 1609 |
setExampleWidgetState (); |
| 1610 |
} |
| 1611 |
|
| 1612 |
/** |
| 1613 |
* Sets the foreground color, background color, and font |
| 1614 |
* of the "Example" widgets to their default settings. |
| 1615 |
* Subclasses may extend in order to reset other colors |
| 1616 |
* and fonts to default settings as well. |
| 1617 |
*/ |
| 1618 |
void resetColorsAndFonts () { |
| 1619 |
Color oldColor = foregroundColor; |
| 1620 |
foregroundColor = null; |
| 1621 |
setExampleWidgetForeground (); |
| 1622 |
if (oldColor != null) oldColor.dispose(); |
| 1623 |
oldColor = backgroundColor; |
| 1624 |
backgroundColor = null; |
| 1625 |
setExampleWidgetBackground (); |
| 1626 |
if (oldColor != null) oldColor.dispose(); |
| 1627 |
Font oldFont = font; |
| 1628 |
font = null; |
| 1629 |
setExampleWidgetFont (); |
| 1630 |
setExampleWidgetSize (); |
| 1631 |
if (oldFont != null) oldFont.dispose(); |
| 1632 |
} |
| 1633 |
|
| 1634 |
boolean rtlSupport() { |
| 1635 |
return RTL_SUPPORT_ENABLE; |
| 1636 |
} |
| 1637 |
|
| 1638 |
/** |
| 1639 |
* Sets the background color of the "Example" widgets' parent. |
| 1640 |
*/ |
| 1641 |
void setExampleGroupBackgroundColor () { |
| 1642 |
if (backgroundModeGroup == null) return; |
| 1643 |
exampleGroup.setBackground (backgroundModeColorButton.getSelection () ? display.getSystemColor(SWT.COLOR_BLUE) : null); |
| 1644 |
} |
| 1645 |
/** |
| 1646 |
* Sets the background image of the "Example" widgets' parent. |
| 1647 |
*/ |
| 1648 |
void setExampleGroupBackgroundImage () { |
| 1649 |
if (backgroundModeGroup == null) return; |
| 1650 |
exampleGroup.setBackgroundImage (backgroundModeImageButton.getSelection () ? instance.images[ControlExample.ciParentBackground] : null); |
| 1651 |
} |
| 1652 |
|
| 1653 |
/** |
| 1654 |
* Sets the background mode of the "Example" widgets' parent. |
| 1655 |
*/ |
| 1656 |
void setExampleGroupBackgroundMode () { |
| 1657 |
if (backgroundModeGroup == null) return; |
| 1658 |
String modeString = backgroundModeCombo.getText (); |
| 1659 |
int mode = SWT.INHERIT_NONE; |
| 1660 |
if (modeString.equals("SWT.INHERIT_DEFAULT")) mode = SWT.INHERIT_DEFAULT; |
| 1661 |
if (modeString.equals("SWT.INHERIT_FORCE")) mode = SWT.INHERIT_FORCE; |
| 1662 |
exampleGroup.setBackgroundMode (mode); |
| 1663 |
} |
| 1664 |
|
| 1665 |
/** |
| 1666 |
* Sets the background color of the "Example" widgets. |
| 1667 |
*/ |
| 1668 |
void setExampleWidgetBackground () { |
| 1669 |
if (colorAndFontTable == null) return; // user cannot change color/font on this tab |
| 1670 |
Control [] controls = getExampleControls (); |
| 1671 |
if (!instance.startup) { |
| 1672 |
for (int i = 0; i < controls.length; i++) { |
| 1673 |
controls[i].setBackground (backgroundColor); |
| 1674 |
} |
| 1675 |
} |
| 1676 |
// Set the background color item's image to match the background color of the example widget(s). |
| 1677 |
Color color = backgroundColor; |
| 1678 |
if (controls.length == 0) return; |
| 1679 |
if (color == null) color = controls [0].getBackground (); |
| 1680 |
TableItem item = colorAndFontTable.getItem(BACKGROUND_COLOR); |
| 1681 |
Image oldImage = item.getImage(); |
| 1682 |
if (oldImage != null) oldImage.dispose(); |
| 1683 |
item.setImage (colorImage (color)); |
| 1684 |
} |
| 1685 |
|
| 1686 |
/** |
| 1687 |
* Sets the enabled state of the "Example" widgets. |
| 1688 |
*/ |
| 1689 |
void setExampleWidgetEnabled () { |
| 1690 |
Control [] controls = getExampleControls (); |
| 1691 |
for (int i=0; i<controls.length; i++) { |
| 1692 |
controls [i].setEnabled (enabledButton.getSelection ()); |
| 1693 |
} |
| 1694 |
} |
| 1695 |
|
| 1696 |
/** |
| 1697 |
* Sets the font of the "Example" widgets. |
| 1698 |
*/ |
| 1699 |
void setExampleWidgetFont () { |
| 1700 |
if (colorAndFontTable == null) return; // user cannot change color/font on this tab |
| 1701 |
Control [] controls = getExampleControls (); |
| 1702 |
if (!instance.startup) { |
| 1703 |
for (int i = 0; i < controls.length; i++) { |
| 1704 |
controls[i].setFont(font); |
| 1705 |
} |
| 1706 |
} |
| 1707 |
/* Set the font item's image and font to match the font of the example widget(s). */ |
| 1708 |
Font ft = font; |
| 1709 |
if (controls.length == 0) return; |
| 1710 |
if (ft == null) ft = controls [0].getFont (); |
| 1711 |
TableItem item = colorAndFontTable.getItem(FONT); |
| 1712 |
Image oldImage = item.getImage(); |
| 1713 |
if (oldImage != null) oldImage.dispose(); |
| 1714 |
item.setImage (fontImage (ft)); |
| 1715 |
item.setFont(ft); |
| 1716 |
colorAndFontTable.layout (); |
| 1717 |
} |
| 1718 |
|
| 1719 |
/** |
| 1720 |
* Sets the foreground color of the "Example" widgets. |
| 1721 |
*/ |
| 1722 |
void setExampleWidgetForeground () { |
| 1723 |
if (colorAndFontTable == null) return; // user cannot change color/font on this tab |
| 1724 |
Control [] controls = getExampleControls (); |
| 1725 |
if (!instance.startup) { |
| 1726 |
for (int i = 0; i < controls.length; i++) { |
| 1727 |
controls[i].setForeground (foregroundColor); |
| 1728 |
} |
| 1729 |
} |
| 1730 |
/* Set the foreground color item's image to match the foreground color of the example widget(s). */ |
| 1731 |
Color color = foregroundColor; |
| 1732 |
if (controls.length == 0) return; |
| 1733 |
if (color == null) color = controls [0].getForeground (); |
| 1734 |
TableItem item = colorAndFontTable.getItem(FOREGROUND_COLOR); |
| 1735 |
Image oldImage = item.getImage(); |
| 1736 |
if (oldImage != null) oldImage.dispose(); |
| 1737 |
item.setImage (colorImage(color)); |
| 1738 |
} |
| 1739 |
|
| 1740 |
/** |
| 1741 |
* Sets the size of the "Example" widgets. |
| 1742 |
*/ |
| 1743 |
void setExampleWidgetSize () { |
| 1744 |
int size = SWT.DEFAULT; |
| 1745 |
if (preferredButton == null) return; |
| 1746 |
if (preferredButton.getSelection()) size = SWT.DEFAULT; |
| 1747 |
if (tooSmallButton.getSelection()) size = TOO_SMALL_SIZE; |
| 1748 |
if (smallButton.getSelection()) size = SMALL_SIZE; |
| 1749 |
if (largeButton.getSelection()) size = LARGE_SIZE; |
| 1750 |
Control [] controls = getExampleControls (); |
| 1751 |
for (int i=0; i<controls.length; i++) { |
| 1752 |
GridData gridData = new GridData(size, size); |
| 1753 |
gridData.grabExcessHorizontalSpace = fillHButton.getSelection(); |
| 1754 |
gridData.grabExcessVerticalSpace = fillVButton.getSelection(); |
| 1755 |
gridData.horizontalAlignment = fillHButton.getSelection() ? SWT.FILL : SWT.LEFT; |
| 1756 |
gridData.verticalAlignment = fillVButton.getSelection() ? SWT.FILL : SWT.TOP; |
| 1757 |
controls [i].setLayoutData (gridData); |
| 1758 |
} |
| 1759 |
tabFolderPage.layout (controls); |
| 1760 |
} |
| 1761 |
|
| 1762 |
/** |
| 1763 |
* Sets the state of the "Example" widgets. Subclasses |
| 1764 |
* may extend this method to set "Example" widget state |
| 1765 |
* that is specific to the widget. |
| 1766 |
*/ |
| 1767 |
void setExampleWidgetState () { |
| 1768 |
setExampleWidgetBackground (); |
| 1769 |
setExampleWidgetForeground (); |
| 1770 |
setExampleWidgetFont (); |
| 1771 |
if (!instance.startup) { |
| 1772 |
setExampleWidgetEnabled (); |
| 1773 |
setExampleWidgetVisibility (); |
| 1774 |
setExampleGroupBackgroundMode (); |
| 1775 |
setExampleGroupBackgroundColor (); |
| 1776 |
setExampleGroupBackgroundImage (); |
| 1777 |
setExampleWidgetBackgroundImage (); |
| 1778 |
setExampleWidgetPopupMenu (); |
| 1779 |
setExampleWidgetSize (); |
| 1780 |
} |
| 1781 |
//TEMPORARY CODE |
| 1782 |
// Control [] controls = getExampleControls (); |
| 1783 |
// for (int i=0; i<controls.length; i++) { |
| 1784 |
// log ("Control=" + controls [i] + ", border width=" + controls [i].getBorderWidth ()); |
| 1785 |
// } |
| 1786 |
} |
| 1787 |
|
| 1788 |
/** |
| 1789 |
* Sets the visibility of the "Example" widgets. |
| 1790 |
*/ |
| 1791 |
void setExampleWidgetVisibility () { |
| 1792 |
Control [] controls = getExampleControls (); |
| 1793 |
for (int i=0; i<controls.length; i++) { |
| 1794 |
controls [i].setVisible (visibleButton.getSelection ()); |
| 1795 |
} |
| 1796 |
} |
| 1797 |
|
| 1798 |
/** |
| 1799 |
* Sets the background image of the "Example" widgets. |
| 1800 |
*/ |
| 1801 |
void setExampleWidgetBackgroundImage () { |
| 1802 |
if (backgroundImageButton != null && backgroundImageButton.isDisposed()) return; |
| 1803 |
Control [] controls = getExampleControls (); |
| 1804 |
for (int i=0; i<controls.length; i++) { |
| 1805 |
controls [i].setBackgroundImage (backgroundImageButton.getSelection () ? instance.images[ControlExample.ciBackground] : null); |
| 1806 |
} |
| 1807 |
} |
| 1808 |
|
| 1809 |
/** |
| 1810 |
* Splits the given string around matches of the given character. |
| 1811 |
* |
| 1812 |
* This subset of java.lang.String.split(String regex) |
| 1813 |
* uses only code that can be run on CLDC platforms. |
| 1814 |
*/ |
| 1815 |
String [] split (String string, char ch) { |
| 1816 |
String [] result = new String[0]; |
| 1817 |
int start = 0; |
| 1818 |
int length = string.length(); |
| 1819 |
while (start < length) { |
| 1820 |
int end = string.indexOf(ch, start); |
| 1821 |
if (end == -1) end = length; |
| 1822 |
String substr = string.substring(start, end); |
| 1823 |
String [] newResult = new String[result.length + 1]; |
| 1824 |
System.arraycopy(result, 0, newResult, 0, result.length); |
| 1825 |
newResult [result.length] = substr; |
| 1826 |
result = newResult; |
| 1827 |
start = end + 1; |
| 1828 |
} |
| 1829 |
return result; |
| 1830 |
} |
| 1831 |
} |