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