Search in sources :

Example 16 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class TableViewTest2 method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    System.out.println("Double Click on Table elements to open the Row Editor");
    window = (Window) bxmlSerializer.readObject(TableViewTest2.class, "table_view_test2.bxml");
    tableView = (TableView) bxmlSerializer.getNamespace().get("tableView");
    menu = (Window) bxmlSerializer.readObject(TableViewTest2.class, "context_menus.bxml");
    tableView.setMenuHandler(new ContextMenusSampleMenuHandlerAdapter());
    System.out.println("Right  Click on Table elements to display Contextual Menu: " + menu);
    TableViewRowEditor tableViewRowEditor = new TableViewRowEditor();
    tableViewRowEditor.setEditEffect(CardPaneSkin.SelectionChangeEffect.HORIZONTAL_SLIDE);
    tableView.setRowEditor(tableViewRowEditor);
    TextArea textArea = new TextArea();
    textArea.setTextKey("value");
    tableViewRowEditor.getCellEditors().put("value", textArea);
    window.open(display);
}
Also used : TableViewRowEditor(org.apache.pivot.wtk.content.TableViewRowEditor) TextArea(org.apache.pivot.wtk.TextArea) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 17 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class SwingDemo method createPivotFrame.

private static void createPivotFrame() {
    // Create the internal frame that will contain the Pivot components
    JInternalFrame internalFrame = new JInternalFrame("Pivot Components");
    desktop.add(internalFrame);
    // Create the display host
    ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();
    internalFrame.add(displayHost);
    // Add the display to the display list
    displays.add(displayHost.getDisplay());
    // Load the Pivot window
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Window window;
    try {
        window = (Window) bxmlSerializer.readObject(SwingDemo.class.getResource("pivot_window.bxml"));
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
    // Open the Pivot window on the display
    window.open(displayHost.getDisplay());
    // Open and select the internal frame
    internalFrame.setLocation(240, 100);
    internalFrame.setSize(480, 360);
    internalFrame.setVisible(true);
    internalFrame.setResizable(true);
    try {
        internalFrame.setSelected(true);
    } catch (PropertyVetoException exception) {
        throw new RuntimeException(exception);
    }
}
Also used : Window(org.apache.pivot.wtk.Window) PropertyVetoException(java.beans.PropertyVetoException) ApplicationContext(org.apache.pivot.wtk.ApplicationContext) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) JInternalFrame(javax.swing.JInternalFrame) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 18 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class TextPaneDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    System.out.println("startup(...)");
    System.out.println("\n" + "In this test application as a sample for setting the display scale on startup, use startup argument \"--scale=n\" property; \n" + "for instance, using \"--scale=2.0\" will set double scale on the whole application.\n" + "\n" + "Anyway, using Ctrl-Shift-MouseWheel will scale the display up and down as well, for the user of your application.\n");
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(TextPaneDemo.class, "text_pane_demo.bxml");
    bxmlSerializer.bind(this, TextPaneDemo.class);
    window.setTitle("Apache Pivot Rich Text Editor Demo");
    // make the text on the "bold" button bold
    Font boldButtonFont = boldButton.getStyles().getFont(Style.font);
    boldButton.getStyles().put(Style.font, boldButtonFont.deriveFont(Font.BOLD));
    // make the text on the "italic" button italic
    Font italicButtonFont = italicButton.getStyles().getFont(Style.font);
    italicButton.getStyles().put(Style.font, italicButtonFont.deriveFont(Font.ITALIC));
    fontFamilyListButton.setListData(new ArrayList<>(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()));
    fontSizeListButton.setSelectedItem(fontFamilyListButton.getListData().get(0));
    fontFamilyListButton.setItemRenderer(new ListViewItemRenderer() {

        @Override
        public void render(Object item, int index, ListView listView, boolean selected, Button.State state, boolean highlighted, boolean disabled) {
            super.render(item, index, listView, selected, state, highlighted, disabled);
            if (item != null) {
                String fontFamilyName = (String) item;
                label.getStyles().put(Style.font, Font.decode(fontFamilyName + "-12"));
            }
        }
    });
    fontFamilyListButton.setDataRenderer(new ListButtonDataRenderer() {

        @Override
        public void render(Object data, Button button, boolean highlight) {
            super.render(data, button, highlight);
            if (data != null) {
                String fontFamilyName = (String) data;
                label.getStyles().put(Style.font, Font.decode(fontFamilyName + "-12"));
            }
        }
    });
    fontSizeListButton.setListData(new NumericSpinnerData(12, 30, 1));
    fontSizeListButton.setSelectedItem(12);
    openFileButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
            fileBrowserSheet.setMode(FileBrowserSheet.Mode.OPEN);
            fileBrowserSheet.open(window, new SheetCloseListener() {

                @Override
                public void sheetClosed(Sheet sheet) {
                    if (sheet.getResult()) {
                        loadedFile = fileBrowserSheet.getSelectedFile();
                        try {
                            BufferedReader reader = new BufferedReader(new FileReader(loadedFile));
                            PlainTextSerializer serializer = new PlainTextSerializer();
                            textPane.setDocument(serializer.readObject(reader));
                            reader.close();
                            window.setTitle(loadedFile.getCanonicalPath());
                        } catch (IOException ex) {
                            ex.printStackTrace();
                            Alert.alert(ex.getMessage(), window);
                        }
                    }
                }
            });
        }
    });
    saveFileButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
            if (loadedFile != null) {
                fileBrowserSheet.setSelectedFile(loadedFile);
            }
            fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_AS);
            fileBrowserSheet.open(window, new SheetCloseListener() {

                @Override
                public void sheetClosed(Sheet sheet) {
                    if (sheet.getResult()) {
                        File selectedFile = fileBrowserSheet.getSelectedFile();
                        try {
                            FileWriter writer = new FileWriter(selectedFile);
                            PlainTextSerializer serializer = new PlainTextSerializer();
                            serializer.writeObject(textPane.getDocument(), writer);
                            writer.close();
                            loadedFile = selectedFile;
                            window.setTitle(loadedFile.getCanonicalPath());
                        } catch (IOException ex) {
                            ex.printStackTrace();
                            Alert.alert(ex.getMessage(), window);
                        }
                    }
                }
            });
        }
    });
    boldButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    if (span.getFont() != null) {
                        Font font = span.getFont();
                        if (font.getStyle() == Font.PLAIN) {
                            font = font.deriveFont(Font.BOLD);
                        } else if (font.getStyle() == Font.BOLD) {
                            font = font.deriveFont(Font.PLAIN);
                        } else {
                            // the font is BOLD+ITALIC
                            font = font.deriveFont(Font.ITALIC);
                        }
                        span.setFont(font);
                    } else {
                        span.setFont("Arial BOLD 12");
                    }
                }
            });
            requestTextPaneFocus();
        }
    });
    italicButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    if (span.getFont() != null) {
                        Font font = span.getFont();
                        if (font.getStyle() == Font.PLAIN) {
                            font = font.deriveFont(Font.ITALIC);
                        } else if (font.getStyle() == Font.ITALIC) {
                            font = font.deriveFont(Font.PLAIN);
                        } else {
                            // the font is BOLD+ITALIC
                            font = font.deriveFont(Font.BOLD);
                        }
                        span.setFont(font);
                    } else {
                        span.setFont("Arial ITALIC 12");
                    }
                }
            });
            requestTextPaneFocus();
        }
    });
    underlineButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    span.setUnderline(!span.isUnderline());
                }
            });
            requestTextPaneFocus();
        }
    });
    strikethroughButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    span.setStrikethrough(!span.isStrikethrough());
                }
            });
            requestTextPaneFocus();
        }
    });
    foregroundColorChooserButton.getColorChooserButtonSelectionListeners().add(new ColorChooserButtonSelectionListener() {

        @Override
        public void selectedColorChanged(ColorChooserButton colorChooserButton, Color previousSelectedColor) {
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    span.setForegroundColor(foregroundColorChooserButton.getSelectedColor());
                }
            });
            requestTextPaneFocus();
        }
    });
    backgroundColorChooserButton.getColorChooserButtonSelectionListeners().add(new ColorChooserButtonSelectionListener() {

        @Override
        public void selectedColorChanged(ColorChooserButton colorChooserButton, Color previousSelectedColor) {
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    span.setBackgroundColor(backgroundColorChooserButton.getSelectedColor());
                }
            });
            requestTextPaneFocus();
        }
    });
    ListButtonSelectionListener fontButtonPressListener = new ListButtonSelectionListener() {

        @Override
        public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
            int selectedFontSize = ((Integer) fontSizeListButton.getSelectedItem()).intValue();
            String selectedFontFamily = (String) fontFamilyListButton.getSelectedItem();
            final Font derivedFont = Font.decode(selectedFontFamily + " " + selectedFontSize);
            applyStyleToSelection(new StyleApplicator() {

                @Override
                public void apply(TextSpan span) {
                    span.setFont(derivedFont);
                }
            });
            requestTextPaneFocus();
        }
    };
    fontFamilyListButton.getListButtonSelectionListeners().add(fontButtonPressListener);
    fontSizeListButton.getListButtonSelectionListeners().add(fontButtonPressListener);
    wrapTextCheckbox.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            textPane.getStyles().put(Style.wrapText, wrapTextCheckbox.isSelected());
            requestTextPaneFocus();
        }
    });
    alignLeftButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyAlignmentStyle(HorizontalAlignment.LEFT);
            requestTextPaneFocus();
        }
    });
    alignCentreButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyAlignmentStyle(HorizontalAlignment.CENTER);
            requestTextPaneFocus();
        }
    });
    alignRightButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            applyAlignmentStyle(HorizontalAlignment.RIGHT);
            requestTextPaneFocus();
        }
    });
    String scaleProperty = properties.get("scale");
    if (scaleProperty != null && !scaleProperty.isEmpty()) {
        try {
            double scaleFactor = Double.parseDouble(scaleProperty);
            System.out.println("Got scaling factor \"" + scaleProperty + "\" from command line arguments, now applying to display");
            display.getDisplayHost().setScale(scaleFactor);
        } catch (NumberFormatException nfe) {
            System.err.println("(NumberFormatException: " + nfe.getMessage());
        }
    }
    window.open(display);
    requestTextPaneFocus();
}
Also used : ListViewItemRenderer(org.apache.pivot.wtk.content.ListViewItemRenderer) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) ListButtonDataRenderer(org.apache.pivot.wtk.content.ListButtonDataRenderer) FileWriter(java.io.FileWriter) NumericSpinnerData(org.apache.pivot.wtk.content.NumericSpinnerData) Font(java.awt.Font) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ListView(org.apache.pivot.wtk.ListView) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) FileReader(java.io.FileReader) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) PlainTextSerializer(org.apache.pivot.wtk.text.PlainTextSerializer) Color(java.awt.Color) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) IOException(java.io.IOException) TextSpan(org.apache.pivot.wtk.text.TextSpan) ListButton(org.apache.pivot.wtk.ListButton) ColorChooserButtonSelectionListener(org.apache.pivot.wtk.ColorChooserButtonSelectionListener) BufferedReader(java.io.BufferedReader) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File)

Example 19 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class XMLViewer method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    bxmlSerializer.getNamespace().put(APPLICATION_KEY, this);
    window = (Window) bxmlSerializer.readObject(XMLViewer.class, "xml_viewer.bxml");
    bxmlSerializer.bind(this);
    Label prompt = new Label("Drag or paste XML here");
    prompt.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    prompt.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    promptDecorator.setOverlay(prompt);
    treeView.getDecorators().add(promptDecorator);
    window.setTitle(WINDOW_TITLE);
    window.open(display);
    window.requestFocus();
    if (System.in.available() > 0) {
        XMLSerializer xmlSerializer = new XMLSerializer();
        try {
            setDocument(xmlSerializer.readObject(System.in));
        } catch (Exception exception) {
        // No-op
        }
    }
}
Also used : BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) XMLSerializer(org.apache.pivot.xml.XMLSerializer) Label(org.apache.pivot.wtk.Label) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) IOException(java.io.IOException)

Example 20 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class ScaleDecoratorDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    scaleWindow = (Window) bxmlSerializer.readObject(DecoratorDemo.class, "scale_window.bxml");
    bxmlSerializer.bind(this);
    imageView.getComponentMouseWheelListeners().add(new ComponentMouseWheelListener() {

        @Override
        public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) {
            // Note: both scale values are the same
            float currentScale = scaleDecorator.getScaleX();
            if (wheelRotation < 0) {
                // UP == zoom in, make scale larger
                scaleDecorator.setScale(currentScale * 2.0f);
            } else {
                // DOWN == zoom out, make scale smaller
                scaleDecorator.setScale(currentScale / 2.0f);
            }
            component.repaint();
            return true;
        }
    });
    scaleWindow.open(display);
}
Also used : Mouse(org.apache.pivot.wtk.Mouse) ComponentMouseWheelListener(org.apache.pivot.wtk.ComponentMouseWheelListener) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)86 Component (org.apache.pivot.wtk.Component)24 IOException (java.io.IOException)19 SerializationException (org.apache.pivot.serialization.SerializationException)14 Window (org.apache.pivot.wtk.Window)13 Button (org.apache.pivot.wtk.Button)11 PushButton (org.apache.pivot.wtk.PushButton)11 File (java.io.File)9 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)9 Frame (org.apache.pivot.wtk.Frame)8 TextInput (org.apache.pivot.wtk.TextInput)8 ArrayList (org.apache.pivot.collections.ArrayList)7 List (org.apache.pivot.collections.List)7 Mouse (org.apache.pivot.wtk.Mouse)6 Sequence (org.apache.pivot.collections.Sequence)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5 ListButton (org.apache.pivot.wtk.ListButton)5 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)5 URL (java.net.URL)4 MalformedURLException (java.net.MalformedURLException)3