Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.generalrobotix.ui.view.graph;
00011
00012 import java.util.*;
00013 import java.io.*;
00014 import java.net.URL;
00015
00022 public class GraphProperties {
00023
00024
00025
00026 private static final String GRAPH_PROPERTIES = "/resources/graph.properties";
00027 private static final String SEP = ".";
00028 private static final String DATA_KIND_NAMES = "dataKindNames";
00029 private static final String UNIT = "unit";
00030 private static final String BASE = "base";
00031 private static final String EXTENT = "extent";
00032 private static final String FACTOR = "factor";
00033 private static final String DATA_KIND = "dataKind";
00034
00035
00036
00037 private static GraphProperties this_;
00038 private static HashMap<String, DataKind> dataKindMap_;
00039 private static HashMap<String, DataKind> attributeMap_;
00040
00041
00042
00048 private GraphProperties() {
00049
00050 URL url = this.getClass().getResource(GRAPH_PROPERTIES);
00051 Properties prop = new Properties();
00052 try {
00053 prop.load(url.openStream());
00054 } catch (IOException ex) {
00055 ex.printStackTrace();
00056 System.exit(0);
00057 }
00058
00059
00060 dataKindMap_ = new HashMap<String, DataKind>();
00061 StringTokenizer dkNames =
00062 new StringTokenizer(prop.getProperty(DATA_KIND_NAMES), ",");
00063 while (dkNames.hasMoreTokens()) {
00064 String dkName = dkNames.nextToken();
00065 String unit = prop.getProperty(dkName + SEP + UNIT);
00066 double base = Double.parseDouble(prop.getProperty(dkName + SEP + BASE));
00067 double extent = Double.parseDouble(prop.getProperty(dkName + SEP + EXTENT));
00068 double factor = (
00069 (prop.containsKey(dkName + SEP + FACTOR))
00070 ? Double.parseDouble((String)prop.getProperty(dkName + SEP + FACTOR))
00071 : 1
00072 );
00073 DataKind dk = new DataKind(dkName, unit, base, extent, factor);
00074 dataKindMap_.put(dkName, dk);
00075 }
00076
00077
00078 attributeMap_ = new HashMap<String, DataKind>();
00079 String postfix = SEP + DATA_KIND;
00080 int postfixlen = postfix.length();
00081 Enumeration elm = prop.propertyNames();
00082 while (elm.hasMoreElements()) {
00083 String pname = (String)elm.nextElement();
00084 if (pname.endsWith(postfix)) {
00085 String aname = pname.substring(
00086 0, pname.length() - postfixlen
00087 );
00088 attributeMap_.put(aname, dataKindMap_.get(prop.getProperty(pname)));
00089 }
00090 }
00091 }
00092
00093
00094
00100 public static DataKind getDataKindFromName(
00101 String dataKindName
00102 ) {
00103 if (this_ == null) {
00104 this_ = new GraphProperties();
00105 }
00106 return (DataKind)dataKindMap_.get(dataKindName);
00107 }
00108
00114 public static DataKind getDataKindFromAttr(
00115 String attribute
00116 ) {
00117 if (this_ == null) {
00118 this_ = new GraphProperties();
00119 }
00120 return (DataKind)attributeMap_.get(attribute);
00121 }
00122 }