001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.jfreechart; 025 026 import java.util.Map; 027 import java.util.WeakHashMap; 028 029 import org.jfree.chart.plot.IntervalMarker; 030 import org.jfree.chart.plot.ValueMarker; 031 import org.jfree.data.xy.XYDataItem; 032 import org.jfree.data.xy.XYSeries; 033 import org.ujmp.core.util.MathUtil; 034 import org.ujmp.gui.MatrixGUIObject; 035 036 public class XYSeriesWrapper extends XYSeries { 037 private static final long serialVersionUID = 2493663877511719452L; 038 039 private static final int MAXITEMS = 3000; 040 041 private final Map<Integer, XYDataItem> values = new WeakHashMap<Integer, XYDataItem>(); 042 043 private MatrixGUIObject matrix = null; 044 045 private ValueMarker meanMarker = null; 046 047 private IntervalMarker standardDeviationMarker = null; 048 049 private IntervalMarker minMaxMarker = null; 050 051 private int seriesId = 0; 052 053 private int stepsize = 1; 054 055 private int start = 0; 056 057 public XYSeriesWrapper(MatrixGUIObject m, int number) { 058 super(m.getColumnName(number), false, true); 059 this.seriesId = number; 060 this.matrix = m; 061 // meanMarker = new MeanMarkerForVariable(variable, number); 062 // standardDeviationMarker = new 063 // StandardDeviationMarkerForVariable(variable, number); 064 // minMaxMarker = new MinMaxMarkerForVariable(variable, number); 065 // variable.getVariable().addVariableListener(this); 066 // stepsize = (int) Math.ceil((double) 067 // variable.getVariable().getMatrixCount() / (double) MAXITEMS); 068 } 069 070 // public void setRange(Range range) { 071 // double length = range.getLength(); 072 // start = (int) Math.floor(range.getLowerBound()); 073 // stepsize = (int) Math.ceil(length / MAXITEMS); 074 // } 075 076 public XYDataItem getDataItem(int index) { 077 // int id = start + index * stepsize; 078 // if (id >= variable.getVariable().getMatrixCount()) { 079 // return new XYDataItem(id, 0.0); 080 // } 081 // 082 // Matrix matrix = variable.getVariable().getMatrix(id); 083 // double value = 0.0; 084 // try { 085 // value = matrix.getAsDouble(number % matrix.getRowCount(), number 086 // / matrix.getRowCount()); 087 // } catch (MatrixException e) { 088 // // TODO Auto-generated catch block 089 // e.printStackTrace(); 090 // } 091 // 092 // XYDataItem xyDataItem = values.get(id); 093 // if (xyDataItem == null) { 094 // xyDataItem = new XYDataItem(id, value); 095 // values.put(id, xyDataItem); 096 // } else { 097 // xyDataItem.setY(value); 098 // } 099 // 100 // return xyDataItem; 101 102 double row = index; 103 try { 104 row = Double.parseDouble(matrix.getRowName(index)); 105 } catch (Exception e) { 106 } 107 108 return new XYDataItem(row, matrix.getMatrix().getAsDouble(index, 109 seriesId)); 110 } 111 112 public int getItemCount() { 113 return (int) matrix.getRowCount(); 114 } 115 116 public int indexOf(Number x) { 117 return (Integer) x; 118 } 119 } 120 121 // public void valueChanged(VariableEvent e) { 122 // if (System.currentTimeMillis() % 10 == 0) 123 // fireSeriesChanged(); 124 // } 125 126 // public ValueMarker getMeanMarker() { 127 // return meanMarker; 128 // } 129 130 // public IntervalMarker getStandardDeviationMarker() { 131 // return standardDeviationMarker; 132 // } 133 134 // public IntervalMarker getMinMaxMarker() { 135 // return minMaxMarker; 136 // } 137 138 // class StandardDeviationMarkerForVariable extends IntervalMarker { 139 // private static final long serialVersionUID = 4093403885413441600L; 140 // 141 // private int number = 0; 142 // 143 // private VariableGUIObject variable = null; 144 // 145 // public StandardDeviationMarkerForVariable(VariableGUIObject v, int number) { 146 // super(0, 0); 147 // this.variable = v; 148 // this.number = number; 149 // setPaint(new Color(255, 100, 100, 60)); 150 // } 151 // 152 // 153 // public double getEndValue() { 154 // try { 155 // return variable.getVariable().getMeanMatrix().getAsDouble(0, number) 156 // + variable.getVariable().getStandardDeviationMatrix().getAsDouble(0, number); 157 // } catch (MatrixException e) { 158 // return 0.0; 159 // } 160 // } 161 // 162 // 163 // public double getStartValue() { 164 // try { 165 // return variable.getVariable().getMeanMatrix().getAsDouble(0, number) 166 // - variable.getVariable().getStandardDeviationMatrix().getAsDouble(0, number); 167 // } catch (MatrixException e) { 168 // return 0.0; 169 // } 170 // } 171 // 172 // } 173 // 174 // class MinMaxMarkerForVariable extends IntervalMarker { 175 // 176 // private int number = 0; 177 // 178 // private VariableGUIObject variable = null; 179 // 180 // public MinMaxMarkerForVariable(VariableGUIObject v, int number) { 181 // super(0, 0); 182 // this.variable = v; 183 // this.number = number; 184 // setPaint(new Color(255, 200, 200, 50)); 185 // } 186 // 187 // 188 // public double getEndValue() { 189 // try { 190 // return variable.getVariable().getMaxMatrix().getAsDouble(0, number); 191 // } catch (MatrixException e) { 192 // return 0.0; 193 // } 194 // } 195 // 196 // 197 // public double getStartValue() { 198 // try { 199 // return variable.getVariable().getMinMatrix().getAsDouble(0, number); 200 // } catch (MatrixException e) { 201 // return 0.0; 202 // } 203 // } 204 // 205 // } 206 // 207 // class MeanMarkerForVariable extends ValueMarker { 208 // private static final long serialVersionUID = 7345423855597100653L; 209 // 210 // private int number = 0; 211 // 212 // private VariableGUIObject variable = null; 213 // 214 // public MeanMarkerForVariable(VariableGUIObject v, int number) { 215 // super(0); 216 // this.variable = v; 217 // this.number = number; 218 // setPaint(new Color(200, 0, 0, 128)); 219 // setLabelAnchor(RectangleAnchor.TOP); 220 // setLabelTextAnchor(TextAnchor.TOP_RIGHT); 221 // } 222 // 223 // 224 // public String getLabel() { 225 // try { 226 // return 227 // StringUtil.format(variable.getVariable().getMeanMatrix().getAsDouble(0, 228 // number)); 229 // } catch (MatrixException e) { 230 // return ""; 231 // } 232 // } 233 // 234 // 235 // public double getValue() { 236 // try { 237 // return variable.getVariable().getMeanMatrix().getAsDouble(0, number); 238 // } catch (MatrixException e) { 239 // return 0.0; 240 // } 241 // } 242 // 243 // 244 // public void setValue(double arg0) { 245 // } 246