AlignableTab
is the abstract
+ * superclass of example controls that can be
+ * aligned.
+ */
+abstract class AlignableTab extends Tab {
+
+ /* Allignment Controls */
+ Button leftButton, rightButton, centerButton;
+
+ /* Alignment Group */
+ Group allignmentGroup;
+
+ /**
+ * Creates the "Control" group.
+ */
+ void createControlGroup () {
+ super.createControlGroup ();
+
+ /* Create the group */
+ allignmentGroup = new Group (controlGroup, SWT.NULL);
+ allignmentGroup.setLayout (new GridLayout ());
+ allignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL |
+ GridData.VERTICAL_ALIGN_FILL));
+ allignmentGroup.setText (ControlPlugin.getResourceString("Alignment"));
+
+ /* Create the controls */
+ leftButton = new Button (allignmentGroup, SWT.RADIO);
+ leftButton.setText (ControlPlugin.getResourceString("Left"));
+ centerButton = new Button (allignmentGroup, SWT.RADIO);
+ centerButton.setText(ControlPlugin.getResourceString("Center"));
+ rightButton = new Button (allignmentGroup, SWT.RADIO);
+ rightButton.setText (ControlPlugin.getResourceString("Right"));
+
+ /* Add the listeners */
+ SelectionListener selectionListener = new SelectionAdapter () {
+ public void widgetSelected(SelectionEvent event) {
+ if (!((Button) event.widget).getSelection ()) return;
+ setExampleWidgetAlignment ();
+ };
+ };
+ leftButton.addSelectionListener (selectionListener);
+ centerButton.addSelectionListener (selectionListener);
+ rightButton.addSelectionListener (selectionListener);
+ }
+
+ /**
+ * Sets the alignment of the "Example" widgets.
+ */
+ abstract void setExampleWidgetAlignment ();
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ Control [] controls = getExampleWidgets ();
+ if (controls.length != 0) {
+ leftButton.setSelection ((controls [0].getStyle () & SWT.LEFT) != 0);
+ centerButton.setSelection ((controls [0].getStyle () & SWT.CENTER) != 0);
+ rightButton.setSelection ((controls [0].getStyle () & SWT.RIGHT) != 0);
+ }
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ButtonTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ButtonTab.java
new file mode 100755
index 0000000000..036842b1b3
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ButtonTab.java
@@ -0,0 +1,181 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+/**
+ * ButtonTab
is the class that
+ * demonstrates SWT buttons.
+ */
+class ButtonTab extends AlignableTab {
+
+ /* Example widgets and groups that contain them */
+ Button button1, button2, button3, button4, button5, button6;
+ Group textButtonGroup, imageButtonGroup;
+
+ /* Allignment widgets added to the "Control" group */
+ Button upButton, downButton;
+
+ /* Style widgets added to the "Style" group */
+ Button pushButton, checkButton, radioButton, toggleButton, arrowButton;
+
+ /**
+ * Creates the "Control" group.
+ */
+ void createControlGroup () {
+ super.createControlGroup ();
+
+ /* Create the controls */
+ upButton = new Button (allignmentGroup, SWT.RADIO);
+ upButton.setText (ControlPlugin.getResourceString("Up"));
+ downButton = new Button (allignmentGroup, SWT.RADIO);
+ downButton.setText (ControlPlugin.getResourceString("Down"));
+
+ /* Add the listeners */
+ SelectionListener selectionListener = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ if (!((Button) event.widget).getSelection()) return;
+ setExampleWidgetAlignment ();
+ };
+ };
+ upButton.addSelectionListener(selectionListener);
+ downButton.addSelectionListener(selectionListener);
+ }
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup () {
+ super.createExampleGroup ();
+
+ /* Create a group for text buttons */
+ textButtonGroup = new Group(exampleGroup, SWT.NONE);
+ GridLayout gridLayout = new GridLayout ();
+ textButtonGroup.setLayout(gridLayout);
+ gridLayout.numColumns = 3;
+ textButtonGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ textButtonGroup.setText (ControlPlugin.getResourceString("Text_Buttons"));
+
+ /* Create a group for the image buttons */
+ imageButtonGroup = new Group(exampleGroup, SWT.NONE);
+ gridLayout = new GridLayout();
+ imageButtonGroup.setLayout(gridLayout);
+ gridLayout.numColumns = 3;
+ imageButtonGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ imageButtonGroup.setText (ControlPlugin.getResourceString("Image_Buttons"));
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+
+ /* Compute the widget style */
+ int style = SWT.NONE;
+ if (pushButton.getSelection()) style |= SWT.PUSH;
+ if (checkButton.getSelection()) style |= SWT.CHECK;
+ if (radioButton.getSelection()) style |= SWT.RADIO;
+ if (toggleButton.getSelection()) style |= SWT.TOGGLE;
+ if (arrowButton.getSelection()) style |= SWT.ARROW;
+ if (borderButton.getSelection()) style |= SWT.BORDER;
+
+ /* Create the example widgets */
+ button1 = new Button(textButtonGroup, style);
+ button1.setText(ControlPlugin.getResourceString("One"));
+ button2 = new Button(textButtonGroup, style);
+ button2.setText(ControlPlugin.getResourceString("Two"));
+ button3 = new Button(textButtonGroup, style);
+ button3.setText(ControlPlugin.getResourceString("Three"));
+ button4 = new Button(imageButtonGroup, style);
+ button4.setImage(ControlPlugin.images[ControlPlugin.ciClosedFolder]);
+ button5 = new Button(imageButtonGroup, style);
+ button5.setImage(ControlPlugin.images[ControlPlugin.ciOpenFolder]);
+ button6 = new Button(imageButtonGroup, style);
+ button6.setImage(ControlPlugin.images[ControlPlugin.ciTarget]);
+ }
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup() {
+ super.createStyleGroup ();
+
+ /* Create the extra widgets */
+ pushButton = new Button (styleGroup, SWT.RADIO);
+ pushButton.setText(ControlPlugin.getResourceString("SWT_PUSH"));
+ checkButton = new Button (styleGroup, SWT.RADIO);
+ checkButton.setText (ControlPlugin.getResourceString("SWT_CHECK"));
+ radioButton = new Button (styleGroup, SWT.RADIO);
+ radioButton.setText (ControlPlugin.getResourceString("SWT_RADIO"));
+ toggleButton = new Button (styleGroup, SWT.RADIO);
+ toggleButton.setText (ControlPlugin.getResourceString("SWT_TOGGLE"));
+ arrowButton = new Button (styleGroup, SWT.RADIO);
+ arrowButton.setText (ControlPlugin.getResourceString("SWT_ARROW"));
+ borderButton = new Button (styleGroup, SWT.CHECK);
+ borderButton.setText (ControlPlugin.getResourceString("SWT_BORDER"));
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [] {button1, button2, button3, button4, button5, button6};
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("Button");
+ }
+
+ /**
+ * Sets the alignment of the "Example" widgets.
+ */
+ void setExampleWidgetAlignment () {
+ int allignment = 0;
+ if (leftButton.getSelection ()) allignment = SWT.LEFT;
+ if (centerButton.getSelection ()) allignment = SWT.CENTER;
+ if (rightButton.getSelection ()) allignment = SWT.RIGHT;
+ if (upButton.getSelection ()) allignment = SWT.UP;
+ if (downButton.getSelection ()) allignment = SWT.DOWN;
+ button1.setAlignment (allignment);
+ button2.setAlignment (allignment);
+ button3.setAlignment (allignment);
+ button4.setAlignment (allignment);
+ button5.setAlignment (allignment);
+ button6.setAlignment (allignment);
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ if (arrowButton.getSelection ()) {
+ upButton.setEnabled (true);
+ centerButton.setEnabled (false);
+ downButton.setEnabled (true);
+ } else {
+ upButton.setEnabled (false);
+ centerButton.setEnabled (true);
+ downButton.setEnabled (false);
+ }
+ upButton.setSelection ((button1.getStyle () & SWT.UP) != 0);
+ downButton.setSelection ((button1.getStyle () & SWT.DOWN) != 0);
+ pushButton.setSelection ((button1.getStyle () & SWT.PUSH) != 0);
+ checkButton.setSelection ((button1.getStyle () & SWT.CHECK) != 0);
+ radioButton.setSelection ((button1.getStyle () & SWT.RADIO) != 0);
+ toggleButton.setSelection ((button1.getStyle () & SWT.TOGGLE) != 0);
+ arrowButton.setSelection ((button1.getStyle () & SWT.ARROW) != 0);
+ borderButton.setSelection ((button1.getStyle () & SWT.BORDER) != 0);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ComboTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ComboTab.java
new file mode 100755
index 0000000000..37ef288ece
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ComboTab.java
@@ -0,0 +1,107 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class ComboTab extends Tab {
+
+ /* Example widgets and groups that contain them */
+ Combo combo1;
+ Group comboGroup;
+
+ /* Style widgets added to the "Style" group */
+ Button dropDownButton, readOnlyButton, simpleButton;
+
+ static String [] ListData = {ControlPlugin.getResourceString("ListData0_0"),
+ ControlPlugin.getResourceString("ListData0_1"),
+ ControlPlugin.getResourceString("ListData0_2"),
+ ControlPlugin.getResourceString("ListData0_3"),
+ ControlPlugin.getResourceString("ListData0_4"),
+ ControlPlugin.getResourceString("ListData0_5"),
+ ControlPlugin.getResourceString("ListData0_6"),
+ ControlPlugin.getResourceString("ListData0_7"),
+ ControlPlugin.getResourceString("ListData0_8")};
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup () {
+ super.createExampleGroup ();
+
+ /* Create a group for the combo box */
+ comboGroup = new Group (exampleGroup, SWT.NULL);
+ comboGroup.setLayout (new GridLayout ());
+ comboGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ comboGroup.setText (ControlPlugin.getResourceString("Combo"));
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+
+ /* Compute the widget style */
+ int style = SWT.NONE;
+ if (dropDownButton.getSelection ()) style |= SWT.DROP_DOWN;
+ if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
+ if (simpleButton.getSelection ()) style |= SWT.SIMPLE;
+ if (borderButton.getSelection ()) style |= SWT.BORDER;
+
+ /* Create the example widgets */
+ combo1 = new Combo (comboGroup, style);
+ combo1.setItems (ListData);
+ if (ListData.length >= 3) {
+ combo1.setText(ListData [2]);
+ }
+ }
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup () {
+ super.createStyleGroup ();
+
+ /* Create the extra widgets */
+ dropDownButton = new Button (styleGroup, SWT.RADIO);
+ dropDownButton.setText (ControlPlugin.getResourceString("SWT_DROP_DOWN"));
+ simpleButton = new Button (styleGroup, SWT.RADIO);
+ simpleButton.setText(ControlPlugin.getResourceString("SWT_SIMPLE"));
+ readOnlyButton = new Button (styleGroup, SWT.CHECK);
+ readOnlyButton.setText (ControlPlugin.getResourceString("SWT_READ_ONLY"));
+ borderButton = new Button (styleGroup, SWT.CHECK);
+ borderButton.setText (ControlPlugin.getResourceString("SWT_BORDER"));
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [] {combo1};
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("Combo");
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ dropDownButton.setSelection ((combo1.getStyle () & SWT.DROP_DOWN) != 0);
+ simpleButton.setSelection ((combo1.getStyle () & SWT.SIMPLE) != 0);
+ readOnlyButton.setSelection ((combo1.getStyle () & SWT.READ_ONLY) != 0);
+ borderButton.setSelection ((combo1.getStyle () & SWT.BORDER) != 0);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/DialogTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/DialogTab.java
new file mode 100755
index 0000000000..14a9f7e301
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/DialogTab.java
@@ -0,0 +1,424 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class DialogTab extends Tab {
+ /* Example widgets and groups that contain them */
+ Group dialogStyleGroup, resultGroup;
+ Text textWidget;
+
+ /* Style widgets added to the "Style" group */
+ Combo dialogCombo;
+ Button okButton, cancelButton;
+ Button yesButton, noButton;
+ Button retryButton;
+ Button abortButton, ignoreButton;
+ Button iconErrorButton, iconInformationButton, iconQuestionButton;
+ Button iconWarningButton, iconWorkingButton;
+ Button modelessButton, primaryModalButton, applicationModalButton, systemModalButton;
+ Button saveButton, openButton;
+
+ static String [] FilterExtensions = {".txt.", ".bat", ".doc"};
+ static String [] FilterNames = {ControlPlugin.getResourceString("FilterName_0"),
+ ControlPlugin.getResourceString("FilterName_1"),
+ ControlPlugin.getResourceString("FilterName_2")};
+
+ /**
+ * Handle a button style selection event.
+ *
+ * @param event the selection event
+ */
+ void buttonStyleSelected(SelectionEvent event) {
+ /*
+ * Only certain combinations of button styles are
+ * supported for various dialogs. Make sure the
+ * control widget reflects only valid combinations.
+ */
+ okButton.setEnabled (
+ !(yesButton.getSelection () || noButton.getSelection () ||
+ retryButton.getSelection () || abortButton.getSelection () ||
+ ignoreButton.getSelection ()));
+ cancelButton.setEnabled (
+ !(abortButton.getSelection () || ignoreButton.getSelection ()));
+ yesButton.setEnabled (
+ !(okButton.getSelection () || retryButton.getSelection () ||
+ abortButton.getSelection () || ignoreButton.getSelection ()));
+ noButton.setEnabled (
+ !(okButton.getSelection () || retryButton.getSelection () ||
+ abortButton.getSelection () || ignoreButton.getSelection ()));
+ retryButton.setEnabled (
+ !(okButton.getSelection() || yesButton.getSelection() || noButton.getSelection ()));
+ abortButton.setEnabled (
+ !(okButton.getSelection () || cancelButton.getSelection () ||
+ yesButton.getSelection () || noButton.getSelection ()));
+ ignoreButton.setEnabled (
+ !(okButton.getSelection () || cancelButton.getSelection () |
+ yesButton.getSelection () || noButton.getSelection ()));
+ }
+
+ /**
+ * Handle the create button selection event.
+ *
+ * @param event org.eclipse.swt.events.SelectionEvent
+ */
+ void createButtonSelected(SelectionEvent event) {
+
+ /* Compute the appropriate dialog style */
+ int style = SWT.NULL;
+ if (okButton.getEnabled () && okButton.getSelection ()) style |= SWT.OK;
+ if (cancelButton.getEnabled () && cancelButton.getSelection ()) style |= SWT.CANCEL;
+ if (yesButton.getEnabled () && yesButton.getSelection ()) style |= SWT.YES;
+ if (noButton.getEnabled () && noButton.getSelection ()) style |= SWT.NO;
+ if (retryButton.getEnabled () && retryButton.getSelection ()) style |= SWT.RETRY;
+ if (abortButton.getEnabled () && abortButton.getSelection ()) style |= SWT.ABORT;
+ if (ignoreButton.getEnabled () && ignoreButton.getSelection ()) style |= SWT.IGNORE;
+ if (iconErrorButton.getEnabled () && iconErrorButton.getSelection ()) style |= SWT.ICON_ERROR;
+ if (iconInformationButton.getEnabled () && iconInformationButton.getSelection ()) style |= SWT.ICON_INFORMATION;
+ if (iconQuestionButton.getEnabled () && iconQuestionButton.getSelection ()) style |= SWT.ICON_QUESTION;
+ if (iconWarningButton.getEnabled () && iconWarningButton.getSelection ()) style |= SWT.ICON_WARNING;
+ if (iconWorkingButton.getEnabled () && iconWorkingButton.getSelection ()) style |= SWT.ICON_WORKING;
+ if (primaryModalButton.getEnabled () && primaryModalButton.getSelection ()) style |= SWT.PRIMARY_MODAL;
+ if (applicationModalButton.getEnabled () && applicationModalButton.getSelection ()) style |= SWT.APPLICATION_MODAL;
+ if (systemModalButton.getEnabled () && systemModalButton.getSelection ()) style |= SWT.SYSTEM_MODAL;
+ if (saveButton.getEnabled () && saveButton.getSelection ()) style |= SWT.SAVE;
+ if (openButton.getEnabled () && openButton.getSelection ()) style |= SWT.OPEN;
+
+ /* Open the appropriate dialog type */
+ String name = dialogCombo.getText ();
+ Shell shell = tabFolderPage.getShell ();
+
+ if (name.equals (ControlPlugin.getResourceString("ColorDialog"))) {
+ ColorDialog dialog = new ColorDialog (shell ,style);
+ dialog.setRGB (new RGB (100, 100, 100));
+ dialog.setText (ControlPlugin.getResourceString("Title"));
+ RGB result = dialog.open ();
+ textWidget.append (ControlPlugin.getResourceString("ColorDialog") + Text.DELIMITER);
+ textWidget.append (ControlPlugin.getResourceString("Result") + " " + result + Text.DELIMITER + Text.DELIMITER);
+ return;
+ }
+
+ if (name.equals (ControlPlugin.getResourceString("DirectoryDialog"))) {
+ DirectoryDialog dialog = new DirectoryDialog (shell, style);
+ dialog.setMessage (ControlPlugin.getResourceString("Example_string"));
+ dialog.setText (ControlPlugin.getResourceString("Title"));
+ String result = dialog.open ();
+ textWidget.append (ControlPlugin.getResourceString("DirectoryDialog") + Text.DELIMITER);
+ textWidget.append (ControlPlugin.getResourceString("Result") + " " + result + Text.DELIMITER + Text.DELIMITER);
+ return;
+ }
+
+ if (name.equals (ControlPlugin.getResourceString("FileDialog"))) {
+ FileDialog dialog = new FileDialog (shell, style);
+ dialog.setFileName (ControlPlugin.getResourceString("readme_txt"));
+ dialog.setFilterNames (FilterNames);
+ dialog.setFilterExtensions (FilterExtensions);
+ dialog.setText (ControlPlugin.getResourceString("Title"));
+ String result = dialog.open();
+ textWidget.append (ControlPlugin.getResourceString("FileDialog") + Text.DELIMITER);
+ textWidget.append (ControlPlugin.getResourceString("Result") + " " + result + Text.DELIMITER + Text.DELIMITER);
+ return;
+ }
+
+ if (name.equals (ControlPlugin.getResourceString("FontDialog"))) {
+ FontDialog dialog = new FontDialog (shell, style);
+ dialog.setText (ControlPlugin.getResourceString("Title"));
+ FontData result = dialog.open ();
+ textWidget.append (ControlPlugin.getResourceString("FontDialog") + Text.DELIMITER);
+ textWidget.append (ControlPlugin.getResourceString("Result") + " " + result + Text.DELIMITER + Text.DELIMITER);
+ return;
+ }
+
+ if (name.equals(ControlPlugin.getResourceString("MessageBox"))) {
+ MessageBox dialog = new MessageBox (shell, style);
+ dialog.setMessage (ControlPlugin.getResourceString("Example_string"));
+ dialog.setText (ControlPlugin.getResourceString("Title"));
+ int result = dialog.open ();
+ textWidget.append (ControlPlugin.getResourceString("MessageBox") + Text.DELIMITER);
+ /*
+ * The resulting integer depends on the original
+ * dialog style. Decode the result and display it.
+ */
+ switch (result) {
+ case SWT.OK:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_OK"));
+ break;
+ case SWT.YES:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_YES"));
+ break;
+ case SWT.NO:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_NO"));
+ break;
+ case SWT.CANCEL:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_CANCEL"));
+ break;
+ case SWT.ABORT:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_ABORT"));
+ break;
+ case SWT.RETRY:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_RETRY"));
+ break;
+ case SWT.IGNORE:
+ textWidget.append (ControlPlugin.getResourceString("Result") + ControlPlugin.getResourceString("SWT_IGNORE"));
+ break;
+ default:
+ textWidget.append(ControlPlugin.getResourceString("Result") + result);
+ break;
+ }
+ textWidget.append (Text.DELIMITER + Text.DELIMITER);
+ }
+ }
+
+ /**
+ * Creates the "Control" group.
+ */
+ void createControlGroup () {
+ /*
+ * Create the "Control" group. This is the group on the
+ * left half of each example tab. It consists of the
+ * style group, the display group and the size group.
+ */
+ controlGroup = new Group (tabFolderPage, SWT.NULL);
+ GridLayout gridLayout= new GridLayout ();
+ controlGroup.setLayout(gridLayout);
+ gridLayout.numColumns = 2;
+ gridLayout.makeColumnsEqualWidth = true;
+ controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ controlGroup.setText (ControlPlugin.getResourceString("Parameters"));
+
+ /*
+ * Create a group to hold the dialog style combo box and
+ * create dialog button.
+ */
+ dialogStyleGroup = new Group (controlGroup, SWT.NULL);
+ dialogStyleGroup.setLayout (new GridLayout ());
+ GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_CENTER);
+ gridData.horizontalSpan = 2;
+ dialogStyleGroup.setLayoutData (gridData);
+ dialogStyleGroup.setText (ControlPlugin.getResourceString("Dialog_Type"));
+ }
+
+ /**
+ * Creates the "Control" widget children.
+ */
+ void createControlWidgets () {
+
+ /* Create the combo */
+ String [] strings = {
+ ControlPlugin.getResourceString("ColorDialog"),
+ ControlPlugin.getResourceString("DirectoryDialog"),
+ ControlPlugin.getResourceString("FileDialog"),
+ ControlPlugin.getResourceString("FontDialog"),
+ ControlPlugin.getResourceString("MessageBox"),
+ };
+ dialogCombo = new Combo (dialogStyleGroup, SWT.READ_ONLY);
+ dialogCombo.setItems (strings);
+ dialogCombo.setText (strings [0]);
+
+ /* Create the create dialog button */
+ Button createButton = new Button(dialogStyleGroup, SWT.NULL);
+ createButton.setText (ControlPlugin.getResourceString("Create_Dialog"));
+ createButton.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+
+ /* Create a group for the various dialog button style controls */
+ Group buttonStyleGroup = new Group (controlGroup, SWT.NULL);
+ buttonStyleGroup.setLayout (new GridLayout ());
+ buttonStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ buttonStyleGroup.setText (ControlPlugin.getResourceString("Button_Styles"));
+
+ /* Create the button style buttons */
+ okButton = new Button (buttonStyleGroup, SWT.CHECK);
+ okButton.setText (ControlPlugin.getResourceString("SWT_OK"));
+ cancelButton = new Button (buttonStyleGroup, SWT.CHECK);
+ cancelButton.setText (ControlPlugin.getResourceString("SWT_CANCEL"));
+ yesButton = new Button (buttonStyleGroup, SWT.CHECK);
+ yesButton.setText (ControlPlugin.getResourceString("SWT_YES"));
+ noButton = new Button (buttonStyleGroup, SWT.CHECK);
+ noButton.setText (ControlPlugin.getResourceString("SWT_NO"));
+ retryButton = new Button (buttonStyleGroup, SWT.CHECK);
+ retryButton.setText (ControlPlugin.getResourceString("SWT_RETRY"));
+ abortButton = new Button (buttonStyleGroup, SWT.CHECK);
+ abortButton.setText (ControlPlugin.getResourceString("SWT_ABORT"));
+ ignoreButton = new Button (buttonStyleGroup, SWT.CHECK);
+ ignoreButton.setText (ControlPlugin.getResourceString("SWT_IGNORE"));
+
+ /* Create a group for the icon style controls */
+ Group iconStyleGroup = new Group (controlGroup, SWT.NULL);
+ iconStyleGroup.setLayout (new GridLayout ());
+ iconStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ iconStyleGroup.setText (ControlPlugin.getResourceString("Icon_Styles"));
+
+ /* Create the icon style buttons */
+ iconErrorButton = new Button (iconStyleGroup, SWT.RADIO);
+ iconErrorButton.setText (ControlPlugin.getResourceString("SWT_ICON_ERROR"));
+ iconInformationButton = new Button (iconStyleGroup, SWT.RADIO);
+ iconInformationButton.setText (ControlPlugin.getResourceString("SWT_ICON_INFORMATION"));
+ iconQuestionButton = new Button (iconStyleGroup, SWT.RADIO);
+ iconQuestionButton.setText (ControlPlugin.getResourceString("SWT_ICON_QUESTION"));
+ iconWarningButton = new Button (iconStyleGroup, SWT.RADIO);
+ iconWarningButton.setText (ControlPlugin.getResourceString("SWT_ICON_WARNING"));
+ iconWorkingButton = new Button (iconStyleGroup, SWT.RADIO);
+ iconWorkingButton.setText (ControlPlugin.getResourceString("SWT_ICON_WORKING"));
+
+ /* Create a group for the modal style controls */
+ Group modalStyleGroup = new Group (controlGroup, SWT.NULL);
+ modalStyleGroup.setLayout (new GridLayout ());
+ modalStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ modalStyleGroup.setText (ControlPlugin.getResourceString("Modal_Styles"));
+
+ /* Create the modal style buttons */
+ modelessButton = new Button (modalStyleGroup, SWT.RADIO);
+ modelessButton.setText (ControlPlugin.getResourceString("SWT_MODELESS"));
+ primaryModalButton = new Button (modalStyleGroup, SWT.RADIO);
+ primaryModalButton.setText (ControlPlugin.getResourceString("SWT_PRIMARY_MODAL"));
+ applicationModalButton = new Button (modalStyleGroup, SWT.RADIO);
+ applicationModalButton.setText (ControlPlugin.getResourceString("SWT_APPLICATION_MODAL"));
+ systemModalButton = new Button (modalStyleGroup, SWT.RADIO);
+ systemModalButton.setText (ControlPlugin.getResourceString("SWT_SYSTEM_MODAL"));
+
+ /* Create a group for the file dialog style controls */
+ Group fileDialogStyleGroup = new Group (controlGroup, SWT.NULL);
+ fileDialogStyleGroup.setLayout (new GridLayout ());
+ fileDialogStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ fileDialogStyleGroup.setText (ControlPlugin.getResourceString("File_Dialog_Styles"));
+
+ /* Create the file dialog style buttons */
+ saveButton = new Button (fileDialogStyleGroup, SWT.RADIO);
+ saveButton.setText (ControlPlugin.getResourceString("SWT_SAVE"));
+ openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
+ openButton.setText(ControlPlugin.getResourceString("SWT_OPEN"));
+
+ /* Add the listeners */
+ dialogCombo.addSelectionListener (new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ dialogSelected (event);
+ };
+ });
+ createButton.addSelectionListener (new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ createButtonSelected (event);
+ };
+ });
+ SelectionListener buttonStyleListener = new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ buttonStyleSelected (event);
+ };
+ };
+ okButton.addSelectionListener (buttonStyleListener);
+ cancelButton.addSelectionListener (buttonStyleListener);
+ yesButton.addSelectionListener (buttonStyleListener);
+ noButton.addSelectionListener (buttonStyleListener);
+ retryButton.addSelectionListener (buttonStyleListener);
+ abortButton.addSelectionListener (buttonStyleListener);
+ ignoreButton.addSelectionListener (buttonStyleListener);
+
+ /* Set default values for style buttons */
+ okButton.setEnabled (false);
+ cancelButton.setEnabled (false);
+ yesButton.setEnabled (false);
+ noButton.setEnabled (false);
+ retryButton.setEnabled (false);
+ abortButton.setEnabled (false);
+ ignoreButton.setEnabled (false);
+ iconErrorButton.setEnabled (false);
+ iconInformationButton.setEnabled (false);
+ iconQuestionButton.setEnabled (false);
+ iconWarningButton.setEnabled (false);
+ iconWorkingButton.setEnabled (false);
+ saveButton.setEnabled (false);
+ openButton.setEnabled (false);
+ openButton.setSelection (true);
+ iconInformationButton.setSelection (true);
+ modelessButton.setSelection (true);
+ }
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup () {
+ super.createExampleGroup ();
+
+ /*
+ * Create a group for the text widget to display
+ * the results returned by the example dialogs.
+ */
+ resultGroup = new Group (exampleGroup, SWT.NULL);
+ resultGroup.setLayout (new GridLayout ());
+ resultGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ resultGroup.setText (ControlPlugin.getResourceString("Dialog_Result"));
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+ /*
+ * Create a multi lined, scrolled text widget for output.
+ */
+ textWidget = new Text(resultGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ GridData gridData = new GridData ();
+ gridData.widthHint = 300;
+ gridData.heightHint = 400;
+ textWidget.setLayoutData (gridData);
+ }
+
+ /**
+ * Handle a dialog type combo selection event.
+ *
+ * @param event the selection event
+ */
+ void dialogSelected (SelectionEvent event) {
+
+ /* Enable/Disable the buttons */
+ String name = dialogCombo.getText ();
+ boolean isMessageBox = name.equals (ControlPlugin.getResourceString("MessageBox"));
+ boolean isFileDialog = name.equals (ControlPlugin.getResourceString("FileDialog"));
+ okButton.setEnabled (isMessageBox);
+ cancelButton.setEnabled (isMessageBox);
+ yesButton.setEnabled (isMessageBox);
+ noButton.setEnabled (isMessageBox);
+ retryButton.setEnabled (isMessageBox);
+ abortButton.setEnabled (isMessageBox);
+ ignoreButton.setEnabled (isMessageBox);
+ iconErrorButton.setEnabled (isMessageBox);
+ iconInformationButton.setEnabled (isMessageBox);
+ iconQuestionButton.setEnabled (isMessageBox);
+ iconWarningButton.setEnabled (isMessageBox);
+ iconWorkingButton.setEnabled (isMessageBox);
+ saveButton.setEnabled (isFileDialog);
+ openButton.setEnabled (isFileDialog);
+
+ /* Unselect the buttons */
+ if (!isMessageBox) {
+ okButton.setSelection (false);
+ cancelButton.setSelection (false);
+ yesButton.setSelection (false);
+ noButton.setSelection (false);
+ retryButton.setSelection (false);
+ abortButton.setSelection (false);
+ ignoreButton.setSelection (false);
+ }
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [0];
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("Dialog");
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/LabelTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/LabelTab.java
new file mode 100755
index 0000000000..3df4a386dd
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/LabelTab.java
@@ -0,0 +1,158 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class LabelTab extends AlignableTab {
+ /* Example widgets and groups that contain them */
+ Label label1, label2, label3, label4, label5, label6;
+ Group textLabelGroup, imageLabelGroup;
+
+ /* Style widgets added to the "Style" group */
+ Button separatorButton, horizontalButton, verticalButton, shadowInButton, shadowOutButton;
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup () {
+ super.createExampleGroup ();
+
+ /* Create a group for the text labels */
+ textLabelGroup = new Group(exampleGroup, SWT.NULL);
+ GridLayout gridLayout = new GridLayout ();
+ textLabelGroup.setLayout (gridLayout);
+ gridLayout.numColumns = 3;
+ textLabelGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ textLabelGroup.setText (ControlPlugin.getResourceString("Text_Labels"));
+
+ /* Create a group for the image labels */
+ imageLabelGroup = new Group (exampleGroup, SWT.SHADOW_NONE);
+ gridLayout = new GridLayout ();
+ imageLabelGroup.setLayout (gridLayout);
+ gridLayout.numColumns = 3;
+ imageLabelGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ imageLabelGroup.setText (ControlPlugin.getResourceString("Image_Labels"));
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+
+ /* Compute the widget style */
+ int style = SWT.NONE;
+ if (separatorButton.getSelection ()) style |= SWT.SEPARATOR;
+ if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
+ if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
+ if (shadowInButton.getSelection ()) style |= SWT.SHADOW_IN;
+ if (shadowOutButton.getSelection ()) style |= SWT.SHADOW_OUT;
+ if (borderButton.getSelection ()) style |= SWT.BORDER;
+
+ /* Create the example widgets */
+ label1 = new Label (textLabelGroup, style);
+ label1.setText(ControlPlugin.getResourceString("One"));
+ label2 = new Label (textLabelGroup, style);
+ label2.setText(ControlPlugin.getResourceString("Two"));
+ label3 = new Label (textLabelGroup, style);
+ label3.setText (ControlPlugin.getResourceString("Three"));
+ label4 = new Label (imageLabelGroup, style);
+ label4.setImage (ControlPlugin.images[ControlPlugin.ciClosedFolder]);
+ label5 = new Label (imageLabelGroup, style);
+ label5.setImage (ControlPlugin.images[ControlPlugin.ciOpenFolder]);
+ label6 = new Label(imageLabelGroup, style);
+ label6.setImage (ControlPlugin.images[ControlPlugin.ciTarget]);
+ }
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup() {
+ super.createStyleGroup ();
+
+ /* Create the extra widgets */
+ separatorButton = new Button (styleGroup, SWT.CHECK);
+ separatorButton.setText (ControlPlugin.getResourceString("SWT_SEPARATOR"));
+ horizontalButton = new Button (styleGroup, SWT.RADIO);
+ horizontalButton.setText (ControlPlugin.getResourceString("SWT_HORIZONTAL"));
+ verticalButton = new Button (styleGroup, SWT.RADIO);
+ verticalButton.setText (ControlPlugin.getResourceString("SWT_VERTICAL"));
+ Group styleSubGroup = new Group (styleGroup, SWT.NULL);
+ styleSubGroup.setLayout (new GridLayout ());
+ shadowInButton = new Button (styleSubGroup, SWT.RADIO);
+ shadowInButton.setText (ControlPlugin.getResourceString("SWT_SHADOW_IN"));
+ shadowOutButton = new Button (styleSubGroup, SWT.RADIO);
+ shadowOutButton.setText (ControlPlugin.getResourceString("SWT_SHADOW_OUT"));
+ borderButton = new Button(styleGroup, SWT.CHECK);
+ borderButton.setText(ControlPlugin.getResourceString("SWT_BORDER"));
+
+ /* Add the listeners */
+ SelectionListener selectionListener = new SelectionAdapter () {
+ public void widgetSelected(SelectionEvent event) {
+ if ((event.widget.getStyle() & SWT.RADIO) != 0) {
+ if (!((Button) event.widget).getSelection ()) return;
+ }
+ recreateExampleWidgets ();
+ };
+ };
+ shadowInButton.addSelectionListener (selectionListener);
+ shadowOutButton.addSelectionListener (selectionListener);
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [] {label1, label2, label3, label4, label5, label6};
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("Label");
+ }
+
+ /**
+ * Sets the alignment of the "Example" widgets.
+ */
+ void setExampleWidgetAlignment () {
+ int allignment = 0;
+ if (leftButton.getSelection ()) allignment = SWT.LEFT;
+ if (centerButton.getSelection ()) allignment = SWT.CENTER;
+ if (rightButton.getSelection ()) allignment = SWT.RIGHT;
+ label1.setAlignment (allignment);
+ label2.setAlignment (allignment);
+ label3.setAlignment (allignment);
+ label4.setAlignment (allignment);
+ label5.setAlignment (allignment);
+ label6.setAlignment (allignment);
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ boolean isSeparator = (label1.getStyle () & SWT.SEPARATOR) != 0;
+ leftButton.setSelection (!isSeparator && (label1.getStyle () & SWT.LEFT) != 0);
+ centerButton.setSelection (!isSeparator && (label1.getStyle () & SWT.CENTER) != 0);
+ rightButton.setSelection (!isSeparator && (label1.getStyle () & SWT.RIGHT) != 0);
+ shadowInButton.setSelection (isSeparator && (label1.getStyle () & SWT.SHADOW_IN) != 0);
+ shadowOutButton.setSelection (isSeparator && (label1.getStyle () & SWT.SHADOW_OUT) != 0);
+ leftButton.setEnabled (!isSeparator);
+ centerButton.setEnabled (!isSeparator);
+ rightButton.setEnabled (!isSeparator);
+ shadowInButton.setEnabled (isSeparator);
+ shadowOutButton.setEnabled (isSeparator);
+ horizontalButton.setEnabled (isSeparator);
+ verticalButton.setEnabled (isSeparator);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ListTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ListTab.java
new file mode 100755
index 0000000000..d55f05b839
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ListTab.java
@@ -0,0 +1,74 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class ListTab extends ScrollableTab {
+
+ /* Example widgets and groups that contain them */
+ List list1;
+ Group listGroup;
+
+ static String [] ListData1 = {ControlPlugin.getResourceString("ListData1_0"),
+ ControlPlugin.getResourceString("ListData1_1"),
+ ControlPlugin.getResourceString("ListData1_2"),
+ ControlPlugin.getResourceString("ListData1_3"),
+ ControlPlugin.getResourceString("ListData1_4"),
+ ControlPlugin.getResourceString("ListData1_5"),
+ ControlPlugin.getResourceString("ListData1_6"),
+ ControlPlugin.getResourceString("ListData1_7"),
+ ControlPlugin.getResourceString("ListData1_8")};
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup () {
+ super.createExampleGroup ();
+
+ /* Create a group for the list */
+ listGroup = new Group (exampleGroup, SWT.NULL);
+ listGroup.setLayout (new GridLayout ());
+ listGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ listGroup.setText (ControlPlugin.getResourceString("List"));
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+
+ /* Compute the widget style */
+ int style = SWT.NONE;
+ if (singleButton.getSelection ()) style |= SWT.SINGLE;
+ if (multiButton.getSelection ()) style |= SWT.MULTI;
+ if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
+ if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
+ if (borderButton.getSelection ()) style |= SWT.BORDER;
+
+ /* Create the example widgets */
+ list1 = new List (listGroup, style);
+ list1.setItems (ListData1);
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [] {list1};
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("List");
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ProgressBarTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ProgressBarTab.java
new file mode 100755
index 0000000000..6c98778d26
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ProgressBarTab.java
@@ -0,0 +1,107 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class ProgressBarTab extends RangeTab {
+ /* Example widgets and groups that contain them */
+ ProgressBar progressBar1;
+ Group progressBarGroup;
+
+ /* Style widgets added to the "Style" group */
+ Button smoothButton;
+
+ /**
+ * Creates the "Example" group.
+ */
+ void createExampleGroup() {
+ super.createExampleGroup ();
+
+ /* Create a group for the progress bar */
+ progressBarGroup = new Group (exampleGroup, SWT.NULL);
+ progressBarGroup.setLayout (new GridLayout ());
+ progressBarGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ progressBarGroup.setText (ControlPlugin.getResourceString("ProgressBar"));
+ }
+
+ /**
+ * Creates the "Example" widgets.
+ */
+ void createExampleWidgets () {
+
+ /* Compute the widget style */
+ int style = SWT.NONE;
+ if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
+ if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
+ if (smoothButton.getSelection ()) style |= SWT.SMOOTH;
+ if (borderButton.getSelection ()) style |= SWT.BORDER;
+
+ /* Create the example widgets */
+ progressBar1 = new ProgressBar (progressBarGroup, style);
+ progressBar1.setMaximum (100);
+ progressBar1.setSelection (50);
+ }
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup () {
+ super.createStyleGroup ();
+
+ /* Create the extra widgets */
+ smoothButton = new Button (styleGroup, SWT.CHECK);
+ smoothButton.setText (ControlPlugin.getResourceString("SWT_SMOOTH"));
+ }
+
+ /**
+ * Gets the "Example" widget children.
+ */
+ Control [] getExampleWidgets () {
+ return new Control [] {progressBar1};
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("ProgressBar");
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ maximumScale.setMaximum (progressBar1.getMaximum ());
+ smoothButton.setSelection ((progressBar1.getStyle () & SWT.SMOOTH) != 0);
+ }
+
+ /**
+ * Sets the maximum of the "Example" widgets.
+ */
+ void setWidgetMaximum () {
+ progressBar1.setMaximum (maximumScale.getSelection ());
+ }
+
+ /**
+ * Sets the minimim of the "Example" widgets.
+ */
+ void setWidgetMinimum () {
+ progressBar1.setMinimum (minimumScale.getSelection ());
+ }
+
+ /**
+ * Sets the selection of the "Example" widgets.
+ */
+ void setWidgetSelection () {
+ progressBar1.setSelection (selectionScale.getSelection ());
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/RangeTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/RangeTab.java
new file mode 100755
index 0000000000..3e39268a0b
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/RangeTab.java
@@ -0,0 +1,161 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+abstract class RangeTab extends Tab {
+ /* Style widgets added to the "Style" group */
+ Button horizontalButton, verticalButton;
+
+ /* Scale widgets added to the "Control" group */
+ Scale minimumScale, selectionScale, maximumScale;
+
+ /**
+ * Creates the "Control" widget children.
+ */
+ void createControlWidgets () {
+
+ /* Leave an empty cell */
+ new Composite (controlGroup, SWT.NULL);
+
+ /* Create controls specific to this example */
+ createMinimumGroup ();
+ createMaximumGroup ();
+ createSelectionGroup ();
+ }
+
+ /**
+ * Create a group of widgets to control the maximum
+ * attribute of the example widget.
+ */
+ void createMaximumGroup() {
+
+ /* Create the group */
+ Group maximumGroup = new Group (controlGroup, SWT.NULL);
+ maximumGroup.setLayout (new GridLayout ());
+ maximumGroup.setText (ControlPlugin.getResourceString("Maximum"));
+
+ /* Create a scale widget */
+ maximumScale = new Scale (maximumGroup, SWT.NULL);
+ maximumScale.setMaximum (100);
+ maximumScale.setSelection (100);
+ maximumScale.setPageIncrement (10);
+ maximumScale.setIncrement (5);
+
+ /* Add the listeners */
+ maximumScale.addSelectionListener(new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ setWidgetMaximum ();
+ };
+ });
+ }
+
+ /**
+ * Create a group of widgets to control the minimum
+ * attribute of the example widget.
+ */
+ void createMinimumGroup() {
+
+ /* Create the group */
+ Group minimumGroup = new Group (controlGroup, SWT.NULL);
+ minimumGroup.setLayout (new GridLayout ());
+ minimumGroup.setText (ControlPlugin.getResourceString("Minimum"));
+
+ /* Create a scale widget */
+ minimumScale = new Scale (minimumGroup, SWT.NULL);
+ minimumScale.setMaximum (100);
+ minimumScale.setPageIncrement (10);
+ minimumScale.setIncrement (5);
+
+ /* Add the listeners */
+ minimumScale.addSelectionListener (new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ setWidgetMinimum ();
+ };
+ });
+
+ }
+
+ /**
+ * Create a group of widgets to control the selection
+ * attribute of the example widget.
+ */
+ void createSelectionGroup() {
+
+ /* Create the group */
+ Group selectionGroup = new Group(controlGroup, SWT.NULL);
+ selectionGroup.setLayout(new GridLayout());
+ GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
+ gridData.horizontalSpan = 2;
+ selectionGroup.setLayoutData(gridData);
+ selectionGroup.setText(ControlPlugin.getResourceString("Selection"));
+
+ /* Create a scale widget */
+ selectionScale = new Scale (selectionGroup, SWT.NULL);
+ selectionScale.setMaximum (100);
+ selectionScale.setSelection (50);
+ selectionScale.setPageIncrement (10);
+ selectionScale.setIncrement (5);
+
+ /* Add the listeners */
+ selectionScale.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setWidgetSelection ();
+ };
+ });
+
+ }
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup () {
+ super.createStyleGroup ();
+
+ /* Create the extra widgets */
+ horizontalButton = new Button (styleGroup, SWT.RADIO);
+ horizontalButton.setText (ControlPlugin.getResourceString("SWT_HORIZONTAL"));
+ verticalButton = new Button (styleGroup, SWT.RADIO);
+ verticalButton.setText (ControlPlugin.getResourceString("SWT_VERTICAL"));
+ borderButton = new Button (styleGroup, SWT.CHECK);
+ borderButton.setText (ControlPlugin.getResourceString("SWT_BORDER"));
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ setWidgetMinimum ();
+ setWidgetMaximum ();
+ setWidgetSelection ();
+ Control [] controls = getExampleWidgets ();
+ if (controls.length != 0){
+ horizontalButton.setSelection ((controls [0].getStyle () & SWT.HORIZONTAL) != 0);
+ verticalButton.setSelection ((controls [0].getStyle () & SWT.VERTICAL) != 0);
+ borderButton.setSelection ((controls [0].getStyle () & SWT.BORDER) != 0);
+ }
+ }
+
+ /**
+ * Sets the maximum of the "Example" widgets.
+ */
+ abstract void setWidgetMaximum ();
+
+ /**
+ * Sets the minimim of the "Example" widgets.
+ */
+ abstract void setWidgetMinimum ();
+
+ /**
+ * Sets the selection of the "Example" widgets.
+ */
+ abstract void setWidgetSelection ();
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/SashTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/SashTab.java
new file mode 100755
index 0000000000..013cf3487f
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/SashTab.java
@@ -0,0 +1,158 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class SashTab extends Tab {
+ /* Example widgets and groups that contain them */
+ Sash hSash, vSash;
+ List list1, list2, list3;
+ Text text;
+
+ static String [] ListData0 = {ControlPlugin.getResourceString("ListData0_0"),
+ ControlPlugin.getResourceString("ListData0_1"),
+ ControlPlugin.getResourceString("ListData0_2"),
+ ControlPlugin.getResourceString("ListData0_3"),
+ ControlPlugin.getResourceString("ListData0_4"),
+ ControlPlugin.getResourceString("ListData0_5"),
+ ControlPlugin.getResourceString("ListData0_6"),
+ ControlPlugin.getResourceString("ListData0_7"),
+ ControlPlugin.getResourceString("ListData0_8")};
+
+ static String [] ListData1 = {ControlPlugin.getResourceString("ListData1_0"),
+ ControlPlugin.getResourceString("ListData1_1"),
+ ControlPlugin.getResourceString("ListData1_2"),
+ ControlPlugin.getResourceString("ListData1_3"),
+ ControlPlugin.getResourceString("ListData1_4"),
+ ControlPlugin.getResourceString("ListData1_5"),
+ ControlPlugin.getResourceString("ListData1_6"),
+ ControlPlugin.getResourceString("ListData1_7"),
+ ControlPlugin.getResourceString("ListData1_8")};
+
+ /* Constants */
+ static final int SASH_WIDTH = 3;
+
+ /**
+ * Creates the tab folder page.
+ */
+ Composite createTabFolderPage (TabFolder tabFolder) {
+ /*
+ * Create the page. This example does not use layouts.
+ */
+ tabFolderPage = new Composite(tabFolder, SWT.BORDER);
+
+ /* Create the list and text widgets */
+ list1 = new List (tabFolderPage, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+ list1.setItems (ListData0);
+ list2 = new List (tabFolderPage, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+ list2.setItems (ListData1);
+ text = new Text (tabFolderPage, SWT.MULTI | SWT.BORDER);
+ text.setText (ControlPlugin.getResourceString("Multi_line"));
+
+ /* Create the sashes */
+ vSash = new Sash (tabFolderPage, SWT.VERTICAL);
+ hSash = new Sash (tabFolderPage, SWT.HORIZONTAL);
+
+ /* Add the listeners */
+ hSash.addSelectionListener (new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ if (event.detail != SWT.DRAG) {
+ hSash.setBounds (event.x, event.y, event.width, event.height);
+ layout ();
+ }
+ }
+ });
+ vSash.addSelectionListener (new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ if (event.detail != SWT.DRAG) {
+ vSash.setBounds(event.x, event.y, event.width, event.height);
+ layout ();
+ }
+ }
+ });
+ tabFolderPage.addControlListener (new ControlAdapter () {
+ public void controlResized (ControlEvent event) {
+ shellResized ();
+ }
+ });
+
+ /*
+ * Do not set the bounds of the lists, text and sashes here
+ * because this method is run before the widget is opened
+ * so we do not know how big the tabComposite is going to be.
+ * When the widget is opened a resize event will occur
+ * and the contained widgets can be sized accordingly.
+ */
+ return tabFolderPage;
+ }
+
+ /**
+ * Gets the text for the tab folder item.
+ */
+ String getTabText () {
+ return ControlPlugin.getResourceString("Sash");
+ }
+
+ /**
+ * Layout the list and text widgets according to the new
+ * positions of the sashes..events.SelectionEvent
+ */
+ void layout () {
+
+ Rectangle tabCompositeBounds = tabFolderPage.getClientArea ();
+ Rectangle hSashBounds = hSash.getBounds ();
+ Rectangle vSashBounds = vSash.getBounds ();
+
+ list1.setBounds (0, 0, vSashBounds.x, hSashBounds.y);
+ list2.setBounds (vSashBounds.x + vSashBounds.width, 0, tabCompositeBounds.width - (vSashBounds.x + vSashBounds.width), hSashBounds.y);
+ text.setBounds (0, hSashBounds.y + hSashBounds.height, tabCompositeBounds.width, tabCompositeBounds.height - (hSashBounds.y + hSashBounds.height));
+
+ /**
+ * If the horizontal sash has been moved then the vertical
+ * sash is either too long or too short and its size must
+ * be adjusted.
+ */
+ vSashBounds.height = hSashBounds.y;
+ vSash.setBounds (vSashBounds);
+ }
+
+ /**
+ * Handle the shell resized event.
+ */
+ void shellResized () {
+
+ /* Get the client area for the shell */
+ Rectangle tabFolderPageBounds = tabFolderPage.getClientArea ();
+
+ /*
+ * Make list 1 half the width and half the height of the tab leaving room for the sash.
+ * Place list 1 in the top left quadrant of the tab.
+ */
+ Rectangle list1Bounds = new Rectangle (0, 0, (tabFolderPageBounds.width - SASH_WIDTH) / 2, (tabFolderPageBounds.height - SASH_WIDTH) / 2);
+ list1.setBounds (list1Bounds);
+
+ /*
+ * Make list 2 half the width and half the height of the tab leaving room for the sash.
+ * Place list 2 in the top right quadrant of the tab.
+ */
+ list2.setBounds (list1Bounds.width + SASH_WIDTH, 0, tabFolderPageBounds.width - (list1Bounds.width + SASH_WIDTH), list1Bounds.height);
+
+ /*
+ * Make the text area the full width and half the height of the tab leaving room for the sash.
+ * Place the text area in the bottom half of the tab.
+ */
+ text.setBounds (0, list1Bounds.height + SASH_WIDTH, tabFolderPageBounds.width, tabFolderPageBounds.height - (list1Bounds.height + SASH_WIDTH));
+
+ /* Position the sashes */
+ vSash.setBounds (list1Bounds.width, 0, SASH_WIDTH, list1Bounds.height);
+ hSash.setBounds (0, list1Bounds.height, tabFolderPageBounds.width, SASH_WIDTH);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ScrollableTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ScrollableTab.java
new file mode 100755
index 0000000000..8695173478
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ScrollableTab.java
@@ -0,0 +1,48 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+
+abstract class ScrollableTab extends Tab {
+ /* Style widgets added to the "Style" group */
+ Button singleButton, multiButton, horizontalButton, verticalButton, borderButton;
+
+ /**
+ * Creates the "Style" group.
+ */
+ void createStyleGroup () {
+ super.createStyleGroup ();
+
+ /* Create the extra widgets */
+ singleButton = new Button (styleGroup, SWT.RADIO);
+ singleButton.setText (ControlPlugin.getResourceString("SWT_SINGLE"));
+ multiButton = new Button (styleGroup, SWT.RADIO);
+ multiButton.setText (ControlPlugin.getResourceString("SWT_MULTI"));
+ horizontalButton = new Button (styleGroup, SWT.CHECK);
+ horizontalButton.setText (ControlPlugin.getResourceString("SWT_H_SCROLL"));
+ verticalButton = new Button (styleGroup, SWT.CHECK);
+ verticalButton.setText (ControlPlugin.getResourceString("SWT_V_SCROLL"));
+ borderButton = new Button (styleGroup, SWT.CHECK);
+ borderButton.setText (ControlPlugin.getResourceString("SWT_BORDER"));
+ }
+
+ /**
+ * Sets the state of the "Example" widgets.
+ */
+ void setExampleWidgetState () {
+ super.setExampleWidgetState ();
+ Control [] controls = getExampleWidgets ();
+ if (controls.length != 0){
+ singleButton.setSelection ((controls [0].getStyle () & SWT.SINGLE) != 0);
+ multiButton.setSelection ((controls [0].getStyle () & SWT.MULTI) != 0);
+ horizontalButton.setSelection ((controls [0].getStyle () & SWT.H_SCROLL) != 0);
+ verticalButton.setSelection ((controls [0].getStyle () & SWT.V_SCROLL) != 0);
+ borderButton.setSelection ((controls [0].getStyle () & SWT.BORDER) != 0);
+ }
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ShellTab.java b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ShellTab.java
new file mode 100755
index 0000000000..1eede5da1f
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.controls/src/org/eclipse/swt/examples/controls/ShellTab.java
@@ -0,0 +1,217 @@
+package org.eclipse.swt.examples.controls;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.events.*;
+
+class ShellTab extends Tab {
+ /* Style widgets added to the "Style" group */
+ Button noParentButton, parentButton;
+ Button noTrimButton, closeButton, titleButton, minButton, maxButton, borderButton, resizeButton;
+ Button createButton, closeAllButton;
+ Group parentStyleGroup;
+
+ /* Variables used to track the open shells */
+ int shellCount = 0;
+ Shell [] shells = new Shell [4];
+
+ /**
+ * Close all the example shells.
+ */
+ void closeAllShells() {
+ for (int i = 0; iTab
is the abstract superclass of every page
+ * in the example's tab folder. Each page in the tab folder
+ * describes a control.
+ *
+ * A Tab itself is not a control but instead provides a
+ * hierarchy with which to share code that is common to
+ * every page in the folder.
+ *
+ * A typical page in a Tab contains a two column composite.
+ * The left column contains the "Example" group. The right
+ * 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", "Display" and "Size" group. Subclasses
+ * can override these defaults to augment a group or stop
+ * a group from being created.
+ */
+abstract class Tab {
+ /* Common control buttons */
+ Button borderButton, enabledButton, visibleButton;
+ Button preferredButton, tooSmallButton, smallButton, largeButton;
+
+ /* Common groups and composites */
+ Composite tabFolderPage;
+ Group exampleGroup, controlGroup, displayGroup, sizeGroup, styleGroup;
+
+ /* Sizing constants for the "Size" group */
+ static final int TOO_SMALL_SIZE = 10;
+ static final int SMALL_SIZE = 50;
+ static final int LARGE_SIZE = 100;
+
+ /**
+ * Creates the "Control" group. The "Control" group
+ * is typically the right hand column in the tab.
+ */
+ void createControlGroup () {
+
+ /*
+ * Create the "Control" group. This is the group on the
+ * left half of each example tab. It consists of the
+ * style group, the display group and the size group.
+ */
+ controlGroup = new Group (tabFolderPage, SWT.NONE);
+ GridLayout gridLayout= new GridLayout ();
+ controlGroup.setLayout (gridLayout);
+ gridLayout.numColumns = 2;
+ gridLayout.makeColumnsEqualWidth = true;
+ controlGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
+ controlGroup.setText (ControlPlugin.getResourceString("Parameters"));
+
+ /* Create individual groups inside the "Control" group */
+ createStyleGroup ();
+ createDisplayGroup ();
+ createSizeGroup ();
+
+ /*
+ * For each Button child in the style group, add a selection
+ * listener that will recreate the example controls. If the
+ * style group button is a RADIO button, ensure that the radio
+ * button is selected before recreating the example controls.
+ * When the user selects a RADIO button, the curreont RADIO
+ * button in the group is deselected and the new RADIO button
+ * is selected automatically. The listeners are notified for
+ * both these operations but typically only do work when a RADIO
+ * button is selected.
+ */
+ SelectionListener selectionListener = new SelectionAdapter () {
+ public void widgetSelected (SelectionEvent event) {
+ if ((event.widget.getStyle () & SWT.RADIO) != 0) {
+ if (!((Button) event.widget).getSelection ()) return;
+ }
+ recreateExampleWidgets ();
+ };
+ };
+ Control [] children = styleGroup.getChildren ();
+ for (int i=0; i <!ELEMENT extension (EMPTY)>
+
<!ATTLIST extension
+
point CDATA #REQUIRED
+
id CDATA #IMPLIED
+
name CDATA #IMPLIED
+
>
+
<!ELEMENT programItem (EMPTY)>
+
<!ATTLIST programItem
+
name CDATA #REQUIRED
+
id CDATA #IMPLIED
+
mainClass CDATA #REQUIRED
+
pluginId CDATA #REQUIRED
+
category CDATA #IMPLIED
+
source CDATA #IMPLIED
+
>
+
<!ELEMENT viewItem (EMPTY)>
+
<!ATTLIST viewItem
+
name CDATA #REQUIRED
+
id CDATA #IMPLIED
+
viewId CDATA #REQUIRED
+
category CDATA #IMPLIED
+
source CDATA #IMPLIED
+
>
+
<!ELEMENT category (EMPTY)>
+
<!ATTLIST category
+
name CDATA #REQUIRED
+
id CDATA #REQUIRED
+
category CDATA #IMPLIED
+
>
+
+ * This method is called when the delegating action has been triggered. + * Implement this method to do the actual work. + *
+ * + * @param action the action proxy that handles the presentation portion of the + * action + */ + public void run(IAction action) { + final Display display = paintView.getDisplay(); + action.setId(id); // temporary workaround since ID field not set by default + display.syncExec(new ActionRunnable(action)); + } + private class ActionRunnable implements Runnable { + IAction action; + public ActionRunnable(IAction action) { + this.action = action; + } + public void run() { + paintView.setPaintToolByAction(action); + } + } + + + /** + * Notifies this action delegate that the selection in the workbench has changed. + *+ * Implementers can use this opportunity to change the availability of the + * action or to modify other presentation properties. + *
+ * + * @param action the action proxy that handles presentation portion of the action + * @param selection the current selection in the workbench + */ + public void selectionChanged(IAction action, ISelection selection) { + // We don't care about the selection for now + } + + /** + * Implementation ofIExecutableExtension
allows us to get access to the
+ * configuration data (i.e. plugin.xml attributes) that were specified in order to create
+ * the IAction we received
+ */
+ public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) {
+ // Get the identifier
+ id = cfig.getAttribute("id");
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedInteractivePaintSession.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedInteractivePaintSession.java
new file mode 100755
index 0000000000..bc58be27bd
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedInteractivePaintSession.java
@@ -0,0 +1,192 @@
+package org.eclipse.swt.examples.paint;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
+
+/**
+ * The superclass for paint tools that contruct objects from individually
+ * picked segments
+ */
+public abstract class SegmentedInteractivePaintSession extends BasicPaintSession
+ implements PaintRenderer {
+ /**
+ * The position of the first click in a segmented selection
+ */
+ private Point anchorPosition = new Point(-1, -1);
+
+ /**
+ * The position of the last drawn temporary point in a segmented selection
+ */
+ private Point tempPosition = new Point(-1, -1);
+
+ /**
+ * The position of the first anchor in a segmented selection sequence
+ */
+ protected Point firstAnchorPosition = new Point(-1, 0);
+
+ /**
+ * Create an SegmentedInteractivePaintSession
+ *
+ * @param paintSurface the drawing surface to use
+ */
+ protected SegmentedInteractivePaintSession(PaintSurface paintSurface) {
+ super(paintSurface);
+ }
+
+ /**
+ * Activate the tool.
+ */
+ public void beginSession() {
+ getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ "session.SegmentedInteractivePaint.message.anchorMode"));
+
+ anchorPosition.x = -1;
+ tempPosition.x = -1;
+ firstAnchorPosition.x = -1;
+ }
+
+ /**
+ * Deactivate the tool.
+ */
+ public void endSession() {
+ }
+
+ /**
+ * Reset the tool.
+ * Aborts any operation in progress.
+ */
+ public void resetSession() {
+ getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ "session.SegmentedInteractivePaint.message.anchorMode"));
+
+ if (anchorPosition.x == -1) return; // spurious event
+
+ if (tempPosition.x != -1) { // restore old image
+ final GC gc = getPaintSurface().getGC();
+ eraseTemporary(gc, anchorPosition, tempPosition);
+ }
+ anchorPosition.x = -1;
+ tempPosition.x = -1;
+ firstAnchorPosition.x = -1;
+ }
+
+ /**
+ * Handle a mouseDown event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseDown(MouseEvent event) {
+ if (event.button != 1) return;
+
+ if (tempPosition.x != -1) { // restore old image
+ final GC gc = getPaintSurface().getGC();
+ Assert.assert(anchorPosition.x != -1);
+ eraseTemporary(gc, anchorPosition, tempPosition);
+ tempPosition.x = event.x;
+ tempPosition.y = event.y;
+ drawPermanent(gc, anchorPosition, tempPosition);
+ tempPosition.x = -1;
+ }
+ anchorPosition.x = event.x;
+ anchorPosition.y = event.y;
+ if (firstAnchorPosition.x == -1) {
+ firstAnchorPosition.x = anchorPosition.x;
+ firstAnchorPosition.y = anchorPosition.y;
+ }
+ getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ "session.SegmentedInteractivePaint.message.interactiveMode"));
+ }
+
+ /**
+ * Handle a mouseDoubleClick event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseDoubleClick(MouseEvent event) {
+ if (event.button != 1) return;
+ if (firstAnchorPosition.x == -1) return; // spurious event
+ Assert.assert(anchorPosition.x != -1);
+
+ final GC gc = getPaintSurface().getGC();
+ if (tempPosition.x != -1) { // restore old image
+ eraseTemporary(gc, anchorPosition, tempPosition);
+ tempPosition.x = -1;
+ }
+ drawPermanent(gc, anchorPosition, firstAnchorPosition);
+ anchorPosition.x = -1;
+ firstAnchorPosition.x = -1;
+
+ getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ "session.SegmentedInteractivePaint.message.anchorMode"));
+ }
+
+ /**
+ * Handle a mouseUp event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseUp(MouseEvent event) {
+ if (event.button != 1) {
+ resetSession(); // abort if right or middle mouse button pressed
+ return;
+ }
+ }
+
+ /**
+ * Handle a mouseMove event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseMove(MouseEvent event) {
+ if (anchorPosition.x == -1) {
+ getPaintSurface().showCurrentPositionStatus();
+ return; // spurious event
+ } else {
+ getPaintSurface().showCurrentRangeStatus(anchorPosition);
+ }
+
+ final GC gc = getPaintSurface().getGC();
+ if (tempPosition.x != -1) { // restore old image
+ eraseTemporary(gc, anchorPosition, tempPosition);
+ }
+ // draw temporary entity
+ tempPosition.x = event.x;
+ tempPosition.y = event.y;
+ drawTemporary(gc, anchorPosition, tempPosition);
+ }
+
+ /**
+ * Draw a permanent entity given 2...n points
+ *
+ * @param points[0] and points[1] are two points
+ * @param numPoints the number of valid points in the array (n >= 2)
+ */
+ public void render(final Point[] points, int numPoints) {
+ Assert.assert(numPoints >= 2);
+
+ final GC gc = getPaintSurface().getGC();
+ for (int i = 1; i < numPoints; ++i) {
+ drawPermanent(gc, points[i - 1], points[i]);
+ }
+ drawPermanent(gc, points[numPoints - 1], points[0]);
+ }
+
+ /**
+ * Draw a permanent segment
+ */
+ protected abstract void drawPermanent(GC gc, Point a, Point b);
+
+ /**
+ * Draw a temporary segment
+ */
+ protected abstract void drawTemporary(GC gc, Point a, Point b);
+
+ /**
+ * Erase a temporary segment
+ */
+ protected abstract void eraseTemporary(GC gc, Point a, Point b);
+}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SimplePaintSession.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SimplePaintSession.java
new file mode 100755
index 0000000000..eec18edf04
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SimplePaintSession.java
@@ -0,0 +1,87 @@
+package org.eclipse.swt.examples.paint;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * The superclass for single-click paint tools
+ */
+public abstract class SimplePaintSession extends BasicPaintSession implements PaintRenderer {
+ /**
+ * A cached Point array
+ */
+ protected Point[] cachedPointArray = new Point[] { new Point(-1, -1) };
+
+ /**
+ * Create a SimplePaintSession
+ *
+ * @param paintSurface the drawing surface to use
+ */
+ protected SimplePaintSession(PaintSurface paintSurface) {
+ super(paintSurface);
+ }
+
+ /**
+ * Activate the tool
+ */
+ public void beginSession() {
+ getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ "session.SimplePaint.message"));
+ }
+
+ /**
+ * Deactivate the tool
+ */
+ public void endSession() {
+ }
+
+ /**
+ * Abort the current operation
+ */
+ public void resetSession() {
+ }
+
+ /**
+ * Handle a mouseDown event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseDown(MouseEvent event) {
+ if (event.button != 1) return; // catch only left mouse actions
+
+ cachedPointArray[0].x = event.x;
+ cachedPointArray[0].y = event.y;
+ render(cachedPointArray, 1);
+ }
+
+ /**
+ * Handle a mouseDoubleClick event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseDoubleClick(MouseEvent event) {
+ mouseDown(event);
+ }
+
+ /**
+ * Handle a mouseUp event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseUp(MouseEvent event) {
+ }
+
+ /**
+ * Handle a mouseMove event
+ *
+ * @param event the mouse event detail information
+ */
+ public void mouseMove(MouseEvent event) {
+ getPaintSurface().showCurrentPositionStatus();
+ }
+}
--
cgit v1.2.3