use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class BoundsTest method test.
@Test
public void test() {
Bounds bndMinus1 = new Bounds(-1, -1, 0, 0);
Bounds bnd0 = new Bounds(0, 0, 0, 0);
Bounds bnd1 = new Bounds(1, 1, 1, 1);
Dimensions dim0 = new Dimensions(0, 0);
Dimensions dim1 = new Dimensions(1, 1);
Point p10 = new Point(10, 10);
Bounds bnd10 = new Bounds(p10, dim1);
Bounds bnd10a = new Bounds(dim1);
Bounds bnd10b = new Bounds(0, 0, 1, 1);
Bounds bnd2 = Bounds.decode("[2, 3, 4, 5]");
Bounds bnd3 = Bounds.decode("{x:2, y:3, width:4, height:5}");
Bounds bnd3a = new Bounds(2, 3, 4, 5);
Bounds bnd4 = new Bounds(4, 4, 4, 5);
// -> {3, 4, 4, 5}
Bounds bnd5 = bnd3a.translate(1, 1);
bnd5 = bnd5.expand(-2, -4);
Bounds bnd5a = new Bounds(3, 4, 2, 1);
Bounds bnd5b = new Bounds(4, 3, 1, 2);
Bounds bndN = new Bounds(0, 0, 8, 9);
Bounds bndAll = bnd1.union(bnd0).union(bnd2).union(bnd3).union(bnd4);
Bounds bnd6 = Bounds.decode("2, 3; 4, 5");
Bounds bnd6a = new Bounds(2, 3, 4, 5);
assertEquals(Bounds.EMPTY, bnd0);
assertNotEquals(bndMinus1, bnd0);
assertNotEquals(bnd0, bnd1);
assertEquals(bnd10a, bnd10b);
assertEquals(bnd10.getLocation(), p10);
assertEquals(bnd10.getSize(), dim1);
assertEquals(bnd2, bnd3);
assertEquals(bnd3, bnd3a);
assertEquals(bndMinus1.getSize(), dim0);
assertEquals(bnd0.getSize(), dim0);
assertEquals(bnd1.getSize(), dim1);
assertFalse(bnd1.contains(bnd0));
assertFalse(bndMinus1.intersects(bnd0));
assertFalse(bnd0.intersects(bnd1));
assertEquals(bnd0.intersect(bnd1), new Bounds(1, 1, -1, -1));
assertTrue(bnd5a.intersects(bnd5b));
assertTrue(bnd0.union(bnd1).equals(new Bounds(0, 0, 2, 2)));
assertFalse(bnd0.equals(bnd1));
assertTrue(bnd5.equals(bnd5a));
assertEquals(bndN, bndAll);
assertEquals(bnd6, bnd6a);
assertEquals(bnd6a.toString(), "Bounds [2,3;4x5]");
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraFormSkin method paint.
@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
GraphicsUtilities.setAntialiasingOn(graphics);
Form form = (Form) getComponent();
Form.SectionSequence sections = form.getSections();
for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
Form.Section section = sections.get(sectionIndex);
for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
Component field = section.get(fieldIndex);
if (field.isVisible()) {
Form.Flag flag = Form.getFlag(field);
if (flag != null) {
if (showFlagIcons) {
MessageType messageType = flag.getMessageType();
Image flagIcon = null;
switch(messageType) {
case ERROR:
{
flagIcon = errorIcon;
break;
}
case WARNING:
{
flagIcon = warningIcon;
break;
}
case QUESTION:
{
flagIcon = questionIcon;
break;
}
case INFO:
{
flagIcon = infoIcon;
break;
}
default:
{
flagIcon = infoIcon;
break;
}
}
Label label = labels.get(sectionIndex).get(fieldIndex);
int flagIconX = label.getX() - (flagIcon.getWidth() + flagIconOffset);
int flagIconY = label.getY() + (label.getHeight() - flagIcon.getHeight()) / 2;
graphics.translate(flagIconX, flagIconY);
flagIcon.paint(graphics);
graphics.translate(-flagIconX, -flagIconY);
}
if (showFlagHighlight) {
MessageType messageType = flag.getMessageType();
Color highlightColor = null;
switch(messageType) {
case ERROR:
{
highlightColor = errorHighlightColor;
break;
}
case WARNING:
{
highlightColor = warningHighlightColor;
break;
}
case QUESTION:
{
highlightColor = questionHighlightColor;
break;
}
case INFO:
{
highlightColor = infoHighlightColor;
break;
}
default:
{
break;
}
}
Bounds fieldBounds = field.getBounds();
graphics.setColor(highlightColor);
graphics.setStroke(new BasicStroke(1));
graphics.drawRect(fieldBounds.x - FLAG_HIGHLIGHT_PADDING, fieldBounds.y - FLAG_HIGHLIGHT_PADDING, fieldBounds.width + FLAG_HIGHLIGHT_PADDING * 2 - 1, fieldBounds.height + FLAG_HIGHLIGHT_PADDING * 2 - 1);
}
}
}
}
}
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraFrameSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
Frame frame = (Frame) getComponent();
boolean maximized = frame.isMaximized();
if (button == Mouse.Button.LEFT && !maximized) {
Bounds titleBarBounds = titleBarTablePane.getBounds();
if (titleBarBounds.contains(x, y)) {
dragOffset = new Point(x, y);
Mouse.capture(component);
} else {
if (resizable && x > resizeHandle.getX() && y > resizeHandle.getY()) {
resizeOffset = new Point(getWidth() - x, getHeight() - y);
Mouse.capture(component);
}
}
}
return consumed;
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraFrameSkin method getClientArea.
@Override
public Bounds getClientArea() {
int width = getWidth();
int height = getHeight();
int titleBarHeight = titleBarTablePane.getHeight();
Frame frame = (Frame) getComponent();
boolean maximized = frame.isMaximized();
Bounds clientArea;
if (maximized && !getShowWindowControls()) {
clientArea = new Bounds(0, 0, width, height);
} else {
clientArea = new Bounds(0, titleBarHeight + 2, width, height - (titleBarHeight + 2));
}
return clientArea;
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraFrameSkin method paint.
@Override
public void paint(Graphics2D graphics) {
// Call the base class to paint the background
super.paint(graphics);
Frame frame = (Frame) getComponent();
int width = getWidth();
int height = getHeight();
boolean maximized = frame.isMaximized();
if (!maximized || getShowWindowControls()) {
int titleBarHeight = titleBarTablePane.getHeight();
// Draw the title area
Color titleBarBackgroundColorLocal = frame.isActive() ? this.titleBarBackgroundColor : inactiveTitleBarBackgroundColor;
Color titleBarBorderColorLocal = frame.isActive() ? this.titleBarBorderColor : inactiveTitleBarBorderColor;
Color titleBarBevelColorLocal = frame.isActive() ? this.titleBarBevelColor : inactiveTitleBarBevelColor;
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, titleBarBevelColorLocal, width / 2f, titleBarHeight + 1, titleBarBackgroundColorLocal));
graphics.fillRect(0, 0, width, titleBarHeight + 1);
// Draw the border
graphics.setPaint(titleBarBorderColorLocal);
GraphicsUtilities.drawRect(graphics, 0, 0, width, titleBarHeight + 2);
// Draw the content area
Bounds contentAreaRectangle = new Bounds(0, titleBarHeight + 2, width, height - (titleBarHeight + 2));
graphics.setPaint(contentBorderColor);
GraphicsUtilities.drawRect(graphics, contentAreaRectangle.x, contentAreaRectangle.y, contentAreaRectangle.width, contentAreaRectangle.height);
if (showContentBevel) {
graphics.setPaint(contentBevelColor);
GraphicsUtilities.drawLine(graphics, contentAreaRectangle.x + 1, contentAreaRectangle.y + 1, contentAreaRectangle.width - 2, Orientation.HORIZONTAL);
}
} else {
graphics.setPaint(titleBarBackgroundColorLocal);
graphics.fillRect(0, 0, width, titleBarHeight + 1);
}
}
}
Aggregations