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.swing.plaf.metal.MetalTheme ; 6 import javax.mail.*; 7 import javax.mail.internet.*; 8 import java.awt.*; 9 import java.awt.event.*; 10 import javax.swing.*; 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 17 public class ReadMessageInternalFrame extends MessageInternalFrame { 18 19 public boolean firstShow = true; 20 21 24 25 public ReadMessageInternalFrame(MessagePanel newParentContainer, MessageProxy newMsgProxy) { 26 super(newParentContainer, newMsgProxy); 27 28 this.addInternalFrameListener(new InternalFrameAdapter() { 29 public void internalFrameClosed(InternalFrameEvent e) { 30 if (getMessageProxy().getMessageUI() == ReadMessageInternalFrame.this) 31 getMessageProxy().setMessageUI(null); 32 } 33 }); 34 35 } 36 37 public ReadMessageInternalFrame(MessagePanel newParentContainer, ReadMessageFrame source) { 38 parentContainer = newParentContainer; 39 messageDisplay = source.getMessageDisplay(); 40 messageDisplay.setMessageUI(this); 41 msg = source.getMessageProxy(); 42 toolbar = source.getToolbar(); 43 keyBindings = source.getKeyBindings(); 44 45 try { 46 this.setTitle((String )msg.getMessageInfo().getMessageProperty("Subject")); 47 } catch (MessagingException me) { 48 this.setTitle(Pooka.getProperty("Pooka.messageFrame.messageTitle.noSubject", "<no subject>")); 49 } 50 51 this.getContentPane().add("North", toolbar); 52 this.getContentPane().add("Center", messageDisplay); 53 54 toolbar.setActive(this.getActions()); 55 56 Point loc = source.getLocationOnScreen(); 57 SwingUtilities.convertPointFromScreen(loc, parentContainer); 58 this.setLocation(loc); 59 60 this.addFocusListener(new FocusAdapter() { 61 public void focusGained(FocusEvent e) { 62 if (getMessageDisplay() != null) 63 getMessageDisplay().requestFocusInWindow(); 64 } 65 }); 66 67 FocusTraversalPolicy ftp = new LayoutFocusTraversalPolicy() { 68 public Component getInitialComponent(JInternalFrame jif) { 69 if (jif instanceof MessageInternalFrame) { 70 return ((MessageInternalFrame) jif).getMessageDisplay(); 71 } 72 73 return super.getInitialComponent(jif); 74 } 75 }; 76 this.setFocusTraversalPolicy(ftp); 77 78 this.addInternalFrameListener(new InternalFrameAdapter() { 79 public void internalFrameClosed(InternalFrameEvent e) { 80 if (getMessageProxy().getMessageUI() == ReadMessageInternalFrame.this) 81 getMessageProxy().setMessageUI(null); 82 } 83 }); 84 85 configureInterfaceStyle(); 86 } 87 88 91 public void configureMessageInternalFrame() throws MessagingException { 92 try { 93 this.setTitle((String )msg.getMessageInfo().getMessageProperty("Subject")); 94 } catch (MessagingException me) { 95 this.setTitle(Pooka.getProperty("Pooka.messageInternalFrame.messageTitle.noSubject", "<no subject>")); 96 } 97 98 messageDisplay = new ReadMessageDisplayPanel(this); 99 messageDisplay.configureMessageDisplay(); 100 101 toolbar = new ConfigurableToolbar("MessageWindowToolbar", Pooka.getResources()); 102 103 this.getContentPane().add("North", toolbar); 104 this.getContentPane().add("Center", messageDisplay); 105 106 toolbar.setActive(this.getActions()); 107 108 java.awt.Component [] toolbarComponents = toolbar.getComponents(); 111 for (int i = 0; i < toolbarComponents.length; i++) { 112 if (toolbarComponents[i] instanceof DisplayStyleComboBox) { 113 DisplayStyleComboBox dscb = (DisplayStyleComboBox) toolbarComponents[i]; 114 if (dscb.displayStyle) 115 ((ReadMessageDisplayPanel)messageDisplay).setDisplayCombo(dscb); 116 117 if (dscb.headerStyle) 118 ((ReadMessageDisplayPanel)messageDisplay).setHeaderCombo(dscb); 119 120 dscb.styleUpdated(getMessageProxy().getDisplayMode(), getMessageProxy().getHeaderMode()); 121 } 122 } 123 124 keyBindings = new ConfigurableKeyBinding(this, "ReadMessageWindow.keyBindings", Pooka.getResources()); 125 keyBindings.setActive(getActions()); 126 127 configureInterfaceStyle(); 128 129 } 130 131 135 public MetalTheme getTheme(ThemeManager tm) { 136 MessageProxy mp = getMessageProxy(); 137 if (mp == null) 138 return null; 139 140 MessageInfo mi = mp.getMessageInfo(); 141 if (mi == null) 142 return null; 143 144 FolderInfo fi = mi.getFolderInfo(); 145 if (fi != null) { 146 String id = Pooka.getProperty(fi.getFolderProperty() + ".theme", ""); 147 if (id != null && ! id.equals("")) { 148 return tm.getTheme(id); 149 } 150 } 151 152 return tm.getDefaultTheme(); 153 } 154 155 159 public void detachWindow() { 160 ReadMessageFrame rmf = new ReadMessageFrame(this); 161 getMessageProxy().setMessageUI(rmf); 162 163 rmf.setVisible(true); 164 try { 165 this.setClosed(true); 166 } catch (java.beans.PropertyVetoException pve) { 167 } 168 } 169 170 177 public void addNotify() { 178 super.addNotify(); 179 if (firstShow) { 180 resizeByWidth(); 181 getMessageDisplay().sizeToDefault(); 182 firstShow = false; 183 } 184 } 185 186 195 196 public void registerKeyboardAction(ActionListener anAction, 197 String aCommand, KeyStroke aKeyStroke, int aCondition) { 198 super.registerKeyboardAction(anAction, aCommand, aKeyStroke, aCondition); 199 200 if (messageDisplay != null) 201 messageDisplay.registerKeyboardAction(anAction, aCommand, aKeyStroke, aCondition); 202 toolbar.registerKeyboardAction(anAction, aCommand, aKeyStroke, aCondition); 203 204 } 205 206 214 215 public void unregisterKeyboardAction(KeyStroke aKeyStroke) { 216 super.unregisterKeyboardAction(aKeyStroke); 217 218 if (messageDisplay != null) 219 messageDisplay.unregisterKeyboardAction(aKeyStroke); 220 toolbar.unregisterKeyboardAction(aKeyStroke); 221 } 222 223 225 public Action [] getActions() { 226 227 Action [] actionList; 228 229 Action [] currentDefault = getDefaultActions(); 230 231 if (messageDisplay.getActions() != null) { 232 Action [] displayActions = messageDisplay.getActions(); 233 actionList = TextAction.augmentList(displayActions, currentDefault); 234 } else { 235 actionList = currentDefault; 236 } 237 238 return actionList; 239 } 240 241 } 242 243 244 245 246 247 | Popular Tags |