Search in sources :

Example 66 with Component

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);
}
Also used : ListViewItemStateListener(org.apache.pivot.wtk.ListViewItemStateListener) Keyboard(org.apache.pivot.wtk.Keyboard) Sequence(org.apache.pivot.collections.Sequence) Span(org.apache.pivot.wtk.Span) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) ListView(org.apache.pivot.wtk.ListView) Button(org.apache.pivot.wtk.Button) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 67 with Component

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);
}
Also used : DropAction(org.apache.pivot.wtk.DropAction) DragSource(org.apache.pivot.wtk.DragSource) Point(org.apache.pivot.wtk.Point) ImageView(org.apache.pivot.wtk.ImageView) DropTarget(org.apache.pivot.wtk.DropTarget) IOException(java.io.IOException) Image(org.apache.pivot.wtk.media.Image) Component(org.apache.pivot.wtk.Component) LocalManifest(org.apache.pivot.wtk.LocalManifest) Manifest(org.apache.pivot.wtk.Manifest) LocalManifest(org.apache.pivot.wtk.LocalManifest)

Example 68 with Component

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;
        }
    });
}
Also used : ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) Keyboard(org.apache.pivot.wtk.Keyboard) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component)

Example 69 with Component

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);
        }
    });
}
Also used : Window(org.apache.pivot.wtk.Window) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Container(org.apache.pivot.wtk.Container) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) ContainerMouseListener(org.apache.pivot.wtk.ContainerMouseListener) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) Display(org.apache.pivot.wtk.Display)

Example 70 with Component

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);
}
Also used : Window(org.apache.pivot.wtk.Window) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

Component (org.apache.pivot.wtk.Component)209 Dimensions (org.apache.pivot.wtk.Dimensions)40 Point (org.apache.pivot.wtk.Point)38 GradientPaint (java.awt.GradientPaint)33 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)24 TextInput (org.apache.pivot.wtk.TextInput)21 Label (org.apache.pivot.wtk.Label)20 BoxPane (org.apache.pivot.wtk.BoxPane)18 Paint (java.awt.Paint)17 Button (org.apache.pivot.wtk.Button)15 PushButton (org.apache.pivot.wtk.PushButton)14 ScrollPane (org.apache.pivot.wtk.ScrollPane)14 TablePane (org.apache.pivot.wtk.TablePane)14 Window (org.apache.pivot.wtk.Window)14 IOException (java.io.IOException)13 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)13 Frame (org.apache.pivot.wtk.Frame)13 FlowPane (org.apache.pivot.wtk.FlowPane)12 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)11 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)10