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.Rectangle;
|
15
|
|
16
|
/**
|
17
|
* Draws a Rectangle whose corners are rounded in appearance. The size of the
|
18
|
* rectangle is determined by the bounds set to it.
|
19
|
*/
|
20
|
public class RoundedRectangle extends Shape {
|
21
|
|
22
|
/**
|
23
|
* The width and height radii applied to each corner.
|
24
|
*
|
25
|
* @deprecated Use {@link #getCornerDimensions()} instead.
|
26
|
*/
|
27
|
protected Dimension corner = new Dimension(8, 8);
|
28
|
|
29
|
/**
|
30
|
* Constructs a round cornered rectangle.
|
31
|
*/
|
32
|
public RoundedRectangle() {
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* @see Shape#fillShape(Graphics)
|
37
|
*/
|
38
|
protected void fillShape(Graphics graphics) {
|
39
|
graphics.fillRoundRectangle(getBounds(), corner.width, corner.height);
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* @see Shape#outlineShape(Graphics)
|
44
|
*/
|
45
|
protected void outlineShape(Graphics graphics) {
|
46
|
float lineInset = Math.max(1.0f, getLineWidthFloat()) / 2.0f;
|
47
|
int inset1 = (int) Math.floor(lineInset);
|
48
|
int inset2 = (int) Math.ceil(lineInset);
|
49
|
|
50
|
Rectangle r = Rectangle.SINGLETON.setBounds(getBounds());
|
51
|
r.x += inset1;
|
52
|
r.y += inset1;
|
53
|
r.width -= inset1 + inset2;
|
54
|
r.height -= inset1 + inset2;
|
55
|
|
56
|
graphics.drawRoundRectangle(r,
|
57
|
Math.max(0, corner.width - (int) lineInset),
|
58
|
Math.max(0, corner.height - (int) lineInset));
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* Sets the dimensions of each corner. This will form the radii of the arcs
|
63
|
* which form the corners.
|
64
|
*
|
65
|
* @param d
|
66
|
* the dimensions of the corner
|
67
|
* @since 2.0
|
68
|
*/
|
69
|
public void setCornerDimensions(Dimension d) {
|
70
|
corner.width = d.width;
|
71
|
corner.height = d.height;
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Returns the dimensions used for each corner.
|
76
|
*
|
77
|
* @return the dimensions of the corner.
|
78
|
* @since 3.7
|
79
|
*/
|
80
|
public Dimension getCornerDimensions() {
|
81
|
return corner.getCopy();
|
82
|
}
|
83
|
}
|