Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarolyn MacLeod2004-04-14 18:32:28 +0000
committerCarolyn MacLeod2004-04-14 18:32:28 +0000
commit68d5d82790199db9de919873869360bbdc422218 (patch)
treef850f3ab1ffc9895a047a0bdc395f4913d269722 /examples
parent99ee63f7e5c6560b31d4a172e90ee2dd1db7a14d (diff)
downloadeclipse.platform.swt-68d5d82790199db9de919873869360bbdc422218.tar.gz
eclipse.platform.swt-68d5d82790199db9de919873869360bbdc422218.tar.xz
eclipse.platform.swt-68d5d82790199db9de919873869360bbdc422218.zip
*** empty log message ***
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/examples_control.properties5
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java121
2 files changed, 123 insertions, 3 deletions
diff --git a/examples/org.eclipse.swt.examples/src/examples_control.properties b/examples/org.eclipse.swt.examples/src/examples_control.properties
index 2b27a80d93..507c6e281c 100644
--- a/examples/org.eclipse.swt.examples/src/examples_control.properties
+++ b/examples/org.eclipse.swt.examples/src/examples_control.properties
@@ -144,8 +144,9 @@ DropDownData_6 =
DropDownData_7 = Strawberries
DropDownData_8 = The Longest String
Colors = Colors and Font
-Table_Item_Colors = Index:0 Table Item Colors
-Tree_Item_Colors = Node 1 Tree Item Colors
+Table_Item_Colors = Table Item 0 Colors
+Tree_Item_Colors = Tree Item 1 Colors
+CTab_Item_Colors = Tab Item 0 Colors
Background_Color = Background Color
Foreground_Color = Foreground Color
Item_Background_Color = Item Background Color
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java
index 0ffb77a5ab..8d67eb9b0d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java
@@ -15,6 +15,7 @@ import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
class CTabFolderTab extends Tab {
@@ -22,7 +23,8 @@ class CTabFolderTab extends Tab {
/* Example widgets and groups that contain them */
CTabFolder tabFolder1;
- Group tabFolderGroup;
+ CTabItem tabItem0;
+ Group tabFolderGroup, tabItemGroup;
/* Style widgets added to the "Style" group */
Button topButton, bottomButton, flatButton, closeButton;
@@ -31,6 +33,11 @@ class CTabFolderTab extends Tab {
ControlExample.getResourceString("CTabItem1_1"),
ControlExample.getResourceString("CTabItem1_2")};
+ /* Controls and resources added to the "Colors" group */
+ Button itemForegroundButton, itemBackgroundButton;
+ Color itemForegroundColor, itemBackgroundColor;
+ Image itemForegroundImage, itemBackgroundImage;
+
/* Other widgets added to the "Other" group */
Button setSimpleTabButton, setImageButton;
@@ -42,6 +49,73 @@ class CTabFolderTab extends Tab {
}
/**
+ * Creates the "Colors" group.
+ */
+ void createColorGroup () {
+ super.createColorGroup();
+
+ tabItemGroup = new Group (colorGroup, SWT.NONE);
+ tabItemGroup.setText (ControlExample.getResourceString ("CTab_Item_Colors"));
+ GridData data = new GridData ();
+ data.horizontalSpan = 2;
+ tabItemGroup.setLayoutData (data);
+ tabItemGroup.setLayout (new GridLayout (2, false));
+ new Label (tabItemGroup, SWT.NONE).setText (ControlExample.getResourceString ("Item_Foreground_Color"));
+ itemForegroundButton = new Button (tabItemGroup, SWT.PUSH);
+ new Label (tabItemGroup, SWT.NONE).setText (ControlExample.getResourceString ("Item_Background_Color"));
+ itemBackgroundButton = new Button (tabItemGroup, SWT.PUSH);
+
+ Shell shell = colorGroup.getShell ();
+ final ColorDialog foregroundDialog = new ColorDialog (shell);
+ final ColorDialog backgroundDialog = new ColorDialog (shell);
+
+ int imageSize = 12;
+ Display display = shell.getDisplay ();
+ itemForegroundImage = new Image(display, imageSize, imageSize);
+ itemBackgroundImage = new Image(display, imageSize, imageSize);
+
+ /* Add listeners to set the colors and font */
+ itemForegroundButton.setImage(itemForegroundImage);
+ itemForegroundButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ Color oldColor = itemForegroundColor;
+ if (oldColor == null) oldColor = tabItem0.getForeground ();
+ foregroundDialog.setRGB(oldColor.getRGB());
+ RGB rgb = foregroundDialog.open();
+ if (rgb == null) return;
+ oldColor = itemForegroundColor;
+ itemForegroundColor = new Color (event.display, rgb);
+ setItemForeground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
+ });
+ itemBackgroundButton.setImage(itemBackgroundImage);
+ itemBackgroundButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ Color oldColor = itemBackgroundColor;
+ if (oldColor == null) oldColor = tabItem0.getBackground ();
+ backgroundDialog.setRGB(oldColor.getRGB());
+ RGB rgb = backgroundDialog.open();
+ if (rgb == null) return;
+ oldColor = itemBackgroundColor;
+ itemBackgroundColor = new Color (event.display, rgb);
+ setItemBackground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
+ });
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent event) {
+ if (itemBackgroundImage != null) itemBackgroundImage.dispose();
+ if (itemForegroundImage != null) itemForegroundImage.dispose();
+ if (itemBackgroundColor != null) itemBackgroundColor.dispose();
+ if (itemForegroundColor != null) itemForegroundColor.dispose();
+ itemBackgroundColor = null;
+ itemForegroundColor = null;
+ }
+ });
+ }
+
+ /**
* Creates the "Other" group.
*/
void createOtherGroup () {
@@ -100,6 +174,7 @@ class CTabFolderTab extends Tab {
Label label = new Label(tabFolder1, SWT.NONE);
label.setText(ControlExample.getResourceString("CTabItem_content") + ": " + i);
item.setControl(label);
+ if (i == 0) tabItem0 = item;
}
tabFolder1.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
@@ -196,12 +271,32 @@ class CTabFolderTab extends Tab {
}
/**
+ * Sets the foreground color, background color, and font
+ * of the "Example" widgets to their default settings.
+ * Also sets foreground and background color of the Node 1
+ * TreeItems to default settings.
+ */
+ void resetColorsAndFonts () {
+ super.resetColorsAndFonts ();
+ Color oldColor = itemForegroundColor;
+ itemForegroundColor = null;
+ setItemForeground ();
+ if (oldColor != null) oldColor.dispose();
+ oldColor = itemBackgroundColor;
+ itemBackgroundColor = null;
+ setItemBackground ();
+ if (oldColor != null) oldColor.dispose();
+ }
+
+ /**
* Sets the state of the "Example" widgets.
*/
void setExampleWidgetState () {
super.setExampleWidgetState ();
setSimpleTabs ();
setImages ();
+ setItemBackground ();
+ setItemForeground ();
}
/**
@@ -226,4 +321,28 @@ class CTabFolderTab extends Tab {
}
setExampleWidgetSize ();
}
+
+ /**
+ * Sets the background color of the Node 1 TreeItems.
+ */
+ void setItemBackground () {
+ tabItem0.setBackground (itemBackgroundColor);
+ /* Set the background button's color to match the color just set. */
+ Color color = itemBackgroundColor;
+ if (color == null) color = tabItem0.getBackground ();
+ drawImage (itemForegroundImage, color);
+ itemBackgroundButton.setImage (itemForegroundImage);
+ }
+
+ /**
+ * Sets the foreground color of Node 1 TreeItems.
+ */
+ void setItemForeground () {
+ tabItem0.setForeground (itemForegroundColor);
+ /* Set the foreground button's color to match the color just set. */
+ Color color = itemForegroundColor;
+ if (color == null) color = tabItem0.getForeground ();
+ drawImage (itemBackgroundImage, color);
+ itemForegroundButton.setImage (itemBackgroundImage);
+ }
}

Back to the top