use of org.apache.pivot.wtk.Component in project pivot by apache.
the class CheckedListViewTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer serializer = new BXMLSerializer();
mainWindow = (Window) serializer.readObject(CheckedListViewTest.class, "checked_list_view_test.bxml");
serializer.bind(this);
allowMixedStateCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
listView.setAllowTriStateCheckmarks(button.isSelected());
// Not sure why, but changing this setting clears all the checks but doesn't
// trigger the item state listener (it's documented, but ...)
selectedItemsLabel.setText("");
}
});
showMixedAsSelectedCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
listView.setCheckmarksMixedAsChecked(button.isSelected());
}
});
listView.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.DELETE) {
@SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
Sequence<Span> selectedRanges = listView.getSelectedRanges();
for (int i = selectedRanges.getLength() - 1; i >= 0; i--) {
Span selectedRange = selectedRanges.get(i);
listData.remove(selectedRange.start, selectedRange.end - selectedRange.start + 1);
}
}
return false;
}
});
listView.getListViewItemStateListeners().add(new ListViewItemStateListener() {
private void displayCheckedItems(ListView listView) {
List<?> listData = listView.getListData();
StringBuffer buf = new StringBuffer();
for (Integer i : listView.getCheckedIndexes()) {
if (buf.length() > 0) {
buf.append(",");
}
Object item = listData.get(i);
buf.append(item.toString());
}
selectedItemsLabel.setText(buf.toString());
}
@Override
public void itemCheckedChanged(ListView listView, int index) {
displayCheckedItems(listView);
}
@Override
public void itemCheckedStateChanged(ListView listView, int index) {
displayCheckedItems(listView);
}
});
listView.setItemChecked(0, true);
listView.setItemChecked(2, true);
mainWindow.open(display);
}
use of org.apache.pivot.wtk.Component 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.Component in project pivot by apache.
the class ComponentKeyListenerExample method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
TextInput textInput = (TextInput) namespace.get("textInput");
textInput.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.S && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
Alert.alert("You pressed Control-S!", component.getWindow());
}
return false;
}
});
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class SheetSlideDirectionWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
// Populate the ListButton with values from the enum
listButton.setListData(new ArrayList<>(SheetPlacement.values()));
listButton = null;
// Populate the form with data from the Sheet's styles
form.load(sheet.getStyles());
// Common ButtonPressListener to be applied to all four of
// the PushButtons representing a slide direction
ButtonPressListener openSheetButtonPressListener = new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
StyleDictionary sheetStyles = sheet.getStyles();
form.store(sheetStyles);
button.store(sheetStyles);
form.load(sheetStyles);
sheet.load(sheetStyles);
sheet.open(button.getWindow());
}
};
// Apply the common ButtonPressListener to the PushButtons
for (Iterator<Component> it = tablePane.iterator(); it.hasNext(); ) {
Component component = it.next();
if (component instanceof PushButton) {
PushButton button = (PushButton) component;
button.getButtonPressListeners().add(openSheetButtonPressListener);
button.setTooltipText("Press me!");
}
}
tablePane = null;
// Mouse handler to enable users to quickly close the sheet
final ContainerMouseListener displayMouseHandler = new ContainerMouseListener() {
@Override
public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display) container;
Component component = display.getComponentAt(x, y);
// Close the sheet by clicking away from it.
// This allows resizing etc to work without requiring
// a close button or similar on the sheet.
boolean consumed = (component != sheet);
if (consumed) {
sheet.close();
}
return consumed;
}
};
// Add/remove the mouse handler based on the Sheet's state
sheet.getWindowStateListeners().add(new WindowStateListener() {
@Override
public void windowOpened(Window window) {
window.getDisplay().getContainerMouseListeners().add(displayMouseHandler);
}
@Override
public void windowClosed(Window window, Display display, Window owner) {
display.getContainerMouseListeners().remove(displayMouseHandler);
}
});
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class BaselineTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = new Window((Component) bxmlSerializer.readObject(getClass().getResource("baseline_test.bxml")));
window.setTitle("Baseline Test");
window.setMaximized(true);
window.open(display);
}
Aggregations