Search in sources :

Example 41 with MenuItem

use of java.awt.MenuItem in project fql by CategoricalData.

the class GUI method makeGUI.

@SuppressWarnings({})
public static Pair<JPanel, MenuBar> makeGUI(JFrame frame) {
    topFrame = frame;
    MenuBar menuBar = new MenuBar();
    Menu fileMenu = makeFileMenu();
    Menu editMenu = makeEditMenu();
    Menu toolsMenu = makesToolsMenu();
    Menu helpMenu = new Menu("Help");
    MenuItem aboutItem = new MenuItem("Help/About");
    helpMenu.add(aboutItem);
    aboutItem.addActionListener(e -> IdeOptions.showAbout());
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(toolsMenu);
    Menu aqlMenu = populateAql();
    menuBar.add(aqlMenu);
    // Menu legacyMenu = new Menu("Legacy");
    Menu fqlMenu = new Menu("FQL");
    Menu fqlppMenu = new Menu("FQL++");
    Menu oplMenu = new Menu("OPL");
    Menu fpqlMenu = new Menu("FPQL");
    populateFql(fqlMenu);
    populateFqlpp(fqlppMenu);
    populateFpql(fpqlMenu);
    populateOpl(oplMenu);
    menuBar.add(fqlMenu);
    menuBar.add(fqlppMenu);
    menuBar.add(fpqlMenu);
    menuBar.add(oplMenu);
    menuBar.add(helpMenu);
    JPanel pan = new JPanel();
    pan.setLayout(new BorderLayout());
    JPanel toolBar = makeToolBar();
    pan.add(toolBar, BorderLayout.PAGE_START);
    pan.add(editors, BorderLayout.CENTER);
    return new Pair<>(pan, menuBar);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) MenuBar(java.awt.MenuBar) MenuItem(java.awt.MenuItem) Menu(java.awt.Menu) Pair(catdata.Pair)

Example 42 with MenuItem

use of java.awt.MenuItem in project fql by CategoricalData.

the class GUI method makeEditMenu.

private static Menu makeEditMenu() {
    Menu editMenu = new Menu("Edit");
    MenuItem findItem = new MenuItem("Find/Replace");
    editMenu.add(findItem);
    MenuItem gotoItem = new MenuItem("Goto Line");
    editMenu.add(gotoItem);
    MenuItem gotoDef = new MenuItem("Goto Definition");
    editMenu.add(gotoDef);
    KeyStroke ctrlShiftR = KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut fx = new MenuShortcut(ctrlShiftR.getKeyCode(), true);
    gotoDef.setShortcut(fx);
    gotoDef.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.showGotoDialog();
        }
    });
    KeyStroke ctrlF = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut f = new MenuShortcut(ctrlF.getKeyCode());
    findItem.setShortcut(f);
    MenuItem copy = new MenuItem("Copy");
    copy.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.topArea.copy();
        }
    });
    KeyStroke ctrlC = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut cc = new MenuShortcut(ctrlC.getKeyCode());
    copy.setShortcut(cc);
    editMenu.add(copy);
    MenuItem rtf = new MenuItem("Copy as RTF");
    editMenu.add(rtf);
    rtf.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.copyAsRtf();
        }
    });
    MenuItem cut = new MenuItem("Cut");
    cut.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.topArea.cut();
        }
    });
    KeyStroke ctrlX = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut cx = new MenuShortcut(ctrlX.getKeyCode());
    cut.setShortcut(cx);
    editMenu.add(cut);
    MenuItem paste = new MenuItem("Paste");
    cut.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.topArea.paste();
        }
    });
    KeyStroke ctrlV = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut cv = new MenuShortcut(ctrlV.getKeyCode());
    paste.setShortcut(cv);
    editMenu.add(paste);
    MenuItem undo = new MenuItem("Undo");
    undo.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.topArea.undoLastAction();
        }
    });
    KeyStroke ctrlZ = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut z = new MenuShortcut(ctrlZ.getKeyCode());
    undo.setShortcut(z);
    editMenu.add(undo);
    MenuItem redo = new MenuItem("Redo");
    redo.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.topArea.redoLastAction();
        }
    });
    KeyStroke ctrlShiftZ = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    MenuShortcut sz = new MenuShortcut(ctrlShiftZ.getKeyCode(), true);
    redo.setShortcut(sz);
    editMenu.add(redo);
    MenuItem back = new MenuItem("Back");
    back.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.backAction();
        }
    });
    editMenu.add(back);
    MenuItem fwd = new MenuItem("Forward");
    fwd.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.fwdAction();
        }
    });
    editMenu.add(fwd);
    MenuItem fall = new MenuItem("Fold All");
    editMenu.add(fall);
    fall.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.foldAll(true);
        }
    });
    MenuItem uall = new MenuItem("Unfold All");
    editMenu.add(uall);
    uall.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.foldAll(false);
        }
    });
    findItem.addActionListener(e -> {
        delay();
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.replaceAction();
        }
    });
    gotoItem.addActionListener(e -> {
        delay();
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.gotoLine();
        }
    });
    MenuItem clear = new MenuItem("Refresh Outline");
    editMenu.add(clear);
    clear.addActionListener(x -> {
        CodeEditor<?, ?, ?> ed = getSelectedEditor();
        if (ed != null) {
            ed.getOutline().build();
            ;
        }
    });
    return editMenu;
}
Also used : KeyStroke(javax.swing.KeyStroke) MenuItem(java.awt.MenuItem) Menu(java.awt.Menu) MenuShortcut(java.awt.MenuShortcut)

Example 43 with MenuItem

use of java.awt.MenuItem in project fql by CategoricalData.

the class GUI method populateFqlpp.

private static void populateFqlpp(Menu menu) {
    MenuItem kbItem = new MenuItem("FQL++ Knuth-Bendix");
    menu.add(kbItem);
    kbItem.addActionListener(x -> new KBViewer());
}
Also used : KBViewer(catdata.fqlpp.KBViewer) MenuItem(java.awt.MenuItem)

Example 44 with MenuItem

use of java.awt.MenuItem in project fql by CategoricalData.

the class GUI method populateAql.

private static Menu populateAql() {
    Menu menu = new Menu("AQL");
    MenuItem st = new MenuItem("Self-Test");
    st.addActionListener(x -> AqlTester.doSelfTests());
    menu.add(st);
    MenuItem im = new MenuItem("Infer Mapping (using last compiled)");
    im.addActionListener(x -> infer(Kind.MAPPING));
    menu.add(im);
    MenuItem iq = new MenuItem("Infer Query (using last compiled)");
    iq.addActionListener(x -> infer(Kind.QUERY));
    menu.add(iq);
    MenuItem it = new MenuItem("Infer Transform (using last compiled)");
    it.addActionListener(x -> infer(Kind.TRANSFORM));
    menu.add(it);
    MenuItem ii = new MenuItem("Infer Instance (using last compiled)");
    it.addActionListener(x -> infer(Kind.INSTANCE));
    menu.add(ii);
    MenuItem ih = new MenuItem("Emit HTML (using last compiled)");
    ih.addActionListener(x -> {
        CodeEditor<?, ?, ?> c = getSelectedEditor();
        if (c == null) {
            // TODO aql refact these actions that depend on selected editor
            return;
        }
        if (c instanceof AqlCodeEditor) {
            AqlCodeEditor a = (AqlCodeEditor) c;
            a.emitDoc();
        }
    });
    menu.add(ih);
    MenuItem formatItem = new MenuItem("Code Format");
    menu.add(formatItem);
    formatItem.addActionListener(x -> formatActionAql());
    return menu;
}
Also used : MenuItem(java.awt.MenuItem) Menu(java.awt.Menu) AqlCodeEditor(catdata.aql.gui.AqlCodeEditor)

Example 45 with MenuItem

use of java.awt.MenuItem in project bisq-desktop by bisq-network.

the class SystemTray method init.

private void init() {
    if (!java.awt.SystemTray.isSupported()) {
        log.error("System tray is not supported.");
        return;
    }
    // prevent exiting the app when the last window gets closed
    // For now we allow to close the app by closing the window.
    // Later we only let it close via the system trays exit.
    Platform.setImplicitExit(false);
    MenuItem aboutItem = new MenuItem(Res.get("systemTray.info"));
    MenuItem exitItem = new MenuItem(Res.get("systemTray.exit"));
    PopupMenu popupMenu = new PopupMenu();
    popupMenu.add(aboutItem);
    popupMenu.addSeparator();
    popupMenu.add(toggleShowHideItem);
    popupMenu.addSeparator();
    popupMenu.add(exitItem);
    String path;
    if (Utilities.isOSX())
        path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
    else if (Utilities.isWindows())
        path = ICON_WINDOWS;
    else
        path = ICON_LINUX;
    try {
        BufferedImage trayIconImage = ImageIO.read(getClass().getResource(path));
        TrayIcon trayIcon = new TrayIcon(trayIconImage);
        // On OSX we get the correct size from the provided image
        if (!Utilities.isOSX()) {
            int trayIconWidth = trayIcon.getSize().width;
            trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
        }
        trayIcon.setPopupMenu(popupMenu);
        trayIcon.setToolTip(Res.get("systemTray.tooltip"));
        java.awt.SystemTray.getSystemTray().add(trayIcon);
    } catch (AWTException e1) {
        log.error("Icon could not be added to system tray.", e1);
    } catch (IOException e2) {
        throw new BisqException(e2);
    }
    toggleShowHideItem.addActionListener(e -> {
        if (stage.isShowing()) {
            toggleShowHideItem.setLabel(SHOW_WINDOW_LABEL);
            UserThread.execute(stage::hide);
        } else {
            toggleShowHideItem.setLabel(HIDE_WINDOW_LABEL);
            UserThread.execute(stage::show);
        }
    });
    aboutItem.addActionListener(e -> {
        try {
            UserThread.execute(() -> GUIUtil.openWebPage("https://bisq.network"));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    });
    exitItem.addActionListener(e -> UserThread.execute(onExit::run));
}
Also used : TrayIcon(java.awt.TrayIcon) BisqException(bisq.core.exceptions.BisqException) MenuItem(java.awt.MenuItem) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) AWTException(java.awt.AWTException) BisqException(bisq.core.exceptions.BisqException) PopupMenu(java.awt.PopupMenu) AWTException(java.awt.AWTException)

Aggregations

MenuItem (java.awt.MenuItem)53 PopupMenu (java.awt.PopupMenu)24 Menu (java.awt.Menu)15 JMenuItem (javax.swing.JMenuItem)15 JPopupMenu (javax.swing.JPopupMenu)13 TrayIcon (java.awt.TrayIcon)12 AWTException (java.awt.AWTException)9 MenuShortcut (java.awt.MenuShortcut)9 ActionEvent (java.awt.event.ActionEvent)9 ActionListener (java.awt.event.ActionListener)9 CheckboxMenuItem (java.awt.CheckboxMenuItem)8 Image (java.awt.Image)8 SystemTray (java.awt.SystemTray)8 IOException (java.io.IOException)6 Dimension (java.awt.Dimension)5 File (java.io.File)4 BorderLayout (java.awt.BorderLayout)3 FileDialog (java.awt.FileDialog)3 URL (java.net.URL)3 SQLException (java.sql.SQLException)3