1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.*; 3 import net.suberic.util.gui.*; 4 import javax.mail.*; 5 import javax.mail.internet.*; 6 import java.awt.*; 7 import java.awt.event.*; 8 import javax.swing.*; 9 import javax.swing.text.TextAction ; 10 import java.util.*; 11 import java.util.regex.*; 12 import javax.swing.text.JTextComponent ; 13 import javax.swing.event.*; 14 import java.io.File ; 15 16 22 public abstract class MessageDisplayPanel extends JPanel { 23 protected MessageUI msgUI; 24 protected JSplitPane splitPane = null; 25 protected AttachmentPane attachmentPanel = null; 26 protected JTextPane editorPane = null; 27 protected JScrollPane editorScrollPane = null; 28 protected boolean hasAttachment = false; 29 protected ConfigurableKeyBinding keyBindings; 30 31 protected HashMap mFontSetMap = new HashMap(); 32 33 protected Matcher currentMatcher = null; 34 35 JPanel attachmentDisplayPanel; 36 37 40 public MessageDisplayPanel() { 41 this.setLayout(new CardLayout()); 42 } 43 44 47 public MessageDisplayPanel(MessageUI newMsgUI) { 48 msgUI = newMsgUI; 49 50 this.setLayout(new BorderLayout()); 51 52 } 53 54 58 59 public abstract void configureMessageDisplay() throws MessagingException; 60 61 64 public abstract net.suberic.pooka.gui.crypto.CryptoStatusDisplay getCryptoStatusDisplay(); 65 66 67 71 public void searchMessage() { 72 String searchString = getMessageUI().showInputDialog(Pooka.getProperty("message.search", "Find what"), Pooka.getProperty("message.search.title", "Find")); 73 if (searchString != null && searchString.length() > 0) 74 findRegexp(searchString); 75 } 76 77 81 public void searchAgain() { 82 if (currentMatcher != null) 83 findNext(); 84 else 85 searchMessage(); 86 } 87 88 91 protected void findRegexp(String regString) { 92 boolean matchSucceeded = doFindRegexp(regString); 93 if (matchSucceeded) { 94 int start = currentMatcher.start(); 95 int end = currentMatcher.end(); 96 JTextPane currentPane = getCurrentEditorPane(); 97 currentPane.setCaretPosition(start); 98 currentPane.moveCaretPosition(end); 99 } 100 } 101 102 105 protected void findNext() { 106 boolean matchSucceeded = doFindNext(); 107 if (matchSucceeded) { 108 int start = currentMatcher.start(); 109 int end = currentMatcher.end(); 110 JTextPane currentPane = getCurrentEditorPane(); 111 currentPane.setCaretPosition(start); 112 currentPane.moveCaretPosition(end); 113 } 114 } 115 116 119 protected boolean doFindRegexp(String regString) { 120 if (currentMatcher != null) { 121 String origString = currentMatcher.pattern().pattern(); 122 if (origString.equals(regString)) { 123 return doFindNext(); 124 } 125 } 126 127 129 Pattern p = Pattern.compile(regString); 130 javax.swing.text.Document currentDoc = getCurrentEditorPane().getDocument(); 131 132 try { 133 currentMatcher = p.matcher(currentDoc.getText(0, currentDoc.getLength())); 134 return currentMatcher.find(); 135 } catch (Exception e) { 136 137 } 138 139 return false; 140 141 } 142 143 146 protected boolean doFindNext() { 147 if (currentMatcher != null) { 148 return currentMatcher.find(); 149 } else { 150 return false; 151 } 152 } 153 154 167 public Dimension getDefaultEditorPaneSize() { 168 int hsize = 500; 169 int vsize = 500; 170 171 try { 172 vsize = Integer.parseInt(Pooka.getProperty("MessageWindow.editorPane.vsize", "500")); 173 } catch (NumberFormatException nfe) { 174 vsize=500; 175 } 176 177 try { 178 if (Pooka.getProperty("MessageWindow.editorPane.hsizeByCharLength", "false").equalsIgnoreCase("true") && editorPane != null) { 179 int charLength = Integer.parseInt(Pooka.getProperty("MessageWindow.editorPane.charLength", "80")); 180 Font currentFont = editorPane.getFont(); 181 if (currentFont != null) { 182 FontMetrics fm = this.getFontMetrics(currentFont); 183 Insets margin = editorPane.getMargin(); 184 int scrollBarWidth = 0; 185 if (editorScrollPane != null && editorScrollPane.getVerticalScrollBar() != null) { 186 scrollBarWidth = editorScrollPane.getVerticalScrollBar().getPreferredSize().width; 187 } 188 hsize = ((int)(charLength * fm.getStringBounds("Remember when you were young? You shone like the sun. Shine on you crazy diamo", editorPane.getGraphics()).getWidth() / 80)) + margin.left + margin.right + scrollBarWidth; 189 } 190 } else { 191 hsize = Integer.parseInt(Pooka.getProperty("MessageWindow.editorPane.hsize", "500")); 192 } 193 } catch (NumberFormatException nfe) { 194 hsize=500; 195 } 196 197 Dimension retval = new Dimension(hsize, vsize); 198 return retval; 199 } 200 201 202 209 public void setDefaultFont() { 210 setDefaultFont(getEditorPane()); 211 } 212 213 220 protected void setDefaultFont(JEditorPane jep) { 221 Font f = null; 222 try { 223 net.suberic.util.swing.ThemeSupporter ts = (net.suberic.util.swing.ThemeSupporter)getMessageUI(); 224 net.suberic.util.swing.ConfigurableMetalTheme cmt = (net.suberic.util.swing.ConfigurableMetalTheme) ts.getTheme(Pooka.getUIFactory().getPookaThemeManager()); 225 if (cmt != null) { 226 f = cmt.getMonospacedFont(); 227 } 228 } catch (Exception e) { 229 } 231 232 if (f == null && mFontSetMap.get(jep) == null) { 233 String fontString = Pooka.getProperty("MessageWindow.editorPane.font", "Monospaced-Plain-11"); 234 235 f = Font.decode(fontString); 236 } 237 238 if (f != null) { 239 jep.setFont(f); 240 mFontSetMap.put(jep, new Boolean (true)); 241 } 242 } 243 244 250 public abstract void sizeToDefault(); 251 252 public UserProfile getDefaultProfile() { 253 if (getMessageProxy() != null) 254 return getMessageProxy().getDefaultProfile(); 255 else 256 return null; 257 } 258 259 public JTextPane getEditorPane() { 260 return editorPane; 261 } 262 263 264 267 public JTextPane getCurrentEditorPane() { 268 return editorPane; 269 } 270 271 public MessageProxy getMessageProxy() { 272 if (msgUI != null) 273 return msgUI.getMessageProxy(); 274 else 275 return null; 276 } 277 278 public MessageUI getMessageUI() { 279 return msgUI; 280 } 281 282 public void setMessageUI(MessageUI newValue) { 283 msgUI = newValue; 284 } 285 286 public String getMessageText() { 287 return getEditorPane().getText(); 288 } 289 290 public String getMessageContentType() { 291 return getEditorPane().getContentType(); 292 } 293 294 public AttachmentPane getAttachmentPanel() { 295 return attachmentPanel; 296 } 297 298 public Action [] getActions() { 299 return null; 300 } 301 302 public JSplitPane getSplitPane() { 303 return splitPane; 304 } 305 } 306 | Popular Tags |