changeset 22:e067ee54f638 tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2014 10:40:11 -0700
parents 94abfc6441a4
children cfcb8d9859a8
files src/org/tn5250j/GlobalConfigure.java src/org/tn5250j/interfaces/ConfigureFactory.java
diffstat 2 files changed, 103 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tn5250j/GlobalConfigure.java	Tue Jun 03 10:29:26 2014 -0700
+++ b/src/org/tn5250j/GlobalConfigure.java	Tue Jun 03 10:40:11 2014 -0700
@@ -37,8 +37,6 @@
 import java.util.Hashtable;
 import java.util.Properties;
 
-import javax.swing.JOptionPane;
-
 import com.five_ten_sg.connectbot.TerminalView;
 import org.tn5250j.interfaces.ConfigureFactory;
 import org.tn5250j.tools.logging.TN5250jLogFactory;
@@ -66,13 +64,6 @@
 
     static private Hashtable registry = new Hashtable();
     static private Hashtable headers = new Hashtable();  //LUC GORRENS
-
-    // Moved to ConfigureFactory
-    //   static final public String SESSIONS = "sessions";
-    static final public File ses = new File(SESSIONS);
-    //   static final public String MACROS = "macros";
-    //   static final public String KEYMAP = "keymap";
-
     private final TN5250jLogger log = TN5250jLogFactory.getLogger (this.getClass());
 
     /**
@@ -191,7 +182,6 @@
             log.info(" Information Message: "
                     + fnfea.getMessage() + ".  The file " + settingsFile()
                     + " will be created for first time use.");
-            checkLegacy();
             saveSettings();
         }
         catch (IOException ioea) {
@@ -206,84 +196,6 @@
         }
     }
 
-    private void checkDirs() {
-        // we now check to see if the settings directory is a directory.  If not then we create it
-        File sd = new File(settings.getProperty("emulator.settingsDirectory"));
-        if (!sd.isDirectory())
-            sd.mkdirs();
-    }
-
-    private void checkLegacy() {
-        // we check if the sessions file already exists in the directory
-        // if it does exist we are working with an old install so we
-        // need to set the settings directory to the users directory
-        // SESSIONS is declared as a string, so we just can use the keyword here.
-        if(ses.exists()) {
-            int cfc;
-            cfc = JOptionPane.showConfirmDialog(null,
-                    "Dear User,\n\n" +
-                    "Seems you are using an old version of tn5250j.\n" +
-                    "In meanwhile the application became multi-user capable,\n" +
-                    "which means ALL the config- and settings-files are\n" +
-                    "placed in your home-dir to avoid further problems in\n" +
-                    "the near future.\n\n" +
-                    "You have the choice to choose if you want the files\n" +
-                    "to be copied or not, please make your choice !\n\n" +
-                    "Shall we copy the files to the new location ?",
-                    "Old install detected", JOptionPane.WARNING_MESSAGE,
-                    JOptionPane.YES_NO_OPTION);
-            if (cfc == 0) {
-                // Here we do a checkdir so we know the destination-dir exists
-                checkDirs();
-                copyConfigs(SESSIONS);
-                copyConfigs(MACROS);
-                copyConfigs(KEYMAP);
-            }
-            else {
-                JOptionPane.showMessageDialog(null,
-                        "Dear User,\n\n" +
-                        "You choosed not to copy the file.\n" +
-                        "This means the program will end here.\n\n" +
-                        "To use this NON-STANDARD behaviour start tn5250j\n" +
-                        "with -Demulator.settingsDirectory=<settings-dir> \n" +
-                        "as a parameter to avoid this question all the time.",
-                        "Using NON-STANDARD behaviour", JOptionPane.WARNING_MESSAGE);
-                System.exit(0);
-            }
-        }
-    }
-
-    private void copyConfigs(String sesFile) {
-        /** Copy the config-files to the user's home-dir */
-        String srcFile = System.getProperty("user.dir") + File.separator + sesFile;
-        String dest = System.getProperty("user.home") +
-        File.separator + TN5250J_FOLDER + File.separator + sesFile;
-        File rmvFile = new File(sesFile);
-        try {
-            FileReader r = new FileReader(srcFile);
-            BufferedReader b = new BufferedReader(r);
-
-            FileWriter w = new FileWriter(dest);
-            PrintWriter p = new PrintWriter(w);
-            String regel = b.readLine();
-            while (regel != null) {
-                p.println(regel);
-                regel = b.readLine();
-            }
-            b.close();
-            p.close();
-            rmvFile.delete();
-        }
-        catch (FileNotFoundException e) {
-            log.warn(srcFile + " not found !");
-        }
-        catch (IOException e) {
-            log.warn("Global io-error !");
-        }
-        catch (ArrayIndexOutOfBoundsException e) {
-        }
-    }
-
     /**
      * Save the settings for the global configuration
      */
@@ -471,9 +383,11 @@
     }
 
     @Override
-    public Properties  getProperties(String regKey,String fileName,
-            boolean createFile,String header,
-            boolean reloadIfLoaded) {
+    public Properties  getProperties(String regKey,
+                                     String fileName,
+                                     boolean createFile,
+                                     String header,
+                                     boolean reloadIfLoaded) {
 
         if (!registry.containsKey(regKey) || reloadIfLoaded) {
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/tn5250j/interfaces/ConfigureFactory.java	Tue Jun 03 10:40:11 2014 -0700
@@ -0,0 +1,98 @@
+/*
+ * @(#)ConfigureFactory.java
+ * @author  Kenneth J. Pouncey
+ * Modified by LDC Luc
+ *
+ * Copyright:    Copyright (c) 2001, 2002, 2003
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA
+ *
+ */
+package org.tn5250j.interfaces;
+
+import org.tn5250j.GlobalConfigure;
+import java.util.Properties;
+
+/**
+ * An interface defining objects that can create Configure
+ * instances.
+ */
+public abstract class ConfigureFactory {
+
+   static final public String SESSIONS = "sessions";
+   static final public String MACROS = "macros";
+   static final public String KEYMAP = "keymap";  
+   private static ConfigureFactory  factory;
+
+   /**
+    * @return An instance of the Configure.
+    */
+  public static ConfigureFactory  getInstance()
+  {
+    ConfigureFactory.setFactory();
+    return factory;
+  }
+
+  private static final void setFactory()
+  {
+    if (factory == null)
+    {
+      try
+      {
+        String  className = System.getProperty(ConfigureFactory.class.getName());
+        if (className != null)
+        {
+          Class<?> classObject = Class.forName(className);
+          Object  object = classObject.newInstance();
+          if (object instanceof ConfigureFactory)
+          {
+            ConfigureFactory.factory = (ConfigureFactory) object;
+          }
+        }
+      }
+      catch (Exception  ex)
+      {
+        ;
+      }
+      if (ConfigureFactory.factory == null)
+      { //take the default
+//        ConfigureFactory.factory = new GlobalConfigureFactory();
+        ConfigureFactory.factory = new GlobalConfigure();
+      }
+    }
+  }
+
+   abstract public void reloadSettings();
+   abstract public void saveSettings();
+   abstract public String getProperty(String regKey);
+   abstract public String getProperty(String regKey, String defaultValue);
+   abstract public void setProperties(String regKey, Properties regProps);
+
+   abstract public void setProperties(String regKey, String fileName, String  header);
+   abstract public void setProperties(String regKey, String fileName, String  header,
+                              boolean createFile);
+   abstract public Properties  getProperties(String regKey);
+   abstract public Properties  getProperties(String regKey,String fileName);
+   abstract public Properties  getProperties(String regKey,String fileName,
+                                                boolean createFile, String header);
+   abstract public Properties  getProperties(String regKey,String fileName,
+                                                boolean createFile, String header,
+                                                boolean reloadIfLoaded);
+   abstract public void saveSettings(String regKey);
+   abstract public void saveSettings(String regKey, String header);
+   abstract public void saveSettings(String regKey, String fileName, String header);
+
+}
\ No newline at end of file