Package org.apache.pivot.beans

Examples of org.apache.pivot.beans.BXMLSerializer$AttributeInvocationHandler


public class Pivot738 extends Application.Adapter {
    private Window window = null;

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = (Window) bxmlSerializer.readObject(Pivot734.class, "pivot_738.bxml");
        window.setMaximized(true);
        window.setWidth(400);
        window.setHeight(250);
        window.open(display);
    }
View Full Code Here


        Action.NamedActionDictionary namedActions = Action.getNamedActions();

        namedActions.put("configureCell", new Action() {
            @Override
            public void perform(Component source) {
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                Sheet sheet;

                // Make the cell component available to script blocks
                int rowIndex = tablePane.getRowAt(contextMenuHandler.getY());
                int columnIndex = tablePane.getColumnAt(contextMenuHandler.getX());
                Component component = tablePane.getCellComponent(rowIndex, columnIndex);
                bxmlSerializer.getNamespace().put("component", component);

                try {
                    sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
                        "table_panes_configure_cell.bxml");
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }

                sheet.open(TablePanes.this);
            }
        });

        namedActions.put("configureRow", new Action() {
            @Override
            public void perform(Component source) {
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                Sheet sheet;

                // Make the selected row available to script blocks
                int rowIndex = tablePane.getRowAt(contextMenuHandler.getY());
                TablePane.Row row = tablePane.getRows().get(rowIndex);
                bxmlSerializer.getNamespace().put("row", row);

                try {
                    sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
                        "table_panes_configure_row.bxml");
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }

                sheet.open(TablePanes.this);
            }
        });

        namedActions.put("insertRow", new Action() {
            @Override
            public void perform(Component source) {
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                Sheet sheet;

                // Create and insert a new row
                TablePane.Row row = new TablePane.Row();
                int rowIndex = tablePane.getRowAt(contextMenuHandler.getY());
                tablePane.getRows().insert(row, rowIndex);

                // Populate the row with the expected content
                row.add(new Label("-1"));
                for (int i = 1, n = tablePane.getColumns().getLength(); i < n; i++) {
                    Panel panel = new Panel();
                    panel.getStyles().put("backgroundColor", "#dddcd5");
                    row.add(panel);
                }

                // Make the new row available to script blocks
                bxmlSerializer.getNamespace().put("row", row);

                try {
                    sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
                        "table_panes_configure_row.bxml");
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }

                sheet.open(TablePanes.this);
            }
        });

        namedActions.put("removeRow", new Action() {
            @Override
            public void perform(Component source) {
                ArrayList<String> options = new ArrayList<String>("OK", "Cancel");
                String message = "Remove Row?";
                Label body = new Label("Are you sure you want to remove the row?");
                body.getStyles().put("wrapText", true);

                final Prompt prompt = new Prompt(MessageType.QUESTION, message, options, body);
                prompt.setSelectedOptionIndex(0);

                prompt.open(TablePanes.this, new SheetCloseListener() {
                    @Override
                    public void sheetClosed(Sheet sheet) {
                        if (prompt.getResult() && prompt.getSelectedOptionIndex() == 0) {
                            int rowIndex = tablePane.getRowAt(contextMenuHandler.getY());
                            tablePane.getRows().remove(rowIndex, 1);
                        }
                    }
                });
            }
        });

        namedActions.put("configureColumn", new Action() {
            @Override
            public void perform(Component source) {
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                Sheet sheet;

                // Make the selected column available to script blocks
                int columnIndex = tablePane.getColumnAt(contextMenuHandler.getX());
                TablePane.Column column = tablePane.getColumns().get(columnIndex);
                bxmlSerializer.getNamespace().put("column", column);

                try {
                    sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
                        "table_panes_configure_column.bxml");
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }

                sheet.open(TablePanes.this);
            }
        });

        namedActions.put("insertColumn", new Action() {
            @Override
            public void perform(Component source) {
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                Sheet sheet;

                // Create and insert a new column
                TablePane.Column column = new TablePane.Column();
                int columnIndex = tablePane.getColumnAt(contextMenuHandler.getX());
                tablePane.getColumns().insert(column, columnIndex);

                // Populate the column with the expected content
                TablePane.RowSequence rows = tablePane.getRows();
                rows.get(0).insert(new Label("-1"), columnIndex);
                for (int i = 1, n = rows.getLength(); i < n; i++) {
                    Panel panel = new Panel();
                    panel.getStyles().put("backgroundColor", "#dddcd5");
                    rows.get(i).insert(panel, columnIndex);
                }

                // Make the new column available to script blocks
                bxmlSerializer.getNamespace().put("column", column);

                try {
                    sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
                        "table_panes_configure_column.bxml");
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
View Full Code Here

        // StringBuffer sb = new StringBuffer();
        // Formatter formatter = new Formatter(sb, locale);
        // String customDecimalFormat = "%,.3f";
        //

        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = new Window((Component)bxmlSerializer.readObject(
            getClass().getResource("text_input_validator_test.bxml")));

        textinputLocale = (TextInput)bxmlSerializer.getNamespace().get("textinputLocale");

        textinputComparableBigDecimal = (TextInput)bxmlSerializer.getNamespace().get("textinputComparableBigDecimal");
        textinputComparableRange = (TextInput)bxmlSerializer.getNamespace().get("textinputComparableRange");
        textinputDouble = (TextInput)bxmlSerializer.getNamespace().get("textinputDouble");
        textinputFloat = (TextInput)bxmlSerializer.getNamespace().get("textinputFloat");
        textinputFloatRange = (TextInput)bxmlSerializer.getNamespace().get("textinputFloatRange");
        textinputIntRange = (TextInput)bxmlSerializer.getNamespace().get("textinputIntRange");
        textinputDateRegex = (TextInput)bxmlSerializer.getNamespace().get("textinputDateRegex");
        textinputCustomBoolean = (TextInput)bxmlSerializer.getNamespace().get("textinputCustomBoolean");
        textinputNotEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputNotEmptyText");
        textinputEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputEmptyText");

        textinputLocale.setText(locale.toString());

        String testValue = "123456789.0";
        // new, validate a value but using BigDecimalValidator (subclass of ComparableValidator)
        textinputComparableBigDecimal.setText("1e300")// huge value, and outside double range ...
        BigDecimalValidator bdComp = new BigDecimalValidator();
        System.out.println("BigDecimalValidator: created instance with value: " + bdComp);
        bdComp.setAutoTrim(true)// enable auto-trim of input string, before validating
        System.out.println("BigDecimalValidator: enable auto-trim of input string, before validating");
        textinputComparableBigDecimal.setValidator(bdComp);

        // new, validate in a range but using ComparableRangeValidator
        textinputComparableRange.setText(nf.format(new BigDecimal(testValue)));
        ComparableRangeValidator<BigDecimal> bdCompRange = new ComparableRangeValidator<BigDecimal>(
            new BigDecimal("2.0"), new BigDecimal("123456789")
        );
        System.out.println("ComparableRangeValidator: created instance with value: " + bdCompRange);
        bdCompRange.setAutoTrim(true)// enable auto-trim of input string, before validating
        System.out.println("ComparableRangeValidator: enable auto-trim of input string, before validating");
        textinputComparableRange.setValidator(bdCompRange);
        textinputComparableRange.getTextInputListeners().add(new TextInputListener.Adapter() {
            @Override
            public void textValidChanged(TextInput textInput) {
                invalidComparableRangeLabel.setText(textInput.isTextValid() ? "valid" : "invalid");
            }
        });
        invalidComparableRangeLabel = (Label)bxmlSerializer.getNamespace().get("invalidComparableRangeLabel");

        textinputDouble.setText("\u221E")// infinite symbol
        textinputDouble.setValidator(new DoubleValidator());

        // textinputFloat.setText("123456.789");
        // new, show different ways to format decimal values in i18n format
        Double value = new Double(testValue);
        // textinputFloat.setText(value.toString());
        // textinputFloat.setText(String.format(customDecimalFormat, value)); // sample using String.format
        // formatter.format(customDecimalFormat, value);                      // sample using Formatter
        // textinputFloat.setText(sb.toString());                             // sample using Formatter
        // textinputFloat.setText(nf.format(value));                          // sample using NumberFormat
        // textinputFloat.setText(df.format(value));                          // sample using DecimalFormat
        textinputFloat.setText(nf.format(value))// using this as a sample
        textinputFloat.setValidator(new FloatValidator());

        // standard float range model
        // note that float approximations could give errors,
        // try to increment/decrement the initial value near a range end, to see problems ...
        textinputFloatRange.setText(nf.format(new Float(testValue)));
        textinputFloatRange.setValidator(new FloatRangeValidator(2.0f, 123456789f));

        // test the listener by updating a label
        textinputFloatRange.getTextInputListeners().add(new TextInputListener.Adapter() {
            @Override
            public void textValidChanged(TextInput textInput) {
                invalidLabel.setText(textInput.isTextValid() ? "valid" : "invalid");
            }
        });

        invalidLabel = (Label)bxmlSerializer.getNamespace().get("invalidLabel");

        // standard int range model
        textinputIntRange.setText("0");
        textinputIntRange.setValidator(new IntRangeValidator(0, 100));
View Full Code Here

    public BXMLExplorerWindow() {
        Action.getNamedActions().put("fileNew", new Action() {
            @Override
            public void perform(Component source) {
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                bxmlSerializer.getNamespace().put("menuHandler", menuHandler);

                Component tab;
                try {
                    tab = (BXMLExplorerDocument) bxmlSerializer.readObject(
                        BXMLExplorerWindow.class, "bxml_explorer_document.bxml");
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                }

                tabPane.getTabs().add(tab);
                TabPane.setTabData(tab, "New File " + tabPane.getTabs().getLength());
                tabPane.setSelectedIndex(tabPane.getTabs().getLength() - 1);
                closeButton.setEnabled(true);
            }
        });

        Action.getNamedActions().put("fileOpen", new Action() {
            @Override
            public void perform(Component source) {
                fileBrowserSheet.open(BXMLExplorerWindow.this, new SheetCloseListener() {
                    @Override
                    public void sheetClosed(Sheet sheet) {
                        if (!sheet.getResult()) {
                            return;
                        }
                        File f = fileBrowserSheet.getSelectedFile();

                        // if we have already loaded the file, select the appropriate tab and return
                        int idx = 0;
                        for (Component comp : tabPane.getTabs()) {
                            if (f.equals(((BXMLExplorerDocument) comp).getLoadedFile())) {
                                tabPane.setSelectedIndex(idx);
                                return;
                            }
                            idx++;
                        }

                        BXMLSerializer bxmlSerializer = new BXMLSerializer();
                        bxmlSerializer.getNamespace().put("menuHandler", menuHandler);

                        Component tab;
                        try {
                            BXMLExplorerDocument explorerDoc = (BXMLExplorerDocument) bxmlSerializer.readObject(
                                BXMLExplorerWindow.class, "bxml_explorer_document.bxml");
                            explorerDoc.load(f);
                            tab = explorerDoc;
                        } catch (RuntimeException exception) {
                            exception.printStackTrace();
View Full Code Here

                        sourceTextArea.setText(url);
                    } catch (IOException exception) {
                        throw new RuntimeException(exception);
                    }

                    BXMLSerializer bxmlSerializer = new BXMLSerializer();
                    try {
                        component = (Component)bxmlSerializer.readObject(url);
                    } catch (IOException exception) {
                        throw new RuntimeException(exception);
                    } catch (SerializationException exception) {
                        throw new RuntimeException(exception);
                    }
View Full Code Here

public class ResolveTest extends Application.Adapter {
    private Window window = null;

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = (Window)bxmlSerializer.readObject(ResolveTest.class, "resolve_test.bxml", true);
        window.open(display);
    }
View Full Code Here

    public static final String CLASS_PROPERTY = "class";

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = (ComponentExplorerWindow)bxmlSerializer.readObject(ComponentExplorer.class,
            "component_explorer_window.bxml", true);
        window.setClassProperty(properties.get(CLASS_PROPERTY));
        window.open(display);
    }
View Full Code Here

    public File getLoadedFile() {
        return file;
    }

    public void load(File f) throws IOException, SerializationException, ParserConfigurationException, SAXException {
        BXMLSerializer serializer = new BXMLSerializer();
        serializer.setLocation(f.toURI().toURL());
        final FileInputStream in = new FileInputStream(f);
        try {
            Object obj = serializer.readObject(in);
            if (!(obj instanceof Component)) {
                throw new IllegalStateException("obj " + obj + " is of class " + obj.getClass()
                    + " which is not a subtype of Component");
            }
            // create an inverse map so we can IDs for widgets
            widgetToID = new HashMap<Object, String>();
            for (String key : serializer.getNamespace()) {
                widgetToID.put(serializer.getNamespace().get(key), key);
            }
            // we can't add a Window into the component hierarchy, so fake it
            if (obj instanceof Window) {
                obj = new FakeWindow((Window) obj);
            }
View Full Code Here

    private BXMLExplorerWindow window = null;


    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = (BXMLExplorerWindow)bxmlSerializer.readObject(BXMLExplorer.class,
            "bxml_explorer_window.bxml", true);
        window.open(display);
    }
View Full Code Here

    @BXML private Menu.Section helpSection;
    @BXML private Menu.Section hoursSection;

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = (Window)bxmlSerializer.readObject(ContextMenuTest.class,
            "context_menu_test.bxml");
        bxmlSerializer.bind(this, ContextMenuTest.class);

        window.setMenuHandler(new MenuHandler.Adapter() {
            @Override
            public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
                menu.getSections().add(globalSection);
View Full Code Here

TOP

Related Classes of org.apache.pivot.beans.BXMLSerializer$AttributeInvocationHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.