Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2020-05-01 12:56:44 +0000
committerPaul Pazderski2020-05-01 23:54:12 +0000
commitf20563c078bf1d75048739ccce601b6ab4756640 (patch)
treeb62cc31084c8586777a3daf7ff07152dc182fe7a /examples
parent56fa90b3d447e0fcc342174da0d9512ff4b202c5 (diff)
downloadeclipse.platform.swt-f20563c078bf1d75048739ccce601b6ab4756640.tar.gz
eclipse.platform.swt-f20563c078bf1d75048739ccce601b6ab4756640.tar.xz
eclipse.platform.swt-f20563c078bf1d75048739ccce601b6ab4756640.zip
Add content color and tab height to ControlExample CTabFolder Tab
The CTabFolder example could already color the active and inactive CTabFolder items. This adds coloring for the first CTabItem content. Height of CTabItems does by default adapt to the required size. This adds the possibility to set a fixed tab height. Change-Id: Ieb3a775645b95bc46cd0614543e138cef1dea8c1 Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF2
-rw-r--r--examples/org.eclipse.swt.examples/pom.xml2
-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.java118
4 files changed, 122 insertions, 5 deletions
diff --git a/examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF b/examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF
index 4742ce5d05..8e4c9e2a8d 100644
--- a/examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.SWTStandaloneExampleSet.name
Bundle-SymbolicName: org.eclipse.swt.examples; singleton:=true
-Bundle-Version: 3.106.800.qualifier
+Bundle-Version: 3.106.900.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/examples/org.eclipse.swt.examples/pom.xml b/examples/org.eclipse.swt.examples/pom.xml
index 3ad24c7c56..bf3a00afea 100644
--- a/examples/org.eclipse.swt.examples/pom.xml
+++ b/examples/org.eclipse.swt.examples/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.examples</artifactId>
- <version>3.106.800-SNAPSHOT</version>
+ <version>3.106.900-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/examples/org.eclipse.swt.examples/src/examples_control.properties b/examples/org.eclipse.swt.examples/src/examples_control.properties
index 12ab870b07..fd333c76ca 100644
--- a/examples/org.eclipse.swt.examples/src/examples_control.properties
+++ b/examples/org.eclipse.swt.examples/src/examples_control.properties
@@ -233,6 +233,8 @@ Set_Unselected_Close_Visible = Close on Unselected Tabs
Set_Unselected_Image_Visible = Image on Unselected Tabs
Selection_Foreground_Color = Selection Foreground Color
Selection_Background_Color = Selection Background Color
+Item_Foreground_Color = Item Foreground Color
+Item_Background_Color = Item Background Color
Link_Foreground_Color = Link Foreground Color
Set_Image = Set Image
Set_Top_Right = Set Top Right
@@ -274,4 +276,5 @@ ColorTitle_1 = Type
ColorTitle_2 = RGBA
ColorTitle_3 = Color
Header_Foreground_Color = Header Foreground Color
-Header_Background_Color = Header Background Color \ No newline at end of file
+Header_Background_Color = Header Background Color
+Tab_Height = Tab Height \ No newline at end of file
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 bafd8ce9f3..a8e36bad33 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
@@ -42,7 +42,7 @@ class CTabFolderTab extends Tab {
/* Example widgets and groups that contain them */
CTabFolder tabFolder1;
- Group tabFolderGroup, itemGroup;
+ Group tabFolderGroup, itemGroup, tabHeightGroup;
/* Style widgets added to the "Style" group */
Button topButton, bottomButton, flatButton, closeButton;
@@ -56,7 +56,9 @@ class CTabFolderTab extends Tab {
static final int SELECTION_FOREGROUND_COLOR = 3;
static final int SELECTION_BACKGROUND_COLOR = 4;
static final int ITEM_FONT = 5;
- Color selectionForegroundColor, selectionBackgroundColor;
+ static final int ITEM_FOREGROUND_COLOR = 6;
+ static final int ITEM_BACKGROUND_COLOR = 7;
+ Color selectionForegroundColor, selectionBackgroundColor, itemForegroundColor, itemBackgroundColor;
Font itemFont;
/* Other widgets added to the "Other" group */
@@ -65,6 +67,8 @@ class CTabFolderTab extends Tab {
ToolBar topRightControl;
+ Button tabHeightDefault, tabHeightSmall, tabHeightMedium, tabHeightLarge;
+
/**
* Creates the Tab within a given instance of ControlExample.
*/
@@ -72,6 +76,34 @@ class CTabFolderTab extends Tab {
super(instance);
}
+ @Override
+ void createControlGroup() {
+ super.createControlGroup();
+
+ /* Create a group for the CTabFolder */
+ tabHeightGroup = new Group (controlGroup, SWT.NONE);
+ tabHeightGroup.setLayout (new GridLayout ());
+ tabHeightGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
+ tabHeightGroup.setText (ControlExample.getResourceString ("Tab_Height"));
+
+ tabHeightDefault = new Button(tabHeightGroup, SWT.RADIO);
+ tabHeightDefault.setText(ControlExample.getResourceString("Preferred"));
+ tabHeightDefault.setSelection(true);
+ tabHeightDefault.addSelectionListener (widgetSelectedAdapter(event -> setTabHeight(SWT.DEFAULT)));
+
+ tabHeightSmall = new Button(tabHeightGroup, SWT.RADIO);
+ tabHeightSmall.setText("8");
+ tabHeightSmall.addSelectionListener (widgetSelectedAdapter(event -> setTabHeight(Integer.parseInt(tabHeightSmall.getText()))));
+
+ tabHeightMedium = new Button(tabHeightGroup, SWT.RADIO);
+ tabHeightMedium.setText("20");
+ tabHeightMedium.addSelectionListener (widgetSelectedAdapter(event -> setTabHeight(Integer.parseInt(tabHeightMedium.getText()))));
+
+ tabHeightLarge = new Button(tabHeightGroup, SWT.RADIO);
+ tabHeightLarge.setText("45");
+ tabHeightLarge.addSelectionListener (widgetSelectedAdapter(event -> setTabHeight(Integer.parseInt(tabHeightLarge.getText()))));
+ }
+
/**
* Creates the "Colors and Fonts" group.
*/
@@ -85,14 +117,22 @@ class CTabFolderTab extends Tab {
item.setText(ControlExample.getResourceString ("Selection_Background_Color"));
item = new TableItem(colorAndFontTable, SWT.None);
item.setText(ControlExample.getResourceString ("Item_Font"));
+ item = new TableItem(colorAndFontTable, SWT.None);
+ item.setText(ControlExample.getResourceString ("Item_Foreground_Color"));
+ item = new TableItem(colorAndFontTable, SWT.None);
+ item.setText(ControlExample.getResourceString ("Item_Background_Color"));
shell.addDisposeListener(event -> {
if (selectionBackgroundColor != null) selectionBackgroundColor.dispose();
if (selectionForegroundColor != null) selectionForegroundColor.dispose();
if (itemFont != null) itemFont.dispose();
+ if (itemBackgroundColor != null) itemBackgroundColor.dispose();
+ if (itemForegroundColor != null) itemForegroundColor.dispose();
selectionBackgroundColor = null;
selectionForegroundColor = null;
itemFont = null;
+ itemBackgroundColor = null;
+ itemForegroundColor = null;
});
}
@@ -136,6 +176,30 @@ class CTabFolderTab extends Tab {
if (oldFont != null) oldFont.dispose ();
}
break;
+ case ITEM_FOREGROUND_COLOR: {
+ Color oldColor = itemForegroundColor;
+ if (oldColor == null) oldColor = tabFolder1.getItem(0).getControl().getForeground();
+ colorDialog.setRGB(oldColor.getRGB());
+ RGB rgb = colorDialog.open();
+ if (rgb == null) return;
+ oldColor = itemForegroundColor;
+ itemForegroundColor = new Color (display, rgb);
+ setItemForeground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
+ break;
+ case ITEM_BACKGROUND_COLOR: {
+ Color oldColor = itemBackgroundColor;
+ if (oldColor == null) oldColor = tabFolder1.getItem(0).getControl().getBackground();
+ colorDialog.setRGB(oldColor.getRGB());
+ RGB rgb = colorDialog.open();
+ if (rgb == null) return;
+ oldColor = itemBackgroundColor;
+ itemBackgroundColor = new Color (display, rgb);
+ setItemBackground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
+ break;
default:
super.changeFontOrColor(index);
}
@@ -353,6 +417,13 @@ class CTabFolderTab extends Tab {
itemFont = null;
setItemFont ();
if (oldFont != null) oldFont.dispose();
+ oldColor = itemForegroundColor;
+ itemForegroundColor = null;
+ setItemForeground ();
+ if (oldColor != null) oldColor.dispose();
+ oldColor = itemBackgroundColor;
+ itemBackgroundColor = null;
+ setItemBackground ();
}
/**
@@ -371,6 +442,8 @@ class CTabFolderTab extends Tab {
setSelectionBackground ();
setSelectionForeground ();
setItemFont ();
+ setItemBackground();
+ setItemForeground();
setExampleWidgetSize();
}
@@ -505,4 +578,45 @@ class CTabFolderTab extends Tab {
item.setFont(ft);
colorAndFontTable.layout ();
}
+
+ /**
+ * Sets the background color of the CTabItem 0 content element.
+ */
+ void setItemBackground () {
+ if (!instance.startup) {
+ tabFolder1.getItem(0).getControl().setBackground(itemBackgroundColor);
+ }
+ /* Set the background color item's image to match the background color of the content. */
+ Color color = itemBackgroundColor;
+ if (color == null) color = tabFolder1.getItem(0).getControl().getBackground();
+ TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR);
+ Image oldImage = item.getImage();
+ if (oldImage != null) oldImage.dispose();
+ item.setImage (colorImage(color));
+ }
+
+ /**
+ * Sets the foreground color of the CTabItem 0 content element.
+ */
+ void setItemForeground () {
+ if (!instance.startup) {
+ tabFolder1.getItem(0).getControl().setForeground(itemForegroundColor);
+ }
+ /* Set the foreground color item's image to match the foreground color of the content. */
+ Color color = itemForegroundColor;
+ if (color == null) color = tabFolder1.getItem(0).getControl().getForeground();
+ TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR);
+ Image oldImage = item.getImage();
+ if (oldImage != null) oldImage.dispose();
+ item.setImage (colorImage(color));
+ }
+
+ /**
+ * Set the fixed item height for the CTabFolder
+ *
+ * @param height new fixed header height
+ */
+ void setTabHeight(int height) {
+ tabFolder1.setTabHeight(height);
+ }
}

Back to the top