1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.*; 3 import javax.mail.*; 4 import javax.mail.internet.MimeMessage ; 5 import javax.mail.event.*; 6 import java.awt.*; 7 import java.awt.event.*; 8 import javax.swing.*; 9 import javax.swing.table.*; 10 import javax.swing.text.TextAction ; 11 import java.util.*; 12 import net.suberic.util.gui.*; 13 import net.suberic.util.event.*; 14 import net.suberic.util.thread.*; 15 import net.suberic.util.swing.*; 16 17 22 23 public class PreviewFolderPanel extends JPanel implements FolderDisplayUI { 24 25 private PreviewContentPanel contentPanel; 26 27 private FolderDisplayPanel folderDisplay = null; 28 private FolderInfo displayedFolder = null; 29 30 33 ConfigurableKeyBinding keyBindings; 34 35 private boolean enabled; 36 37 private Action [] defaultActions; 38 39 42 public PreviewFolderPanel(PreviewContentPanel newContentPanel) { 43 contentPanel = newContentPanel; 44 45 this.setSize(new java.awt.Dimension (newContentPanel.getSize().width, Integer.parseInt(Pooka.getProperty("Pooka.previewPanel.folderSize", "200")))); 46 this.setPreferredSize(new java.awt.Dimension (newContentPanel.getSize().width, Integer.parseInt(Pooka.getProperty("Pooka.contentPanel.dividerLocation", "200")))); 47 48 folderDisplay = new FolderDisplayPanel(); 49 50 } 51 52 55 public PreviewFolderPanel(PreviewContentPanel newContentPanel, FolderInfo folder) { 56 contentPanel = newContentPanel; 57 58 displayedFolder = folder; 59 folderDisplay = new FolderDisplayPanel(folder, false); 60 61 configurePanel(); 62 } 63 64 67 public PreviewFolderPanel(PreviewContentPanel newContentPanel, FolderInternalFrame fif) { 68 contentPanel = newContentPanel; 69 70 displayedFolder = fif.getFolderInfo(); 71 folderDisplay = fif.getFolderDisplay(); 72 73 configurePanel(); 74 } 75 76 79 void configurePanel() { 80 81 this.setSize(contentPanel.getSize()); 82 83 85 this.setLayout(new java.awt.BorderLayout ()); 86 87 96 97 this.add("Center", folderDisplay); 99 101 defaultActions = new Action [] { 102 new ActionWrapper(new ExpungeAction(), getFolderInfo().getFolderThread()), 103 new NextMessageAction(), 104 new PreviousMessageAction(), 105 new GotoMessageAction(), 106 new SearchAction(), 107 new SelectAllAction(), 108 new PreviewMessageAction() 109 }; 110 111 keyBindings = new ConfigurableKeyBinding(this, "PreviewFolderWindow.keyBindings", Pooka.getResources()); 112 113 keyBindings.setActive(getActions()); 114 115 118 this.addFocusListener(new FocusAdapter() { 119 public void focusGained(FocusEvent e) { 120 if (folderDisplay != null) { 121 folderDisplay.requestFocusInWindow(); 122 } 123 } 124 }); 125 126 getFolderDisplay().getMessageTable().getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener () { 127 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 128 if (enabled) { 129 if (keyBindings != null) { 130 keyBindings.setActive(getActions()); 131 } 132 } 133 } 134 }); 135 } 136 137 141 public void searchFolder() { 142 getFolderInfo().showSearchFolder(); 143 } 144 145 150 public void openFolderDisplay() { 151 openFolderDisplay(true); 152 } 153 154 160 public void openFolderDisplay(boolean selected) { 161 Runnable runMe = new Runnable () { 162 public void run() { 163 if (displayedFolder != null) 164 contentPanel.showFolder(displayedFolder.getFolderID()); 165 setEnabled(true); 166 } 167 }; 168 if (SwingUtilities.isEventDispatchThread()) 169 runMe.run(); 170 else 171 SwingUtilities.invokeLater(runMe); 172 173 } 174 175 180 public void closeFolderDisplay() { 181 contentPanel.removePreviewPanel(getFolderInfo().getFolderID()); 182 folderDisplay.removeMessageTable(); 183 if (displayedFolder != null && displayedFolder.getFolderDisplayUI() == this) 184 displayedFolder.setFolderDisplayUI(null); 185 displayedFolder = null; 186 setEnabled(false); 187 } 188 189 192 public void expungeMessages() { 193 try { 194 getFolderInfo().getFolder().expunge(); 195 } catch (MessagingException me) { 196 showError(Pooka.getProperty("error.Message.ExpungeErrorMessage", "Error: could not expunge messages.") +"\n" + me.getMessage()); 197 } 198 } 199 200 205 public FolderInfo getFolderInfo() { 206 return displayedFolder; 207 } 208 209 212 public void setFolderInfo(FolderInfo fi) { 213 getFolderDisplay().removeMessageTable(); 214 getFolderDisplay().setFolderInfo(fi); 215 getFolderDisplay().createMessageTable(); 216 217 displayedFolder = fi; 218 219 } 220 221 226 public void setEnabled(boolean newValue) { 227 enabled = newValue; 228 229 if (keyBindings != null) 230 keyBindings.setActive(getActions()); 231 } 232 233 238 public int selectMessage(int messageNumber) { 239 return getFolderDisplay().selectMessage(messageNumber); 240 } 241 242 247 public void makeSelectionVisible(int messageNumber) { 248 getFolderDisplay().makeSelectionVisible(messageNumber); 249 } 250 251 public int selectNextMessage() { 252 return getFolderDisplay().selectNextMessage(); 253 } 254 255 public int selectPreviousMessage() { 256 return getFolderDisplay().selectPreviousMessage(); 257 } 258 259 public int selectNextUnreadMessage() { 260 return getFolderDisplay().selectNextUnreadMessage(); 261 } 262 263 268 public void resetFolderTableModel(FolderTableModel ftm) { 269 getFolderDisplay().resetFolderTableModel(ftm); 270 } 271 272 276 public void showStatusMessage(String msg) { 277 Pooka.getUIFactory().showStatusMessage(getFolderInfo().getFolderID() + ": " + msg); 278 } 279 280 284 public void clearStatusMessage() { 285 Pooka.getUIFactory().clearStatus(); 286 } 287 288 293 public void setBusy(boolean newValue) { 294 final boolean newV = newValue; 295 Runnable runMe = new Runnable () { 296 public void run() { 297 if (newV) 298 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 299 else 300 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 301 } 302 }; 303 304 if (SwingUtilities.isEventDispatchThread()) 305 runMe.run(); 306 else 307 SwingUtilities.invokeLater(runMe); 308 309 } 310 311 316 public String showInputDialog(String pInputMessage, String pTitle) { 317 final String inputMessage = pInputMessage; 318 final String title = pTitle; 319 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 320 321 Runnable runMe = new Runnable () { 322 public void run() { 323 fResponseWrapper.setString(JOptionPane.showInputDialog(PreviewFolderPanel.this, inputMessage, title, JOptionPane.QUESTION_MESSAGE)); 324 } 325 }; 326 327 if (! SwingUtilities.isEventDispatchThread()) { 328 try { 329 SwingUtilities.invokeAndWait(runMe); 330 } catch (Exception e) { 331 } 332 } else { 333 runMe.run(); 334 } 335 336 return fResponseWrapper.getString(); 337 } 338 339 344 public String showInputDialog(Object [] pInputPanels, String pTitle) { 345 final Object [] inputPanels= pInputPanels; 346 final String title = pTitle; 347 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 348 349 Runnable runMe = new Runnable () { 350 public void run() { 351 fResponseWrapper.setString(JOptionPane.showInputDialog(PreviewFolderPanel.this, inputPanels, title, JOptionPane.QUESTION_MESSAGE)); 352 } 353 }; 354 355 if (! SwingUtilities.isEventDispatchThread()) { 356 try { 357 SwingUtilities.invokeAndWait(runMe); 358 } catch (Exception e) { 359 } 360 } else { 361 runMe.run(); 362 } 363 364 return fResponseWrapper.getString(); 365 } 366 367 372 public int showConfirmDialog(String message, String title, int optionType, int messageType) { 373 return JOptionPane.showConfirmDialog(this, message, title, messageType); 374 } 375 376 381 public UserProfile getDefaultProfile() { 382 if (getFolderInfo() != null) 383 return getFolderInfo().getDefaultProfile(); 384 else return null; 385 } 386 387 392 public void showError(String errorMessage) { 393 showError(errorMessage, Pooka.getProperty("Error", "Error")); 394 } 395 396 401 public void showError(String errorMessage, Exception e) { 402 showError(errorMessage, Pooka.getProperty("Error", "Error"), e); 403 } 404 405 410 public void showError(String errorMessage, String title) { 411 final String errorMsg = errorMessage; 412 final String realTitle = title; 413 Runnable runMe = new Runnable () { 414 public void run() { 415 416 JOptionPane.showMessageDialog(PreviewFolderPanel.this, errorMsg, realTitle, JOptionPane.ERROR_MESSAGE); 417 } 418 }; 419 420 if (SwingUtilities.isEventDispatchThread()) { 421 runMe.run(); 422 } else { 423 SwingUtilities.invokeLater(runMe); 424 } 425 426 } 427 428 433 public void showError(String errorMessage, String title, Exception e) { 434 showError(errorMessage + e.getMessage(), title); 435 e.printStackTrace(); 436 } 437 438 441 public String formatMessage(String message) { 442 return Pooka.getUIFactory().formatMessage(message); 443 } 444 445 447 451 public void handleMessageLoaded(net.suberic.pooka.event.MessageLoadedEvent e) { 452 456 } 457 458 460 463 public void closed(ConnectionEvent e) { 464 465 } 466 467 470 public void disconnected(ConnectionEvent e) { 471 472 } 473 474 477 public void opened(ConnectionEvent e) { 478 479 } 480 481 485 public void messagesAdded(MessageCountEvent e) { 486 } 488 489 493 public void messagesRemoved(MessageCountEvent e) { 494 496 Runnable updateAdapter = new Runnable () { 497 public void run() { 498 Pooka.getMainPanel().refreshActiveMenus(); 499 } 500 }; 501 if (SwingUtilities.isEventDispatchThread()) 502 updateAdapter.run(); 503 else 504 SwingUtilities.invokeLater(updateAdapter); 505 506 } 507 508 public void messageChanged(MessageChangedEvent e) { 510 514 if (getFolderDisplay() != null) 515 getFolderDisplay().moveSelectionOnRemoval(e); 516 517 final MessageInfo mi = getFolderInfo().getMessageInfo(e.getMessage()); 518 if (mi != null) { 519 SwingUtilities.invokeLater(new Runnable () { 520 public void run() { 521 getFolderDisplay().repaintMessage(mi.getMessageProxy()); 525 } 526 }); 527 } 528 } 529 530 534 public void removeRows(java.util.Vector removedProxies) { 535 getFolderDisplay().removeRows(removedProxies); 536 } 537 538 541 546 547 550 555 556 561 public Action [] getActions() { 562 if (enabled) { 563 Action [] returnValue = defaultActions; 564 565 if (getFolderDisplay() != null) { 566 if (returnValue == null) { 567 returnValue = getFolderDisplay().getActions(); 568 } else { 569 returnValue = TextAction.augmentList(returnValue, getFolderDisplay().getActions()); 570 } 571 } 572 573 return returnValue; 574 575 } else { 576 return null; 577 } 578 } 579 580 public FolderDisplayPanel getFolderDisplay() { 581 return folderDisplay; 582 } 583 584 public class ExpungeAction extends AbstractAction { 585 586 ExpungeAction() { 587 super("message-expunge"); 588 } 589 590 public void actionPerformed(ActionEvent e) { 591 594 if (displayedFolder != null) { 595 displayedFolder.getFolderThread().addToQueue(new AbstractAction() { 596 public void actionPerformed(ActionEvent e) { 597 expungeMessages(); 598 599 } 600 }, e); 601 } 602 603 } 604 } 605 606 public class NextMessageAction extends AbstractAction { 607 608 NextMessageAction() { 609 super("message-next"); 610 } 611 612 public void actionPerformed(ActionEvent e) { 613 selectNextMessage(); 614 } 615 } 616 617 public class PreviousMessageAction extends AbstractAction { 618 619 PreviousMessageAction() { 620 super("message-previous"); 621 } 622 623 public void actionPerformed(ActionEvent e) { 624 selectPreviousMessage(); 625 } 626 } 627 628 public class NextUnreadMessageAction extends AbstractAction { 629 630 NextUnreadMessageAction() { 631 super("message-next-unread"); 632 } 633 634 public void actionPerformed(ActionEvent e) { 635 selectNextUnreadMessage(); 636 } 637 } 638 639 public class GotoMessageAction extends AbstractAction { 640 641 GotoMessageAction() { 642 super("message-goto"); 643 } 644 645 public void actionPerformed(ActionEvent e) { 646 } 648 } 649 650 public class SearchAction extends AbstractAction { 651 652 SearchAction() { 653 super("folder-search"); 654 } 655 656 public void actionPerformed(ActionEvent e) { 657 searchFolder(); 658 } 659 } 660 661 public class SelectAllAction extends AbstractAction { 662 663 SelectAllAction() { 664 super("select-all"); 665 } 666 667 public void actionPerformed(ActionEvent e) { 668 getFolderDisplay().selectAll(); 669 } 670 } 671 672 public class PreviewMessageAction extends AbstractAction { 673 PreviewMessageAction() { 674 super("message-preview"); 675 } 676 677 public void actionPerformed(ActionEvent e) { 678 contentPanel.refreshCurrentMessage(); 679 } 680 } 681 682 } 683 684 | Popular Tags |