use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraSheetSkin method mouseMove.
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
if (Mouse.getCapturer() == component) {
Sheet sheet = (Sheet) getComponent();
Display display = sheet.getDisplay();
Point location = sheet.mapPointToAncestor(display, x, y);
// Pretend that the mouse can't move off screen (off the display)
location = new Point(Math.min(Math.max(location.x, 0), display.getWidth() - 1), Math.min(Math.max(location.y, 0), display.getHeight() - 1));
if (resizeOffset != null) {
// Resize the frame
int preferredWidth = -1;
int preferredHeight = -1;
boolean preferredWidthSet = component.isPreferredWidthSet();
boolean preferredHeightSet = component.isPreferredHeightSet();
boolean noPreferredSet = !(preferredWidthSet || preferredHeightSet);
if (preferredWidthSet || noPreferredSet) {
preferredWidth = Math.max(location.x - sheet.getX() + resizeOffset.x, 2);
preferredWidth = Math.min(preferredWidth, sheet.getMaximumWidth());
preferredWidth = Math.max(preferredWidth, sheet.getMinimumWidth());
}
if (preferredHeightSet || noPreferredSet) {
preferredHeight = Math.max(location.y - sheet.getY() + resizeOffset.y, resizeHandle.getHeight() + 7);
preferredHeight = Math.min(preferredHeight, sheet.getMaximumHeight());
preferredHeight = Math.max(preferredHeight, sheet.getMinimumHeight());
}
sheet.setPreferredSize(preferredWidth, preferredHeight);
}
} else {
Cursor cursor = null;
Bounds resizeHandleBounds = resizeHandle.getBounds();
if (resizable && resizeHandleBounds.contains(x, y)) {
boolean preferredWidthSet = component.isPreferredWidthSet();
boolean preferredHeightSet = component.isPreferredHeightSet();
if (preferredWidthSet && preferredHeightSet) {
cursor = Cursor.RESIZE_SOUTH_EAST;
} else if (preferredWidthSet) {
cursor = Cursor.RESIZE_EAST;
} else if (preferredHeightSet) {
cursor = Cursor.RESIZE_SOUTH;
} else {
cursor = Cursor.RESIZE_SOUTH_EAST;
}
}
component.setCursor(cursor);
}
return consumed;
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraSheetSkin method alignToOwner.
public void alignToOwner() {
Sheet sheet = (Sheet) getComponent();
Window owner = sheet.getOwner();
if (owner != null) {
Bounds clientArea = owner.getClientArea();
Point location = owner.mapPointToAncestor(owner.getDisplay(), clientArea.x, clientArea.y);
int x = location.x;
int y = location.y;
switch(slideSource) {
case NORTH:
x = location.x + (clientArea.width - getWidth()) / 2;
y = location.y;
break;
case SOUTH:
x = location.x + (clientArea.width - getWidth()) / 2;
y = location.y + (clientArea.height - getHeight());
break;
case WEST:
x = location.x;
y = location.y + (clientArea.height - getHeight()) / 2;
break;
case EAST:
x = location.x + (clientArea.width - getWidth());
y = location.y + (clientArea.height - getHeight()) / 2;
break;
default:
throw new IllegalStateException("slideSource is null or an unexpected value");
}
sheet.setLocation(x, y);
}
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraListButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
ListButton listButton = (ListButton) getComponent();
int width = getWidth();
int height = getHeight();
Color colorLocal = null;
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (listButton.isEnabled()) {
colorLocal = this.color;
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = (pressed || (listViewPopup.isOpen() && !listViewPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
borderColorLocal = this.borderColor;
} else {
colorLocal = disabledColor;
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
graphics.setStroke(new BasicStroke());
// Paint the background
GraphicsUtilities.setAntialiasingOn(graphics);
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
} else {
graphics.setPaint(backgroundColorLocal);
}
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
// Paint the content
GraphicsUtilities.setAntialiasingOff(graphics);
Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
Button.DataRenderer dataRenderer = listButton.getDataRenderer();
dataRenderer.render(listButton.getButtonData(), listButton, false);
dataRenderer.setSize(Math.max(contentBounds.width - (padding.getWidth() + 2) + 1, 0), Math.max(contentBounds.height - (padding.getHeight() + 2) + 1, 0));
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(padding.left + 1, padding.top + 1);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
GraphicsUtilities.setAntialiasingOn(graphics);
// Paint the border
if (!themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.setStroke(new BasicStroke(1));
graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
graphics.draw(new Line2D.Double(contentBounds.x + contentBounds.width, 0.5, contentBounds.x + contentBounds.width, contentBounds.height));
}
// Paint the focus state
if (listButton.isFocused()) {
BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
graphics.setStroke(dashStroke);
graphics.setColor(borderColorLocal);
graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(contentBounds.width - 4, 0), Math.max(contentBounds.height - 4, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
}
GraphicsUtilities.setAntialiasingOff(graphics);
// Paint the trigger
GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
triggerIconShape.moveTo(0, 0);
triggerIconShape.lineTo(3, 3);
triggerIconShape.lineTo(6, 0);
triggerIconShape.closePath();
Graphics2D triggerGraphics = (Graphics2D) graphics.create();
triggerGraphics.setStroke(new BasicStroke(0));
triggerGraphics.setPaint(colorLocal);
Bounds triggerBounds = getTriggerBounds();
int tx = triggerBounds.x + Math.round((triggerBounds.width - triggerIconShape.getBounds().width) / 2f) - 1;
int ty = triggerBounds.y + Math.round((triggerBounds.height - triggerIconShape.getBounds().height) / 2f) - 1;
triggerGraphics.translate(tx, ty);
triggerGraphics.draw(triggerIconShape);
triggerGraphics.fill(triggerIconShape);
triggerGraphics.dispose();
// Paint the trigger highlight
if (listButton.isRepeatable()) {
Point mouseLocation = listButton.getMouseLocation();
if (mouseLocation != null) {
graphics.setPaint(new Color(0, 0, 0, 0.25f));
if (triggerBounds.contains(mouseLocation)) {
graphics.clipRect(triggerBounds.x, triggerBounds.y, triggerBounds.width, height);
} else {
graphics.clipRect(0, 0, width - triggerBounds.width, height);
}
GraphicsUtilities.setAntialiasingOn(graphics);
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
GraphicsUtilities.setAntialiasingOff(graphics);
}
}
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraListButtonSkin method getTriggerBounds.
@Override
public Bounds getTriggerBounds() {
int width = getWidth();
int height = getHeight();
return new Bounds(Math.max(width - (TRIGGER_WIDTH + 1), 0), 0, TRIGGER_WIDTH + 1, Math.max(height, 0));
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraListViewSkin method mouseOut.
@Override
public void mouseOut(Component component) {
super.mouseOut(component);
ListView listView = (ListView) getComponent();
if (highlightIndex != -1 && listView.getSelectMode() != ListView.SelectMode.NONE && showHighlight) {
Bounds itemBounds = getItemBounds(highlightIndex);
repaintComponent(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
}
highlightIndex = -1;
selectIndex = -1;
}
Aggregations