Search in sources :

Example 1 with AlmondAction

use of se.trixon.almond.util.AlmondAction in project java-jotasync by trixon.

the class ActionManager method init.

public ActionManager init(ActionMap actionMap, InputMap inputMap) {
    mActionMap = actionMap;
    mInputMap = inputMap;
    AlmondAction action;
    KeyStroke keyStroke;
    int commandMask = SystemHelper.getCommandMask();
    initHelpAction("https://trixon.se/projects/jotasync/documentation/");
    if (mAlmondOptions.getMenuMode() == MenuModePanel.MenuMode.BUTTON) {
        // menu
        int menuKey = KeyEvent.VK_M;
        keyStroke = KeyStroke.getKeyStroke(menuKey, commandMask);
        action = new AlmondAction(Dict.MENU.toString()) {

            @Override
            public void actionPerformed(ActionEvent e) {
                mAppListeners.forEach((appActionListener) -> {
                    try {
                        appActionListener.onMenu(e);
                    } catch (Exception exception) {
                    }
                });
            }
        };
        initAction(action, MENU, keyStroke, MaterialIcon._Navigation.MENU, true);
        keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0);
        mInputMap.put(keyStroke, MENU);
    }
    // options
    keyStroke = KeyStroke.getKeyStroke(getOptionsKey(), commandMask);
    keyStroke = IS_MAC ? null : keyStroke;
    action = new AlmondAction(Dict.OPTIONS.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onOptions(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, OPTIONS, keyStroke, MaterialIcon._Action.SETTINGS, true);
    // start
    keyStroke = null;
    action = new AlmondAction(Dict.START.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onStart(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, START, keyStroke, MaterialIcon._Av.PLAY_ARROW, false);
    // cancel
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    action = new AlmondAction(Dict.CANCEL.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onCancel(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, CANCEL, keyStroke, MaterialIcon._Content.CLEAR, false);
    // save tab
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, commandMask);
    action = new AlmondAction(Dict.SAVE.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onSave(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, SAVE_TAB, keyStroke, MaterialIcon._Content.SAVE, false);
    // close tab
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_W, commandMask);
    action = new AlmondAction(Dict.TAB_CLOSE.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onClose(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, CLOSE_TAB, keyStroke, MaterialIcon._Navigation.CLOSE, false);
    // start Server
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_O, commandMask | InputEvent.SHIFT_MASK);
    action = new AlmondAction(Dict.START.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onServerStart(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, START_SERVER, keyStroke, null, true);
    // shutdown Server
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, commandMask | InputEvent.SHIFT_MASK);
    action = new AlmondAction(Dict.SHUTDOWN.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onServerShutdown(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, SHUTDOWN_SERVER, keyStroke, null, false);
    // shutdown server and quit
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Q, commandMask + InputEvent.SHIFT_MASK);
    action = new AlmondAction(Dict.SHUTDOWN_AND_QUIT.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onServerShutdownAndQuit(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, SHUTDOWN_SERVER_QUIT, keyStroke, null, false);
    // connect
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_O, commandMask);
    action = new AlmondAction(Dict.CONNECT_TO_SERVER.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onClientConnect(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, CONNECT, keyStroke, MaterialIcon._Communication.CALL_MADE, true);
    // disconnect
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, commandMask);
    action = new AlmondAction(Dict.DISCONNECT.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onClientDisconnect(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, DISCONNECT, keyStroke, MaterialIcon._Communication.CALL_RECEIVED, false);
    // cron
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_T, commandMask);
    action = new AlmondAction(mBundle.getString("schedule")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onCron(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, CRON, keyStroke, MaterialIcon._Action.SCHEDULE, false);
    action.putValue(Action.SELECTED_KEY, false);
    // jobEditor
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_J, commandMask);
    action = new AlmondAction(mBundle.getString("jobEditor")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appListener) -> {
                try {
                    appListener.onEdit(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, JOB_EDITOR, keyStroke, MaterialIcon._Editor.MODE_EDIT, false);
    // about rsync
    keyStroke = null;
    action = new AlmondAction(String.format(Dict.ABOUT_S.toString(), "rsync")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onAboutRsync(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, ABOUT_RSYNC, keyStroke, null, false);
    // quit
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Q, commandMask);
    action = new AlmondAction(Dict.QUIT.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onQuit(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, QUIT, keyStroke, MaterialIcon._Content.CLEAR, true);
    return this;
}
Also used : InputEvent(java.awt.event.InputEvent) KeyStroke(javax.swing.KeyStroke) MaterialIcon(se.trixon.almond.util.icons.material.MaterialIcon) Action(javax.swing.Action) MenuModePanel(se.trixon.almond.util.swing.dialogs.MenuModePanel) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) HashSet(java.util.HashSet) Dict(se.trixon.almond.util.Dict) ResourceBundle(java.util.ResourceBundle) AlmondActionManager(se.trixon.almond.util.AlmondActionManager) SystemHelper(se.trixon.almond.util.SystemHelper) AlmondAction(se.trixon.almond.util.AlmondAction) InputMap(javax.swing.InputMap) ActionMap(javax.swing.ActionMap) AlmondAction(se.trixon.almond.util.AlmondAction) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke)

Example 2 with AlmondAction

use of se.trixon.almond.util.AlmondAction in project java-jotasync by trixon.

the class MainFrame method initActions.

private void initActions() {
    mActionManager = ActionManager.getInstance().init(getRootPane().getActionMap(), getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW));
    // about
    PomInfo pomInfo = new PomInfo(MainFrame.class, "se.trixon", "jotasync");
    AboutModel aboutModel = new AboutModel(SystemHelper.getBundle(MainFrame.class, "about"), SystemHelper.getResourceAsImageIcon(MainFrame.class, "sync-256px.png"));
    aboutModel.setAppVersion(pomInfo.getVersion());
    AboutPanel aboutPanel = new AboutPanel(aboutModel);
    AlmondAction action = AboutPanel.getAction(MainFrame.this, aboutPanel);
    getRootPane().getActionMap().put(ActionManager.ABOUT, action);
    // File
    connectMenuItem.setAction(mActionManager.getAction(ActionManager.CONNECT));
    disconnectMenuItem.setAction(mActionManager.getAction(ActionManager.DISCONNECT));
    startServerMenuItem.setAction(mActionManager.getAction(ActionManager.START_SERVER));
    shutdownServerMenuItem.setAction(mActionManager.getAction(ActionManager.SHUTDOWN_SERVER));
    shutdownServerQuitMenuItem.setAction(mActionManager.getAction(ActionManager.SHUTDOWN_SERVER_QUIT));
    saveMenuItem.setAction(mActionManager.getAction(ActionManager.SAVE_TAB));
    quitMenuItem.setAction(mActionManager.getAction(ActionManager.QUIT));
    // Tools
    cronCheckBoxMenuItem.setAction(mActionManager.getAction(ActionManager.CRON));
    jobEditorMenuItem.setAction(mActionManager.getAction(ActionManager.JOB_EDITOR));
    optionsMenuItem.setAction(mActionManager.getAction(ActionManager.OPTIONS));
    // Help
    helpMenuItem.setAction(mActionManager.getAction(ActionManager.HELP));
    aboutMenuItem.setAction(mActionManager.getAction(ActionManager.ABOUT));
    aboutRsyncMenuItem.setAction(mActionManager.getAction(ActionManager.ABOUT_RSYNC));
}
Also used : PomInfo(se.trixon.almond.util.PomInfo) AlmondAction(se.trixon.almond.util.AlmondAction) AboutModel(se.trixon.almond.util.swing.dialogs.about.AboutModel) AboutPanel(se.trixon.almond.util.swing.dialogs.about.AboutPanel)

Example 3 with AlmondAction

use of se.trixon.almond.util.AlmondAction in project java-mapollage by trixon.

the class ActionManager method init.

public ActionManager init(ActionMap actionMap, InputMap inputMap) {
    mActionMap = actionMap;
    mInputMap = inputMap;
    AlmondAction action;
    KeyStroke keyStroke;
    int commandMask = SystemHelper.getCommandMask();
    initHelpAction("https://trixon.se/projects/mapollage/documentation/");
    initAboutDateFormatAction();
    if (mAlmondOptions.getMenuMode() == MenuModePanel.MenuMode.BUTTON) {
        // menu
        int menuKey = KeyEvent.VK_M;
        keyStroke = KeyStroke.getKeyStroke(menuKey, commandMask);
        action = new AlmondAction(Dict.MENU.toString()) {

            @Override
            public void actionPerformed(ActionEvent e) {
                mAppListeners.forEach((appActionListener) -> {
                    try {
                        appActionListener.onMenu(e);
                    } catch (Exception exception) {
                    }
                });
            }
        };
        initAction(action, MENU, keyStroke, MaterialIcon._Navigation.MENU, true);
        keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0);
        mInputMap.put(keyStroke, MENU);
    }
    // options
    keyStroke = KeyStroke.getKeyStroke(getOptionsKey(), commandMask);
    keyStroke = IS_MAC ? null : keyStroke;
    action = new AlmondAction(Dict.OPTIONS.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onOptions(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, OPTIONS, keyStroke, MaterialIcon._Action.SETTINGS, true);
    // start
    keyStroke = null;
    action = new AlmondAction(Dict.START.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onStart(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, START, keyStroke, MaterialIcon._Av.PLAY_ARROW, false);
    // cancel
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    action = new AlmondAction(Dict.CANCEL.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onCancel(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, CANCEL, keyStroke, MaterialIcon._Content.CLEAR, false);
    // add
    keyStroke = null;
    action = new AlmondAction(Dict.ADD.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mProfileListeners.forEach((profileListener) -> {
                try {
                    profileListener.onAdd(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, ADD, keyStroke, MaterialIcon._Content.ADD, true);
    // clone
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, commandMask + InputEvent.SHIFT_DOWN_MASK);
    action = new AlmondAction(Dict.CLONE.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mProfileListeners.forEach((profileListener) -> {
                try {
                    profileListener.onClone(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, CLONE, keyStroke, MaterialIcon._Content.CONTENT_COPY, false);
    // edit
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E, commandMask + InputEvent.SHIFT_DOWN_MASK);
    action = new AlmondAction(Dict.RENAME.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mProfileListeners.forEach((profileListener) -> {
                try {
                    profileListener.onEdit(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, RENAME, keyStroke, MaterialIcon._Editor.MODE_EDIT, false);
    // remove
    keyStroke = null;
    action = new AlmondAction(Dict.REMOVE.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mProfileListeners.forEach((profileListener) -> {
                try {
                    profileListener.onRemove(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, REMOVE, keyStroke, MaterialIcon._Content.REMOVE, false);
    // remove all
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK);
    action = new AlmondAction(Dict.REMOVE_ALL.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mProfileListeners.forEach((profileListener) -> {
                try {
                    profileListener.onRemoveAll(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, REMOVE_ALL, keyStroke, MaterialIcon._Content.CLEAR, false);
    // quit
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Q, commandMask);
    action = new AlmondAction(Dict.QUIT.toString()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            mAppListeners.forEach((appActionListener) -> {
                try {
                    appActionListener.onQuit(e);
                } catch (Exception exception) {
                }
            });
        }
    };
    initAction(action, QUIT, keyStroke, MaterialIcon._Content.CLEAR, true);
    return this;
}
Also used : InputEvent(java.awt.event.InputEvent) KeyStroke(javax.swing.KeyStroke) MaterialIcon(se.trixon.almond.util.icons.material.MaterialIcon) MenuModePanel(se.trixon.almond.util.swing.dialogs.MenuModePanel) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) HashSet(java.util.HashSet) Dict(se.trixon.almond.util.Dict) AlmondActionManager(se.trixon.almond.util.AlmondActionManager) SystemHelper(se.trixon.almond.util.SystemHelper) AlmondAction(se.trixon.almond.util.AlmondAction) InputMap(javax.swing.InputMap) ActionMap(javax.swing.ActionMap) AlmondAction(se.trixon.almond.util.AlmondAction) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke)

Aggregations

AlmondAction (se.trixon.almond.util.AlmondAction)3 ActionEvent (java.awt.event.ActionEvent)2 InputEvent (java.awt.event.InputEvent)2 KeyEvent (java.awt.event.KeyEvent)2 HashSet (java.util.HashSet)2 ActionMap (javax.swing.ActionMap)2 InputMap (javax.swing.InputMap)2 KeyStroke (javax.swing.KeyStroke)2 AlmondActionManager (se.trixon.almond.util.AlmondActionManager)2 Dict (se.trixon.almond.util.Dict)2 SystemHelper (se.trixon.almond.util.SystemHelper)2 MaterialIcon (se.trixon.almond.util.icons.material.MaterialIcon)2 MenuModePanel (se.trixon.almond.util.swing.dialogs.MenuModePanel)2 ResourceBundle (java.util.ResourceBundle)1 Action (javax.swing.Action)1 PomInfo (se.trixon.almond.util.PomInfo)1 AboutModel (se.trixon.almond.util.swing.dialogs.about.AboutModel)1 AboutPanel (se.trixon.almond.util.swing.dialogs.about.AboutPanel)1