MOA 12.03
Real Time Analytics for Data Streams
GUIDefaults.java
Go to the documentation of this file.
00001 /*
00002  *    This program is free software; you can redistribute it and/or modify
00003  *    it under the terms of the GNU General Public License as published by
00004  *    the Free Software Foundation; either version 3 of the License, or
00005  *    (at your option) any later version.
00006  *
00007  *    This program is distributed in the hope that it will be useful,
00008  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *    GNU General Public License for more details.
00011  *
00012  *    You should have received a copy of the GNU General Public License
00013  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00014  *    
00015  */
00016 
00017 /*
00018  * GUIDefaults.java
00019  * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand
00020  */
00021 package moa.gui;
00022 
00023 import moa.core.PropertiesReader;
00024 import weka.core.Utils;
00025 
00026 import java.io.Serializable;
00027 import java.util.Collections;
00028 import java.util.Enumeration;
00029 import java.util.Properties;
00030 import java.util.Vector;
00031 
00039 public class GUIDefaults
00040         implements Serializable {
00041 
00043     private static final long serialVersionUID = 4954795757927524225L;
00044 
00046     public final static String PROPERTY_FILE = "moa/gui/GUI.props";
00047 
00049     protected static Properties PROPERTIES;
00050 
00051     static {
00052         try {
00053             PROPERTIES = PropertiesReader.readProperties(PROPERTY_FILE);
00054         } catch (Exception e) {
00055             System.err.println("Problem reading properties. Fix before continuing.");
00056             e.printStackTrace();
00057             PROPERTIES = new Properties();
00058         }
00059     }
00060 
00069     public static String get(String property, String defaultValue) {
00070         return PROPERTIES.getProperty(property, defaultValue);
00071     }
00072 
00078     public final static Properties getProperties() {
00079         return PROPERTIES;
00080     }
00081 
00091     protected static Object getObject(String property, String defaultValue) {
00092         return getObject(property, defaultValue, Object.class);
00093     }
00094 
00105     protected static Object getObject(String property, String defaultValue, Class cls) {
00106         Object result;
00107         String tmpStr;
00108         String[] tmpOptions;
00109 
00110         result = null;
00111 
00112         try {
00113             tmpStr = get(property, defaultValue);
00114             tmpOptions = Utils.splitOptions(tmpStr);
00115             if (tmpOptions.length != 0) {
00116                 tmpStr = tmpOptions[0];
00117                 tmpOptions[0] = "";
00118                 result = Utils.forName(cls, tmpStr, tmpOptions);
00119             }
00120         } catch (Exception e) {
00121             e.printStackTrace();
00122             result = null;
00123         }
00124 
00125         return result;
00126     }
00127 
00134     public static String[] getTabs() {
00135         String[] result;
00136         String tabs;
00137 
00138         // read and split on comma
00139         tabs = get("Tabs", "moa.gui.ClassificationTabPanel,moa.gui.clustertab.ClusteringTabPanel");
00140         result = tabs.split(",");
00141 
00142         return result;
00143     }
00144 
00159     public static String getInitialDirectory() {
00160         String result;
00161 
00162         result = get("InitialDirectory", "%c");
00163         result = result.replaceAll("%t", System.getProperty("java.io.tmpdir"));
00164         result = result.replaceAll("%h", System.getProperty("user.home"));
00165         result = result.replaceAll("%c", System.getProperty("user.dir"));
00166         result = result.replaceAll("%%", System.getProperty("%"));
00167 
00168         return result;
00169     }
00170 
00176     public static void main(String[] args) {
00177         Enumeration names;
00178         String name;
00179         Vector sorted;
00180 
00181         System.out.println("\nMOA defaults:");
00182         names = PROPERTIES.propertyNames();
00183 
00184         // sort names
00185         sorted = new Vector();
00186         while (names.hasMoreElements()) {
00187             sorted.add(names.nextElement());
00188         }
00189         Collections.sort(sorted);
00190         names = sorted.elements();
00191 
00192         // output
00193         while (names.hasMoreElements()) {
00194             name = names.nextElement().toString();
00195             System.out.println("- " + name + ": " + PROPERTIES.getProperty(name, ""));
00196         }
00197         System.out.println();
00198     }
00199 }
 All Classes Namespaces Files Functions Variables Enumerations