1 package net.suberic.pooka.gui; 2 import java.awt.CardLayout ; 3 import javax.swing.*; 4 import net.suberic.pooka.*; 5 import net.suberic.util.swing.*; 6 import java.io.IOException ; 7 import java.util.HashMap ; 8 import net.suberic.pooka.Pooka; 9 import net.suberic.util.gui.*; 10 import java.awt.BorderLayout ; 11 import java.awt.event.ActionEvent ; 12 import javax.swing.event.ListSelectionListener ; 13 import javax.swing.plaf.metal.MetalTheme ; 14 15 19 public class PreviewContentPanel extends JPanel implements ContentPanel, MessageUI, ThemeSupporter, ThemeListener { 20 21 private JPanel folderDisplay = null; 22 private ReadMessageDisplayPanel messageDisplay; 23 private JPanel messageCardPanel; 24 25 private JSplitPane splitPanel; 26 27 private PreviewFolderPanel current = null; 28 29 HashMap cardTable = new HashMap (); 30 31 private ListSelectionListener selectionListener; 32 33 protected javax.swing.plaf.metal.MetalTheme currentTheme = null; 34 35 private boolean savingOpenFolders; 36 37 40 public PreviewContentPanel() { 41 folderDisplay = new JPanel(); 42 folderDisplay.setLayout(new CardLayout ()); 43 folderDisplay.add("emptyPanel", new JPanel()); 44 45 messageDisplay = new ReadMessageDisplayPanel(); 46 47 try { 48 messageDisplay.configureMessageDisplay(); 49 } catch (javax.mail.MessagingException me) { 50 } 52 53 splitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, folderDisplay, messageDisplay); 54 55 56 this.setLayout(new BorderLayout ()); 57 58 this.add("Center", splitPanel); 59 60 splitPanel.setDividerLocation(Integer.parseInt(Pooka.getProperty("Pooka.contentPanel.dividerLocation", "200"))); 61 62 selectionListener = new ListSelectionListener () { 63 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 64 if (! e.getValueIsAdjusting()) 65 selectedMessageChanged(); 66 } 67 }; 68 69 this.setSavingOpenFolders(Pooka.getProperty("Pooka.saveOpenFoldersOnExit", "false").equalsIgnoreCase("true")); 70 71 74 this.addFocusListener(new java.awt.event.FocusAdapter () { 75 public void focusGained(java.awt.event.FocusEvent e) { 76 if (current != null) { 77 current.requestFocusInWindow(); 78 } 79 } 80 }); 81 } 82 83 86 public PreviewContentPanel(MessagePanel mp) { 87 this(); 88 89 91 JInternalFrame[] frames = mp.getAllFrames(); 92 93 String selectedID = null; 94 95 for (int i = 0; i < frames.length; i++) { 96 if (frames[i] instanceof FolderInternalFrame) { 97 PreviewFolderPanel newPP = new PreviewFolderPanel(this, (FolderInternalFrame) frames[i]); 98 net.suberic.pooka.FolderInfo fi = newPP.getFolderInfo(); 99 String folderID = fi.getFolderID(); 100 fi.setFolderDisplayUI(newPP); 101 addPreviewPanel(newPP, folderID); 102 if (frames[i].isSelected()) { 103 selectedID = folderID; 104 } else if (selectedID == null) { 105 selectedID = folderID; 107 } 108 } else if (frames[i] instanceof MessageInternalFrame) { 109 if (frames[i].isSelected()) { 110 if (frames[i] instanceof ReadMessageInternalFrame) { 111 selectedID = ((ReadMessageInternalFrame) frames[i]).getMessageProxy().getMessageInfo().getFolderInfo().getFolderID(); 112 } 113 } 114 ((MessageInternalFrame) frames[i]).detachWindow(); 115 } 116 } 117 118 if (selectedID != null) 119 showFolder(selectedID); 120 } 121 122 125 public void configureInterfaceStyle() { 126 Runnable runMe = new Runnable () { 127 public void run() { 128 try { 129 Pooka.getUIFactory().getPookaThemeManager().updateUI(PreviewContentPanel.this, PreviewContentPanel.this); 130 getMessageDisplay().setDefaultFont(); 131 getMessageDisplay().sizeToDefault(); 132 } catch (Exception e) { 133 } 134 } 135 }; 136 137 if (! SwingUtilities.isEventDispatchThread()) { 138 SwingUtilities.invokeLater(runMe); 139 } else { 140 runMe.run(); 141 } 142 } 143 144 147 public MetalTheme getCurrentTheme() { 148 return currentTheme; 149 } 150 151 154 public void setCurrentTheme(MetalTheme newTheme) { 155 if (currentTheme != null && currentTheme instanceof ConfigurableMetalTheme) { 156 ((ConfigurableMetalTheme)currentTheme).removeThemeListener(this); 157 } 158 currentTheme = newTheme; 159 160 if (currentTheme != null && currentTheme instanceof ConfigurableMetalTheme) { 161 ((ConfigurableMetalTheme)currentTheme).addThemeListener(this); 162 } 163 } 164 165 168 public void themeChanged(ConfigurableMetalTheme theme) { 169 if (currentTheme != null && currentTheme == theme) { 172 Runnable r = new Runnable () { 173 public void run() { 174 try { 175 Pooka.getUIFactory().getPookaThemeManager().updateUI(PreviewContentPanel.this, PreviewContentPanel.this, true); 176 getMessageDisplay().setDefaultFont(); 177 } catch (Exception e) { 178 } 179 180 } 181 }; 182 if (SwingUtilities.isEventDispatchThread()) { 183 r.run(); 184 } else { 185 SwingUtilities.invokeLater(r); 186 } 187 } 188 } 189 190 191 195 public MetalTheme getTheme(ThemeManager tm) { 196 MessageProxy mp = getMessageProxy(); 197 if (mp == null) { 198 return tm.getDefaultTheme(); 199 } 200 201 MessageInfo mi = mp.getMessageInfo(); 202 if (mi == null) { 203 return tm.getDefaultTheme(); 204 } 205 206 FolderInfo fi = mi.getFolderInfo(); 207 if (fi != null) { 208 String id = Pooka.getProperty(fi.getFolderProperty() + ".theme", ""); 209 if (id != null && ! id.equals("")) { 210 return tm.getTheme(id); 211 } 212 } 213 214 return tm.getDefaultTheme(); 215 216 } 217 218 219 223 public void savePanelSize() { 224 Pooka.setProperty("Pooka.contentPanel.dividerLocation", Integer.toString(splitPanel.getDividerLocation())); 225 } 226 227 230 public void showFolder(String folderId) { 231 if (current != null) { 232 current.getFolderDisplay().getMessageTable().getSelectionModel().removeListSelectionListener(selectionListener); 233 } 234 current = (PreviewFolderPanel) cardTable.get(folderId); 235 236 ((CardLayout )folderDisplay.getLayout()).show(folderDisplay, folderId); 237 if (current != null) { 238 current.getFolderDisplay().getMessageTable().getSelectionModel().addListSelectionListener(selectionListener); 239 } 240 241 selectedMessageChanged(); 242 folderDisplay.repaint(); 243 selectFolderDisplay(); 244 } 245 246 249 public void selectedMessageChanged() { 250 if (getAutoPreview()) { 251 refreshCurrentMessage(); 252 } else { 253 clearCurrentMessage(); 254 } 255 Pooka.getMainPanel().refreshActiveMenus(); 256 refreshCurrentUser(); 257 } 258 259 262 public void refreshCurrentMessage() { 263 if (current != null) { 264 final MessageProxy mp = current.getFolderDisplay().getSelectedMessage(); 265 if (! (mp instanceof MultiMessageProxy)) { 266 if (current != null) { 267 current.getFolderInfo().getFolderThread().addToQueue(new javax.swing.AbstractAction () { 268 public void actionPerformed(java.awt.event.ActionEvent ae) { 269 messageDisplay.setMessageUI(PreviewContentPanel.this); 270 try { 271 refreshDisplay(); 272 if (mp != null && mp.getMessageInfo() != null) 273 mp.getMessageInfo().setSeen(true); 274 } catch (javax.mail.MessagingException me) { 275 } 277 } 278 }, new java.awt.event.ActionEvent (this, 0, "message-refresh")); 279 } 280 } 281 } 282 } 283 284 287 public void clearCurrentMessage() { 288 messageDisplay.setMessageUI(null); 289 try { 290 refreshDisplay(); 291 } catch (Exception e) { 292 } 294 } 295 296 299 public void addPreviewPanel(PreviewFolderPanel newPanel, String folderId) { 300 cardTable.put(folderId, newPanel); 301 folderDisplay.add(newPanel, folderId); 302 } 303 304 307 public void removePreviewPanel(String folderId) { 308 PreviewFolderPanel panel = (PreviewFolderPanel)cardTable.get(folderId); 309 if (panel != null) { 310 if (panel == current) 311 current = null; 312 folderDisplay.remove(panel); 313 cardTable.remove(folderId); 314 } 315 } 316 317 318 325 public void openSavedFolders(java.util.Vector folderList) { 326 if (folderList != null && folderList.size() > 0) { 327 net.suberic.pooka.FolderInfo fInfo = Pooka.getStoreManager().getFolderById((String )folderList.elementAt(0)); 328 if (fInfo != null && fInfo.getFolderNode() != null) { 329 FolderNode fNode = fInfo.getFolderNode(); 330 fNode.makeVisible(); 331 Action a = fNode.getAction("file-open"); 332 a.actionPerformed(new java.awt.event.ActionEvent (this, 0, "file-open")); 333 } 334 } 335 } 336 337 340 public void saveOpenFolders() { 341 if (current != null && current.getFolderInfo() != null) { 342 String folderId = current.getFolderInfo().getFolderID(); 343 Pooka.setProperty("Pooka.openFolderList", folderId); 344 } 345 } 346 347 350 public boolean isSavingOpenFolders() { 351 return savingOpenFolders; 352 } 353 354 357 public void setSavingOpenFolders(boolean newValue) { 358 savingOpenFolders=newValue; 359 } 360 361 368 public javax.swing.JComponent getUIComponent() { 369 return this; 370 } 371 372 379 public void setUIComponent(javax.swing.JComponent comp) { 380 } 382 383 388 public void showHelpScreen(String title, java.net.URL url) { 389 JFrame jf = new JFrame(title); 390 JEditorPane jep = new JEditorPane(); 391 try { 392 jep.setPage(url); 393 } catch (IOException ioe) { 394 jep.setText(Pooka.getProperty("err.noHelpPage", "No help available.")); 395 } 396 jep.setEditable(false); 397 jf.setSize(500,500); 398 jf.getContentPane().add(new JScrollPane(jep)); 399 jf.setVisible(true); 400 } 401 402 405 public void selectFolderDisplay() { 406 if (current != null) 407 current.requestFocusInWindow(); 408 } 409 410 413 public void selectMessageDisplay() { 414 messageDisplay.requestFocusInWindow(); 415 } 416 417 420 public PreviewFolderPanel getCurrentPanel() { 421 return current; 422 } 423 424 427 public void refreshActiveMenus() { 428 } 433 434 437 public void refreshCurrentUser() { 438 Pooka.getMainPanel().refreshCurrentUser(); 439 } 440 441 444 public MessageProxy getMessageProxy() { 445 if (current != null && current.getFolderDisplay() != null) 446 return current.getFolderDisplay().getSelectedMessage(); 447 else 448 return null; 449 } 450 451 454 public void openMessageUI() { 455 } 457 458 461 public void closeMessageUI() { 462 } 464 465 468 public net.suberic.util.swing.ProgressDialog createProgressDialog(int min, int max, int initialValue, String title, String content) { 469 return Pooka.getUIFactory().createProgressDialog(min, max, initialValue, title, content); 470 } 471 472 475 public net.suberic.pooka.gui.crypto.CryptoStatusDisplay getCryptoStatusDisplay() { 476 return getMessageDisplay().getCryptoStatusDisplay(); 477 } 478 479 public void setBusy(boolean newValue) { 480 } 482 483 public void setEnabled(boolean newValue) { 484 } 486 487 490 public void refreshDisplay() throws javax.mail.MessagingException { 491 configureInterfaceStyle(); 492 messageDisplay.resetEditorText(); 493 494 java.awt.Component fOwner = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 495 if (fOwner != null && messageDisplay != null && SwingUtilities.isDescendingFrom(fOwner, messageDisplay) && messageDisplay.getMessageUI() == null) { 496 if (current != null) { 497 current.requestFocusInWindow(); 498 } 499 } 500 } 501 502 public boolean getAutoPreview() { 503 return (Pooka.getProperty("Pooka.autoPreview", "true").equalsIgnoreCase("true")); 504 } 505 506 511 public int showConfirmDialog(String pMessageText, String pTitle, int pType) { 512 final String messageText = pMessageText; 513 final String title = pTitle; 514 final int type = pType; 515 516 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 517 Runnable runMe = new Runnable () { 518 public void run() { 519 fResponseWrapper.setInt(JOptionPane.showConfirmDialog(PreviewContentPanel.this, messageText, title, type)); 520 } 521 }; 522 523 if (! SwingUtilities.isEventDispatchThread()) { 524 try { 525 SwingUtilities.invokeAndWait(runMe); 526 } catch (Exception e) { 527 } 528 } else { 529 runMe.run(); 530 } 531 532 return fResponseWrapper.getInt(); 533 } 534 535 540 public int showConfirmDialog(String pMessageText, String pTitle, int pOptionType, int pIconType) { 541 final String messageText = pMessageText; 542 final String title = pTitle; 543 final int optionType = pOptionType; 544 final int iconType = pIconType; 545 546 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 547 Runnable runMe = new Runnable () { 548 public void run() { 549 fResponseWrapper.setInt(JOptionPane.showConfirmDialog(PreviewContentPanel.this, messageText, title, optionType, iconType)); 550 } 551 }; 552 553 if (! SwingUtilities.isEventDispatchThread()) { 554 try { 555 SwingUtilities.invokeAndWait(runMe); 556 } catch (Exception e) { 557 } 558 } else { 559 runMe.run(); 560 } 561 562 return fResponseWrapper.getInt(); 563 } 564 565 570 public void showError(String pErrorMessage, String pTitle) { 571 final String errorMessage = pErrorMessage; 572 final String title = pTitle; 573 574 Runnable runMe = new Runnable () { 575 public void run() { 576 JOptionPane.showMessageDialog(PreviewContentPanel.this, errorMessage, title, JOptionPane.ERROR_MESSAGE); 577 } 578 }; 579 580 if (! SwingUtilities.isEventDispatchThread()) { 581 try { 582 SwingUtilities.invokeAndWait(runMe); 583 } catch (Exception e) { 584 } 585 } else { 586 runMe.run(); 587 } 588 } 589 590 595 public void showError(String errorMessage) { 596 showError(errorMessage, Pooka.getProperty("Error", "Error")); 597 } 598 599 604 public void showError(String errorMessage, Exception e) { 605 showError(errorMessage, Pooka.getProperty("Error", "Error"), e); 606 } 607 608 613 public void showError(String errorMessage, String title, Exception e) { 614 showError(errorMessage + e.getMessage(), title); 615 e.printStackTrace(); 616 } 617 618 621 public String formatMessage(String message) { 622 return Pooka.getUIFactory().formatMessage(message); 623 } 624 625 630 public String showInputDialog(String pInputMessage, String pTitle) { 631 final String inputMessage = pInputMessage; 632 final String title = pTitle; 633 634 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 635 Runnable runMe = new Runnable () { 636 public void run() { 637 fResponseWrapper.setString(JOptionPane.showInputDialog(PreviewContentPanel.this, inputMessage, title, JOptionPane.QUESTION_MESSAGE)); 638 } 639 }; 640 641 if (! SwingUtilities.isEventDispatchThread()) { 642 try { 643 SwingUtilities.invokeAndWait(runMe); 644 } catch (Exception e) { 645 } 646 } else { 647 runMe.run(); 648 } 649 650 return fResponseWrapper.getString(); 651 } 652 653 658 public String showInputDialog(Object [] pInputPanes, String pTitle) { 659 final Object [] inputPanes = pInputPanes; 660 final String title = pTitle; 661 662 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 663 Runnable runMe = new Runnable () { 664 public void run() { 665 fResponseWrapper.setString(JOptionPane.showInputDialog(PreviewContentPanel.this, inputPanes, title, JOptionPane.QUESTION_MESSAGE)); 666 } 667 }; 668 669 if (! SwingUtilities.isEventDispatchThread()) { 670 try { 671 SwingUtilities.invokeAndWait(runMe); 672 } catch (Exception e) { 673 } 674 } else { 675 runMe.run(); 676 } 677 678 return fResponseWrapper.getString(); 679 680 } 681 682 687 public void showMessageDialog(String message, String title) { 688 JOptionPane.showMessageDialog(this, message, title, JOptionPane.PLAIN_MESSAGE); 689 } 690 691 694 public PookaUIFactory getPookaUIFactory() { 695 return Pooka.getUIFactory(); 696 } 697 698 701 public ReadMessageDisplayPanel getMessageDisplay() { 702 return messageDisplay; 703 } 704 705 public Action[] defaultActions = { 706 new NextWindowAction(), 707 new PreviousWindowAction() 708 }; 709 710 public Action[] getDefaultActions() { 711 return defaultActions; 712 } 713 714 715 718 public Action[] getActions() { 719 Action[] returnValue = getDefaultActions(); 720 721 if (current != null && current.getActions() != null) { 722 returnValue = javax.swing.text.TextAction.augmentList(returnValue, current.getActions()); 723 } 724 725 if (returnValue == null) 726 return messageDisplay.getActions(); 727 else { 728 if (messageDisplay.getActions() != null) 729 return javax.swing.text.TextAction.augmentList(returnValue, messageDisplay.getActions()); 730 else 731 return returnValue; 732 } 733 } 734 735 738 public UserProfile getDefaultProfile() { 739 if (current != null) 740 return current.getDefaultProfile(); 741 else if (messageDisplay != null) 742 return messageDisplay.getDefaultProfile(); 743 else 744 return null; 745 } 746 747 public HashMap getCardTable() { 748 return cardTable; 749 } 750 751 public ListSelectionListener getSelectionListener() { 752 return selectionListener; 753 } 754 755 756 public class NextWindowAction extends AbstractAction { 757 NextWindowAction() { 758 super("window-next"); 759 } 760 761 public void actionPerformed(ActionEvent e) { 762 selectFolderDisplay(); 763 } 764 } 765 766 public class PreviousWindowAction extends AbstractAction { 767 PreviousWindowAction() { 768 super("window-previous"); 769 } 770 771 public void actionPerformed(ActionEvent e) { 772 selectMessageDisplay(); 773 } 774 } 775 776 777 778 } 779 780 | Popular Tags |