001: package net.sf.jmoney.charts;
002:
003: import java.lang.reflect.Constructor;
004: import java.text.DateFormat;
005: import java.text.ParseException;
006: import java.text.SimpleDateFormat;
007: import java.util.Date;
008: import java.util.Vector;
009:
010: import org.eclipse.core.runtime.Assert;
011: import org.jfree.data.time.RegularTimePeriod;
012:
013: /**
014: * @author Faucheux
015: * This class is only a container to collect all the parameters of
016: * a LineChart.
017: */
018: public class StackedChartParameters {
019:
020: public/*String*/Vector accountList;
021: public Date fromDate, toDate;
022: public int maxLevel = 1;
023: public boolean isStacked = false;
024:
025: // Frequences of the dataes
026: public static final int DAY = 0;
027: public static final int MONTH = 1;
028: public static final int YEAR = 2;
029: public int frequence = YEAR;
030:
031: // Contructor for the Object which represents the choosen TimePeriod: Month, Year...
032: public Constructor regularPeriodConstructor = null;
033:
034: // Dateformat object to format the dates which appears in the graph.
035: DateFormat dateformat = null;
036:
037: /**
038: *
039: */
040: public StackedChartParameters() {
041: accountList = new Vector();
042: fromDate = new Date(0); // 01.01.1970
043: toDate = new Date(); // today
044: }
045:
046: /**
047: * @param accountList The accountList to set.
048: */
049: public void setAccountList(Vector accountList) {
050: this .accountList = accountList;
051: }
052:
053: /**
054: * @param fromDate The fromDate to set.
055: */
056: public void setFromDate(Date fromDate) {
057: this .fromDate = fromDate;
058: }
059:
060: /**
061: * @param toDate The toDate to set.
062: */
063: public void setToDate(Date toDate) {
064: this .toDate = toDate;
065: }
066:
067: public void setDates(String fromDate, String toDate) {
068: DateFormat df = new SimpleDateFormat();
069: try {
070: setFromDate(df.parse(fromDate));
071: setToDate(df.parse(toDate));
072: } catch (ParseException e) {
073: e.printStackTrace();
074: }
075: ;
076: }
077:
078: /**
079: * @param frequence The frequence to set.
080: */
081: public void setFrequence(int frequence) {
082: this .frequence = frequence;
083: }
084:
085: /**
086: * Instanciate the regularPeriodConstructor with the value dependant of periodClass
087: * The dateformat is intanciated too
088: * @author Faucheux
089: */
090: public void instanciateConstructor() {
091: try {
092: Class periodClass = null;
093: String stringFormat = null;
094: switch (frequence) {
095: case MONTH:
096: stringFormat = "MM.yy";
097: periodClass = Class
098: .forName("org.jfree.data.time.Month");
099: break;
100: case YEAR:
101: stringFormat = "yyyy";
102: periodClass = Class.forName("org.jfree.data.time.Year");
103: break;
104: default:
105: Assert.isTrue(false);
106: }
107: dateformat = new SimpleDateFormat(stringFormat);
108: regularPeriodConstructor = periodClass
109: .getConstructor(new Class[] { Class
110: .forName("java.util.Date") });
111: } catch (ClassNotFoundException e) {
112: e.printStackTrace();
113: } catch (NoSuchMethodException e) {
114: e.printStackTrace();
115: }
116:
117: }
118:
119: /**
120: * Create and returns a new object (Month, Day, Year...) which type depends of the choose Period
121: * @param date
122: * @return
123: */
124: public RegularTimePeriod createPeriod(Date date) {
125: RegularTimePeriod re = null;
126: try {
127: re = (RegularTimePeriod) regularPeriodConstructor
128: .newInstance(new Object[] { date });
129: } catch (Exception e) {
130: e.printStackTrace();
131: }
132: return re;
133: }
134:
135: /**
136: * @param maxLevel The maxLevel to set.
137: */
138: public void setMaxLevel(int maxLevel) {
139: this .maxLevel = maxLevel;
140: }
141:
142: public void setIsStacked(boolean isStacked) {
143: this.isStacked = isStacked;
144: }
145: }
|