001: package fr.aliacom.form.common;
002:
003: import java.beans.PropertyChangeListener;
004: import java.beans.PropertyChangeSupport;
005: import java.util.prefs.BackingStoreException;
006: import java.util.prefs.Preferences;
007:
008: import fr.aliacom.common.ui.IColor;
009: import fr.aliacom.common.ui.IIcon;
010: import fr.aliacom.common.ui.IInternalFrame;
011: import fr.aliacom.common.ui.ISplashScreen;
012: import fr.aliacom.common.ui.ITopLevelFrame;
013: import fr.aliacom.form.storage.IFormRepository;
014: import fr.aliacom.form.storage.IIconRepository;
015: import fr.aliacom.form.storage.IScriptRepository;
016: import fr.aliacom.util.StringFunctions;
017:
018: /**
019: * @author tom
020: *
021: * (C) 2001, 2002 Thomas Cataldo
022: */
023: public abstract class Toolkit implements IIconRepository,
024: IFormRepository, IScriptRepository {
025:
026: public static final int OPEN = 1 << 0;
027: public static final int SAVE = 1 << 1;
028:
029: private Preferences prefs;
030: private PropertyChangeSupport pcs;
031:
032: public Toolkit() {
033: prefs = Preferences.userNodeForPackage(getClass());
034: pcs = new PropertyChangeSupport(this );
035: }
036:
037: public abstract void init();
038:
039: public void handleError(IFormComponent parent, Throwable t) {
040: String message = "An (un)expected error occured. Sorry for the inconvenience.\n"
041: + "Please report the following text at \"tcataldo@users.sourceforge.net\":\n\n"
042: + StringFunctions.getExceptionTraceText(t);
043: handleError(parent, message);
044: }
045:
046: public abstract void handleError(IFormComponent parent, String s);
047:
048: /**
049: * Method getNewParser.
050: * @return FormParser
051: */
052: public abstract IFormParser getNewParser();
053:
054: /**
055: * Method newAliaInternalFrame.
056: * @param f
057: * @return AliaInternalFrame
058: */
059: public abstract IInternalFrame newInternalFrame(IForm f);
060:
061: /**
062: * Method newAliaTopLevelFrame.
063: * @param f
064: * @return AliaTopLevelFrame
065: */
066: public abstract ITopLevelFrame newTopLevelFrame(IForm f);
067:
068: /**
069: * Method confirm.
070: * @param form
071: * @param confirmMessage
072: * @return boolean
073: */
074: public abstract boolean confirm(IFormComponent form,
075: String confirmMessage);
076:
077: /**
078: * Method newSplashScreen.
079: * @param iconName
080: * @param i
081: * @return SplashScreen
082: */
083: public abstract ISplashScreen newSplashScreen(String iconName, int i);
084:
085: /**
086: * Method getIcon.
087: * @param iconName
088: * @return Icon
089: */
090: public abstract IIcon getIcon(String iconName);
091:
092: /**
093: * Method asyncExec.
094: * @param asyncCommandWorker
095: */
096: public abstract void asyncExec(Runnable asyncCommandWorker);
097:
098: /**
099: * Method asyncExec.
100: * @param syncCommandWorker
101: */
102: public abstract void syncExec(Runnable syncCommandWorker);
103:
104: public FormWorker startWork(IWorker worker) {
105: final FormWorker task = new FormWorker(worker);
106: task.start();
107: return task;
108: }
109:
110: /**
111: * Method getDisplay.
112: * @return Display
113: */
114: public abstract Object getDisplay();
115:
116: /**
117: * Method start.
118: */
119: public abstract void start(IApplication app);
120:
121: public abstract void stop();
122:
123: public abstract IColor newColor(int r, int g, int b);
124:
125: public abstract void setMainWindow(IForm mainWindow);
126:
127: public abstract IForm getMainWindow();
128:
129: public abstract String showDirectoryDialog();
130:
131: public abstract String showFontDialog();
132:
133: /**
134: *
135: * @param mode Toolkit.OPEN or Toolkit.SAVE
136: * @return the path of the selected file, or <code>null</code> if cancelled.
137: */
138: public abstract String showFileDialog(int mode);
139:
140: public String getMonospaceFontName() {
141: return prefs.get("monospace", "Monospace");
142: }
143:
144: public void setMonospaceFontName(String font) {
145: String oldValue = getMonospaceFontName();
146: prefs.put("monospace", font);
147: pcs.firePropertyChange("monospaceFontName", oldValue, font);
148: try {
149: prefs.sync();
150: } catch (BackingStoreException e) {
151: handleError(getMainWindow(), e);
152: }
153: }
154:
155: /**
156: * Returns the icon to display when the icon asked
157: * by the user is not available in the {@link IIconRepository}.
158: *
159: * @return the broken icon
160: */
161: public abstract IIcon getBrokenIcon();
162:
163: /**
164: * @param propertyName
165: * @param listener
166: */
167: public synchronized void addPropertyChangeListener(
168: String propertyName, PropertyChangeListener listener) {
169: pcs.addPropertyChangeListener(propertyName, listener);
170: }
171:
172: /**
173: * @param propertyName
174: * @param listener
175: */
176: public synchronized void removePropertyChangeListener(
177: String propertyName, PropertyChangeListener listener) {
178: pcs.removePropertyChangeListener(propertyName, listener);
179: }
180:
181: }
|