KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > PookaPreviewPaneUIFactory


1 package net.suberic.pooka.gui;
2 import net.suberic.util.gui.propedit.PropertyEditorFactory;
3 import net.suberic.util.gui.ConfigurableToolbar;
4 import net.suberic.util.gui.IconManager;
5 import net.suberic.util.swing.*;
6 import net.suberic.pooka.*;
7 import net.suberic.pooka.gui.search.*;
8 import javax.swing.JDialog JavaDoc;
9 import javax.swing.JScrollPane JavaDoc;
10 import javax.swing.JTextArea JavaDoc;
11 import javax.swing.JFrame JavaDoc;
12 import javax.swing.JOptionPane JavaDoc;
13 import javax.swing.SwingUtilities JavaDoc;
14 import java.awt.*;
15
16 /**
17  * This is an implementation of PookaUIFactory which creates a single
18  * panel which shows the list of messages in the folder and a preview
19  * pane which shows the message itself. You should also be able to
20  * open messages in individual Frames. New messages go into individual
21  * Frames, also.
22  */

23 public class PookaPreviewPaneUIFactory extends SwingUIFactory {
24
25   PreviewContentPanel contentPanel = null;
26
27   /**
28    * Constructor.
29    */

30   public PookaPreviewPaneUIFactory(PookaUIFactory pSource) {
31     if (pSource != null) {
32       editorFactory = new PropertyEditorFactory(Pooka.getResources(), pSource.getIconManager(), Pooka.getPookaManager().getHelpBroker());
33       pookaThemeManager = new ThemeManager("Pooka.theme", Pooka.getResources());
34       mIconManager = pSource.getIconManager();
35       mMessageNotificationManager = pSource.getMessageNotificationManager();
36     } else {
37       pookaThemeManager = new ThemeManager("Pooka.theme", Pooka.getResources());
38       mIconManager = IconManager.getIconManager(Pooka.getResources(), "IconManager._default");
39       editorFactory = new PropertyEditorFactory(Pooka.getResources(), mIconManager, Pooka.getPookaManager().getHelpBroker());
40       mMessageNotificationManager = new MessageNotificationManager();
41
42     }
43   }
44
45   /**
46    * Constructor.
47    */

48   public PookaPreviewPaneUIFactory() {
49     this(null);
50   }
51
52   /**
53    * Creates an appropriate MessageUI object for the given MessageProxy,
54    * using the provided MessageUI as a guideline.
55    *
56    * Note that this implementation ignores the mui component.
57    */

58   public MessageUI createMessageUI(MessageProxy mp, MessageUI templateMui) {
59     // each MessageProxy can have exactly one MessageUI.
60
if (mp.getMessageUI() != null)
61       return mp.getMessageUI();
62
63     MessageUI mui;
64     if (mp instanceof NewMessageProxy) {
65       mui = new NewMessageFrame((NewMessageProxy) mp);
66     } else
67       mui = new ReadMessageFrame(mp);
68
69     mp.setMessageUI(mui);
70
71     applyNewWindowLocation((JFrame JavaDoc)mui);
72     return mui;
73   }
74
75   /**
76    * Opens the given MessageProxy in the default manner for this UI.
77    * Usually this will just be callen createMessageUI() and openMessageUI()
78    * on it. However, in some cases (Preview Panel without auto display)
79    * it may be necessary to act differently.
80    *
81    */

82   public void doDefaultOpen(MessageProxy mp) {
83     if (contentPanel.getAutoPreview()) {
84       if (mp != null)
85         mp.openWindow();
86     } else {
87       SwingUtilities.invokeLater(new Runnable JavaDoc() {
88           public void run() {
89             contentPanel.refreshCurrentMessage();
90           }
91         });
92     }
93   }
94
95   /**
96    * Creates an appropriate FolderDisplayUI object for the given
97    * FolderInfo.
98    */

99   public FolderDisplayUI createFolderDisplayUI(net.suberic.pooka.FolderInfo fi) {
100     // a FolderInfo can only have one FolderDisplayUI.
101

102     if (fi.getFolderDisplayUI() != null)
103       return fi.getFolderDisplayUI();
104
105     PreviewFolderPanel fw = new PreviewFolderPanel(contentPanel, fi);
106     contentPanel.addPreviewPanel(fw, fi.getFolderID());
107     return fw;
108
109   }
110
111   /**
112    * Creates a JPanel which will be used to show messages and folders.
113    *
114    * This implementation creates an instance of PreviewContentPanel.
115    */

116   public ContentPanel createContentPanel() {
117     contentPanel = new PreviewContentPanel();
118     contentPanel.setSize(1000,1000);
119
120     return contentPanel;
121   }
122
123   /**
124    * Creates a Toolbar for the MainPanel.
125    */

126   public ConfigurableToolbar createMainToolbar() { return new ConfigurableToolbar("MainToolbar", Pooka.getResources());
127   }
128
129   /**
130    * Creates a Toolbar for the FolderPanel.
131    */

132   public ConfigurableToolbar createFolderPanelToolbar() {
133     return null;
134   }
135
136   /**
137    * Creates a JPanel which will be used to show messages and folders.
138    *
139    * This implementation creates an instance PreviewConentPanel from a
140    * given MessagePanel.
141    */

142   public ContentPanel createContentPanel(MessagePanel mp) {
143     contentPanel = new PreviewContentPanel(mp);
144     contentPanel.setSize(1000,1000);
145
146     return contentPanel;
147   }
148
149   /**
150    * Shows an Editor Window with the given title, which allows the user
151    * to edit the values in the properties Vector. The given properties
152    * will be shown according to the values in the templates Vector.
153    * Note that there should be an entry in the templates Vector for
154    * each entry in the properties Vector.
155    */

156   public void showEditorWindow(String JavaDoc title, String JavaDoc property, String JavaDoc template) {
157     JDialog JavaDoc jd = (JDialog JavaDoc)getEditorFactory().createEditorWindow(title, property, template);
158     jd.pack();
159     applyNewWindowLocation(jd);
160     jd.setVisible(true);
161   }
162
163   /**
164    * This shows an Confirm Dialog window. We include this so that
165    * the MessageProxy can call the method without caring abou the
166    * actual implementation of the Dialog.
167    */

168   public int showConfirmDialog(String JavaDoc messageText, String JavaDoc title, int type) {
169     String JavaDoc displayMessage = formatMessage(messageText);
170     final ResponseWrapper fResponseWrapper = new ResponseWrapper();
171     final String JavaDoc fDisplayMessage = displayMessage;
172     final String JavaDoc fTitle = title;
173     final int fType = type;
174     Runnable JavaDoc runMe = new Runnable JavaDoc() {
175         public void run() {
176         }
177       };
178
179     if (! SwingUtilities.isEventDispatchThread()) {
180       try {
181         SwingUtilities.invokeAndWait(runMe);
182       } catch (Exception JavaDoc e) {
183       }
184     } else {
185       runMe.run();
186     }
187
188     return fResponseWrapper.getInt();
189   }
190
191
192   /**
193    * Shows a Confirm dialog with the given Object[] as the Message.
194    */

195   public int showConfirmDialog(Object JavaDoc[] messageComponents, String JavaDoc title, int type) {
196     final ResponseWrapper fResponseWrapper = new ResponseWrapper();
197     final Object JavaDoc[] fMessageComponents = messageComponents;
198     final String JavaDoc fTitle = title;
199     final int fType = type;
200     Runnable JavaDoc runMe = new Runnable JavaDoc() {
201         public void run() {
202           fResponseWrapper.setInt(JOptionPane.showConfirmDialog(contentPanel.getUIComponent(), fMessageComponents, fTitle, fType));
203         }
204       };
205
206     if (! SwingUtilities.isEventDispatchThread()) {
207       try {
208         SwingUtilities.invokeAndWait(runMe);
209       } catch (Exception JavaDoc e) {
210       }
211     } else {
212       runMe.run();
213     }
214
215     return fResponseWrapper.getInt();
216   }
217
218   /**
219    * This shows an Error Message window. We include this so that
220    * the MessageProxy can call the method without caring abou the
221    * actual implementation of the Dialog.
222    */

223   public void showError(String JavaDoc errorMessage) {
224     showError(errorMessage, Pooka.getProperty("Error", "Error"));
225   }
226
227   /**
228    * This shows an Error Message window. We include this so that
229    * the MessageProxy can call the method without caring abou the
230    * actual implementation of the Dialog.
231    */

232   public void showError(String JavaDoc errorMessage, Exception JavaDoc e) {
233     showError(errorMessage, Pooka.getProperty("Error", "Error"), e);
234   }
235
236   /**
237    * Creates a ProgressDialog using the given values.
238    */

239   public ProgressDialog createProgressDialog(int min, int max, int initialValue, String JavaDoc title, String JavaDoc content) {
240     return new ProgressDialogImpl(min, max, initialValue, title, content);
241   }
242
243   /**
244    * Shows an Address Selection form for the given AddressEntryTextArea.
245    */

246   public void showAddressWindow(AddressEntryTextArea aeta) {
247     JFrame JavaDoc jf = new JFrame JavaDoc(Pooka.getProperty("AddressBookTable.title", "Choose Address"));
248     jf.getContentPane().add(new AddressBookSelectionPanel(aeta, jf));
249     jf.pack();
250     applyNewWindowLocation(jf);
251     jf.setVisible(true);
252   }
253
254   /**
255    * Determines the location for new windows.
256    */

257   public void applyNewWindowLocation(Window f) {
258     try {
259       Point newLocation = getNewWindowLocation(f);
260       f.setLocation(newLocation);
261     } catch (Exception JavaDoc e) {
262     }
263   }
264
265   int lastX = 20;
266   int lastY = 20;
267   boolean firstPlacement = true;
268
269   /**
270    * Determines the location for new windows.
271    */

272   public Point getNewWindowLocation(Window f) throws Exception JavaDoc {
273     if (firstPlacement) {
274       Point location = Pooka.getMainPanel().getParentFrame().getLocation();
275       lastX = location.x;
276       lastY = location.y;
277       firstPlacement = false;
278     }
279     GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
280
281     Rectangle bounds = conf.getBounds();
282
283     int baseDelta = 20;
284
285     Dimension componentSize = f.getSize();
286
287     int currentX = lastX + baseDelta;
288     int currentY = lastY + baseDelta;
289     if (currentX + componentSize.width > bounds.x + bounds.width) {
290       currentX = bounds.x;
291     }
292
293     if (currentY + componentSize.height > bounds.y + bounds.height) {
294       currentY = bounds.y;
295     }
296
297     lastX = currentX;
298     lastY = currentY;
299
300     return new Point(currentX, currentY);
301   }
302
303 }
304
Popular Tags