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.text.TextAction ; 11 import java.util.*; 12 import javax.swing.text.JTextComponent ; 13 import javax.swing.event.*; 14 import java.io.File ; 15 import javax.swing.plaf.metal.MetalTheme ; 16 17 18 21 public abstract class MessageFrame extends JFrame implements MessageUI, ThemeSupporter, ThemeListener { 22 23 protected MessageProxy msg; 24 protected MessageDisplayPanel messageDisplay; 25 26 protected ConfigurableToolbar toolbar; 27 protected ConfigurableKeyBinding keyBindings; 28 protected ConfigurableMenuBar menuBar; 29 30 protected javax.swing.plaf.metal.MetalTheme currentTheme = null; 31 32 35 36 public MessageFrame(MessageProxy newMsgProxy) { 37 super(Pooka.getProperty("Pooka.messageInternalFrame.messageTitle.newMessage", "New Message")); 38 39 msg=newMsgProxy; 40 41 this.getContentPane().setLayout(new BorderLayout()); 42 43 java.net.URL standardUrl = this.getClass().getResource(Pooka.getProperty("Pooka.standardIcon", "images/PookaIcon.gif")); 44 if (standardUrl != null) { 45 ImageIcon standardIcon = new ImageIcon(standardUrl); 46 setIconImage(standardIcon.getImage()); 47 } 48 49 this.addFocusListener(new FocusAdapter() { 50 public void focusGained(FocusEvent e) { 51 if (getMessageDisplay() != null) 52 getMessageDisplay().requestFocusInWindow(); 53 } 54 }); 55 56 57 } 58 59 protected MessageFrame() { 60 this.getContentPane().setLayout(new BorderLayout()); 61 62 java.net.URL standardUrl = this.getClass().getResource(Pooka.getProperty("Pooka.standardIcon", "images/PookaIcon.gif")); 63 if (standardUrl != null) { 64 ImageIcon standardIcon = new ImageIcon(standardUrl); 65 setIconImage(standardIcon.getImage()); 66 } 67 68 this.addFocusListener(new FocusAdapter() { 69 public void focusGained(FocusEvent e) { 70 if (getMessageDisplay() != null) 71 getMessageDisplay().requestFocusInWindow(); 72 } 73 }); 74 75 } 76 77 81 82 protected abstract void configureMessageFrame(); 83 84 87 public void configureInterfaceStyle() { 88 Runnable runMe = new Runnable () { 89 public void run() { 90 try { 91 Pooka.getUIFactory().getPookaThemeManager().updateUI(MessageFrame.this, MessageFrame.this); 92 getMessageDisplay().setDefaultFont(); 93 getMessageDisplay().sizeToDefault(); 94 MessageFrame.this.setSize(MessageFrame.this.getPreferredSize()); 95 } catch (Exception e) { 96 } 97 } 98 }; 99 100 if (! SwingUtilities.isEventDispatchThread()) { 101 SwingUtilities.invokeLater(runMe); 102 } else { 103 runMe.run(); 104 } 105 } 106 107 110 public MetalTheme getCurrentTheme() { 111 return currentTheme; 112 } 113 114 117 public void setCurrentTheme(MetalTheme newTheme) { 118 if (currentTheme != null && currentTheme instanceof ConfigurableMetalTheme) { 119 ((ConfigurableMetalTheme)currentTheme).removeThemeListener(this); 120 } 121 currentTheme = newTheme; 122 123 if (currentTheme != null && currentTheme instanceof ConfigurableMetalTheme) { 124 ((ConfigurableMetalTheme)currentTheme).addThemeListener(this); 125 } 126 } 127 128 131 public void themeChanged(ConfigurableMetalTheme theme) { 132 if (currentTheme != null && currentTheme == theme) { 135 SwingUtilities.invokeLater(new Runnable () { 136 public void run() { 137 try { 138 Pooka.getUIFactory().getPookaThemeManager().updateUI(MessageFrame.this, MessageFrame.this, true); 139 getMessageDisplay().setDefaultFont(); 140 getMessageDisplay().sizeToDefault(); 141 MessageFrame.this.setSize(MessageFrame.this.getPreferredSize()); 142 } catch (Exception e) { 143 } 144 145 } 146 }); 147 } 148 } 149 150 153 public void openMessageUI() { 154 this.setVisible(true); 155 } 156 157 160 public void closeMessageUI() { 161 this.dispose(); 162 } 163 164 167 public abstract void attachWindow(); 168 169 174 public int showConfirmDialog(String pMessageText, String pTitle, int pType) { 175 final String messageText = pMessageText; 176 final String title = pTitle; 177 final int type = pType; 178 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 179 180 Runnable runMe = new Runnable () { 181 public void run() { 182 fResponseWrapper.setInt(JOptionPane.showConfirmDialog(MessageFrame.this, messageText, title, type)); 183 } 184 }; 185 186 if (! SwingUtilities.isEventDispatchThread()) { 187 try { 188 SwingUtilities.invokeAndWait(runMe); 189 } catch (Exception e) { 190 } 191 } else { 192 runMe.run(); 193 } 194 195 return fResponseWrapper.getInt(); 196 } 197 198 203 public int showConfirmDialog(String pMessageText, String pTitle, int pOptionType, int pIconType) { 204 final String messageText = pMessageText; 205 final String title = pTitle; 206 final int optionType = pOptionType; 207 final int iconType = pIconType; 208 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 209 210 Runnable runMe = new Runnable () { 211 public void run() { 212 fResponseWrapper.setInt(JOptionPane.showConfirmDialog(MessageFrame.this, messageText, title, optionType, iconType)); 213 } 214 }; 215 216 if (! SwingUtilities.isEventDispatchThread()) { 217 try { 218 SwingUtilities.invokeAndWait(runMe); 219 } catch (Exception e) { 220 } 221 } else { 222 runMe.run(); 223 } 224 225 return fResponseWrapper.getInt(); 226 } 227 228 233 public void showError(String pErrorMessage, String pTitle) { 234 final String errorMessage = pErrorMessage; 235 final String title = pTitle; 236 237 Runnable runMe = new Runnable () { 238 public void run() { 239 JOptionPane.showMessageDialog(MessageFrame.this, errorMessage, title, JOptionPane.ERROR_MESSAGE); 240 } 241 }; 242 243 if (! SwingUtilities.isEventDispatchThread()) { 244 try { 245 SwingUtilities.invokeAndWait(runMe); 246 } catch (Exception e) { 247 } 248 } else { 249 runMe.run(); 250 } 251 252 } 253 254 259 public void showError(String errorMessage) { 260 showError(errorMessage, Pooka.getProperty("Error", "Error")); 261 } 262 263 268 public void showError(String errorMessage, Exception e) { 269 showError(errorMessage, Pooka.getProperty("Error", "Error"), e); 270 } 271 272 277 public void showError(String errorMessage, String title, Exception e) { 278 showError(errorMessage + e.getMessage(), title); 279 e.printStackTrace(); 280 } 281 282 285 public String formatMessage(String message) { 286 return Pooka.getUIFactory().formatMessage(message); 287 } 288 289 294 public String showInputDialog(String pInputMessage, String pTitle) { 295 final String inputMessage = pInputMessage; 296 final String title = pTitle; 297 298 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 299 Runnable runMe = new Runnable () { 300 public void run() { 301 fResponseWrapper.setString(JOptionPane.showInputDialog(MessageFrame.this, inputMessage, title, JOptionPane.QUESTION_MESSAGE)); 302 } 303 }; 304 305 if (! SwingUtilities.isEventDispatchThread()) { 306 try { 307 SwingUtilities.invokeAndWait(runMe); 308 } catch (Exception e) { 309 } 310 } else { 311 runMe.run(); 312 } 313 314 return fResponseWrapper.getString(); 315 } 316 317 322 public String showInputDialog(Object [] pInputPanes, String pTitle) { 323 final Object [] inputPanes = pInputPanes; 324 final String title = pTitle; 325 326 final ResponseWrapper fResponseWrapper = new ResponseWrapper(); 327 Runnable runMe = new Runnable () { 328 public void run() { 329 fResponseWrapper.setString(JOptionPane.showInputDialog(MessageFrame.this, inputPanes, title, JOptionPane.QUESTION_MESSAGE)); 330 } 331 }; 332 333 if (! SwingUtilities.isEventDispatchThread()) { 334 try { 335 SwingUtilities.invokeAndWait(runMe); 336 } catch (Exception e) { 337 } 338 } else { 339 runMe.run(); 340 } 341 342 return fResponseWrapper.getString(); 343 } 344 345 350 public void showMessageDialog(String pErrorMessage, String pTitle) { 351 final String errorMessage = pErrorMessage; 352 final String title = pTitle; 353 354 Runnable runMe = new Runnable () { 355 public void run() { 356 JOptionPane.showMessageDialog(MessageFrame.this, errorMessage, title, JOptionPane.PLAIN_MESSAGE); 357 } 358 }; 359 360 if (! SwingUtilities.isEventDispatchThread()) { 361 try { 362 SwingUtilities.invokeAndWait(runMe); 363 } catch (Exception e) { 364 } 365 } else { 366 runMe.run(); 367 } 368 369 } 370 371 375 public void resizeByWidth() { 376 this.setSize(this.getPreferredSize()); 379 } 380 381 384 public ProgressDialog createProgressDialog(int min, int max, int initialValue, String title, String content) { 385 return new ProgressDialogImpl(min, max, initialValue, title, content); 386 } 387 388 391 public net.suberic.pooka.gui.crypto.CryptoStatusDisplay getCryptoStatusDisplay() { 392 return getMessageDisplay().getCryptoStatusDisplay(); 393 } 394 395 396 402 public void setBusy(boolean newValue) { 403 final boolean fNewValue = newValue; 404 Runnable runMe = new Runnable () { 405 public void run() { 406 if (fNewValue) 407 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 408 else 409 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 410 } 411 }; 412 413 if (SwingUtilities.isEventDispatchThread()) { 414 runMe.run(); 415 } else { 416 SwingUtilities.invokeLater(runMe); 417 } 418 } 419 420 423 public void refreshDisplay() throws MessagingException { 424 if (messageDisplay instanceof ReadMessageDisplayPanel) 425 ((ReadMessageDisplayPanel)messageDisplay).resetEditorText(); 426 } 427 428 436 437 public UserProfile getDefaultProfile() { 438 return getMessageProxy().getDefaultProfile(); 439 } 440 441 public MessageDisplayPanel getMessageDisplay() { 442 return messageDisplay; 443 } 444 445 public MessageProxy getMessageProxy() { 446 return msg; 447 } 448 449 public void setMessageProxy(MessageProxy newValue) { 450 msg = newValue; 451 } 452 453 public String getMessageText() { 454 return getMessageDisplay().getMessageText(); 455 } 456 457 public String getMessageContentType() { 458 return getMessageDisplay().getMessageContentType(); 459 } 460 461 public AttachmentPane getAttachmentPanel() { 462 return getMessageDisplay().getAttachmentPanel(); 463 } 464 465 public ConfigurableToolbar getToolbar() { 466 return toolbar; 467 } 468 469 public ConfigurableKeyBinding getKeyBindings() { 470 return keyBindings; 471 } 472 473 475 public Action [] getActions() { 476 return defaultActions; 477 } 478 479 public Action [] getDefaultActions() { 480 return defaultActions; 481 } 482 483 485 487 public Action [] defaultActions = { 488 new CloseAction(), 489 new AttachAction() 490 }; 491 492 class CloseAction extends AbstractAction { 493 494 CloseAction() { 495 super("file-close"); 496 } 497 498 public void actionPerformed(ActionEvent e) { 499 closeMessageUI(); 500 } 501 } 502 503 public class AttachAction extends AbstractAction { 504 AttachAction() { 505 super("window-detach"); 506 } 507 508 public void actionPerformed(ActionEvent e) { 509 attachWindow(); 510 } 511 } 512 } 513 514 515 516 517 518 | Popular Tags |