comparison dwtexamples/controlexample/CLabelTab.d @ 0:052c3aebd1d3

initial import
author Frank Benoit <benoit@tionex.de>
date Fri, 01 Feb 2008 21:46:26 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:052c3aebd1d3
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtexamples.controlexample.CLabelTab;
14
15
16
17 import dwt.DWT;
18 import dwt.custom.CLabel;
19 import dwt.layout.GridData;
20 import dwt.layout.GridLayout;
21 import dwt.widgets.Button;
22 import dwt.widgets.Group;
23 import dwt.widgets.Widget;
24
25
26 import dwtexamples.controlexample.AlignableTab;
27 import dwtexamples.controlexample.ControlExample;
28
29 import tango.text.convert.Format;
30
31 class CLabelTab : AlignableTab {
32 /* Example widgets and groups that contain them */
33 CLabel label1, label2, label3;
34 Group textLabelGroup;
35
36 /* Style widgets added to the "Style" group */
37 Button shadowInButton, shadowOutButton, shadowNoneButton;
38
39 /**
40 * Creates the Tab within a given instance of ControlExample.
41 */
42 this(ControlExample instance) {
43 super(instance);
44 }
45
46 /**
47 * Creates the "Example" group.
48 */
49 void createExampleGroup () {
50 super.createExampleGroup ();
51
52 /* Create a group for the text labels */
53 textLabelGroup = new Group(exampleGroup, DWT.NONE);
54 GridLayout gridLayout = new GridLayout ();
55 textLabelGroup.setLayout (gridLayout);
56 gridLayout.numColumns = 3;
57 textLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
58 textLabelGroup.setText (ControlExample.getResourceString("Custom_Labels"));
59 }
60
61 /**
62 * Creates the "Example" widgets.
63 */
64 void createExampleWidgets () {
65
66 /* Compute the widget style */
67 int style = getDefaultStyle();
68 if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN;
69 if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE;
70 if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT;
71 if (leftButton.getSelection ()) style |= DWT.LEFT;
72 if (centerButton.getSelection ()) style |= DWT.CENTER;
73 if (rightButton.getSelection ()) style |= DWT.RIGHT;
74
75 /* Create the example widgets */
76 label1 = new CLabel (textLabelGroup, style);
77 label1.setText(ControlExample.getResourceString("One"));
78 label1.setImage (instance.images[ControlExample.ciClosedFolder]);
79 label2 = new CLabel (textLabelGroup, style);
80 label2.setImage (instance.images[ControlExample.ciTarget]);
81 label3 = new CLabel (textLabelGroup, style);
82 label3.setText(Format( "{}\n{}", ControlExample.getResourceString("Example_string"), ControlExample.getResourceString("One_Two_Three")));
83 }
84
85 /**
86 * Creates the "Style" group.
87 */
88 void createStyleGroup() {
89 super.createStyleGroup ();
90
91 /* Create the extra widgets */
92 shadowNoneButton = new Button (styleGroup, DWT.RADIO);
93 shadowNoneButton.setText ("DWT.SHADOW_NONE");
94 shadowInButton = new Button (styleGroup, DWT.RADIO);
95 shadowInButton.setText ("DWT.SHADOW_IN");
96 shadowOutButton = new Button (styleGroup, DWT.RADIO);
97 shadowOutButton.setText ("DWT.SHADOW_OUT");
98 }
99
100 /**
101 * Gets the "Example" widget children.
102 */
103 Widget [] getExampleWidgets () {
104 return [ cast(Widget) label1, label2, label3];
105 }
106
107 /**
108 * Returns a list of set/get API method names (without the set/get prefix)
109 * that can be used to set/get values in the example control(s).
110 */
111 char[][] getMethodNames() {
112 return ["Text", "ToolTipText"];
113 }
114
115 /**
116 * Gets the text for the tab folder item.
117 */
118 char[] getTabText () {
119 return "CLabel";
120 }
121
122 /**
123 * Sets the alignment of the "Example" widgets.
124 */
125 void setExampleWidgetAlignment () {
126 int alignment = 0;
127 if (leftButton.getSelection ()) alignment = DWT.LEFT;
128 if (centerButton.getSelection ()) alignment = DWT.CENTER;
129 if (rightButton.getSelection ()) alignment = DWT.RIGHT;
130 label1.setAlignment (alignment);
131 label2.setAlignment (alignment);
132 label3.setAlignment (alignment);
133 }
134
135 /**
136 * Sets the state of the "Example" widgets.
137 */
138 void setExampleWidgetState () {
139 super.setExampleWidgetState ();
140 leftButton.setSelection ((label1.getStyle () & DWT.LEFT) !is 0);
141 centerButton.setSelection ((label1.getStyle () & DWT.CENTER) !is 0);
142 rightButton.setSelection ((label1.getStyle () & DWT.RIGHT) !is 0);
143 shadowInButton.setSelection ((label1.getStyle () & DWT.SHADOW_IN) !is 0);
144 shadowOutButton.setSelection ((label1.getStyle () & DWT.SHADOW_OUT) !is 0);
145 shadowNoneButton.setSelection ((label1.getStyle () & (DWT.SHADOW_IN | DWT.SHADOW_OUT)) is 0);
146 }
147 }