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.Scene; 011 import EVolve.data.DataFilter; 012 import EVolve.data.Entity; 013 import EVolve.data.Selection; 014 import EVolve.exceptions.NoDataPlotException; 015 import EVolve.util.xmlutils.datastructures.SerializedVisualization; 016 import EVolve.visualization.Dimension; 017 import EVolve.visualization.ReferenceDimension; 018 import EVolve.visualization.ValueDimension; 019 import EVolve.visualization.XYViz.XYVisualization; 020 021 022 public abstract class ValueReferenceVisualization extends XYVisualization{ 023 protected ValueDimension xAxis; 024 protected ReferenceDimension yAxis; 025 protected ReferenceDimension zAxis; 026 private long start=0; 027 028 public Dimension[] createDimension() { 029 Dimension [] returnDimension = new Dimension[2]; 030 031 xAxis = new ValueDimension(); 032 yAxis = new ReferenceDimension(true); 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 protected void adjustTimeAxis() { 047 Selection activeSelection = Scene.getFilter().getActiveSelection(); 048 start = ((activeSelection == null)) ? 0 : activeSelection.getStartTime(); 049 if (start < 0) start = 0; 050 } 051 052 public void sort() { 053 if (image == null) return; 054 055 canvas.reset(); 056 try { 057 String comparatorName = ""; 058 try { 059 comparatorName = yAxis.getSelectedComparatorName(); 060 } catch (IndexOutOfBoundsException e) { 061 // this exception happens when user click fresh button before visulize the topmost viz 062 return; 063 } 064 int beforeLink = yAxis.getEntityNumberBeforeLink(); 065 066 if (normalOrientation) { 067 canvas.setName(timeHeader() + xAxis.getName() + " (" + 068 ((interval == -1) ? ""+xMax+"" : ((""+start +" - ")) + (xMax > start ? xMax : start+xMax)) + 069 (interval == -1 ? "" : (",interval " + String.valueOf(interval))) +")", 070 yAxis.getName() + " (" + ((beforeLink == -1) ? "" : (""+beforeLink+" / " + yAxis.getEntityNumber())) 071 + ", " + comparatorName +")"); 072 canvas.setAutoImage(image.getSortedImage(null, yAxis)); 073 } else { 074 canvas.setName(yAxis.getName() + " (" + ((beforeLink == -1) ? "" : (""+beforeLink+" / ")) + 075 yAxis.getEntityNumber() + ", " + comparatorName + ")", 076 timeHeader() + xAxis.getName() + " (" + 077 ((interval == -1) ? ""+xMax+"" : ((""+start +" - ")) + (xMax > start ? xMax : start+xMax)) 078 + ")"); 079 canvas.setAutoImage(image.getSortedImage(yAxis, null)); 080 } 081 canvas.repaint(); 082 enableBrowseSourceMenu(); 083 } catch (NoDataPlotException e) { 084 Scene.showErrorMessage(e.getMessage()); 085 } 086 } 087 088 public SerializedVisualization getCurrentConfiguration() { 089 SerializedVisualization data = super.getCurrentConfiguration(); 090 data.xAxis = xAxis.getName(); 091 data.yAxis = yAxis.getName(); 092 data.yAxisSortScheme = comboSortSchemes[0].getSelectedItem().toString(); 093 data.zAxis = (zAxis == null) ? null : zAxis.getName(); 094 095 return data; 096 } 097 098 protected void updateConfiguration() { 099 canvas.setName(xAxis.getName(), yAxis.getName()); 100 super.updateConfiguration(); 101 } 102 103 /** 104 * Mouse moved. 105 * 106 * @param x position on X-axis 107 * @param y position on Y-axis 108 */ 109 protected String mouseMove(int x, int y) { 110 int X = canvas.getImageX(x); 111 int Y = canvas.getImageY(y); 112 String time = xAxis.getName(); 113 String returnVal = null; 114 115 if ((Y >= 0) && (Y < yAxis.getEntityNumber())) { 116 if (shift_pressed && (image.getSortedColor(null,yAxis,X,Y)==null)) 117 Scene.setStatus(" "); 118 else { 119 Entity entity = yAxis.getEntity(Y); 120 time = ((interval == -1)||(X>=timeMap.size())||(X<0)) ? "" : time + ":" + ((long[])timeMap.get(X))[0]; 121 if (entity != null) { 122 if (((interval == -1)||(X>=timeMap.size())||(X<0))) 123 return null; 124 returnVal = entity.getName() + ":" + ((long[])timeMap.get(X))[0]; 125 Scene.setStatus(returnVal); 126 } else 127 Scene.setStatus(" "); 128 } 129 130 } else { 131 Scene.setStatus(" "); 132 } 133 return returnVal; 134 } 135 136 protected void changeOrientation() { 137 super.changeOrientation(); 138 sort(); 139 } 140 141 private String timeHeader() { 142 DataFilter dataFilter = xAxis.getDataFilter(); 143 String[] property = dataFilter.getProperty(); 144 for (int i=0; i< property.length; i++) { 145 if (property[i].equals("time")) 146 return "Time - "; 147 } 148 return ""; 149 } 150 151 protected String getEntityUnderMouse() { 152 int X = canvas.getImageX(mouseX); 153 int Y = canvas.getImageY(mouseY); 154 155 if ((Y >= 0) && (Y < yAxis.getEntityNumber())) { 156 if (normalOrientation) { 157 if ((image.getSortedColor(null,yAxis,X,Y)!=null)) 158 return yAxis.getEntity(Y).getName(); 159 } else { 160 if (image.getSortedColor(yAxis,null,X,Y)!=null) 161 return yAxis.getEntity(X).getName(); 162 } 163 } 164 165 return null; 166 } 167 168 public Object clone(){ 169 ValueReferenceVisualization o = null; 170 171 o = (ValueReferenceVisualization)super.clone(); 172 173 o.xAxis =(ValueDimension)xAxis.clone(); 174 o.yAxis =(ReferenceDimension) yAxis.clone(); 175 o.zAxis =(zAxis == null) ? null : (ReferenceDimension)zAxis.clone(); 176 o.dimension[0] = o.xAxis; 177 o.dimension[1] = o.yAxis; 178 if (o.zAxis != null) o.dimension[2] = o.zAxis; 179 o.createMenu(); 180 181 return o; 182 } 183 }