diff options
author | Grant Gayed | 2003-03-03 16:43:28 +0000 |
---|---|---|
committer | Grant Gayed | 2003-03-03 16:43:28 +0000 |
commit | 59534c7cbb22f23d1d3e8f358ce58641fe41a8aa (patch) | |
tree | bab59a8ea5c9cb416dbb908c5fca692acd868b6b | |
parent | 84255bf5f83ec4c813df37e8e145b1c015d891af (diff) | |
download | eclipse.platform.swt-59534c7cbb22f23d1d3e8f358ce58641fe41a8aa.tar.gz eclipse.platform.swt-59534c7cbb22f23d1d3e8f358ce58641fe41a8aa.tar.xz eclipse.platform.swt-59534c7cbb22f23d1d3e8f358ce58641fe41a8aa.zip |
*** empty log message ***
4 files changed, 161 insertions, 57 deletions
diff --git a/examples/org.eclipse.swt.examples/src/examples_control.properties b/examples/org.eclipse.swt.examples/src/examples_control.properties index d546ec4a1d..3e9607f068 100644 --- a/examples/org.eclipse.swt.examples/src/examples_control.properties +++ b/examples/org.eclipse.swt.examples/src/examples_control.properties @@ -1,5 +1,6 @@ error.CouldNotLoadResources = Unable to load resources window.title = SWT Controls +custom.window.title = SWT Custom Controls Text_Buttons = Text Buttons Size = Size 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 35355466ba..a4b66e308d 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 @@ -21,6 +21,7 @@ public class ControlExample { private ShellTab shellTab;
private TabFolder tabFolder;
private EventConsole eventConsole;
+ static boolean standAlone = false;
static final int
ciClosedFolder = 0,
@@ -41,41 +42,80 @@ public class ControlExample { public ControlExample(Composite parent) {
initResources();
tabFolder = new TabFolder (parent, SWT.NULL);
- Tab [] tabs = new Tab [] {
+ Tab [] tabs = createTabs();
+ for (int i=0; i<tabs.length; i++) {
+ TabItem item = new TabItem (tabFolder, SWT.NULL);
+ item.setText (tabs [i].getTabText ());
+ item.setControl (tabs [i].createTabFolderPage (tabFolder));
+ }
+ if (standAlone) {
+ createMenus (parent.getShell ());
+ }
+ }
+
+ /**
+ * Open the event logger.
+ */
+ private void closeEventConsole() {
+ if (eventConsole != null) {
+ eventConsole.close ();
+ eventConsole = null;
+ }
+ }
+
+ /**
+ * Create this example's menus.
+ */
+ void createMenus(final Shell shell) {
+ Menu bar = new Menu (shell, SWT.BAR);
+ MenuItem consoleItem = new MenuItem (bar, SWT.CASCADE);
+ consoleItem.setText ("Controls");
+ shell.setMenuBar (bar);
+ Menu dropDown = new Menu (bar);
+ consoleItem.setMenu (dropDown);
+
+ final MenuItem showEvents = new MenuItem (dropDown, SWT.CHECK);
+ showEvents.setAccelerator(SWT.MOD1 + 'C');
+ showEvents.setText ("&Show Events");
+ showEvents.addListener (SWT.Selection, new Listener () {
+ public void handleEvent (Event e) {
+ if (showEvents.getSelection()) {
+ openEventConsole (shell);
+ } else {
+ closeEventConsole ();
+ }
+ }
+ });
+
+ final MenuItem exit = new MenuItem (dropDown, SWT.NONE);
+ exit.setText ("E&xit");
+ exit.addListener (SWT.Selection, new Listener () {
+ public void handleEvent (Event e) {
+ shell.dispose();
+ }
+ });
+ }
+
+ /**
+ * Answers the set of example Tabs
+ */
+ Tab[] createTabs() {
+ return new Tab [] {
new ButtonTab (this),
new ComboTab (this),
- new CComboTab (this),
new CoolBarTab (this),
- new CTabFolderTab (this),
new DialogTab (this),
new LabelTab (this),
- new CLabelTab (this),
new ListTab (this),
new ProgressBarTab (this),
new SashTab (this),
- new SashFormTab (this),
shellTab = new ShellTab(this),
new SliderTab (this),
new TableTab (this),
- new TableTreeTab (this),
new TextTab (this),
new ToolBarTab (this),
new TreeTab (this),
};
- eventConsole = new EventConsole (parent.getShell());
- for (int i=0; i<tabs.length; i++) {
- TabItem item = new TabItem (tabFolder, SWT.NULL);
- item.setText (tabs [i].getTabText ());
- item.setControl (tabs [i].createTabFolderPage (tabFolder));
- }
- eventConsole.open ();
- }
-
- /**
- * Grabs input focus.
- */
- public void setFocus() {
- tabFolder.setFocus();
}
/**
@@ -98,21 +138,18 @@ public class ControlExample { }
/**
- * Invokes as a standalone program.
+ * Frees the resources
*/
- public static void main(String[] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- ControlExample instance = new ControlExample(shell);
- shell.setText(getResourceString("window.title"));
- shell.open();
- while (! shell.isDisposed()) {
- if (! display.readAndDispatch()) display.sleep();
+ void freeResources() {
+ if (images != null) {
+ for (int i = 0; i < images.length; ++i) {
+ final Image image = images[i];
+ if (image != null) image.dispose();
+ }
+ images = null;
}
- instance.dispose();
}
-
+
/**
* Gets a string from the resource bundle.
* We don't want to crash because of a missing String.
@@ -146,7 +183,7 @@ public class ControlExample { /**
* Loads the resources
*/
- private void initResources() {
+ void initResources() {
final Class clazz = ControlExample.class;
if (resourceBundle != null) {
try {
@@ -172,23 +209,44 @@ public class ControlExample { }
/**
- * Frees the resources
+ * Logs an event to the event console.
*/
- private void freeResources() {
- if (images != null) {
- for (int i = 0; i < images.length; ++i) {
- final Image image = images[i];
- if (image != null) image.dispose();
- }
- images = null;
+ void log(Event event) {
+ if (eventConsole != null) {
+ eventConsole.log(event);
}
}
-
+
/**
- * Logs an event to the event console.
+ * Invokes as a standalone program.
*/
- void log(Event event) {
- eventConsole.log(event);
+ public static void main(String[] args) {
+ standAlone = true;
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ ControlExample instance = new ControlExample(shell);
+ shell.setText(getResourceString("window.title"));
+ shell.open();
+ while (! shell.isDisposed()) {
+ if (! display.readAndDispatch()) display.sleep();
+ }
+ instance.dispose();
+ }
+
+ /**
+ * Open the event logger.
+ */
+ void openEventConsole(Shell shell) {
+ eventConsole = new EventConsole (shell);
+ eventConsole.open ();
+ }
+
+ /**
+ * Grabs input focus.
+ */
+ public void setFocus() {
+ tabFolder.setFocus();
}
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CustomControlExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CustomControlExample.java new file mode 100644 index 0000000000..71a526c48d --- /dev/null +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CustomControlExample.java @@ -0,0 +1,54 @@ +package org.eclipse.swt.examples.controlexample; + +import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.*; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * This file is 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 + */ + +public class CustomControlExample extends ControlExample { + + /** + * Creates an instance of a CustomControlExample embedded + * inside the supplied parent Composite. + * + * @param parent the container of the example + */ + public CustomControlExample(Composite parent) { + super (parent); + } + + /** + * Answers the set of example Tabs + */ + Tab[] createTabs() { + return new Tab [] { + new CComboTab (this), + new CTabFolderTab (this), + new CLabelTab (this), + new SashFormTab (this), + new TableTreeTab (this), + }; + } + + /** + * Invokes as a standalone program. + */ + public static void main(String[] args) { + standAlone = true; + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + CustomControlExample instance = new CustomControlExample(shell); + shell.setText(getResourceString("custom.window.title")); + shell.open(); + while (! shell.isDisposed()) { + if (! display.readAndDispatch()) display.sleep(); + } + instance.dispose(); + } +} diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/EventConsole.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/EventConsole.java index 414a2b63de..4898786864 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/EventConsole.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/EventConsole.java @@ -29,7 +29,7 @@ public class EventConsole { public EventConsole (Shell parent) { super (); shell = new Shell (parent, SWT.SHELL_TRIM); - shell.setText ("ControlExample Events"); + shell.setText ("Events"); shell.setLayout (new FillLayout ()); Point parentSize = parent.getSize(); shell.setBounds(10, parentSize.y - 100, parentSize.x / 2, 200); @@ -59,14 +59,6 @@ public class EventConsole { } }); - MenuItem close = new MenuItem (dropDown, SWT.NONE); - close.setText ("&Dismiss"); - close.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - shell.dispose (); - isActive = false; - } - }); shell.addListener(SWT.Dispose, new Listener() { public void handleEvent(Event event) { isActive = false; @@ -85,10 +77,9 @@ public class EventConsole { public void log (Event event) { if (isActive && eventsFilter [event.type]) { - StringBuffer output = new StringBuffer ("Control: "); + StringBuffer output = new StringBuffer (EVENT_TYPES[event.type]); + output.append (": "); output.append (event.widget.toString ()); - output.append (" Type: "); - output.append (EVENT_TYPES[event.type]); output.append (" X: "); output.append (event.x); output.append (" Y: "); |