| 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.slidertab; |
|---|
| 12 |
|
|---|
| 13 |
private { |
|---|
| 14 |
import swt.all; |
|---|
| 15 |
import controlexample.tab; |
|---|
| 16 |
import controlexample.rangetab; |
|---|
| 17 |
import controlexample.controlexample; |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class SliderTab : RangeTab { |
|---|
| 22 |
/* Example widgets and groups that contain them */ |
|---|
| 23 |
Scale scale1; |
|---|
| 24 |
Slider slider1; |
|---|
| 25 |
Group sliderGroup, scaleGroup; |
|---|
| 26 |
|
|---|
| 27 |
/* Scale widgets added to the "Control" group */ |
|---|
| 28 |
Scale incrementScale, pageIncrementScale, thumbScale; |
|---|
| 29 |
|
|---|
| 30 |
/** |
|---|
| 31 |
* Creates the Tab within a given instance_ren of ControlExample. |
|---|
| 32 |
*/ |
|---|
| 33 |
this(ControlExample instance_ren) { |
|---|
| 34 |
super(instance_ren); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
/** |
|---|
| 38 |
* Creates the "Control" widget children. |
|---|
| 39 |
*/ |
|---|
| 40 |
void createControlWidgets () { |
|---|
| 41 |
super.createControlWidgets (); |
|---|
| 42 |
createThumbGroup (); |
|---|
| 43 |
createIncrementGroup (); |
|---|
| 44 |
createPageIncrementGroup (); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
/** |
|---|
| 48 |
* Creates the "Example" group. |
|---|
| 49 |
*/ |
|---|
| 50 |
void createExampleGroup () { |
|---|
| 51 |
super.createExampleGroup (); |
|---|
| 52 |
|
|---|
| 53 |
/* Create a group for the slider */ |
|---|
| 54 |
sliderGroup = new Group (exampleGroup, SWT.NONE); |
|---|
| 55 |
sliderGroup.setLayout (new GridLayout ()); |
|---|
| 56 |
sliderGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); |
|---|
| 57 |
sliderGroup.setText ("Slider"); |
|---|
| 58 |
|
|---|
| 59 |
/* Create a group for the scale */ |
|---|
| 60 |
scaleGroup = new Group (exampleGroup, SWT.NONE); |
|---|
| 61 |
scaleGroup.setLayout (new GridLayout ()); |
|---|
| 62 |
scaleGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); |
|---|
| 63 |
scaleGroup.setText ("Scale"); |
|---|
| 64 |
|
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
/** |
|---|
| 68 |
* Creates the "Example" widgets. |
|---|
| 69 |
*/ |
|---|
| 70 |
void createExampleWidgets () { |
|---|
| 71 |
|
|---|
| 72 |
/* Compute the widget style */ |
|---|
| 73 |
int style = getDefaultStyle(); |
|---|
| 74 |
if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL; |
|---|
| 75 |
if (verticalButton.getSelection ()) style |= SWT.VERTICAL; |
|---|
| 76 |
if (borderButton.getSelection ()) style |= SWT.BORDER; |
|---|
| 77 |
|
|---|
| 78 |
/* Create the example widgets */ |
|---|
| 79 |
scale1 = new Scale (scaleGroup, style); |
|---|
| 80 |
scale1.setMaximum (100); |
|---|
| 81 |
scale1.setSelection (50); |
|---|
| 82 |
scale1.setIncrement (5); |
|---|
| 83 |
scale1.setPageIncrement (10); |
|---|
| 84 |
slider1 = new Slider(sliderGroup, style); |
|---|
| 85 |
slider1.setMaximum (100); |
|---|
| 86 |
slider1.setSelection (50); |
|---|
| 87 |
slider1.setIncrement(5); |
|---|
| 88 |
slider1.setPageIncrement (10); |
|---|
| 89 |
slider1.setThumb (10); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
/** |
|---|
| 93 |
* Create a group of widgets to control the increment |
|---|
| 94 |
* attribute of the example widget. |
|---|
| 95 |
*/ |
|---|
| 96 |
void createIncrementGroup() { |
|---|
| 97 |
|
|---|
| 98 |
/* Create the group */ |
|---|
| 99 |
Group incrementGroup = new Group (controlGroup, SWT.NONE); |
|---|
| 100 |
incrementGroup.setLayout (new GridLayout ()); |
|---|
| 101 |
incrementGroup.setText (ControlExample.getResourceString("Increment")); |
|---|
| 102 |
incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); |
|---|
| 103 |
|
|---|
| 104 |
/* Create the scale widget */ |
|---|
| 105 |
incrementScale = new Scale (incrementGroup, SWT.NONE); |
|---|
| 106 |
incrementScale.setMaximum (100); |
|---|
| 107 |
incrementScale.setSelection (5); |
|---|
| 108 |
incrementScale.setPageIncrement (10); |
|---|
| 109 |
incrementScale.setIncrement (5); |
|---|
| 110 |
|
|---|
| 111 |
GridData data = new GridData (GridData.FILL_HORIZONTAL); |
|---|
| 112 |
data.widthHint = 100; |
|---|
| 113 |
incrementScale.setLayoutData (data); |
|---|
| 114 |
|
|---|
| 115 |
/* Add the listeners */ |
|---|
| 116 |
incrementScale.handleEvent(this, SWT.Selection, &setWidgetIncrement); |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
/** |
|---|
| 120 |
* Create a group of widgets to control the page increment |
|---|
| 121 |
* attribute of the example widget. |
|---|
| 122 |
*/ |
|---|
| 123 |
void createPageIncrementGroup() { |
|---|
| 124 |
|
|---|
| 125 |
/* Create the group */ |
|---|
| 126 |
Group pageIncrementGroup = new Group (controlGroup, SWT.NONE); |
|---|
| 127 |
pageIncrementGroup.setLayout (new GridLayout ()); |
|---|
| 128 |
pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); |
|---|
| 129 |
pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); |
|---|
| 130 |
|
|---|
| 131 |
/* Create the scale widget */ |
|---|
| 132 |
pageIncrementScale = new Scale (pageIncrementGroup, SWT.NONE); |
|---|
| 133 |
pageIncrementScale.setMaximum (100); |
|---|
| 134 |
pageIncrementScale.setSelection (10); |
|---|
| 135 |
pageIncrementScale.setPageIncrement (10); |
|---|
| 136 |
pageIncrementScale.setIncrement (5); |
|---|
| 137 |
|
|---|
| 138 |
GridData data = new GridData (GridData.FILL_HORIZONTAL); |
|---|
| 139 |
data.widthHint = 100; |
|---|
| 140 |
pageIncrementScale.setLayoutData (data); |
|---|
| 141 |
|
|---|
| 142 |
/* Add the listeners */ |
|---|
| 143 |
pageIncrementScale.handleEvent(this, SWT.Selection, &setWidgetPageIncrement); |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
/** |
|---|
| 147 |
* Create a group of widgets to control the thumb |
|---|
| 148 |
* attribute of the example widget. |
|---|
| 149 |
*/ |
|---|
| 150 |
void createThumbGroup() { |
|---|
| 151 |
|
|---|
| 152 |
/* Create the group */ |
|---|
| 153 |
Group thumbGroup = new Group (controlGroup, SWT.NONE); |
|---|
| 154 |
thumbGroup.setLayout (new GridLayout ()); |
|---|
| 155 |
thumbGroup.setText (ControlExample.getResourceString("Thumb")); |
|---|
| 156 |
thumbGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); |
|---|
| 157 |
|
|---|
| 158 |
/* Create the scale widget */ |
|---|
| 159 |
thumbScale = new Scale (thumbGroup, SWT.NONE); |
|---|
| 160 |
thumbScale.setMaximum (100); |
|---|
| 161 |
thumbScale.setSelection (10); |
|---|
| 162 |
thumbScale.setPageIncrement (10); |
|---|
| 163 |
thumbScale.setIncrement (5); |
|---|
| 164 |
|
|---|
| 165 |
GridData data = new GridData (GridData.FILL_HORIZONTAL); |
|---|
| 166 |
data.widthHint = 100; |
|---|
| 167 |
thumbScale.setLayoutData (data); |
|---|
| 168 |
|
|---|
| 169 |
/* Add the listeners */ |
|---|
| 170 |
thumbScale.handleEvent(this, SWT.Selection, &setWidgetThumb); |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
/** |
|---|
| 174 |
* Gets the "Example" widget children. |
|---|
| 175 |
*/ |
|---|
| 176 |
Control [] getExampleWidgets () { |
|---|
| 177 |
Control[] result; |
|---|
| 178 |
result ~= scale1; |
|---|
| 179 |
result ~= slider1; |
|---|
| 180 |
return result; |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
/** |
|---|
| 184 |
* Gets the text for the tab folder item. |
|---|
| 185 |
*/ |
|---|
| 186 |
String getTabText () { |
|---|
| 187 |
return "Slider/Scale"; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
/** |
|---|
| 191 |
* Sets the state of the "Example" widgets. |
|---|
| 192 |
*/ |
|---|
| 193 |
void setExampleWidgetState () { |
|---|
| 194 |
super.setExampleWidgetState (); |
|---|
| 195 |
setWidgetIncrement (); |
|---|
| 196 |
setWidgetPageIncrement (); |
|---|
| 197 |
setWidgetThumb (); |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
/** |
|---|
| 201 |
* Sets the increment of the "Example" widgets. |
|---|
| 202 |
*/ |
|---|
| 203 |
void setWidgetIncrement () { |
|---|
| 204 |
slider1.setIncrement (incrementScale.getSelection ()); |
|---|
| 205 |
scale1.setIncrement (incrementScale.getSelection ()); |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
/** |
|---|
| 209 |
* Sets the minimim of the "Example" widgets. |
|---|
| 210 |
*/ |
|---|
| 211 |
void setWidgetMaximum () { |
|---|
| 212 |
slider1.setMaximum (maximumScale.getSelection ()); |
|---|
| 213 |
scale1.setMaximum (maximumScale.getSelection ()); |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
/** |
|---|
| 217 |
* Sets the minimim of the "Example" widgets. |
|---|
| 218 |
*/ |
|---|
| 219 |
void setWidgetMinimum () { |
|---|
| 220 |
slider1.setMinimum (minimumScale.getSelection ()); |
|---|
| 221 |
scale1.setMinimum (minimumScale.getSelection ()); |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
/** |
|---|
| 225 |
* Sets the page increment of the "Example" widgets. |
|---|
| 226 |
*/ |
|---|
| 227 |
void setWidgetPageIncrement () { |
|---|
| 228 |
slider1.setPageIncrement (pageIncrementScale.getSelection ()); |
|---|
| 229 |
scale1.setPageIncrement (pageIncrementScale.getSelection ()); |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
/** |
|---|
| 233 |
* Sets the selection of the "Example" widgets. |
|---|
| 234 |
*/ |
|---|
| 235 |
void setWidgetSelection () { |
|---|
| 236 |
slider1.setSelection (selectionScale.getSelection ()); |
|---|
| 237 |
scale1.setSelection (selectionScale.getSelection ()); |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
/** |
|---|
| 241 |
* Sets the thumb of the "Example" widgets. |
|---|
| 242 |
*/ |
|---|
| 243 |
void setWidgetThumb () { |
|---|
| 244 |
slider1.setThumb (thumbScale.getSelection ()); |
|---|
| 245 |
} |
|---|
| 246 |
} |
|---|