1 package net.suberic.pooka.gui; 2 3 import javax.swing.*; 4 import javax.swing.event.ChangeEvent ; 5 import javax.swing.event.ChangeListener ; 6 import java.awt.*; 7 import java.util.*; 8 9 import javax.mail.MessagingException ; 10 import net.suberic.pooka.*; 11 12 16 public class SendFailedDialog extends JPanel { 17 18 static String P_RESOURCE = "SendFailedDialog"; 20 21 static String S_ABORT = "abort"; 23 static String S_SEND_OTHER_SERVER = "send"; 24 static String S_SAVE_TO_OUTBOX = "outbox"; 25 26 public static String S_NOTHING = "nothing"; 28 public static String S_SESSION_DEFAULT = "session"; 29 public static String S_CHANGE_DEFAULT = "change_default"; 30 31 MessagingException mException; 33 34 OutgoingMailServer mOriginalMailServer; 36 37 JTextArea mMessageDisplay; 39 40 JComboBox mMailServerList = null; 42 43 ButtonGroup mActionButtons = null; 46 47 ButtonGroup mServerDefaultButtons = null; 50 51 boolean sendButtonSelected = false; 52 53 56 public SendFailedDialog(OutgoingMailServer pServer, MessagingException me) { 57 mException = me; 58 mOriginalMailServer = pServer; 59 } 60 61 64 public void configureComponent() { 65 this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 66 67 JPanel messagePanel = new JPanel(); 68 mMessageDisplay = new JTextArea(Pooka.getProperty("error.MessageUI.sendFailed", "Failed to send Message.") + "\n" + mException.getMessage()); 69 JLabel testLabel = new JLabel(); 70 71 mMessageDisplay.setBackground(testLabel.getBackground()); 72 mMessageDisplay.setFont(testLabel.getFont()); 73 mMessageDisplay.setForeground(testLabel.getForeground()); 74 mMessageDisplay.setEditable(false); 75 76 messagePanel.add(mMessageDisplay); 77 78 JPanel buttonPanel = createActionPanel(); 79 80 JPanel actionPanel = createServerDefaultPanel(); 81 82 mMailServerList = createMailServerList(); 83 84 JPanel choicePanel = new JPanel(); 85 choicePanel.setBorder(BorderFactory.createEtchedBorder()); 86 choicePanel.setLayout(new BoxLayout(choicePanel, BoxLayout.X_AXIS)); 87 88 choicePanel.add(buttonPanel); 89 90 Box mailServerListBox = new Box(BoxLayout.Y_AXIS); 91 mailServerListBox.add(Box.createVerticalGlue()); 92 mailServerListBox.add(mMailServerList); 93 mailServerListBox.add(Box.createVerticalGlue()); 94 choicePanel.add(mailServerListBox); 95 choicePanel.add(actionPanel); 96 97 this.add(messagePanel); 98 this.add(choicePanel); 99 this.add(new net.suberic.util.swing.ExceptionDisplayPanel(Pooka.getProperty("error.showStackTrace", "Stack Trace"), mException)); 100 101 reactivatePanels(); 102 } 103 104 107 protected JPanel createActionPanel() { 108 JPanel returnValue = new JPanel(); 109 returnValue.setBorder(BorderFactory.createEtchedBorder()); 110 returnValue.setLayout(new BoxLayout(returnValue, BoxLayout.Y_AXIS)); 111 112 ButtonGroup choices = new ButtonGroup(); 113 114 JRadioButton abortButton = new JRadioButton(); 115 abortButton.setText(Pooka.getProperty(P_RESOURCE + ".cancel", "Cancel send")); 116 abortButton.setActionCommand(S_ABORT); 117 abortButton.setSelected(true); 118 choices.add(abortButton); 119 returnValue.add(abortButton); 120 121 final JRadioButton sendButton = new JRadioButton(); 122 sendButton.setText(Pooka.getProperty(P_RESOURCE + ".send", "Send using another server")); 123 sendButton.setActionCommand(S_SEND_OTHER_SERVER); 124 choices.add(sendButton); 125 returnValue.add(sendButton); 126 127 JRadioButton outboxButton = new JRadioButton(); 128 outboxButton.setText(Pooka.getProperty(P_RESOURCE + ".outbox", "Save to outbox")); 129 outboxButton.setActionCommand(S_SAVE_TO_OUTBOX); 130 choices.add(outboxButton); 131 returnValue.add(outboxButton); 132 133 mActionButtons = choices; 134 135 sendButton.addChangeListener(new ChangeListener () { 136 public void stateChanged(ChangeEvent ce) { 137 synchronized(sendButton) { 138 boolean selected = sendButton.isSelected(); 139 if (selected != sendButtonSelected) { 140 sendButtonSelected = selected; 141 reactivatePanels(); 142 } 143 } 144 } 145 }); 146 147 return returnValue; 148 } 149 150 153 public JComboBox createMailServerList() { 154 Vector v = Pooka.getOutgoingMailManager().getOutgoingMailServerList(); 155 Iterator it = v.iterator(); 156 Vector idList = new Vector(); 157 while (it.hasNext()) { 158 OutgoingMailServer current = (OutgoingMailServer) it.next(); 159 idList.add(current.getItemID()); 160 } 161 JComboBox returnValue = new JComboBox(idList); 162 if (mOriginalMailServer != null) 163 returnValue.setSelectedItem(mOriginalMailServer.getItemID()); 164 165 return returnValue; 166 } 167 168 172 public JPanel createServerDefaultPanel() { 173 174 JPanel returnValue = new JPanel(); 175 returnValue.setBorder(BorderFactory.createEtchedBorder()); 176 returnValue.setLayout(new BoxLayout(returnValue, BoxLayout.Y_AXIS)); 177 178 ButtonGroup choices = new ButtonGroup(); 179 180 JRadioButton current = new JRadioButton(); 181 current.setText(Pooka.getProperty(P_RESOURCE + ".noDefault", "Keep default")); 182 current.setActionCommand(S_NOTHING); 183 current.setSelected(true); 184 choices.add(current); 185 returnValue.add(current); 186 187 current = new JRadioButton(); 188 current.setText(Pooka.getProperty(P_RESOURCE + ".defaultThisSession", "Set as default for this session")); 189 current.setActionCommand(S_SESSION_DEFAULT); 190 choices.add(current); 191 returnValue.add(current); 192 193 current = new JRadioButton(); 194 current.setText(Pooka.getProperty(P_RESOURCE + ".defaultPerm", "Set as default")); 195 current.setActionCommand(S_CHANGE_DEFAULT); 196 choices.add(current); 197 returnValue.add(current); 198 199 mServerDefaultButtons = choices; 200 return returnValue; 201 202 } 203 204 207 public void reactivatePanels() { 208 String actionCommand = mActionButtons.getSelection().getActionCommand(); 209 210 if (actionCommand == S_SEND_OTHER_SERVER) { 211 mMailServerList.setEnabled(true); 212 Enumeration elements = mServerDefaultButtons.getElements(); 213 while (elements.hasMoreElements()) { 214 AbstractButton ab = (AbstractButton) elements.nextElement(); 215 ab.setEnabled(true); 216 } 217 } else { 218 mMailServerList.setEnabled(false); 219 Enumeration elements = mServerDefaultButtons.getElements(); 220 while (elements.hasMoreElements()) { 221 AbstractButton ab = (AbstractButton) elements.nextElement(); 222 ab.setEnabled(false); 223 } 224 } 225 } 226 227 230 public boolean resendMessage() { 231 if (mActionButtons.getSelection().getActionCommand() == S_SEND_OTHER_SERVER) { 232 return true; 233 } else { 234 return false; 235 } 236 } 237 238 241 public boolean getSaveToOutbox() { 242 243 if (mActionButtons.getSelection().getActionCommand() == S_SAVE_TO_OUTBOX) { 244 return true; 245 } else { 246 return false; 247 } 248 249 } 250 251 254 public OutgoingMailServer getMailServer() { 255 String selectedValue = (String ) mMailServerList.getSelectedItem(); 256 OutgoingMailServer returnValue = Pooka.getOutgoingMailManager().getOutgoingMailServer(selectedValue); 257 return returnValue; 258 } 259 260 263 public String getMailServerAction() { 264 String selectedValue = mServerDefaultButtons.getSelection().getActionCommand(); 265 return selectedValue; 266 } 267 } 268 269 | Popular Tags |