Search in sources :

Example 71 with Bounds

use of org.apache.pivot.wtk.Bounds in project pivot by apache.

the class TerraListViewSkin method layout.

@Override
public void layout() {
    ListView listView = (ListView) getComponent();
    @SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
    ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
    if (variableItemHeight) {
        int width = getWidth();
        int checkboxHeight = 0;
        if (listView.getCheckmarksEnabled()) {
            checkboxHeight = CHECKBOX.getHeight() + checkboxPadding.getHeight();
        }
        int n = listData.getLength();
        itemBoundaries = new ArrayList<>(n);
        int itemY = 0;
        for (int i = 0; i < n; i++) {
            Object item = listData.get(i);
            int itemWidth = width;
            int itemX = 0;
            Button.State state = Button.State.UNSELECTED;
            if (listView.getCheckmarksEnabled()) {
                if (listView.getAllowTriStateCheckmarks()) {
                    state = listView.getItemCheckmarkState(i);
                } else {
                    state = listView.isItemChecked(i) ? Button.State.SELECTED : Button.State.UNSELECTED;
                }
                itemX = CHECKBOX.getWidth() + checkboxPadding.getWidth();
                itemWidth -= itemX;
            }
            itemRenderer.render(item, i, listView, false, state, false, false);
            int itemHeight = itemRenderer.getPreferredHeight(itemWidth);
            if (listView.getCheckmarksEnabled()) {
                itemHeight = Math.max(itemHeight, checkboxHeight);
            }
            itemY += itemHeight;
            itemBoundaries.add(itemY);
        }
    } else {
        itemRenderer.render(null, -1, listView, false, Button.State.UNSELECTED, false, false);
        fixedItemHeight = itemRenderer.getPreferredHeight(-1);
        if (listView.getCheckmarksEnabled()) {
            fixedItemHeight = Math.max(CHECKBOX.getHeight() + checkboxPadding.getHeight(), fixedItemHeight);
        }
    }
    if (validateSelection) {
        // Ensure that the selection is visible
        Sequence<Span> selectedRanges = listView.getSelectedRanges();
        if (selectedRanges.getLength() > 0) {
            int rangeStart = selectedRanges.get(0).start;
            int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
            Bounds selectionBounds = getItemBounds(rangeStart);
            selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
            Bounds visibleSelectionBounds = listView.getVisibleArea(selectionBounds);
            if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
                listView.scrollAreaToVisible(selectionBounds);
            }
        }
    }
    validateSelection = false;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Span(org.apache.pivot.wtk.Span) ListView(org.apache.pivot.wtk.ListView) Button(org.apache.pivot.wtk.Button) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List)

Example 72 with Bounds

use of org.apache.pivot.wtk.Bounds in project pivot by apache.

the class TerraListViewSkin method selectedRangeAdded.

// List view selection detail events
@Override
public void selectedRangeAdded(ListView listView, int rangeStart, int rangeEnd) {
    if (listView.isValid()) {
        Bounds selectionBounds = getItemBounds(rangeStart);
        selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
        repaintComponent(selectionBounds);
        // Ensure that the selection is visible
        Bounds visibleSelectionBounds = listView.getVisibleArea(selectionBounds);
        if (visibleSelectionBounds.height < selectionBounds.height) {
            listView.scrollAreaToVisible(selectionBounds);
        }
    } else {
        validateSelection = true;
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 73 with Bounds

use of org.apache.pivot.wtk.Bounds in project pivot by apache.

the class TerraListViewSkin method selectedRangeRemoved.

@Override
public void selectedRangeRemoved(ListView listView, int rangeStart, int rangeEnd) {
    // Repaint the area containing the removed selection
    if (listView.isValid()) {
        Bounds selectionBounds = getItemBounds(rangeStart);
        selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
        repaintComponent(selectionBounds);
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 74 with Bounds

use of org.apache.pivot.wtk.Bounds in project pivot by apache.

the class TerraMenuButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    MenuButton menuButton = (MenuButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    Color colorLocal = null;
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (!toolbar || highlighted || menuButton.isFocused() || menuPopup.isOpen()) {
        if (menuButton.isEnabled()) {
            colorLocal = this.color;
            backgroundColorLocal = this.backgroundColor;
            bevelColorLocal = (pressed || (menuPopup.isOpen() && !menuPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
            borderColorLocal = this.borderColor;
        } else {
            colorLocal = disabledColor;
            backgroundColorLocal = disabledBackgroundColor;
            bevelColorLocal = disabledBevelColor;
            borderColorLocal = disabledBorderColor;
        }
    }
    // Paint the background
    if (backgroundColorLocal != null && bevelColorLocal != null) {
        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(padding.left + 1, padding.top + 1, Math.max(width - (padding.getWidth() + spacing + TRIGGER_WIDTH + 2), 0), Math.max(height - (padding.getHeight() + 2), 0));
    Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
    dataRenderer.render(menuButton.getButtonData(), menuButton, highlighted);
    dataRenderer.setSize(contentBounds.getSize());
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(contentBounds.x, contentBounds.y);
    contentGraphics.clipRect(0, 0, contentBounds.width, contentBounds.height);
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    GraphicsUtilities.setAntialiasingOn(graphics);
    // Paint the border
    if (borderColorLocal != null && !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));
    }
    // Paint the focus state
    if (menuButton.isFocused() && !toolbar) {
        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(this.borderColor);
        graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0), Math.max(height - 5, 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 = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, // TODO: this calculation doesn't look right \\// (should be + not -?)
    TRIGGER_WIDTH, Math.max(height - (padding.top - padding.bottom), 0));
    int tx = triggerBounds.x + (triggerBounds.width - triggerIconShape.getBounds().width) / 2;
    int ty = triggerBounds.y + (triggerBounds.height - triggerIconShape.getBounds().height) / 2;
    triggerGraphics.translate(tx, ty);
    triggerGraphics.draw(triggerIconShape);
    triggerGraphics.fill(triggerIconShape);
    triggerGraphics.dispose();
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Bounds(org.apache.pivot.wtk.Bounds) MenuButton(org.apache.pivot.wtk.MenuButton) GradientPaint(java.awt.GradientPaint) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 75 with Bounds

use of org.apache.pivot.wtk.Bounds in project pivot by apache.

the class TerraCalendarSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    super.paint(graphics);
    int width = getWidth();
    Bounds monthYearRowBounds = calendarTablePane.getRowBounds(0);
    graphics.setColor(highlightBackgroundColor);
    graphics.fillRect(monthYearRowBounds.x, monthYearRowBounds.y, monthYearRowBounds.width, monthYearRowBounds.height);
    Bounds labelRowBounds = calendarTablePane.getRowBounds(1);
    graphics.setColor(dividerColor);
    int dividerY = labelRowBounds.y + labelRowBounds.height - 2;
    GraphicsUtilities.drawLine(graphics, 2, dividerY, Math.max(0, width - 4), Orientation.HORIZONTAL);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint)

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