KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.suberic.pooka.gui;
2 import net.suberic.util.gui.propedit.PropertyEditorFactory;
3 //import net.suberic.util.gui.propedit.DesktopPropertyEditorFactory;
4
import net.suberic.util.gui.ConfigurableToolbar;
5 import net.suberic.util.gui.IconManager;
6 import net.suberic.util.swing.*;
7 import net.suberic.pooka.*;
8 import net.suberic.pooka.gui.search.*;
9
10 import java.awt.Dimension JavaDoc;
11 import java.awt.GraphicsConfiguration JavaDoc;
12 import java.awt.GraphicsEnvironment JavaDoc;
13 import java.awt.Point JavaDoc;
14 import java.awt.Rectangle JavaDoc;
15 import java.awt.Window JavaDoc;
16
17 import javax.swing.JInternalFrame JavaDoc;
18 import javax.swing.JDialog JavaDoc;
19 import javax.swing.JScrollPane JavaDoc;
20 import javax.swing.JTextArea JavaDoc;
21 import javax.swing.JLabel JavaDoc;
22 import javax.swing.JOptionPane JavaDoc;
23 import javax.swing.SwingUtilities JavaDoc;
24 import javax.mail.MessagingException JavaDoc;
25
26 /**
27  * This is an implementation of PookaUIFactory which creates InternalFrame
28  * objects on a JDesktopPane.
29  */

30 public class PookaDesktopPaneUIFactory extends SwingUIFactory {
31
32   MessagePanel messagePanel = null;
33
34   /**
35    * Constructor.
36    */

37   public PookaDesktopPaneUIFactory(PookaUIFactory pSource) {
38     if (pSource != null) {
39       editorFactory = new PropertyEditorFactory(Pooka.getResources(), pSource.getIconManager(), Pooka.getPookaManager().getHelpBroker());
40       pookaThemeManager = pSource.getPookaThemeManager();
41       mIconManager = pSource.getIconManager();
42       mMessageNotificationManager = pSource.getMessageNotificationManager();
43     } else {
44       pookaThemeManager = new ThemeManager("Pooka.theme", Pooka.getResources());
45       mIconManager = IconManager.getIconManager(Pooka.getResources(), "IconManager._default");
46       editorFactory = new PropertyEditorFactory(Pooka.getResources(), mIconManager, Pooka.getPookaManager().getHelpBroker());
47       mMessageNotificationManager = new MessageNotificationManager();
48     }
49   }
50
51   /**
52    * Constructor.
53    */

54   public PookaDesktopPaneUIFactory() {
55     this(null);
56   }
57
58   /**
59    * Creates an appropriate MessageUI object for the given MessageProxy,
60    * using the provided MessageUI as a guideline.
61    */

62   public MessageUI createMessageUI(MessageProxy mp, MessageUI templateMui) throws javax.mail.MessagingException JavaDoc {
63     // each MessageProxy can have exactly one MessageUI.
64
if (mp.getMessageUI() != null)
65       return mp.getMessageUI();
66
67     boolean createExternal = (templateMui != null && templateMui instanceof MessageFrame);
68
69     MessageUI mui;
70     if (mp instanceof NewMessageProxy) {
71       if (createExternal)
72         mui = new NewMessageFrame((NewMessageProxy) mp);
73       else
74         mui = new NewMessageInternalFrame(getMessagePanel(), (NewMessageProxy) mp);
75     } else {
76       if (createExternal) {
77         mui = new ReadMessageFrame(mp);
78       } else {
79         mui = new ReadMessageInternalFrame(getMessagePanel(), mp);
80         ((ReadMessageInternalFrame)mui).configureMessageInternalFrame();
81       }
82     }
83
84     mp.setMessageUI(mui);
85     return mui;
86   }
87
88   /**
89    * Opens the given MessageProxy in the default manner for this UI.
90    * Usually this will just be callen createMessageUI() and openMessageUI()
91    * on it. However, in some cases (Preview Panel without auto display)
92    * it may be necessary to act differently.
93    *
94    * For this implementation, just calls mp.openWindow().
95    */

96   public void doDefaultOpen(MessageProxy mp) {
97     if (mp != null)
98       mp.openWindow();
99   }
100
101   /**
102    * Creates an appropriate FolderDisplayUI object for the given
103    * FolderInfo.
104    */

105   public FolderDisplayUI createFolderDisplayUI(net.suberic.pooka.FolderInfo fi) {
106     // a FolderInfo can only have one FolderDisplayUI.
107

108     if (fi.getFolderDisplayUI() != null)
109       return fi.getFolderDisplayUI();
110
111     FolderDisplayUI fw = new FolderInternalFrame(fi, getMessagePanel());
112     return fw;
113   }
114
115   /**
116    * Shows an Editor Window with the given title, which allows the user
117    * to edit the values in the properties Vector. The given properties
118    * will be shown according to the values in the templates Vector.
119    * Note that there should be an entry in the templates Vector for
120    * each entry in the properties Vector.
121    */

122   public void showEditorWindow(String JavaDoc title, String JavaDoc property, String JavaDoc template) {
123     JDialog JavaDoc jd = (JDialog JavaDoc)getEditorFactory().createEditorWindow(title, property, template);
124     jd.pack();
125     applyNewWindowLocation(jd);
126     jd.setVisible(true);
127   /*
128     JInternalFrame jif = (JInternalFrame)getEditorFactory().createEditorWindow(title, property, template);
129     getMessagePanel().add(jif);
130     jif.setLocation(getMessagePanel().getNewWindowLocation(jif, true));
131
132     jif.setVisible(true);
133
134     try {
135       jif.setSelected(true);
136     } catch (java.beans.PropertyVetoException pve) {
137     }
138   */

139   }
140
141   /**
142    * Determines the location for new windows.
143    */

144   public void applyNewWindowLocation(Window JavaDoc f) {
145     try {
146       Point JavaDoc newLocation = getNewWindowLocation(f);
147       f.setLocation(newLocation);
148     } catch (Exception JavaDoc e) {
149     }
150   }
151
152   /**
153    * Determines the location for new windows.
154    */

155   public Point JavaDoc getNewWindowLocation(Window JavaDoc f) throws Exception JavaDoc {
156     Point JavaDoc location = Pooka.getMainPanel().getParentFrame().getLocation();
157     Dimension JavaDoc mainWindowSize = Pooka.getMainPanel().getParentFrame().getSize();
158     Dimension JavaDoc windowSize = f.getSize();
159     int yValue = ((mainWindowSize.height - windowSize.height) / 2) + location.y;
160     int xValue = ((mainWindowSize.width - windowSize.width) / 2) + location.x;
161     return new Point JavaDoc(xValue, yValue);
162   }
163
164
165   /**
166    * Creates a JPanel which will be used to show messages and folders.
167    *
168    * This implementation creates an instance of MessagePanel.
169    */

170   public ContentPanel createContentPanel() {
171     messagePanel = new MessagePanel();
172     messagePanel.setSize(1000,1000);
173     JScrollPane JavaDoc messageScrollPane = new JScrollPane JavaDoc(messagePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
174     messagePanel.setDesktopManager(messagePanel.new ExtendedDesktopManager(messagePanel, messageScrollPane));
175     messagePanel.setUIComponent(messageScrollPane);
176
177     //((PropertyEditorFactory) editorFactory).setDesktop(messagePanel);
178
return messagePanel;
179   }
180
181   /**
182    * Creates a JPanel which will be used to show messages and folders.
183    *
184    * This implementation creates an instance of MessagePanel.
185    */

186   public ContentPanel createContentPanel(PreviewContentPanel pcp) {
187     messagePanel = new MessagePanel(pcp);
188     messagePanel.setSize(1000,1000);
189     JScrollPane JavaDoc messageScrollPane = new JScrollPane JavaDoc(messagePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
190     messagePanel.setDesktopManager(messagePanel.new ExtendedDesktopManager(messagePanel, messageScrollPane));
191     messagePanel.setUIComponent(messageScrollPane);
192
193     //((DesktopPropertyEditorFactory) editorFactory).setDesktop(messagePanel);
194
return messagePanel;
195   }
196
197
198   /**
199    * Creates a Toolbar for the MainPanel.
200    * This implementation returns null.
201    */

202   public ConfigurableToolbar createMainToolbar() {
203     return null;
204   }
205
206   /**
207    * Creates a Toolbar for the FolderPanel.
208    */

209   public ConfigurableToolbar createFolderPanelToolbar() {
210     return new ConfigurableToolbar("FolderToolbar", Pooka.getResources());
211   }
212
213   /**
214    * Returns the MessagePanel associated with this Factory.
215    */

216   public MessagePanel getMessagePanel() {
217     return messagePanel;
218   }
219
220
221   /**
222    * This shows an Error Message window.
223    */

224   public void showError(String JavaDoc errorMessage) {
225     showError(errorMessage, Pooka.getProperty("Error", "Error"));
226   }
227
228   /**
229    * This shows an Error Message window.
230    */

231   public void showError(String JavaDoc errorMessage, Exception JavaDoc e) {
232     showError(errorMessage, Pooka.getProperty("Error", "Error"), e);
233   }
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 ProgressInternalDialog(min, max, initialValue, title, content, getMessagePanel());
241   }
242
243   /**
244    * Checks to see if the given component is in the main Pooka frame.
245    */

246   public boolean isInMainFrame(java.awt.Component JavaDoc c) {
247     java.awt.Window JavaDoc mainWindow = SwingUtilities.getWindowAncestor(messagePanel);
248     java.awt.Window JavaDoc componentWindow = SwingUtilities.getWindowAncestor(c);
249     return (mainWindow == componentWindow);
250   }
251
252
253 }
254
Popular Tags