Lines 1-12
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, |
2 |
* Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, |
3 |
* Canada. All rights reserved. This program and the accompanying materials are |
3 |
* Canada. All rights reserved. This program and the accompanying materials are |
4 |
* made available under the terms of the Eclipse Public License v1.0 which |
4 |
* made available under the terms of the Eclipse Public License v1.0 which |
5 |
* accompanies this distribution, and is available at |
5 |
* accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: The Chisel Group, University of Victoria |
8 |
* Contributors: |
|
|
9 |
* The Chisel Group, University of Victoria |
10 |
* Mateusz Matela <mateusz.matela@gmail.com> - Adapt Zest to changes in layout - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283179 |
9 |
******************************************************************************/ |
11 |
******************************************************************************/ |
|
|
12 |
|
10 |
package org.eclipse.zest.core.widgets; |
13 |
package org.eclipse.zest.core.widgets; |
11 |
|
14 |
|
12 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
Lines 14-74
Link Here
|
14 |
import java.util.LinkedList; |
17 |
import java.util.LinkedList; |
15 |
import java.util.List; |
18 |
import java.util.List; |
16 |
|
19 |
|
|
|
20 |
import org.eclipse.draw2d.ActionEvent; |
21 |
import org.eclipse.draw2d.ActionListener; |
17 |
import org.eclipse.draw2d.Animation; |
22 |
import org.eclipse.draw2d.Animation; |
|
|
23 |
import org.eclipse.draw2d.Clickable; |
18 |
import org.eclipse.draw2d.ColorConstants; |
24 |
import org.eclipse.draw2d.ColorConstants; |
|
|
25 |
import org.eclipse.draw2d.Figure; |
19 |
import org.eclipse.draw2d.FreeformLayout; |
26 |
import org.eclipse.draw2d.FreeformLayout; |
20 |
import org.eclipse.draw2d.FreeformViewport; |
27 |
import org.eclipse.draw2d.FreeformViewport; |
|
|
28 |
import org.eclipse.draw2d.Graphics; |
21 |
import org.eclipse.draw2d.IFigure; |
29 |
import org.eclipse.draw2d.IFigure; |
|
|
30 |
import org.eclipse.draw2d.Label; |
22 |
import org.eclipse.draw2d.LayoutAnimator; |
31 |
import org.eclipse.draw2d.LayoutAnimator; |
23 |
import org.eclipse.draw2d.LineBorder; |
32 |
import org.eclipse.draw2d.LineBorder; |
24 |
import org.eclipse.draw2d.PolylineConnection; |
|
|
25 |
import org.eclipse.draw2d.ScrollPane; |
33 |
import org.eclipse.draw2d.ScrollPane; |
|
|
34 |
import org.eclipse.draw2d.ToolbarLayout; |
35 |
import org.eclipse.draw2d.Triangle; |
26 |
import org.eclipse.draw2d.Viewport; |
36 |
import org.eclipse.draw2d.Viewport; |
27 |
import org.eclipse.draw2d.geometry.Dimension; |
37 |
import org.eclipse.draw2d.geometry.Dimension; |
28 |
import org.eclipse.draw2d.geometry.Point; |
38 |
import org.eclipse.draw2d.geometry.Point; |
29 |
import org.eclipse.draw2d.geometry.Rectangle; |
39 |
import org.eclipse.draw2d.geometry.Rectangle; |
|
|
40 |
import org.eclipse.swt.events.SelectionEvent; |
41 |
import org.eclipse.swt.events.SelectionListener; |
42 |
import org.eclipse.swt.graphics.Color; |
30 |
import org.eclipse.swt.graphics.Image; |
43 |
import org.eclipse.swt.graphics.Image; |
|
|
44 |
import org.eclipse.swt.graphics.RGB; |
45 |
import org.eclipse.swt.widgets.Display; |
31 |
import org.eclipse.zest.core.widgets.internal.AspectRatioFreeformLayer; |
46 |
import org.eclipse.zest.core.widgets.internal.AspectRatioFreeformLayer; |
32 |
import org.eclipse.zest.core.widgets.internal.ContainerFigure; |
47 |
import org.eclipse.zest.core.widgets.internal.ContainerFigure; |
33 |
import org.eclipse.zest.core.widgets.internal.ExpandGraphLabel; |
|
|
34 |
import org.eclipse.zest.core.widgets.internal.ZestRootLayer; |
48 |
import org.eclipse.zest.core.widgets.internal.ZestRootLayer; |
35 |
import org.eclipse.zest.layouts.InvalidLayoutConfiguration; |
|
|
36 |
import org.eclipse.zest.layouts.LayoutAlgorithm; |
49 |
import org.eclipse.zest.layouts.LayoutAlgorithm; |
37 |
import org.eclipse.zest.layouts.LayoutEntity; |
|
|
38 |
import org.eclipse.zest.layouts.LayoutRelationship; |
39 |
import org.eclipse.zest.layouts.LayoutStyles; |
40 |
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; |
50 |
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; |
|
|
51 |
import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle; |
41 |
|
52 |
|
42 |
/* |
53 |
/** |
43 |
* A Container than can be added to a Graph. Nodes can be added to this |
54 |
* A Container that can be added to a Graph. Nodes can be added to this |
44 |
* container. The container supports collapsing and expanding and has the same |
55 |
* container. The container supports collapsing and expanding and has the same |
45 |
* properties as the nodes. Containers cannot have custom figures. |
56 |
* properties as the nodes. Containers cannot have custom figures. |
46 |
* |
57 |
* |
47 |
* @author Ian Bull |
58 |
* @author Ian Bull |
48 |
*/ |
59 |
*/ |
49 |
public class GraphContainer extends GraphNode implements IContainer { |
60 |
public class GraphContainer extends GraphNode { |
|
|
61 |
|
62 |
public static class ExpandGraphLabel extends Figure implements ActionListener { |
63 |
|
64 |
private boolean isExpanded; |
65 |
private Expander expander = new Expander(); |
66 |
private Color darkerBackground; |
67 |
|
68 |
class Expander extends Clickable { |
69 |
private Triangle triangle; |
70 |
|
71 |
public Expander() { |
72 |
setStyle(Clickable.STYLE_TOGGLE); |
73 |
triangle = new Triangle(); |
74 |
triangle.setSize(10, 10); |
75 |
triangle.setBackgroundColor(ColorConstants.black); |
76 |
triangle.setForegroundColor(ColorConstants.black); |
77 |
triangle.setFill(true); |
78 |
triangle.setDirection(Triangle.EAST); |
79 |
triangle.setLocation(new Point(5, 3)); |
80 |
this.setLayoutManager(new FreeformLayout()); |
81 |
this.add(triangle); |
82 |
this.setPreferredSize(15, 15); |
83 |
this.addActionListener(ExpandGraphLabel.this); |
84 |
} |
85 |
|
86 |
public void open() { |
87 |
triangle.setDirection(Triangle.SOUTH); |
88 |
} |
89 |
|
90 |
public void close() { |
91 |
triangle.setDirection(Triangle.EAST); |
92 |
} |
93 |
|
94 |
} |
95 |
|
96 |
/** |
97 |
* Sets the expander state (the little triangle) to |
98 |
* ExpanderGraphLabel.OPEN or ExpanderGraphLabel.CLOSED |
99 |
* |
100 |
* @param state |
101 |
*/ |
102 |
public void setExpandedState(boolean expanded) { |
103 |
if (expanded) { |
104 |
expander.open(); |
105 |
} else { |
106 |
expander.close(); |
107 |
} |
108 |
this.isExpanded = expanded; |
109 |
} |
110 |
|
111 |
/* |
112 |
* (non-Javadoc) |
113 |
* |
114 |
* @see |
115 |
* org.eclipse.draw2d.ActionListener#actionPerformed(org.eclipse.draw2d |
116 |
* .ActionEvent) |
117 |
*/ |
118 |
public void actionPerformed(ActionEvent event) { |
119 |
if (isExpanded) { |
120 |
container.close(true); |
121 |
} else { |
122 |
container.open(true); |
123 |
} |
124 |
} |
125 |
|
126 |
private final int arcWidth = 8; |
127 |
private final Label label; |
128 |
private final GraphContainer container; |
129 |
private final ToolbarLayout layout; |
130 |
|
131 |
public ExpandGraphLabel(GraphContainer container, String text, Image image, boolean cacheLabel) { |
132 |
this.label = new Label(text) { |
133 |
|
134 |
/** |
135 |
* <b>This method is overwritten so that the text is not |
136 |
* truncated.</b><br> |
137 |
* |
138 |
* {@inheritDoc} |
139 |
* |
140 |
*/ |
141 |
protected void paintFigure(Graphics graphics) { |
142 |
if (isOpaque()) { |
143 |
super.paintFigure(graphics); |
144 |
} |
145 |
Rectangle bounds = getBounds(); |
146 |
graphics.translate(bounds.x, bounds.y); |
147 |
if (getIcon() != null) { |
148 |
graphics.drawImage(getIcon(), getIconLocation()); |
149 |
} |
150 |
if (!isEnabled()) { |
151 |
graphics.translate(1, 1); |
152 |
graphics.setForegroundColor(ColorConstants.buttonLightest); |
153 |
graphics.drawText(getSubStringText(), getTextLocation()); |
154 |
graphics.translate(-1, -1); |
155 |
graphics.setForegroundColor(ColorConstants.buttonDarker); |
156 |
} |
157 |
graphics.drawText(getText(), getTextLocation()); |
158 |
graphics.translate(-bounds.x, -bounds.y); |
159 |
} |
160 |
}; |
161 |
this.setText(text); |
162 |
this.setImage(image); |
163 |
this.container = container; |
164 |
this.setFont(Display.getDefault().getSystemFont()); |
165 |
layout = new ToolbarLayout(true); |
166 |
layout.setSpacing(5); |
167 |
layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); |
168 |
this.setLayoutManager(layout); |
169 |
this.add(this.expander); |
170 |
this.add(this.label); |
171 |
} |
172 |
|
173 |
private Color getDarkerBackgroundColor() { |
174 |
if (darkerBackground == null) { |
175 |
Color baseColor = getBackgroundColor(); |
176 |
int blue = (int) (baseColor.getBlue() * 0.8 + 0.5); |
177 |
int red = (int) (baseColor.getRed() * 0.8 + 0.5); |
178 |
int green = (int) (baseColor.getGreen() * 0.8 + 0.5); |
179 |
darkerBackground = new Color(Display.getCurrent(), new RGB(red, green, blue)); |
180 |
} |
181 |
return darkerBackground; |
182 |
} |
183 |
|
184 |
/* |
185 |
* (non-Javadoc) |
186 |
* |
187 |
* @see |
188 |
* org.eclipse.draw2d.Label#paintFigure(org.eclipse.draw2d.Graphics) |
189 |
*/ |
190 |
public void paint(Graphics graphics) { |
191 |
|
192 |
graphics.setForegroundColor(getDarkerBackgroundColor()); |
193 |
graphics.setBackgroundColor(getBackgroundColor()); |
194 |
|
195 |
graphics.pushState(); |
196 |
|
197 |
// fill in the background |
198 |
Rectangle bounds = getBounds().getCopy(); |
199 |
Rectangle r = bounds.getCopy(); |
200 |
r.y += arcWidth / 2; |
201 |
r.height -= arcWidth; |
202 |
|
203 |
Rectangle top = bounds.getCopy(); |
204 |
top.height /= 2; |
205 |
graphics.setForegroundColor(getBackgroundColor()); |
206 |
graphics.setBackgroundColor(getBackgroundColor()); |
207 |
graphics.fillRoundRectangle(top, arcWidth, arcWidth); |
208 |
|
209 |
top.y = top.y + top.height; |
210 |
graphics.setForegroundColor(darkerBackground); |
211 |
graphics.setBackgroundColor(darkerBackground); |
212 |
graphics.fillRoundRectangle(top, arcWidth, arcWidth); |
213 |
|
214 |
graphics.setBackgroundColor(darkerBackground); |
215 |
graphics.setForegroundColor(getBackgroundColor()); |
216 |
graphics.fillGradient(r, true); |
217 |
|
218 |
super.paint(graphics); |
219 |
graphics.popState(); |
220 |
graphics.setForegroundColor(darkerBackground); |
221 |
graphics.setBackgroundColor(darkerBackground); |
222 |
// paint the border |
223 |
bounds.setSize(bounds.width - 1, bounds.height - 1); |
224 |
graphics.drawRoundRectangle(bounds, arcWidth, arcWidth); |
225 |
} |
226 |
|
227 |
public void setBackgroundColor(Color bg) { |
228 |
super.setBackgroundColor(bg); |
229 |
if (darkerBackground != null) { |
230 |
darkerBackground.dispose(); |
231 |
} |
232 |
darkerBackground = null; |
233 |
} |
234 |
|
235 |
public void setTextT(String string) { |
236 |
this.setPreferredSize(null); |
237 |
this.label.setText(string); |
238 |
this.add(label); |
239 |
this.layout.layout(this); |
240 |
this.invalidate(); |
241 |
this.revalidate(); |
242 |
this.validate(); |
243 |
} |
244 |
|
245 |
public void setText(String string) { |
246 |
this.label.setText(string); |
247 |
} |
248 |
|
249 |
public void setImage(Image image) { |
250 |
this.label.setIcon(image); |
251 |
} |
252 |
|
253 |
public void setFocus() { |
254 |
expander.requestFocus(); |
255 |
} |
256 |
|
257 |
} |
50 |
|
258 |
|
51 |
//private static final double CONTAINER_SCALE = 0.75; |
259 |
static final double SCALED_WIDTH = 300; |
52 |
private static final double scaledWidth = 300; |
260 |
static final double SCALED_HEIGHT = 200; |
53 |
private static final double scaledHeight = 200; |
|
|
54 |
private static final int CONTAINER_HEIGHT = 200; |
261 |
private static final int CONTAINER_HEIGHT = 200; |
55 |
private static final int MIN_WIDTH = 250; |
262 |
private static final int MIN_WIDTH = 250; |
|
|
263 |
private static final int MIN_HEIGHT = 30; |
56 |
private static final int ANIMATION_TIME = 100; |
264 |
private static final int ANIMATION_TIME = 100; |
57 |
private static final int SUBLAYER_OFFSET = 2; |
265 |
private static final int SUBLAYER_OFFSET = 2; |
58 |
|
266 |
|
|
|
267 |
private static SelectionListener selectionListener; |
268 |
|
59 |
private ExpandGraphLabel expandGraphLabel; |
269 |
private ExpandGraphLabel expandGraphLabel; |
60 |
|
270 |
|
61 |
//private FreeformLayer container; |
|
|
62 |
//private FreeformLayer edgeLayer; |
63 |
private List childNodes = null; |
271 |
private List childNodes = null; |
64 |
private int childAreaHeight = CONTAINER_HEIGHT; |
272 |
private int childAreaHeight = CONTAINER_HEIGHT; |
65 |
|
273 |
|
66 |
public ZestRootLayer zestLayer; |
274 |
private ZestRootLayer zestLayer; |
67 |
private ScrollPane scrollPane; |
275 |
private ScrollPane scrollPane; |
68 |
private LayoutAlgorithm layoutAlgorithm; |
276 |
private LayoutAlgorithm layoutAlgorithm; |
69 |
private boolean isExpanded = false; |
277 |
private boolean isExpanded = false; |
70 |
//private ScalableFreeformLayeredPane scalledLayer; |
|
|
71 |
private AspectRatioFreeformLayer scalledLayer; |
278 |
private AspectRatioFreeformLayer scalledLayer; |
|
|
279 |
private InternalLayoutContext layoutContext; |
72 |
|
280 |
|
73 |
/** |
281 |
/** |
74 |
* Creates a new GraphContainer. A GraphContainer may contain nodes, |
282 |
* Creates a new GraphContainer. A GraphContainer may contain nodes, |
Lines 76-96
Link Here
|
76 |
* @param graph The graph that the container is being added to |
284 |
* @param graph The graph that the container is being added to |
77 |
* @param style |
285 |
* @param style |
78 |
*/ |
286 |
*/ |
79 |
public GraphContainer(IContainer graph, int style) { |
287 |
public GraphContainer(Graph graph, int style) { |
80 |
this(graph, style, ""); |
288 |
this(graph, style, ""); |
|
|
289 |
} |
290 |
|
291 |
public GraphContainer(Graph graph, int style, String text) { |
292 |
this(graph, style, text, null); |
293 |
} |
81 |
|
294 |
|
|
|
295 |
public GraphContainer(Graph graph, int style, String text, Image image) { |
296 |
this(NodeContainerAdapter.get(graph), style, text, image); |
82 |
} |
297 |
} |
83 |
|
298 |
|
84 |
public GraphContainer(IContainer graph, int style, String text) { |
299 |
public GraphContainer(GraphContainer graph, int style) { |
|
|
300 |
this(graph, style, ""); |
301 |
} |
302 |
|
303 |
public GraphContainer(GraphContainer graph, int style, String text) { |
85 |
this(graph, style, text, null); |
304 |
this(graph, style, text, null); |
|
|
305 |
} |
86 |
|
306 |
|
|
|
307 |
public GraphContainer(GraphContainer graph, int style, String text, Image image) { |
308 |
this(NodeContainerAdapter.get(graph), style, text, image); |
87 |
} |
309 |
} |
88 |
|
310 |
|
89 |
public GraphContainer(IContainer graph, int style, String text, Image image) { |
311 |
public GraphContainer(NodeContainerAdapter graph, int style, String text, Image image) { |
90 |
super(graph, style, text, image); |
312 |
super(graph.getGraph(), style, text, image); |
91 |
initModel(graph, text, image); |
313 |
initModel(graph, text, image); |
92 |
close(false); |
314 |
close(false); |
93 |
childNodes = new ArrayList(); |
315 |
childNodes = new ArrayList(); |
|
|
316 |
registerToParent(graph); |
94 |
} |
317 |
} |
95 |
|
318 |
|
96 |
/** |
319 |
/** |
Lines 100-119
Link Here
|
100 |
throw new RuntimeException("Operation not supported: Containers cannot have custom figures"); |
323 |
throw new RuntimeException("Operation not supported: Containers cannot have custom figures"); |
101 |
} |
324 |
} |
102 |
|
325 |
|
103 |
/* |
|
|
104 |
* (non-Javadoc) |
105 |
* @see org.eclipse.mylar.zest.core.widgets.GraphItem#getItemType() |
106 |
public int getItemType() { |
107 |
return GraphItem.CONTAINER; |
108 |
} |
109 |
|
110 |
/** |
111 |
* Gets the figure for this container. |
112 |
*/ |
113 |
public IFigure getNodeFigure() { |
114 |
return this.nodeFigure; |
115 |
} |
116 |
|
117 |
/** |
326 |
/** |
118 |
* Close this node. |
327 |
* Close this node. |
119 |
* @param animate |
328 |
* @param animate |
Lines 124-139
Link Here
|
124 |
} |
333 |
} |
125 |
isExpanded = false; |
334 |
isExpanded = false; |
126 |
|
335 |
|
127 |
expandGraphLabel.setExpandedState(ExpandGraphLabel.CLOSED); |
336 |
expandGraphLabel.setExpandedState(false); |
128 |
Rectangle newBounds = scrollPane.getBounds().getCopy(); |
337 |
Rectangle newBounds = scrollPane.getBounds().getCopy(); |
129 |
newBounds.height = 0; |
338 |
newBounds.height = 0; |
130 |
|
339 |
|
131 |
//this.nodeFigure.setConstraint(scrollPane, newBounds); |
|
|
132 |
//this.nodeFigure.revalidate(); |
133 |
scrollPane.setSize(scrollPane.getSize().width, 0); |
340 |
scrollPane.setSize(scrollPane.getSize().width, 0); |
134 |
updateFigureForModel(this.zestLayer); |
341 |
updateFigureForModel(this.zestLayer); |
135 |
scrollPane.setVisible(false); |
342 |
scrollPane.setVisible(false); |
136 |
//setSize(expandGraphLabel.getSize().width, expandGraphLabel.getSize().height); |
|
|
137 |
List children = this.zestLayer.getChildren(); |
343 |
List children = this.zestLayer.getChildren(); |
138 |
for (Iterator iterator = children.iterator(); iterator.hasNext();) { |
344 |
for (Iterator iterator = children.iterator(); iterator.hasNext();) { |
139 |
IFigure child = (IFigure) iterator.next(); |
345 |
IFigure child = (IFigure) iterator.next(); |
Lines 145-151
Link Here
|
145 |
if (animate) { |
351 |
if (animate) { |
146 |
Animation.run(ANIMATION_TIME); |
352 |
Animation.run(ANIMATION_TIME); |
147 |
} |
353 |
} |
148 |
//this.nodeFigure.getUpdateManager().performUpdate(); |
|
|
149 |
updateFigureForModel(nodeFigure); |
354 |
updateFigureForModel(nodeFigure); |
150 |
} |
355 |
} |
151 |
|
356 |
|
Lines 235-241
Link Here
|
235 |
private void moveNodesUp(Rectangle containerBounds, GraphNode graphContainer) { |
440 |
private void moveNodesUp(Rectangle containerBounds, GraphNode graphContainer) { |
236 |
|
441 |
|
237 |
// Get all nodes below this container, in order |
442 |
// Get all nodes below this container, in order |
238 |
List orderedNodesBelowY = getOrderedNodesBelowY(parent.getNodes(), containerBounds.y, graphContainer); |
443 |
List orderedNodesBelowY = getOrderedNodesBelowY(parent.getGraph().getNodes(), containerBounds.y, graphContainer); |
239 |
int leftSide = containerBounds.x; |
444 |
int leftSide = containerBounds.x; |
240 |
int rightSide = containerBounds.x + containerBounds.width; |
445 |
int rightSide = containerBounds.x + containerBounds.width; |
241 |
List nodesToConsider = new LinkedList(); |
446 |
List nodesToConsider = new LinkedList(); |
Lines 292-302
Link Here
|
292 |
} |
497 |
} |
293 |
isExpanded = true; |
498 |
isExpanded = true; |
294 |
|
499 |
|
295 |
expandGraphLabel.setExpandedState(ExpandGraphLabel.OPEN); |
500 |
expandGraphLabel.setExpandedState(true); |
296 |
|
501 |
|
297 |
scrollPane.setSize(computeChildArea()); |
502 |
scrollPane.setSize(computeChildArea()); |
298 |
scrollPane.setVisible(true); |
503 |
scrollPane.setVisible(true); |
299 |
//setSize(expandGraphLabel.getSize().width, expandGraphLabel.getSize().height + expandedHeight - SUBLAYER_OFFSET); |
|
|
300 |
|
504 |
|
301 |
List children = this.zestLayer.getChildren(); |
505 |
List children = this.zestLayer.getChildren(); |
302 |
for (Iterator iterator = children.iterator(); iterator.hasNext();) { |
506 |
for (Iterator iterator = children.iterator(); iterator.hasNext();) { |
Lines 308-323
Link Here
|
308 |
updateFigureForModel(nodeFigure); |
512 |
updateFigureForModel(nodeFigure); |
309 |
|
513 |
|
310 |
Rectangle containerBounds = new Rectangle(this.getLocation(), new Dimension(this.getSize().width, CONTAINER_HEIGHT + this.expandGraphLabel.getSize().height)); |
514 |
Rectangle containerBounds = new Rectangle(this.getLocation(), new Dimension(this.getSize().width, CONTAINER_HEIGHT + this.expandGraphLabel.getSize().height)); |
311 |
//moveIntersectedNodes(containerBounds, this); |
|
|
312 |
moveNodesDown(containerBounds, this); |
515 |
moveNodesDown(containerBounds, this); |
313 |
moveNodesUp(containerBounds, this); |
516 |
moveNodesUp(containerBounds, this); |
314 |
//pack(graph); |
|
|
315 |
if (animate) { |
517 |
if (animate) { |
316 |
Animation.run(ANIMATION_TIME); |
518 |
Animation.run(ANIMATION_TIME); |
317 |
} |
519 |
} |
318 |
this.getFigure().getUpdateManager().performValidation(); |
520 |
this.getFigure().getUpdateManager().performValidation(); |
319 |
//this.nodeFigure.getUpdateManager().performUpdate(); |
|
|
320 |
|
321 |
} |
521 |
} |
322 |
|
522 |
|
323 |
/** |
523 |
/** |
Lines 328-334
Link Here
|
328 |
private void moveNodesDown(Rectangle containerBounds, GraphContainer graphContainer) { |
528 |
private void moveNodesDown(Rectangle containerBounds, GraphContainer graphContainer) { |
329 |
|
529 |
|
330 |
// Find all nodes below here |
530 |
// Find all nodes below here |
331 |
List nodesBelowHere = getOrderedNodesBelowY(parent.getNodes(), containerBounds.y, graphContainer); |
531 |
List nodesBelowHere = getOrderedNodesBelowY(parent.getGraph().getNodes(), containerBounds.y, graphContainer); |
332 |
Iterator nodesBelowHereIterator = nodesBelowHere.iterator(); |
532 |
Iterator nodesBelowHereIterator = nodesBelowHere.iterator(); |
333 |
List nodesToMove = new LinkedList(); |
533 |
List nodesToMove = new LinkedList(); |
334 |
int left = containerBounds.x; |
534 |
int left = containerBounds.x; |
Lines 349-391
Link Here
|
349 |
|
549 |
|
350 |
} |
550 |
} |
351 |
|
551 |
|
352 |
void highlightNode(GraphNode node) { |
|
|
353 |
|
354 |
} |
355 |
|
356 |
void highlightEdge(GraphConnection connection) { |
357 |
} |
358 |
|
359 |
void highlightNode(GraphContainer container) { |
360 |
|
361 |
} |
362 |
|
363 |
void unhighlightNode(GraphNode node) { |
364 |
|
365 |
} |
366 |
|
367 |
void unhighlightNode(GraphContainer container) { |
368 |
|
369 |
} |
370 |
|
371 |
// /** |
372 |
// * Gets a list of nodes below the given node |
373 |
// * @param node |
374 |
// * @return |
375 |
// */ |
376 |
// private List getNodesBelow(int y, List nodes) { |
377 |
// Iterator allNodes = nodes.iterator(); |
378 |
// LinkedList result = new LinkedList(); |
379 |
// while (allNodes.hasNext()) { |
380 |
// GraphNode nextNode = (GraphNode) allNodes.next(); |
381 |
// int top = nextNode.getLocation().y; |
382 |
// if (top > y) { |
383 |
// result.add(nextNode); |
384 |
// } |
385 |
// } |
386 |
// return result; |
387 |
// } |
388 |
|
389 |
/** |
552 |
/** |
390 |
* Checks all the nodes in the list of nodesToCheck to see if they intersect with the bounds set |
553 |
* Checks all the nodes in the list of nodesToCheck to see if they intersect with the bounds set |
391 |
* @param node |
554 |
* @param node |
Lines 439-561
Link Here
|
439 |
} |
602 |
} |
440 |
} |
603 |
} |
441 |
|
604 |
|
442 |
// /** |
|
|
443 |
// * This finds the highest Y Value of a set of nodes. |
444 |
// * @param nodes |
445 |
// * @return |
446 |
// */ |
447 |
// private int findSmallestYValue(List nodes) { |
448 |
// Iterator iterator = nodes.iterator(); |
449 |
// int lowestNode /*highest on the screen*/= Integer.MAX_VALUE - 100; // Subtract 100 so we don't overflow |
450 |
// while (iterator.hasNext()) { |
451 |
// GraphNode node = (GraphNode) iterator.next(); |
452 |
// int y = node.getLocation().y; |
453 |
// lowestNode = Math.min(lowestNode, y); |
454 |
// } |
455 |
// return lowestNode; |
456 |
// } |
457 |
|
458 |
// /** |
459 |
// * Clears the nodes that the container intersects as it expands |
460 |
// * @param containerBounds |
461 |
// * @param graphContainer |
462 |
// */ |
463 |
// private void moveIntersectedNodes(Rectangle containerBounds, GraphNode graphContainer) { |
464 |
// |
465 |
// List nodesBelowHere = getNodesBelow(this.getLocation().y, graphContainer.getGraphModel().getNodes()); |
466 |
// List intersectingNodes = intersectingNodes(containerBounds, nodesBelowHere, graphContainer); |
467 |
// int delta = getMaxMovement(containerBounds, intersectingNodes); |
468 |
// shiftNodesDown(intersectingNodes, delta); |
469 |
// |
470 |
// int lowestNode /*highest on the screen*/= findSmallestYValue(intersectingNodes); |
471 |
// nodesBelowHere = getNodesBelow(lowestNode, nodesBelowHere); |
472 |
// |
473 |
// while (nodesBelowHere.size() > 0) { |
474 |
// Iterator intersectingNodeIterator = intersectingNodes.iterator(); |
475 |
// List nodesMovedInLastIteration = new LinkedList(); |
476 |
// while (intersectingNodeIterator.hasNext()) { |
477 |
// GraphNode node = (GraphNode) intersectingNodeIterator.next(); |
478 |
// intersectingNodes = intersectingNodes(node.getBounds(), nodesBelowHere, node); |
479 |
// delta = getMaxMovement(node.getBounds(), intersectingNodes); |
480 |
// if (delta > 0) { |
481 |
// shiftNodesDown(intersectingNodes, delta); |
482 |
// nodesMovedInLastIteration.addAll(intersectingNodes); |
483 |
// } |
484 |
// } |
485 |
// lowestNode /*highest on the screen*/= findSmallestYValue(nodesMovedInLastIteration); |
486 |
// nodesBelowHere = getNodesBelow(lowestNode, nodesBelowHere); |
487 |
// intersectingNodes = nodesMovedInLastIteration; |
488 |
// } |
489 |
// } |
490 |
|
491 |
/** |
605 |
/** |
492 |
* Gets the graph that this container has been added to. |
606 |
* Gets the graph that this container has been added to. |
493 |
*/ |
607 |
*/ |
494 |
public Graph getGraph() { |
608 |
public Graph getGraph() { |
495 |
return this.graph.getGraph(); |
609 |
return this.graph; |
496 |
} |
610 |
} |
497 |
|
611 |
|
498 |
public int getItemType() { |
612 |
public int getItemType() { |
499 |
return CONTAINER; |
613 |
return CONTAINER; |
500 |
} |
614 |
} |
501 |
|
615 |
|
502 |
/** |
|
|
503 |
* |
504 |
*/ |
505 |
public void setLayoutAlgorithm(LayoutAlgorithm algorithm, boolean applyLayout) { |
616 |
public void setLayoutAlgorithm(LayoutAlgorithm algorithm, boolean applyLayout) { |
|
|
617 |
if (this.layoutAlgorithm != null) { |
618 |
this.layoutAlgorithm.setLayoutContext(null); |
619 |
} |
620 |
|
506 |
this.layoutAlgorithm = algorithm; |
621 |
this.layoutAlgorithm = algorithm; |
|
|
622 |
this.layoutAlgorithm.setLayoutContext(getLayoutContext()); |
507 |
if (applyLayout) { |
623 |
if (applyLayout) { |
508 |
applyLayout(); |
624 |
applyLayout(); |
509 |
} |
625 |
} |
510 |
|
|
|
511 |
} |
626 |
} |
512 |
|
627 |
|
513 |
public void applyLayout() { |
628 |
InternalLayoutContext getLayoutContext() { |
514 |
if ((this.getNodes().size() == 0)) { |
629 |
if (layoutContext == null) { |
515 |
return; |
630 |
layoutContext = new InternalLayoutContext(this); |
516 |
} |
631 |
} |
|
|
632 |
return layoutContext; |
633 |
} |
517 |
|
634 |
|
518 |
int layoutStyle = 0; |
635 |
DisplayIndependentRectangle getLayoutBounds() { |
519 |
|
636 |
double width = GraphContainer.SCALED_WIDTH - 10; |
520 |
if (checkStyle(ZestStyles.NODES_NO_LAYOUT_RESIZE)) { |
637 |
double height = GraphContainer.SCALED_HEIGHT - 10; |
521 |
layoutStyle = LayoutStyles.NO_LAYOUT_NODE_RESIZING; |
638 |
return new DisplayIndependentRectangle(25, 25, width - 50, height - 50); |
522 |
} |
639 |
} |
523 |
|
640 |
|
|
|
641 |
public void applyLayout() { |
524 |
if (layoutAlgorithm == null) { |
642 |
if (layoutAlgorithm == null) { |
525 |
layoutAlgorithm = new TreeLayoutAlgorithm(layoutStyle); |
643 |
setLayoutAlgorithm(new TreeLayoutAlgorithm(), false); |
526 |
} |
|
|
527 |
|
528 |
layoutAlgorithm.setStyle(layoutAlgorithm.getStyle() | layoutStyle); |
529 |
|
530 |
// calculate the size for the layout algorithm |
531 |
//Dimension d = this.scalledLayer.getSize(); |
532 |
Dimension d = new Dimension(); |
533 |
d.width = (int) scaledWidth; |
534 |
d.height = (int) scaledHeight; |
535 |
|
536 |
d.width = d.width - 10; |
537 |
d.height = d.height - 10; |
538 |
//if (d.height <= 0) { |
539 |
//d.height = (CONTAINER_HEIGHT); |
540 |
//} |
541 |
//d.scale(1 / this.scalledLayer.getScale()); |
542 |
|
543 |
if (d.isEmpty()) { |
544 |
return; |
545 |
} |
546 |
LayoutRelationship[] connectionsToLayout = getGraph().getConnectionsToLayout(getNodes()); |
547 |
LayoutEntity[] nodesToLayout = getGraph().getNodesToLayout(getNodes()); |
548 |
|
549 |
try { |
550 |
Animation.markBegin(); |
551 |
layoutAlgorithm.applyLayout(nodesToLayout, connectionsToLayout, 25, 25, d.width - 50, d.height - 50, false, false); |
552 |
Animation.run(ANIMATION_TIME); |
553 |
getFigure().getUpdateManager().performUpdate(); |
554 |
|
555 |
} catch (InvalidLayoutConfiguration e) { |
556 |
e.printStackTrace(); |
557 |
} |
644 |
} |
558 |
|
645 |
Animation.markBegin(); |
|
|
646 |
layoutAlgorithm.applyLayout(); |
647 |
layoutContext.flushChanges(false); |
648 |
Animation.run(ANIMATION_TIME); |
649 |
getFigure().getUpdateManager().performUpdate(); |
559 |
} |
650 |
} |
560 |
|
651 |
|
561 |
/** |
652 |
/** |
Lines 616-651
Link Here
|
616 |
labelWidth = MIN_WIDTH; |
707 |
labelWidth = MIN_WIDTH; |
617 |
expandGraphLabel.setPreferredSize(labelWidth, labelHeight); |
708 |
expandGraphLabel.setPreferredSize(labelWidth, labelHeight); |
618 |
} |
709 |
} |
619 |
if (labelHeight < 30) { |
|
|
620 |
labelHeight = 30; |
621 |
} |
622 |
|
710 |
|
623 |
dimension.labelHeight = labelHeight; |
711 |
dimension.labelHeight = Math.max(labelHeight, MIN_HEIGHT); |
624 |
dimension.width = labelWidth; |
712 |
dimension.width = Math.max(labelWidth, this.size.width); |
625 |
dimension.width = Math.max(dimension.width, this.size.width); |
713 |
dimension.expandedHeight = Math.max(dimension.labelHeight + childAreaHeight - SUBLAYER_OFFSET, this.size.height); |
626 |
dimension.expandedHeight = dimension.labelHeight + childAreaHeight - SUBLAYER_OFFSET; |
|
|
627 |
dimension.expandedHeight = Math.max(dimension.expandedHeight, this.size.height); |
628 |
|
714 |
|
629 |
return dimension; |
715 |
return dimension; |
630 |
} |
716 |
} |
631 |
|
717 |
|
632 |
/* |
|
|
633 |
private double computeChildScale() { |
634 |
Dimension childArea = computeChildArea(); |
635 |
double widthScale = childArea.width / scaledWidth; |
636 |
double heightScale = childArea.height / scaledHeight; |
637 |
return Math.min(widthScale, heightScale); |
638 |
} |
639 |
*/ |
640 |
private double computeHeightScale() { |
718 |
private double computeHeightScale() { |
641 |
Dimension childArea = computeChildArea(); |
719 |
Dimension childArea = computeChildArea(); |
642 |
double heightScale = childArea.height / scaledHeight; |
720 |
double heightScale = childArea.height / SCALED_HEIGHT; |
643 |
return heightScale; |
721 |
return heightScale; |
644 |
} |
722 |
} |
645 |
|
723 |
|
646 |
private double computeWidthScale() { |
724 |
private double computeWidthScale() { |
647 |
Dimension childArea = computeChildArea(); |
725 |
Dimension childArea = computeChildArea(); |
648 |
double widthScale = childArea.width / scaledWidth; |
726 |
double widthScale = childArea.width / SCALED_WIDTH; |
649 |
return widthScale; |
727 |
return widthScale; |
650 |
} |
728 |
} |
651 |
|
729 |
|
Lines 666-715
Link Here
|
666 |
scrollPane.addLayoutListener(LayoutAnimator.getDefault()); |
744 |
scrollPane.addLayoutListener(LayoutAnimator.getDefault()); |
667 |
|
745 |
|
668 |
Viewport viewport = new FreeformViewport(); |
746 |
Viewport viewport = new FreeformViewport(); |
669 |
/* |
|
|
670 |
* This is the code that helps remove the scroll bars moving when the nodes |
671 |
* are dragged. |
672 |
* |
673 |
viewport.setHorizontalRangeModel(new DefaultRangeModel() { |
674 |
public void setAll(int min, int ext, int max) { |
675 |
System.out.println("Max: " + max + " : current Max: " + getMaximum()); |
676 |
if (max < getMaximum()) { |
677 |
max = getMaximum(); |
678 |
} |
679 |
super.setAll(min, ext, max); |
680 |
} |
681 |
|
682 |
public void setMaximum(int maximum) { |
683 |
// TODO Auto-generated method stub |
684 |
System.out.println("Max: " + maximum + " : current Max: " + getMaximum()); |
685 |
if (maximum < getMaximum()) { |
686 |
return; |
687 |
} |
688 |
super.setMaximum(maximum); |
689 |
} |
690 |
}); |
691 |
*/ |
692 |
|
747 |
|
693 |
scrollPane.setViewport(viewport); |
748 |
scrollPane.setViewport(viewport); |
694 |
viewport.addLayoutListener(LayoutAnimator.getDefault()); |
749 |
viewport.addLayoutListener(LayoutAnimator.getDefault()); |
695 |
scrollPane.setScrollBarVisibility(ScrollPane.AUTOMATIC); |
750 |
scrollPane.setScrollBarVisibility(ScrollPane.AUTOMATIC); |
696 |
|
751 |
|
697 |
//scalledLayer = new ScalableFreeformLayeredPane(); |
|
|
698 |
scalledLayer = new AspectRatioFreeformLayer("debug label"); |
752 |
scalledLayer = new AspectRatioFreeformLayer("debug label"); |
699 |
scalledLayer.addLayoutListener(LayoutAnimator.getDefault()); |
753 |
scalledLayer.addLayoutListener(LayoutAnimator.getDefault()); |
700 |
//scalledLayer.setScale(computeChildScale()); |
|
|
701 |
scalledLayer.setScale(computeWidthScale(), computeHeightScale()); |
754 |
scalledLayer.setScale(computeWidthScale(), computeHeightScale()); |
702 |
//container = new FreeformLayer(); |
|
|
703 |
//edgeLayer = new FreeformLayer(); |
704 |
zestLayer = new ZestRootLayer(); |
755 |
zestLayer = new ZestRootLayer(); |
705 |
zestLayer.addLayoutListener(LayoutAnimator.getDefault()); |
756 |
zestLayer.addLayoutListener(LayoutAnimator.getDefault()); |
706 |
//container.addLayoutListener(LayoutAnimator.getDefault()); |
|
|
707 |
//edgeLayer.addLayoutListener(LayoutAnimator.getDefault()); |
708 |
//scalledLayer.add(edgeLayer); |
709 |
//scalledLayer.add(container); |
710 |
scalledLayer.add(zestLayer); |
757 |
scalledLayer.add(zestLayer); |
711 |
|
758 |
|
712 |
//container.setLayoutManager(new FreeformLayout()); |
|
|
713 |
zestLayer.setLayoutManager(new FreeformLayout()); |
759 |
zestLayer.setLayoutManager(new FreeformLayout()); |
714 |
scrollPane.setSize(computeChildArea()); |
760 |
scrollPane.setSize(computeChildArea()); |
715 |
scrollPane.setLocation(new Point(0, containerDimension.labelHeight - SUBLAYER_OFFSET)); |
761 |
scrollPane.setLocation(new Point(0, containerDimension.labelHeight - SUBLAYER_OFFSET)); |
Lines 728-733
Link Here
|
728 |
return containerFigure; |
774 |
return containerFigure; |
729 |
} |
775 |
} |
730 |
|
776 |
|
|
|
777 |
private void registerToParent(NodeContainerAdapter parent) { |
778 |
if (parent.getItemType() == GRAPH) { |
779 |
createSelectionListener(); |
780 |
parent.getGraph().addSelectionListener(selectionListener); |
781 |
} |
782 |
} |
783 |
|
784 |
private void createSelectionListener() { |
785 |
if (selectionListener == null) { |
786 |
selectionListener = new SelectionListener() { |
787 |
public void widgetSelected(SelectionEvent e) { |
788 |
if (e.item instanceof GraphContainer) { |
789 |
//set focus to expand label so that pressing space opens/closes |
790 |
//the last selected container |
791 |
((GraphContainer) e.item).expandGraphLabel.setFocus(); |
792 |
} |
793 |
} |
794 |
|
795 |
public void widgetDefaultSelected(SelectionEvent e) { |
796 |
// ignore |
797 |
} |
798 |
}; |
799 |
|
800 |
} |
801 |
} |
802 |
|
731 |
protected void updateFigureForModel(IFigure currentFigure) { |
803 |
protected void updateFigureForModel(IFigure currentFigure) { |
732 |
|
804 |
|
733 |
expandGraphLabel.setTextT(getText()); |
805 |
expandGraphLabel.setTextT(getText()); |
Lines 774-780
Link Here
|
774 |
refreshLocation(); |
846 |
refreshLocation(); |
775 |
figure.getUpdateManager().performValidation(); |
847 |
figure.getUpdateManager().performValidation(); |
776 |
*/ |
848 |
*/ |
777 |
|
|
|
778 |
} |
849 |
} |
779 |
|
850 |
|
780 |
protected void refreshLocation() { |
851 |
protected void refreshLocation() { |
Lines 803-835
Link Here
|
803 |
scalledLayer.setScale(computeWidthScale(), computeHeightScale()); |
874 |
scalledLayer.setScale(computeWidthScale(), computeHeightScale()); |
804 |
} |
875 |
} |
805 |
|
876 |
|
806 |
void addConnectionFigure(PolylineConnection connection) { |
877 |
void addFigure(IFigure figure) { |
807 |
nodeFigure.add(connection); |
878 |
nodeFigure.add(figure); |
808 |
//zestLayer.addConnection(connection); |
|
|
809 |
} |
879 |
} |
810 |
|
880 |
|
811 |
void addNode(GraphNode node) { |
881 |
void addNode(GraphNode node) { |
812 |
zestLayer.addNode(node.getNodeFigure()); |
882 |
zestLayer.addNode(node.getNodeFigure()); |
813 |
this.childNodes.add(node); |
883 |
this.childNodes.add(node); |
814 |
//container.add(node.getNodeFigure()); |
884 |
node.setVisible(isExpanded); |
815 |
//graph.registerItem(node); |
|
|
816 |
} |
885 |
} |
817 |
|
886 |
|
818 |
void addNode(GraphContainer container) { |
887 |
void addNode(GraphContainer container) { |
819 |
// Containers cannot be added to other containers (yet) |
888 |
throw new RuntimeException("Containers cannot be added to other containers (yet)"); |
820 |
} |
889 |
} |
821 |
|
890 |
|
822 |
public List getNodes() { |
891 |
public List getNodes() { |
823 |
return this.childNodes; |
892 |
return this.childNodes; |
824 |
} |
893 |
} |
825 |
|
|
|
826 |
void paint() { |
827 |
Iterator iterator = getNodes().iterator(); |
828 |
|
829 |
while (iterator.hasNext()) { |
830 |
GraphNode node = (GraphNode) iterator.next(); |
831 |
node.paint(); |
832 |
} |
833 |
} |
834 |
|
835 |
} |
894 |
} |