Search in sources :

Example 31 with MenuItem

use of java.awt.MenuItem in project screenbird by adamhub.

the class ScreenRecorder method createTray.

/**
     * Sets up the system tray for screenRecorder application
     */
private void createTray() {
    PopupMenu menu = new PopupMenu();
    MenuItem aboutItem = new MenuItem("About");
    aboutItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfRecorderPanel, String.format("Screenbird%nBuild Version %s", RecorderPanel.resources.getString("BUILD")));
        }
    });
    menu.add(aboutItem);
    // Open the settings menu
    MenuItem settingsItem = new MenuItem("Preferences");
    settingsItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (jpRecorderPanel.isRecorderConfigSate())
                jpRecorderPanel.showSettingsForm();
        }
    });
    menu.add(settingsItem);
    // Hide or show the recorder 
    MenuItem messageItem = new MenuItem("Hide/Show");
    messageItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (jfRecorderPanel.getState() == JFrame.NORMAL) {
                jfRecorderPanel.setState(JFrame.ICONIFIED);
            } else {
                jfRecorderPanel.setState(JFrame.NORMAL);
            }
        }
    });
    menu.add(messageItem);
    MenuItem closeItem = new MenuItem("Quit/Exit");
    closeItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            destroy();
        }
    });
    menu.add(closeItem);
    // Loads the pastevid logo
    Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_16));
    if (!MediaUtil.osIsWindows()) {
        icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_24));
    }
    // Assigns the pastevid logo
    TrayIcon tray = new TrayIcon(icon, "Screenbird", menu);
    try {
        SystemTray.getSystemTray().add(tray);
    } catch (AWTException ex) {
        log(ex);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) ActionEvent(java.awt.event.ActionEvent) MenuItem(java.awt.MenuItem) Image(java.awt.Image) PopupMenu(java.awt.PopupMenu) AWTException(java.awt.AWTException)

Example 32 with MenuItem

use of java.awt.MenuItem in project voltdb by VoltDB.

the class DatabaseManager method main.

public void main() {
    fMain = new Frame("HSQL Database Manager");
    imgEmpty = createImage(new MemoryImageSource(2, 2, new int[4 * 4], 2, 2));
    fMain.setIconImage(imgEmpty);
    fMain.addWindowListener(this);
    MenuBar bar = new MenuBar();
    // used shortcuts: CERGTSIUDOLM
    String[] fitems = { "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "-Save Result csv...", "--", "-Exit" };
    addMenu(bar, "File", fitems);
    String[] vitems = { "RRefresh Tree", "--", "GResults in Grid", "TResults in Text", "--", "1Shrink Tree", "2Enlarge Tree", "3Shrink Command", "4Enlarge Command" };
    addMenu(bar, "View", vitems);
    String[] sitems = { "SSELECT", "IINSERT", "UUPDATE", "DDELETE", "--", "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "-CHECKPOINT", "-SCRIPT", "-SET", "-SHUTDOWN", "--", "-Test Script" };
    addMenu(bar, "Command", sitems);
    Menu recent = new Menu("Recent");
    mRecent = new Menu("Recent");
    bar.add(mRecent);
    String[] soptions = { "-AutoCommit on", "-AutoCommit off", "OCommit", "LRollback", "--", "-Disable MaxRows", "-Set MaxRows to 100", "--", "-Logging on", "-Logging off", "--", "-Insert test data" };
    addMenu(bar, "Options", soptions);
    String[] stools = { "-Dump", "-Restore", "-Transfer" };
    addMenu(bar, "Tools", stools);
    Menu hMenu = new Menu("Help");
    MenuItem aItem = new MenuItem("About");
    aItem.setShortcut(new MenuShortcut('A'));
    aItem.addActionListener(this);
    hMenu.add(aItem);
    MenuItem hItem = new MenuItem("Help");
    hItem.setShortcut(new MenuShortcut('H'));
    hItem.addActionListener(this);
    hMenu.add(hItem);
    //bar.add(hMenu);
    // Command above disabled only until a help display bug is fixed.
    fMain.setMenuBar(bar);
    fMain.setSize(640, 480);
    fMain.add("Center", this);
    initGUI();
    sRecent = new String[iMaxRecent];
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();
    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
        fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {
        fMain.setLocation(0, 0);
        fMain.setSize(d);
    }
    fMain.show();
    // (ulrivo): load query from command line
    if (defScript != null) {
        if (defDirectory != null) {
            defScript = defDirectory + File.separator + defScript;
        }
        txtCommand.setText(DatabaseManagerCommon.readFile(defScript));
    }
    txtCommand.requestFocus();
}
Also used : Frame(java.awt.Frame) MenuBar(java.awt.MenuBar) MenuItem(java.awt.MenuItem) Menu(java.awt.Menu) MenuShortcut(java.awt.MenuShortcut) Dimension(java.awt.Dimension) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 33 with MenuItem

use of java.awt.MenuItem in project voltdb by VoltDB.

the class DatabaseManager method actionPerformed.

public void actionPerformed(ActionEvent ev) {
    String s = ev.getActionCommand();
    if (s == null) {
        if (ev.getSource() instanceof MenuItem) {
            MenuItem i;
            s = ((MenuItem) ev.getSource()).getLabel();
        }
    }
    if (s == null) {
    } else if (s.equals("Execute")) {
        execute();
    } else if (s.equals("Clear")) {
        clear();
    } else if (s.equals("Exit")) {
        windowClosing(null);
    } else if (s.equals("Transfer")) {
        Transfer.work(null);
    } else if (s.equals("Dump")) {
        Transfer.work(new String[] { "-d" });
    } else if (s.equals("Restore")) {
        Transfer.work(new String[] { "-r" });
        refreshTree();
    } else if (s.equals("Logging on")) {
        JavaSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
        JavaSystem.setLogToSystem(false);
    } else if (s.equals("Help")) {
        showHelp(new String[] { "", HELP_TEXT });
    } else if (s.equals("About")) {
        showHelp(new String[] { "", ABOUT_TEXT });
    } else if (s.equals("Refresh Tree")) {
        refreshTree();
    } else if (s.startsWith("#")) {
        int i = Integer.parseInt(s.substring(1));
        txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
        connect(ConnectionDialog.createConnection(fMain, "Connect"));
        refreshTree();
    } else if (s.equals("Results in Grid")) {
        iResult = 0;
        pResult.removeAll();
        pResult.add("Center", gResult);
        pResult.doLayout();
    } else if (s.equals("Open Script...")) {
        FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            StringBuffer buf = new StringBuffer();
            ifHuge = DatabaseManagerCommon.readFile(f.getDirectory() + file);
            if (4096 <= ifHuge.length()) {
                buf.append("This huge file cannot be edited.\n Please execute or clear\n");
                txtCommand.setText(buf.toString());
            } else {
                txtCommand.setText(ifHuge);
            }
        }
    } else if (s.equals("Save Script...")) {
        FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
        }
    } else if (s.equals("Save Result csv...")) {
        FileDialog f = new FileDialog(fMain, "Save Result CSV", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String dir = f.getDirectory();
        String file = f.getFile();
        if (dir != null) {
            file = dir + "/" + file;
        }
        if (file != null) {
            showResultInText();
            saveAsCsv(file);
        }
    } else if (s.equals("Save Result...")) {
        FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            showResultInText();
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
        }
    } else if (s.equals("Results in Text")) {
        iResult = 1;
        pResult.removeAll();
        pResult.add("Center", txtResult);
        pResult.doLayout();
        showResultInText();
    } else if (s.equals("AutoCommit on")) {
        try {
            cConn.setAutoCommit(true);
        } catch (SQLException e) {
        }
    } else if (s.equals("AutoCommit off")) {
        try {
            cConn.setAutoCommit(false);
        } catch (SQLException e) {
        }
    } else if (s.equals("Enlarge Tree")) {
        Dimension d = tTree.getMinimumSize();
        d.width += 20;
        tTree.setMinimumSize(d);
        fMain.pack();
    } else if (s.equals("Shrink Tree")) {
        Dimension d = tTree.getMinimumSize();
        d.width -= 20;
        if (d.width >= 0) {
            tTree.setMinimumSize(d);
        }
        fMain.pack();
    } else if (s.equals("Enlarge Command")) {
        txtCommand.setRows(txtCommand.getRows() + 1);
        fMain.pack();
    } else if (s.equals("Shrink Command")) {
        int i = txtCommand.getRows() - 1;
        txtCommand.setRows(i < 1 ? 1 : i);
        fMain.pack();
    } else if (s.equals("Commit")) {
        try {
            cConn.commit();
        } catch (SQLException e) {
        }
    } else if (s.equals("Insert test data")) {
        insertTestData();
    } else if (s.equals("Rollback")) {
        try {
            cConn.rollback();
        } catch (SQLException e) {
        }
    } else if (s.equals("Disable MaxRows")) {
        try {
            sStatement.setMaxRows(0);
        } catch (SQLException e) {
        }
    } else if (s.equals("Set MaxRows to 100")) {
        try {
            sStatement.setMaxRows(100);
        } catch (SQLException e) {
        }
    } else if (s.equals("SELECT")) {
        showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
        showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
        showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
        showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
        showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
        showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
        showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
        showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
        showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
        showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
        showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
        showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
        showHelp(DatabaseManagerCommon.testHelp);
    }
}
Also used : SQLException(java.sql.SQLException) MenuItem(java.awt.MenuItem) Dimension(java.awt.Dimension) FileDialog(java.awt.FileDialog)

Example 34 with MenuItem

use of java.awt.MenuItem in project voltdb by VoltDB.

the class ZaurusDatabaseManager method actionPerformed.

/**
     * Method declaration
     *
     *
     * @param ev
     */
public void actionPerformed(ActionEvent ev) {
    String s = ev.getActionCommand();
    if (s == null) {
        if (ev.getSource() instanceof MenuItem) {
            MenuItem i;
            s = ((MenuItem) ev.getSource()).getLabel();
        }
    }
    if (s.equals("Execute")) {
        execute();
        layoutCard.show(pCard, "result");
    } else if (s.equals("Tree")) {
        layoutCard.show(pCard, "tree");
    } else if (s.equals("Command")) {
        layoutCard.show(pCard, "command");
    } else if (s.equals("Result")) {
        layoutCard.show(pCard, "result");
    } else if (s.equals("Editor")) {
        layoutCard.show(pCard, "editor");
    } else if (s.equals("Exit")) {
        windowClosing(null);
    } else if (s.equals("Logging on")) {
        JavaSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
        JavaSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
        refreshTree();
        layoutCard.show(pCard, "tree");
    } else if (s.startsWith("#")) {
        int i = Integer.parseInt(s.substring(1));
        txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
        connect(ZaurusConnectionDialog.createConnection(fMain, "Connect", new Insets(defWidth, defHeight, defLocX, defLocY)));
        refreshTree();
        layoutCard.show(pCard, "tree");
    } else if (s.equals("View Tree")) {
        layoutCard.show(pCard, "tree");
    } else if (s.equals("View Command")) {
        layoutCard.show(pCard, "command");
    } else if (s.equals("View Result")) {
        layoutCard.show(pCard, "result");
    } else if (s.equals("View Editor")) {
        layoutCard.show(pCard, "editor");
    } else if (s.equals("Results in Grid")) {
        iResult = 0;
        pResult.removeAll();
        pResult.add("Center", gResult);
        pResult.doLayout();
        layoutCard.show(pCard, "result");
    } else if (s.equals("Open Script...")) {
        FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
        }
        layoutCard.show(pCard, "command");
    } else if (s.equals("Save Script...")) {
        FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
        }
    } else if (s.equals("Save Result...")) {
        FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            showResultInText();
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
        }
    } else if (s.equals("Results in Text")) {
        iResult = 1;
        pResult.removeAll();
        pResult.add("Center", txtResult);
        pResult.doLayout();
        showResultInText();
        layoutCard.show(pCard, "result");
    } else if (s.equals("AutoCommit on")) {
        try {
            cConn.setAutoCommit(true);
        } catch (SQLException e) {
        }
    } else if (s.equals("AutoCommit off")) {
        try {
            cConn.setAutoCommit(false);
        } catch (SQLException e) {
        }
    } else if (s.equals("Commit")) {
        try {
            cConn.commit();
        } catch (SQLException e) {
        }
    } else if (s.equals("Insert test data")) {
        insertTestData();
        layoutCard.show(pCard, "result");
    } else if (s.equals("Rollback")) {
        try {
            cConn.rollback();
        } catch (SQLException e) {
        }
    } else if (s.equals("Disable MaxRows")) {
        try {
            sStatement.setMaxRows(0);
        } catch (SQLException e) {
        }
    } else if (s.equals("Set MaxRows to 100")) {
        try {
            sStatement.setMaxRows(100);
        } catch (SQLException e) {
        }
    } else if (s.equals("SELECT")) {
        showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
        showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
        showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
        showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
        showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
        showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
        showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
        showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
        showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
        showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
        showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
        showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
        showHelp(DatabaseManagerCommon.testHelp);
    } else if (s.equals("Show HTML-Help in browser")) {
        try {
            System.out.println("Starting Opera on index.html");
            Runtime.getRuntime().exec(new String[] { "opera", "/home/QtPalmtop/help/html/hsqldb/index.html" });
        } catch (IOException e) {
            System.out.println("A problem with Opera occured.");
        }
    }
}
Also used : Insets(java.awt.Insets) SQLException(java.sql.SQLException) MenuItem(java.awt.MenuItem) IOException(java.io.IOException) FileDialog(java.awt.FileDialog)

Example 35 with MenuItem

use of java.awt.MenuItem in project voltdb by VoltDB.

the class Transfer method actionPerformed.

/**
     * Method declaration
     *
     *
     * @param ev
     */
public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() instanceof TextField) {
        saveTable();
        return;
    }
    String s = ev.getActionCommand();
    MenuItem i = new MenuItem();
    if (s == null) {
        if (ev.getSource() instanceof MenuItem) {
            i = (MenuItem) ev.getSource();
            s = i.getLabel();
        }
    }
    if (s == null) {
    }
    if (s.equals("Start Transfer") || s.equals("ReStart Transfer")) {
        bStart.setLabel("ReStart Transfer");
        bStart.invalidate();
        CurrentTransfer = 0;
        CurrentAlter = 0;
        transfer();
    } else if (s.equals("Continue Transfer")) {
        transfer();
    } else if (s.equals("Start Dump") || s.equals("Start Restore")) {
        CurrentTransfer = 0;
        CurrentAlter = 0;
        transfer();
    } else if (s.equals("Quit")) {
        exit();
    } else if (s.indexOf("Select Schema") >= 0) {
        String[] selection = lTable.getSelectedItems();
        if ((selection == null) || (selection.length == 0)) {
            return;
        }
        if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
            sSourceSchemas = selection;
        } else {
            sDestSchema = selection[0];
        }
        if (iTransferMode == TRFM_DUMP) {
            iSelectionStep = Transfer.SELECT_SOURCE_TABLES;
        } else {
            iSelectionStep++;
        }
        ProcessNextStep();
    } else if (s.indexOf("Select Catalog") >= 0) {
        String selection = lTable.getSelectedItem();
        if ((selection == null) || (selection.equals(""))) {
            return;
        }
        if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
            sSourceCatalog = selection;
            sSourceSchemas = null;
        } else {
            sDestCatalog = selection;
            sDestSchema = null;
            try {
                targetDb.setCatalog(sDestCatalog);
            } catch (Exception ex) {
                trace("Catalog " + sDestCatalog + " could not be selected in the target database");
                sDestCatalog = null;
            }
        }
        iSelectionStep++;
        ProcessNextStep();
    } else if (s.equals("Insert 10 rows only")) {
        iMaxRows = 10;
    } else if (s.equals("Insert 1000 rows only")) {
        iMaxRows = 1000;
    } else if (s.equals("Insert all rows")) {
        iMaxRows = 0;
    } else if (s.equals("Load Settings...")) {
        FileDialog f = new FileDialog(fMain, "Load Settings", FileDialog.LOAD);
        f.show();
        String file = f.getDirectory() + f.getFile();
        if (file != null) {
            LoadPrefs(file);
            displayTable(tCurrent);
        }
    } else if (s.equals("Save Settings...")) {
        FileDialog f = new FileDialog(fMain, "Save Settings", FileDialog.SAVE);
        f.show();
        String file = f.getDirectory() + f.getFile();
        if (file != null) {
            SavePrefs(file);
        }
    } else if (s.equals("Exit")) {
        windowClosing(null);
    }
}
Also used : TextField(java.awt.TextField) MenuItem(java.awt.MenuItem) FileDialog(java.awt.FileDialog)

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