KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class ReadMessageInternalFrame extends MessageInternalFrame {
18
19   public boolean firstShow = true;
20
21   /**
22    * Creates a ReadMessageInternalFrame from the given Message.
23    */

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 JavaDoc)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 JavaDoc 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   /**
89    * Configures the MessageInteralFrame.
90    */

91   public void configureMessageInternalFrame() throws MessagingException {
92     try {
93       this.setTitle((String JavaDoc)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     // check to see if there are any DisplayStyleComboBoxes
109
// in the toolbar
110
java.awt.Component JavaDoc[] 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   /**
132    * Gets the Theme object from the ThemeManager which is appropriate
133    * for this UI.
134    */

135   public MetalTheme JavaDoc 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 JavaDoc 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   /**
156    * Detaches this window from the desktop panel. Actually creates a new
157    * top-level frame and copies the contents to that frame.
158    */

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 JavaDoc pve) {
167     }
168   }
169
170   /**
171    * Overrides JComponent.addNotify().
172    *
173    * We override addNotify() here to call resizeByWidth() to set
174    * the correct width, and, if there is a splitPane with an attachment
175    * panel, to set the correct divider location on the split pane.
176    */

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

195
196   public void registerKeyboardAction(ActionListener anAction,
197                                      String JavaDoc 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   /**
207    * This unregisters the Keyboard action not only for the FolderWindow
208    * itself, but also for pretty much all of its children, also. This
209    * is to work around something which I think is a bug in jdk 1.2.
210    * (this is not really necessary in jdk 1.3.)
211    *
212    * Overrides JComponent.unregisterKeyboardAction(KeyStroke aKeyStroke)
213    */

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   //------- Actions ----------//
224

225   public Action JavaDoc[] getActions() {
226
227     Action JavaDoc[] actionList;
228
229     Action JavaDoc[] currentDefault = getDefaultActions();
230
231     if (messageDisplay.getActions() != null) {
232       Action JavaDoc[] 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