Mercurial > projects > dwt-addons
comparison dwtx/draw2d/LabeledContainer.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.LabeledContainer; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwt.graphics.Font; | |
18 import dwtx.draw2d.Figure; | |
19 import dwtx.draw2d.Border; | |
20 import dwtx.draw2d.LabeledBorder; | |
21 import dwtx.draw2d.GroupBoxBorder; | |
22 import dwtx.draw2d.CompoundBorder; | |
23 | |
24 /** | |
25 * A Container with a title bar describing the contents of the container. The frame is | |
26 * generated by a {@link LabeledBorder}. | |
27 */ | |
28 public class LabeledContainer | |
29 : Figure | |
30 { | |
31 | |
32 /** | |
33 * Constructs a default container with a {@link GroupBoxBorder}. | |
34 * | |
35 * @since 2.0 | |
36 */ | |
37 public this() { | |
38 this(new GroupBoxBorder()); | |
39 } | |
40 | |
41 /** | |
42 * Constructs a labeled container with the border given as input. | |
43 * | |
44 * @param border the border | |
45 * @since 2.0 | |
46 */ | |
47 public this(Border border) { | |
48 setBorder(border); | |
49 setOpaque(true); | |
50 } | |
51 | |
52 private static LabeledBorder findLabeledBorder(Border border) { | |
53 if ( auto b = cast(LabeledBorder)border ) | |
54 return b; | |
55 if ( auto cb = cast(CompoundBorder)border ) { | |
56 LabeledBorder labeled = findLabeledBorder(cb.getInnerBorder()); | |
57 if (labeled is null) | |
58 labeled = findLabeledBorder(cb.getOuterBorder()); | |
59 return labeled; | |
60 } | |
61 return null; | |
62 } | |
63 | |
64 /** | |
65 * Returns the text of the LabeledContainer's label. | |
66 * | |
67 * @return the label text | |
68 * @since 2.0 | |
69 */ | |
70 public String getLabel() { | |
71 return getLabeledBorder().getLabel(); | |
72 } | |
73 | |
74 /** | |
75 * Returns the LabeledBorder of this container. | |
76 * | |
77 * @return the border | |
78 * @since 2.0 | |
79 */ | |
80 protected LabeledBorder getLabeledBorder() { | |
81 return findLabeledBorder(getBorder()); | |
82 } | |
83 | |
84 /** | |
85 * Sets the title of the container. | |
86 * | |
87 * @param s the new title text | |
88 * @since 2.0 | |
89 */ | |
90 public void setLabel(String s) { | |
91 getLabeledBorder().setLabel(s); | |
92 revalidate(); | |
93 repaint(); | |
94 } | |
95 | |
96 /** | |
97 * Sets the font to be used for the container title. | |
98 * | |
99 * @param f the new font | |
100 * @since 2.0 | |
101 */ | |
102 public void setLabelFont(Font f) { | |
103 getLabeledBorder().setFont(f); | |
104 revalidate(); | |
105 repaint(); | |
106 } | |
107 | |
108 } |