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 ; 9 import javax.swing.JScrollPane ; 10 import javax.swing.JTextArea ; 11 import javax.swing.JFrame ; 12 import javax.swing.JOptionPane ; 13 import javax.swing.SwingUtilities ; 14 import java.awt.*; 15 16 23 public class PookaPreviewPaneUIFactory extends SwingUIFactory { 24 25 PreviewContentPanel contentPanel = null; 26 27 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 48 public PookaPreviewPaneUIFactory() { 49 this(null); 50 } 51 52 58 public MessageUI createMessageUI(MessageProxy mp, MessageUI templateMui) { 59 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 )mui); 72 return mui; 73 } 74 75 82 public void doDefaultOpen(MessageProxy mp) { 83 if (contentPanel.getAutoPreview()) { 84 if (mp != null) 85 mp.openWindow(); 86 } else { 87 SwingUtilities.invokeLater(new Runnable () { 88 public void run() { 89 contentPanel.refreshCurrentMessage(); 90 } 91 }); 92 } 93 } 94 95 99 public FolderDisplayUI createFolderDisplayUI(net.suberic.pooka.FolderInfo fi) { 100 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 116 public ContentPanel createContentPanel() { 117 contentPanel = new PreviewContentPanel(); 118 contentPanel.setSize(1000,1000); 119 120 return contentPanel; 121 } 122 123 126 public ConfigurableToolbar createMainToolbar() { return new ConfigurableToolbar("MainToolbar", Pooka.getResources()); 127 } 128 129 132 public ConfigurableToolbar createFolderPanelToolbar() { 133 return null; 134 } 135 136 142 public ContentPanel createContentPanel(MessagePanel mp) { 143 contentPanel = new PreviewContentPanel(mp); 144 contentPanel.setSize(1000,1000); 145 146 return contentPanel; 147 } 148 149 156 public void showEditorWindow(String title, String property, String template) { 157 JDialog jd = (JDialog )getEditorFactory().createEditorWindow(title, property, template); 158 jd.pack(); 159 applyNewWindowLocation(jd); 160 jd.setVisible(true); 161 } 162 163 168 public int showConfirmDialog(String messageText, String title, int type) { 169 String displayMessage = formatMessage(messageText); 170 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 171 final String fDisplayMessage = displayMessage; 172 final String fTitle = title; 173 final int fType = type; 174 Runnable runMe = new Runnable () { 175 public void run() { 176 } 177 }; 178 179 if (! SwingUtilities.isEventDispatchThread()) { 180 try { 181 SwingUtilities.invokeAndWait(runMe); 182 } catch (Exception e) { 183 } 184 } else { 185 runMe.run(); 186 } 187 188 return fResponseWrapper.getInt(); 189 } 190 191 192 195 public int showConfirmDialog(Object [] messageComponents, String title, int type) { 196 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 197 final Object [] fMessageComponents = messageComponents; 198 final String fTitle = title; 199 final int fType = type; 200 Runnable runMe = new Runnable () { 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 e) { 210 } 211 } else { 212 runMe.run(); 213 } 214 215 return fResponseWrapper.getInt(); 216 } 217 218 223 public void showError(String errorMessage) { 224 showError(errorMessage, Pooka.getProperty("Error", "Error")); 225 } 226 227 232 public void showError(String errorMessage, Exception e) { 233 showError(errorMessage, Pooka.getProperty("Error", "Error"), e); 234 } 235 236 239 public ProgressDialog createProgressDialog(int min, int max, int initialValue, String title, String content) { 240 return new ProgressDialogImpl(min, max, initialValue, title, content); 241 } 242 243 246 public void showAddressWindow(AddressEntryTextArea aeta) { 247 JFrame jf = new JFrame (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 257 public void applyNewWindowLocation(Window f) { 258 try { 259 Point newLocation = getNewWindowLocation(f); 260 f.setLocation(newLocation); 261 } catch (Exception e) { 262 } 263 } 264 265 int lastX = 20; 266 int lastY = 20; 267 boolean firstPlacement = true; 268 269 272 public Point getNewWindowLocation(Window f) throws Exception { 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 |