| 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.clabeltab; |
|---|
| 12 |
|
|---|
| 13 |
private { |
|---|
| 14 |
import swt.all; |
|---|
| 15 |
import controlexample.alignabletab; |
|---|
| 16 |
import controlexample.controlexample; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
class CLabelTab : AlignableTab { |
|---|
| 20 |
/* Example widgets and groups that contain them */ |
|---|
| 21 |
CLabel label1, label2, label3; |
|---|
| 22 |
Group textLabelGroup; |
|---|
| 23 |
|
|---|
| 24 |
/* Style widgets added to the "Style" group */ |
|---|
| 25 |
Button shadowInButton, shadowOutButton, shadowNoneButton; |
|---|
| 26 |
|
|---|
| 27 |
/** |
|---|
| 28 |
* Creates the Tab within a given instance_ren of ControlExample. |
|---|
| 29 |
*/ |
|---|
| 30 |
this(ControlExample instance_ren) { |
|---|
| 31 |
super(instance_ren); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
/** |
|---|
| 35 |
* Creates the "Example" group. |
|---|
| 36 |
*/ |
|---|
| 37 |
void createExampleGroup () { |
|---|
| 38 |
super.createExampleGroup (); |
|---|
| 39 |
|
|---|
| 40 |
/* Create a group for the text labels */ |
|---|
| 41 |
textLabelGroup = new Group(exampleGroup, SWT.NONE); |
|---|
| 42 |
GridLayout gridLayout = new GridLayout (); |
|---|
| 43 |
textLabelGroup.setLayout (gridLayout); |
|---|
| 44 |
gridLayout.numColumns = 3; |
|---|
| 45 |
textLabelGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); |
|---|
| 46 |
textLabelGroup.setText (ControlExample.getResourceString("Custom_Labels")); |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
/** |
|---|
| 50 |
* Creates the "Example" widgets. |
|---|
| 51 |
*/ |
|---|
| 52 |
void createExampleWidgets () { |
|---|
| 53 |
|
|---|
| 54 |
/* Compute the widget style */ |
|---|
| 55 |
int style = getDefaultStyle(); |
|---|
| 56 |
if (shadowInButton.getSelection ()) style |= SWT.SHADOW_IN; |
|---|
| 57 |
if (shadowNoneButton.getSelection ()) style |= SWT.SHADOW_NONE; |
|---|
| 58 |
if (shadowOutButton.getSelection ()) style |= SWT.SHADOW_OUT; |
|---|
| 59 |
|
|---|
| 60 |
/* Create the example widgets */ |
|---|
| 61 |
label1 = new CLabel (textLabelGroup, style); |
|---|
| 62 |
label1.setText(ControlExample.getResourceString("One")); |
|---|
| 63 |
label1.setImage (instance_ren.images[ControlExample.ciClosedFolder]); |
|---|
| 64 |
label2 = new CLabel (textLabelGroup, style); |
|---|
| 65 |
label2.setImage (instance_ren.images[ControlExample.ciTarget]); |
|---|
| 66 |
label3 = new CLabel (textLabelGroup, style); |
|---|
| 67 |
label3.setText(ControlExample.getResourceString("Example_string")); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
/** |
|---|
| 71 |
* Creates the "Style" group. |
|---|
| 72 |
*/ |
|---|
| 73 |
void createStyleGroup() { |
|---|
| 74 |
super.createStyleGroup (); |
|---|
| 75 |
|
|---|
| 76 |
/* Create the extra widgets */ |
|---|
| 77 |
shadowNoneButton = new Button (styleGroup, SWT.RADIO); |
|---|
| 78 |
shadowNoneButton.setText ("SWT.SHADOW_NONE"); |
|---|
| 79 |
shadowInButton = new Button (styleGroup, SWT.RADIO); |
|---|
| 80 |
shadowInButton.setText ("SWT.SHADOW_IN"); |
|---|
| 81 |
shadowOutButton = new Button (styleGroup, SWT.RADIO); |
|---|
| 82 |
shadowOutButton.setText ("SWT.SHADOW_OUT"); |
|---|
| 83 |
|
|---|
| 84 |
/* Add the listeners */ |
|---|
| 85 |
void widgetSelected(SelectionEvent event) { |
|---|
| 86 |
CLabelTab c = cast(CLabelTab)event.cData; |
|---|
| 87 |
if ((event.widget.getStyle() & SWT.RADIO) != 0) { |
|---|
| 88 |
if (!(cast(Button) event.widget).getSelection ()) return; |
|---|
| 89 |
} |
|---|
| 90 |
c.recreateExampleWidgets (); |
|---|
| 91 |
}; |
|---|
| 92 |
shadowInButton.handleSelection(this, &widgetSelected); |
|---|
| 93 |
shadowOutButton.handleSelection(this, &widgetSelected); |
|---|
| 94 |
shadowNoneButton.handleSelection(this, &widgetSelected); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
/** |
|---|
| 98 |
* Gets the "Example" widget children. |
|---|
| 99 |
*/ |
|---|
| 100 |
Control [] getExampleWidgets () { |
|---|
| 101 |
Control[] result; |
|---|
| 102 |
result ~= label1; |
|---|
| 103 |
result ~= label2; |
|---|
| 104 |
result ~= label3; |
|---|
| 105 |
return result; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
/** |
|---|
| 109 |
* Gets the text for the tab folder item. |
|---|
| 110 |
*/ |
|---|
| 111 |
String getTabText () { |
|---|
| 112 |
return "CLabel"; |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
/** |
|---|
| 116 |
* Sets the alignment of the "Example" widgets. |
|---|
| 117 |
*/ |
|---|
| 118 |
void setExampleWidgetAlignment () { |
|---|
| 119 |
int alignment = 0; |
|---|
| 120 |
if (leftButton.getSelection ()) alignment = SWT.LEFT; |
|---|
| 121 |
if (centerButton.getSelection ()) alignment = SWT.CENTER; |
|---|
| 122 |
if (rightButton.getSelection ()) alignment = SWT.RIGHT; |
|---|
| 123 |
label1.setAlignment (alignment); |
|---|
| 124 |
label2.setAlignment (alignment); |
|---|
| 125 |
label3.setAlignment (alignment); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
/** |
|---|
| 129 |
* Sets the state of the "Example" widgets. |
|---|
| 130 |
*/ |
|---|
| 131 |
void setExampleWidgetState () { |
|---|
| 132 |
super.setExampleWidgetState (); |
|---|
| 133 |
leftButton.setSelection ((label1.getStyle () & SWT.LEFT) != 0); |
|---|
| 134 |
centerButton.setSelection ((label1.getStyle () & SWT.CENTER) != 0); |
|---|
| 135 |
rightButton.setSelection ((label1.getStyle () & SWT.RIGHT) != 0); |
|---|
| 136 |
shadowInButton.setSelection ((label1.getStyle () & SWT.SHADOW_IN) != 0); |
|---|
| 137 |
shadowOutButton.setSelection ((label1.getStyle () & SWT.SHADOW_OUT) != 0); |
|---|
| 138 |
shadowNoneButton.setSelection ((label1.getStyle () & (SWT.SHADOW_IN | SWT.SHADOW_OUT)) == 0); |
|---|
| 139 |
} |
|---|
| 140 |
} |
|---|