Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Pun2016-05-31 09:40:33 -0400
committerEric Williams2016-06-08 13:32:42 -0400
commitaef14358a6968c4245bd00ea88871fdb49db0080 (patch)
tree7f106c93602fbf282966fa144cedecec70dfbecc /examples
parent63e349a3fef39352e3e26eda56a2889c534a9e46 (diff)
downloadeclipse.platform.swt-aef14358a6968c4245bd00ea88871fdb49db0080.tar.gz
eclipse.platform.swt-aef14358a6968c4245bd00ea88871fdb49db0080.tar.xz
eclipse.platform.swt-aef14358a6968c4245bd00ea88871fdb49db0080.zip
Bug 494958 - Add color tab to ControlExample
I have added a new "Color" tab into ControlExample that displays all available colors to use in the format Name, Type, RGB, and the actual color. The colors used are from SWT.java and are put into a hash table with the id as its key and the name as its value. I was able to get the RGB color codes by building a method called getRGBColor(), which grabs the Color object using Display.getSystemColor() and then building the string using the getRed(), getBlue(), and getGreen() methods from the color object. The colortab class extends from the Tab class, but a lot of the methods added were from the Tables class. I also overloaded the createControlGroup() method to create a custom Parameters group (located on the right side of the example group). This allowed me to remove a lot of unnecessary controls for my color table as they are not relevant. Change-Id: I7f650ceada799dfe0252155efa18cf2ff78b2910 Signed-off-by: Ian Pun <ipun@redhat.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/examples_control.properties4
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java233
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java24
3 files changed, 254 insertions, 7 deletions
diff --git a/examples/org.eclipse.swt.examples/src/examples_control.properties b/examples/org.eclipse.swt.examples/src/examples_control.properties
index f97f435739..b3586343e0 100644
--- a/examples/org.eclipse.swt.examples/src/examples_control.properties
+++ b/examples/org.eclipse.swt.examples/src/examples_control.properties
@@ -265,3 +265,7 @@ Show_In_Tray = Show In Tray
BrowserNotFound = Browser not found: {0}
MozillaNotFound = Cannot use SWT.MOZILLA style: {0}\nSee http://www.eclipse.org/swt/faq.php#howusemozilla for more information.
WebKitNotFound = Cannot use SWT.WEBKIT style: {0}\nSee http://www.eclipse.org/swt/faq.php#howusewebkit for more information.
+ColorTitle_0 = Name
+ColorTitle_1 = Type
+ColorTitle_2 = RGB
+ColorTitle_3 = Color \ No newline at end of file
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java
new file mode 100644
index 0000000000..48a19d0f85
--- /dev/null
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java
@@ -0,0 +1,233 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2016 Red Hat, Inc. 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ian Pun <ipun@redhat.com> - addition of Color tab
+ *******************************************************************************/
+package org.eclipse.swt.examples.controlexample;
+
+
+import java.util.HashMap;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Widget;
+
+class ColorTab extends Tab {
+ Table colors;
+ Group colorsGroup;
+ HashMap <Integer, String> hmap = new HashMap <> ();
+ static final int namedColorEnd = 8;
+ static String [] columnTitles = {ControlExample.getResourceString("ColorTitle_0"),
+ ControlExample.getResourceString("ColorTitle_1"),
+ ControlExample.getResourceString("ColorTitle_2"),
+ ControlExample.getResourceString("ColorTitle_3")};
+
+ /* Size widgets added to the "Size" group */
+ Button packColumnsButton;
+
+ /**
+ * Creates the color tab within a given instance of ControlExample.
+ */
+ ColorTab(ControlExample instance) {
+ super(instance);
+ addTableElements();
+ }
+
+ void addTableElements () {
+ hmap.put(SWT.COLOR_WHITE, "COLOR_WHITE");
+ hmap.put(SWT.COLOR_BLACK, "COLOR_BLACK");
+ hmap.put(SWT.COLOR_RED, "COLOR_RED");
+ hmap.put(SWT.COLOR_DARK_RED, "COLOR_DARK_RED");
+ hmap.put(SWT.COLOR_GREEN, "COLOR_GREEN");
+ hmap.put(SWT.COLOR_DARK_GREEN, "COLOR_DARK_GREEN");
+ hmap.put(SWT.COLOR_YELLOW, "COLOR_YELLOW");
+ hmap.put(SWT.COLOR_DARK_YELLOW, "COLOR_DARK_YELLOW");
+ hmap.put(SWT.COLOR_WIDGET_DARK_SHADOW, "COLOR_WIDGET_DARK_SHADOW");
+ hmap.put(SWT.COLOR_WIDGET_NORMAL_SHADOW, "COLOR_WIDGET_NORMAL_SHADOW");
+ hmap.put(SWT.COLOR_WIDGET_LIGHT_SHADOW, "COLOR_WIDGET_LIGHT_SHADOW");
+ hmap.put(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW, "COLOR_WIDGET_HIGHLIGHT_SHADOW");
+ hmap.put(SWT.COLOR_WIDGET_FOREGROUND, "COLOR_WIDGET_FOREGROUND");
+ hmap.put(SWT.COLOR_WIDGET_BACKGROUND, "COLOR_WIDGET_BACKGROUND");
+ hmap.put(SWT.COLOR_WIDGET_BORDER, "COLOR_WIDGET_BORDER");
+ hmap.put(SWT.COLOR_LIST_FOREGROUND, "COLOR_LIST_FOREGROUND");
+ hmap.put(SWT.COLOR_LIST_BACKGROUND, "COLOR_LIST_BACKGROUND");
+ hmap.put(SWT.COLOR_LIST_SELECTION, "COLOR_LIST_SELECTION");
+ hmap.put(SWT.COLOR_LIST_SELECTION_TEXT, "COLOR_LIST_SELECTION_TEXT");
+ hmap.put(SWT.COLOR_INFO_FOREGROUND, "COLOR_INFO_FOREGROUND");
+ hmap.put(SWT.COLOR_INFO_BACKGROUND, "COLOR_INFO_BACKGROUND");
+ hmap.put(SWT.COLOR_TITLE_FOREGROUND, "COLOR_TITLE_FOREGROUND");
+ hmap.put(SWT.COLOR_TITLE_BACKGROUND, "COLOR_TITLE_BACKGROUND");
+ hmap.put(SWT.COLOR_TITLE_BACKGROUND_GRADIENT, "COLOR_TITLE_BACKGROUND_GRADIENT");
+ hmap.put(SWT.COLOR_TITLE_INACTIVE_FOREGROUND, "COLOR_TITLE_INACTIVE_FOREGROUND");
+ hmap.put(SWT.COLOR_TITLE_INACTIVE_BACKGROUND, "COLOR_TITLE_INACTIVE_BACKGROUND");
+ hmap.put(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT, "COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT");
+ hmap.put(SWT.COLOR_LINK_FOREGROUND, "COLOR_LINK_FOREGROUND");
+ }
+
+ /**
+ * Creates the "Example" group.
+ */
+ @Override
+ void createExampleGroup () {
+ super.createExampleGroup ();
+ /* Create a group for the list */
+ colorsGroup = new Group (exampleGroup, SWT.NONE);
+ colorsGroup.setLayout (new GridLayout ());
+ colorsGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
+ colorsGroup.setText ("Color");
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ @Override
+ void createExampleWidgets () {
+
+ /* Create the color table widget */
+ /* Compute the widget style */
+ int style = getDefaultStyle();
+ colors = new Table (colorsGroup, style);
+ colors.setHeaderVisible(true);
+ // fill in the table.
+ for (int i = 0; i < columnTitles.length; i++) {
+ TableColumn tableColumn = new TableColumn(colors, SWT.NONE);
+ tableColumn.setText(columnTitles[i]);
+ tableColumn.setToolTipText(ControlExample.getResourceString("Tooltip", new String [] {columnTitles[i]}));
+ }
+ // fill in the Data. Put an empty line inbetween "Named" and "SWT" colors.
+ boolean emptyLineFlag=false;
+ for (Integer key : hmap.keySet()){
+ if (!emptyLineFlag){
+ TableItem item = new TableItem (colors, SWT.NONE);
+ item.setText(hmap.get(key));
+ item.setText(0,hmap.get(key));
+ item.setText(1,"Named");
+ item.setText(2,getRGBcolor(key));
+ // the spaces will help the color cell be large enough to see
+ item.setText(3," ");
+ item.setBackground(3,display.getSystemColor(key));
+ if(key == namedColorEnd){
+ TableItem emptyItem = new TableItem(colors, SWT.NONE);
+ emptyItem.setText("");
+ emptyLineFlag=true;
+ }
+ }
+ else{
+ TableItem item = new TableItem (colors, SWT.NONE);
+ item.setText(hmap.get(key));
+ item.setText(0,hmap.get(key)+" ");
+ item.setText(1,"System ");
+ item.setText(2,getRGBcolor(key)+" ");
+ // the spaces will help the color cell be large enough to see
+ item.setText(3," ");
+ item.setBackground(3,display.getSystemColor(key));
+ }
+ }
+ for (int i = 0; i < columnTitles.length; i++) {
+ colors.getColumn(i).pack();
+ }
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ @Override
+ Widget [] getExampleWidgets () {
+ return new Widget [] {colors};
+ }
+
+ /**
+ * Gets the Tab name.
+ */
+ @Override
+ String getTabText () {
+ return "Color";
+ }
+
+ /**
+ * Colors only needs Orientation, Size, and Other groups. Everything else will be removed.
+ */
+ @Override
+ void createSizeGroup () {
+ super.createSizeGroup();
+
+ packColumnsButton = new Button (sizeGroup, SWT.PUSH);
+ packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns"));
+ packColumnsButton.addSelectionListener(new SelectionAdapter () {
+ @Override
+ public void widgetSelected (SelectionEvent event) {
+ packColumns ();
+ setExampleWidgetSize ();
+ }
+ });
+ }
+
+ void packColumns () {
+ int columnCount = colors.getColumnCount();
+ for (int i = 0; i < columnCount; i++) {
+ TableColumn tableColumn = colors.getColumn(i);
+ tableColumn.pack();
+ }
+ }
+
+ String getRGBcolor(int id){
+ String result;
+ Color color = display.getSystemColor(id);
+ result = "("+color.getRed() + "," + color.getGreen() + "," + color.getBlue()+")";
+ return result;
+ }
+
+ @Override
+ boolean rtlSupport() {
+ return false;
+ }
+
+ /**
+ * Override the "Control" group. The "Control" group
+ * is typically the right hand column in the tab.
+ */
+ @Override
+ void createControlGroup () {
+ controlGroup = new Group (tabFolderPage, SWT.NONE);
+ controlGroup.setLayout (new GridLayout (2, true));
+ controlGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false));
+ controlGroup.setText (ControlExample.getResourceString("Parameters"));
+ /* Create individual groups inside the "Control" group */
+ createOtherGroup ();
+ createSetGetGroup();
+ createSizeGroup ();
+ createOrientationGroup ();
+
+ SelectionListener selectionListener = new SelectionAdapter () {
+ @Override
+ public void widgetSelected (SelectionEvent event) {
+ if ((event.widget.getStyle () & SWT.RADIO) != 0) {
+ if (!((Button) event.widget).getSelection ()) return;
+ }
+ if (!handleTextDirection (event.widget)) {
+ recreateExampleWidgets ();
+ }
+ }
+ };
+ // attach listeners to the Orientation buttons
+ rtlButton.addSelectionListener (selectionListener);
+ ltrButton.addSelectionListener (selectionListener);
+ defaultOrietationButton.addSelectionListener (selectionListener);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java
index 0ae9a4bce0..6da9e63b7c 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java
@@ -11,14 +11,23 @@
package org.eclipse.swt.examples.controlexample;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
-import java.io.*;
-import java.text.*;
-import java.util.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
public class ControlExample {
private static ResourceBundle resourceBundle =
@@ -83,6 +92,7 @@ public class ControlExample {
return new Tab [] {
new ButtonTab (this),
new CanvasTab (this),
+ new ColorTab(this),
new ComboTab (this),
new CoolBarTab (this),
new DateTimeTab (this),

Back to the top