use of org.apache.pivot.wtk.Point in project pivot by apache.
the class MenuBarItemSkin method activeChanged.
@Override
public void activeChanged(MenuBar.Item menuBarItem) {
if (menuBarItem.isActive()) {
Display display = menuBarItem.getDisplay();
Point menuBarItemLocation = menuBarItem.mapPointToAncestor(display, 0, getHeight());
// TODO Ensure that the popup remains within the bounds of the
// display
menuPopup.setLocation(menuBarItemLocation.x, menuBarItemLocation.y);
menuPopup.open(menuBarItem.getWindow());
menuPopup.requestFocus();
} else {
menuPopup.close(true);
}
repaintComponent();
}
use of org.apache.pivot.wtk.Point in project pivot by apache.
the class DragAndDropDemo method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
// Text
label.setDragSource(new DragSource() {
private LocalManifest content = null;
@Override
public boolean beginDrag(Component component, int x, int y) {
String text = label.getText();
if (text != null) {
content = new LocalManifest();
content.putText(label.getText());
}
return (content != null);
}
@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() && DropAction.COPY.isSelected(supportedDropActions)) {
dropAction = DropAction.COPY;
}
return dropAction;
}
@Override
public void dragExit(Component component) {
// empty block
}
@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()) {
try {
label.setText(dragContent.getText());
dropAction = DropAction.COPY;
} catch (IOException exception) {
System.err.println(exception);
}
}
dragExit(component);
return dropAction;
}
});
copyTextButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
String text = label.getText();
LocalManifest clipboardContent = new LocalManifest();
clipboardContent.putText(text);
Clipboard.setContent(clipboardContent);
}
});
pasteTextButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Manifest clipboardContent = Clipboard.getContent();
if (clipboardContent != null && clipboardContent.containsText()) {
try {
label.setText(clipboardContent.getText());
} catch (IOException exception) {
System.err.println(exception);
}
}
}
});
// Images
imageView.setDragSource(new DragSource() {
private LocalManifest content = null;
@Override
public boolean beginDrag(Component component, int x, int y) {
Image image = imageView.getImage();
if (image != null) {
content = new LocalManifest();
content.putImage(image);
}
return (content != null);
}
@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();
}
});
imageView.setDropTarget(new DropTarget() {
@Override
public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsImage() && DropAction.COPY.isSelected(supportedDropActions)) {
dropAction = DropAction.COPY;
}
return dropAction;
}
@Override
public void dragExit(Component component) {
// empty block
}
@Override
public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsImage() ? DropAction.COPY : null);
}
@Override
public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsImage() ? DropAction.COPY : null);
}
@Override
public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsImage()) {
try {
imageView.setImage(dragContent.getImage());
dropAction = DropAction.COPY;
} catch (IOException exception) {
System.err.println(exception);
}
}
dragExit(component);
return dropAction;
}
});
copyImageButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Image image = imageView.getImage();
if (image != null) {
LocalManifest clipboardContent = new LocalManifest();
clipboardContent.putImage(image);
Clipboard.setContent(clipboardContent);
}
}
});
pasteImageButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Manifest clipboardContent = Clipboard.getContent();
if (clipboardContent != null && clipboardContent.containsImage()) {
try {
imageView.setImage(clipboardContent.getImage());
} catch (IOException exception) {
System.err.println(exception);
}
}
}
});
// Files
listView.setListData(new FileList());
listView.setDragSource(new DragSource() {
private LocalManifest content = null;
@Override
public boolean beginDrag(Component component, int x, int y) {
ListView listViewLocal = (ListView) component;
FileList fileList = (FileList) listViewLocal.getListData();
if (fileList.getLength() > 0) {
content = new LocalManifest();
content.putFileList(fileList);
}
return (content != null);
}
@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();
}
});
listView.setDropTarget(new DropTarget() {
@Override
public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsFileList() && DropAction.COPY.isSelected(supportedDropActions)) {
dropAction = DropAction.COPY;
}
return dropAction;
}
@Override
public void dragExit(Component component) {
// empty block
}
@Override
public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsFileList() ? DropAction.COPY : null);
}
@Override
public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsFileList() ? DropAction.COPY : null);
}
@Override
public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsFileList()) {
try {
listView.setListData(dragContent.getFileList());
dropAction = DropAction.COPY;
} catch (IOException exception) {
System.err.println(exception);
}
}
dragExit(component);
return dropAction;
}
});
copyFilesButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
// TODO
}
});
pasteFilesButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
// TODO
}
});
}
use of org.apache.pivot.wtk.Point in project pivot by apache.
the class DragDropTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
frame1.setTitle("Frame 1");
frame1.setPreferredSize(160, 120);
frame1.getStyles().put(Style.resizable, false);
DragSource imageDragSource = new DragSource() {
private Image image = null;
private Point offset = null;
private LocalManifest content = null;
@Override
public boolean beginDrag(Component component, int x, int y) {
ImageView imageView = (ImageView) component;
image = imageView.getImage();
if (image != null) {
imageView.setImage((Image) null);
content = new LocalManifest();
content.putImage(image);
offset = new Point(x - (imageView.getWidth() - image.getWidth()) / 2, y - (imageView.getHeight() - image.getHeight()) / 2);
}
return (image != null);
}
@Override
public void endDrag(Component component, DropAction dropAction) {
if (dropAction == null) {
ImageView imageView = (ImageView) component;
imageView.setImage(image);
}
image = null;
offset = null;
content = null;
}
@Override
public boolean isNative() {
return false;
}
@Override
public LocalManifest getContent() {
return content;
}
@Override
public Visual getRepresentation() {
return image;
}
@Override
public Point getOffset() {
return offset;
}
@Override
public int getSupportedDropActions() {
return DropAction.MOVE.getMask();
}
};
DropTarget imageDropTarget = new DropTarget() {
@Override
public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
DropAction dropAction = null;
ImageView imageView = (ImageView) component;
if (imageView.getImage() == null && dragContent.containsImage() && DropAction.MOVE.isSelected(supportedDropActions)) {
dropAction = DropAction.MOVE;
component.getStyles().put(Style.backgroundColor, IMAGE_VIEW_DROP_HIGHLIGHT_COLOR);
}
return dropAction;
}
@Override
public void dragExit(Component component) {
component.getStyles().put(Style.backgroundColor, IMAGE_VIEW_BACKGROUND_COLOR);
}
@Override
public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsImage() ? DropAction.MOVE : null);
}
@Override
public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsImage() ? DropAction.MOVE : null);
}
@Override
public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsImage()) {
ImageView imageView = (ImageView) component;
try {
imageView.setImage(dragContent.getImage());
dropAction = DropAction.MOVE;
} catch (IOException exception) {
System.err.println(exception);
}
}
dragExit(component);
return dropAction;
}
};
ImageView imageView1 = new ImageView();
imageView1.setImage(Image.load(getClass().getResource("go-home.png")));
imageView1.getStyles().put(Style.backgroundColor, IMAGE_VIEW_BACKGROUND_COLOR);
imageView1.setDragSource(imageDragSource);
imageView1.setDropTarget(imageDropTarget);
frame1.setContent(imageView1);
frame1.open(display);
frame2.setTitle("Frame 2");
frame2.setPreferredSize(160, 120);
frame2.setLocation(180, 0);
ImageView imageView2 = new ImageView();
imageView2.getStyles().put(Style.backgroundColor, IMAGE_VIEW_BACKGROUND_COLOR);
imageView2.setDragSource(imageDragSource);
imageView2.setDropTarget(imageDropTarget);
frame2.setContent(imageView2);
frame2.open(display);
}
use of org.apache.pivot.wtk.Point in project pivot by apache.
the class TerraVFSBrowserSkin method getFileAt.
@Override
public FileObject getFileAt(int x, int y) {
FileObject file = null;
VFSBrowser fileBrowser = (VFSBrowser) 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 = (FileObject) fileTableView.getTableData().get(index);
}
}
return file;
}
use of org.apache.pivot.wtk.Point in project pivot by apache.
the class BoundsTest method test.
@Test
public void test() {
Bounds bndMinus1 = new Bounds(-1, -1, 0, 0);
Bounds bnd0 = new Bounds(0, 0, 0, 0);
Bounds bnd1 = new Bounds(1, 1, 1, 1);
Dimensions dim0 = new Dimensions(0, 0);
Dimensions dim1 = new Dimensions(1, 1);
Point p10 = new Point(10, 10);
Bounds bnd10 = new Bounds(p10, dim1);
Bounds bnd10a = new Bounds(dim1);
Bounds bnd10b = new Bounds(0, 0, 1, 1);
Bounds bnd2 = Bounds.decode("[2, 3, 4, 5]");
Bounds bnd3 = Bounds.decode("{x:2, y:3, width:4, height:5}");
Bounds bnd3a = new Bounds(2, 3, 4, 5);
Bounds bnd4 = new Bounds(4, 4, 4, 5);
// -> {3, 4, 4, 5}
Bounds bnd5 = bnd3a.translate(1, 1);
bnd5 = bnd5.expand(-2, -4);
Bounds bnd5a = new Bounds(3, 4, 2, 1);
Bounds bnd5b = new Bounds(4, 3, 1, 2);
Bounds bndN = new Bounds(0, 0, 8, 9);
Bounds bndAll = bnd1.union(bnd0).union(bnd2).union(bnd3).union(bnd4);
Bounds bnd6 = Bounds.decode("2, 3; 4, 5");
Bounds bnd6a = new Bounds(2, 3, 4, 5);
assertEquals(Bounds.EMPTY, bnd0);
assertNotEquals(bndMinus1, bnd0);
assertNotEquals(bnd0, bnd1);
assertEquals(bnd10a, bnd10b);
assertEquals(bnd10.getLocation(), p10);
assertEquals(bnd10.getSize(), dim1);
assertEquals(bnd2, bnd3);
assertEquals(bnd3, bnd3a);
assertEquals(bndMinus1.getSize(), dim0);
assertEquals(bnd0.getSize(), dim0);
assertEquals(bnd1.getSize(), dim1);
assertFalse(bnd1.contains(bnd0));
assertFalse(bndMinus1.intersects(bnd0));
assertFalse(bnd0.intersects(bnd1));
assertEquals(bnd0.intersect(bnd1), new Bounds(1, 1, -1, -1));
assertTrue(bnd5a.intersects(bnd5b));
assertTrue(bnd0.union(bnd1).equals(new Bounds(0, 0, 2, 2)));
assertFalse(bnd0.equals(bnd1));
assertTrue(bnd5.equals(bnd5a));
assertEquals(bndN, bndAll);
assertEquals(bnd6, bnd6a);
assertEquals(bnd6a.toString(), "Bounds [2,3;4x5]");
}
Aggregations