Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.Action


        private ButtonGroup imageMenuGroup = null;

        @Override
        public Vote previewExpandedChange(Rollup rollup) {
            if (component == null) {
                Action.getNamedActions().put("selectImageAction", new Action() {
                    @Override
                    public String getDescription() {
                        return "Select Image Action";
                    }
View Full Code Here


            Action.getNamedActions().get("copy").setEnabled(textInput.getSelectionLength() > 0);
        }
    };

    public MenuBars() {
        Action.getNamedActions().put("fileNew", new Action() {
            @Override
            public void perform() {
                WTKXSerializer wtkxSerializer = new WTKXSerializer();
                Component tab;
                try {
                    tab = new Border((Component)wtkxSerializer.readObject(this, "document.wtkx"));

                    TextInput textInput1 = (TextInput)wtkxSerializer.get("textInput1");
                    textInput1.setMenuHandler(menuHandler);

                    TextInput textInput2 = (TextInput)wtkxSerializer.get("textInput2");
                    textInput2.setMenuHandler(menuHandler);

                    PushButton pushButton = (PushButton)wtkxSerializer.get("pushButton");
                    pushButton.setMenuHandler(menuHandler);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                }

                tabPane.getTabs().add(tab);
                TabPane.setLabel(tab, "Document " + tabPane.getTabs().getLength());
                tabPane.setSelectedIndex(tabPane.getTabs().getLength() - 1);
            }
        });

        Action.getNamedActions().put("fileOpen", new Action() {
            @Override
            public void perform() {
                fileBrowserSheet.open(window);
            }
        });

        Action.getNamedActions().put("cut", new Action(false) {
            @Override
            public void perform() {
                TextInput textInput = (TextInput)window.getFocusDescendant();
                textInput.cut();
            }
        });

        Action.getNamedActions().put("copy", new Action(false) {
            @Override
            public void perform() {
                TextInput textInput = (TextInput)window.getFocusDescendant();
                textInput.copy();
            }
        });

        Action.getNamedActions().put("paste", new Action(false) {
            @Override
            public void perform() {
                TextInput textInput = (TextInput)window.getFocusDescendant();
                textInput.paste();
            }
View Full Code Here

            Action.getNamedActions().get("copy").setEnabled(textInput.getSelectionLength() > 0);
        }
    };

    public MenuBars() {
        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 = new Border((Component)bxmlSerializer.readObject(MenuBars.class, "document.bxml"));
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                }

                tabPane.getTabs().add(tab);
                TabPane.setTabData(tab, "Document " + tabPane.getTabs().getLength());
                tabPane.setSelectedIndex(tabPane.getTabs().getLength() - 1);
            }
        });

        Action.getNamedActions().put("fileOpen", new Action() {
            @Override
            public void perform(Component source) {
                fileBrowserSheet.open(MenuBars.this);
            }
        });

        Action.getNamedActions().put("cut", new Action(false) {
            @Override
            public void perform(Component source) {
                TextInput textInput = (TextInput)MenuBars.this.getFocusDescendant();
                textInput.cut();
            }
        });

        Action.getNamedActions().put("copy", new Action(false) {
            @Override
            public void perform(Component source) {
                TextInput textInput = (TextInput)MenuBars.this.getFocusDescendant();
                textInput.copy();
            }
        });

        Action.getNamedActions().put("paste", new Action(false) {
            @Override
            public void perform(Component source) {
                TextInput textInput = (TextInput)MenuBars.this.getFocusDescendant();
                textInput.paste();
            }
View Full Code Here

    @Override
    public void initialize(Map<String, Object> arg0, URL arg1, Resources arg2) {
        System.out.println("LeakTestWindow initialize(...)\n");

        button.setAction(new Action() {
            @Override
            public void perform(Component component) {
                dialogTest++;
                System.out.println("Dialog test number " + dialogTest + " at " + new Date());
                TestDialog dialog = TestDialog.create();
View Full Code Here

    private ContextMenuHandler contextMenuHandler = new ContextMenuHandler();

    public TablePanes() {
        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);
                }

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

        namedActions.put("removeColumn", new Action() {
            @Override
            public void perform(Component source) {
                ArrayList<String> options = new ArrayList<String>("OK", "Cancel");
                String message = "Remove Column?";
                Label body = new Label("Are you sure you want to remove the column?");
View Full Code Here

        Menu.Item doNothingMenuItem = new Menu.Item("Do Nothing and disabled");
        doNothingMenuItem.setEnabled(false);
        menuSection.add(doNothingMenuItem);

        Menu.Item whatIsThisMenuItem = new Menu.Item("What is this?");
        whatIsThisMenuItem.setAction(new Action() {
            @Override
            public void perform(Component source) {
                String description = (descendant != null) ? (String)descendant.getUserData().get("description") : "empty";
                String message = "This is a " + description + " description.";

                System.out.println("perform: " + message);
            }
        });
        menuSection.add(whatIsThisMenuItem);

        Menu.Item nullActionMenuItem = new Menu.Item("Item with null action");
        nullActionMenuItem.setAction((Action) null);
        menuSection.add(nullActionMenuItem);

        Menu.Item disabledActionMenuItem = new Menu.Item("Item with disabled action");
        disabledActionMenuItem.setAction(new Action() {
            @Override
            public void perform(Component source) {
                System.out.println("in perform");
            }
        });
View Full Code Here

        }

        @Override
        public Vote previewExpandedChange(Rollup rollup) {
            if (this.component == null) {
                Action.getNamedActions().put("selectImageAction", new Action() {
                    @Override
                    public String getDescription() {
                        return "Select Image Action";
                    }
View Full Code Here

            Action.getNamedActions().get("copy").setEnabled(textInput.getSelectionLength() > 0);
        }
    };

    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();
                            BXMLExplorer.displayLoadException(exception, BXMLExplorerWindow.this);
                            return;
                        } catch (IOException exception) {
                            exception.printStackTrace();
                            BXMLExplorer.displayLoadException(exception, BXMLExplorerWindow.this);
                            return;
                        } catch (SerializationException exception) {
                            exception.printStackTrace();
                            BXMLExplorer.displayLoadException(exception, BXMLExplorerWindow.this);
                            return;
                        } catch (ParserConfigurationException exception) {
                            exception.printStackTrace();
                            BXMLExplorer.displayLoadException(exception, BXMLExplorerWindow.this);
                            return;
                        } catch (SAXException exception) {
                            exception.printStackTrace();
                            BXMLExplorer.displayLoadException(exception, BXMLExplorerWindow.this);
                            return;
                        }

                        tabPane.getTabs().add(tab);
                        TabPane.setTabData(tab, f.getName());
                        tabPane.setSelectedIndex(tabPane.getTabs().getLength() - 1);
                        closeButton.setEnabled(true);
                    }
                });

            }
        });

        Action.getNamedActions().put("cut", new Action(false) {
            @Override
            public void perform(Component source) {
                TextInput textInput = (TextInput) BXMLExplorerWindow.this.getFocusDescendant();
                textInput.cut();
            }
        });

        Action.getNamedActions().put("copy", new Action(false) {
            @Override
            public void perform(Component source) {
                TextInput textInput = (TextInput) BXMLExplorerWindow.this.getFocusDescendant();
                textInput.copy();
            }
        });

        Action.getNamedActions().put("paste", new Action(false) {
            @Override
            public void perform(Component source) {
                TextInput textInput = (TextInput) BXMLExplorerWindow.this.getFocusDescendant();
                textInput.paste();
            }
View Full Code Here

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

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        Action.getNamedActions().put("action1", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert(MessageType.INFO, "Action 1 performed.", window);
            }
        });

        Action.getNamedActions().put("action2", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert(MessageType.INFO, "Action 2 performed.", window);
            }
        });
View Full Code Here

    private Frame frame = null;
    private Spinner spinner = null;

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        Action action = new Action() {
            @Override
            public String getDescription() {
                return null;
            }
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.Action

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.