Project

General

Profile

Download (3.51 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Research Group Software Construction,
11
 *     RWTH Aachen University, Germany - Contribution for Bugzilla 195527
12
 *******************************************************************************/
13
package org.eclipse.draw2d;
14

    
15
import org.eclipse.draw2d.rap.swt.SWT;
16

    
17
/**
18
 * Layer designed specifically to handle the presence of connections. This is
19
 * done due to the necessity of having a router for the connections added.
20
 */
21
public class ConnectionLayer extends FreeformLayer {
22

    
23
	int antialias = SWT.DEFAULT;
24

    
25
	/**
26
	 * The ConnectionRouter used to route all connections on this layer.
27
	 */
28
	protected ConnectionRouter connectionRouter;
29

    
30
	/**
31
	 * Adds the given figure with the given contraint at the given index. If the
32
	 * figure is a {@link Connection}, its {@link ConnectionRouter} is set.
33
	 * 
34
	 * @param figure
35
	 *            Figure being added
36
	 * @param constraint
37
	 *            Constraint of the figure being added
38
	 * @param index
39
	 *            Index where the figure is to be added
40
	 * @since 2.0
41
	 */
42
	public void add(IFigure figure, Object constraint, int index) {
43
		super.add(figure, constraint, index);
44

    
45
		// If the connection layout manager is set, then every
46
		// figure added should use this layout manager.
47
		if (figure instanceof Connection && getConnectionRouter() != null)
48
			((Connection) figure).setConnectionRouter(getConnectionRouter());
49
	}
50

    
51
	/**
52
	 * Returns the ConnectionRouter being used by this layer.
53
	 * 
54
	 * @return ConnectionRouter being used by this layer
55
	 * @since 2.0
56
	 */
57
	public ConnectionRouter getConnectionRouter() {
58
		return connectionRouter;
59
	}
60

    
61
	/**
62
	 * @see IFigure#paint(Graphics)
63
	 */
64
	public void paint(Graphics graphics) {
65
		if (antialias != SWT.DEFAULT)
66
			graphics.setAntialias(antialias);
67
		super.paint(graphics);
68
	}
69

    
70
	/**
71
	 * Removes the figure from this Layer. If the figure is a {@link Connection}
72
	 * , that Connection's {@link ConnectionRouter} is set to <code>null</code>.
73
	 * 
74
	 * @param figure
75
	 *            The figure to remove
76
	 */
77
	public void remove(IFigure figure) {
78
		if (figure instanceof Connection)
79
			((Connection) figure).setConnectionRouter(null);
80
		super.remove(figure);
81
	}
82

    
83
	/**
84
	 * Sets the ConnectionRouter for this layer. This router is set as the
85
	 * ConnectionRouter for all the child connections of this Layer.
86
	 * 
87
	 * @param router
88
	 *            The ConnectionRouter to set for this Layer
89
	 * @since 2.0
90
	 */
91
	public void setConnectionRouter(ConnectionRouter router) {
92
		connectionRouter = router;
93
		FigureIterator iter = new FigureIterator(this);
94
		IFigure figure;
95
		while (iter.hasNext()) {
96
			figure = iter.nextFigure();
97
			if (figure instanceof Connection)
98
				((Connection) figure).setConnectionRouter(router);
99
		}
100
	}
101

    
102
	/**
103
	 * Sets whether antialiasing should be enabled for the connection layer. If
104
	 * this value is set to something other than {@link SWT#DEFAULT},
105
	 * {@link Graphics#setAntialias(int)} will be called with the given value
106
	 * when painting this layer.
107
	 * 
108
	 * @param antialias
109
	 *            the antialias setting
110
	 * @since 3.1
111
	 */
112
	public void setAntialias(int antialias) {
113
		this.antialias = antialias;
114
	}
115

    
116
}
(46-46/171)