001 /** 002 * Created by IntelliJ IDEA. 003 * User: Wei Wang 004 * Date: Nov 28, 2002 005 * Time: 12:45:22 AM 006 */ 007 008 package EVolve.visualization.XYViz.RefRefViz; 009 010 import java.util.HashMap; 011 012 import EVolve.Scene; 013 import EVolve.exceptions.NoDataPlotException; 014 import EVolve.visualization.Dimension; 015 import EVolve.visualization.ReferenceDimension; 016 import EVolve.visualization.ValueDimension; 017 import EVolve.visualization.XYViz.XYVisualization; 018 019 public abstract class ReferenceReferenceVisualization extends XYVisualization{ 020 protected ReferenceDimension xAxis, yAxis; 021 protected ValueDimension zAxis; // used as correlation 022 protected int[][] value; // value of the points 023 protected String[] info; 024 protected static int SELECT_OPTION; 025 026 027 public Dimension[] createDimension() { 028 value = null; 029 xAxis = new ReferenceDimension(true); 030 yAxis = new ReferenceDimension(true); 031 zAxis = null; 032 info = new String[3]; 033 034 Dimension[] returnVal = new Dimension[2]; 035 returnVal[0] = xAxis; 036 returnVal[1] = yAxis; 037 038 SELECT_OPTION = 0x0011; 039 return returnVal; 040 } 041 042 protected void updateConfiguration() { 043 canvas.setName(xAxis.getName(), yAxis.getName()); 044 super.updateConfiguration(); 045 } 046 047 public void preVisualize() { 048 timeMap.clear(); 049 } 050 051 public ReferenceDimension getLinkableDimension(int dim) { 052 if (dim > 1) 053 return null; 054 return (ReferenceDimension)dimension[dim]; 055 } 056 057 public void makeSelection() { 058 preMakeSelection(); 059 if (selectionName==null) return; 060 061 if (SELECT_OPTION == 0) { 062 Scene.showErrorMessage("Nothing will be selected, please check Selection menu."); 063 return; 064 } 065 066 if (dataSourceId != Scene.getDataSourceManager().getCurrentDataSourceId()) { 067 Scene.showErrorMessage("The active data source used currently is different from \n" + 068 "this visualization, please choose \"" + 069 Scene.getDataSourceManager().getUsedDataSourceName(dataSourceId)+"\"."); 070 return; 071 } 072 073 int x1 = canvas.getStartX(); 074 int x2 = canvas.getEndX(); 075 int y1 = canvas.getEndY(); 076 int y2 = canvas.getStartY(); 077 078 if (((x1<0)&&(x2<0)) || ((x1>=xAxis.getEntityNumber()))&&(x2>=xAxis.getEntityNumber()) || 079 ((y1<0)&&(y2<0)) || ((y1>=yAxis.getEntityNumber())&&(y2>=yAxis.getEntityNumber()))) 080 return; 081 082 if (x1 < 0) { 083 x1 = 0; 084 } 085 086 if (x2 > (xAxis.getEntityNumber() - 1)) { 087 x2 = xAxis.getEntityNumber() - 1; 088 } 089 090 if (y1 < 0) { 091 y1 = 0; 092 } 093 094 if (y2 > (yAxis.getEntityNumber() - 1)) { 095 y2 = yAxis.getEntityNumber() - 1; 096 } 097 098 int[] selection = null; 099 switch (SELECT_OPTION & 0xf0f0) { 100 case 0x1000: // select occurred entities on x axis 101 HashMap idList = new HashMap(); 102 for (int i=x1; i<=x2; i++) { 103 for (int j=y1; j<=y2; j++) { 104 if ((image.getSortedColor(xAxis,yAxis,i,j) != null)&&(!idList.containsValue(new Integer(i)))) 105 idList.put(new Integer(idList.size()),new Integer(i)); 106 } 107 } 108 selection = new int[idList.size()]; 109 for (int i=0; i<idList.size(); i++) 110 selection[i] = ((Integer)idList.get(new Integer(i))).intValue(); 111 xAxis.makeSelection(selectionName,subjectDefinition.getType(),selection); 112 break; 113 case 0x0010: // select all entities on x axis 114 selection = new int[x2-x1+1]; 115 for (int i=x1; i<=x2; i++) 116 selection[i-x1] = i; 117 xAxis.makeSelection(selectionName,subjectDefinition.getType(),selection); 118 break; 119 case 0x0000: // x axis is not seletcted 120 /*x1 = 0; 121 x2 = xAxis.getEntityNumber() - 1; 122 selection = new int[x2-x1+1]; 123 for (int i=0; i<=x2; i++) 124 selection[i] = i;*/ 125 break; 126 } 127 128 switch (SELECT_OPTION & 0x0f0f) { 129 case 0x0100: //select occurred entities 130 HashMap idList = new HashMap(); 131 for (int i=x1; i<=x2; i++) { 132 for (int j=y1; j<=y2; j++) { 133 if ((image.getSortedColor(xAxis,yAxis,i,j) != null)&&(!idList.containsValue(new Integer(i)))) 134 idList.put(new Integer(idList.size()),new Integer(i)); 135 } 136 } 137 selection = new int[idList.size()]; 138 for (int i=0; i<idList.size(); i++) 139 selection[i] = ((Integer)idList.get(new Integer(i))).intValue(); 140 yAxis.makeSelection(selectionName,subjectDefinition.getType(),selection); 141 break; 142 case 0x0001: // select all entities 143 selection = new int[y2-y1+1]; 144 for (int i=y1; i<=y2; i++) 145 selection[i-y1] = i; 146 yAxis.makeSelection(selectionName,subjectDefinition.getType(),selection); 147 break; 148 case 0x0000: 149 /*y1 = 0; 150 y2 = yAxis.getEntityNumber() - 1; 151 selection = new int[y2-y1+1]; 152 for (int i=0; i<=y2; i++) 153 selection[i] = i;*/ 154 break; 155 } 156 157 } 158 159 /** 160 * Mouse moved. 161 * 162 * @param x position on X-axis 163 * @param y position on Y-axis 164 */ 165 protected String mouseMove(int x, int y) { 166 int X = canvas.getImageX(x); 167 int Y = canvas.getImageY(y); 168 169 if ((X >= 0) && (X < xAxis.getEntityNumber()) && (Y >= 0) && (Y < yAxis.getEntityNumber())) { 170 171 if (shift_pressed && (image.getSortedColor(xAxis,yAxis,X,Y)==null)) 172 Scene.setStatus(" "); 173 else { 174 if (value == null) 175 Scene.setStatus(info[0] + xAxis.getEntity(X).getName() + info[1] + 176 yAxis.getEntity(Y).getName() + info[2]); 177 else { 178 HashMap mapX = xAxis.getEntityName2IntMap(); 179 HashMap mapY = yAxis.getEntityName2IntMap(); 180 String xName = xAxis.getEntity(X).getName(), yName = yAxis.getEntity(Y).getName(); 181 Scene.setStatus(info[0] + xName + info[1] + yName + 182 info[2] + value[((Integer)mapX.get(xName)).intValue()][((Integer)mapY.get(yName)).intValue()]); 183 } 184 } 185 } else { 186 Scene.setStatus(" "); 187 } 188 189 return null; 190 } 191 192 public void sort() { 193 try { 194 int before1 = xAxis.getEntityNumberBeforeLink(); 195 int before2 = xAxis.getEntityNumberBeforeLink(); 196 canvas.setName(xAxis.getName() + " (" + ((before1 == -1) ? "" : (""+before1+" / ")) 197 + xAxis.getEntityNumber() + 198 ", " + xAxis.getSelectedComparatorName() + ")", 199 yAxis.getName() + " (" + ((before2 == -1) ? "" : (""+before2+" / ")) 200 + yAxis.getEntityNumber() + 201 ", " + yAxis.getSelectedComparatorName() + ")"); 202 canvas.setImage(image.getSortedImage(xAxis, yAxis).getImage()); 203 canvas.repaint(); 204 enableBrowseSourceMenu(); 205 } catch (NoDataPlotException e) { 206 Scene.showErrorMessage(e.getMessage()); 207 } 208 } 209 210 protected void changeOrientation() { 211 super.changeOrientation(); 212 ReferenceDimension temp = xAxis; 213 xAxis = yAxis; 214 yAxis = temp; 215 String tempInfo = info[0]; 216 info[0] = info[1]; 217 info[1] = tempInfo; 218 sort(); 219 } 220 221 public int[][] getValue() { 222 return value; 223 } 224 225 public void setValue(int[][] newValue) { 226 value = newValue; 227 } 228 229 protected String getEntityUnderMouse() { 230 return null; 231 } 232 233 public Object clone() { 234 ReferenceReferenceVisualization o = null; 235 236 o = (ReferenceReferenceVisualization)super.clone(); 237 o.xAxis = (ReferenceDimension)xAxis.clone(); 238 o.yAxis = (ReferenceDimension)yAxis.clone(); 239 o.zAxis = (ValueDimension)zAxis.clone(); 240 o.dimension[0] = o.xAxis; 241 o.dimension[1] = o.yAxis; 242 o.dimension[2] = o.zAxis; 243 o.createMenu(); 244 if (value != null) { 245 o.value = new int[value.length][]; 246 for (int i=0; i<value.length; i++) { 247 o.value[i] = new int[value[i].length]; 248 for (int j=0; j<value[i].length; j++) 249 o.value[i][j] = value[i][j]; 250 } 251 } 252 if (info != null) { 253 o.info = new String[info.length]; 254 for (int i=0; i<info.length; i++) 255 o.info[i] = info[i]; 256 } 257 o.panelConfiguration = o.createConfigurationPanel(); 258 o.createDialog(); 259 return o; 260 } 261 }