package uk.ac.leeds.ccg.cluster; /**TimeParameters class * Description: TimeParameter methods used by all time series methods */ import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class TimeParameters extends Parameters { // Version id private static final String version = "$id$"; // Members /**@param animate control for visualising search * @param thresh significance threshold for the test * @param numBin number of bins * @param minTime earliest (start) time for data * @param maxTime latest (end) time for data */ private boolean animate; private double thresh,minTime,maxTime; private int numBin; // Constructors public TimeParameters(){ setDefaultTimeParameters(); } public TimeParameters(File file) throws IOException,FileNotFoundException{ // Read into a stream tokenised buffered input stream StreamTokenizer st = new StreamTokenizer ( new BufferedReader ( new InputStreamReader ( new FileInputStream (file)))); System.out.println ("Setting timeparameters from "+file); st.nextToken(); if (st.sval.equalsIgnoreCase("true")) {setAnimate(true);} else {setAnimate(false);} st.nextToken(); setSignificanceThreshold(st.nval); st.nextToken(); setNumBin((int)st.nval); st.nextToken(); setStartTime(st.nval); st.nextToken(); setEndTime(st.nval); notifyTimeParametersChangedListeners(); } public TimeParameters(boolean animate, double thresh, int numBin, double minTime, double maxTime){ setAnimate(animate); setSignificanceThreshold(thresh); setNumBin(numBin); setStartTime(minTime); setEndTime(maxTime); notifyTimeParametersChangedListeners(); } // Methods public String tostring(){ return "[animate "+getAnimate()+"]\n"+ "[significance threshold "+getSignificanceThreshold()+"]\n"+ "[number of bins "+getNumBin()+"]\n"+ "[start time "+getStartTime()+"]\n"+ "[end time "+getEndTime()+"]\n"; } // public TimeParameters getParameters() {return this;} public void setTimeParameters(boolean animate, double thresh, int numBin, double minTime, double maxTime){ setAnimate(animate); setSignificanceThreshold(thresh); setNumBin(numBin); setStartTime(minTime); setEndTime(maxTime); notifyTimeParametersChangedListeners(); } public void setDefaultTimeParameters(){ setTimeParameters(false,0.01d,17,1.0d,365.0d); notifyTimeParametersChangedListeners(); } public boolean getAnimate() {return animate;} public void setAnimate(boolean b) {animate=b;} public double getSignificanceThreshold() {return thresh;} public void setSignificanceThreshold(double d) {thresh=d;} public int getNumBin() {return numBin;} public void setNumBin(int d) {numBin=d;} public double getStartTime() {return minTime;} public void setStartTime(double d) {minTime=d;} public double getEndTime() {return maxTime;} public void setEndTime(double d) {maxTime=d;} public void writeTimeParameters(File file) throws IOException,FileNotFoundException{ PrintWriter pw = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream (file)))); pw.println(getAnimate()); pw.println(getSignificanceThreshold()); pw.println(getNumBin()); pw.println(getStartTime()); pw.println(getEndTime()); System.out.println ("TimeParameters saved to "+file); pw.flush(); pw.close(); } Vector listeners = new Vector(); public void removeTimeParametersChangedListener(TimeParametersChangedListener lcl) { listeners.removeElement(lcl); } public void addTimeParametersChangedListener(TimeParametersChangedListener lcl) { listeners.addElement(lcl); } public void notifyTimeParametersChangedListeners(){ Vector l; TimeParametersChangedEvent lce = new TimeParametersChangedEvent(this); synchronized(this) {l = (Vector)listeners.clone(); } for (int i = 0; i < l.size();i++) { ((TimeParametersChangedListener)l.elementAt(i)).TimeParametersChanged(lce); } } }