Mercurial > projects > dwt-addons
comparison dwtx/draw2d/ConnectionLayer.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.draw2d.ConnectionLayer; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwt.DWT; | |
18 import dwtx.draw2d.FreeformLayer; | |
19 import dwtx.draw2d.IFigure; | |
20 import dwtx.draw2d.Graphics; | |
21 import dwtx.draw2d.ConnectionRouter; | |
22 import dwtx.draw2d.Connection; | |
23 | |
24 /** | |
25 * Layer designed specifically to handle the presence of connections. This is done due to | |
26 * the necessity of having a router for the connections added. | |
27 */ | |
28 public class ConnectionLayer | |
29 : FreeformLayer | |
30 { | |
31 | |
32 int antialias = DWT.DEFAULT; | |
33 | |
34 /** | |
35 * The ConnectionRouter used to route all connections on this layer. | |
36 */ | |
37 protected ConnectionRouter connectionRouter; | |
38 | |
39 /** | |
40 * Adds the given figure with the given contraint at the given index. If the figure is a | |
41 * {@link Connection}, its {@link ConnectionRouter} is set. | |
42 * | |
43 * @param figure Figure being added | |
44 * @param constraint Constraint of the figure being added | |
45 * @param index Index where the figure is to be added | |
46 * @since 2.0 | |
47 */ | |
48 public void add(IFigure figure, Object constraint, int index) { | |
49 super.add(figure, constraint, index); | |
50 | |
51 // If the connection layout manager is set, then every | |
52 // figure added should use this layout manager. | |
53 if (null !is cast(Connection )figure && getConnectionRouter() !is null) | |
54 (cast(Connection)figure).setConnectionRouter(getConnectionRouter()); | |
55 } | |
56 | |
57 /** | |
58 * Returns the ConnectionRouter being used by this layer. | |
59 * | |
60 * @return ConnectionRouter being used by this layer | |
61 * @since 2.0 | |
62 */ | |
63 public ConnectionRouter getConnectionRouter() { | |
64 return connectionRouter; | |
65 } | |
66 | |
67 /** | |
68 * @see IFigure#paint(Graphics) | |
69 */ | |
70 public void paint(Graphics graphics) { | |
71 if (antialias !is DWT.DEFAULT) | |
72 graphics.setAntialias(antialias); | |
73 super.paint(graphics); | |
74 } | |
75 | |
76 /** | |
77 * Removes the figure from this Layer. If the figure is a {@link Connection}, that | |
78 * Connection's {@link ConnectionRouter} is set to <code>null</code>. | |
79 * | |
80 * @param figure The figure to remove | |
81 */ | |
82 public void remove(IFigure figure) { | |
83 if ( auto f = cast(Connection)figure ) | |
84 f.setConnectionRouter(null); | |
85 super.remove(figure); | |
86 } | |
87 | |
88 /** | |
89 * Sets the ConnectionRouter for this layer. This router is set as the ConnectionRouter | |
90 * for all the child connections of this Layer. | |
91 * | |
92 * @param router The ConnectionRouter to set for this Layer | |
93 * @since 2.0 | |
94 */ | |
95 public void setConnectionRouter(ConnectionRouter router) { | |
96 connectionRouter = router; | |
97 FigureIterator iter = new FigureIterator(this); | |
98 IFigure figure; | |
99 while (iter.hasNext()) { | |
100 figure = iter.nextFigure(); | |
101 if ( auto f = cast(Connection)figure ) | |
102 f.setConnectionRouter(router); | |
103 } | |
104 } | |
105 | |
106 /** | |
107 * Sets whether antialiasing should be enabled for the connection layer. If this value is | |
108 * set to something other than {@link DWT#DEFAULT}, {@link Graphics#setAntialias(int)} | |
109 * will be called with the given value when painting this layer. | |
110 * @param antialias the antialias setting | |
111 * @since 3.1 | |
112 */ | |
113 public void setAntialias(int antialias) { | |
114 this.antialias = antialias; | |
115 } | |
116 | |
117 } |