4 * Created on 2007/07/21, 22:37
7 package org.jent.checksmtp;
9 import java.awt.AWTException;
10 import java.awt.Color;
11 import java.awt.Dimension;
12 import java.awt.Image;
13 import java.awt.MenuItem;
14 import java.awt.Point;
15 import java.awt.PopupMenu;
16 import java.awt.SystemTray;
17 import java.awt.Toolkit;
18 import java.awt.TrayIcon;
19 import java.awt.event.ActionEvent;
20 import java.awt.event.ActionListener;
21 import javax.swing.ImageIcon;
22 import javax.swing.InputVerifier;
23 import javax.swing.JComponent;
24 import javax.swing.JFrame;
25 import javax.swing.JTextField;
29 * @author Takuya Ono <takuya-o@users.sourceforge.jp>
31 public class ApplicationUI extends javax.swing.JFrame {
33 /** Creates new form ApplicationUI */
34 public ApplicationUI() {
38 jButtonOK.requestFocusInWindow();
39 //getRootPane().setDefaultButton(jButtonOK);
44 private void resetDisplay() {
45 //reset display data from ApplicationProperties.
46 jTextFieldReceiverPort.setText(Integer.toString(ApplicationProperties.getSmtpPort()));
47 jTextFieldServerHost.setText(ApplicationProperties.getSmtpServerHost());
48 jTextFieldServerPort.setText(Integer.toString(ApplicationProperties.getSmtpServerPort()));
49 jCheckBoxServerSSL.setSelected(ApplicationProperties.getSmtpServerSSL());
50 jCheckBoxEnableRemoteConnect.setSelected(ApplicationProperties.getSmtpEnebleRemoteConnect());
51 jTextFieldConfirmTimeout.setText(Integer.toString(ApplicationProperties.getConfirmTimeout()));
53 jCheckBoxLdap.setSelected(ApplicationProperties.getLdap());
54 jTextFieldProviderUrl.setText(ApplicationProperties.getLdapProviderURL());
55 jTextFieldBaseDn.setText(ApplicationProperties.getLdapRoot());
56 jTextFieldAttribute.setText(ApplicationProperties.getLdapAttributes());
57 jCheckBoxIsSjis.setSelected(ApplicationProperties.getLdapIsSjis());
61 static private MessageDialogUI portNumberOutOfRangeErrorDialog = null;
62 class PortNumberInputVerifier extends InputVerifier {
63 public boolean verify(JComponent jComponent) {
64 JTextField jTextField = (JTextField) jComponent;
66 String input = jTextField.getText();
69 int port = Integer.parseInt(input);
71 } catch (Exception e) {
76 jTextField.setBackground(Color.PINK);
77 if ( portNumberOutOfRangeErrorDialog == null ) {
78 portNumberOutOfRangeErrorDialog =
79 new MessageDialogUI(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.Port_number_is_integer_from_1_to_65535."),
80 null, MessageDialogUI.WARNING_MODE);
82 portNumberOutOfRangeErrorDialog.setVisible(true);
85 jTextField.setBackground(Color.WHITE);
92 static private MessageDialogUI timeoutRangeErrorDialog = null;
93 class TimeoutNumberInputVerifier extends InputVerifier {
94 public boolean verify(JComponent jComponent) {
95 JTextField jTextField = (JTextField) jComponent;
97 String input = jTextField.getText();
100 int timeout = Integer.parseInt(input);
101 checkTimeoutRange(timeout);
102 } catch (Exception e) {
107 jTextField.setBackground(Color.PINK);
108 if ( timeoutRangeErrorDialog == null ) {
109 timeoutRangeErrorDialog =
110 new MessageDialogUI(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.exception.Timeout_need_to_a_positive_number"),
111 null, MessageDialogUI.WARNING_MODE);
113 timeoutRangeErrorDialog.setVisible(true);
116 jTextField.setBackground(Color.WHITE);
124 /** This method is called from within the constructor to
125 * initialize the form.
126 * WARNING: Do NOT modify this code. The content of this method is
127 * always regenerated by the Form Editor.
129 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
130 private void initComponents() {
132 jTabbedPane = new javax.swing.JTabbedPane();
133 jPanelMail = new javax.swing.JPanel();
134 jLabel1 = new javax.swing.JLabel();
135 jLabel2 = new javax.swing.JLabel();
136 jLabel3 = new javax.swing.JLabel();
137 jTextFieldReceiverPort = new javax.swing.JTextField();
138 jTextFieldServerHost = new javax.swing.JTextField();
139 jTextFieldServerPort = new javax.swing.JTextField();
140 jCheckBoxEnableRemoteConnect = new javax.swing.JCheckBox();
141 jLabel7 = new javax.swing.JLabel();
142 jTextFieldConfirmTimeout = new javax.swing.JTextField();
143 jCheckBoxServerSSL = new javax.swing.JCheckBox();
144 jPanelLDAP = new javax.swing.JPanel();
145 jCheckBoxLdap = new javax.swing.JCheckBox();
146 jLabel4 = new javax.swing.JLabel();
147 jLabel5 = new javax.swing.JLabel();
148 jLabel6 = new javax.swing.JLabel();
149 jTextFieldProviderUrl = new javax.swing.JTextField();
150 jTextFieldBaseDn = new javax.swing.JTextField();
151 jTextFieldAttribute = new javax.swing.JTextField();
152 jCheckBoxIsSjis = new javax.swing.JCheckBox();
153 jPanelAbout = new javax.swing.JPanel();
154 jLabelProgramName = new javax.swing.JLabel();
155 jLabelProgramVersion = new javax.swing.JLabel();
156 jLabelSfURL = new javax.swing.JLabel();
157 jButtonOK = new javax.swing.JButton();
158 jButtonCancel = new javax.swing.JButton();
159 jButtonQuit = new javax.swing.JButton();
161 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
162 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle"); // NOI18N
163 setTitle(bundle.getString("ApplicationUI.title")); // NOI18N
164 setIconImage(loadImageIcon());
165 addWindowListener(new java.awt.event.WindowAdapter() {
166 public void windowDeiconified(java.awt.event.WindowEvent evt) {
167 formWindowDeiconified(evt);
169 public void windowIconified(java.awt.event.WindowEvent evt) {
170 formWindowIconified(evt);
174 jLabel1.setText(bundle.getString("ApplicationUI.jLabel1.text")); // NOI18N
176 jLabel2.setText(bundle.getString("ApplicationUI.jLabel2.text")); // NOI18N
178 jLabel3.setText(bundle.getString("ApplicationUI.jLabel3.text")); // NOI18N
180 jTextFieldReceiverPort.setText(bundle.getString("ApplicationUI.jTextFieldReceiverPort.text")); // NOI18N
181 jTextFieldReceiverPort.setToolTipText(bundle.getString("ApplicationUI.jTextFieldReceiverPort.toolTipText")); // NOI18N
182 jTextFieldReceiverPort.setInputVerifier(new PortNumberInputVerifier());
183 jTextFieldReceiverPort.setMinimumSize(new java.awt.Dimension(44, 19));
184 jTextFieldReceiverPort.addActionListener(new java.awt.event.ActionListener() {
185 public void actionPerformed(java.awt.event.ActionEvent evt) {
186 jTextFieldReceiverPortActionPerformed(evt);
190 jTextFieldServerHost.setText(bundle.getString("ApplicationUI.jTextFieldServerHost.text")); // NOI18N
191 jTextFieldServerHost.setToolTipText(bundle.getString("ApplicationUI.jTextFieldServerHost.toolTipText")); // NOI18N
192 jTextFieldServerHost.setMinimumSize(new java.awt.Dimension(88, 19));
194 jTextFieldServerPort.setText(bundle.getString("ApplicationUI.jTextFieldServerPort.text")); // NOI18N
195 jTextFieldServerPort.setToolTipText(bundle.getString("ApplicationUI.jTextFieldServerPort.toolTipText")); // NOI18N
196 jTextFieldServerPort.setInputVerifier(new PortNumberInputVerifier());
197 jTextFieldServerPort.setMinimumSize(new java.awt.Dimension(44, 19));
199 jCheckBoxEnableRemoteConnect.setText(bundle.getString("ApplicationUI.jCheckBoxEnableRemoteConnect.text")); // NOI18N
200 jCheckBoxEnableRemoteConnect.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxEnableRemoteConnect.toolTipText")); // NOI18N
201 jCheckBoxEnableRemoteConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
202 jCheckBoxEnableRemoteConnect.setMargin(new java.awt.Insets(0, 0, 0, 0));
204 jLabel7.setText(bundle.getString("ApplicationUI.jLabel7.text")); // NOI18N
206 jTextFieldConfirmTimeout.setText(bundle.getString("ApplicationUI.jTextFieldConfirmTimeout.text")); // NOI18N
207 jTextFieldConfirmTimeout.setToolTipText(bundle.getString("ApplicationUI.jTextFieldConfirmTimeout.toolTipText")); // NOI18N
208 jTextFieldConfirmTimeout.setInputVerifier(new TimeoutNumberInputVerifier()
210 jTextFieldConfirmTimeout.setMinimumSize(new java.awt.Dimension(1, 19));
212 jCheckBoxServerSSL.setText(bundle.getString("ApplicationUI.jCheckBoxServerSSL.text")); // NOI18N
213 jCheckBoxServerSSL.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxServerSSL.toolTipText")); // NOI18N
214 jCheckBoxServerSSL.addChangeListener(new javax.swing.event.ChangeListener() {
215 public void stateChanged(javax.swing.event.ChangeEvent evt) {
216 jCheckBoxServerSSLStateChanged(evt);
220 org.jdesktop.layout.GroupLayout jPanelMailLayout = new org.jdesktop.layout.GroupLayout(jPanelMail);
221 jPanelMail.setLayout(jPanelMailLayout);
222 jPanelMailLayout.setHorizontalGroup(
223 jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
224 .add(jPanelMailLayout.createSequentialGroup()
226 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
227 .add(jPanelMailLayout.createSequentialGroup()
228 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
229 .add(jPanelMailLayout.createSequentialGroup()
231 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
232 .add(jTextFieldConfirmTimeout, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
233 .add(jPanelMailLayout.createSequentialGroup()
235 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
236 .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
237 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 77, Short.MAX_VALUE)
238 .add(jCheckBoxEnableRemoteConnect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 207, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
239 .add(jPanelMailLayout.createSequentialGroup()
241 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
242 .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
243 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
245 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
246 .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
247 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
248 .add(jCheckBoxServerSSL)
249 .addContainerGap())))
252 jPanelMailLayout.linkSize(new java.awt.Component[] {jLabel1, jLabel2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
254 jPanelMailLayout.setVerticalGroup(
255 jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
256 .add(jPanelMailLayout.createSequentialGroup()
258 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
260 .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
261 .add(jCheckBoxEnableRemoteConnect))
262 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
263 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
265 .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
266 .add(jCheckBoxServerSSL)
267 .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
269 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE)
270 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
272 .add(jTextFieldConfirmTimeout, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
276 jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelMail.TabConstraints.tabTitle"), null, jPanelMail, bundle.getString("ApplicationUI.jPanelMail.TabConstraints tabToolTip")); // NOI18N
278 jCheckBoxLdap.setText(bundle.getString("ApplicationUI.jCheckBoxLdap.text")); // NOI18N
279 jCheckBoxLdap.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxLdap.toolTipText")); // NOI18N
280 jCheckBoxLdap.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
281 jCheckBoxLdap.setMargin(new java.awt.Insets(0, 0, 0, 0));
282 jCheckBoxLdap.addChangeListener(new javax.swing.event.ChangeListener() {
283 public void stateChanged(javax.swing.event.ChangeEvent evt) {
284 jCheckBoxLdapStateChanged(evt);
288 jLabel4.setText(bundle.getString("ApplicationUI.jLabel4.text")); // NOI18N
290 jLabel5.setText(bundle.getString("ApplicationUI.jLabel5.text")); // NOI18N
292 jLabel6.setText(bundle.getString("ApplicationUI.jLabel6.text")); // NOI18N
294 jTextFieldProviderUrl.setText(bundle.getString("ApplicationUI.jTextFieldProviderUrl.text")); // NOI18N
295 jTextFieldProviderUrl.setToolTipText(bundle.getString("ApplicationUI.jTextFieldProviderUrl.toolTipText")); // NOI18N
296 jTextFieldProviderUrl.setEnabled(false);
298 jTextFieldBaseDn.setText(bundle.getString("ApplicationUI.jTextFieldBaseDn.text")); // NOI18N
299 jTextFieldBaseDn.setToolTipText(bundle.getString("ApplicationUI.jTextFieldBaseDn.toolTipText")); // NOI18N
300 jTextFieldBaseDn.setEnabled(false);
302 jTextFieldAttribute.setText(bundle.getString("ApplicationUI.jTextFieldAttribute.text")); // NOI18N
303 jTextFieldAttribute.setToolTipText(bundle.getString("ApplicationUI.jTextFieldAttribute.toolTipText")); // NOI18N
304 jTextFieldAttribute.setEnabled(false);
306 jCheckBoxIsSjis.setText(bundle.getString("ApplicationUI.jCheckBoxIsSjis.text")); // NOI18N
307 jCheckBoxIsSjis.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxIsSjis.toolTipText")); // NOI18N
308 jCheckBoxIsSjis.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
309 jCheckBoxIsSjis.setEnabled(false);
310 jCheckBoxIsSjis.setMargin(new java.awt.Insets(0, 0, 0, 0));
312 org.jdesktop.layout.GroupLayout jPanelLDAPLayout = new org.jdesktop.layout.GroupLayout(jPanelLDAP);
313 jPanelLDAP.setLayout(jPanelLDAPLayout);
314 jPanelLDAPLayout.setHorizontalGroup(
315 jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
316 .add(jPanelLDAPLayout.createSequentialGroup()
317 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
318 .add(jPanelLDAPLayout.createSequentialGroup()
320 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
321 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel6)
322 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel5)
323 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4))
324 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
325 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
326 .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
327 .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
328 .add(jPanelLDAPLayout.createSequentialGroup()
329 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
330 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
331 .add(jCheckBoxIsSjis))))
332 .add(jPanelLDAPLayout.createSequentialGroup()
334 .add(jCheckBoxLdap)))
338 jPanelLDAPLayout.linkSize(new java.awt.Component[] {jLabel4, jLabel5, jLabel6}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
340 jPanelLDAPLayout.setVerticalGroup(
341 jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
342 .add(jPanelLDAPLayout.createSequentialGroup()
345 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
346 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
348 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
349 .add(jCheckBoxIsSjis))
350 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
351 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
353 .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
354 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
355 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
357 .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
358 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
361 jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelLDAP.TabConstraints.tabTitle"), null, jPanelLDAP, bundle.getString("ApplicationUI.jPanelLDAP.TabConstraints tabToolTip")); // NOI18N
363 jLabelProgramName.setFont(new java.awt.Font("Dialog", 1, 18));
364 jLabelProgramName.setText(bundle.getString("ApplicationUI.jLabelProgramName.text")); // NOI18N
366 jLabelProgramVersion.setFont(new java.awt.Font("Dialog", 1, 18));
367 jLabelProgramVersion.setText(bundle.getString("ApplicationUI.jLabelProgramVersion.text")); // NOI18N
369 jLabelSfURL.setFont(new java.awt.Font("Dialog", 1, 14));
370 jLabelSfURL.setText(bundle.getString("ApplicationUI.jLabelSfURL.text")); // NOI18N
372 org.jdesktop.layout.GroupLayout jPanelAboutLayout = new org.jdesktop.layout.GroupLayout(jPanelAbout);
373 jPanelAbout.setLayout(jPanelAboutLayout);
374 jPanelAboutLayout.setHorizontalGroup(
375 jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
376 .add(jPanelAboutLayout.createSequentialGroup()
377 .add(jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
378 .add(jPanelAboutLayout.createSequentialGroup()
380 .add(jLabelProgramName)
381 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
382 .add(jLabelProgramVersion))
383 .add(jPanelAboutLayout.createSequentialGroup()
386 .addContainerGap(38, Short.MAX_VALUE))
388 jPanelAboutLayout.setVerticalGroup(
389 jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
390 .add(jPanelAboutLayout.createSequentialGroup()
392 .add(jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
393 .add(jLabelProgramName)
394 .add(jLabelProgramVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
395 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
397 .addContainerGap(57, Short.MAX_VALUE))
400 jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelAbout.TabConstraints.tabTitle"), null, jPanelAbout, bundle.getString("ApplicationUI.jPanelAbout.TabConstraints tabToolTip")); // NOI18N
402 jButtonOK.setText(bundle.getString("ApplicationUI.jButtonOK.text")); // NOI18N
403 jButtonOK.setToolTipText(bundle.getString("ApplicationUI.jButtonOK.toolTipText")); // NOI18N
404 jButtonOK.addActionListener(new java.awt.event.ActionListener() {
405 public void actionPerformed(java.awt.event.ActionEvent evt) {
406 jButtonOKActionPerformed(evt);
410 jButtonCancel.setText(bundle.getString("ApplicationUI.jButtonCancel.text")); // NOI18N
411 jButtonCancel.setToolTipText(bundle.getString("ApplicationUI.jButtonCancel.toolTipText")); // NOI18N
412 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
413 public void actionPerformed(java.awt.event.ActionEvent evt) {
414 jButtonCancelActionPerformed(evt);
418 jButtonQuit.setText(bundle.getString("ApplicationUI.jButtonQuit.text")); // NOI18N
419 jButtonQuit.setToolTipText(bundle.getString("ApplicationUI.jButtonQuit.toolTipText")); // NOI18N
420 jButtonQuit.addActionListener(new java.awt.event.ActionListener() {
421 public void actionPerformed(java.awt.event.ActionEvent evt) {
422 jButtonQuitActionPerformed(evt);
426 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
427 getContentPane().setLayout(layout);
428 layout.setHorizontalGroup(
429 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
430 .add(layout.createSequentialGroup()
433 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 190, Short.MAX_VALUE)
435 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
438 .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
441 layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK, jButtonQuit}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
443 layout.setVerticalGroup(
444 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
445 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
446 .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
447 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
448 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
456 }// </editor-fold>//GEN-END:initComponents
458 private void formWindowDeiconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeiconified
459 setTitle(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.title"));
460 //If enable is can not input field anything in JRE1.4 on Windows. jButtonOK.requestFocusInWindow();
461 }//GEN-LAST:event_formWindowDeiconified
463 private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
464 setTitle(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.shortTitle"));
465 }//GEN-LAST:event_formWindowIconified
467 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
470 port = Integer.parseInt(jTextFieldReceiverPort.getText());
471 checkPortRange(port);
472 } catch (NumberFormatException ex) {
473 jTextFieldReceiverPort.setBackground(Color.PINK);
476 boolean enableRemoteConnect = jCheckBoxEnableRemoteConnect.isSelected();
478 String serverHost = jTextFieldServerHost.getText();
481 serverPort = Integer.parseInt(jTextFieldServerPort.getText());
482 checkPortRange(serverPort);
483 } catch (NumberFormatException ex) {
484 jTextFieldServerPort.setBackground(Color.PINK);
487 boolean serverSSL = jCheckBoxServerSSL.isSelected();
491 confirmTimeout = Integer.parseInt(jTextFieldConfirmTimeout.getText());
492 checkTimeoutRange(confirmTimeout);
493 } catch (NumberFormatException nfEx) {
494 jTextFieldConfirmTimeout.setBackground(Color.PINK);
498 boolean enableLdap = jCheckBoxLdap.isSelected();
499 String ldapUrl = jTextFieldProviderUrl.getText();
500 String rootDn = jTextFieldBaseDn.getText();
501 String attribute = jTextFieldAttribute.getText();
502 boolean isSjis = jCheckBoxIsSjis.isSelected();
504 if ( port != ApplicationProperties.getSmtpPort()
505 || enableRemoteConnect != ApplicationProperties.getSmtpEnebleRemoteConnect()
506 || !serverHost.equals(ApplicationProperties.getSmtpServerHost())
507 || serverPort != ApplicationProperties.getSmtpServerPort()
508 || serverSSL != ApplicationProperties.getSmtpServerSSL()
509 || confirmTimeout != ApplicationProperties.getConfirmTimeout()
510 || enableLdap != ApplicationProperties.getLdap()
511 || !ldapUrl.equals(ApplicationProperties.getLdapProviderURL())
512 || !rootDn.equals(ApplicationProperties.getLdapRoot())
513 || !attribute.equals(ApplicationProperties.getLdapAttributes())
514 || isSjis != ApplicationProperties.getLdapIsSjis()
515 || isModifiedPotition()
517 // When modify data, save properries file.
518 ApplicationProperties.setSmtpPort(port);
519 ApplicationProperties.setSmtpEnableRemoteConnect(enableRemoteConnect);
521 ApplicationProperties.setSmtpServerHost(serverHost);
522 ApplicationProperties.setSmtpServerPort(serverPort);
523 ApplicationProperties.setSmtpServerSSL(serverSSL);
525 ApplicationProperties.setConfirmTimeout(confirmTimeout);
527 ApplicationProperties.setLdap(enableLdap);
528 ApplicationProperties.setLdapProviderURL(ldapUrl);
529 ApplicationProperties.setLdapRoot(rootDn);
530 ApplicationProperties.setLdapAttributes(attribute);
531 ApplicationProperties.setLdapIsSjis(isSjis);
533 smtpClient.configChangeNotify();
534 if ( !ApplicationProperties.save() ) {
535 new MessageDialogUI(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.error.Fail_the_properties_file_save."), null,
536 MessageDialogUI.ERROR_MODE);
543 }//GEN-LAST:event_jButtonOKActionPerformed
546 * Time out second is need to positive number
548 private void checkTimeoutRange(final int confirmTimeout) throws NumberFormatException {
549 if ( confirmTimeout < 0 ) {
550 throw new NumberFormatException(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.exception.Timeout_need_to_a_positive_number"));
555 * Check port number range. It is unsigned short number.
556 * Argument is port number.
558 private void checkPortRange(final int port) {
559 if ( port <= 0 || port > 65535 ) {
560 throw new NumberFormatException(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.error.Out_of_range."));
564 private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed
566 }//GEN-LAST:event_jButtonQuitActionPerformed
568 private void jCheckBoxLdapStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxLdapStateChanged
569 boolean check = jCheckBoxLdap.isSelected();
570 jTextFieldProviderUrl.setEnabled(check);
571 jTextFieldBaseDn.setEnabled(check);
572 jTextFieldAttribute.setEnabled(check);
573 jCheckBoxIsSjis.setEnabled(check);
574 }//GEN-LAST:event_jCheckBoxLdapStateChanged
576 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
577 //this.setVisible(false);
579 if ( portNumberOutOfRangeErrorDialog != null && portNumberOutOfRangeErrorDialog.isVisible() ) {
580 portNumberOutOfRangeErrorDialog.dispose();
583 }//GEN-LAST:event_jButtonCancelActionPerformed
585 private void jCheckBoxServerSSLStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxServerSSLStateChanged
587 boolean check = jCheckBoxServerSSL.isSelected();
588 // smtp(port 25) and ssmpt(port 465) switch. cf. TLS/STARTTLS port 587
589 if ( check == true && jTextFieldServerPort.getText().equals("25") ) {
590 jTextFieldServerPort.setText("465");
591 }else if ( check == false && jTextFieldServerPort.getText().equals("465") ) {
592 jTextFieldServerPort.setText("25");
594 }//GEN-LAST:event_jCheckBoxServerSSLStateChanged
596 private void jTextFieldReceiverPortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldReceiverPortActionPerformed
597 // TODO add your handling code here:
598 }//GEN-LAST:event_jTextFieldReceiverPortActionPerformed
600 private boolean isModifiedPotition() {
603 if ( getExtendedState() == JFrame.NORMAL ) {
604 Point locationPoint = getLocationOnScreen(); //TODO: IllegalComponentStateException
608 //Unexpect logic. Because this method call from pushed "OK" button.
612 int h = this.getHeight();
613 int w = this.getWidth();
614 boolean modified = false;
616 if ( x != ApplicationProperties.getConfigDialogPosX()
617 || y != ApplicationProperties.getConfigDialogPosY()
618 || h != ApplicationProperties.getConfigDialogPosH()
619 || w != ApplicationProperties.getConfigDialogPosW()
622 ApplicationProperties.setConfigDialogPosX(x);
623 ApplicationProperties.setConfigDialogPosY(y);
624 ApplicationProperties.setConfigDialogPosH(h);
625 ApplicationProperties.setConfigDialogPosW(w);
631 private boolean initSystemTray() {
632 useSystemTray = false;
634 Class.forName("java.awt.SystemTray"); // NOI18N
635 /* SystemTray suuport */
636 final SystemTray tray = SystemTray.getSystemTray();
637 if(SystemTray.isSupported()){
638 final PopupMenu popup = new PopupMenu();
639 final TrayIcon trayIcon = new TrayIcon(loadImageIcon(),
640 java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.shortTitle"),
642 trayIcon.setImageAutoSize(true);
644 MenuItem menuItemOpen = new MenuItem(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.title"));
645 menuItemOpen.addActionListener(new ActionListener() {
646 public void actionPerformed(ActionEvent e) {
650 MenuItem menuItemQuit = new MenuItem(java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.jButtonQuit.text"));
651 menuItemQuit.addActionListener(new ActionListener() {
652 public void actionPerformed(ActionEvent e) {
653 tray.remove(trayIcon);
658 popup.add(menuItemOpen);
659 popup.add(menuItemQuit);
662 this.jButtonQuit.setVisible(false); //unvisible QUIT button.
663 useSystemTray = true;
666 } catch (AWTException ex) {
667 System.err.println("SystemTray initialize error.");
668 ex.printStackTrace();
669 } catch (ClassNotFoundException ex) {
670 // Do not support SystemTray on this VM.
671 } catch (NoClassDefFoundError ex) {
672 // Do not support SystemTray on this VM.
674 return useSystemTray;
677 private void iconified() {
678 if ( useSystemTray ) {
679 this.setVisible(false);
681 this.setExtendedState(ICONIFIED);
685 private void deicoified() {
686 if ( useSystemTray ) {
687 this.setVisible(true);
689 this.setExtendedState(NORMAL);
693 private Image loadImageIcon() {
694 ImageIcon imageIcon = new ImageIcon( getClass()
695 .getResource("images/mdc-icon16x16.png") // NOI18N
696 ,java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle").getString("ApplicationUI.jLabelProgramName.text"));
698 return imageIcon.getImage();
702 * @param args the command line arguments
704 public static void main(String args[]) {
707 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
708 } catch (Exception e) {
714 java.awt.EventQueue.invokeLater(new Runnable() {
716 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
717 ApplicationUI applicationUI = new ApplicationUI();
718 applicationUI.setVisible(true);
720 applicationUI.useSystemTray = applicationUI.initSystemTray();
722 //If exsist configuration file, iconise at start up.
723 if ( ApplicationProperties.isFileLoaded() ) {
724 int x = ApplicationProperties.getConfigDialogPosX();
725 int y = ApplicationProperties.getConfigDialogPosY();
726 int w = ApplicationProperties.getConfigDialogPosW();
727 int h = ApplicationProperties.getConfigDialogPosH();
729 if ( x > screenSize.width ) {
730 x = screenSize.width - w;
731 if ( x < 0 ) { x = 0; };
733 if ( y > screenSize.height ) {
734 y = screenSize.height - h;
735 if ( y < 0 ) { y = 0; };
737 applicationUI.setBounds(x, y, w, h);
738 applicationUI.iconified();
740 //No Configuration file.
741 Dimension frameSize = ApplicationProperties.getConfigurationDialogSize();
742 if (frameSize.height > screenSize.height) {
743 frameSize.height = screenSize.height;
745 if (frameSize.width > screenSize.width) {
746 frameSize.width = screenSize.width;
749 applicationUI.setBounds(
750 (screenSize.width - frameSize.width) / 2,
751 (screenSize.height - frameSize.height) / 2,
752 frameSize.width, frameSize.height );
756 smtpClient = new SMTPclient();
758 private static SMTPclient smtpClient = null;
759 private boolean useSystemTray = false;
761 // Variables declaration - do not modify//GEN-BEGIN:variables
762 private javax.swing.JButton jButtonCancel;
763 private javax.swing.JButton jButtonOK;
764 private javax.swing.JButton jButtonQuit;
765 private javax.swing.JCheckBox jCheckBoxEnableRemoteConnect;
766 private javax.swing.JCheckBox jCheckBoxIsSjis;
767 private javax.swing.JCheckBox jCheckBoxLdap;
768 private javax.swing.JCheckBox jCheckBoxServerSSL;
769 private javax.swing.JLabel jLabel1;
770 private javax.swing.JLabel jLabel2;
771 private javax.swing.JLabel jLabel3;
772 private javax.swing.JLabel jLabel4;
773 private javax.swing.JLabel jLabel5;
774 private javax.swing.JLabel jLabel6;
775 private javax.swing.JLabel jLabel7;
776 private javax.swing.JLabel jLabelProgramName;
777 private javax.swing.JLabel jLabelProgramVersion;
778 private javax.swing.JLabel jLabelSfURL;
779 private javax.swing.JPanel jPanelAbout;
780 private javax.swing.JPanel jPanelLDAP;
781 private javax.swing.JPanel jPanelMail;
782 private javax.swing.JTabbedPane jTabbedPane;
783 private javax.swing.JTextField jTextFieldAttribute;
784 private javax.swing.JTextField jTextFieldBaseDn;
785 private javax.swing.JTextField jTextFieldConfirmTimeout;
786 private javax.swing.JTextField jTextFieldProviderUrl;
787 private javax.swing.JTextField jTextFieldReceiverPort;
788 private javax.swing.JTextField jTextFieldServerHost;
789 private javax.swing.JTextField jTextFieldServerPort;
790 // End of variables declaration//GEN-END:variables