001 /* EVolve - an Extensible Software Visualization Framework 002 * Copyright (C) 2001-2002 Qin Wang 003 * 004 * This library is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Library General Public 006 * License as published by the Free Software Foundation; either 007 * version 2 of the License, or (at your option) any later version. 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Library General Public 015 * License along with this library; if not, write to the 016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 017 * Boston, MA 02111-1307, USA. 018 */ 019 020 /* 021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/ 022 */ 023 024 package EVolve.data; 025 026 import java.awt.Color; 027 import java.util.HashMap; 028 import java.util.Iterator; 029 030 import EVolve.Scene; 031 032 public class ElementFilter { 033 private int[] linkIndex; 034 private HashMap[] color; 035 protected Color colorBlue = new Color(120, 160, 255); 036 037 public ElementFilter(ElementDefinition elementDefinition, Selection[] selection) { 038 int count = 0; 039 for (int i = 0; i < elementDefinition.getFieldDefinition().length; i++) { 040 if (elementDefinition.getFieldDefinition()[i].getReference() != -1) { 041 count++; 042 } 043 } 044 linkIndex = new int[count]; 045 count = 0; 046 for (int i = 0; i < elementDefinition.getFieldDefinition().length; i++) { 047 if (elementDefinition.getFieldDefinition()[i].getReference() != -1) { 048 linkIndex[count] = i; 049 count++; 050 } 051 } 052 053 color = new HashMap[linkIndex.length]; 054 for (int i = 0; i < color.length; i++) { 055 //color[i] = new Color[Scene.getDataManager().getEntity()[elementDefinition.getFieldDefinition()[linkIndex[i]].getReference()].size()]; 056 color[i] = new HashMap(); 057 HashMap entities = Scene.getDataManager().getEntity()[elementDefinition.getFieldDefinition()[linkIndex[i]].getReference()]; 058 Iterator it = entities.keySet().iterator(); 059 while (it.hasNext()) { 060 Long key = (Long)it.next(); 061 color[i].put(key,colorBlue); 062 for (int k = 0; k < selection.length; k++) { 063 boolean isSelected = true; 064 065 for (int l = 0; l < selection[k].getLink().length; l++) { 066 if ((selection[k].getLink()[l].getSourceType() == elementDefinition.getType()) && 067 (selection[k].getLink()[l].getSourceIndex() == linkIndex[i])) { 068 isSelected = false; 069 for (int m = 0; m < selection[k].getSelected().length; m++) { 070 if (selection[k].getLink()[l].getTarget(key.longValue()) == selection[k].getSelected()[m].getId()) { 071 isSelected = true; 072 if ((color[i].get(key) == colorBlue) && (selection[k].getColor() != null)) { 073 color[i].put(key,selection[k].getColor()); 074 } 075 break; 076 } 077 } 078 break; 079 } 080 } 081 if ((!isSelected) && (selection[k].getColor() == null)) { 082 color[i].put(key,null); 083 break; 084 } 085 } 086 } 087 088 /*for (int j = 0; j < color[i].length; j++) { 089 color[i][j] = colorBlue;//Color.black; 090 for (int k = 0; k < selection.length; k++) { 091 boolean isSelected = true; 092 for (int l = 0; l < selection[k].getLink().length; l++) { 093 if ((selection[k].getLink()[l].getSourceType() == elementDefinition.getType()) && (selection[k].getLink()[l].getOriginMappedId() == linkIndex[i])) { 094 isSelected = false; 095 for (int m = 0; m < selection[k].getSelected().length; m++) { 096 if (selection[k].getLink()[l].getTarget(j) == selection[k].getSelected()[m].getId()) { 097 isSelected = true; 098 if ((color[i][j] == colorBlue) && (selection[k].getColor() != null)) { 099 color[i][j] = selection[k].getColor(); 100 } 101 break; 102 } 103 } 104 break; 105 } 106 } 107 if ((!isSelected) && (selection[k].getColor() == null)) { 108 color[i][j] = null; 109 break; 110 } 111 } 112 }*/ 113 } 114 } 115 116 public Color getColor(Element element) { 117 Color result = colorBlue;//Color.black; 118 for (int i = 0; i < linkIndex.length; i++) { 119 if (color[i].get(new Long(element.getField()[linkIndex[i]])) == null) { 120 return null; 121 } 122 if (result == colorBlue/*Color.black*/) { 123 result = (Color)color[i].get(new Long(element.getField()[linkIndex[i]])); 124 } 125 } 126 return result; 127 } 128 }