001: /*
002: * Created on May 13, 2004
003: */
004: package net.charabia.jsmoothgen.application.swtgui;
005:
006: import java.util.HashSet;
007: import java.util.Set;
008:
009: import org.eclipse.swt.SWT;
010: import org.eclipse.swt.events.SelectionAdapter;
011: import org.eclipse.swt.events.SelectionEvent;
012: import org.eclipse.swt.graphics.Image;
013: import org.eclipse.swt.widgets.Composite;
014: import org.eclipse.swt.widgets.Control;
015: import org.eclipse.swt.widgets.Shell;
016: import org.eclipse.swt.widgets.ToolBar;
017: import org.eclipse.swt.widgets.ToolItem;
018:
019: /**
020: * @author Dumon
021: */
022: public abstract class JSmoothPage {
023: private Control control;
024: private JSmoothApplication js;
025: private Set modifyListeners = new HashSet();
026: private String toolTip = "";
027: private Image image;
028: private boolean hidden = false;
029: private String id = "";
030: private ToolItem item;
031:
032: public JSmoothPage(JSmoothApplication js) {
033: this .js = js;
034: }
035:
036: public final Control createControl(Composite parent) {
037: return control = createPageArea(parent);
038: }
039:
040: public ToolItem createToolItem(final ToolBar toolbar) {
041: configureResources();
042: item = new ToolItem(toolbar, SWT.RADIO);
043: item.setImage(getImage());
044: item.setToolTipText(getToolTip());
045: item.addSelectionListener(new SelectionAdapter() {
046: public void widgetSelected(SelectionEvent e) {
047: js.showPage(JSmoothPage.this );
048: ToolItem[] items = toolbar.getItems();
049: for (int i = 0; i < items.length; i++) {
050: if (items[i] != item)
051: items[i].setSelection(false);
052: }
053: }
054: });
055: return item;
056: }
057:
058: public ToolItem getToolItem() {
059: return item;
060: }
061:
062: protected abstract Control createPageArea(Composite parent);
063:
064: protected abstract void configureResources();
065:
066: public Control getControl() {
067: return control;
068: }
069:
070: protected void setControl(Control cmp) {
071: control = cmp;
072: }
073:
074: protected Shell getShell() {
075: return js.getShell();
076: }
077:
078: protected void setToolTip(String toolTip) {
079: this .toolTip = toolTip;
080: }
081:
082: protected String getToolTip() {
083: return toolTip;
084: }
085:
086: public String getId() {
087: return id;
088: }
089:
090: protected void setId(String id) {
091: this .id = id;
092: }
093:
094: protected Image getImage() {
095: return image;
096: }
097:
098: protected void setImage(Image image) {
099: this .image = image;
100: }
101:
102: protected JSmoothApplication getApplication() {
103: return js;
104: }
105:
106: protected void setHidden(boolean hidden) {
107: this .hidden = hidden;
108: }
109:
110: public boolean isHidden() {
111: return hidden;
112: }
113:
114: public abstract void load();
115: }
|