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 EVolve.visualization.XYViz.XYVisualization;
011 import EVolve.visualization.*;
012 import EVolve.visualization.Dimension;
013 import EVolve.Scene;
014 import java.util.ArrayList;
015
016 public abstract class ReferenceReferenceVisualization extends XYVisualization{
017 protected ReferenceDimension xAxis, yAxis;
018 protected ValueDimension zAxis; // used as correlation
019 protected int[][] value; // value of the points
020 protected String[] info;
021 protected static int SELECT_OPTION;
022
023
024 public Dimension[] createDimension() {
025 value = null;
026 xAxis = new ReferenceDimension();
027 yAxis = new ReferenceDimension();
028 zAxis = null;
029 info = new String[3];
030
031 Dimension[] returnVal = new Dimension[2];
032 returnVal[0] = xAxis;
033 returnVal[1] = yAxis;
034
035 SELECT_OPTION = 0x0011;
036 return returnVal;
037 }
038
039 protected void updateConfiguration() {
040 ((AxesPanel)panel).setName(xAxis.getName(), yAxis.getName());
041 super.updateConfiguration();
042 }
043
044 public ReferenceDimension getLinkableDimension(int dim) {
045 if (dim > 1)
046 return null;
047 return (ReferenceDimension)dimension[dim];
048 }
049
050 public void makeSelection() {
051 if (SELECT_OPTION == 0) {
052 Scene.showErrorMessage("Nothing will be selected, please check Selection menu.");
053 return;
054 }
055
056 int x1 = ((AxesPanel)panel).getStartX();
057 int x2 = ((AxesPanel)panel).getEndX();
058 int y1 = ((AxesPanel)panel).getEndY();
059 int y2 = ((AxesPanel)panel).getStartY();
060
061 if (x1 < 0) {
062 x1 = 0;
063 }
064
065 if (x2 > (xAxis.getEntityNumber() - 1)) {
066 x2 = xAxis.getEntityNumber() - 1;
067 }
068
069 if (y1 < 0) {
070 y1 = 0;
071 }
072
073 if (y2 > (yAxis.getEntityNumber() - 1)) {
074 y2 = yAxis.getEntityNumber() - 1;
075 }
076
077 int[] selection = null;
078 switch (SELECT_OPTION & 0xf0f0) {
079 case 0x1000: // select occurred entities on x axis
080 ArrayList idList = new ArrayList();
081 for (int i=x1; i<=x2; i++) {
082 for (int j=y1; j<=y2; j++) {
083 if (image.getSortedColor(xAxis,yAxis,i,j) != null)
084 idList.add(new Integer(i));
085 }
086 }
087 selection = new int[idList.size()];
088 for (int i=0; i<idList.size(); i++)
089 selection[i] = ((Integer)idList.get(i)).intValue();
090 xAxis.makeSelection(selection);
091 break;
092 case 0x0010: // select all entities on x axis
093 selection = new int[x2-x1+1];
094 for (int i=x1; i<=x2; i++)
095 selection[i-x1] = i;
096 xAxis.makeSelection(selection);
097 break;
098 case 0x0000: // x axis is not seletcted
099 /*x1 = 0;
100 x2 = xAxis.getEntityNumber() - 1;
101 selection = new int[x2-x1+1];
102 for (int i=0; i<=x2; i++)
103 selection[i] = i;*/
104 break;
105 }
106
107 switch (SELECT_OPTION & 0x0f0f) {
108 case 0x0100: //select occurred entities
109 ArrayList idList = new ArrayList();
110 for (int i=x1; i<=x2; i++) {
111 for (int j=y1; j<=y2; j++) {
112 if (image.getSortedColor(xAxis,yAxis,i,j) != null)
113 idList.add(new Integer(i));
114 }
115 }
116 selection = new int[idList.size()];
117 for (int i=0; i<idList.size(); i++)
118 selection[i] = ((Integer)idList.get(i)).intValue();
119 yAxis.makeSelection(selection);
120 break;
121 case 0x0001: // select all entities
122 selection = new int[y2-y1+1];
123 for (int i=y1; i<=y2; i++)
124 selection[i-y1] = i;
125 yAxis.makeSelection(selection);
126 break;
127 case 0x0000:
128 /*y1 = 0;
129 y2 = yAxis.getEntityNumber() - 1;
130 selection = new int[y2-y1+1];
131 for (int i=0; i<=y2; i++)
132 selection[i] = i;*/
133 break;
134 }
135
136 }
137
138 /**
139 * Mouse moved.
140 *
141 * @param x position on X-axis
142 * @param y position on Y-axis
143 */
144 protected void mouseMove(int x, int y) {
145 int X = ((AxesPanel)panel).getImageX(x);
146 int Y = ((AxesPanel)panel).getImageY(y);
147
148 if ((X >= 0) && (X < xAxis.getEntityNumber()) && (Y >= 0) && (Y < yAxis.getEntityNumber())) {
149
150 if (shift_pressed && (image.getSortedColor(xAxis,yAxis,X,Y)==null))
151 Scene.setStatus(" ");
152 else {
153 if (value == null)
154 Scene.setStatus(info[0] + xAxis.getEntity(X).getName() + info[1] +
155 yAxis.getEntity(Y).getName() + info[2]);
156 else {
157 Scene.setStatus(info[0] + xAxis.getEntity(X).getName() + info[1] +
158 yAxis.getEntity(Y).getName() + info[2] + value[xAxis.getEntity(X).getId()][yAxis.getEntity(Y).getId()]);
159 }
160 }
161 } else {
162 Scene.setStatus(" ");
163 }
164 }
165
166 public void sort() {
167 magnifier.setAxises(xAxis,yAxis);
168 ((AxesPanel)panel).setName(xAxis.getName() + " (" + xAxis.getEntityNumber() +
169 ", " + xAxis.getSelectedComparatorName() + ")",
170 yAxis.getName() + " (" + yAxis.getEntityNumber() +
171 ", " + yAxis.getSelectedComparatorName() + ")");
172 ((AxesPanel)panel).setImage(image.getSortedImage(xAxis, yAxis).getImage());
173 panel.repaint();
174 enableBrowseSourceMenu();
175 }
176
177 protected void changeOrientation() {
178 super.changeOrientation();
179 ReferenceDimension temp = xAxis;
180 xAxis = yAxis;
181 yAxis = temp;
182 String tempInfo = info[0];
183 info[0] = info[1];
184 info[1] = tempInfo;
185 sort();
186 }
187
188 public int[][] getValue() {
189 return value;
190 }
191
192 public void setValue(int[][] newValue) {
193 value = newValue;
194 }
195
196 protected String getEntityUnderMouse() {
197 return null;
198 }
199 }