OSDN Git Service

ADD: Support about tab, it described program name and version.
[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.Color;
10 import java.awt.Dimension;
11 import java.awt.Point;
12 import java.awt.Toolkit;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import javax.swing.InputVerifier;
16 import javax.swing.JComponent;
17 import javax.swing.JFrame;
18 import javax.swing.JTextField;
19
20 /**
21  *
22  * @author  Takuya Ono <takuya-o@users.sourceforge.jp>
23  */
24 public class ApplicationUI extends javax.swing.JFrame {
25   
26   /** Creates new form ApplicationUI */
27   public ApplicationUI() {
28     initComponents();
29     
30     //set Focus
31     jButtonOK.requestFocusInWindow();
32     //getRootPane().setDefaultButton(jButtonOK);
33     
34     resetDisplay();
35   }
36   
37   private void resetDisplay() {
38     jTextFieldReceiverPort.setText(Integer.toString(ApplicationProperties.getSmtpPort()));
39     jTextFieldServerHost.setText(ApplicationProperties.getSmtpServerHost());
40     jTextFieldServerPort.setText(Integer.toString(ApplicationProperties.getSmtpServerPort()));
41     jCheckBoxEnableRemoteConnect.setSelected(ApplicationProperties.getSmtpEnebleRemoteConnect());
42     
43     jCheckBoxLdap.setSelected(ApplicationProperties.getLdap());
44     jTextFieldProviderUrl.setText(ApplicationProperties.getLdapProviderURL());
45     jTextFieldBaseDn.setText(ApplicationProperties.getLdapRoot());
46     jTextFieldAttribute.setText(ApplicationProperties.getLdapAttributes());
47     jCheckBoxIsSjis.setSelected(ApplicationProperties.getLdapIsSjis());
48     
49   }
50   
51   static private MessageDialogUI portNumberOutOfRangeErrorDialog = null;
52   class PortNumberInputVerifier extends  InputVerifier {
53     public boolean verify(JComponent jComponent) {
54       JTextField jTextField = (JTextField) jComponent;
55       boolean ret = true;
56       String input = jTextField.getText();
57       
58       try {
59         int port = Integer.parseInt(input);
60         checkPortRange(port);
61       } catch (Exception e) {
62         ret = false;
63       }
64       
65       if ( !ret ) {
66         jTextField.setBackground(Color.PINK);
67         if ( portNumberOutOfRangeErrorDialog == null ) {
68           portNumberOutOfRangeErrorDialog = 
69                   new MessageDialogUI("Port number is integer from 1 to 65535.",
70                   null, MessageDialogUI.WARNING_MODE);
71         } else {
72           portNumberOutOfRangeErrorDialog.setVisible(true);
73         }
74       } else {
75         jTextField.setBackground(Color.WHITE);
76       }
77       
78       return ret;
79     }
80   }
81   
82   /** This method is called from within the constructor to
83    * initialize the form.
84    * WARNING: Do NOT modify this code. The content of this method is
85    * always regenerated by the Form Editor.
86    */
87   // <editor-fold defaultstate="collapsed" desc=" Generated Code">//GEN-BEGIN:initComponents
88   private void initComponents() {
89     jTabbedPane = new javax.swing.JTabbedPane();
90     jPanelMail = new javax.swing.JPanel();
91     jLabel1 = new javax.swing.JLabel();
92     jLabel2 = new javax.swing.JLabel();
93     jLabel3 = new javax.swing.JLabel();
94     jTextFieldReceiverPort = new javax.swing.JTextField();
95     jTextFieldServerHost = new javax.swing.JTextField();
96     jTextFieldServerPort = new javax.swing.JTextField();
97     jCheckBoxEnableRemoteConnect = new javax.swing.JCheckBox();
98     jPanelLDAP = new javax.swing.JPanel();
99     jCheckBoxLdap = new javax.swing.JCheckBox();
100     jLabel4 = new javax.swing.JLabel();
101     jLabel5 = new javax.swing.JLabel();
102     jLabel6 = new javax.swing.JLabel();
103     jTextFieldProviderUrl = new javax.swing.JTextField();
104     jTextFieldBaseDn = new javax.swing.JTextField();
105     jTextFieldAttribute = new javax.swing.JTextField();
106     jCheckBoxIsSjis = new javax.swing.JCheckBox();
107     jPanelAbout = new javax.swing.JPanel();
108     jLabelProgramName = new javax.swing.JLabel();
109     jLabelProgramVersion = new javax.swing.JLabel();
110     jLabelSfURL = new javax.swing.JLabel();
111     jButtonOK = new javax.swing.JButton();
112     jButtonCancel = new javax.swing.JButton();
113     jButtonQuit = new javax.swing.JButton();
114
115     setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
116     java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle"); // NOI18N
117     setTitle(bundle.getString("ApplicationUI.title")); // NOI18N
118     addWindowListener(new java.awt.event.WindowAdapter() {
119       public void windowDeiconified(java.awt.event.WindowEvent evt) {
120         formWindowDeiconified(evt);
121       }
122       public void windowIconified(java.awt.event.WindowEvent evt) {
123         formWindowIconified(evt);
124       }
125     });
126
127     jLabel1.setText(bundle.getString("ApplicationUI.jLabel1.text")); // NOI18N
128
129     jLabel2.setText(bundle.getString("ApplicationUI.jLabel2.text")); // NOI18N
130
131     jLabel3.setText(bundle.getString("ApplicationUI.jLabel3.text")); // NOI18N
132
133     jTextFieldReceiverPort.setText(bundle.getString("ApplicationUI.jTextFieldReceiverPort.text")); // NOI18N
134     jTextFieldReceiverPort.setToolTipText(bundle.getString("ApplicationUI.jTextFieldReceiverPort.toolTipText")); // NOI18N
135     jTextFieldReceiverPort.setInputVerifier(new PortNumberInputVerifier());
136
137     jTextFieldServerHost.setText(bundle.getString("ApplicationUI.jTextFieldServerHost.text")); // NOI18N
138     jTextFieldServerHost.setToolTipText(bundle.getString("ApplicationUI.jTextFieldServerHost.toolTipText")); // NOI18N
139
140     jTextFieldServerPort.setText(bundle.getString("ApplicationUI.jTextFieldServerPort.text")); // NOI18N
141     jTextFieldServerPort.setToolTipText(bundle.getString("ApplicationUI.jTextFieldServerPort.toolTipText")); // NOI18N
142     jTextFieldServerPort.setInputVerifier(new PortNumberInputVerifier());
143
144     jCheckBoxEnableRemoteConnect.setText(bundle.getString("ApplicationUI.jCheckBoxEnableRemoteConnect.text")); // NOI18N
145     jCheckBoxEnableRemoteConnect.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxEnableRemoteConnect.toolTipText")); // NOI18N
146     jCheckBoxEnableRemoteConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
147     jCheckBoxEnableRemoteConnect.setMargin(new java.awt.Insets(0, 0, 0, 0));
148
149     org.jdesktop.layout.GroupLayout jPanelMailLayout = new org.jdesktop.layout.GroupLayout(jPanelMail);
150     jPanelMail.setLayout(jPanelMailLayout);
151     jPanelMailLayout.setHorizontalGroup(
152       jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153       .add(jPanelMailLayout.createSequentialGroup()
154         .addContainerGap()
155         .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
156           .add(jPanelMailLayout.createSequentialGroup()
157             .add(jLabel1)
158             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
159             .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
160             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
161             .add(jCheckBoxEnableRemoteConnect))
162           .add(jPanelMailLayout.createSequentialGroup()
163             .add(jLabel2)
164             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
165             .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
166             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
167             .add(jLabel3)
168             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
169             .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
170         .addContainerGap())
171     );
172
173     jPanelMailLayout.linkSize(new java.awt.Component[] {jLabel1, jLabel2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
174
175     jPanelMailLayout.setVerticalGroup(
176       jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
177       .add(jPanelMailLayout.createSequentialGroup()
178         .addContainerGap()
179         .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
180           .add(jLabel1)
181           .add(jCheckBoxEnableRemoteConnect)
182           .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
183         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
184         .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
185           .add(jLabel2)
186           .add(jLabel3)
187           .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
188           .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
189         .addContainerGap(58, Short.MAX_VALUE))
190     );
191     jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelMail.TabConstraints.tabTitle"), jPanelMail); // NOI18N
192
193     jCheckBoxLdap.setText(bundle.getString("ApplicationUI.jCheckBoxLdap.text")); // NOI18N
194     jCheckBoxLdap.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxLdap.toolTipText")); // NOI18N
195     jCheckBoxLdap.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
196     jCheckBoxLdap.setMargin(new java.awt.Insets(0, 0, 0, 0));
197     jCheckBoxLdap.addChangeListener(new javax.swing.event.ChangeListener() {
198       public void stateChanged(javax.swing.event.ChangeEvent evt) {
199         jCheckBoxLdapStateChanged(evt);
200       }
201     });
202
203     jLabel4.setText(bundle.getString("ApplicationUI.jLabel4.text")); // NOI18N
204
205     jLabel5.setText(bundle.getString("ApplicationUI.jLabel5.text")); // NOI18N
206
207     jLabel6.setText(bundle.getString("ApplicationUI.jLabel6.text")); // NOI18N
208
209     jTextFieldProviderUrl.setText(bundle.getString("ApplicationUI.jTextFieldProviderUrl.text")); // NOI18N
210     jTextFieldProviderUrl.setToolTipText(bundle.getString("ApplicationUI.jTextFieldProviderUrl.toolTipText")); // NOI18N
211     jTextFieldProviderUrl.setEnabled(false);
212
213     jTextFieldBaseDn.setText(bundle.getString("ApplicationUI.jTextFieldBaseDn.text")); // NOI18N
214     jTextFieldBaseDn.setToolTipText(bundle.getString("ApplicationUI.jTextFieldBaseDn.toolTipText")); // NOI18N
215     jTextFieldBaseDn.setEnabled(false);
216
217     jTextFieldAttribute.setText(bundle.getString("ApplicationUI.jTextFieldAttribute.text")); // NOI18N
218     jTextFieldAttribute.setToolTipText(bundle.getString("ApplicationUI.jTextFieldAttribute.toolTipText")); // NOI18N
219     jTextFieldAttribute.setEnabled(false);
220
221     jCheckBoxIsSjis.setText(bundle.getString("ApplicationUI.jCheckBoxIsSjis.text")); // NOI18N
222     jCheckBoxIsSjis.setToolTipText(bundle.getString("ApplicationUI.jCheckBoxIsSjis.toolTipText")); // NOI18N
223     jCheckBoxIsSjis.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
224     jCheckBoxIsSjis.setEnabled(false);
225     jCheckBoxIsSjis.setMargin(new java.awt.Insets(0, 0, 0, 0));
226
227     org.jdesktop.layout.GroupLayout jPanelLDAPLayout = new org.jdesktop.layout.GroupLayout(jPanelLDAP);
228     jPanelLDAP.setLayout(jPanelLDAPLayout);
229     jPanelLDAPLayout.setHorizontalGroup(
230       jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
231       .add(jPanelLDAPLayout.createSequentialGroup()
232         .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
233           .add(jPanelLDAPLayout.createSequentialGroup()
234             .addContainerGap()
235             .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
236               .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel6)
237               .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel5)
238               .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4))
239             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
240             .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
241               .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
242               .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
243               .add(jPanelLDAPLayout.createSequentialGroup()
244                 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
245                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
246                 .add(jCheckBoxIsSjis))))
247           .add(jPanelLDAPLayout.createSequentialGroup()
248             .add(12, 12, 12)
249             .add(jCheckBoxLdap)))
250         .addContainerGap())
251     );
252
253     jPanelLDAPLayout.linkSize(new java.awt.Component[] {jLabel4, jLabel5, jLabel6}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
254
255     jPanelLDAPLayout.setVerticalGroup(
256       jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
257       .add(jPanelLDAPLayout.createSequentialGroup()
258         .addContainerGap()
259         .add(jCheckBoxLdap)
260         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
261         .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
262           .add(jLabel4)
263           .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
264           .add(jCheckBoxIsSjis))
265         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
266         .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
267           .add(jLabel5)
268           .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
269         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
270         .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
271           .add(jLabel6)
272           .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
273         .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
274     );
275     jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelLDAP.TabConstraints.tabTitle"), jPanelLDAP); // NOI18N
276
277     jLabelProgramName.setFont(new java.awt.Font("Dialog", 1, 18));
278     jLabelProgramName.setText(bundle.getString("ApplicationUI.jLabelProgramName.text")); // NOI18N
279
280     jLabelProgramVersion.setFont(new java.awt.Font("Dialog", 1, 18));
281     jLabelProgramVersion.setText(bundle.getString("ApplicationUI.jLabelProgramVersion.text")); // NOI18N
282
283     jLabelSfURL.setFont(new java.awt.Font("Dialog", 1, 14));
284     jLabelSfURL.setText(bundle.getString("ApplicationUI.jLabelSfURL.text")); // NOI18N
285
286     org.jdesktop.layout.GroupLayout jPanelAboutLayout = new org.jdesktop.layout.GroupLayout(jPanelAbout);
287     jPanelAbout.setLayout(jPanelAboutLayout);
288     jPanelAboutLayout.setHorizontalGroup(
289       jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
290       .add(jPanelAboutLayout.createSequentialGroup()
291         .add(jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
292           .add(jPanelAboutLayout.createSequentialGroup()
293             .addContainerGap()
294             .add(jLabelProgramName)
295             .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
296             .add(jLabelProgramVersion))
297           .add(jPanelAboutLayout.createSequentialGroup()
298             .add(55, 55, 55)
299             .add(jLabelSfURL)))
300         .addContainerGap(35, Short.MAX_VALUE))
301     );
302     jPanelAboutLayout.setVerticalGroup(
303       jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
304       .add(jPanelAboutLayout.createSequentialGroup()
305         .addContainerGap()
306         .add(jPanelAboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
307           .add(jLabelProgramName)
308           .add(jLabelProgramVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
309         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
310         .add(jLabelSfURL)
311         .addContainerGap(57, Short.MAX_VALUE))
312     );
313     jTabbedPane.addTab(bundle.getString("ApplicationUI.jPanelAbout.TabConstraints.tabTitle"), jPanelAbout); // NOI18N
314
315     jButtonOK.setText(bundle.getString("ApplicationUI.jButtonOK.text")); // NOI18N
316     jButtonOK.setToolTipText(bundle.getString("ApplicationUI.jButtonOK.toolTipText")); // NOI18N
317     jButtonOK.addActionListener(new java.awt.event.ActionListener() {
318       public void actionPerformed(java.awt.event.ActionEvent evt) {
319         jButtonOKActionPerformed(evt);
320       }
321     });
322
323     jButtonCancel.setText(bundle.getString("ApplicationUI.jButtonCancel.text")); // NOI18N
324     jButtonCancel.setToolTipText(bundle.getString("ApplicationUI.jButtonCancel.toolTipText")); // NOI18N
325     jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
326       public void actionPerformed(java.awt.event.ActionEvent evt) {
327         jButtonCancelActionPerformed(evt);
328       }
329     });
330
331     jButtonQuit.setText(bundle.getString("ApplicationUI.jButtonQuit.text")); // NOI18N
332     jButtonQuit.setToolTipText(bundle.getString("ApplicationUI.jButtonQuit.toolTipText")); // NOI18N
333     jButtonQuit.addActionListener(new java.awt.event.ActionListener() {
334       public void actionPerformed(java.awt.event.ActionEvent evt) {
335         jButtonQuitActionPerformed(evt);
336       }
337     });
338
339     org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
340     getContentPane().setLayout(layout);
341     layout.setHorizontalGroup(
342       layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
343       .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
344       .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
345         .addContainerGap()
346         .add(jButtonQuit)
347         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 145, Short.MAX_VALUE)
348         .add(jButtonOK)
349         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
350         .add(jButtonCancel)
351         .addContainerGap())
352     );
353
354     layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK, jButtonQuit}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
355
356     layout.setVerticalGroup(
357       layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
358       .add(layout.createSequentialGroup()
359         .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
360         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
361         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
362           .add(jButtonCancel)
363           .add(jButtonOK)
364           .add(jButtonQuit))
365         .addContainerGap())
366     );
367     pack();
368   }// </editor-fold>//GEN-END:initComponents
369   
370   private void formWindowDeiconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeiconified
371     setTitle("Mail Destination Confirm Properties");
372     jButtonOK.requestFocusInWindow();
373   }//GEN-LAST:event_formWindowDeiconified
374   
375   private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
376     setTitle("mdc");
377   }//GEN-LAST:event_formWindowIconified
378   
379   private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
380     int port;
381     try {
382       port = Integer.parseInt(jTextFieldReceiverPort.getText());
383       checkPortRange(port);
384     } catch (NumberFormatException ex) {
385       jTextFieldReceiverPort.setBackground(Color.PINK);
386       throw ex;
387     }
388     String serverHost = jTextFieldServerHost.getText();
389     int serverPort;
390     try {
391       serverPort = Integer.parseInt(jTextFieldServerPort.getText());
392       checkPortRange(serverPort);
393     } catch (NumberFormatException ex) {
394       jTextFieldServerPort.setBackground(Color.PINK);
395       throw ex;
396     }
397     boolean enableRemoteConnect = jCheckBoxEnableRemoteConnect.isSelected();
398     
399     boolean enableLdap = jCheckBoxLdap.isSelected();
400     String ldapUrl = jTextFieldProviderUrl.getText();
401     String rootDn = jTextFieldBaseDn.getText();
402     String attribute = jTextFieldAttribute.getText();
403     boolean isSjis = jCheckBoxIsSjis.isSelected();
404     
405     if ( port != ApplicationProperties.getSmtpPort()
406     || !serverHost.equals(ApplicationProperties.getSmtpServerHost())
407     || serverPort != ApplicationProperties.getSmtpServerPort()
408     || enableRemoteConnect != ApplicationProperties.getSmtpEnebleRemoteConnect()
409     
410     || enableLdap != ApplicationProperties.getLdap()
411     || !ldapUrl.equals(ApplicationProperties.getLdapProviderURL())
412     || !rootDn.equals(ApplicationProperties.getLdapRoot())
413     || !attribute.equals(ApplicationProperties.getLdapAttributes())
414     || isSjis != ApplicationProperties.getLdapIsSjis()
415     || isModifiedPotition()
416     ) {
417       // When modify data, save properries file.
418       ApplicationProperties.setSmtpPort(port);
419       ApplicationProperties.setSmtpServerHost(serverHost);
420       ApplicationProperties.setSmtpServerPort(serverPort);
421       ApplicationProperties.setSmtpEnableRemoteConnect(enableRemoteConnect);
422       
423       ApplicationProperties.setLdap(enableLdap);
424       ApplicationProperties.setLdapProviderURL(ldapUrl);
425       ApplicationProperties.setLdapRoot(rootDn);
426       ApplicationProperties.setLdapAttributes(attribute);
427       ApplicationProperties.setLdapIsSjis(isSjis);
428       
429       smtpClient.configChangeNotify();
430       if ( !ApplicationProperties.save() ) {
431         new MessageDialogUI("Fail the properties file save.", null,
432                 MessageDialogUI.ERROR_MODE);
433       } else {
434         iconified();
435       }
436     } else {
437       iconified();
438     }
439   }//GEN-LAST:event_jButtonOKActionPerformed
440
441   /**
442    *  Check port number range. It is unsigned short number.
443    *  Argument is port number.
444    **/
445   private void checkPortRange(final int port) {
446     if ( port <= 0 || port > 65535 ) {
447       throw new NumberFormatException("Out of range.");
448     }
449   }
450   
451   private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed
452     System.exit(0);
453   }//GEN-LAST:event_jButtonQuitActionPerformed
454   
455   private void jCheckBoxLdapStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxLdapStateChanged
456     boolean check = jCheckBoxLdap.isSelected();
457     jTextFieldProviderUrl.setEnabled(check);
458     jTextFieldBaseDn.setEnabled(check);
459     jTextFieldAttribute.setEnabled(check);
460     jCheckBoxIsSjis.setEnabled(check);
461   }//GEN-LAST:event_jCheckBoxLdapStateChanged
462   
463   private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
464     //this.setVisible(false);
465     resetDisplay();
466     if ( portNumberOutOfRangeErrorDialog != null && portNumberOutOfRangeErrorDialog.isVisible() ) {
467       portNumberOutOfRangeErrorDialog.dispose();
468     }
469     iconified();
470   }//GEN-LAST:event_jButtonCancelActionPerformed
471   
472   private boolean isModifiedPotition() {
473     int x = 0;
474     int y = 0;
475     if ( getExtendedState() == JFrame.NORMAL ) {
476       Point locationPoint = getLocationOnScreen(); //TODO: IllegalComponentStateException
477       x = locationPoint.x;
478       y = locationPoint.y;
479     } else {
480       //Unexpect logic. Because this method call from pushed "OK" button.
481       x = getX();
482       y = getY();
483     }
484     int h = this.getHeight();
485     int w = this.getWidth();
486     boolean modified = false;
487     
488     if ( x != ApplicationProperties.getConfigDialogPosX()
489     || y != ApplicationProperties.getConfigDialogPosY()
490     || h != ApplicationProperties.getConfigDialogPosH()
491     || w != ApplicationProperties.getConfigDialogPosW()
492     ) {
493       modified = true;
494       ApplicationProperties.setConfigDialogPosX(x);
495       ApplicationProperties.setConfigDialogPosY(y);
496       ApplicationProperties.setConfigDialogPosH(h);
497       ApplicationProperties.setConfigDialogPosW(w);
498     }
499     return modified;
500   }
501   
502   
503   private boolean initSystemTray() {
504     boolean useSystemTray = false;
505     try {
506       Class.forName("java.awt.SystemTray");
507       /* TODO: SystemTray suuport
508       java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray();
509       if(tray.isSupported()){
510         java.awt.TrayIcon trayIcon = new java.awt.TrayIcon(
511                 new javax.swing.ImageIcon(
512                 SystemTrayTest.class.getResource("images/mdc.gif")).getImage());
513         trayIcon.setImageAutoSize(true);
514        
515         // create a action listener to listen for default action executed on the tray icon
516         ActionListener listener = new ActionListener() {
517           public void actionPerformed(ActionEvent e) {
518             // execute default action of the application
519             if ( e.paramString().equal("Quit")) {
520               System.exit(0);
521             } else {
522               setVisible(true);
523               if ( this.getExtendedState() == ICONIFIED ) {
524                 this.setExtendedState(NORMAL);
525               }
526             }
527           }
528         };
529         java.awt.PopupMenu popup = new java.awt.PopupMenu();
530         popup.addActionListener(listener);
531         popup.add("Config");
532         popup.add("Quit");
533         trayIcon.setPopupMenu(popup);
534         tray.add(trayIcon);
535         useSystemTray = true;
536      }
537        */
538     } catch (ClassNotFoundException ex) {
539       // Do not support SystemTray on this VM.
540     }
541     return useSystemTray;
542   }
543   
544   private void iconified() {
545     if ( useSystemTray ) {
546       this.setVisible(false);
547     } else {
548       this.setExtendedState(ICONIFIED);
549     }
550   }
551   
552   /**
553    * @param args the command line arguments
554    */
555   public static void main(String args[]) {
556     /* TKYN OLD
557     try {
558       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
559     } catch (Exception e) {
560       e.printStackTrace();
561     }
562      */
563     
564     //TKYN ORIGNAL BLOCK
565     java.awt.EventQueue.invokeLater(new Runnable() {
566       public void run() {
567         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
568         ApplicationUI applicationUI = new ApplicationUI();
569         applicationUI.setVisible(true);
570         
571         applicationUI.useSystemTray = applicationUI.initSystemTray();
572         
573         //If exsist configuration file, iconise at start up.
574         if ( ApplicationProperties.isFileLoaded() ) {
575           int x = ApplicationProperties.getConfigDialogPosX();
576           int y = ApplicationProperties.getConfigDialogPosY();
577           int w = ApplicationProperties.getConfigDialogPosW();
578           int h = ApplicationProperties.getConfigDialogPosH();
579           
580           if ( x > screenSize.width ) {
581             x = screenSize.width - w;
582             if ( x < 0 ) { x = 0; };
583           }
584           if ( y > screenSize.height ) {
585             y = screenSize.height - h;
586             if ( y < 0 ) { y = 0; };
587           }
588           applicationUI.setBounds(x, y, w, h);
589           applicationUI.iconified();
590         } else {
591           //No Configuration file.
592           Dimension frameSize =  ApplicationProperties.getConfigurationDialogSize();
593           if (frameSize.height > screenSize.height) {
594             frameSize.height = screenSize.height;
595           }
596           if (frameSize.width > screenSize.width) {
597             frameSize.width = screenSize.width;
598           }
599           
600           applicationUI.setBounds(
601                   (screenSize.width - frameSize.width) / 2,
602                   (screenSize.height - frameSize.height) / 2,
603                   frameSize.width, frameSize.height );
604         }
605       }
606     });
607     
608     smtpClient = new SMTPclient();
609   }
610   private static SMTPclient smtpClient = null;
611   private boolean useSystemTray = false;
612   
613   // Variables declaration - do not modify//GEN-BEGIN:variables
614   private javax.swing.JButton jButtonCancel;
615   private javax.swing.JButton jButtonOK;
616   private javax.swing.JButton jButtonQuit;
617   private javax.swing.JCheckBox jCheckBoxEnableRemoteConnect;
618   private javax.swing.JCheckBox jCheckBoxIsSjis;
619   private javax.swing.JCheckBox jCheckBoxLdap;
620   private javax.swing.JLabel jLabel1;
621   private javax.swing.JLabel jLabel2;
622   private javax.swing.JLabel jLabel3;
623   private javax.swing.JLabel jLabel4;
624   private javax.swing.JLabel jLabel5;
625   private javax.swing.JLabel jLabel6;
626   private javax.swing.JLabel jLabelProgramName;
627   private javax.swing.JLabel jLabelProgramVersion;
628   private javax.swing.JLabel jLabelSfURL;
629   private javax.swing.JPanel jPanelAbout;
630   private javax.swing.JPanel jPanelLDAP;
631   private javax.swing.JPanel jPanelMail;
632   private javax.swing.JTabbedPane jTabbedPane;
633   private javax.swing.JTextField jTextFieldAttribute;
634   private javax.swing.JTextField jTextFieldBaseDn;
635   private javax.swing.JTextField jTextFieldProviderUrl;
636   private javax.swing.JTextField jTextFieldReceiverPort;
637   private javax.swing.JTextField jTextFieldServerHost;
638   private javax.swing.JTextField jTextFieldServerPort;
639   // End of variables declaration//GEN-END:variables
640   
641 }