001 /**
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: Nov 27, 2002
005 * Time: 3:57:05 PM
006 */
007
008 package EVolve.visualization.XYViz.ValRefViz;
009
010 import EVolve.visualization.XYViz.XYVisualization;
011 import EVolve.visualization.XYViz.ValRefViz.HotSpotViz.PredictionViz;
012 import EVolve.visualization.*;
013 import EVolve.util.VizInfo;
014 import EVolve.Scene;
015 import EVolve.data.ElementDefinition;
016 import EVolve.data.DataFilter;
017 import EVolve.data.Entity;
018
019 import java.util.*;
020
021
022 public abstract class ValueReferenceVisualization extends XYVisualization{
023 protected ValueDimension xAxis;
024 protected ReferenceDimension yAxis;
025 protected ReferenceDimension zAxis;
026 protected ArrayList eventCounter; // event counter
027
028 public Dimension[] createDimension() {
029 Dimension [] returnDimension = new Dimension[2];
030
031 xAxis = new ValueDimension();
032 yAxis = new ReferenceDimension();
033 zAxis = null;
034
035 returnDimension[0] = xAxis;
036 returnDimension[1] = yAxis;
037
038 return returnDimension;
039 }
040
041 public ReferenceDimension getLinkableDimension(int dim) {
042 if (dim!=1) return null;
043 return (ReferenceDimension)dimension[dim];
044 }
045
046 public void sort() {
047 String comparatorName = yAxis.getSelectedComparatorName();
048 if (normalOrientation) {
049 ((AxesPanel)panel).setName(timeHeader() + xAxis.getName() + " (" + xMax +
050 (interval == -1 ? "" : (",interval " + String.valueOf(interval))) +")",
051 yAxis.getName() + " (" + yAxis.getEntityNumber() +
052 ", " + comparatorName +")");
053 ((AxesPanel)panel).setImage(image.getSortedImage(null, yAxis).getImage());
054 magnifier.setAxises(null,yAxis);
055 }
056 else {
057 ((AxesPanel)panel).setName(yAxis.getName() + " (" + yAxis.getEntityNumber() + ", " +
058 comparatorName + ")",
059 timeHeader() + xAxis.getName() + " (" + xMax + ")");
060 ((AxesPanel)panel).setImage(image.getSortedImage(yAxis, null).getImage());
061 magnifier.setAxises(yAxis,null);
062 }
063 panel.repaint();
064 enableBrowseSourceMenu();
065 }
066
067 public HashMap getCurrentConfigure() {
068 HashMap configure = super.getCurrentConfigure();
069
070 VizInfo vizInfo = new VizInfo();
071 vizInfo.setFactory((VisualizationFactory)configure.get("Factory"));
072 vizInfo.setSubject((ElementDefinition)configure.get("Subject"));
073
074 String[] dimensionDefs = new String[3];
075 dimensionDefs[0] = xAxis.getName() ;
076 dimensionDefs[1] = yAxis.getName() ;
077 dimensionDefs[2] = (zAxis == null) ? ";not using" : zAxis.getName() ;
078 configure.put("Dimension",vizInfo.createDimension(dimensionDefs));
079 if (this instanceof PredictionViz)
080 configure.put("Predictor",((PredictionViz)this).getPredictor());
081 else
082 configure.put("Predictor",null);
083 vizInfo.createInterval(new Integer(interval).toString());
084
085 return configure;
086 }
087
088 protected void updateConfiguration() {
089 ((AxesPanel)panel).setName(xAxis.getName(), yAxis.getName());
090 super.updateConfiguration();
091 }
092
093 /**
094 * Mouse moved.
095 *
096 * @param x position on X-axis
097 * @param y position on Y-axis
098 */
099 protected void mouseMove(int x, int y) {
100 int X = ((AxesPanel)panel).getImageX(x);
101 int Y = ((AxesPanel)panel).getImageY(y);
102
103 if ((Y >= 0) && (Y < yAxis.getEntityNumber())) {
104 if (normalOrientation) {
105 if (shift_pressed && (image.getSortedColor(null,yAxis,X,Y)==null))
106 Scene.setStatus(" ");
107 else {
108 Entity entity = yAxis.getEntity(Y);
109 Scene.setStatus(entity == null ? " " : entity.getName());
110 }
111 } else {
112 if (shift_pressed && (image.getSortedColor(yAxis,null,X,Y)==null))
113 Scene.setStatus(" ");
114 else {
115 Entity entity = yAxis.getEntity(X);
116 Scene.setStatus(entity == null ? " " : entity.getName());
117 }
118 }
119 } else {
120 Scene.setStatus(" ");
121 }
122 }
123
124 protected void changeOrientation() {
125 super.changeOrientation();
126 sort();
127 }
128
129 private String timeHeader() {
130 DataFilter dataFilter = xAxis.getDataFilter();
131 String[] property = dataFilter.getProperty();
132 for (int i=0; i< property.length; i++) {
133 if (property[i].equals("time"))
134 return "Time - ";
135 }
136 return "";
137 }
138
139 protected String getEntityUnderMouse() {
140 int X = ((AxesPanel)panel).getImageX(mouseX);
141 int Y = ((AxesPanel)panel).getImageY(mouseY);
142
143 if ((Y >= 0) && (Y < yAxis.getEntityNumber())) {
144 if (normalOrientation) {
145 if ((image.getSortedColor(null,yAxis,X,Y)!=null))
146 return yAxis.getEntity(Y).getName();
147 } else {
148 if (image.getSortedColor(yAxis,null,X,Y)!=null)
149 return yAxis.getEntity(X).getName();
150 }
151 }
152
153 return null;
154 }
155 }