OSDN Git Service

Support: [ #25090 ] TLS/SSL SMTP server connection suuport. Ph.1
[mdc/BetaProject.git] / src / org / jent / checksmtp / ApplicationUI.java
1 /*
2  * ApplicationUI.java
3  *
4  * Created on 2007/07/21, 22:37
5  */
6
7 package org.jent.checksmtp;
8
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;
26
27 /**
28  *
29  * @author  Takuya Ono <takuya-o@users.sourceforge.jp>
30  */
31 public class ApplicationUI extends javax.swing.JFrame {
32   
33   /** Creates new form ApplicationUI */
34   public ApplicationUI() {
35     initComponents();
36     
37     //set Focus
38     jButtonOK.requestFocusInWindow();
39     //getRootPane().setDefaultButton(jButtonOK);
40     
41     resetDisplay();
42   }
43   
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()));
52     
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());
58     
59   }
60   
61   static private MessageDialogUI portNumberOutOfRangeErrorDialog = null;
62   class PortNumberInputVerifier extends  InputVerifier {
63     public boolean verify(JComponent jComponent) {
64       JTextField jTextField = (JTextField) jComponent;
65       boolean ret = true;
66       String input = jTextField.getText();
67       
68       try {
69         int port = Integer.parseInt(input);
70         checkPortRange(port);
71       } catch (Exception e) {
72         ret = false;
73       }
74       
75       if ( !ret ) {
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);
81         } else {
82           portNumberOutOfRangeErrorDialog.setVisible(true);
83         }
84       } else {
85         jTextField.setBackground(Color.WHITE);
86       }
87       
88       return ret;
89     }
90   }
91   
92   static private MessageDialogUI timeoutRangeErrorDialog = null;
93   class TimeoutNumberInputVerifier extends  InputVerifier {
94     public boolean verify(JComponent jComponent) {
95       JTextField jTextField = (JTextField) jComponent;
96       boolean ret = true;
97       String input = jTextField.getText();
98       
99       try {
100         int timeout = Integer.parseInt(input);
101         checkTimeoutRange(timeout);
102       } catch (Exception e) {
103         ret = false;
104       }
105       
106       if ( !ret ) {
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);
112         } else {
113           timeoutRangeErrorDialog.setVisible(true);
114         }
115       } else {
116         jTextField.setBackground(Color.WHITE);
117       }
118       
119       return ret;
120     }
121   }
122   
123   
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.
128    */
129   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
130   private void initComponents() {
131
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();
160
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);
168       }
169       public void windowIconified(java.awt.event.WindowEvent evt) {
170         formWindowIconified(evt);
171       }
172     });
173
174     jLabel1.setText(bundle.getString("ApplicationUI.jLabel1.text")); // NOI18N
175
176     jLabel2.setText(bundle.getString("ApplicationUI.jLabel2.text")); // NOI18N
177
178     jLabel3.setText(bundle.getString("ApplicationUI.jLabel3.text")); // NOI18N
179
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);
187       }
188     });
189
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));
193
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));
198
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));
203
204     jLabel7.setText(bundle.getString("ApplicationUI.jLabel7.text")); // NOI18N
205
206     jTextFieldConfirmTimeout.setText(bundle.getString("ApplicationUI.jTextFieldConfirmTimeout.text")); // NOI18N
207     jTextFieldConfirmTimeout.setToolTipText(bundle.getString("ApplicationUI.jTextFieldConfirmTimeout.toolTipText")); // NOI18N
208     jTextFieldConfirmTimeout.setInputVerifier(new TimeoutNumberInputVerifier()
209     );
210     jTextFieldConfirmTimeout.setMinimumSize(new java.awt.Dimension(1, 19));
211
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);
217       }
218     });
219
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()
225         .addContainerGap()
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()
230                 .add(jLabel7)
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()
234                 .add(jLabel1)
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()
240             .add(jLabel2)
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)
244             .add(jLabel3)
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())))
250     );
251
252     jPanelMailLayout.linkSize(new java.awt.Component[] {jLabel1, jLabel2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
253
254     jPanelMailLayout.setVerticalGroup(
255       jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
256       .add(jPanelMailLayout.createSequentialGroup()
257         .addContainerGap()
258         .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
259           .add(jLabel1)
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)
264           .add(jLabel2)
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)
268           .add(jLabel3))
269         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE)
270         .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
271           .add(jLabel7)
272           .add(jTextFieldConfirmTimeout, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
273         .addContainerGap())
274     );
275
276     jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelMail.TabConstraints.tabTitle"), null, jPanelMail, bundle.getString("ApplicationUI.jPanelMail.TabConstraints tabToolTip")); // NOI18N
277
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);
285       }
286     });
287
288     jLabel4.setText(bundle.getString("ApplicationUI.jLabel4.text")); // NOI18N
289
290     jLabel5.setText(bundle.getString("ApplicationUI.jLabel5.text")); // NOI18N
291
292     jLabel6.setText(bundle.getString("ApplicationUI.jLabel6.text")); // NOI18N
293
294     jTextFieldProviderUrl.setText(bundle.getString("ApplicationUI.jTextFieldProviderUrl.text")); // NOI18N
295     jTextFieldProviderUrl.setToolTipText(bundle.getString("ApplicationUI.jTextFieldProviderUrl.toolTipText")); // NOI18N
296     jTextFieldProviderUrl.setEnabled(false);
297
298     jTextFieldBaseDn.setText(bundle.getString("ApplicationUI.jTextFieldBaseDn.text")); // NOI18N
299     jTextFieldBaseDn.setToolTipText(bundle.getString("ApplicationUI.jTextFieldBaseDn.toolTipText")); // NOI18N
300     jTextFieldBaseDn.setEnabled(false);
301
302     jTextFieldAttribute.setText(bundle.getString("ApplicationUI.jTextFieldAttribute.text")); // NOI18N
303     jTextFieldAttribute.setToolTipText(bundle.getString("ApplicationUI.jTextFieldAttribute.toolTipText")); // NOI18N
304     jTextFieldAttribute.setEnabled(false);
305
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));
311
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()
319             .addContainerGap()
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()
333             .add(12, 12, 12)
334             .add(jCheckBoxLdap)))
335         .addContainerGap())
336     );
337
338     jPanelLDAPLayout.linkSize(new java.awt.Component[] {jLabel4, jLabel5, jLabel6}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
339
340     jPanelLDAPLayout.setVerticalGroup(
341       jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
342       .add(jPanelLDAPLayout.createSequentialGroup()
343         .addContainerGap()
344         .add(jCheckBoxLdap)
345         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
346         .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
347           .add(jLabel4)
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)
352           .add(jLabel5)
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)
356           .add(jLabel6)
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))
359     );
360
361     jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelLDAP.TabConstraints.tabTitle"), null, jPanelLDAP, bundle.getString("ApplicationUI.jPanelLDAP.TabConstraints tabToolTip")); // NOI18N
362
363     jLabelProgramName.setFont(new java.awt.Font("Dialog", 1, 18));
364     jLabelProgramName.setText(bundle.getString("ApplicationUI.jLabelProgramName.text")); // NOI18N
365
366     jLabelProgramVersion.setFont(new java.awt.Font("Dialog", 1, 18));
367     jLabelProgramVersion.setText(bundle.getString("ApplicationUI.jLabelProgramVersion.text")); // NOI18N
368
369     jLabelSfURL.setFont(new java.awt.Font("Dialog", 1, 14));
370     jLabelSfURL.setText(bundle.getString("ApplicationUI.jLabelSfURL.text")); // NOI18N
371
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()
379             .addContainerGap()
380             .add(jLabelProgramName)
381             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
382             .add(jLabelProgramVersion))
383           .add(jPanelAboutLayout.createSequentialGroup()
384             .add(55, 55, 55)
385             .add(jLabelSfURL)))
386         .addContainerGap(38, Short.MAX_VALUE))
387     );
388     jPanelAboutLayout.setVerticalGroup(
389       jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
390       .add(jPanelAboutLayout.createSequentialGroup()
391         .addContainerGap()
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)
396         .add(jLabelSfURL)
397         .addContainerGap(57, Short.MAX_VALUE))
398     );
399
400     jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelAbout.TabConstraints.tabTitle"), null, jPanelAbout, bundle.getString("ApplicationUI.jPanelAbout.TabConstraints tabToolTip")); // NOI18N
401
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);
407       }
408     });
409
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);
415       }
416     });
417
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);
423       }
424     });
425
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()
431         .addContainerGap()
432         .add(jButtonQuit)
433         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 190, Short.MAX_VALUE)
434         .add(jButtonOK)
435         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
436         .add(jButtonCancel)
437         .addContainerGap())
438       .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
439     );
440
441     layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK, jButtonQuit}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
442
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)
449           .add(jButtonQuit)
450           .add(jButtonCancel)
451           .add(jButtonOK))
452         .addContainerGap())
453     );
454
455     pack();
456   }// </editor-fold>//GEN-END:initComponents
457   
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
462   
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
466   
467   private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
468     int port;
469     try {
470       port = Integer.parseInt(jTextFieldReceiverPort.getText());
471       checkPortRange(port);
472     } catch (NumberFormatException ex) {
473       jTextFieldReceiverPort.setBackground(Color.PINK);
474       throw ex;
475     }
476     boolean enableRemoteConnect = jCheckBoxEnableRemoteConnect.isSelected();
477
478     String serverHost = jTextFieldServerHost.getText();
479     int serverPort;
480     try {
481       serverPort = Integer.parseInt(jTextFieldServerPort.getText());
482       checkPortRange(serverPort);
483     } catch (NumberFormatException ex) {
484       jTextFieldServerPort.setBackground(Color.PINK);
485       throw ex;
486     }
487     boolean serverSSL = jCheckBoxServerSSL.isSelected();
488
489     int confirmTimeout;
490     try {
491       confirmTimeout = Integer.parseInt(jTextFieldConfirmTimeout.getText());
492       checkTimeoutRange(confirmTimeout);
493     } catch (NumberFormatException nfEx) {
494       jTextFieldConfirmTimeout.setBackground(Color.PINK);
495       throw nfEx;
496     }
497         
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();
503     
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()
516     ) {
517       // When modify data, save properries file.
518       ApplicationProperties.setSmtpPort(port);
519       ApplicationProperties.setSmtpEnableRemoteConnect(enableRemoteConnect);
520
521       ApplicationProperties.setSmtpServerHost(serverHost);
522       ApplicationProperties.setSmtpServerPort(serverPort);
523       ApplicationProperties.setSmtpServerSSL(serverSSL);
524
525       ApplicationProperties.setConfirmTimeout(confirmTimeout);
526       
527       ApplicationProperties.setLdap(enableLdap);
528       ApplicationProperties.setLdapProviderURL(ldapUrl);
529       ApplicationProperties.setLdapRoot(rootDn);
530       ApplicationProperties.setLdapAttributes(attribute);
531       ApplicationProperties.setLdapIsSjis(isSjis);
532       
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);
537       } else {
538         iconified();
539       }
540     } else {
541       iconified();
542     }
543   }//GEN-LAST:event_jButtonOKActionPerformed
544
545   /**
546    * Time out second is need to positive number
547    */
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"));
551     }
552   }
553   
554   /**
555    *  Check port number range. It is unsigned short number.
556    *  Argument is port number.
557    **/
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."));
561     }
562   }
563   
564   private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed
565     System.exit(0);
566   }//GEN-LAST:event_jButtonQuitActionPerformed
567   
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
575   
576   private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
577     //this.setVisible(false);
578     resetDisplay();
579     if ( portNumberOutOfRangeErrorDialog != null && portNumberOutOfRangeErrorDialog.isVisible() ) {
580       portNumberOutOfRangeErrorDialog.dispose();
581     }
582     iconified();
583   }//GEN-LAST:event_jButtonCancelActionPerformed
584
585   private void jCheckBoxServerSSLStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxServerSSLStateChanged
586     // takuya-o
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");
593     }
594   }//GEN-LAST:event_jCheckBoxServerSSLStateChanged
595
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
599   
600   private boolean isModifiedPotition() {
601     int x = 0;
602     int y = 0;
603     if ( getExtendedState() == JFrame.NORMAL ) {
604       Point locationPoint = getLocationOnScreen(); //TODO: IllegalComponentStateException
605       x = locationPoint.x;
606       y = locationPoint.y;
607     } else {
608       //Unexpect logic. Because this method call from pushed "OK" button.
609       x = getX();
610       y = getY();
611     }
612     int h = this.getHeight();
613     int w = this.getWidth();
614     boolean modified = false;
615     
616     if ( x != ApplicationProperties.getConfigDialogPosX()
617     || y != ApplicationProperties.getConfigDialogPosY()
618     || h != ApplicationProperties.getConfigDialogPosH()
619     || w != ApplicationProperties.getConfigDialogPosW()
620     ) {
621       modified = true;
622       ApplicationProperties.setConfigDialogPosX(x);
623       ApplicationProperties.setConfigDialogPosY(y);
624       ApplicationProperties.setConfigDialogPosH(h);
625       ApplicationProperties.setConfigDialogPosW(w);
626     }
627     return modified;
628   }
629   
630   
631   private boolean initSystemTray() {
632     useSystemTray = false;
633     try {
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"),
641           popup);
642         trayIcon.setImageAutoSize(true);
643        
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) {
647             deicoified();
648           }
649         });
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);
654             dispose();
655             System.exit(0);
656           }
657         });
658         popup.add(menuItemOpen);
659         popup.add(menuItemQuit);
660         tray.add(trayIcon);
661        
662         this.jButtonQuit.setVisible(false); //unvisible QUIT button.
663         useSystemTray = true;
664       }
665        /**/
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.
673     }
674     return useSystemTray;
675   }
676   
677   private void iconified() {
678     if ( useSystemTray ) {
679       this.setVisible(false);
680     } else {
681       this.setExtendedState(ICONIFIED);
682     }
683   }
684   
685   private void deicoified() {
686     if ( useSystemTray ) {
687       this.setVisible(true);
688     } else {
689       this.setExtendedState(NORMAL);
690     } 
691   }
692   
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"));
697     
698     return imageIcon.getImage();
699   }
700   
701   /**
702    * @param args the command line arguments
703    */
704   public static void main(String args[]) {
705     /* TKYN OLD
706     try {
707       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
708     } catch (Exception e) {
709       e.printStackTrace();
710     }
711      */
712     
713     //TKYN ORIGNAL BLOCK
714     java.awt.EventQueue.invokeLater(new Runnable() {
715       public void run() {
716         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
717         ApplicationUI applicationUI = new ApplicationUI();
718         applicationUI.setVisible(true);
719         
720         applicationUI.useSystemTray = applicationUI.initSystemTray();
721         
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();
728           
729           if ( x > screenSize.width ) {
730             x = screenSize.width - w;
731             if ( x < 0 ) { x = 0; };
732           }
733           if ( y > screenSize.height ) {
734             y = screenSize.height - h;
735             if ( y < 0 ) { y = 0; };
736           }
737           applicationUI.setBounds(x, y, w, h);
738           applicationUI.iconified();
739         } else {
740           //No Configuration file.
741           Dimension frameSize =  ApplicationProperties.getConfigurationDialogSize();
742           if (frameSize.height > screenSize.height) {
743             frameSize.height = screenSize.height;
744           }
745           if (frameSize.width > screenSize.width) {
746             frameSize.width = screenSize.width;
747           }
748           
749           applicationUI.setBounds(
750                   (screenSize.width - frameSize.width) / 2,
751                   (screenSize.height - frameSize.height) / 2,
752                   frameSize.width, frameSize.height );
753         }
754       }
755     });
756     smtpClient = new SMTPclient();
757   }
758   private static SMTPclient smtpClient = null;
759   private boolean useSystemTray = false;
760   
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
791   
792 }