Search in sources :

Example 36 with Bounds

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;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Cursor(org.apache.pivot.wtk.Cursor) Sheet(org.apache.pivot.wtk.Sheet) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 37 with Bounds

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);
    }
}
Also used : Window(org.apache.pivot.wtk.Window) Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Sheet(org.apache.pivot.wtk.Sheet) Point(org.apache.pivot.wtk.Point)

Example 38 with Bounds

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);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) Point(org.apache.pivot.wtk.Point) Line2D(java.awt.geom.Line2D) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) ListButton(org.apache.pivot.wtk.ListButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton)

Example 39 with Bounds

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));
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 40 with Bounds

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;
}
Also used : ListView(org.apache.pivot.wtk.ListView) Bounds(org.apache.pivot.wtk.Bounds)

Aggregations

Bounds (org.apache.pivot.wtk.Bounds)77 Point (org.apache.pivot.wtk.Point)21 GradientPaint (java.awt.GradientPaint)15 Color (java.awt.Color)10 Graphics2D (java.awt.Graphics2D)9 Rectangle (java.awt.Rectangle)7 TableView (org.apache.pivot.wtk.TableView)7 BasicStroke (java.awt.BasicStroke)6 GeneralPath (java.awt.geom.GeneralPath)5 Button (org.apache.pivot.wtk.Button)5 Component (org.apache.pivot.wtk.Component)5 Span (org.apache.pivot.wtk.Span)5 TextArea (org.apache.pivot.wtk.TextArea)5 TextPane (org.apache.pivot.wtk.TextPane)5 FontRenderContext (java.awt.font.FontRenderContext)4 LineMetrics (java.awt.font.LineMetrics)4 Area (java.awt.geom.Area)4 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 ArrayList (org.apache.pivot.collections.ArrayList)4 ScrollPane (org.apache.pivot.wtk.ScrollPane)4