KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > ReadMessageFrame


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 JavaDoc;
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 JavaDoc;
12 import java.util.*;
13 import javax.swing.text.JTextComponent JavaDoc;
14 import javax.swing.event.*;
15 import java.io.File JavaDoc;
16
17
18 public class ReadMessageFrame extends MessageFrame {
19
20   public boolean firstShow = true;
21
22   /**
23    * Creates a ReadMessageFrame from the given Message.
24    */

25
26   public ReadMessageFrame(MessageProxy newMsgProxy) {
27     super(newMsgProxy);
28
29     configureMessageFrame();
30
31   }
32
33   /**
34    * Creates a ReadMessageFrameFrame from an existing ReadMessageInternalFrame.
35    */

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 JavaDoc)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     // check to see if there are any DisplayStyleComboBoxes
55
// in the toolbar
56
java.awt.Component JavaDoc[] 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 JavaDoc)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_IN_FOCUSED_WINDOW);
104
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   /**
126    * Gets the Theme object from the ThemeManager which is appropriate
127    * for this UI.
128    */

129   public MetalTheme JavaDoc 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 JavaDoc 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   /**
151    * Attaches the window to a MessagePanel.
152    */

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   /**
164    * Overrides JComponent.addNotify().
165    *
166    * We override addNotify() here to call resizeByWidth() to set
167    * the correct width, and, if there is a splitPane with an attachment
168    * panel, to set the correct divider location on the split pane.
169    */

170   public void addNotify() {
171     super.addNotify();
172     if (firstShow) {
173       getMessageDisplay().sizeToDefault();
174       resizeByWidth();
175       firstShow = false;
176     }
177   }
178
179   /**
180    * This registers the Keyboard action not only for the FolderWindow
181    * itself, but also for pretty much all of its children, also. This
182    * is to work around something which I think is a bug in jdk 1.2.
183    * (this is not really necessary in jdk 1.3.)
184    *
185    * Overrides JComponent.registerKeyboardAction(ActionListener anAction,
186    * String aCommand, KeyStroke aKeyStroke, int aCondition)
187    */

188
189   public void registerKeyboardAction(ActionListener anAction,
190                                      String JavaDoc 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   /**
199    * This unregisters the Keyboard action not only for the FolderWindow
200    * itself, but also for pretty much all of its children, also. This
201    * is to work around something which I think is a bug in jdk 1.2.
202    * (this is not really necessary in jdk 1.3.)
203    *
204    * Overrides JComponent.unregisterKeyboardAction(KeyStroke aKeyStroke)
205    */

206
207   public void unregisterKeyboardAction(KeyStroke aKeyStroke) {
208     if (messageDisplay != null)
209       messageDisplay.unregisterKeyboardAction(aKeyStroke);
210     toolbar.unregisterKeyboardAction(aKeyStroke);
211   }
212
213
214   //------- Actions ----------//
215

216   public Action JavaDoc[] getActions() {
217
218     Action JavaDoc[] 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