Mercurial > projects > dwt-addons
comparison dwtx/draw2d/CompoundBorder.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.CompoundBorder; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.draw2d.geometry.Dimension; | |
18 import dwtx.draw2d.geometry.Insets; | |
19 | |
20 import dwtx.draw2d.AbstractBorder; | |
21 import dwtx.draw2d.Border; | |
22 import dwtx.draw2d.IFigure; | |
23 import dwtx.draw2d.Graphics; | |
24 | |
25 /** | |
26 * CompoundBorder allows for the nesting of two borders. The nested borders are referred | |
27 * to as the <i>inner</i> and <i>outer</i> borders. | |
28 */ | |
29 public class CompoundBorder | |
30 : AbstractBorder | |
31 { | |
32 | |
33 /** The inner Border. */ | |
34 protected Border inner; | |
35 /** The outer Border. */ | |
36 protected Border outer; | |
37 | |
38 /** | |
39 * Constructs a default CompoundBorder with no borders under it. | |
40 * | |
41 * @since 2.0 | |
42 */ | |
43 public this() { } | |
44 | |
45 /** | |
46 * Constructs a CompoundBorder with the two borders specified as input. | |
47 * | |
48 * @param outer Border which is drawn on the outside | |
49 * @param inner Border which is drawn inside the outer border | |
50 * | |
51 * @since 2.0 | |
52 */ | |
53 public this(Border outer, Border inner) { | |
54 this.outer = outer; | |
55 this.inner = inner; | |
56 } | |
57 | |
58 /** | |
59 * Returns the inner border of this CompoundBorder. | |
60 * | |
61 * @return The inner border | |
62 * @since 2.0 | |
63 */ | |
64 public Border getInnerBorder() { | |
65 return inner; | |
66 } | |
67 | |
68 /** | |
69 * Returns the total insets required to hold both the inner and outer borders of this | |
70 * CompoundBorder. | |
71 * | |
72 * @param figure Figure for which this is the border | |
73 * @return The total insets for this border | |
74 * @since 2.0 | |
75 */ | |
76 public Insets getInsets(IFigure figure) { | |
77 Insets insets = null; | |
78 if (inner !is null) | |
79 insets = inner.getInsets(figure); | |
80 else | |
81 insets = new Insets(); | |
82 if (outer !is null) { | |
83 Insets moreInsets = outer.getInsets(figure); | |
84 insets = insets.getAdded(moreInsets); | |
85 } | |
86 return insets; | |
87 } | |
88 | |
89 /** | |
90 * @see dwtx.draw2d.Border#getPreferredSize(IFigure) | |
91 */ | |
92 public Dimension getPreferredSize(IFigure fig) { | |
93 Dimension prefSize = new Dimension(inner.getPreferredSize(fig)); | |
94 Insets outerInsets = outer.getInsets(fig); | |
95 prefSize.expand(outerInsets.getWidth(), outerInsets.getHeight()); | |
96 prefSize.union_(outer.getPreferredSize(fig)); | |
97 return prefSize; | |
98 } | |
99 | |
100 /** | |
101 * Returns the outer border of this CompoundBorder. | |
102 * | |
103 * @return The outer border | |
104 * @since 2.0 | |
105 */ | |
106 public Border getOuterBorder() { | |
107 return outer; | |
108 } | |
109 | |
110 /** | |
111 * Returns <code>true</code> if this border is opaque. Return value is dependent on the | |
112 * opaque state of both the borders it contains. Both borders have to be opaque for this | |
113 * border to be opaque. In the absence of any of the borders, this border is not opaque. | |
114 * | |
115 * @return <code>true</code> if this border is opaque | |
116 */ | |
117 public bool isOpaque() { | |
118 return ((inner !is null) ? inner.isOpaque() : false) | |
119 && ((outer !is null) ? outer.isOpaque() : false); | |
120 } | |
121 | |
122 /** | |
123 * @see dwtx.draw2d.Border#paint(IFigure, Graphics, Insets) | |
124 */ | |
125 public void paint(IFigure figure, Graphics g, Insets insets) { | |
126 if (outer !is null) { | |
127 g.pushState(); | |
128 outer.paint(figure, g, insets); | |
129 g.popState(); | |
130 | |
131 insets = insets.getAdded(outer.getInsets(figure)); | |
132 } | |
133 if (inner !is null) | |
134 inner.paint(figure, g, insets); | |
135 } | |
136 | |
137 } |