annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module dwtx.draw2d.LabeledContainer;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 import dwt.dwthelper.utils;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 import dwt.graphics.Font;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import dwtx.draw2d.Figure;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 import dwtx.draw2d.Border;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import dwtx.draw2d.LabeledBorder;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import dwtx.draw2d.GroupBoxBorder;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import dwtx.draw2d.CompoundBorder;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 * A Container with a title bar describing the contents of the container. The frame is
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 * generated by a {@link LabeledBorder}.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 public class LabeledContainer
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 : Figure
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 * Constructs a default container with a {@link GroupBoxBorder}.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 * @since 2.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 public this() {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 this(new GroupBoxBorder());
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 * Constructs a labeled container with the border given as input.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 * @param border the border
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 * @since 2.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 public this(Border border) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 setBorder(border);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 setOpaque(true);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 private static LabeledBorder findLabeledBorder(Border border) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 if ( auto b = cast(LabeledBorder)border )
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 return b;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 if ( auto cb = cast(CompoundBorder)border ) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 LabeledBorder labeled = findLabeledBorder(cb.getInnerBorder());
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 if (labeled is null)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 labeled = findLabeledBorder(cb.getOuterBorder());
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 return labeled;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 return null;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 * Returns the text of the LabeledContainer's label.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 * @return the label text
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 * @since 2.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 public String getLabel() {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 return getLabeledBorder().getLabel();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 * Returns the LabeledBorder of this container.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 * @return the border
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 * @since 2.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 protected LabeledBorder getLabeledBorder() {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 return findLabeledBorder(getBorder());
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 * Sets the title of the container.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 * @param s the new title text
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 * @since 2.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 public void setLabel(String s) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 getLabeledBorder().setLabel(s);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 revalidate();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 repaint();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 * Sets the font to be used for the container title.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 * @param f the new font
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100 * @since 2.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 public void setLabelFont(Font f) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 getLabeledBorder().setFont(f);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 revalidate();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 repaint();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 }