4 * Created on 2007/07/21, 22:37
7 package org.jent.checksmtp;
9 import java.awt.Dimension;
10 import java.awt.Toolkit;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ActionListener;
16 * @author Takuya Ono <takuya-o@users.sourceforge.jp>
18 public class ApplicationUI extends javax.swing.JFrame {
20 /** Creates new form ApplicationUI */
21 public ApplicationUI() {
27 private void resetDisplay() {
28 jTextFieldReceiverPort.setText(Integer.toString(ApplicationProperties.getSmtpPort()));
29 jTextFieldServerHost.setText(ApplicationProperties.getSmtpServerHost());
30 jTextFieldServerPort.setText(Integer.toString(ApplicationProperties.getSmtpServerPort()));
31 jCheckBoxEnableRemoteConnect.setSelected(ApplicationProperties.getSmtpEnebleRemoteConnect());
33 jCheckBoxLdap.setSelected(ApplicationProperties.getLdap());
34 jTextFieldProviderUrl.setText(ApplicationProperties.getLdapProviderURL());
35 jTextFieldBaseDn.setText(ApplicationProperties.getLdapRoot());
36 jTextFieldAttribute.setText(ApplicationProperties.getLdapAttributes());
37 jCheckBoxIsSjis.setSelected(ApplicationProperties.getLdapIsSjis());
42 /** This method is called from within the constructor to
43 * initialize the form.
44 * WARNING: Do NOT modify this code. The content of this method is
45 * always regenerated by the Form Editor.
47 // <editor-fold defaultstate="collapsed" desc=" Generated Code">//GEN-BEGIN:initComponents
48 private void initComponents() {
49 jTabbedPane = new javax.swing.JTabbedPane();
50 jPanelMail = new javax.swing.JPanel();
51 jLabel1 = new javax.swing.JLabel();
52 jLabel2 = new javax.swing.JLabel();
53 jLabel3 = new javax.swing.JLabel();
54 jTextFieldReceiverPort = new javax.swing.JTextField();
55 jTextFieldServerHost = new javax.swing.JTextField();
56 jTextFieldServerPort = new javax.swing.JTextField();
57 jCheckBoxEnableRemoteConnect = new javax.swing.JCheckBox();
58 jPanelLDAP = new javax.swing.JPanel();
59 jCheckBoxLdap = new javax.swing.JCheckBox();
60 jLabel4 = new javax.swing.JLabel();
61 jLabel5 = new javax.swing.JLabel();
62 jLabel6 = new javax.swing.JLabel();
63 jTextFieldProviderUrl = new javax.swing.JTextField();
64 jTextFieldBaseDn = new javax.swing.JTextField();
65 jTextFieldAttribute = new javax.swing.JTextField();
66 jCheckBoxIsSjis = new javax.swing.JCheckBox();
67 jButtonOK = new javax.swing.JButton();
68 jButtonCancel = new javax.swing.JButton();
69 jButtonQuit = new javax.swing.JButton();
71 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
72 setTitle("Mail Destination Confirm Properties");
73 addWindowListener(new java.awt.event.WindowAdapter() {
74 public void windowDeiconified(java.awt.event.WindowEvent evt) {
75 formWindowDeiconified(evt);
77 public void windowIconified(java.awt.event.WindowEvent evt) {
78 formWindowIconified(evt);
82 jLabel1.setText("Receiver Port:");
84 jLabel2.setText("Mail Server:");
86 jLabel3.setText("Port:");
88 jTextFieldReceiverPort.setText("8725");
89 jTextFieldReceiverPort.setToolTipText("Mail Destination Confirmer SMTP port number.");
91 jTextFieldServerHost.setText("mail");
92 jTextFieldServerHost.setToolTipText("Mail server host name or IP address.");
94 jTextFieldServerPort.setText("25");
95 jTextFieldServerPort.setToolTipText("Mail server port number.");
97 jCheckBoxEnableRemoteConnect.setText("Enable remote connect");
98 jCheckBoxEnableRemoteConnect.setToolTipText("Enable remote machine access this service. (Usually: disable)");
99 jCheckBoxEnableRemoteConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
100 jCheckBoxEnableRemoteConnect.setMargin(new java.awt.Insets(0, 0, 0, 0));
102 org.jdesktop.layout.GroupLayout jPanelMailLayout = new org.jdesktop.layout.GroupLayout(jPanelMail);
103 jPanelMail.setLayout(jPanelMailLayout);
104 jPanelMailLayout.setHorizontalGroup(
105 jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
106 .add(jPanelMailLayout.createSequentialGroup()
108 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
109 .add(jPanelMailLayout.createSequentialGroup()
111 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
112 .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
113 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
114 .add(jCheckBoxEnableRemoteConnect))
115 .add(jPanelMailLayout.createSequentialGroup()
117 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
118 .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
119 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
121 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
122 .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
126 jPanelMailLayout.linkSize(new java.awt.Component[] {jLabel1, jLabel2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
128 jPanelMailLayout.setVerticalGroup(
129 jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
130 .add(jPanelMailLayout.createSequentialGroup()
132 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
134 .add(jCheckBoxEnableRemoteConnect)
135 .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
136 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
137 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
140 .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
141 .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
142 .addContainerGap(74, Short.MAX_VALUE))
144 jTabbedPane.addTab("Mail", jPanelMail);
146 jCheckBoxLdap.setText("Enable LDAP search");
147 jCheckBoxLdap.setToolTipText("Enable LDAP configration.");
148 jCheckBoxLdap.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
149 jCheckBoxLdap.setMargin(new java.awt.Insets(0, 0, 0, 0));
150 jCheckBoxLdap.addChangeListener(new javax.swing.event.ChangeListener() {
151 public void stateChanged(javax.swing.event.ChangeEvent evt) {
152 jCheckBoxLdapStateChanged(evt);
156 jLabel4.setText("URL:");
158 jLabel5.setText("Root DN:");
160 jLabel6.setText("Attribute:");
162 jTextFieldProviderUrl.setText("ldap://localhost:389/");
163 jTextFieldProviderUrl.setToolTipText("LDAP server URL.");
164 jTextFieldProviderUrl.setEnabled(false);
166 jTextFieldBaseDn.setText("C=JP");
167 jTextFieldBaseDn.setToolTipText("LDAP search start DN.");
168 jTextFieldBaseDn.setEnabled(false);
170 jTextFieldAttribute.setText("cn");
171 jTextFieldAttribute.setToolTipText("Display Attribuite. Example: cn title;lang-ja-jp");
172 jTextFieldAttribute.setEnabled(false);
174 jCheckBoxIsSjis.setText("Force SJIS");
175 jCheckBoxIsSjis.setToolTipText("Check this, when LDAP server use Shift JIS on network.");
176 jCheckBoxIsSjis.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
177 jCheckBoxIsSjis.setEnabled(false);
178 jCheckBoxIsSjis.setMargin(new java.awt.Insets(0, 0, 0, 0));
180 org.jdesktop.layout.GroupLayout jPanelLDAPLayout = new org.jdesktop.layout.GroupLayout(jPanelLDAP);
181 jPanelLDAP.setLayout(jPanelLDAPLayout);
182 jPanelLDAPLayout.setHorizontalGroup(
183 jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184 .add(jPanelLDAPLayout.createSequentialGroup()
185 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
186 .add(jPanelLDAPLayout.createSequentialGroup()
188 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
189 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel6)
190 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel5)
191 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4))
192 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
193 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
194 .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
195 .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
196 .add(jPanelLDAPLayout.createSequentialGroup()
197 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
198 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
199 .add(jCheckBoxIsSjis))))
200 .add(jPanelLDAPLayout.createSequentialGroup()
202 .add(jCheckBoxLdap)))
206 jPanelLDAPLayout.linkSize(new java.awt.Component[] {jLabel4, jLabel5, jLabel6}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
208 jPanelLDAPLayout.setVerticalGroup(
209 jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
210 .add(jPanelLDAPLayout.createSequentialGroup()
213 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
214 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
216 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
217 .add(jCheckBoxIsSjis))
218 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
219 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
221 .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
222 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
223 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
225 .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
226 .addContainerGap(28, Short.MAX_VALUE))
228 jTabbedPane.addTab("LDAP", jPanelLDAP);
230 jButtonOK.setText("OK");
231 jButtonOK.addActionListener(new java.awt.event.ActionListener() {
232 public void actionPerformed(java.awt.event.ActionEvent evt) {
233 jButtonOKActionPerformed(evt);
237 jButtonCancel.setText("Cancel");
238 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
239 public void actionPerformed(java.awt.event.ActionEvent evt) {
240 jButtonCancelActionPerformed(evt);
244 jButtonQuit.setText("Quit");
245 jButtonQuit.addActionListener(new java.awt.event.ActionListener() {
246 public void actionPerformed(java.awt.event.ActionEvent evt) {
247 jButtonQuitActionPerformed(evt);
251 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
252 getContentPane().setLayout(layout);
253 layout.setHorizontalGroup(
254 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
256 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
259 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 145, Short.MAX_VALUE)
261 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
266 layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK, jButtonQuit}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
268 layout.setVerticalGroup(
269 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
270 .add(layout.createSequentialGroup()
272 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
273 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
280 }// </editor-fold>//GEN-END:initComponents
282 private void formWindowDeiconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeiconified
283 setTitle("Mail Destination Confirm Properties");
284 }//GEN-LAST:event_formWindowDeiconified
286 private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
288 }//GEN-LAST:event_formWindowIconified
290 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
293 port = Integer.parseInt(jTextFieldReceiverPort.getText());
294 } catch (NumberFormatException ex) {
295 ex.printStackTrace();
296 port = ApplicationProperties.getSmtpPort(); //last saved value.
297 jTextFieldReceiverPort.setText(Integer.toString(port));
299 String serverHost = jTextFieldServerHost.getText();
302 serverPort = Integer.parseInt(jTextFieldServerPort.getText());
303 } catch (NumberFormatException ex) {
304 ex.printStackTrace();
305 serverPort = ApplicationProperties.getSmtpServerPort(); //last saved value.
306 jTextFieldServerPort.setText(Integer.toString(serverPort));
308 boolean enableRemoteConnect = jCheckBoxEnableRemoteConnect.isSelected();
310 boolean enableLdap = jCheckBoxLdap.isSelected();
311 String ldapUrl = jTextFieldProviderUrl.getText();
312 String rootDn = jTextFieldBaseDn.getText();
313 String attribute = jTextFieldAttribute.getText();
314 boolean isSjis = jCheckBoxIsSjis.isSelected();
316 if ( port != ApplicationProperties.getSmtpPort()
317 || !serverHost.equals(ApplicationProperties.getSmtpServerHost())
318 || serverPort != ApplicationProperties.getSmtpServerPort()
319 || enableRemoteConnect != ApplicationProperties.getSmtpEnebleRemoteConnect()
321 || enableLdap != ApplicationProperties.getLdap()
322 || !ldapUrl.equals(ApplicationProperties.getLdapProviderURL())
323 || !rootDn.equals(ApplicationProperties.getLdapRoot())
324 || !attribute.equals(ApplicationProperties.getLdapAttributes())
325 || isSjis != ApplicationProperties.getLdapIsSjis()
326 || isModifiedPotition()
328 // When modify data, save properries file.
329 ApplicationProperties.setSmtpPort(port);
330 ApplicationProperties.setSmtpServerHost(serverHost);
331 ApplicationProperties.setSmtpServerPort(serverPort);
332 ApplicationProperties.setSmtpEnableRemoteConnect(enableRemoteConnect);
334 ApplicationProperties.setLdap(enableLdap);
335 ApplicationProperties.setLdapProviderURL(ldapUrl);
336 ApplicationProperties.setLdapRoot(rootDn);
337 ApplicationProperties.setLdapAttributes(attribute);
338 ApplicationProperties.setLdapIsSjis(isSjis);
340 smtpClient.configChangeNotify();
341 if ( !ApplicationProperties.save() ) {
342 //TODO: Display Save error Dialog.
347 }//GEN-LAST:event_jButtonOKActionPerformed
349 private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed
351 }//GEN-LAST:event_jButtonQuitActionPerformed
353 private void jCheckBoxLdapStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxLdapStateChanged
354 // TODO add your handling code here:
355 boolean check = jCheckBoxLdap.isSelected();
356 jTextFieldProviderUrl.setEnabled(check);
357 jTextFieldBaseDn.setEnabled(check);
358 jTextFieldAttribute.setEnabled(check);
359 jCheckBoxIsSjis.setEnabled(check);
360 }//GEN-LAST:event_jCheckBoxLdapStateChanged
362 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
363 // TODO add your handling code here:
364 //this.setVisible(false);
367 }//GEN-LAST:event_jButtonCancelActionPerformed
369 private boolean isModifiedPotition() {
370 int x = this.getX(); //TODO: get real potition on screen.
372 int h = this.getHeight();
373 int w = this.getWidth();
374 boolean modified = false;
376 if ( x != ApplicationProperties.getConfigDialogPosX()
377 || y != ApplicationProperties.getConfigDialogPosY()
378 || h != ApplicationProperties.getConfigDialogPosH()
379 || w != ApplicationProperties.getConfigDialogPosW()
382 ApplicationProperties.setConfigDialogPosX(x);
383 ApplicationProperties.setConfigDialogPosY(y);
384 ApplicationProperties.setConfigDialogPosH(h);
385 ApplicationProperties.setConfigDialogPosW(w);
391 private boolean initSystemTray() {
392 boolean useSystemTray = false;
394 Class.forName("java.awt.SystemTray");
395 /* TODO: SystemTray suuport
396 java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray();
397 if(tray.isSupported()){
398 java.awt.TrayIcon trayIcon = new java.awt.TrayIcon(
399 new javax.swing.ImageIcon(
400 SystemTrayTest.class.getResource("images/mdc.gif")).getImage());
401 trayIcon.setImageAutoSize(true);
403 // create a action listener to listen for default action executed on the tray icon
404 ActionListener listener = new ActionListener() {
405 public void actionPerformed(ActionEvent e) {
406 // execute default action of the application
407 if ( e.paramString().equal("Quit")) {
411 if ( this.getExtendedState() == ICONIFIED ) {
412 this.setExtendedState(NORMAL);
417 java.awt.PopupMenu popup = new java.awt.PopupMenu();
418 popup.addActionListener(listener);
421 trayIcon.setPopupMenu(popup);
423 useSystemTray = true;
426 } catch (ClassNotFoundException ex) {
427 // Do not support SystemTray on this VM.
429 return useSystemTray;
432 private void iconified() {
433 if ( useSystemTray ) {
434 this.setVisible(false);
436 this.setExtendedState(ICONIFIED);
441 * @param args the command line arguments
443 public static void main(String args[]) {
446 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
447 } catch (Exception e) {
453 java.awt.EventQueue.invokeLater(new Runnable() {
455 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
456 ApplicationUI applicationUI = new ApplicationUI();
457 applicationUI.setVisible(true);
459 applicationUI.useSystemTray = applicationUI.initSystemTray();
461 //If exsist configuration file, iconise at start up.
462 if ( ApplicationProperties.isFileLoaded() ) {
463 int x = ApplicationProperties.getConfigDialogPosX();
464 int y = ApplicationProperties.getConfigDialogPosY();
465 int w = ApplicationProperties.getConfigDialogPosW();
466 int h = ApplicationProperties.getConfigDialogPosH();
468 if ( x > screenSize.width ) {
469 x = screenSize.width - w;
470 if ( x < 0 ) { x = 0; };
472 if ( y > screenSize.height ) {
473 y = screenSize.height - h;
474 if ( y < 0 ) { y = 0; };
476 applicationUI.setBounds(x, y, w, h);
477 applicationUI.iconified();
479 //No Configuration file.
480 Dimension frameSize = ApplicationProperties.getConfigurationDialogSize();
481 if (frameSize.height > screenSize.height) {
482 frameSize.height = screenSize.height;
484 if (frameSize.width > screenSize.width) {
485 frameSize.width = screenSize.width;
488 applicationUI.setBounds(
489 (screenSize.width - frameSize.width) / 2,
490 (screenSize.height - frameSize.height) / 2,
491 frameSize.width, frameSize.height );
496 smtpClient = new SMTPclient();
498 private static SMTPclient smtpClient = null;
499 private boolean useSystemTray = false;
501 // Variables declaration - do not modify//GEN-BEGIN:variables
502 private javax.swing.JButton jButtonCancel;
503 private javax.swing.JButton jButtonOK;
504 private javax.swing.JButton jButtonQuit;
505 private javax.swing.JCheckBox jCheckBoxEnableRemoteConnect;
506 private javax.swing.JCheckBox jCheckBoxIsSjis;
507 private javax.swing.JCheckBox jCheckBoxLdap;
508 private javax.swing.JLabel jLabel1;
509 private javax.swing.JLabel jLabel2;
510 private javax.swing.JLabel jLabel3;
511 private javax.swing.JLabel jLabel4;
512 private javax.swing.JLabel jLabel5;
513 private javax.swing.JLabel jLabel6;
514 private javax.swing.JPanel jPanelLDAP;
515 private javax.swing.JPanel jPanelMail;
516 private javax.swing.JTabbedPane jTabbedPane;
517 private javax.swing.JTextField jTextFieldAttribute;
518 private javax.swing.JTextField jTextFieldBaseDn;
519 private javax.swing.JTextField jTextFieldProviderUrl;
520 private javax.swing.JTextField jTextFieldReceiverPort;
521 private javax.swing.JTextField jTextFieldServerHost;
522 private javax.swing.JTextField jTextFieldServerPort;
523 // End of variables declaration//GEN-END:variables