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());
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations