1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.*; 3 import javax.swing.*; 4 import java.awt.FlowLayout ; 5 import net.suberic.pooka.event.*; 6 import javax.mail.event.*; 7 import java.awt.event.ActionListener ; 8 import java.awt.event.ActionEvent ; 9 10 14 public class FolderStatusBar extends JPanel implements MessageCountListener, MessageChangedListener { 15 FolderInfo folderInfo; 16 JLabel folderLabel; 17 JLabel messageCount; 18 JPanel loaderPanel; 19 JPanel gotoPanel; 20 JTextField gotoInputField; 21 LoadMessageTracker tracker = null; 22 int mUnreadCount = 0; 23 int mTotalCount = 0; 24 25 public FolderStatusBar(FolderInfo newFolder) { 26 folderInfo = newFolder; 27 folderLabel = new JLabel(getFolderInfo().getFolderName()); 28 messageCount = new JLabel(); 29 updateMessageCount(); 30 loaderPanel = new JPanel(); 31 32 gotoPanel = new JPanel(); 33 gotoPanel.add(new JLabel(Pooka.getProperty("FolderStatusBar.goto", "Goto Message"))); 34 gotoInputField = new JTextField(5); 35 gotoInputField.addActionListener(new ActionListener () { 36 public void actionPerformed(ActionEvent e) { 37 try { 38 int msgNum = Integer.parseInt(e.getActionCommand()); 39 if (getFolderInfo() != null) { 40 FolderDisplayUI fdui = getFolderInfo().getFolderDisplayUI(); 41 fdui.selectMessage(msgNum - 1); 42 } 43 } catch (NumberFormatException nfe) { 44 45 } 46 gotoInputField.selectAll(); 47 } 48 }); 49 50 gotoInputField.registerKeyboardAction(new ActionListener () { 51 public void actionPerformed(ActionEvent e) { 52 FolderDisplayUI fdui = getFolderInfo().getFolderDisplayUI(); 53 if (fdui != null) { 54 int nextMessage = fdui.selectNextMessage(); 55 gotoInputField.setText(Integer.toString(nextMessage)); 56 gotoInputField.selectAll(); 57 } 58 } 59 }, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DOWN, 0), JComponent.WHEN_FOCUSED); 60 61 gotoInputField.registerKeyboardAction(new ActionListener () { 62 public void actionPerformed(ActionEvent e) { 63 FolderDisplayUI fdui = getFolderInfo().getFolderDisplayUI(); 64 if (fdui != null) { 65 int previousMessage = fdui.selectPreviousMessage(); 66 gotoInputField.setText(Integer.toString(previousMessage)); 67 gotoInputField.selectAll(); 68 } 69 } 70 }, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_UP, 0), JComponent.WHEN_FOCUSED); 71 72 gotoPanel.add(gotoInputField); 73 74 java.awt.GridBagConstraints constraints = new java.awt.GridBagConstraints (); 75 java.awt.GridBagLayout layout = new java.awt.GridBagLayout (); 76 constraints.weightx = 0.0; 77 constraints.fill = java.awt.GridBagConstraints.VERTICAL; 78 constraints.anchor = java.awt.GridBagConstraints.WEST; 79 constraints.ipadx = 5; 80 constraints.insets = new java.awt.Insets (0, 10, 0, 10); 81 this.setLayout(layout); 82 83 layout.setConstraints(folderLabel, constraints); 84 this.add(folderLabel); 85 JSeparator js = new JSeparator(SwingConstants.VERTICAL); 86 layout.setConstraints(js, constraints); 87 this.add(js); 88 layout.setConstraints(messageCount, constraints); 89 this.add(messageCount); 90 js = new JSeparator(SwingConstants.VERTICAL); 91 layout.setConstraints(js, constraints); 92 this.add(js); 93 constraints.fill = java.awt.GridBagConstraints.BOTH; 94 constraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; 95 constraints.weightx = 1.0; 96 layout.setConstraints(loaderPanel, constraints); 97 this.add(loaderPanel); 98 constraints.weightx = 0.0; 99 constraints.fill = java.awt.GridBagConstraints.VERTICAL; 100 constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 101 constraints.anchor = java.awt.GridBagConstraints.EAST; 102 layout.setConstraints(gotoPanel, constraints); 103 this.add(gotoPanel); 104 } 105 106 public void messageChanged(MessageChangedEvent mce) { 107 if (mce.getMessageChangeType() == MessageChangedEvent.FLAGS_CHANGED) { 108 updateMessageCount(); 109 } 110 } 111 112 public void messagesAdded(MessageCountEvent e) { 113 updateMessageCount(); 114 } 115 116 123 public void messagesRemoved(MessageCountEvent e) { 124 updateMessageCount(); 125 } 126 127 132 public void updateMessageCount() { 133 int newTotalCount = getFolderInfo().getMessageCount(); 134 int newUnreadCount = getFolderInfo().getUnreadCount(); 135 if (newTotalCount != mTotalCount || newUnreadCount != mUnreadCount) { 136 SwingUtilities.invokeLater(new Runnable () { 137 public void run() { 138 int secTotalCount = getFolderInfo().getMessageCount(); 139 int secUnreadCount = getFolderInfo().getUnreadCount(); 140 141 if (secTotalCount != mTotalCount || secUnreadCount != mUnreadCount) { 142 mTotalCount = secTotalCount; 143 mUnreadCount = secUnreadCount; 144 messageCount.setText(mUnreadCount + " " + Pooka.getProperty("FolderFolderStatusBar.unreadMessages", "Unread") + " / " + mTotalCount + " " + Pooka.getProperty("FolderFolderStatusBar.totalMessages", "Total")); 145 messageCount.repaint(); 146 } 147 } 148 }); 149 } 150 } 151 152 156 public void activateGotoDialog() { 157 gotoInputField.selectAll(); 158 gotoInputField.requestFocusInWindow(); 159 } 160 161 public FolderInfo getFolderInfo() { 162 return folderInfo; 163 } 164 165 public JPanel getLoaderPanel() { 166 return loaderPanel; 167 } 168 169 public LoadMessageTracker getTracker() { 170 return tracker; 171 } 172 173 public void setTracker(LoadMessageTracker newTracker) { 174 tracker = newTracker; 175 } 176 } | Popular Tags |