From 081af71ddb8e840be3bb04ac8c05f477d6c1512e Mon Sep 17 00:00:00 2001 From: takuya-o Date: Sun, 22 Jul 2007 07:56:30 +0000 Subject: [PATCH] Change IDE JDeveloper to NetBeans 5.5. Support configuration screen. Support Quit operation from configuration frame. Req#5596 --- .cvsignore | 3 + build.xml | 69 +++ manifest.mf | 3 + nbproject/.cvsignore | 1 + nbproject/build-impl.xml | 541 ++++++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 59 +++ nbproject/project.xml | 16 + src/org/jent/checksmtp/ApplicationProperties.java | 231 +++++---- src/org/jent/checksmtp/ApplicationUI.form | 330 +++++++++++++ src/org/jent/checksmtp/ApplicationUI.java | 518 +++++++++++++++++++++ src/org/jent/checksmtp/Processer.java | 3 +- src/org/jent/checksmtp/SMTPclient.java | 34 +- src/org/jent/checksmtp/ToListUI.form | 114 +++++ src/org/jent/checksmtp/ToListUI.java | 218 +++++++++ test/org/jent/checksmtp/ToListUITest.java | 93 ++++ 16 files changed, 2156 insertions(+), 85 deletions(-) create mode 100644 .cvsignore create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/.cvsignore create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/org/jent/checksmtp/ApplicationUI.form create mode 100644 src/org/jent/checksmtp/ApplicationUI.java create mode 100644 src/org/jent/checksmtp/ToListUI.form create mode 100644 src/org/jent/checksmtp/ToListUI.java create mode 100644 test/org/jent/checksmtp/ToListUITest.java diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..d54b3b2 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,3 @@ +build +dist + diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..b9c39ac --- /dev/null +++ b/build.xml @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project mdc2. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/.cvsignore b/nbproject/.cvsignore new file mode 100644 index 0000000..3e18ebf --- /dev/null +++ b/nbproject/.cvsignore @@ -0,0 +1 @@ +private diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..2b16378 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,541 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.src.dir + Must set test.test.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..4cea6f2 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=715a224e +build.xml.script.CRC32=1bb9c400 +build.xml.stylesheet.CRC32=240b97a2 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=715a224e +nbproject/build-impl.xml.script.CRC32=c01b1fa7 +nbproject/build-impl.xml.stylesheet.CRC32=65d7ca21 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..362335f --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,59 @@ +application.args= +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mdc2.jar +dist.javadoc.dir=${dist.dir}/javadoc +file.reference.BetaProject-src=test +file.reference.BetaProject-test=src +jar.compress=false +javac.classpath=\ + ${libs.swing-layout.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=true +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=org.jent.checksmtp.ApplicationUI +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +src.src.dir=src +test.test.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..1e4e6e2 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + mdc2 + 1.6.5 + + + + + + + + + diff --git a/src/org/jent/checksmtp/ApplicationProperties.java b/src/org/jent/checksmtp/ApplicationProperties.java index 7e42ca4..3f580a2 100644 --- a/src/org/jent/checksmtp/ApplicationProperties.java +++ b/src/org/jent/checksmtp/ApplicationProperties.java @@ -1,8 +1,8 @@ package org.jent.checksmtp; +import java.awt.Dimension; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -25,8 +25,7 @@ import java.util.Properties; *
-.ldap.attribues
LDAP Search attribues separate by space (Defaut:cn) * */ -public class ApplicationProperties -{ +public class ApplicationProperties { private static final String PREFIX = "org.jent.checksmtp"; private static final String SMTP_PORT = PREFIX + ".port"; private static final String SMTP_ENEBLE_REMOTE_CONNECT = PREFIX + ".enableRemoteConnect"; @@ -37,142 +36,216 @@ public class ApplicationProperties private static final String LDAP_ROOT = LDAP_PREFIX + ".baseDn"; private static final String LDAP_IS_SJIS = LDAP_PREFIX + ".isSjis"; private static final String LDAP_IS_ATTRIBUTES = LDAP_PREFIX + ".attributes"; - + private static final String CONFIG_DIALOG_PREFIX = PREFIX + ".configDialog"; + private static final String CONFIG_DIALOG_POS_X = CONFIG_DIALOG_PREFIX + ".pos.x"; + private static final String CONFIG_DIALOG_POS_Y = CONFIG_DIALOG_PREFIX + ".pos.y"; + private static final String CONFIG_DIALOG_POS_W = CONFIG_DIALOG_PREFIX + ".pos.w"; + private static final String CONFIG_DIALOG_POS_H = CONFIG_DIALOG_PREFIX + ".pos.h"; + private static final String CONFIRM_DIALOG_PREFIX = PREFIX + ".confirmDialog"; + private static final String CONFIRM_DIALOG_POS_X = CONFIRM_DIALOG_PREFIX + ".pos.x"; + private static final String CONFIRM_DIALOG_POS_Y = CONFIRM_DIALOG_PREFIX + ".pos.y"; + private static final String CONFIRM_DIALOG_POS_W = CONFIRM_DIALOG_PREFIX + ".pos.w"; + private static final String CONFIRM_DIALOG_POS_H = CONFIRM_DIALOG_PREFIX + ".pos.h"; + private static final String PROPERTIES_FILENAME = ".checksmtp.properties"; - + private static Properties applicationProperties = new Properties(); - + private static String fileName = PROPERTIES_FILENAME; - + + private static boolean isFileLoaded = false; //Exsist configuration file. + + public static boolean isFileLoaded() { + return isFileLoaded; + } + static { - try - { + try { //InputStream is = ApplicationProperties.class.getClassLoader().getResourceAsStream("checksmtp.properties"); fileName = System.getProperty("user.home") + File.separator + PROPERTIES_FILENAME; FileInputStream is = new FileInputStream(fileName); applicationProperties.load(is); + isFileLoaded = true; is.close(); - } - catch (IOException e) - { + } catch (IOException e) { System.err.println("No checksmtp.properties in " + fileName); } } - - private ApplicationProperties() - { + + private ApplicationProperties() { } - + /** - * Application Properties Save - */ - public static void save() - { + * Application Properties Save + */ + public static boolean save() { FileOutputStream fos; - try - { + boolean resultOK = true; + + try { fos = new FileOutputStream(fileName); applicationProperties.store(fos, "Appliction Properties"); fos.close(); - } - catch (IOException e) - { + } catch (IOException e) { + resultOK = false; System.err.println(fileName + "was occrred save error."); e.printStackTrace(); } + return resultOK; } - - public static String getSmtpServerHost() - { + + public static String getSmtpServerHost() { return applicationProperties.getProperty(SMTP_SERVER_HOST, "mail"); } - - public static void setSmtpServerHost(String obj) - { + + public static void setSmtpServerHost(String obj) { applicationProperties.setProperty(SMTP_SERVER_HOST, obj); } - - public static int getSmtpServerPort() - { + + public static int getSmtpServerPort() { return Integer.parseInt(applicationProperties.getProperty(SMTP_SERVER_PORT, "25")); } - - public static void setSmtpServerPort(int port) - { + + public static void setSmtpServerPort(int port) { applicationProperties.setProperty(SMTP_SERVER_PORT, new Integer(port).toString()); } - - public static int getSmtpPort() - { + + public static int getSmtpPort() { return Integer.parseInt(applicationProperties.getProperty(SMTP_PORT, "8725")); } - - public static void setSmtpPort(int port) - { + + public static void setSmtpPort(int port) { applicationProperties.setProperty(SMTP_PORT, new Integer(port).toString()); } - public static boolean getSmtpEnebleRemoteConnect() - { + public static boolean getSmtpEnebleRemoteConnect() { String str = applicationProperties.getProperty(SMTP_ENEBLE_REMOTE_CONNECT); return new Boolean(str).booleanValue(); } - - public static void setSmtpEnableRemoteConnect(boolean obj) - { + + public static void setSmtpEnableRemoteConnect(boolean obj) { applicationProperties.setProperty(SMTP_ENEBLE_REMOTE_CONNECT, Boolean.toString(obj)); } - - public static String getLdapProviderURL() - { + + public static String getLdapProviderURL() { return applicationProperties.getProperty(LDAP_PROVIDER_URL, "ldap://localhost:389"); } - - public static void setLdapProviderURL(String obj) - { + + public static void setLdapProviderURL(String obj) { applicationProperties.setProperty(LDAP_PROVIDER_URL, obj); } - - public static String getLdapRoot() - { + + public static String getLdapRoot() { return applicationProperties.getProperty(LDAP_ROOT, "C=JP"); } - - public static void setLdapRoot(String obj) - { + + public static void setLdapRoot(String obj) { applicationProperties.setProperty(LDAP_ROOT, obj); } - - public static boolean getLdapIsSjis() - { + + public static boolean getLdapIsSjis() { return new Boolean(applicationProperties.getProperty(LDAP_IS_SJIS)).booleanValue(); } - - public static void setLdapRoot(boolean obj) - { + + public static void setLdapIsSjis(boolean obj) { applicationProperties.setProperty(LDAP_IS_SJIS, Boolean.toString(obj)); } - - public static boolean getLdap() - { + + public static boolean getLdap() { String str = applicationProperties.getProperty(LDAP_PREFIX); Boolean flg = new Boolean(str); return flg.booleanValue(); } - - public static void setLdap(boolean obj) - { + + public static void setLdap(boolean obj) { applicationProperties.setProperty(LDAP_PREFIX, Boolean.toString(obj)); } - - public static String getLdapAttributes() - { + + public static String getLdapAttributes() { return applicationProperties.getProperty(LDAP_IS_ATTRIBUTES, "cn"); } - - public static void setLdapAttributes(String obj) - { + + public static void setLdapAttributes(String obj) { applicationProperties.setProperty(LDAP_IS_ATTRIBUTES, obj); } - + + // + // Config Dialog + // + public static Dimension getConfigurationDialogSize() { + Dimension resultDimension = new Dimension(getConfigDialogPosW(), getConfigDialogPosH()); + return resultDimension; + } + public static int getConfigDialogPosX() { + return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_X, "0")); + } + + public static void setConfigDialogPosX(int x) { + applicationProperties.setProperty(CONFIG_DIALOG_POS_X, new Integer(x).toString()); + } + + public static int getConfigDialogPosY() { + return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_Y, "0")); + } + + public static void setConfigDialogPosY(int y) { + applicationProperties.setProperty(CONFIG_DIALOG_POS_Y, new Integer(y).toString()); + } + + public static int getConfigDialogPosW() { + return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_W, "400")); + } + + public static void setConfigDialogPosW(int w) { + applicationProperties.setProperty(CONFIG_DIALOG_POS_W, new Integer(w).toString()); + } + + public static int getConfigDialogPosH() { + return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_H, "232")); + } + + public static void setConfigDialogPosH(int h) { + applicationProperties.setProperty(CONFIG_DIALOG_POS_H, new Integer(h).toString()); + } + + // + // Confirm Dialog + // + static Dimension getConfirmDialogSize() { + Dimension resultDimension = new Dimension(getConfirmDialogPosW(), getConfirmDialogPosH()); + return resultDimension; + } + + public static int getConfirmDialogPosX() { + return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_X, "0")); + } + + public static void setConfirmDialogPosX(int x) { + applicationProperties.setProperty(CONFIRM_DIALOG_POS_X, new Integer(x).toString()); + } + + public static int getConfirmDialogPosY() { + return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_Y, "0")); + } + + public static void setConfirmDialogPosY(int y) { + applicationProperties.setProperty(CONFIRM_DIALOG_POS_Y, new Integer(y).toString()); + } + + public static int getConfirmDialogPosW() { + return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_W, "400")); + } + + public static void setConfirmDialogPosW(int w) { + applicationProperties.setProperty(CONFIRM_DIALOG_POS_W, new Integer(w).toString()); + } + + public static int getConfirmDialogPosH() { + return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_H, "177")); + } + + public static void setConfirmDialogPosH(int h) { + applicationProperties.setProperty(CONFIRM_DIALOG_POS_H, new Integer(h).toString()); + } + } diff --git a/src/org/jent/checksmtp/ApplicationUI.form b/src/org/jent/checksmtp/ApplicationUI.form new file mode 100644 index 0000000..8238d3a --- /dev/null +++ b/src/org/jent/checksmtp/ApplicationUI.form @@ -0,0 +1,330 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/org/jent/checksmtp/ApplicationUI.java b/src/org/jent/checksmtp/ApplicationUI.java new file mode 100644 index 0000000..297643d --- /dev/null +++ b/src/org/jent/checksmtp/ApplicationUI.java @@ -0,0 +1,518 @@ +/* + * ApplicationUI.java + * + * Created on 2007/07/21, 22:37 + */ + +package org.jent.checksmtp; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * + * @author Takuya Ono + */ +public class ApplicationUI extends javax.swing.JFrame { + + /** Creates new form ApplicationUI */ + public ApplicationUI() { + initComponents(); + + resetDisplay(); + } + + private void resetDisplay() { + jTextFieldReceiverPort.setText(Integer.toString(ApplicationProperties.getSmtpPort())); + jTextFieldServerHost.setText(ApplicationProperties.getSmtpServerHost()); + jTextFieldServerPort.setText(Integer.toString(ApplicationProperties.getSmtpServerPort())); + jCheckBoxEnableRemoteConnect.setSelected(ApplicationProperties.getSmtpEnebleRemoteConnect()); + + jCheckBoxLdap.setSelected(ApplicationProperties.getLdap()); + jTextFieldProviderUrl.setText(ApplicationProperties.getLdapProviderURL()); + jTextFieldBaseDn.setText(ApplicationProperties.getLdapRoot()); + jTextFieldAttribute.setText(ApplicationProperties.getLdapAttributes()); + jCheckBoxIsSjis.setSelected(ApplicationProperties.getLdapIsSjis()); + + } + + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + jTabbedPane = new javax.swing.JTabbedPane(); + jPanelMail = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jTextFieldReceiverPort = new javax.swing.JTextField(); + jTextFieldServerHost = new javax.swing.JTextField(); + jTextFieldServerPort = new javax.swing.JTextField(); + jCheckBoxEnableRemoteConnect = new javax.swing.JCheckBox(); + jPanelLDAP = new javax.swing.JPanel(); + jCheckBoxLdap = new javax.swing.JCheckBox(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + jTextFieldProviderUrl = new javax.swing.JTextField(); + jTextFieldBaseDn = new javax.swing.JTextField(); + jTextFieldAttribute = new javax.swing.JTextField(); + jCheckBoxIsSjis = new javax.swing.JCheckBox(); + jButtonOK = new javax.swing.JButton(); + jButtonCancel = new javax.swing.JButton(); + jButtonQuit = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setTitle("Mail Dest. Confirm Properties"); + addComponentListener(new java.awt.event.ComponentAdapter() { + public void componentHidden(java.awt.event.ComponentEvent evt) { + formComponentHidden(evt); + } + }); + + jLabel1.setText("Receiver Port:"); + + jLabel2.setText("Mail Server:"); + + jLabel3.setText("Port:"); + + jTextFieldReceiverPort.setText("8725"); + jTextFieldReceiverPort.setToolTipText("Mail Destination Confirmer SMTP port number."); + + jTextFieldServerHost.setText("mail"); + jTextFieldServerHost.setToolTipText("Mail server host name or IP address."); + + jTextFieldServerPort.setText("25"); + jTextFieldServerPort.setToolTipText("Mail server port number."); + + jCheckBoxEnableRemoteConnect.setText("Enable remote connect"); + jCheckBoxEnableRemoteConnect.setToolTipText("Enable remote machine access this service. (Usually: disable)"); + jCheckBoxEnableRemoteConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jCheckBoxEnableRemoteConnect.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + org.jdesktop.layout.GroupLayout jPanelMailLayout = new org.jdesktop.layout.GroupLayout(jPanelMail); + jPanelMail.setLayout(jPanelMailLayout); + jPanelMailLayout.setHorizontalGroup( + jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanelMailLayout.createSequentialGroup() + .addContainerGap() + .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanelMailLayout.createSequentialGroup() + .add(jLabel1) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jCheckBoxEnableRemoteConnect)) + .add(jPanelMailLayout.createSequentialGroup() + .add(jLabel2) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jLabel3) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + + jPanelMailLayout.linkSize(new java.awt.Component[] {jLabel1, jLabel2}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + jPanelMailLayout.setVerticalGroup( + jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanelMailLayout.createSequentialGroup() + .addContainerGap() + .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel1) + .add(jCheckBoxEnableRemoteConnect) + .add(jTextFieldReceiverPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jPanelMailLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel2) + .add(jLabel3) + .add(jTextFieldServerHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jTextFieldServerPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(74, Short.MAX_VALUE)) + ); + jTabbedPane.addTab("Mail", jPanelMail); + + jCheckBoxLdap.setText("Enable LDAP search"); + jCheckBoxLdap.setToolTipText("Enable LDAP configration."); + jCheckBoxLdap.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jCheckBoxLdap.setMargin(new java.awt.Insets(0, 0, 0, 0)); + jCheckBoxLdap.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + jCheckBoxLdapStateChanged(evt); + } + }); + + jLabel4.setText("URL:"); + + jLabel5.setText("Root DN:"); + + jLabel6.setText("Attribuite:"); + + jTextFieldProviderUrl.setText("ldap://localhost:389/"); + jTextFieldProviderUrl.setToolTipText("LDAP server URL."); + jTextFieldProviderUrl.setEnabled(false); + + jTextFieldBaseDn.setText("C=JP"); + jTextFieldBaseDn.setToolTipText("LDAP search start DN."); + jTextFieldBaseDn.setEnabled(false); + + jTextFieldAttribute.setText("cn"); + jTextFieldAttribute.setToolTipText("Display Attribuite. Example: cn title;lang-ja-jp"); + jTextFieldAttribute.setEnabled(false); + + jCheckBoxIsSjis.setText("Force SJIS"); + jCheckBoxIsSjis.setToolTipText("Check this, when LDAP server use Shift JIS on network."); + jCheckBoxIsSjis.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jCheckBoxIsSjis.setEnabled(false); + jCheckBoxIsSjis.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + org.jdesktop.layout.GroupLayout jPanelLDAPLayout = new org.jdesktop.layout.GroupLayout(jPanelLDAP); + jPanelLDAP.setLayout(jPanelLDAPLayout); + jPanelLDAPLayout.setHorizontalGroup( + jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanelLDAPLayout.createSequentialGroup() + .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanelLDAPLayout.createSequentialGroup() + .addContainerGap() + .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel6) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel5) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE) + .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE) + .add(jPanelLDAPLayout.createSequentialGroup() + .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jCheckBoxIsSjis)))) + .add(jPanelLDAPLayout.createSequentialGroup() + .add(12, 12, 12) + .add(jCheckBoxLdap))) + .addContainerGap()) + ); + + jPanelLDAPLayout.linkSize(new java.awt.Component[] {jLabel4, jLabel5, jLabel6}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + jPanelLDAPLayout.setVerticalGroup( + jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanelLDAPLayout.createSequentialGroup() + .addContainerGap() + .add(jCheckBoxLdap) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel4) + .add(jTextFieldProviderUrl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jCheckBoxIsSjis)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel5) + .add(jTextFieldBaseDn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jPanelLDAPLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel6) + .add(jTextFieldAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(28, Short.MAX_VALUE)) + ); + jTabbedPane.addTab("LDAP", jPanelLDAP); + + jButtonOK.setText("OK"); + jButtonOK.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonOKActionPerformed(evt); + } + }); + + jButtonCancel.setText("Cancel"); + jButtonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonCancelActionPerformed(evt); + } + }); + + jButtonQuit.setText("Quit"); + jButtonQuit.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonQuitActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .add(jButtonQuit) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 145, Short.MAX_VALUE) + .add(jButtonOK) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jButtonCancel) + .addContainerGap()) + ); + + layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK, jButtonQuit}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jButtonCancel) + .add(jButtonOK) + .add(jButtonQuit)) + .addContainerGap()) + ); + pack(); + }// //GEN-END:initComponents + + private void formComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentHidden +// TODO add your handling code here: + }//GEN-LAST:event_formComponentHidden + + private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed + int port; + try { + port = Integer.parseInt(jTextFieldReceiverPort.getText()); + } catch (NumberFormatException ex) { + ex.printStackTrace(); + port = ApplicationProperties.getSmtpPort(); //last saved value. + jTextFieldReceiverPort.setText(Integer.toString(port)); + } + String serverHost = jTextFieldServerHost.getText(); + int serverPort; + try { + serverPort = Integer.parseInt(jTextFieldServerPort.getText()); + } catch (NumberFormatException ex) { + ex.printStackTrace(); + serverPort = ApplicationProperties.getSmtpServerPort(); //last saved value. + jTextFieldServerPort.setText(Integer.toString(serverPort)); + } + boolean enableRemoteConnect = jCheckBoxEnableRemoteConnect.isSelected(); + + boolean enableLdap = jCheckBoxLdap.isSelected(); + String ldapUrl = jTextFieldProviderUrl.getText(); + String rootDn = jTextFieldBaseDn.getText(); + String attribute = jTextFieldAttribute.getText(); + boolean isSjis = jCheckBoxIsSjis.isSelected(); + + if ( port != ApplicationProperties.getSmtpPort() + || !serverHost.equals(ApplicationProperties.getSmtpServerHost()) + || serverPort != ApplicationProperties.getSmtpServerPort() + || enableRemoteConnect != ApplicationProperties.getSmtpEnebleRemoteConnect() + + || enableLdap != ApplicationProperties.getLdap() + || !ldapUrl.equals(ApplicationProperties.getLdapProviderURL()) + || !rootDn.equals(ApplicationProperties.getLdapRoot()) + || !attribute.equals(ApplicationProperties.getLdapAttributes()) + || isSjis != ApplicationProperties.getLdapIsSjis() + || isModifiedPotition() + ) { + // When modify data, save properries file. + ApplicationProperties.setSmtpPort(port); + ApplicationProperties.setSmtpServerHost(serverHost); + ApplicationProperties.setSmtpServerPort(serverPort); + ApplicationProperties.setSmtpEnableRemoteConnect(enableRemoteConnect); + + ApplicationProperties.setLdap(enableLdap); + ApplicationProperties.setLdapProviderURL(ldapUrl); + ApplicationProperties.setLdapRoot(rootDn); + ApplicationProperties.setLdapAttributes(attribute); + ApplicationProperties.setLdapIsSjis(isSjis); + + smtpClient.configChangeNotify(); + if ( !ApplicationProperties.save() ) { + //TODO: Display Save error Dialog. + } + } + iconified(); + + }//GEN-LAST:event_jButtonOKActionPerformed + + private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed + System.exit(0); + }//GEN-LAST:event_jButtonQuitActionPerformed + + private void jCheckBoxLdapStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxLdapStateChanged +// TODO add your handling code here: + boolean check = jCheckBoxLdap.isSelected(); + jTextFieldProviderUrl.setEnabled(check); + jTextFieldBaseDn.setEnabled(check); + jTextFieldAttribute.setEnabled(check); + jCheckBoxIsSjis.setEnabled(check); + }//GEN-LAST:event_jCheckBoxLdapStateChanged + + private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed +// TODO add your handling code here: + //this.setVisible(false); + resetDisplay(); + iconified(); + }//GEN-LAST:event_jButtonCancelActionPerformed + + private boolean isModifiedPotition() { + int x = this.getX(); //TODO: get real potition on screen. + int y = this.getY(); + int h = this.getHeight(); + int w = this.getWidth(); + boolean modified = false; + + if ( x != ApplicationProperties.getConfigDialogPosX() + || y != ApplicationProperties.getConfigDialogPosY() + || h != ApplicationProperties.getConfigDialogPosH() + || w != ApplicationProperties.getConfigDialogPosW() + ) { + modified = true; + ApplicationProperties.setConfigDialogPosX(x); + ApplicationProperties.setConfigDialogPosY(y); + ApplicationProperties.setConfigDialogPosH(h); + ApplicationProperties.setConfigDialogPosW(w); + } + return modified; + } + + + private boolean initSystemTray() { + boolean useSystemTray = false; + try { + Class.forName("java.awt.SystemTray"); + /* TODO: SystemTray suuport + java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray(); + if(tray.isSupported()){ + java.awt.TrayIcon trayIcon = new java.awt.TrayIcon( + new javax.swing.ImageIcon( + SystemTrayTest.class.getResource("images/mdc.gif")).getImage()); + trayIcon.setImageAutoSize(true); + + // create a action listener to listen for default action executed on the tray icon + ActionListener listener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + // execute default action of the application + if ( e.paramString().equal("Quit")) { + System.exit(0); + } else { + setVisible(true); + if ( this.getExtendedState() == ICONIFIED ) { + this.setExtendedState(NORMAL); + } + } + } + }; + java.awt.PopupMenu popup = new java.awt.PopupMenu(); + popup.addActionListener(listener); + popup.add("Config"); + popup.add("Quit"); + trayIcon.setPopupMenu(popup); + tray.add(trayIcon); + useSystemTray = true; + } + */ + } catch (ClassNotFoundException ex) { + // Do not support SystemTray on this VM. + } + return useSystemTray; +} + +private void iconified() { + if ( useSystemTray ) { + this.setVisible(false); + } else { + this.setExtendedState(ICONIFIED); + } +} + +/** + * @param args the command line arguments + */ +public static void main(String args[]) { + /* TKYN OLD + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) { + e.printStackTrace(); + } + */ + + //TKYN ORIGNAL BLOCK + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + ApplicationUI applicationUI = new ApplicationUI(); + applicationUI.setVisible(true); + + applicationUI.useSystemTray = applicationUI.initSystemTray(); + + //If exsist configuration file, iconise at start up. + if ( ApplicationProperties.isFileLoaded() ) { + int x = ApplicationProperties.getConfigDialogPosX(); + int y = ApplicationProperties.getConfigDialogPosY(); + int w = ApplicationProperties.getConfigDialogPosW(); + int h = ApplicationProperties.getConfigDialogPosH(); + + if ( x > screenSize.width ) { + x = screenSize.width - w; + if ( x < 0 ) { x = 0; }; + } + if ( y > screenSize.height ) { + y = screenSize.height - h; + if ( y < 0 ) { y = 0; }; + } + applicationUI.setBounds(x, y, w, h); + applicationUI.iconified(); + } else { + //No Configuration file. + Dimension frameSize = ApplicationProperties.getConfigurationDialogSize(); + if (frameSize.height > screenSize.height) { + frameSize.height = screenSize.height; + } + if (frameSize.width > screenSize.width) { + frameSize.width = screenSize.width; + } + + applicationUI.setBounds( + (screenSize.width - frameSize.width) / 2, + (screenSize.height - frameSize.height) / 2, + frameSize.width, frameSize.height ); + } + } + }); + + smtpClient = new SMTPclient(); +} +private static SMTPclient smtpClient = null; +private boolean useSystemTray = false; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButtonCancel; + private javax.swing.JButton jButtonOK; + private javax.swing.JButton jButtonQuit; + private javax.swing.JCheckBox jCheckBoxEnableRemoteConnect; + private javax.swing.JCheckBox jCheckBoxIsSjis; + private javax.swing.JCheckBox jCheckBoxLdap; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JPanel jPanelLDAP; + private javax.swing.JPanel jPanelMail; + private javax.swing.JTabbedPane jTabbedPane; + private javax.swing.JTextField jTextFieldAttribute; + private javax.swing.JTextField jTextFieldBaseDn; + private javax.swing.JTextField jTextFieldProviderUrl; + private javax.swing.JTextField jTextFieldReceiverPort; + private javax.swing.JTextField jTextFieldServerHost; + private javax.swing.JTextField jTextFieldServerPort; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/org/jent/checksmtp/Processer.java b/src/org/jent/checksmtp/Processer.java index 3aecc06..44fc230 100644 --- a/src/org/jent/checksmtp/Processer.java +++ b/src/org/jent/checksmtp/Processer.java @@ -99,6 +99,7 @@ public class Processer implements Runnable, ResultNotify { client = null; } catch (IOException e) { System.err.println("Execption occurred in Processer."); + //TODO: Display error Dialog. e.printStackTrace(); } finally { //for failsafe Socket close. @@ -230,7 +231,7 @@ public class Processer implements Runnable, ResultNotify { } //checkout toList - new ToListDialog(this, toList); + new ToListUI(this, toList); while (result == RESULT_UNKNOWN) { try { diff --git a/src/org/jent/checksmtp/SMTPclient.java b/src/org/jent/checksmtp/SMTPclient.java index 43e445e..4bb6fb6 100644 --- a/src/org/jent/checksmtp/SMTPclient.java +++ b/src/org/jent/checksmtp/SMTPclient.java @@ -5,16 +5,24 @@ import java.io.IOException; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketTimeoutException; public class SMTPclient implements Runnable { + private boolean isConfigChange = false; + private boolean fatalError = false; + public SMTPclient() { Thread thread = new Thread(this); thread.start(); } + public void configChangeNotify() { + isConfigChange = true; + } + public void run() { - while (true) { + while (!fatalError) { ServerSocket server = null; try { @@ -25,21 +33,37 @@ public class SMTPclient implements Runnable { try { if ( ApplicationProperties.getSmtpEnebleRemoteConnect() ) { System.out.println("Enable remote connection."); - server = new ServerSocket(serverport, 10); + server = new ServerSocket(serverport, 10); //TODO: Backlog Configuable } else { - server = new ServerSocket(serverport, 10, + server = new ServerSocket(serverport, 10, //TODO: Backlog Configuable InetAddress.getByAddress( new byte[] { 127, 0, 0, 1 })); } } catch (IOException e) { + fatalError = true; + System.err.println("Fatal Error Occurred. Stop service."); + //TODO: Display error dialog. e.printStackTrace(); //Unexpected!! } + acceptWait: while (true) { // Wait connect from mail client - Socket client = server.accept(); + server.setSoTimeout(1000); //TODO: Configuable accept wait time. + Socket client; + try { + client = server.accept(); + } catch (SocketTimeoutException ex) { + //Check interupt + if ( isConfigChange ) { + System.err.println("Configuration change restart service."); + isConfigChange = false; + server.close(); + break; // renew ServerSocket + } + continue; + } System.err.println("Accept new STMP socket."); - Processer processer = new Processer(client); Thread clientThread = new Thread(processer); clientThread.start(); diff --git a/src/org/jent/checksmtp/ToListUI.form b/src/org/jent/checksmtp/ToListUI.form new file mode 100644 index 0000000..ce83f6e --- /dev/null +++ b/src/org/jent/checksmtp/ToListUI.form @@ -0,0 +1,114 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/org/jent/checksmtp/ToListUI.java b/src/org/jent/checksmtp/ToListUI.java new file mode 100644 index 0000000..33d055b --- /dev/null +++ b/src/org/jent/checksmtp/ToListUI.java @@ -0,0 +1,218 @@ +/* + * ToListUI.java + * + * Created on 2007/07/22, 11:17 + */ + +package org.jent.checksmtp; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.util.List; + +/** + * + * @author tkyn + */ +public class ToListUI extends javax.swing.JFrame { + private List toList = null; + private ResultNotify resultNotify = null; + + /** Creates new form ToListUI */ + public ToListUI() { + initComponents(); + } + + public ToListUI(ResultNotify processer, List toList) { + this(); //TODO: test dould call... + this.toList = toList; + this.resultNotify = processer; + + if (toList != null) { + jList1.setListData(toList.toArray()); + //jList1.update(); + jList1.setVisible(true); + } + this.setVisible(true); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + //If exsist configuration file, iconise at start up. + if ( ApplicationProperties.isFileLoaded() ) { + int x = ApplicationProperties.getConfirmDialogPosX(); + int y = ApplicationProperties.getConfirmDialogPosY(); + int w = ApplicationProperties.getConfirmDialogPosW(); + int h = ApplicationProperties.getConfirmDialogPosH(); + if ( x > screenSize.width ) { + x = screenSize.width - w; + if ( x < 0 ) { x = 0; }; + } + if ( y > screenSize.height ) { + y = screenSize.height - h; + if ( y < 0 ) { y = 0; }; + } + this.setBounds(x, y, w, h); + } else { + //No Configuration file. + Dimension frameSize = ApplicationProperties.getConfirmDialogSize(); + if (frameSize.height > screenSize.height) { + frameSize.height = screenSize.height; + } + if (frameSize.width > screenSize.width) { + frameSize.width = screenSize.width; + } + this.setBounds( + (screenSize.width - frameSize.width) / 2, + (screenSize.height - frameSize.height) / 2, + frameSize.width, frameSize.height ); + } + + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + jPanel1 = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButtonOK = new javax.swing.JButton(); + jButtonCancel = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Confirm Address"); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosed(java.awt.event.WindowEvent evt) { + formWindowClosed(evt); + } + }); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButtonOK.setText("OK"); + jButtonOK.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonOKActionPerformed(evt); + } + }); + + jButtonCancel.setText("Cancel"); + jButtonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonCancelActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .addContainerGap(200, Short.MAX_VALUE) + .add(jButtonOK) + .add(14, 14, 14) + .add(jButtonCancel) + .addContainerGap()) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) + ); + + jPanel1Layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup() + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jButtonOK) + .add(jButtonCancel))) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + pack(); + }// //GEN-END:initComponents + + private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed + restorePosition(); + resultNotify.sayNG(); + }//GEN-LAST:event_formWindowClosed + + private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed + resultNotify.sayNG(); + this.dispose(); + }//GEN-LAST:event_jButtonCancelActionPerformed + + private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed + //push OK + resultNotify.sayOK(); + this.dispose(); + }//GEN-LAST:event_jButtonOKActionPerformed + + private boolean restorePosition() { + int x = this.getX(); //TODO: get real potition on screen. + int y = this.getY(); + int h = this.getHeight(); + int w = this.getWidth(); + boolean modified = false; + + if ( x != ApplicationProperties.getConfirmDialogPosX() + || y != ApplicationProperties.getConfirmDialogPosY() + || h != ApplicationProperties.getConfirmDialogPosH() + || w != ApplicationProperties.getConfirmDialogPosW() + ) { + modified = true; + ApplicationProperties.setConfirmDialogPosX(x); + ApplicationProperties.setConfirmDialogPosY(y); + ApplicationProperties.setConfirmDialogPosH(h); + ApplicationProperties.setConfirmDialogPosW(w); + if ( !ApplicationProperties.save() ) { + //TODO: save error dialog. + } + } + return modified; + } + + /** + * @param args the command line arguments + * + * public static void main(String args[]) { + * java.awt.EventQueue.invokeLater(new Runnable() { + * public void run() { + * new ToListUI().setVisible(true); + * } + * }); + * } + */ + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButtonCancel; + private javax.swing.JButton jButtonOK; + private javax.swing.JList jList1; + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables + +} diff --git a/test/org/jent/checksmtp/ToListUITest.java b/test/org/jent/checksmtp/ToListUITest.java new file mode 100644 index 0000000..11251cf --- /dev/null +++ b/test/org/jent/checksmtp/ToListUITest.java @@ -0,0 +1,93 @@ +/* + * ToListUITest.java + * JUnit based test + * + * Created on 2007/07/22, 11:41 + */ + +package org.jent.checksmtp; + +import java.util.ArrayList; +import javax.swing.JFrame; +import junit.framework.*; +import junit.swingui.TestRunner; + +/** + * + * @author tkyn + */ +public class ToListUITest extends TestCase implements ResultNotify { + private final ArrayList arrayList = new ArrayList(); + private JFrame toListUI = null; + private boolean result = false; + + public ToListUITest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + /** + * Test of main method, of class org.jent.checksmtp.ToListUI. + */ + public void testMain() { + System.out.println("main"); + + String[] args = null; + + //ToListUI.main(args); + + // review the generated test code and remove the default call to fail. + //fail("The test case is a prototype."); + + } + + private void pushTestSetup(String msg) { + arrayList.add(msg); + for (int i = 0; i < 100; i++) { + arrayList.add("NO" + i); + } + toListUI = new ToListUI(this, arrayList); + arrayList.clear(); + + try { + synchronized (this) { + wait(30 * 1000); + //Wait 30sec + } + } catch (InterruptedException e) { + fail("Dialg wait interrupted"); + } + } + + private synchronized void notifyResult() { + notify(); + } + + public void sayOK() { + result = true; + notifyResult(); + } + + public void sayNG() { + result = false; + notifyResult(); + } + + public void testPushOK() { + pushTestSetup("Please push OK button."); + assertTrue("Time out or push CANCEL", result); + } + + public void testPushCANCEL() { + pushTestSetup("Please push CANCEL button."); + assertTrue("Time out or push OK", !result); + } + + public void testPushClose() { + pushTestSetup("Please close Window."); + assertTrue("Time out or push OK", !result); + } + +} -- 2.11.0