Project

General

Profile

Download (7.83 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright 2005, CHISEL Group, University of Victoria, Victoria, BC, Canada.
3
 * All rights reserved. This program and the accompanying materials are made
4
 * available under the terms of the Eclipse Public License v1.0 which
5
 * accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors: The Chisel Group, University of Victoria
9
 *******************************************************************************/
10
package org.eclipse.zest.layouts.exampleStructures;
11

    
12
import java.util.HashMap;
13
import java.util.Map;
14

    
15
import org.eclipse.zest.layouts.LayoutBendPoint;
16
import org.eclipse.zest.layouts.LayoutEntity;
17
import org.eclipse.zest.layouts.LayoutRelationship;
18
import org.eclipse.zest.layouts.constraints.BasicEdgeConstraints;
19
import org.eclipse.zest.layouts.constraints.LabelLayoutConstraint;
20
import org.eclipse.zest.layouts.constraints.LayoutConstraint;
21
import org.eclipse.zest.layouts.dataStructures.BendPoint;
22

    
23
/**
24
 * The SimpleRelation class describes the relationship between
25
 * two objects: source and destination.  Each relationship
26
 * has a weight and direction associated with it.
27
 * Note: The source object is at the beginning of the relationship.
28
 * Note: The destination object is at the end of the relationship.
29
 *
30
 * @version  2.0
31
 * @author   Casey Best (version 1.0 by Jingwei Wu)
32
 * @author Chris Bennett
33
 */
34
public class SimpleRelationship implements LayoutRelationship {
35

    
36
	private static int DEFAULT_REL_LINE_WIDTH = 1;
37
	private static int DEFAULT_REL_LINE_WIDTH_SELECTED = DEFAULT_REL_LINE_WIDTH + 2;
38
	private static Object DEFAULT_RELATIONSHIP_COLOR;
39
	private static Object DEFAULT_RELATIONSHIP_HIGHLIGHT_COLOR;
40

    
41
	/** The line width for this relationship. */
42
	private int lineWidth = DEFAULT_REL_LINE_WIDTH;
43

    
44
	/** The color for this relationship. */
45
	private Object color = DEFAULT_RELATIONSHIP_COLOR;
46

    
47
	/**
48
	 * A list of layout dependent attributes
49
	 */
50
	private Map attributes;
51

    
52
	/**
53
	 * The sourceEntity of this SimpleRelation.
54
	 */
55
	protected LayoutEntity sourceEntity;
56

    
57
	/**
58
	 * The object of this SimpleRelation.
59
	 */
60
	protected LayoutEntity destinationEntity;
61

    
62
	/**
63
	 * If directional, algorithms must note the direction of the relationship.
64
	 * If not directional, algorithms are to ignore which direction the relationship is going.
65
	 * Switching the source and destination should make no difference. 
66
	 */
67
	protected boolean bidirectional;
68

    
69
	/**
70
	 * The weight given to this relation.
71
	 */
72
	private double weight;
73

    
74
	private Object internalRelationship;
75

    
76
	private LayoutBendPoint[] bendPoints;
77

    
78
	private String label;
79

    
80
	/**
81
	 * Constructor.
82
	 * @param sourceEntity The sourceEntity of this SimpleRelation.
83
	 * @param destinationEntity The object of this SimpleRelation.
84
	 * @param bidirectional Determines if the <code>sourceEntity</code> and
85
	 * <code>destinationEntity</code> are equal(exchangeable).
86
	 * @throws java.lang.NullPointerException If either <code>sourceEntity
87
	 * </code> or <code>destinationEntity</code> is <code>null</code>.
88
	 */
89
	public SimpleRelationship(LayoutEntity sourceEntity, LayoutEntity destinationEntity, boolean bidirectional) {
90
		this(sourceEntity, destinationEntity, bidirectional, 1);
91
	}
92

    
93
	/**
94
	 * Constructor.
95
	 * @param sourceEntity The sourceEntity of this SimpleRelation.
96
	 * @param destinationEntity The destinationEntity of this SimpleRelation.
97
	 * @param exchangeable Determines if the <code>sourceEntity</code> and
98
	 * <code>destinationEntity</code> are equal(exchangeable).
99
	 * @throws java.lang.NullPointerException If either <code>sourceEntity
100
	 * </code> or <code>destinationEntity</code> is <code>null</code>.
101
	 */
102
	public SimpleRelationship(LayoutEntity sourceEntity, LayoutEntity destinationEntity, boolean bidirectional, double weight) {
103
		this.destinationEntity = destinationEntity;
104
		this.sourceEntity = sourceEntity;
105
		this.bidirectional = bidirectional;
106
		this.weight = weight;
107
		this.attributes = new HashMap();
108
		this.lineWidth = DEFAULT_REL_LINE_WIDTH;
109
		this.color = DEFAULT_RELATIONSHIP_COLOR;
110
	}
111

    
112
	/**
113
	 * Gets the sourceEntity of this SimpleRelation whether the relation is
114
	 * exchangeable or not.
115
	 * @return The sourceEntity.
116
	 */
117
	public LayoutEntity getSourceInLayout() {
118
		return sourceEntity;
119
	}
120

    
121
	/**
122
	 * Gets the destinationEntity of this SimpleRelation whether the relation is
123
	 * exchangeable or not.
124
	 * @return The destinationEntity of this SimpleRelation.
125
	 */
126
	public LayoutEntity getDestinationInLayout() {
127
		return destinationEntity;
128
	}
129

    
130
	/**
131
	 * If bidirectional, the direction of the relationship doesn't matter.  Switching the source and destination should make no difference.
132
	 * If not bidirectional, layout algorithms need to take into account the direction of the relationship.  The direction is based on the
133
	 * source and destination entities.
134
	 */
135
	public boolean isBidirectionalInLayout() {
136
		return bidirectional;
137
	}
138

    
139
	public void setWeightInLayout(double weight) {
140
		this.weight = weight;
141
	}
142

    
143
	public double getWeightInLayout() {
144
		return weight;
145
	}
146

    
147
	/**
148
	 * An algorithm may require a place to store information.  Use this structure for that purpose.
149
	 */
150
	public void setAttributeInLayout(String attribute, Object value) {
151
		attributes.put(attribute, value);
152
	}
153

    
154
	/**
155
	 * An algorithm may require a place to store information.  Use this structure for that purpose.
156
	 */
157
	public Object getAttributeInLayout(String attribute) {
158
		return attributes.get(attribute);
159
	}
160

    
161
	public String toString() {
162
		String arrow = (isBidirectionalInLayout() ? " <-> " : " -> ");
163
		return "(" + sourceEntity + arrow + destinationEntity + ")";
164
	}
165

    
166
	public int getLineWidth() {
167
		return this.lineWidth;
168
	}
169

    
170
	public void setLineWidth(int lineWidth) {
171
		this.lineWidth = lineWidth;
172
	}
173

    
174
	public void resetLineWidth() {
175
		this.lineWidth = DEFAULT_REL_LINE_WIDTH;
176
	}
177

    
178
	public static void setDefaultSize(int i) {
179
		DEFAULT_REL_LINE_WIDTH = i;
180
		DEFAULT_REL_LINE_WIDTH_SELECTED = DEFAULT_REL_LINE_WIDTH + 2;
181
	}
182

    
183
	public void setSelected() {
184
		this.color = DEFAULT_RELATIONSHIP_HIGHLIGHT_COLOR;
185
		this.lineWidth = DEFAULT_REL_LINE_WIDTH_SELECTED;
186
	}
187

    
188
	public void setUnSelected() {
189
		this.color = DEFAULT_RELATIONSHIP_COLOR;
190
		this.lineWidth = DEFAULT_REL_LINE_WIDTH;
191
	}
192

    
193
	public Object getColor() {
194
		return color;
195
	}
196

    
197
	public void setColor(Object c) {
198
		this.color = c;
199
	}
200

    
201
	public static void setDefaultColor(Object c) {
202
		DEFAULT_RELATIONSHIP_COLOR = c;
203
	}
204

    
205
	public static void setDefaultHighlightColor(Object c) {
206
		DEFAULT_RELATIONSHIP_HIGHLIGHT_COLOR = c;
207
	}
208

    
209
	/* (non-Javadoc)
210
	 * @see ca.uvic.cs.chisel.layouts.LayoutRelationship#getInternalRelationship()
211
	 */
212
	public Object getLayoutInformation() {
213
		return internalRelationship;
214
	}
215

    
216
	/* (non-Javadoc)
217
	 * @see ca.uvic.cs.chisel.layouts.LayoutRelationship#setInternalRelationship(java.lang.Object)
218
	 */
219
	public void setLayoutInformation(Object layoutInformation) {
220
		this.internalRelationship = layoutInformation;
221
	}
222

    
223
	public void setBendPoints(LayoutBendPoint[] bendPoints) {
224
		this.bendPoints = bendPoints;
225
	}
226

    
227
	public LayoutBendPoint[] getBendPoints() {
228
		return this.bendPoints;
229
	}
230

    
231
	public void clearBendPoints() {
232
		this.bendPoints = new BendPoint[0];
233
	}
234

    
235
	public void setDestinationInLayout(LayoutEntity destination) {
236
		this.destinationEntity = destination;
237
	}
238

    
239
	/**
240
	 * Set the label for this edge (available in the label layout constraint). 
241
	 */
242
	public void setLabel(String label) {
243
		this.label = label;
244
	}
245

    
246
	/**
247
	 * Populate the specified layout constraint
248
	 */
249
	public void populateLayoutConstraint(LayoutConstraint constraint) {
250
		if (constraint instanceof LabelLayoutConstraint) {
251
			LabelLayoutConstraint labelConstraint = (LabelLayoutConstraint) constraint;
252
			labelConstraint.label = this.label;
253
			labelConstraint.pointSize = 18;
254
		} else if (constraint instanceof BasicEdgeConstraints) {
255
			// noop
256

    
257
		}
258
	}
259

    
260
	public Object getGraphData() {
261
		return null;
262
	}
263

    
264
	public void setGraphData(Object o) {
265

    
266
	}
267

    
268
}
(4-4/4)