Mercurial > projects > dwt-addons
comparison dwtx/draw2d/GroupBoxBorder.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.GroupBoxBorder; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.draw2d.geometry.Dimension; | |
18 import dwtx.draw2d.geometry.Insets; | |
19 import dwtx.draw2d.geometry.Rectangle; | |
20 import dwtx.draw2d.AbstractLabeledBorder; | |
21 import dwtx.draw2d.IFigure; | |
22 import dwtx.draw2d.Graphics; | |
23 import dwtx.draw2d.FigureUtilities; | |
24 | |
25 /** | |
26 * A labeled border intended to house a Figure with a group of children. The label should | |
27 * serve as a description of the group. | |
28 */ | |
29 public class GroupBoxBorder | |
30 : AbstractLabeledBorder | |
31 { | |
32 | |
33 /** | |
34 * Constructs a GroupBoxBorder with the name of this class as its label. | |
35 * | |
36 * @since 2.0 | |
37 */ | |
38 public this() { } | |
39 | |
40 /** | |
41 * Constructs a GroupBoxBorder with label s. | |
42 * | |
43 * @param s the label | |
44 * @since 2.0 | |
45 */ | |
46 public this(String s) { | |
47 super(s); | |
48 } | |
49 | |
50 /** | |
51 * Calculates and returns the Insets for this GroupBoxBorder. | |
52 * | |
53 * @param figure IFigure on which the calculations should be made. Generally this is | |
54 * the IFigure of which this GroupBoxBorder is surrounding. | |
55 * @return the Insets for this GroupBoxBorder. | |
56 * @since 2.0 | |
57 */ | |
58 protected Insets calculateInsets(IFigure figure) { | |
59 int height = getTextExtents(figure).height; | |
60 return new Insets(height); | |
61 } | |
62 | |
63 /** | |
64 * @see dwtx.draw2d.Border#getPreferredSize(IFigure) | |
65 */ | |
66 public Dimension getPreferredSize(IFigure fig) { | |
67 Dimension textSize = getTextExtents(fig); | |
68 return textSize.getCopy().expand(textSize.height * 2, 0); | |
69 } | |
70 | |
71 /** | |
72 * @see Border#paint(IFigure, Graphics, Insets) | |
73 */ | |
74 public void paint(IFigure figure, Graphics g, Insets insets) { | |
75 tempRect.setBounds(getPaintRectangle(figure, insets)); | |
76 Rectangle r = tempRect; | |
77 if (r.isEmpty()) | |
78 return; | |
79 | |
80 Rectangle textLoc = new Rectangle(r.getTopLeft(), getTextExtents(figure)); | |
81 r.crop(new Insets(getTextExtents(figure).height / 2)); | |
82 FigureUtilities.paintEtchedBorder(g, r); | |
83 | |
84 textLoc.x += getInsets(figure).left; | |
85 g.setFont(getFont(figure)); | |
86 g.setForegroundColor(getTextColor()); | |
87 g.clipRect(textLoc); | |
88 g.fillText(getLabel(), textLoc.getTopLeft()); | |
89 } | |
90 | |
91 } |