root/branches/0.2/controlexample/progressbartab.d

Revision 46, 4.2 kB (checked in by JJR, 4 years ago)

* 0.2 Branch added: New working DWT version submitted by Shawn Liu.

Line 
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.progressbartab;
12
13 private {
14 import swt.all;
15 import controlexample.tab;
16 import controlexample.rangetab;
17 import controlexample.controlexample;
18 }
19
20
21 class ProgressBarTab : RangeTab {
22     /* Example widgets and groups that contain them */
23     ProgressBar progressBar1;
24     Group progressBarGroup;
25
26     /* Style widgets added to the "Style" group */
27     Button smoothButton;
28     Button indeterminateButton;
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 "Example" group.
39      */
40     void createExampleGroup() {
41         super.createExampleGroup ();
42
43         /* Create a group for the progress bar */
44         progressBarGroup = new Group (exampleGroup, SWT.NONE);
45         progressBarGroup.setLayout (new GridLayout ());
46         progressBarGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
47         progressBarGroup.setText ("ProgressBar");
48     }
49
50     /**
51      * Creates the "Example" widgets.
52      */
53     void createExampleWidgets () {
54
55         /* Compute the widget style */
56         int style = getDefaultStyle();
57         if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
58         if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
59         if (smoothButton.getSelection ()) style |= SWT.SMOOTH;
60         if (borderButton.getSelection ()) style |= SWT.BORDER;
61         if (indeterminateButton.getSelection ()) style |= SWT.INDETERMINATE;
62
63         /* Create the example widgets */
64         progressBar1 = new ProgressBar (progressBarGroup, style);
65         progressBar1.setMaximum (100);
66         progressBar1.setSelection (50);
67     }
68
69     /**
70      * Creates the "Style" group.
71      */
72     void createStyleGroup () {
73         super.createStyleGroup ();
74
75         /* Create the extra widgets */
76         smoothButton = new Button (styleGroup, SWT.CHECK);
77         smoothButton.setText ("SWT.SMOOTH");
78         indeterminateButton = new Button (styleGroup, SWT.CHECK);
79         indeterminateButton.setText ("SWT.INDETERMINATE");
80     }
81
82     /**
83      * Gets the "Example" widget children.
84      */
85     Control [] getExampleWidgets () {
86         Control[] controls;
87         controls ~= progressBar1;
88         return controls;
89     }
90
91     /**
92      * Gets the text for the tab folder item.
93      */
94     String getTabText () {
95         return "ProgressBar";
96     }
97
98     /**
99      * Sets the state of the "Example" widgets.
100      */
101     void setExampleWidgetState () {
102         super.setExampleWidgetState ();
103         if (indeterminateButton.getSelection ()) {
104             selectionScale.setEnabled (false);
105             minimumScale.setEnabled (false);
106             maximumScale.setEnabled (false);
107         } else {
108             selectionScale.setEnabled (true);
109             minimumScale.setEnabled (true);
110             maximumScale.setEnabled (true);
111         }
112         maximumScale.setMaximum (progressBar1.getMaximum ());
113         smoothButton.setSelection ((progressBar1.getStyle () & SWT.SMOOTH) != 0);
114         indeterminateButton.setSelection ((progressBar1.getStyle () & SWT.INDETERMINATE) != 0);
115     }
116
117     /**
118      * Sets the maximum of the "Example" widgets.
119      */
120     void setWidgetMaximum () {
121         progressBar1.setMaximum (maximumScale.getSelection ());
122         updateScales ();
123     }
124
125     /**
126      * Sets the minimim of the "Example" widgets.
127      */
128     void setWidgetMinimum () {
129         progressBar1.setMinimum (minimumScale.getSelection ());
130         updateScales ();
131     }
132
133     /**
134      * Sets the selection of the "Example" widgets.
135      */
136     void setWidgetSelection () {
137         progressBar1.setSelection (selectionScale.getSelection ());
138         updateScales ();
139     }
140
141     /**
142      * Update the scale widgets to reflect the actual value set
143      * on the "Example" widget.
144      */
145     void updateScales () {
146         minimumScale.setSelection (progressBar1.getMinimum ());
147         selectionScale.setSelection (progressBar1.getSelection ());
148         maximumScale.setSelection (progressBar1.getMaximum ());
149     }
150 }
Note: See TracBrowser for help on using the browser.