Search in sources :

Example 11 with Point

use of org.apache.pivot.wtk.Point 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 12 with Point

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

the class NativeDragDropTest method startup.

@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
    final Label label = new Label("http://pivot.apache.org/");
    label.getStyles().put(Style.font, new Font("Arial", Font.PLAIN, 24));
    label.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    label.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    label.setDragSource(new DragSource() {

        private LocalManifest content = null;

        @Override
        public boolean beginDrag(Component component, int x, int y) {
            content = new LocalManifest();
            content.putText(label.getText());
            return true;
        }

        @Override
        public void endDrag(Component component, DropAction dropAction) {
            content = null;
        }

        @Override
        public boolean isNative() {
            return true;
        }

        @Override
        public LocalManifest getContent() {
            return content;
        }

        @Override
        public Visual getRepresentation() {
            return null;
        }

        @Override
        public Point getOffset() {
            return null;
        }

        @Override
        public int getSupportedDropActions() {
            return DropAction.COPY.getMask();
        }
    });
    label.setDropTarget(new DropTarget() {

        @Override
        public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
            DropAction dropAction = null;
            if (dragContent.containsText()) {
                frame.getStyles().put(Style.backgroundColor, "#ffcccc");
                dropAction = DropAction.COPY;
            }
            return dropAction;
        }

        @Override
        public void dragExit(Component component) {
            frame.getStyles().put(Style.backgroundColor, "#ffffff");
        }

        @Override
        public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
            return (dragContent.containsText() ? DropAction.COPY : null);
        }

        @Override
        public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
            return (dragContent.containsText() ? DropAction.COPY : null);
        }

        @Override
        public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
            DropAction dropAction = null;
            if (dragContent.containsText()) {
                Label labelLocal = (Label) component;
                try {
                    labelLocal.setText(dragContent.getText());
                } catch (IOException exception) {
                    System.err.println(exception);
                }
            }
            dragExit(component);
            return dropAction;
        }
    });
    frame = new Frame(label);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Label(org.apache.pivot.wtk.Label) DropAction(org.apache.pivot.wtk.DropAction) DragSource(org.apache.pivot.wtk.DragSource) Point(org.apache.pivot.wtk.Point) IOException(java.io.IOException) LocalManifest(org.apache.pivot.wtk.LocalManifest) Manifest(org.apache.pivot.wtk.Manifest) Font(java.awt.Font) LocalManifest(org.apache.pivot.wtk.LocalManifest) Point(org.apache.pivot.wtk.Point) DropTarget(org.apache.pivot.wtk.DropTarget) Component(org.apache.pivot.wtk.Component) Visual(org.apache.pivot.wtk.Visual)

Example 13 with Point

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

the class ComponentSkin method tooltipTriggered.

@Override
public void tooltipTriggered(Component componentArgument, int x, int y) {
    String tooltipText = component.getTooltipText();
    if (tooltipText != null) {
        Label tooltipLabel = new Label(tooltipText);
        boolean tooltipWrapText = component.getTooltipWrapText();
        tooltipLabel.getStyles().put(Style.wrapText, tooltipWrapText);
        Tooltip tooltip = new Tooltip(tooltipLabel);
        Display display = component.getDisplay();
        Point location = component.mapPointToAncestor(display, x, y);
        // Ensure that the tooltip stays on screen
        int tooltipX = location.x + 16;
        int tooltipY = location.y;
        int tooltipWidth = tooltip.getPreferredWidth();
        int tooltipHeight = tooltip.getPreferredHeight();
        if (tooltipX + tooltipWidth > display.getWidth()) {
            // the cursor
            if (tooltipY > tooltipHeight) {
                tooltipX = display.getWidth() - tooltipWidth;
            } else {
                tooltipX = location.x - tooltipWidth - 16;
            }
            if (tooltipX < 0) {
                tooltipX = 0;
            }
            // these x adjustments
            if (tooltipX < location.x && tooltipX + tooltipWidth > location.x) {
                tooltipY -= tooltipHeight;
                if (tooltipY < 0) {
                    tooltipY = 0;
                }
            }
        }
        if (tooltipY + tooltipHeight > display.getHeight()) {
            tooltipY -= tooltipHeight;
        }
        tooltip.setLocation(tooltipX, tooltipY);
        tooltip.open(component.getWindow());
    }
}
Also used : Tooltip(org.apache.pivot.wtk.Tooltip) Label(org.apache.pivot.wtk.Label) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 14 with Point

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

the class ListViewItemEditor method beginEdit.

@Override
public void beginEdit(ListView listViewArgument, int itemIndexArgument) {
    this.listView = listViewArgument;
    this.itemIndex = itemIndexArgument;
    // Get the data being edited
    List<?> listData = listViewArgument.getListData();
    ListItem listItem = (ListItem) listData.get(itemIndexArgument);
    String text = listItem.getText();
    textInput.setText(text != null ? text : "");
    textInput.selectAll();
    // Get the item bounds
    Bounds itemBounds = listViewArgument.getItemBounds(itemIndexArgument);
    int itemIndent = listViewArgument.getItemIndent();
    itemBounds = new Bounds(itemBounds.x + itemIndent, itemBounds.y, itemBounds.width - itemIndent, itemBounds.height);
    // Render the item data
    ListViewItemRenderer itemRenderer = (ListViewItemRenderer) listViewArgument.getItemRenderer();
    itemRenderer.render(listItem, itemIndexArgument, listViewArgument, false, Button.State.UNSELECTED, false, false);
    itemRenderer.setSize(itemBounds.width, itemBounds.height);
    // Calculate the text bounds
    Bounds textBounds = itemRenderer.getTextBounds();
    // Calculate the bounds of what is being edited
    Insets padding = (Insets) textInput.getStyles().get(Style.padding);
    Bounds editBounds = new Bounds(itemBounds.x + textBounds.x - (padding.left + 1), itemBounds.y, itemBounds.width - textBounds.x + (padding.left + 1), itemBounds.height);
    // Scroll to make the item as visible as possible
    listViewArgument.scrollAreaToVisible(editBounds.x, editBounds.y, textBounds.width + padding.left + 1, editBounds.height);
    // Constrain the bounds by what is visible through viewport ancestors
    editBounds = listViewArgument.getVisibleArea(editBounds);
    Point location = listViewArgument.mapPointToAncestor(listViewArgument.getDisplay(), editBounds.x, editBounds.y);
    textInput.setPreferredWidth(editBounds.width);
    setLocation(location.x, location.y + (editBounds.height - getPreferredHeight(-1)) / 2);
    // Open the editor
    open(listViewArgument.getWindow());
}
Also used : Insets(org.apache.pivot.wtk.Insets) Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point)

Example 15 with Point

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

the class TableViewRowEditor method beginEdit.

@Override
public void beginEdit(TableView tableViewArgument, int rowIndexArgument, int columnIndexArgument) {
    this.tableView = tableViewArgument;
    this.rowIndex = rowIndexArgument;
    this.columnIndex = columnIndexArgument;
    Container tableViewParent = tableViewArgument.getParent();
    tableViewScrollPane = (tableViewParent instanceof ScrollPane) ? (ScrollPane) tableViewParent : null;
    // Add/create the editor components
    TableView.ColumnSequence tableViewColumns = tableViewArgument.getColumns();
    TablePane.ColumnSequence tablePaneColumns = tablePane.getColumns();
    for (int i = 0, n = tableViewColumns.getLength(); i < n; i++) {
        // Add a new column to the table pane to match the table view column
        TablePane.Column tablePaneColumn = new TablePane.Column();
        tablePaneColumn.setWidth(tableViewArgument.getColumnBounds(i).width);
        tablePaneColumns.add(tablePaneColumn);
        // Determine which component to use as the editor for this column
        String columnName = tableViewColumns.get(i).getName();
        Component editorComponent = null;
        if (columnName != null) {
            editorComponent = cellEditors.get(columnName);
        }
        // Default to a read-only text input editor
        if (editorComponent == null) {
            TextInput editorTextInput = new TextInput();
            editorTextInput.setTextKey(columnName);
            editorTextInput.setEnabled(false);
            editorTextInput.setTextBindType(BindType.LOAD);
            editorComponent = editorTextInput;
        }
        // Add the editor component to the table pane
        editorRow.add(editorComponent);
    }
    // Get the data being edited
    List<?> tableData = tableViewArgument.getTableData();
    Object tableRow = tableData.get(rowIndexArgument);
    // Load the row data into the editor components
    tablePane.load(tableRow);
    // Get the row bounds
    Bounds rowBounds = tableViewArgument.getRowBounds(rowIndexArgument);
    rowImage.bounds = rowBounds;
    // Scroll to make the row as visible as possible
    tableViewArgument.scrollAreaToVisible(rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
    // Constrain the bounds by what is visible through viewport ancestors
    rowBounds = tableViewArgument.getVisibleArea(rowBounds);
    Point location = tableViewArgument.mapPointToAncestor(tableViewArgument.getDisplay(), rowBounds.x, rowBounds.y);
    // Set size and location and match scroll left
    setPreferredWidth(rowBounds.width);
    setLocation(location.x, location.y + (rowBounds.height - getPreferredHeight(-1)) / 2);
    if (tableViewScrollPane != null) {
        scrollPane.setScrollLeft(tableViewScrollPane.getScrollLeft());
    }
    // Open the editor
    open(tableViewArgument.getWindow());
    // Start the transition
    cardPane.setSelectedIndex(EDITOR_CARD_INDEX);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Container(org.apache.pivot.wtk.Container) ScrollPane(org.apache.pivot.wtk.ScrollPane) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) TableView(org.apache.pivot.wtk.TableView) TablePane(org.apache.pivot.wtk.TablePane)

Aggregations

Point (org.apache.pivot.wtk.Point)26 Bounds (org.apache.pivot.wtk.Bounds)11 Component (org.apache.pivot.wtk.Component)9 Display (org.apache.pivot.wtk.Display)9 TextInput (org.apache.pivot.wtk.TextInput)6 IOException (java.io.IOException)5 GradientPaint (java.awt.GradientPaint)4 Button (org.apache.pivot.wtk.Button)4 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 Container (org.apache.pivot.wtk.Container)3 Cursor (org.apache.pivot.wtk.Cursor)3 DragSource (org.apache.pivot.wtk.DragSource)3 DropAction (org.apache.pivot.wtk.DropAction)3 DropTarget (org.apache.pivot.wtk.DropTarget)3 Label (org.apache.pivot.wtk.Label)3 Line2D (java.awt.geom.Line2D)2 File (java.io.File)2 FileObject (org.apache.commons.vfs2.FileObject)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 ArrayList (org.apache.pivot.collections.ArrayList)2