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 Dest. Confirm Properties");
73 addComponentListener(new java.awt.event.ComponentAdapter() {
74 public void componentHidden(java.awt.event.ComponentEvent evt) {
75 formComponentHidden(evt);
79 jLabel1.setText("Receiver Port:");
81 jLabel2.setText("Mail Server:");
83 jLabel3.setText("Port:");
85 jTextFieldReceiverPort.setText("8725");
86 jTextFieldReceiverPort.setToolTipText("Mail Destination Confirmer SMTP port number.");
88 jTextFieldServerHost.setText("mail");
89 jTextFieldServerHost.setToolTipText("Mail server host name or IP address.");
91 jTextFieldServerPort.setText("25");
92 jTextFieldServerPort.setToolTipText("Mail server port number.");
94 jCheckBoxEnableRemoteConnect.setText("Enable remote connect");
95 jCheckBoxEnableRemoteConnect.setToolTipText("Enable remote machine access this service. (Usually: disable)");
96 jCheckBoxEnableRemoteConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
97 jCheckBoxEnableRemoteConnect.setMargin(new java.awt.Insets(0, 0, 0, 0));
99 org.jdesktop.layout.GroupLayout jPanelMailLayout = new org.jdesktop.layout.GroupLayout(jPanelMail);
100 jPanelMail.setLayout(jPanelMailLayout);
101 jPanelMailLayout.setHorizontalGroup(
102 jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
103 .add(jPanelMailLayout.createSequentialGroup()
105 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
106 .add(jPanelMailLayout.createSequentialGroup()
108 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
109 .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
110 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
111 .add(jCheckBoxEnableRemoteConnect))
112 .add(jPanelMailLayout.createSequentialGroup()
114 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
115 .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
116 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
118 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
119 .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
123 jPanelMailLayout.linkSize(new java.awt.Component[] {jLabel1, jLabel2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
125 jPanelMailLayout.setVerticalGroup(
126 jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
127 .add(jPanelMailLayout.createSequentialGroup()
129 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
131 .add(jCheckBoxEnableRemoteConnect)
132 .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
133 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
134 .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
137 .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
138 .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
139 .addContainerGap(74, Short.MAX_VALUE))
141 jTabbedPane.addTab("Mail", jPanelMail);
143 jCheckBoxLdap.setText("Enable LDAP search");
144 jCheckBoxLdap.setToolTipText("Enable LDAP configration.");
145 jCheckBoxLdap.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
146 jCheckBoxLdap.setMargin(new java.awt.Insets(0, 0, 0, 0));
147 jCheckBoxLdap.addChangeListener(new javax.swing.event.ChangeListener() {
148 public void stateChanged(javax.swing.event.ChangeEvent evt) {
149 jCheckBoxLdapStateChanged(evt);
153 jLabel4.setText("URL:");
155 jLabel5.setText("Root DN:");
157 jLabel6.setText("Attribuite:");
159 jTextFieldProviderUrl.setText("ldap://localhost:389/");
160 jTextFieldProviderUrl.setToolTipText("LDAP server URL.");
161 jTextFieldProviderUrl.setEnabled(false);
163 jTextFieldBaseDn.setText("C=JP");
164 jTextFieldBaseDn.setToolTipText("LDAP search start DN.");
165 jTextFieldBaseDn.setEnabled(false);
167 jTextFieldAttribute.setText("cn");
168 jTextFieldAttribute.setToolTipText("Display Attribuite. Example: cn title;lang-ja-jp");
169 jTextFieldAttribute.setEnabled(false);
171 jCheckBoxIsSjis.setText("Force SJIS");
172 jCheckBoxIsSjis.setToolTipText("Check this, when LDAP server use Shift JIS on network.");
173 jCheckBoxIsSjis.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
174 jCheckBoxIsSjis.setEnabled(false);
175 jCheckBoxIsSjis.setMargin(new java.awt.Insets(0, 0, 0, 0));
177 org.jdesktop.layout.GroupLayout jPanelLDAPLayout = new org.jdesktop.layout.GroupLayout(jPanelLDAP);
178 jPanelLDAP.setLayout(jPanelLDAPLayout);
179 jPanelLDAPLayout.setHorizontalGroup(
180 jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
181 .add(jPanelLDAPLayout.createSequentialGroup()
182 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
183 .add(jPanelLDAPLayout.createSequentialGroup()
185 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
186 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel6)
187 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel5)
188 .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4))
189 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
190 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
191 .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
192 .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
193 .add(jPanelLDAPLayout.createSequentialGroup()
194 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
195 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
196 .add(jCheckBoxIsSjis))))
197 .add(jPanelLDAPLayout.createSequentialGroup()
199 .add(jCheckBoxLdap)))
203 jPanelLDAPLayout.linkSize(new java.awt.Component[] {jLabel4, jLabel5, jLabel6}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
205 jPanelLDAPLayout.setVerticalGroup(
206 jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
207 .add(jPanelLDAPLayout.createSequentialGroup()
210 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
211 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
213 .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
214 .add(jCheckBoxIsSjis))
215 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
216 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
218 .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
219 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
220 .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
222 .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
223 .addContainerGap(28, Short.MAX_VALUE))
225 jTabbedPane.addTab("LDAP", jPanelLDAP);
227 jButtonOK.setText("OK");
228 jButtonOK.addActionListener(new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 jButtonOKActionPerformed(evt);
234 jButtonCancel.setText("Cancel");
235 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
236 public void actionPerformed(java.awt.event.ActionEvent evt) {
237 jButtonCancelActionPerformed(evt);
241 jButtonQuit.setText("Quit");
242 jButtonQuit.addActionListener(new java.awt.event.ActionListener() {
243 public void actionPerformed(java.awt.event.ActionEvent evt) {
244 jButtonQuitActionPerformed(evt);
248 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
249 getContentPane().setLayout(layout);
250 layout.setHorizontalGroup(
251 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
252 .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
253 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
256 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 145, Short.MAX_VALUE)
258 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
263 layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK, jButtonQuit}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
265 layout.setVerticalGroup(
266 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
267 .add(layout.createSequentialGroup()
268 .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
269 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
270 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
277 }// </editor-fold>//GEN-END:initComponents
279 private void formComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentHidden
280 // TODO add your handling code here:
281 }//GEN-LAST:event_formComponentHidden
283 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
286 port = Integer.parseInt(jTextFieldReceiverPort.getText());
287 } catch (NumberFormatException ex) {
288 ex.printStackTrace();
289 port = ApplicationProperties.getSmtpPort(); //last saved value.
290 jTextFieldReceiverPort.setText(Integer.toString(port));
292 String serverHost = jTextFieldServerHost.getText();
295 serverPort = Integer.parseInt(jTextFieldServerPort.getText());
296 } catch (NumberFormatException ex) {
297 ex.printStackTrace();
298 serverPort = ApplicationProperties.getSmtpServerPort(); //last saved value.
299 jTextFieldServerPort.setText(Integer.toString(serverPort));
301 boolean enableRemoteConnect = jCheckBoxEnableRemoteConnect.isSelected();
303 boolean enableLdap = jCheckBoxLdap.isSelected();
304 String ldapUrl = jTextFieldProviderUrl.getText();
305 String rootDn = jTextFieldBaseDn.getText();
306 String attribute = jTextFieldAttribute.getText();
307 boolean isSjis = jCheckBoxIsSjis.isSelected();
309 if ( port != ApplicationProperties.getSmtpPort()
310 || !serverHost.equals(ApplicationProperties.getSmtpServerHost())
311 || serverPort != ApplicationProperties.getSmtpServerPort()
312 || enableRemoteConnect != ApplicationProperties.getSmtpEnebleRemoteConnect()
314 || enableLdap != ApplicationProperties.getLdap()
315 || !ldapUrl.equals(ApplicationProperties.getLdapProviderURL())
316 || !rootDn.equals(ApplicationProperties.getLdapRoot())
317 || !attribute.equals(ApplicationProperties.getLdapAttributes())
318 || isSjis != ApplicationProperties.getLdapIsSjis()
319 || isModifiedPotition()
321 // When modify data, save properries file.
322 ApplicationProperties.setSmtpPort(port);
323 ApplicationProperties.setSmtpServerHost(serverHost);
324 ApplicationProperties.setSmtpServerPort(serverPort);
325 ApplicationProperties.setSmtpEnableRemoteConnect(enableRemoteConnect);
327 ApplicationProperties.setLdap(enableLdap);
328 ApplicationProperties.setLdapProviderURL(ldapUrl);
329 ApplicationProperties.setLdapRoot(rootDn);
330 ApplicationProperties.setLdapAttributes(attribute);
331 ApplicationProperties.setLdapIsSjis(isSjis);
333 smtpClient.configChangeNotify();
334 if ( !ApplicationProperties.save() ) {
335 //TODO: Display Save error Dialog.
340 }//GEN-LAST:event_jButtonOKActionPerformed
342 private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed
344 }//GEN-LAST:event_jButtonQuitActionPerformed
346 private void jCheckBoxLdapStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxLdapStateChanged
347 // TODO add your handling code here:
348 boolean check = jCheckBoxLdap.isSelected();
349 jTextFieldProviderUrl.setEnabled(check);
350 jTextFieldBaseDn.setEnabled(check);
351 jTextFieldAttribute.setEnabled(check);
352 jCheckBoxIsSjis.setEnabled(check);
353 }//GEN-LAST:event_jCheckBoxLdapStateChanged
355 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
356 // TODO add your handling code here:
357 //this.setVisible(false);
360 }//GEN-LAST:event_jButtonCancelActionPerformed
362 private boolean isModifiedPotition() {
363 int x = this.getX(); //TODO: get real potition on screen.
365 int h = this.getHeight();
366 int w = this.getWidth();
367 boolean modified = false;
369 if ( x != ApplicationProperties.getConfigDialogPosX()
370 || y != ApplicationProperties.getConfigDialogPosY()
371 || h != ApplicationProperties.getConfigDialogPosH()
372 || w != ApplicationProperties.getConfigDialogPosW()
375 ApplicationProperties.setConfigDialogPosX(x);
376 ApplicationProperties.setConfigDialogPosY(y);
377 ApplicationProperties.setConfigDialogPosH(h);
378 ApplicationProperties.setConfigDialogPosW(w);
384 private boolean initSystemTray() {
385 boolean useSystemTray = false;
387 Class.forName("java.awt.SystemTray");
388 /* TODO: SystemTray suuport
389 java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray();
390 if(tray.isSupported()){
391 java.awt.TrayIcon trayIcon = new java.awt.TrayIcon(
392 new javax.swing.ImageIcon(
393 SystemTrayTest.class.getResource("images/mdc.gif")).getImage());
394 trayIcon.setImageAutoSize(true);
396 // create a action listener to listen for default action executed on the tray icon
397 ActionListener listener = new ActionListener() {
398 public void actionPerformed(ActionEvent e) {
399 // execute default action of the application
400 if ( e.paramString().equal("Quit")) {
404 if ( this.getExtendedState() == ICONIFIED ) {
405 this.setExtendedState(NORMAL);
410 java.awt.PopupMenu popup = new java.awt.PopupMenu();
411 popup.addActionListener(listener);
414 trayIcon.setPopupMenu(popup);
416 useSystemTray = true;
419 } catch (ClassNotFoundException ex) {
420 // Do not support SystemTray on this VM.
422 return useSystemTray;
425 private void iconified() {
426 if ( useSystemTray ) {
427 this.setVisible(false);
429 this.setExtendedState(ICONIFIED);
434 * @param args the command line arguments
436 public static void main(String args[]) {
439 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
440 } catch (Exception e) {
446 java.awt.EventQueue.invokeLater(new Runnable() {
448 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
449 ApplicationUI applicationUI = new ApplicationUI();
450 applicationUI.setVisible(true);
452 applicationUI.useSystemTray = applicationUI.initSystemTray();
454 //If exsist configuration file, iconise at start up.
455 if ( ApplicationProperties.isFileLoaded() ) {
456 int x = ApplicationProperties.getConfigDialogPosX();
457 int y = ApplicationProperties.getConfigDialogPosY();
458 int w = ApplicationProperties.getConfigDialogPosW();
459 int h = ApplicationProperties.getConfigDialogPosH();
461 if ( x > screenSize.width ) {
462 x = screenSize.width - w;
463 if ( x < 0 ) { x = 0; };
465 if ( y > screenSize.height ) {
466 y = screenSize.height - h;
467 if ( y < 0 ) { y = 0; };
469 applicationUI.setBounds(x, y, w, h);
470 applicationUI.iconified();
472 //No Configuration file.
473 Dimension frameSize = ApplicationProperties.getConfigurationDialogSize();
474 if (frameSize.height > screenSize.height) {
475 frameSize.height = screenSize.height;
477 if (frameSize.width > screenSize.width) {
478 frameSize.width = screenSize.width;
481 applicationUI.setBounds(
482 (screenSize.width - frameSize.width) / 2,
483 (screenSize.height - frameSize.height) / 2,
484 frameSize.width, frameSize.height );
489 smtpClient = new SMTPclient();
491 private static SMTPclient smtpClient = null;
492 private boolean useSystemTray = false;
494 // Variables declaration - do not modify//GEN-BEGIN:variables
495 private javax.swing.JButton jButtonCancel;
496 private javax.swing.JButton jButtonOK;
497 private javax.swing.JButton jButtonQuit;
498 private javax.swing.JCheckBox jCheckBoxEnableRemoteConnect;
499 private javax.swing.JCheckBox jCheckBoxIsSjis;
500 private javax.swing.JCheckBox jCheckBoxLdap;
501 private javax.swing.JLabel jLabel1;
502 private javax.swing.JLabel jLabel2;
503 private javax.swing.JLabel jLabel3;
504 private javax.swing.JLabel jLabel4;
505 private javax.swing.JLabel jLabel5;
506 private javax.swing.JLabel jLabel6;
507 private javax.swing.JPanel jPanelLDAP;
508 private javax.swing.JPanel jPanelMail;
509 private javax.swing.JTabbedPane jTabbedPane;
510 private javax.swing.JTextField jTextFieldAttribute;
511 private javax.swing.JTextField jTextFieldBaseDn;
512 private javax.swing.JTextField jTextFieldProviderUrl;
513 private javax.swing.JTextField jTextFieldReceiverPort;
514 private javax.swing.JTextField jTextFieldServerHost;
515 private javax.swing.JTextField jTextFieldServerPort;
516 // End of variables declaration//GEN-END:variables