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 EVolve.*; 027 import java.awt.*; 028 029 public class ElementFilter { 030 private int[] linkIndex; 031 private Color[][] color; 032 protected Color colorBlue = new Color(120, 160, 255); 033 034 public ElementFilter(ElementDefinition elementDefinition, Selection[] selection) { 035 int count = 0; 036 for (int i = 0; i < elementDefinition.getFieldDefinition().length; i++) { 037 if (elementDefinition.getFieldDefinition()[i].getReference() != -1) { 038 count++; 039 } 040 } 041 linkIndex = new int[count]; 042 count = 0; 043 for (int i = 0; i < elementDefinition.getFieldDefinition().length; i++) { 044 if (elementDefinition.getFieldDefinition()[i].getReference() != -1) { 045 linkIndex[count] = i; 046 count++; 047 } 048 } 049 050 color = new Color[linkIndex.length][]; 051 for (int i = 0; i < color.length; i++) { 052 color[i] = new Color[Scene.getDataManager().getEntity()[elementDefinition.getFieldDefinition()[linkIndex[i]].getReference()].length]; 053 for (int j = 0; j < color[i].length; j++) { 054 color[i][j] = colorBlue;//Color.black; 055 for (int k = 0; k < selection.length; k++) { 056 boolean isSelected = true; 057 for (int l = 0; l < selection[k].getLink().length; l++) { 058 if ((selection[k].getLink()[l].getSourceType() == elementDefinition.getType()) && (selection[k].getLink()[l].getSourceIndex() == linkIndex[i])) { 059 isSelected = false; 060 for (int m = 0; m < selection[k].getSelected().length; m++) { 061 if (selection[k].getLink()[l].getTarget(j) == selection[k].getSelected()[m].getId()) { 062 isSelected = true; 063 if ((color[i][j] == colorBlue/*Color.black*/) && (selection[k].getColor() != null)) { 064 color[i][j] = selection[k].getColor(); 065 } 066 break; 067 } 068 } 069 break; 070 } 071 } 072 if ((!isSelected) && (selection[k].getColor() == null)) { 073 color[i][j] = null; 074 break; 075 } 076 } 077 } 078 } 079 } 080 081 public Color getColor(Element element) { 082 Color result = colorBlue;//Color.black; 083 for (int i = 0; i < linkIndex.length; i++) { 084 if (color[i][element.getField()[linkIndex[i]]] == null) { 085 return null; 086 } 087 if (result == colorBlue/*Color.black*/) { 088 result = color[i][element.getField()[linkIndex[i]]]; 089 } 090 } 091 return result; 092 } 093 }