001 /*
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: 4-Sep-2002
005 * Time: 1:44:25 PM
006 * To change template for new class use
007 * Code Style | Class Templates options (Tools | IDE Options).
008 */
009 package EVolve.util;
010
011 import EVolve.visualization.*;
012 import EVolve.data.*;
013 import java.util.ArrayList;
014 import EVolve.Scene;
015
016 public class LinkedVisualization {
017 private boolean repaint;
018 private ArrayList viz;
019 private int dimension;
020 private int targetType;
021 private Entity[][] entity_defined;
022 private Entity[] entity;
023 private int beginRepaint;
024
025
026 public LinkedVisualization(int dimension) {
027 repaint = false;
028 this.dimension = dimension;
029 viz = new ArrayList();
030 targetType = -1;
031 entity_defined = new Entity[Scene.getDataManager().getElementDefinition().length][];
032 for (int i=0; i<entity_defined.length; i++) {
033 entity_defined[i] = null;
034 }
035 beginRepaint = 0;
036 }
037
038 public boolean getRepaint() {
039 return repaint;
040 }
041
042 public void setRepaint(boolean repaint) {
043 this.repaint = repaint;
044 }
045
046 public boolean exists(Visualization visual) {
047 boolean retValue = false;
048 for (int i=0;i<viz.size();i++) {
049 if (((Visualization)viz.get(i)).getVisualizationID() == visual.getVisualizationID()) {
050 retValue = true;
051 }
052 }
053 return retValue;
054 }
055
056 private void updateMaxEntity(Visualization visual) {
057 ReferenceDimension referenceDimension = visual.getLinkableDimension(dimension);
058 if (referenceDimension != null)
059 referenceDimension.linkEntities(entity);
060 }
061
062 public void addVisualization(Visualization [] visuals) {
063 int type,beginRepaint = viz.size();
064
065 for (int i=0;i<visuals.length;i++) {
066 if (exists(visuals[i])) { beginRepaint =0; continue;}
067 type = visuals[i].getLinkableDimension(dimension).getDataFilter().getTargetType();
068 if ((targetType != type)&&(entity_defined[type]==null)) {
069 entity_defined[type] = Scene.getDataManager().getEntity()[type];
070 entity = entity_defined[type];
071 targetType = type;
072 }
073 viz.add(viz.size(),visuals[i]);
074 }
075 for (int i = beginRepaint; i< viz.size(); i++) {
076 updateMaxEntity((Visualization)viz.get(i));
077 }
078 }
079
080 public void visualize() {
081 Scene.getVisualizationManager().prepareForLinkedViz(viz,beginRepaint);
082 Scene.visualize();
083 setRepaint(false);
084 beginRepaint = 0;
085 }
086
087 public void unregisterViz(Visualization visual) {
088 for (int i=0;i<viz.size();i++) {
089 if (((Visualization)viz.get(i)).getVisualizationID() == visual.getVisualizationID()) {
090 viz.remove(i);
091 }
092 }
093 if (viz.size() == 1) viz.clear();
094 }
095 }