| 1 |
/******************************************************************************* |
|---|
| 2 |
* Copyright (c) 2000, 2003 IBM Corporation and others. |
|---|
| 3 |
* All rights reserved. This program and the accompanying materials |
|---|
| 4 |
* are made available under the terms of the Common Public License v1.0 |
|---|
| 5 |
* which accompanies this distribution, and is available at |
|---|
| 6 |
* http://www.eclipse.org/legal/cpl-v10.html |
|---|
| 7 |
* |
|---|
| 8 |
* Contributors: |
|---|
| 9 |
* IBM Corporation - initial API and implementation |
|---|
| 10 |
*******************************************************************************/ |
|---|
| 11 |
module controlexample.controlexample; |
|---|
| 12 |
|
|---|
| 13 |
private { |
|---|
| 14 |
import swt.all; |
|---|
| 15 |
|
|---|
| 16 |
import controlexample.buttontab; |
|---|
| 17 |
import controlexample.canvastab; |
|---|
| 18 |
import controlexample.combotab; |
|---|
| 19 |
import controlexample.controlexample; |
|---|
| 20 |
import controlexample.coolbartab; |
|---|
| 21 |
import controlexample.dialogtab; |
|---|
| 22 |
import controlexample.grouptab; |
|---|
| 23 |
import controlexample.labeltab; |
|---|
| 24 |
import controlexample.listtab; |
|---|
| 25 |
import controlexample.progressbartab; |
|---|
| 26 |
import controlexample.sashtab; |
|---|
| 27 |
import controlexample.shelltab; |
|---|
| 28 |
import controlexample.slidertab; |
|---|
| 29 |
import controlexample.tab; |
|---|
| 30 |
import controlexample.tabfoldertab; |
|---|
| 31 |
import controlexample.tabletab; |
|---|
| 32 |
import controlexample.texttab; |
|---|
| 33 |
import controlexample.toolbartab; |
|---|
| 34 |
import controlexample.treetab; |
|---|
| 35 |
|
|---|
| 36 |
import controlexample.ccombotab; |
|---|
| 37 |
import controlexample.ctabfoldertab; |
|---|
| 38 |
import controlexample.clabeltab; |
|---|
| 39 |
import controlexample.sashformtab; |
|---|
| 40 |
import controlexample.styledtexttab; |
|---|
| 41 |
import controlexample.tabletreetab; |
|---|
| 42 |
|
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
public class ControlExample { |
|---|
| 46 |
// private static ResourceBundle resourceBundle = |
|---|
| 47 |
// ResourceBundle.getBundle("examples_control"); |
|---|
| 48 |
private ShellTab shellTab; |
|---|
| 49 |
private TabFolder tabFolder; |
|---|
| 50 |
Image images[]; |
|---|
| 51 |
|
|---|
| 52 |
static int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2; |
|---|
| 53 |
static String[] imageLocations = [ |
|---|
| 54 |
"CLOSEDFOLDER", |
|---|
| 55 |
"OPENFOLDER", |
|---|
| 56 |
"TARGET" |
|---|
| 57 |
]; |
|---|
| 58 |
|
|---|
| 59 |
BOOL startup = true; |
|---|
| 60 |
|
|---|
| 61 |
static String[String] stringRes; |
|---|
| 62 |
|
|---|
| 63 |
static void intStringRes(){ |
|---|
| 64 |
if(stringRes.length > 0) |
|---|
| 65 |
return; |
|---|
| 66 |
stringRes["error.CouldNotLoadResources"] = "Unable to load resources"; |
|---|
| 67 |
stringRes["window.title"] = "SWT Controls"; |
|---|
| 68 |
stringRes["custom.window.title"] = "SWT Custom Controls"; |
|---|
| 69 |
stringRes["Text_Buttons"] = "Text Buttons"; |
|---|
| 70 |
stringRes["Size"] = "Size"; |
|---|
| 71 |
stringRes["Alignment"] = "Alignment"; |
|---|
| 72 |
stringRes["Left"] = "Left"; |
|---|
| 73 |
stringRes["Right"] = "Right"; |
|---|
| 74 |
stringRes["Up"] = "Up"; |
|---|
| 75 |
stringRes["Down"] = "Down"; |
|---|
| 76 |
stringRes["Center"] = "Center"; |
|---|
| 77 |
stringRes["One"] = "One"; |
|---|
| 78 |
stringRes["Two"] = "Two"; |
|---|
| 79 |
stringRes["Three"] = "Three"; |
|---|
| 80 |
stringRes["Image_Buttons"] = "Image Buttons"; |
|---|
| 81 |
stringRes["Control_Example"] = "Control Example"; |
|---|
| 82 |
stringRes["Parameters"] = "Parameters"; |
|---|
| 83 |
stringRes["Other"] = "Other"; |
|---|
| 84 |
stringRes["Enabled"] = "Enabled"; |
|---|
| 85 |
stringRes["Visible"] = "Visible"; |
|---|
| 86 |
stringRes["Preferred"] = "Preferred"; |
|---|
| 87 |
stringRes["Styles"] = "Styles"; |
|---|
| 88 |
stringRes["Listeners"] = "Listeners"; |
|---|
| 89 |
stringRes["Select_Listeners"] = "Select Listeners"; |
|---|
| 90 |
stringRes["Listen"] = "Listen"; |
|---|
| 91 |
stringRes["Clear"] = "Clear"; |
|---|
| 92 |
stringRes["Select_All"] = "Select All"; |
|---|
| 93 |
stringRes["Deselect_All"] = "Deselect All"; |
|---|
| 94 |
stringRes["OK"] = "OK"; |
|---|
| 95 |
stringRes["FillDamage"] = "Fill Damaged Area With Color"; |
|---|
| 96 |
stringRes["Title_Text"] = "Title Text"; |
|---|
| 97 |
stringRes["Text_Labels"] = "Text Labels"; |
|---|
| 98 |
stringRes["Image_Labels"] = "Image Labels"; |
|---|
| 99 |
stringRes["Custom_Labels"] = "Custom Labels"; |
|---|
| 100 |
stringRes["Custom_Combo"] = "Custom Combo"; |
|---|
| 101 |
stringRes["One_Two_Three"] = "One Two Three"; |
|---|
| 102 |
stringRes["Text_ToolBar"] = "Text ToolBar"; |
|---|
| 103 |
stringRes["Image_ToolBar"] = "Image ToolBar"; |
|---|
| 104 |
stringRes["Maximum"] = "Maximum"; |
|---|
| 105 |
stringRes["Minimum"] = "Minimum"; |
|---|
| 106 |
stringRes["Selection"] = "Selection"; |
|---|
| 107 |
stringRes["Increment"] = "Increment"; |
|---|
| 108 |
stringRes["Page_Increment"] = "Page Increment"; |
|---|
| 109 |
stringRes["Thumb"] = "Thumb"; |
|---|
| 110 |
stringRes["Tree_With_Images"] = "Tree With Images"; |
|---|
| 111 |
stringRes["Dialog_Type"] = "Dialog Type"; |
|---|
| 112 |
stringRes["Create_Dialog"] = "Create Dialog"; |
|---|
| 113 |
stringRes["Button_Styles"] = "Button Styles"; |
|---|
| 114 |
stringRes["Icon_Styles"] = "Icon Styles"; |
|---|
| 115 |
stringRes["Modal_Styles"] = "Modal Styles"; |
|---|
| 116 |
stringRes["File_Dialog_Styles"] = "File Dialog Styles"; |
|---|
| 117 |
stringRes["Item_Styles"] = "Item Styles"; |
|---|
| 118 |
stringRes["Dialog_Result"] = "Dialog Result"; |
|---|
| 119 |
stringRes["ColorDialog"] = "ColorDialog"; |
|---|
| 120 |
stringRes["DirectoryDialog"] = "DirectoryDialog"; |
|---|
| 121 |
stringRes["FileDialog"] = "FileDialog"; |
|---|
| 122 |
stringRes["FontDialog"] = "FontDialog"; |
|---|
| 123 |
stringRes["PrintDialog"] = "PrintDialog"; |
|---|
| 124 |
stringRes["MessageBox"] = "MessageBox"; |
|---|
| 125 |
stringRes["Multi_line"] = "A multi line text widget."; |
|---|
| 126 |
stringRes["Example_string"] = "The quick brown fox jumps over the lazy dog."; |
|---|
| 127 |
stringRes["Header_Visible"] = "Header Visible"; |
|---|
| 128 |
stringRes["Lines_Visible"] = "Lines Visible"; |
|---|
| 129 |
stringRes["Locked"] = "Locked"; |
|---|
| 130 |
stringRes["Node_1"] = "Node 1"; |
|---|
| 131 |
stringRes["Node_2"] = "Node 2"; |
|---|
| 132 |
stringRes["Node_3"] = "Node 3"; |
|---|
| 133 |
stringRes["Node_4"] = "Node 4"; |
|---|
| 134 |
stringRes["Node_1_1"] = "Node 1.1"; |
|---|
| 135 |
stringRes["Node_2_1"] = "Node 2.1"; |
|---|
| 136 |
stringRes["Node_3_1"] = "Node 3.1"; |
|---|
| 137 |
stringRes["Node_2_2"] = "Node 2.2"; |
|---|
| 138 |
stringRes["Node_2_2_1"] = "Node 2.2.1"; |
|---|
| 139 |
stringRes["Parent"] = "Parent"; |
|---|
| 140 |
stringRes["No_Parent"] = "No Parent"; |
|---|
| 141 |
stringRes["Decoration_Styles"] = "Decoration Styles"; |
|---|
| 142 |
stringRes["Create_Shell"] = "Create Shell"; |
|---|
| 143 |
stringRes["Close_All_Shells"] = "Close All Shells"; |
|---|
| 144 |
stringRes["Push"] = "Push"; |
|---|
| 145 |
stringRes["Radio"] = "Radio"; |
|---|
| 146 |
stringRes["Check"] = "Check"; |
|---|
| 147 |
stringRes["Drop_Down"] = "Drop Down"; |
|---|
| 148 |
stringRes["Images_failed"] = "Warning: Failed to load images"; |
|---|
| 149 |
stringRes["readme_txt"] = "readme.txt"; |
|---|
| 150 |
stringRes["Index"] = "Index:"; |
|---|
| 151 |
stringRes["Title"] = "Title:"; |
|---|
| 152 |
stringRes["Close"] = "Close"; |
|---|
| 153 |
stringRes["Result"] = "Result: {0}"; |
|---|
| 154 |
stringRes["FilterName_0"] = "D Source Files"; |
|---|
| 155 |
stringRes["FilterName_1"] = "Text Files"; |
|---|
| 156 |
stringRes["FilterName_2"] = "Batch Files"; |
|---|
| 157 |
stringRes["FilterName_3"] = "Doc Files"; |
|---|
| 158 |
stringRes["FilterName_4"] = "All Files"; |
|---|
| 159 |
stringRes["TableTitle_0"] = "Name"; |
|---|
| 160 |
stringRes["TableTitle_1"] = "Type"; |
|---|
| 161 |
stringRes["TableTitle_2"] = "Size"; |
|---|
| 162 |
stringRes["TableTitle_3"] = "Modified"; |
|---|
| 163 |
stringRes["TableLine0_0"] = "<empty>"; |
|---|
| 164 |
stringRes["TableLine0_1"] = "classes"; |
|---|
| 165 |
stringRes["TableLine0_2"] = "0"; |
|---|
| 166 |
stringRes["TableLine0_3"] = "today"; |
|---|
| 167 |
stringRes["TableLine1_0"] = "<empty>"; |
|---|
| 168 |
stringRes["TableLine1_1"] = "databases"; |
|---|
| 169 |
stringRes["TableLine1_2"] = "2556"; |
|---|
| 170 |
stringRes["TableLine1_3"] = "<empty>"; |
|---|
| 171 |
stringRes["TableLine2_0"] = "<empty>"; |
|---|
| 172 |
stringRes["TableLine2_1"] = "images"; |
|---|
| 173 |
stringRes["TableLine2_2"] = "91571"; |
|---|
| 174 |
stringRes["TableLine2_3"] = "yesterday"; |
|---|
| 175 |
stringRes["ListData0_0"] = "Line 1"; |
|---|
| 176 |
stringRes["ListData0_1"] = "Line 2"; |
|---|
| 177 |
stringRes["ListData0_2"] = "Line 3"; |
|---|
| 178 |
stringRes["ListData0_3"] = "Line 4"; |
|---|
| 179 |
stringRes["ListData0_4"] = "Line 5"; |
|---|
| 180 |
stringRes["ListData0_5"] = "Line 6"; |
|---|
| 181 |
stringRes["ListData0_6"] = "Line 7"; |
|---|
| 182 |
stringRes["ListData0_7"] = "Line 8"; |
|---|
| 183 |
stringRes["ListData0_8"] = "Longest Line In List"; |
|---|
| 184 |
stringRes["ListData1_0"] = "Apples"; |
|---|
| 185 |
stringRes["ListData1_1"] = "Oranges"; |
|---|
| 186 |
stringRes["ListData1_2"] = "Bananas"; |
|---|
| 187 |
stringRes["ListData1_3"] = "Grapefruit"; |
|---|
| 188 |
stringRes["ListData1_4"] = "Peaches"; |
|---|
| 189 |
stringRes["ListData1_5"] = "Kiwi"; |
|---|
| 190 |
stringRes["ListData1_6"] = "Apricots"; |
|---|
| 191 |
stringRes["ListData1_7"] = "Strawberries"; |
|---|
| 192 |
stringRes["ListData1_8"] = "The Longest String"; |
|---|
| 193 |
stringRes["DropDownData_0"] = "Apples"; |
|---|
| 194 |
stringRes["DropDownData_1"] = "Oranges"; |
|---|
| 195 |
stringRes["DropDownData_2"] = ""; |
|---|
| 196 |
stringRes["DropDownData_3"] = "Grapefruit"; |
|---|
| 197 |
stringRes["DropDownData_4"] = "Peaches"; |
|---|
| 198 |
stringRes["DropDownData_5"] = "Kiwi"; |
|---|
| 199 |
stringRes["DropDownData_6"] = ""; |
|---|
| 200 |
stringRes["DropDownData_7"] = "Strawberries"; |
|---|
| 201 |
stringRes["DropDownData_8"] = "The Longest String"; |
|---|
| 202 |
stringRes["Colors"] = "Colors and Font"; |
|---|
| 203 |
stringRes["Table_Item_Colors"] = "Row 0 Colors and Font"; |
|---|
| 204 |
stringRes["Tree_Item_Colors"] = "Node 1 Colors and Font"; |
|---|
| 205 |
stringRes["CTab_Item_Colors"] = "CTab 0 Font"; |
|---|
| 206 |
stringRes["Background_Color"] = "Background Color"; |
|---|
| 207 |
stringRes["Foreground_Color"] = "Foreground Color"; |
|---|
| 208 |
stringRes["Font"] = "&Font..."; |
|---|
| 209 |
stringRes["Defaults"] = "&Defaults"; |
|---|
| 210 |
stringRes["Wrap_Text"] = "Jack and Jill went up the hill to fetch a pail of water, \r\nJack fell down and broke his crown and Jill came tumbling after!"; |
|---|
| 211 |
stringRes["Foreground_Style"] = "Foreground Style"; |
|---|
| 212 |
stringRes["Background_Style"] = "Background Style"; |
|---|
| 213 |
stringRes["StyledText_Styles"] = "Text Styles"; |
|---|
| 214 |
stringRes["StyledText_Style_Instructions"] = "Select text, then style."; |
|---|
| 215 |
stringRes["Bold"] = "Bold"; |
|---|
| 216 |
stringRes["Italic"] = "Italic"; |
|---|
| 217 |
stringRes["Fill"] = "Horizontal Fill"; |
|---|
| 218 |
stringRes["TabItem1_0"] = "Tab 0"; |
|---|
| 219 |
stringRes["TabItem1_1"] = "Tab 1"; |
|---|
| 220 |
stringRes["TabItem1_2"] = "Tab 2"; |
|---|
| 221 |
stringRes["TabItem_content"] = "TabItem Content"; |
|---|
| 222 |
stringRes["CTabItem1_0"] = "CTabItem 0"; |
|---|
| 223 |
stringRes["CTabItem1_1"] = "CTabItem 1"; |
|---|
| 224 |
stringRes["CTabItem1_2"] = "CTabItem 2 has a long name"; |
|---|
| 225 |
stringRes["CItem_Colors"] = "CTabItem Colors"; |
|---|
| 226 |
stringRes["CTabItem_content"] = "CTabItem Content"; |
|---|
| 227 |
stringRes["Set_Simple_Tabs"] = "Simple Tabs"; |
|---|
| 228 |
stringRes["Set_Image"] = "Image"; |
|---|
| 229 |
stringRes["TableTree_column"] = "Column"; |
|---|
| 230 |
stringRes["MenuItem_Cut"] = "Cu&t Ctrl+X"; |
|---|
| 231 |
stringRes["MenuItem_Copy"] = "&Copy Ctrl+C"; |
|---|
| 232 |
stringRes["MenuItem_Paste"] = "&Paste Ctrl+V"; |
|---|
| 233 |
stringRes["MenuItem_SelectAll"] = "Select &All Ctrl+A"; |
|---|
| 234 |
stringRes["Orientation"] = "Orientation"; |
|---|
| 235 |
stringRes["Default"] = "Default (Inherit)"; |
|---|
| 236 |
|
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
/** |
|---|
| 240 |
* Creates an inst of a ControlExample embedded inside |
|---|
| 241 |
* the supplied parent Composite. |
|---|
| 242 |
* |
|---|
| 243 |
* @param parent the container of the example |
|---|
| 244 |
*/ |
|---|
| 245 |
public this(Composite parent) { |
|---|
| 246 |
ResourceManager.registerResourceUser(parent); |
|---|
| 247 |
parent.getShell().setImage(ResourceManager.getImage("DLOGO", "BMPFILE")); |
|---|
| 248 |
intStringRes(); |
|---|
| 249 |
initResources(); |
|---|
| 250 |
tabFolder = new TabFolder (parent, SWT.NONE); |
|---|
| 251 |
Tab [] tabs = createTabs(); |
|---|
| 252 |
for (int i=0; i<tabs.length; i++) { |
|---|
| 253 |
TabItem item = new TabItem (tabFolder, SWT.NONE); |
|---|
| 254 |
item.setText (tabs [i].getTabText ()); |
|---|
| 255 |
item.setControl (tabs [i].createTabFolderPage (tabFolder)); |
|---|
| 256 |
item.setData (tabs [i]); |
|---|
| 257 |
} |
|---|
| 258 |
startup = false; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
/** |
|---|
| 262 |
* Answers the set of example Tabs |
|---|
| 263 |
*/ |
|---|
| 264 |
Tab[] createTabs() { |
|---|
| 265 |
Tab[] tabs; |
|---|
| 266 |
tabs ~= new ButtonTab (this); |
|---|
| 267 |
tabs ~= new CanvasTab (this); |
|---|
| 268 |
tabs ~= new ComboTab (this); |
|---|
| 269 |
tabs ~= new CoolBarTab (this); |
|---|
| 270 |
tabs ~= new DialogTab (this); |
|---|
| 271 |
tabs ~= new GroupTab (this); |
|---|
| 272 |
tabs ~= new LabelTab (this); |
|---|
| 273 |
tabs ~= new ListTab (this); |
|---|
| 274 |
tabs ~= new ProgressBarTab (this); |
|---|
| 275 |
tabs ~= new SashTab (this); |
|---|
| 276 |
tabs ~= (shellTab = new ShellTab(this)); |
|---|
| 277 |
tabs ~= new SliderTab (this); |
|---|
| 278 |
tabs ~= new TabFolderTab (this); |
|---|
| 279 |
tabs ~= new TableTab (this); |
|---|
| 280 |
tabs ~= new TextTab (this); |
|---|
| 281 |
tabs ~= new ToolBarTab (this); |
|---|
| 282 |
tabs ~= new TreeTab (this); |
|---|
| 283 |
tabs ~= new CComboTab (this); |
|---|
| 284 |
tabs ~= new CLabelTab (this); |
|---|
| 285 |
tabs ~= new CTabFolderTab (this); |
|---|
| 286 |
tabs ~= new SashFormTab (this); |
|---|
| 287 |
// tabs ~= new StyledTextTab (this); |
|---|
| 288 |
tabs ~= new TableTreeTab (this); |
|---|
| 289 |
return tabs; |
|---|
| 290 |
} |
|---|
| 291 |
|
|---|
| 292 |
/** |
|---|
| 293 |
* Disposes of all resources associated with a particular |
|---|
| 294 |
* inst of the ControlExample. |
|---|
| 295 |
*/ |
|---|
| 296 |
public void dispose() { |
|---|
| 297 |
/* |
|---|
| 298 |
* Destroy any shells that may have been created |
|---|
| 299 |
* by the Shells tab. When a shell is disposed, |
|---|
| 300 |
* all child shells are also disposed. Therefore |
|---|
| 301 |
* it is necessary to check for disposed shells |
|---|
| 302 |
* in the shells list to avoid disposing a shell |
|---|
| 303 |
* twice. |
|---|
| 304 |
*/ |
|---|
| 305 |
if (shellTab !== null) shellTab.closeAllShells (); |
|---|
| 306 |
shellTab = null; |
|---|
| 307 |
tabFolder = null; |
|---|
| 308 |
freeResources(); |
|---|
| 309 |
} |
|---|
| 310 |
|
|---|
| 311 |
/** |
|---|
| 312 |
* Frees the resources |
|---|
| 313 |
*/ |
|---|
| 314 |
// <Shawn> ResourceManager will freeResources automatically |
|---|
| 315 |
void freeResources() { |
|---|
| 316 |
// if (images !== null) { |
|---|
| 317 |
// for (int i = 0; i < images.length; ++i) { |
|---|
| 318 |
// Image image = images[i]; |
|---|
| 319 |
// if (image !== null) image.dispose(); |
|---|
| 320 |
// } |
|---|
| 321 |
// images = null; |
|---|
| 322 |
// } |
|---|
| 323 |
} |
|---|
| 324 |
|
|---|
| 325 |
/** |
|---|
| 326 |
* Gets a string from the resource bundle. |
|---|
| 327 |
* We don't want to crash because of a missing String. |
|---|
| 328 |
* Returns the key if not found. |
|---|
| 329 |
*/ |
|---|
| 330 |
static String getResourceString(String key) { |
|---|
| 331 |
if(key in stringRes) |
|---|
| 332 |
return stringRes[key]; |
|---|
| 333 |
else |
|---|
| 334 |
return key; |
|---|
| 335 |
} |
|---|
| 336 |
|
|---|
| 337 |
/** |
|---|
| 338 |
* Gets a string from the resource bundle and binds it |
|---|
| 339 |
* with the given arguments. If the key is not found, |
|---|
| 340 |
* return the key. |
|---|
| 341 |
*/ |
|---|
| 342 |
static String getResourceString(String key, Object[] args) { |
|---|
| 343 |
if(key in stringRes) |
|---|
| 344 |
key = stringRes[key]; |
|---|
| 345 |
foreach(Object obj; args){ |
|---|
| 346 |
if(obj) |
|---|
| 347 |
key ~= " " ~ obj.toString(); |
|---|
| 348 |
} |
|---|
| 349 |
return key; |
|---|
| 350 |
} |
|---|
| 351 |
|
|---|
| 352 |
/** |
|---|
| 353 |
* Loads the resources |
|---|
| 354 |
*/ |
|---|
| 355 |
void initResources() { |
|---|
| 356 |
// Class clazz = ControlExample.class; |
|---|
| 357 |
// if (resourceBundle !== null) { |
|---|
| 358 |
try { |
|---|
| 359 |
if (images is null) { |
|---|
| 360 |
images = new Image[imageLocations.length]; |
|---|
| 361 |
for (int i = 0; i < imageLocations.length; ++i) { |
|---|
| 362 |
|
|---|
| 363 |
// ImageData source = new ImageData(imageLocations[i]); |
|---|
| 364 |
// ImageData mask = source.getTransparencyMask(); |
|---|
| 365 |
// images[i] = new Image(null, source, mask); |
|---|
| 366 |
images[i] = ResourceManager.getImage(imageLocations[i], "BMPFILE"); |
|---|
| 367 |
} |
|---|
| 368 |
} |
|---|
| 369 |
return; |
|---|
| 370 |
} catch (Throwable t) { |
|---|
| 371 |
} |
|---|
| 372 |
String error = getResourceString("error.CouldNotLoadResources"); |
|---|
| 373 |
freeResources(); |
|---|
| 374 |
throw new Exception(error); |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
/** |
|---|
| 379 |
* Grabs input focus. |
|---|
| 380 |
*/ |
|---|
| 381 |
public void setFocus() { |
|---|
| 382 |
tabFolder.setFocus(); |
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
/** |
|---|
| 386 |
* Sets the size of the shell to it's "packed" size, |
|---|
| 387 |
* unless that makes it bigger than the display, |
|---|
| 388 |
* in which case set it to 9/10 of display size. |
|---|
| 389 |
*/ |
|---|
| 390 |
static void setShellSize (Display display, Shell shell) { |
|---|
| 391 |
Rectangle bounds = display.getBounds(); |
|---|
| 392 |
Point size = (cast(Control)shell).computeSize (SWT.DEFAULT, SWT.DEFAULT); |
|---|
| 393 |
if (size.x > bounds.width) size.x = bounds.width * 9 / 10; |
|---|
| 394 |
if (size.y > bounds.height) size.y = bounds.height * 9 / 10; |
|---|
| 395 |
|
|---|
| 396 |
// <Shawn> since I add customered Control example tab together, the width is too large |
|---|
| 397 |
size.x = size.x * 3 / 4; |
|---|
| 398 |
shell.setSize (size); |
|---|
| 399 |
} |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
static void run(){ |
|---|
| 403 |
Display display = new Display(); |
|---|
| 404 |
Shell shell = new Shell(display); |
|---|
| 405 |
shell.setLayout(new FillLayout()); |
|---|
| 406 |
ControlExample inst = new ControlExample(shell); |
|---|
| 407 |
shell.setText(ControlExample.getResourceString("window.title")); |
|---|
| 408 |
ControlExample.setShellSize(display, shell); |
|---|
| 409 |
shell.open(); |
|---|
| 410 |
while (! shell.isDisposed()) { |
|---|
| 411 |
if (! display.readAndDispatch()) display.sleep(); |
|---|
| 412 |
} |
|---|
| 413 |
inst.dispose(); |
|---|
| 414 |
} |
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
/** |
|---|
| 418 |
* Invokes as a standalone program. |
|---|
| 419 |
*/ |
|---|
| 420 |
public void main(String[] args) { |
|---|
| 421 |
try{ run(); |
|---|
| 422 |
}catch(Exception e){ |
|---|
| 423 |
Util.trace(e.toString()); |
|---|
| 424 |
} |
|---|
| 425 |
} |
|---|