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
028 public class ReferenceLink {
029 private String name; // name of the link
030 private int sourceType; // type of the source element
031 private int sourceIndex; // field index of the source element
032 private int targetType; // type of the target entity
033 private int[] target; // id of the targets
034 private String description; // description of the link
035
036 /**
037 * Creates a reference link.
038 *
039 * @param name name of the link
040 * @param sourceType type of the source element
041 * @param sourceIndex field index of the source element
042 * @param targetType type of the target entity
043 * @param description description of the link
044 */
045 public ReferenceLink(String name, int sourceType, int sourceIndex, int targetType, String description) {
046 this.name = name;
047 this.sourceType = sourceType;
048 this.sourceIndex = sourceIndex;
049 this.targetType = targetType;
050 this.description = description;
051
052 target = new int[Scene.getDataManager().getEntity()[targetType].length];
053 for (int i = 0; i < target.length; i++) {
054 target[i] = i;
055 }
056 }
057
058 /**
059 * Creates a reference link by combining two reference links.
060 *
061 * @param from where the link starts
062 * @param to where the link ends
063 */
064 public ReferenceLink(ReferenceLink from, ReferenceLink to) {
065 this.name = to.name;
066 this.sourceType = from.sourceType;
067 this.sourceIndex = from.sourceIndex;
068 this.targetType = to.targetType;
069 this.description = from.description + " >>> " + to.description;
070
071 target = new int[from.target.length];
072 for (int i = 0; i < target.length; i++) {
073 target[i] = to.target[Scene.getDataManager().getEntity()[from.targetType][from.target[i]].getField()[to.sourceIndex]];
074 }
075 }
076
077 /**
078 * Gets the name of the link.
079 *
080 * @return name of the link
081 */
082 public String getName() {
083 return name;
084 }
085
086 /**
087 * Gets the type of the source element.
088 *
089 * @return type of the source element
090 */
091 public int getSourceType() {
092 return sourceType;
093 }
094
095 /**
096 * Gets the field index of the source element.
097 *
098 * @return field index of the source element
099 */
100 public int getSourceIndex() {
101 return sourceIndex;
102 }
103
104 /**
105 * Gets the type of the target entity.
106 *
107 * @return type of the target entity
108 */
109 public int getTargetType() {
110 return targetType;
111 }
112
113 /**
114 * Gets the target.
115 *
116 * @param source reference
117 * @return target
118 */
119 public int getTarget(int source) {
120 return target[source];
121 }
122
123 /**
124 * Gets the description of the link.
125 *
126 * @return description of the link
127 */
128 public String getDescription() {
129 return description;
130 }
131 }