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 18 public class ReadMessageFrame extends MessageFrame { 19 20 public boolean firstShow = true; 21 22 25 26 public ReadMessageFrame(MessageProxy newMsgProxy) { 27 super(newMsgProxy); 28 29 configureMessageFrame(); 30 31 } 32 33 36 ReadMessageFrame(ReadMessageInternalFrame source) { 37 messageDisplay = source.getMessageDisplay(); 38 messageDisplay.setMessageUI(this); 39 msg = source.getMessageProxy(); 40 toolbar = source.getToolbar(); 41 keyBindings = source.getKeyBindings(); 42 43 try { 44 this.setTitle((String )msg.getMessageInfo().getMessageProperty("Subject")); 45 } catch (MessagingException me) { 46 this.setTitle(Pooka.getProperty("Pooka.messageFrame.messageTitle.noSubject", "<no subject>")); 47 } 48 49 this.getContentPane().add("North", toolbar); 50 this.getContentPane().add("Center", messageDisplay); 51 52 toolbar.setActive(this.getActions()); 53 54 java.awt.Component [] toolbarComponents = toolbar.getComponents(); 57 for (int i = 0; i < toolbarComponents.length; i++) { 58 if (toolbarComponents[i] instanceof DisplayStyleComboBox) { 59 DisplayStyleComboBox dscb = (DisplayStyleComboBox) toolbarComponents[i]; 60 if (dscb.displayStyle) 61 ((ReadMessageDisplayPanel)messageDisplay).setDisplayCombo(dscb); 62 63 if (dscb.headerStyle) 64 ((ReadMessageDisplayPanel)messageDisplay).setHeaderCombo(dscb); 65 66 dscb.styleUpdated(getMessageProxy().getDisplayMode(), getMessageProxy().getHeaderMode()); 67 } 68 } 69 70 this.setLocation(source.getLocationOnScreen()); 71 72 configureInterfaceStyle(); 73 74 this.addWindowListener(new WindowAdapter() { 75 public void windowClosing(WindowEvent e) { 76 if (getMessageProxy().getMessageUI() == ReadMessageFrame.this) { 77 getMessageProxy().setMessageUI(null); 78 } 79 } 80 }); 81 } 82 83 protected void configureMessageFrame() { 84 try { 85 try { 86 this.setTitle((String )msg.getMessageInfo().getMessageProperty("Subject")); 87 } catch (MessagingException me) { 88 this.setTitle(Pooka.getProperty("Pooka.messageFrame.messageTitle.noSubject", "<no subject>")); 89 } 90 91 messageDisplay = new ReadMessageDisplayPanel(this); 92 messageDisplay.configureMessageDisplay(); 93 94 toolbar = new ConfigurableToolbar("MessageWindowToolbar", Pooka.getResources()); 95 96 this.getContentPane().add("North", toolbar); 97 this.getContentPane().add("Center", messageDisplay); 98 99 toolbar.setActive(this.getActions()); 100 101 keyBindings = new ConfigurableKeyBinding(getMessageDisplay(), "ReadMessageWindow.keyBindings", Pooka.getResources()); 102 103 keyBindings.setCondition(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 105 106 keyBindings.setActive(getActions()); 107 108 } catch (MessagingException me) { 109 showError(Pooka.getProperty("error.MessageFrame.errorLoadingMessage", "Error loading Message: ") + "\n" + me.getMessage(), Pooka.getProperty("error.MessageFrame.errorLoadingMessage.title", "Error loading message.")); 110 me.printStackTrace(); 111 } 112 113 configureInterfaceStyle(); 114 115 this.addWindowListener(new WindowAdapter() { 116 public void windowClosing(WindowEvent e) { 117 if (getMessageProxy().getMessageUI() == ReadMessageFrame.this) { 118 getMessageProxy().setMessageUI(null); 119 } 120 } 121 }); 122 123 } 124 125 129 public MetalTheme getTheme(ThemeManager tm) { 130 MessageProxy mp = getMessageProxy(); 131 if (mp == null) 132 return null; 133 134 MessageInfo mi = mp.getMessageInfo(); 135 if (mi == null) 136 return null; 137 138 FolderInfo fi = mi.getFolderInfo(); 139 if (fi != null) { 140 String id = Pooka.getProperty(fi.getFolderProperty() + ".theme", ""); 141 if (id != null && ! id.equals("")) { 142 return tm.getTheme(id); 143 } 144 } 145 146 return tm.getDefaultTheme(); 147 148 } 149 150 153 public void attachWindow() { 154 if (Pooka.getMainPanel().getContentPanel() instanceof MessagePanel) { 155 MessagePanel mp = (MessagePanel) Pooka.getMainPanel().getContentPanel(); 156 ReadMessageInternalFrame rmif = new ReadMessageInternalFrame(mp, this); 157 getMessageProxy().setMessageUI(rmif); 158 rmif.openMessageUI(); 159 this.dispose(); 160 } 161 } 162 163 170 public void addNotify() { 171 super.addNotify(); 172 if (firstShow) { 173 getMessageDisplay().sizeToDefault(); 174 resizeByWidth(); 175 firstShow = false; 176 } 177 } 178 179 188 189 public void registerKeyboardAction(ActionListener anAction, 190 String aCommand, KeyStroke aKeyStroke, int aCondition) { 191 192 if (messageDisplay != null) 193 messageDisplay.registerKeyboardAction(anAction, aCommand, aKeyStroke, aCondition); 194 toolbar.registerKeyboardAction(anAction, aCommand, aKeyStroke, aCondition); 195 196 } 197 198 206 207 public void unregisterKeyboardAction(KeyStroke aKeyStroke) { 208 if (messageDisplay != null) 209 messageDisplay.unregisterKeyboardAction(aKeyStroke); 210 toolbar.unregisterKeyboardAction(aKeyStroke); 211 } 212 213 214 216 public Action [] getActions() { 217 218 Action [] actionList; 219 220 if (messageDisplay.getActions() != null) { 221 actionList = TextAction.augmentList(messageDisplay.getActions(), getDefaultActions()); 222 } else 223 actionList = getDefaultActions(); 224 225 return actionList; 226 } 227 228 229 } 230 231 232 233 234 235 | Popular Tags |