1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.*; 3 import net.suberic.util.gui.*; 4 import net.suberic.util.swing.*; 5 import javax.mail.*; 6 import javax.mail.internet.*; 7 import java.awt.*; 8 import java.awt.event.*; 9 import javax.swing.*; 10 import javax.swing.plaf.basic.*; 11 import javax.swing.text.TextAction ; 12 import java.util.*; 13 import javax.swing.text.JTextComponent ; 14 import javax.swing.event.*; 15 import java.io.File ; 16 import javax.swing.plaf.metal.MetalTheme ; 17 18 23 public abstract class MessageInternalFrame extends JInternalFrame implements MessageUI, ThemeSupporter, ThemeListener { 24 25 protected MessagePanel parentContainer; 26 27 protected MessageProxy msg; 28 protected MessageDisplayPanel messageDisplay; 29 30 protected ConfigurableToolbar toolbar; 31 protected ConfigurableKeyBinding keyBindings; 32 protected boolean addedToDesktop = false; 33 34 protected PookaUIFactory uiFactory; 35 36 protected javax.swing.plaf.metal.MetalTheme currentTheme = null; 37 38 41 public MessageInternalFrame(MessagePanel newParentContainer, MessageProxy newMsgProxy) { 42 super(Pooka.getProperty("Pooka.messageInternalFrame.messageTitle.newMessage", "New Message"), true, true, true, true); 43 44 parentContainer = newParentContainer; 45 msg=newMsgProxy; 46 47 this.getContentPane().setLayout(new BorderLayout()); 48 49 this.addFocusListener(new FocusAdapter() { 50 public void focusGained(FocusEvent e) { 51 if (getMessageDisplay() != null) 52 getMessageDisplay().requestFocusInWindow(); 53 } 54 }); 55 56 FocusTraversalPolicy ftp = new LayoutFocusTraversalPolicy() { 57 public Component getInitialComponent(JInternalFrame jif) { 58 if (jif instanceof MessageInternalFrame) { 59 return ((MessageInternalFrame) jif).getMessageDisplay(); 60 } 61 62 return super.getInitialComponent(jif); 63 } 64 }; 65 this.setFocusTraversalPolicy(ftp); 66 67 if (getUI() instanceof BasicInternalFrameUI) { 68 ((BasicInternalFrameUI) getUI()).getNorthPane().addMouseListener(new MouseAdapter() { 69 70 public void mousePressed(MouseEvent evt) { 71 if (evt.getButton() == MouseEvent.BUTTON2) { 72 try { 73 Object messagePanel = SwingUtilities.getAncestorOfClass(Class.forName("net.suberic.pooka.gui.MessagePanel"), MessageInternalFrame.this); 74 if (messagePanel != null) { 75 ((MessagePanel) messagePanel).unselectAndMoveToBack(MessageInternalFrame.this); 76 evt.consume(); 77 } 78 } catch (Exception e) { 79 getLogger().log(java.util.logging.Level.FINE, "exception lowering MessageInternalFrame", e); 80 } 81 } 82 } 83 }); 84 } 85 } 86 87 90 91 protected MessageInternalFrame() { 92 super(Pooka.getProperty("Pooka.messageInternalFrame.messageTitle.newMessage", "New Message"), true, true, true, true); 93 this.getContentPane().setLayout(new BorderLayout()); 94 95 if (getUI() instanceof BasicInternalFrameUI) { 96 ((BasicInternalFrameUI) getUI()).getNorthPane().addMouseListener(new MouseAdapter() { 97 98 public void mouseClicked(MouseEvent evt) { 99 if (evt.getButton() == MouseEvent.BUTTON2) { 100 try { 101 Object messagePanel = SwingUtilities.getAncestorOfClass(Class.forName("net.suberic.pooka.gui.MessagePanel"), MessageInternalFrame.this); 102 if (messagePanel != null) { 103 ((MessagePanel) messagePanel).unselectAndMoveToBack(MessageInternalFrame.this); 104 evt.consume(); 105 } 106 } catch (Exception e) { 107 getLogger().log(java.util.logging.Level.FINE, "exception lowering MessageInternalFrame", e); 108 } 109 } 110 } 111 112 }); 113 } 114 } 115 116 120 121 protected abstract void configureMessageInternalFrame() throws MessagingException; 122 123 126 public void configureInterfaceStyle() { 127 Runnable runMe = new Runnable () { 128 public void run() { 129 try { 130 Pooka.getUIFactory().getPookaThemeManager().updateUI(MessageInternalFrame.this, MessageInternalFrame.this); 131 getMessageDisplay().setDefaultFont(); 132 getMessageDisplay().sizeToDefault(); 133 MessageInternalFrame.this.setSize(MessageInternalFrame.this.getPreferredSize()); 134 if (getUI() instanceof BasicInternalFrameUI) { 135 ((BasicInternalFrameUI) getUI()).getNorthPane().addMouseListener(new MouseAdapter() { 136 137 public void mouseClicked(MouseEvent evt) { 138 if (evt.getButton() == MouseEvent.BUTTON2) { 139 try { 140 Object messagePanel = SwingUtilities.getAncestorOfClass(Class.forName("net.suberic.pooka.gui.MessagePanel"), MessageInternalFrame.this); 141 if (messagePanel != null) { 142 ((MessagePanel) messagePanel).unselectAndMoveToBack(MessageInternalFrame.this); 143 evt.consume(); 144 } 145 } catch (Exception e) { 146 getLogger().log(java.util.logging.Level.FINE, "exception lowering MessageInternalFrame", e); 147 } 148 } 149 } 150 151 }); 152 } 153 } catch (Exception e) { 154 } 155 } 156 }; 157 158 if (! SwingUtilities.isEventDispatchThread()) { 159 SwingUtilities.invokeLater(runMe); 160 } else { 161 runMe.run(); 162 } 163 } 164 165 168 public MetalTheme getCurrentTheme() { 169 return currentTheme; 170 } 171 172 175 public void setCurrentTheme(MetalTheme newTheme) { 176 if (currentTheme != null && currentTheme instanceof ConfigurableMetalTheme) { 177 ((ConfigurableMetalTheme)currentTheme).removeThemeListener(this); 178 } 179 currentTheme = newTheme; 180 181 if (currentTheme != null && currentTheme instanceof ConfigurableMetalTheme) { 182 ((ConfigurableMetalTheme)currentTheme).addThemeListener(this); 183 } 184 } 185 186 189 public void themeChanged(ConfigurableMetalTheme theme) { 190 if (currentTheme != null && currentTheme == theme) { 193 SwingUtilities.invokeLater(new Runnable () { 194 public void run() { 195 try { 196 Pooka.getUIFactory().getPookaThemeManager().updateUI(MessageInternalFrame.this, MessageInternalFrame.this, true); 197 getMessageDisplay().setDefaultFont(); 198 getMessageDisplay().sizeToDefault(); 199 MessageInternalFrame.this.setSize(MessageInternalFrame.this.getPreferredSize()); 200 201 } catch (Exception e) { 202 } 203 204 } 205 }); 206 } 207 } 208 209 213 public void openMessageUI() { 214 getParentContainer().openMessageWindow(getMessageProxy(), !addedToDesktop); 215 addedToDesktop = true; 216 } 217 218 221 public void closeMessageUI() { 222 try { 223 this.setClosed(true); 224 } catch (java.beans.PropertyVetoException e) { 225 } 226 } 227 228 232 public abstract void detachWindow(); 233 234 235 240 public int showConfirmDialog(String pMessageText, String pTitle, int pType) { 241 final String messageText = pMessageText; 242 final String title = pTitle; 243 final int type = pType; 244 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 245 246 Runnable runMe = new Runnable () { 247 public void run() { 248 fResponseWrapper.setInt(JOptionPane.showInternalConfirmDialog((JDesktopPane)Pooka.getMainPanel().getContentPanel(), messageText, title, type)); 249 } 250 }; 251 252 if (! SwingUtilities.isEventDispatchThread()) { 253 try { 254 SwingUtilities.invokeAndWait(runMe); 255 } catch (Exception e) { 256 } 257 } else { 258 runMe.run(); 259 } 260 261 return fResponseWrapper.getInt(); 262 } 263 264 269 public int showConfirmDialog(String pMessageText, String pTitle, int pOptionType, int pIconType) { 270 final String messageText = pMessageText; 271 final String title = pTitle; 272 final int optionType = pOptionType; 273 final int iconType = pIconType; 274 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 275 276 Runnable runMe = new Runnable () { 277 public void run() { 278 fResponseWrapper.setInt(JOptionPane.showInternalConfirmDialog((JDesktopPane)Pooka.getMainPanel().getContentPanel(), messageText, title, optionType)); 279 } 280 }; 281 282 if (! SwingUtilities.isEventDispatchThread()) { 283 try { 284 SwingUtilities.invokeAndWait(runMe); 285 } catch (Exception e) { 286 } 287 } else { 288 runMe.run(); 289 } 290 291 return fResponseWrapper.getInt(); 292 } 293 294 299 public void showError(String errorMessage, String title) { 300 Pooka.getUIFactory().showError(errorMessage, title); 301 } 302 303 308 public void showError(String errorMessage) { 309 Pooka.getUIFactory().showError(errorMessage); 310 } 311 312 317 public void showError(String errorMessage, Exception e) { 318 Pooka.getUIFactory().showError(errorMessage, e); 319 } 320 321 326 public void showError(String errorMessage, String title, Exception e) { 327 Pooka.getUIFactory().showError(errorMessage, title, e); 328 } 329 330 333 public String formatMessage(String message) { 334 return Pooka.getUIFactory().formatMessage(message); 335 } 336 337 342 public void showMessageDialog(String pMessage, String pTitle) { 343 final String message = pMessage; 344 final String title = pTitle; 345 346 Runnable runMe = new Runnable () { 347 public void run() { 348 JOptionPane.showInternalMessageDialog((JDesktopPane)Pooka.getMainPanel().getContentPanel(), message, title, JOptionPane.PLAIN_MESSAGE); 349 } 350 }; 351 352 if (! SwingUtilities.isEventDispatchThread()) { 353 try { 354 SwingUtilities.invokeAndWait(runMe); 355 } catch (Exception e) { 356 } 357 } else { 358 runMe.run(); 359 } 360 } 361 362 367 public String showInputDialog(String inputMessage, String title) { 368 return Pooka.getUIFactory().showInputDialog(inputMessage, title); 369 } 370 371 376 public String showInputDialog(Object [] pInputPanes, String pTitle) { 377 final Object [] inputPanes = pInputPanes; 378 final String title = pTitle; 379 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 380 381 Runnable runMe = new Runnable () { 382 public void run() { 383 fResponseWrapper.setString(JOptionPane.showInternalInputDialog((MessagePanel)Pooka.getMainPanel().getContentPanel(), inputPanes, title, JOptionPane.QUESTION_MESSAGE)); 384 385 } 386 }; 387 388 if (! SwingUtilities.isEventDispatchThread()) { 389 try { 390 SwingUtilities.invokeAndWait(runMe); 391 } catch (Exception e) { 392 } 393 } else { 394 runMe.run(); 395 } 396 397 return fResponseWrapper.getString(); 398 } 399 400 404 public void resizeByWidth() { 405 409 this.setSize(this.getPreferredSize()); 410 } 411 412 415 public ProgressDialog createProgressDialog(int min, int max, int initialValue, String title, String content) { 416 return new ProgressInternalDialog(min, max, initialValue, title, content, getParentContainer()); 417 } 418 419 422 public net.suberic.pooka.gui.crypto.CryptoStatusDisplay getCryptoStatusDisplay() { 423 return getMessageDisplay().getCryptoStatusDisplay(); 424 } 425 426 427 428 434 public void setBusy(boolean newValue) { 435 final boolean fNewValue = newValue; 436 Runnable runMe = new Runnable () { 437 public void run() { 438 if (fNewValue) 439 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 440 else 441 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 442 } 443 }; 444 445 if (SwingUtilities.isEventDispatchThread()) { 446 runMe.run(); 447 } else { 448 SwingUtilities.invokeLater(runMe); 449 } 450 } 451 452 455 public void refreshDisplay() throws MessagingException { 456 if (messageDisplay instanceof ReadMessageDisplayPanel) 457 ((ReadMessageDisplayPanel)messageDisplay).resetEditorText(); 458 } 459 460 461 469 470 public UserProfile getDefaultProfile() { 471 return getMessageProxy().getDefaultProfile(); 472 } 473 474 public MessageDisplayPanel getMessageDisplay() { 475 return messageDisplay; 476 } 477 478 public MessageProxy getMessageProxy() { 479 return msg; 480 } 481 482 public void setMessageProxy(MessageProxy newValue) { 483 msg = newValue; 484 } 485 486 public String getMessageText() { 487 return getMessageDisplay().getMessageText(); 488 } 489 490 public String getMessageContentType() { 491 return getMessageDisplay().getMessageContentType(); 492 } 493 494 public AttachmentPane getAttachmentPanel() { 495 return getMessageDisplay().getAttachmentPanel(); 496 } 497 498 public MessagePanel getParentContainer() { 499 return parentContainer; 500 } 501 502 public ConfigurableToolbar getToolbar() { 503 return toolbar; 504 } 505 506 public ConfigurableKeyBinding getKeyBindings() { 507 return keyBindings; 508 } 509 510 public java.util.logging.Logger getLogger() { 511 return java.util.logging.Logger.getLogger("Pooka.debug.gui"); 512 } 513 514 516 public Action [] getActions() { 517 return defaultActions; 518 } 519 520 public Action [] getDefaultActions() { 521 return defaultActions; 522 } 523 524 526 528 public Action [] defaultActions = { 529 new CloseAction(), 530 new DetachAction() 531 }; 532 533 class CloseAction extends AbstractAction { 534 535 CloseAction() { 536 super("file-close"); 537 } 538 539 public void actionPerformed(ActionEvent e) { 540 closeMessageUI(); 541 } 542 } 543 544 class DetachAction extends AbstractAction { 545 DetachAction() { 546 super("window-detach"); 547 } 548 549 public void actionPerformed(ActionEvent e) { 550 detachWindow(); 551 } 552 } 553 } 554 555 556 557 558 559 | Popular Tags |