summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorCarolyn MacLeod <carolyn>2003-11-14 17:07:16 +0000
committerCarolyn MacLeod <carolyn>2003-11-14 17:07:16 +0000
commit0b3c64915dbf572d29b0385fcd30962f1fda3994 (patch)
treebb0de32e6265e41ebbafd9d7d30e47153a1ba0d6 /examples
parent2c35de82ae65c7619247302d81332aa442fdb466 (diff)
downloadeclipse.platform.swt-0b3c64915dbf572d29b0385fcd30962f1fda3994.tar.gz
eclipse.platform.swt-0b3c64915dbf572d29b0385fcd30962f1fda3994.tar.xz
eclipse.platform.swt-0b3c64915dbf572d29b0385fcd30962f1fda3994.zip
Added CanvasTab
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/examples_control.properties3
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java304
-rwxr-xr-xexamples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java1
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java8
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java8
-rwxr-xr-xexamples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java26
-rwxr-xr-xexamples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java12
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTreeTab.java12
8 files changed, 340 insertions, 34 deletions
diff --git a/examples/org.eclipse.swt.examples/src/examples_control.properties b/examples/org.eclipse.swt.examples/src/examples_control.properties
index 508501a9cd..f9e07fe4bf 100644
--- a/examples/org.eclipse.swt.examples/src/examples_control.properties
+++ b/examples/org.eclipse.swt.examples/src/examples_control.properties
@@ -26,7 +26,7 @@ Three = Three
Image_Buttons = Image Buttons
Control_Example = Control Example
Parameters = Parameters
-State = State
+Other = Other
Enabled = Enabled
Visible = Visible
Preferred = Preferred
@@ -38,6 +38,7 @@ Clear = Clear
Select_All = Select All
Deselect_All = Deselect All
OK = OK
+FillDamage = Fill Damaged Area With Color
Title_Text = Title Text
Text_Labels = Text Labels
Image_Labels = Image Labels
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java
new file mode 100644
index 0000000000..5c612487e6
--- /dev/null
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java
@@ -0,0 +1,304 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.examples.controlexample;
+
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.layout.*;
+
+class CanvasTab extends Tab {
+ static int colors [] = {
+ SWT.COLOR_RED,
+ SWT.COLOR_GREEN,
+ SWT.COLOR_BLUE,
+ SWT.COLOR_MAGENTA,
+ SWT.COLOR_YELLOW,
+ SWT.COLOR_CYAN,
+ SWT.COLOR_DARK_RED,
+ SWT.COLOR_DARK_GREEN,
+ SWT.COLOR_DARK_BLUE,
+ SWT.COLOR_DARK_MAGENTA,
+ SWT.COLOR_DARK_YELLOW,
+ SWT.COLOR_DARK_CYAN
+ };
+
+ /* Example widgets and groups that contain them */
+ Canvas canvas;
+ Group canvasGroup;
+
+ /* Style widgets added to the "Style" group */
+ Button horizontalButton, verticalButton, noBackgroundButton, noFocusButton, noMergePaintsButton, noRedrawResizeButton;
+
+ /* Other widgets added to the "Other" group */
+ Button caretButton, fillDamageButton;
+
+ int paintCount;
+ int cx, cy;
+ int maxX, maxY;
+
+ /**
+ * Creates the Tab within a given instance of ControlExample.
+ */
+ CanvasTab(ControlExample instance) {
+ super(instance);
+ }
+
+ /**
+ * Creates a bitmap image.
+ */
+ Image createBitmapImage (Display display, String name) {
+ ImageData source = new ImageData(ControlExample.class.getResourceAsStream(name + ".bmp"));
+ ImageData mask = new ImageData(ControlExample.class.getResourceAsStream(name + "_mask.bmp"));
+ return new Image (display, source, mask);
+ }
+
+ /**
+ * Creates the "Other" group.
+ */
+ void createOtherGroup () {
+ super.createOtherGroup ();
+
+ /* Create display controls specific to this example */
+ caretButton = new Button (otherGroup, SWT.CHECK);
+ caretButton.setText (ControlExample.getResourceString("Caret"));
+ fillDamageButton = new Button (otherGroup, SWT.CHECK);
+ fillDamageButton.setText (ControlExample.getResourceString("FillDamage"));
+
+ /* Add the listeners */
+ caretButton.addSelectionListener (new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ setCaret ();
+ }
+ });
+ }
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup () {
+ super.createExampleGroup ();
+
+ /* Create a group for the canvas widget */
+ canvasGroup = new Group (exampleGroup, SWT.NONE);
+ canvasGroup.setLayout (new GridLayout ());
+ canvasGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ canvasGroup.setText ("Canvas");
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+
+ /* Compute the widget style */
+ int style = getDefaultStyle();
+ if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
+ if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
+ if (borderButton.getSelection ()) style |= SWT.BORDER;
+ if (noBackgroundButton.getSelection ()) style |= SWT.NO_BACKGROUND;
+ if (noFocusButton.getSelection ()) style |= SWT.NO_FOCUS;
+ if (noMergePaintsButton.getSelection ()) style |= SWT.NO_MERGE_PAINTS;
+ if (noRedrawResizeButton.getSelection ()) style |= SWT.NO_REDRAW_RESIZE;
+
+ /* Create the example widgets */
+ paintCount = 0; cx = 0; cy = 0;
+ canvas = new Canvas (canvasGroup, style);
+ canvas.addPaintListener(new PaintListener () {
+ public void paintControl(PaintEvent e) {
+ paintCount++;
+ GC gc = e.gc;
+ if (fillDamageButton.getSelection ()) {
+ Color color = e.display.getSystemColor (colors [paintCount % colors.length]);
+ gc.setBackground(color);
+ gc.fillRectangle(e.x, e.y, e.width, e.height);
+ }
+ Point size = canvas.getSize ();
+ gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
+ String counter = new Integer(paintCount).toString();
+ Point extent = gc.stringExtent(counter);
+ gc.drawString(counter, cx + (size.x - extent.x) / 2, cy + (size.y - extent.y) / 2);
+ }
+ });
+ canvas.addControlListener(new ControlAdapter() {
+ public void controlResized(ControlEvent event) {
+ Point size = canvas.getSize ();
+ maxX = size.x * 3 / 2; maxY = size.y * 3 / 2;
+ resizeScrollBars ();
+ }
+ });
+ ScrollBar bar = canvas.getHorizontalBar();
+ if (bar != null) {
+ bar.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ scrollHorizontal ((ScrollBar)event.widget);
+ }
+ });
+ }
+ bar = canvas.getVerticalBar();
+ if (bar != null) {
+ bar.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ scrollVertical ((ScrollBar)event.widget);
+ }
+ });
+ }
+ resizeScrollBars ();
+ }
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup() {
+ super.createStyleGroup();
+
+ /* Create the extra widgets */
+ horizontalButton = new Button (styleGroup, SWT.CHECK);
+ horizontalButton.setText ("SWT.H_SCROLL");
+ horizontalButton.setSelection(true);
+ verticalButton = new Button (styleGroup, SWT.CHECK);
+ verticalButton.setText ("SWT.V_SCROLL");
+ verticalButton.setSelection(true);
+ borderButton = new Button (styleGroup, SWT.CHECK);
+ borderButton.setText ("SWT.BORDER");
+ noBackgroundButton = new Button (styleGroup, SWT.CHECK);
+ noBackgroundButton.setText ("SWT.NO_BACKGROUND");
+ noFocusButton = new Button (styleGroup, SWT.CHECK);
+ noFocusButton.setText ("SWT.NO_FOCUS");
+ noMergePaintsButton = new Button (styleGroup, SWT.CHECK);
+ noMergePaintsButton.setText ("SWT.NO_MERGE_PAINTS");
+ noRedrawResizeButton = new Button (styleGroup, SWT.CHECK);
+ noRedrawResizeButton.setText ("SWT.NO_REDRAW_RESIZE");
+ }
+
+ /**
+ * Creates the tab folder page.
+ *
+ * @param tabFolder org.eclipse.swt.widgets.TabFolder
+ * @return the new page for the tab folder
+ */
+ Composite createTabFolderPage (TabFolder tabFolder) {
+ super.createTabFolderPage (tabFolder);
+
+ /*
+ * Add a resize listener to the tabFolderPage so that
+ * if the user types into the example widget to change
+ * its preferred size, and then resizes the shell, we
+ * recalculate the preferred size correctly.
+ */
+ tabFolderPage.addControlListener(new ControlAdapter() {
+ public void controlResized(ControlEvent e) {
+ setExampleWidgetSize ();
+ }
+ });
+
+ return tabFolderPage;
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [] {canvas};
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return "Canvas";
+ }
+
+ /**
+ * Resizes the maximum and thumb of both scrollbars.
+ */
+ void resizeScrollBars () {
+ Rectangle clientArea = canvas.getClientArea();
+ ScrollBar bar = canvas.getHorizontalBar();
+ if (bar != null) {
+ bar.setMaximum(maxX);
+ bar.setThumb(clientArea.width);
+ bar.setPageIncrement(clientArea.width);
+ }
+ bar = canvas.getVerticalBar();
+ if (bar != null) {
+ bar.setMaximum(maxY);
+ bar.setThumb(clientArea.height);
+ bar.setPageIncrement(clientArea.height);
+ }
+ }
+
+ /**
+ * Scrolls the canvas horizontally.
+ *
+ * @param scrollBar
+ */
+ void scrollHorizontal (ScrollBar scrollBar) {
+ Rectangle bounds = canvas.getClientArea();
+ int x = -scrollBar.getSelection();
+ if (x + maxX < bounds.width) {
+ x = bounds.width - maxX;
+ }
+ canvas.scroll(x, cy, cx, cy, maxX, maxY, false);
+ cx = x;
+ }
+
+ /**
+ * Scrolls the canvas vertically.
+ *
+ * @param scrollBar
+ */
+ void scrollVertical (ScrollBar scrollBar) {
+ Rectangle bounds = canvas.getClientArea();
+ int y = -scrollBar.getSelection();
+ if (y + maxY < bounds.height) {
+ y = bounds.height - maxY;
+ }
+ canvas.scroll(cx, y, cx, cy, maxX, maxY, false);
+ cy = y;
+ }
+
+ /**
+ * Sets the caret into the "Example" widget.
+ */
+ void setCaret () {
+ if (caretButton.getSelection ()) {
+ Caret caret = new Caret(canvas, SWT.NONE);
+ Font font = canvas.getFont();
+ caret.setFont(font);
+ GC gc = new GC(canvas);
+ gc.setFont(font);
+ caret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight());
+ gc.dispose();
+ canvas.setCaret (caret);
+ canvas.setFocus();
+ } else {
+ canvas.setCaret (null);
+ }
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ horizontalButton.setSelection ((canvas.getStyle () & SWT.H_SCROLL) != 0);
+ verticalButton.setSelection ((canvas.getStyle () & SWT.V_SCROLL) != 0);
+ borderButton.setSelection ((canvas.getStyle () & SWT.BORDER) != 0);
+ noBackgroundButton.setSelection ((canvas.getStyle () & SWT.NO_BACKGROUND) != 0);
+ noFocusButton.setSelection ((canvas.getStyle () & SWT.NO_FOCUS) != 0);
+ noMergePaintsButton.setSelection ((canvas.getStyle () & SWT.NO_MERGE_PAINTS) != 0);
+ noRedrawResizeButton.setSelection ((canvas.getStyle () & SWT.NO_REDRAW_RESIZE) != 0);
+ setCaret ();
+ }
+}
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 df7d173d88..3201eac2f2 100755
--- 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
@@ -56,6 +56,7 @@ public class ControlExample {
Tab[] createTabs() {
return new Tab [] {
new ButtonTab (this),
+ new CanvasTab (this),
new ComboTab (this),
new CoolBarTab (this),
new DialogTab (this),
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java
index 8f331b0d30..7a9180a19d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java
@@ -37,13 +37,13 @@ class CoolBarTab extends Tab {
}
/**
- * Creates the "Display" group.
+ * Creates the "Other" group.
*/
- void createDisplayGroup () {
- super.createDisplayGroup ();
+ void createOtherGroup () {
+ super.createOtherGroup ();
/* Create display controls specific to this example */
- lockedButton = new Button (displayGroup, SWT.CHECK);
+ lockedButton = new Button (otherGroup, SWT.CHECK);
lockedButton.setText (ControlExample.getResourceString("Locked"));
/* Add the listeners */
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java
index 00f666ff8e..7d1b496528 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java
@@ -34,13 +34,13 @@ class GroupTab extends Tab {
}
/**
- * Creates the "Display" group.
+ * Creates the "Other" group.
*/
- void createDisplayGroup () {
- super.createDisplayGroup ();
+ void createOtherGroup () {
+ super.createOtherGroup ();
/* Create display controls specific to this example */
- titleButton = new Button (displayGroup, SWT.CHECK);
+ titleButton = new Button (otherGroup, SWT.CHECK);
titleButton.setText (ControlExample.getResourceString("Title_Text"));
/* Add the listeners */
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java
index db84a04bb5..bef173772e 100755
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java
@@ -31,7 +31,7 @@ import org.eclipse.swt.events.*;
* column contains "Control" group. The "Control" group
* contains controls that allow the user to interact with
* the example control. The "Control" group typically
- * contains a "Style", "State" and "Size" group. Subclasses
+ * contains a "Style", "Other" and "Size" group. Subclasses
* can override these defaults to augment a group or stop
* a group from being created.
*/
@@ -42,7 +42,7 @@ abstract class Tab {
/* Common groups and composites */
Composite tabFolderPage;
- Group exampleGroup, controlGroup, listenersGroup, displayGroup, sizeGroup, styleGroup, colorGroup;
+ Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup;
/* Controlling instance */
final ControlExample instance;
@@ -100,7 +100,7 @@ abstract class Tab {
/*
* Create the "Control" group. This is the group on the
* right half of each example tab. It consists of the
- * style group, the display group and the size group.
+ * "Style" group, the "Other" group and the "Size" group.
*/
controlGroup = new Group (tabFolderPage, SWT.NONE);
controlGroup.setLayout (new GridLayout (2, true));
@@ -109,7 +109,7 @@ abstract class Tab {
/* Create individual groups inside the "Control" group */
createStyleGroup ();
- createDisplayGroup ();
+ createOtherGroup ();
createSizeGroup ();
createColorGroup ();
if (RTL_SUPPORT_ENABLE) {
@@ -153,7 +153,7 @@ abstract class Tab {
* Creates the "Control" widget children.
* Subclasses override this method to augment
* the standard controls created in the "Style",
- * "State" and "Size" groups.
+ * "Other" and "Size" groups.
*/
void createControlWidgets () {
}
@@ -262,20 +262,20 @@ abstract class Tab {
}
/**
- * Creates the "State" group. This is typically
+ * Creates the "Other" group. This is typically
* a child of the "Control" group.
*/
- void createDisplayGroup () {
+ void createOtherGroup () {
/* Create the group */
- displayGroup = new Group (controlGroup, SWT.NONE);
- displayGroup.setLayout (new GridLayout ());
- displayGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
- displayGroup.setText (ControlExample.getResourceString("State"));
+ otherGroup = new Group (controlGroup, SWT.NONE);
+ otherGroup.setLayout (new GridLayout ());
+ otherGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ otherGroup.setText (ControlExample.getResourceString("Other"));
/* Create the controls */
- enabledButton = new Button(displayGroup, SWT.CHECK);
+ enabledButton = new Button(otherGroup, SWT.CHECK);
enabledButton.setText(ControlExample.getResourceString("Enabled"));
- visibleButton = new Button(displayGroup, SWT.CHECK);
+ visibleButton = new Button(otherGroup, SWT.CHECK);
visibleButton.setText(ControlExample.getResourceString("Visible"));
/* Add the listeners */
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java
index 3222ec5d47..54df9dc0f2 100755
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java
@@ -25,7 +25,7 @@ class TableTab extends ScrollableTab {
/* Style widgets added to the "Style" group */
Button checkButton, fullSelectionButton, hideSelectionButton;
- /* Display widgets added to the "Display" group */
+ /* Other widgets added to the "Other" group */
Button headerVisibleButton, linesVisibleButton;
/* Controls and resources added to the "Colors" group */
@@ -128,15 +128,15 @@ class TableTab extends ScrollableTab {
}
/**
- * Creates the "Display" group.
+ * Creates the "Other" group.
*/
- void createDisplayGroup () {
- super.createDisplayGroup ();
+ void createOtherGroup () {
+ super.createOtherGroup ();
/* Create display controls specific to this example */
- headerVisibleButton = new Button (displayGroup, SWT.CHECK);
+ headerVisibleButton = new Button (otherGroup, SWT.CHECK);
headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible"));
- linesVisibleButton = new Button (displayGroup, SWT.CHECK);
+ linesVisibleButton = new Button (otherGroup, SWT.CHECK);
linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible"));
/* Add the listeners */
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTreeTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTreeTab.java
index 0625b68184..c414a74c3a 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTreeTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTreeTab.java
@@ -25,7 +25,7 @@ class TableTreeTab extends ScrollableTab {
/* Style widgets added to the "Style" group */
Button checkButton, fullSelectionButton;
- /* Display widgets added to the "Display" group */
+ /* Other widgets added to the "Other" group */
Button headerVisibleButton, linesVisibleButton;
/**
@@ -36,15 +36,15 @@ class TableTreeTab extends ScrollableTab {
}
/**
- * Creates the "Display" group.
+ * Creates the "Other" group.
*/
- void createDisplayGroup () {
- super.createDisplayGroup ();
+ void createOtherGroup () {
+ super.createOtherGroup ();
/* Create display controls specific to this example */
- headerVisibleButton = new Button (displayGroup, SWT.CHECK);
+ headerVisibleButton = new Button (otherGroup, SWT.CHECK);
headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible"));
- linesVisibleButton = new Button (displayGroup, SWT.CHECK);
+ linesVisibleButton = new Button (otherGroup, SWT.CHECK);
linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible"));
/* Add the listeners */