Search in sources :

Example 16 with Point

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

the class TreeViewNodeEditor method beginEdit.

@Override
public void beginEdit(TreeView treeViewArgument, Path pathArgument) {
    this.treeView = treeViewArgument;
    this.path = pathArgument;
    // Get the data being edited
    List<?> treeData = treeViewArgument.getTreeData();
    TreeNode treeNode = (TreeNode) Sequence.Tree.get(treeData, pathArgument);
    String text = treeNode.getText();
    textInput.setText(text != null ? text : "");
    textInput.selectAll();
    // Get the node bounds
    Bounds nodeBounds = treeViewArgument.getNodeBounds(pathArgument);
    int nodeIndent = treeViewArgument.getNodeIndent(pathArgument.getLength());
    nodeBounds = new Bounds(nodeBounds.x + nodeIndent, nodeBounds.y, nodeBounds.width - nodeIndent, nodeBounds.height);
    // Render the node data
    TreeViewNodeRenderer nodeRenderer = (TreeViewNodeRenderer) treeViewArgument.getNodeRenderer();
    nodeRenderer.render(treeNode, pathArgument, treeViewArgument.getRowIndex(pathArgument), treeViewArgument, false, false, TreeView.NodeCheckState.UNCHECKED, false, false);
    nodeRenderer.setSize(nodeBounds.width, nodeBounds.height);
    // Get the text bounds
    Bounds textBounds = nodeRenderer.getTextBounds();
    // Calculate the bounds of what is being edited
    Insets padding = (Insets) textInput.getStyles().get(Style.padding);
    Bounds editBounds = new Bounds(nodeBounds.x + textBounds.x - (padding.left + 1), nodeBounds.y, nodeBounds.width - textBounds.x + (padding.left + 1), nodeBounds.height);
    // Scroll to make the node as visible as possible
    treeViewArgument.scrollAreaToVisible(editBounds.x, editBounds.y, textBounds.width + padding.left + 1, editBounds.height);
    // Constrain the bounds by what is visible through viewport ancestors
    editBounds = treeViewArgument.getVisibleArea(editBounds);
    Point location = treeViewArgument.mapPointToAncestor(treeViewArgument.getDisplay(), editBounds.x, editBounds.y);
    textInput.setPreferredWidth(editBounds.width);
    setLocation(location.x, location.y + (editBounds.height - getPreferredHeight(-1)) / 2);
    // Open the editor
    open(treeViewArgument.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 17 with Point

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

the class MenuItemSkin method buttonPressed.

@Override
public void buttonPressed(Button button) {
    Menu.Item menuItem = (Menu.Item) getComponent();
    Menu menu = menuItem.getMenu();
    if (menu != null && !menuPopup.isOpen()) {
        // Size and position the popup
        Display display = menuItem.getDisplay();
        Dimensions displaySize = display.getSize();
        Point location = menuItem.mapPointToAncestor(display, getWidth(), 0);
        menuPopup.setLocation(location.x, location.y);
        int width = getWidth();
        // If the popup extends over the right edge of the display,
        // move it so that the right edge of the popup lines up with the
        // left edge of the menu item
        int popupWidth = menuPopup.getPreferredWidth();
        if (location.x + popupWidth > displaySize.width) {
            menuPopup.setX(location.x - width - popupWidth);
        }
        menuPopup.open(menuItem.getWindow());
        menuPopup.requestFocus();
    }
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Menu(org.apache.pivot.wtk.Menu) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 18 with Point

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

the class TerraPaletteSkin method mouseMove.

@Override
public boolean mouseMove(Component component, int x, int y) {
    boolean consumed = super.mouseMove(component, x, y);
    if (Mouse.getCapturer() == component) {
        Palette palette = (Palette) getComponent();
        Display display = palette.getDisplay();
        Point location = palette.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 (dragOffset != null) {
            // Move the window
            palette.setLocation(location.x - dragOffset.x, location.y - dragOffset.y);
        } else {
            if (resizeOffset != null) {
                // Resize the frame
                int preferredWidth = -1;
                int preferredHeight = -1;
                if (palette.isPreferredWidthSet()) {
                    preferredWidth = Math.max(location.x - palette.getX() + resizeOffset.x, titleBarTablePane.getPreferredWidth(-1) + 2);
                    preferredWidth = Math.min(preferredWidth, palette.getMaximumWidth());
                    preferredWidth = Math.max(preferredWidth, palette.getMinimumWidth());
                }
                if (palette.isPreferredHeightSet()) {
                    preferredHeight = Math.max(location.y - palette.getY() + resizeOffset.y, titleBarTablePane.getHeight() + resizeHandle.getHeight() + 7);
                    preferredHeight = Math.min(preferredHeight, palette.getMaximumHeight());
                    preferredHeight = Math.max(preferredHeight, palette.getMinimumHeight());
                }
                palette.setPreferredSize(preferredWidth, preferredHeight);
            }
        }
    } else {
        Cursor cursor = null;
        if (resizeHandle.isVisible() && x > resizeHandle.getX() && y > resizeHandle.getY()) {
            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;
            }
        }
        component.setCursor(cursor);
    }
    return consumed;
}
Also used : Palette(org.apache.pivot.wtk.Palette) Point(org.apache.pivot.wtk.Point) Cursor(org.apache.pivot.wtk.Cursor) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Display(org.apache.pivot.wtk.Display)

Example 19 with Point

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

the class TerraPaletteSkin method mouseDown.

@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseDown(component, button, x, y);
    Window window = (Window) getComponent();
    boolean maximized = window.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 (resizeHandle.isVisible() && x > resizeHandle.getX() && y > resizeHandle.getY()) {
                resizeOffset = new Point(getWidth() - x, getHeight() - y);
                Mouse.capture(component);
            }
        }
    }
    return consumed;
}
Also used : Window(org.apache.pivot.wtk.Window) Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point)

Example 20 with Point

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

the class TerraFileBrowserSkin method getFileAt.

@Override
public File getFileAt(int x, int y) {
    File file = null;
    FileBrowser fileBrowser = (FileBrowser) getComponent();
    Component component = fileBrowser.getDescendantAt(x, y);
    if (component == fileTableView) {
        Point location = fileTableView.mapPointFromAncestor(fileBrowser, x, y);
        int index = fileTableView.getRowAt(location.y);
        if (index != -1) {
            file = (File) fileTableView.getTableData().get(index);
        }
    }
    return file;
}
Also used : FileBrowser(org.apache.pivot.wtk.FileBrowser) Point(org.apache.pivot.wtk.Point) Component(org.apache.pivot.wtk.Component) File(java.io.File) Point(org.apache.pivot.wtk.Point)

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