Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java78
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java24
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java24
3 files changed, 124 insertions, 2 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java
index 542ae8e908..eea885b91b 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -57,7 +57,9 @@ class TreeTab extends ScrollableTab {
static final int CELL_FOREGROUND_COLOR = 6;
static final int CELL_BACKGROUND_COLOR = 7;
static final int CELL_FONT = 8;
- Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor;
+ static final int HEADER_FOREGROUND_COLOR = 9;
+ static final int HEADER_BACKGROUND_COLOR = 10;
+ Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor, headerForegroundColor, headerBackgroundColor;
Font itemFont, cellFont;
static String [] columnTitles = {ControlExample.getResourceString("TableTitle_0"),
@@ -107,6 +109,10 @@ class TreeTab extends ScrollableTab {
item.setText(ControlExample.getResourceString ("Cell_Background_Color"));
item = new TableItem(colorAndFontTable, SWT.None);
item.setText(ControlExample.getResourceString ("Cell_Font"));
+ item = new TableItem(colorAndFontTable, SWT.None);
+ item.setText(ControlExample.getResourceString ("Header_Foreground_Color"));
+ item = new TableItem(colorAndFontTable, SWT.None);
+ item.setText(ControlExample.getResourceString ("Header_Background_Color"));
shell.addDisposeListener(event -> {
if (itemBackgroundColor != null) itemBackgroundColor.dispose();
@@ -115,12 +121,16 @@ class TreeTab extends ScrollableTab {
if (cellBackgroundColor != null) cellBackgroundColor.dispose();
if (cellForegroundColor != null) cellForegroundColor.dispose();
if (cellFont != null) cellFont.dispose();
+ if (headerBackgroundColor != null) headerBackgroundColor.dispose();
+ if (headerForegroundColor != null) headerForegroundColor.dispose();
itemBackgroundColor = null;
itemForegroundColor = null;
itemFont = null;
cellBackgroundColor = null;
cellForegroundColor = null;
cellFont = null;
+ headerForegroundColor = null;
+ headerBackgroundColor = null;
});
}
@@ -201,6 +211,29 @@ class TreeTab extends ScrollableTab {
if (oldFont != null) oldFont.dispose ();
}
break;
+ case HEADER_FOREGROUND_COLOR: {
+ Color oldColor = headerForegroundColor;
+ if (oldColor == null) oldColor = tree1.getHeaderForeground();
+ colorDialog.setRGB(oldColor.getRGB());
+ RGB rgb = colorDialog.open();
+ if (rgb == null) return;
+ oldColor = headerForegroundColor;
+ headerForegroundColor = new Color (display, rgb);
+ setHeaderForeground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
+ break;
+ case HEADER_BACKGROUND_COLOR: {
+ Color oldColor = headerBackgroundColor;
+ if (oldColor == null) oldColor = tree1.getHeaderBackground();
+ colorDialog.setRGB(oldColor.getRGB());
+ RGB rgb = colorDialog.open();
+ if (rgb == null) return;
+ oldColor = headerBackgroundColor;
+ headerBackgroundColor = new Color (display, rgb);
+ setHeaderBackground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
default:
super.changeFontOrColor(index);
}
@@ -492,6 +525,36 @@ class TreeTab extends ScrollableTab {
}
}
+ void setHeaderBackground () {
+ if (!instance.startup) {
+ tree1.setHeaderBackground (headerBackgroundColor);
+ tree2.setHeaderBackground (headerBackgroundColor);
+ }
+ /* Set the header background color item's image to match the header background color. */
+ Color color = headerBackgroundColor;
+ if (color == null) color = tree1.getHeaderBackground();
+ TableItem item = colorAndFontTable.getItem(HEADER_BACKGROUND_COLOR);
+ Image oldImage1 = item.getImage();
+ if (oldImage1 != null) oldImage1.dispose();
+ item.setImage (colorImage(color));
+
+ }
+
+ void setHeaderForeground () {
+ if (!instance.startup) {
+ tree1.setHeaderForeground (headerForegroundColor);
+ tree2.setHeaderForeground (headerForegroundColor);
+ }
+ /* Set the header foreground color item's image to match the header foreground color. */
+ Color color = headerForegroundColor;
+ if (color == null) color = tree1.getHeaderForeground();
+ TableItem item = colorAndFontTable.getItem(HEADER_FOREGROUND_COLOR);
+ Image oldImage1 = item.getImage();
+ if (oldImage1 != null) oldImage1.dispose();
+ item.setImage (colorImage(color));
+
+ }
+
/**
* Sets the moveable columns state of the "Example" widgets.
*/
@@ -555,6 +618,15 @@ class TreeTab extends ScrollableTab {
cellFont = null;
setCellFont ();
if (oldFont != null) oldFont.dispose();
+ oldColor = headerBackgroundColor;
+ headerBackgroundColor = null;
+ setHeaderBackground ();
+ if (oldColor != null) oldColor.dispose();
+ oldColor = headerForegroundColor;
+ headerForegroundColor = null;
+ setHeaderForeground ();
+ if (oldColor != null) oldColor.dispose();
+
}
/**
@@ -568,6 +640,8 @@ class TreeTab extends ScrollableTab {
setCellBackground ();
setCellForeground ();
setCellFont ();
+ setHeaderBackground ();
+ setHeaderForeground ();
if (!instance.startup) {
setColumnsMoveable ();
setColumnsResizable ();
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java
index 10eb87c1c8..82b66e2594 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java
@@ -14,6 +14,7 @@ package org.eclipse.swt.tests.junit;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -22,6 +23,7 @@ import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
@@ -1340,6 +1342,28 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
}
@Test
+public void test_setHeaderBackgroundLorg_eclipse_swt_graphics_Color() {
+ assertNotNull(table.getHeaderBackground());
+ Color color = new Color(control.getDisplay(), 12, 34, 56);
+ table.setHeaderBackground(color);
+ assertEquals(color, table.getHeaderBackground());
+ table.setHeaderBackground(null);
+ assertFalse(table.getHeaderBackground().equals(color));
+ color.dispose();
+}
+
+@Test
+public void test_setHeaderForegroundLorg_eclipse_swt_graphics_Color() {
+ assertNotNull(table.getHeaderForeground());
+ Color color = new Color(control.getDisplay(), 12, 34, 56);
+ table.setHeaderForeground(color);
+ assertEquals(color, table.getHeaderForeground());
+ table.setHeaderForeground(null);
+ assertFalse(table.getHeaderForeground().equals(color));
+ color.dispose();
+}
+
+@Test
public void test_setHeaderVisibleZ() {
assertFalse(table.getHeaderVisible());
table.setHeaderVisible(true);
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java
index 2e483abe5b..ebf789e15b 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java
@@ -13,6 +13,7 @@ package org.eclipse.swt.tests.junit;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -21,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
@@ -359,6 +361,28 @@ public void test_selectAll() {
}
@Test
+public void test_setHeaderBackgroundLorg_eclipse_swt_graphics_Color() {
+ assertNotNull(tree.getHeaderBackground());
+ Color color = new Color(control.getDisplay(), 12, 34, 56);
+ tree.setHeaderBackground(color);
+ assertEquals(color, tree.getHeaderBackground());
+ tree.setHeaderBackground(null);
+ assertFalse(tree.getHeaderBackground().equals(color));
+ color.dispose();
+}
+
+@Test
+public void test_setHeaderForegroundLorg_eclipse_swt_graphics_Color() {
+ assertNotNull(tree.getHeaderForeground());
+ Color color = new Color(control.getDisplay(), 12, 34, 56);
+ tree.setHeaderForeground(color);
+ assertEquals(color, tree.getHeaderForeground());
+ tree.setHeaderForeground(null);
+ assertFalse(tree.getHeaderForeground().equals(color));
+ color.dispose();
+}
+
+@Test
public void test_setHeaderVisibleZ() {
assertFalse(tree.getHeaderVisible());
tree.setHeaderVisible(true);

Back to the top