Example usage for javax.swing KeyStroke getKeyStroke

List of usage examples for javax.swing KeyStroke getKeyStroke

Introduction

In this page you can find the example usage for javax.swing KeyStroke getKeyStroke.

Prototype

public static KeyStroke getKeyStroke(int keyCode, int modifiers) 

Source Link

Document

Returns a shared instance of a KeyStroke, given a numeric key code and a set of modifiers.

Usage

From source file:de.xplib.xdbm.util.I18N.java

/**
 * @param keyIn ..//from  www .  j a v  a 2s  . com
 * @return ..
 */
public KeyStroke getAccelerator(final String keyIn) {

    String value = this.getValue(keyIn, "accelerator");
    if (value.startsWith(keyIn)) {
        return null;
    }

    String[] s = value.toUpperCase().split(",");
    if (s.length == 0 || s[0].equals("")) {
        return null;
    }

    int code = (int) s[0].charAt(0);
    int mod = 0;
    for (int i = 1; i < s.length; i++) {
        char c = s[i].charAt(0);
        if (c == 'S') {
            mod = mod | ActionEvent.SHIFT_MASK;
        } else if (c == 'A') {
            mod = mod | ActionEvent.ALT_MASK;
        } else if (c == 'C') {
            mod = mod | ActionEvent.CTRL_MASK;
        } else if (c == 'M') {
            mod = mod | ActionEvent.META_MASK;
        }
    }
    return KeyStroke.getKeyStroke(code, mod);
}

From source file:org.pgptool.gui.ui.keyslist.KeysTableView.java

@SuppressWarnings("serial")
private void initTableKeyListener() {
    int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
    InputMap inputMap = table.getInputMap(condition);
    ActionMap actionMap = table.getActionMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
    actionMap.put(DELETE, new AbstractAction() {
        @Override//from  ww w. j  av a2  s  . c om
        public void actionPerformed(ActionEvent e) {
            if (pm == null) {
                return;
            }
            safePerformAction(pm.getActionDelete(), null);
        }
    });
}

From source file:com.mucommander.ui.viewer.image.ImageViewer.java

public ImageViewer() {
    imageViewerImpl = new ImageViewerImpl();

    setComponentToPresent(imageViewerImpl);

    // create Go menu
    MnemonicHelper menuMnemonicHelper = new MnemonicHelper();
    controlsMenu = MenuToolkit.addMenu(Translator.get("image_viewer.controls_menu"), menuMnemonicHelper, null);

    nextImageItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.next_image"),
            menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), this);
    prevImageItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.previous_image"),
            menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), this);
    controlsMenu.add(new JSeparator());
    if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) {
        zoomInItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_in"),
                menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), this);
        zoomOutItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_out"),
                menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0), this);
    } else {/*from w ww  .j a  v a 2s  .c o  m*/
        zoomInItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_in"),
                menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), this);
        zoomOutItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_out"),
                menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), this);
    }
}

From source file:org.nekorp.workflow.desktop.view.CostoServicioView.java

private void setShorcuts() {
    InputMap im = tablaCostos.getInputMap(JTable.WHEN_FOCUSED);
    ActionMap am = tablaCostos.getActionMap();
    Action deleteAction = new AbstractAction() {
        @Override/*from   ww w .  ja  va  2  s.c o m*/
        public void actionPerformed(ActionEvent e) {
            borrarActionPerformed(e);
        }
    };
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "Delete");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "Delete");
    am.put("Delete", deleteAction);
    Action addAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            borrarActionPerformed(e);
        }
    };
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0), "Add");
    am.put("Add", addAction);
}

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Build menu./*  w  w w .  java  2s .  com*/
 */
public void makeMenu() {
    JMenuItem menuItem;

    JMenu menu;
    JMenu submenu;

    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    menu = new JMenu(Menu.MENU_FILE);
    menu.setMnemonic(KeyEvent.VK_F);
    menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    submenu = new JMenu(Menu.EXPORT_MENU);
    menu.add(submenu);
    //submenu.setMnemonic( KeyEvent.VK_E );

    SchemeExporter.makeSchemeExportMenu(submenu, getActionListener());

    // Export window graphics
    submenu.add(GraphicsExporter.getExportMenu());

    menu.addSeparator();
    menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuBar.add(menu);
    menu = new JMenu(Menu.MENU_EDIT);
    menu.setMnemonic(KeyEvent.VK_E);

    menu.add(undoAction);
    menu.add(redoAction);
    menu.add(cloneAction);

    menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true);
    painterEnabled.addActionListener(getActionListener());
    menu.add(painterEnabled);

    menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            Canvas canvas = Editor.getInstance().getCurrentCanvas();
            if (canvas == null || !canvas.getPackage().hasPainters()) {
                painterEnabled.setVisible(false);
            } else {
                painterEnabled.setVisible(true);
                painterEnabled.setSelected(canvas.isEnableClassPainter());
            }
        }

    });

    menuBar.add(menu);

    menu = new JMenu(Menu.MENU_VIEW);
    menu.setMnemonic(KeyEvent.VK_V);
    gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid());
    gridCheckBox.setMnemonic('G');
    gridCheckBox.addActionListener(getActionListener());
    menu.add(gridCheckBox);

    ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls());
    ctrlCheckBox.setMnemonic('C');
    ctrlCheckBox.addActionListener(getActionListener());
    menu.add(ctrlCheckBox);

    showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true);
    showPortCheckBox.addActionListener(getActionListener());
    menu.add(showPortCheckBox);

    showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false);
    showObjectNamesCheckBox.addActionListener(getActionListener());
    menu.add(showObjectNamesCheckBox);

    //sync View with current canvas
    menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            Canvas canvas;

            if ((canvas = getCurrentCanvas()) == null)
                return;

            gridCheckBox.setSelected(canvas.isGridVisible());
            ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible());
            showPortCheckBox.setSelected(canvas.isDrawPorts());
            showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames());
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });

    menuBar.add(menu);

    menu = new JMenu(Menu.MENU_PACKAGE);
    menu.setMnemonic(KeyEvent.VK_P);
    menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    if (Desktop.isDesktopSupported()) {
        menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B);
        menuItem.addActionListener(getActionListener());
        menu.add(menuItem);
    }
    menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.CLOSE_ALL);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuBar.add(menu);
    menu.add(new JSeparator());
    final JMenu submenuRecent = new JMenu(Menu.RECENT);
    submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        final JMenuItem empty = new JMenuItem("Empty");

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {

            makeRecentSubMenu(submenuRecent);

            if (submenuRecent.getMenuComponentCount() == 0) {

                submenuRecent.add(empty);
                empty.setEnabled(false);

            } else {
                if (!((submenuRecent.getMenuComponentCount() == 1)
                        && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) {
                    submenuRecent.remove(empty);
                }
            }

        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });
    menu.add(submenuRecent);
    final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME);
    menuScheme.setMnemonic(KeyEvent.VK_S);
    makeSchemeMenu(menuScheme);

    menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {

            makeSchemeMenu(menuScheme);

        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });

    /*
     * menuItem = new JMenuItem("Planner");
     * menuItem.addActionListener(aListener); menuScheme.add(menuItem);
     * menuItem = new JMenuItem("Plan, compile, run");
     * menuItem.setActionCommand("Run");
     * menuItem.addActionListener(aListener); menuScheme.add(menuItem);
     */
    // menuScheme.setMnemonic(KeyEvent.VK_A);
    menuBar.add(menuScheme);
    menu = new JMenu(Menu.MENU_OPTIONS);
    menu.setMnemonic(KeyEvent.VK_O);

    menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK));
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.FONTS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.SAVE_SETTINGS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    submenu = new JMenu(Menu.MENU_LAF);
    submenu.setMnemonic(KeyEvent.VK_L);
    Look.getInstance().createMenuItems(submenu);
    menu.add(submenu);
    menuBar.add(menu);

    makeToolsMenu(menuBar);

    menu = new JMenu(Menu.MENU_HELP);
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);
    menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
}

From source file:br.ufrgs.enq.jcosmo.ui.COSMOSACDialog.java

public COSMOSACDialog() {
    super("JCOSMO Simple");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    db = COSMOSACDataBase.getInstance();

    COSMOSAC models[] = new COSMOSAC[5];
    models[0] = new COSMOSAC();
    models[1] = new COSMOPAC();
    models[2] = new COSMOSAC_SVP();
    models[3] = new COSMOSAC_G();
    models[4] = new PCMSAC();
    modelBox = new JComboBox(models);
    modelBox.addActionListener(this);

    JPanel north = new JPanel(new GridLayout(0, 2));
    add(north, BorderLayout.NORTH);
    JPanel northAba1 = new JPanel(new GridLayout(0, 4));
    JPanel northAba2 = new JPanel(new GridLayout(0, 2));

    //Where the GUI is created:
    JMenuBar menuBar;//from w ww  .  j ava2  s.c o m
    JMenu file, help;
    JMenuItem menuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    // the file menu
    file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    menuBar.add(file);
    menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    menuItem.setActionCommand(QUIT);
    menuItem.addActionListener(this);
    file.add(menuItem);

    // the help menu
    help = new JMenu("Help");
    file.setMnemonic(KeyEvent.VK_H);
    menuBar.add(help);
    menuItem = new JMenuItem("About", KeyEvent.VK_A);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    menuItem.setActionCommand(ABOUT);
    menuItem.addActionListener(this);
    help.add(menuItem);

    setJMenuBar(menuBar);

    listModel = new DefaultListModel();
    list = new JList(listModel);
    list.setBorder(BorderFactory.createTitledBorder("compounds"));
    list.setVisibleRowCount(2);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton addButton = new JButton("Add");
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new AddCompoundDialog(COSMOSACDialog.this);
        }
    });

    removeButton = new JButton("Remove");
    removeButton.addActionListener(this);
    visibRemove(false);

    JButton calcButton = new JButton("Calculate");
    calcButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rebuildChart();
            rebuildSigmaProfiles();
        }
    });

    JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rebuildSigmaProfiles();
        }
    });

    ignoreSGButton = new JCheckBox("Ignore SG");
    ignoreSGButton.setToolTipText("Toogles the ignore flag for the Staverman-Guggenheim term");
    ignoreSGButton.addActionListener(this);

    JPanel but = new JPanel(new GridLayout(0, 1));
    but.add(addButton, BorderLayout.EAST);
    but.add(removeButton, BorderLayout.EAST);
    but.add(modelBox);
    north.add(listScrollPane);
    north.add(but);

    northAba1.add(new JLabel("Temperature [K]"));
    northAba1.add(temperature = new JTextField(10));
    temperature.setText("298");

    northAba1.add(new JLabel("Sigma HB"));
    northAba1.add(sigmaHB = new JTextField(10));
    northAba1.add(new JLabel("Sigma HB2"));
    northAba1.add(sigmaHB2 = new JTextField(10));
    northAba1.add(new JLabel("Sigma HB3"));
    northAba1.add(sigmaHB3 = new JTextField(10));

    northAba1.add(new JLabel("Charge HB"));
    northAba1.add(chargeHB = new JTextField(10));

    northAba1.add(new JLabel("Sigma Disp"));
    northAba1.add(sigmaDisp = new JTextField(10));
    northAba1.add(new JLabel("Charge Disp"));
    northAba1.add(chargeDisp = new JTextField(10));

    northAba1.add(new JLabel("Beta"));
    northAba1.add(beta = new JTextField(10));
    northAba1.add(new JLabel("fpol"));
    northAba1.add(fpol = new JTextField(10));
    northAba1.add(new JLabel("Anorm"));
    northAba1.add(anorm = new JTextField(10));

    northAba1.add(ignoreSGButton);
    northAba1.add(calcButton);
    northAba2.add(new JLabel(""));
    northAba2.add(refreshButton);

    //      chart = new JLineChart();
    //      add(chart, BorderLayout.CENTER);
    //      chart.setTitle("Gamma Plot");
    //      chart.setSubtitle("");
    //      chart.setXAxisLabel("Mole Fraction, x_1");
    //      chart.setYAxisLabel("ln gamma, gE/RT");
    //      chart.setSource(getTitle());
    //      chart.setLegendPosition(LegendPosition.BOTTOM);
    //      chart.setShapesVisible(true);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction, x_1", "ln gamma, gE/RT", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setRange(new Range(0.0, 1.0));

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setUseFillPaint(true);
    r.setBaseFillPaint(Color.white);
    r.setBaseShapesVisible(true);

    JFreeChart sigmaProfileChart = ChartFactory.createXYLineChart(null, "sigma", "P^x", null,
            PlotOrientation.VERTICAL, true, true, false);
    sigmaProfilePlot = sigmaProfileChart.getXYPlot();
    sigmaProfilePlot.getDomainAxis().setAutoRange(false);
    sigmaProfilePlot.getDomainAxis().setRange(new Range(-0.025, 0.025));

    //      sigmaProfilePlot.setBackgroundPaint(Color.lightGray);
    //      sigmaProfilePlot.setDomainGridlinePaint(Color.white);
    //      sigmaProfilePlot.setRangeGridlinePaint(Color.white);

    JFreeChart chartSegGamma = ChartFactory.createXYLineChart(null, "sigma", "Segment Gamma", null,
            PlotOrientation.VERTICAL, true, true, false);
    plotSegGamma = (XYPlot) chartSegGamma.getPlot();

    JPanel south = new JPanel();
    south.setLayout(new FlowLayout());
    south.add(new JLabel("<html>ln &gamma;<sup>&infin;</sup><sub>1</sub>:</html>"));
    south.add(lnGammaInf1Label = new JLabel());
    south.add(new JLabel("<html>ln &gamma;<sup>&infin;</sup><sub>2</sub>:</html>"));
    south.add(lnGammaInf2Label = new JLabel());
    south.add(Box.createHorizontalStrut(20));
    south.add(new JLabel("<html>&gamma;<sup>&infin;</sup><sub>1</sub>:</html>"));
    south.add(gammaInf1Label = new JLabel());
    south.add(new JLabel("<html>&gamma;<sup>&infin;</sup><sub>2</sub>:</html>"));
    south.add(gammaInf2Label = new JLabel());

    JPanel aba1 = new JPanel(new BorderLayout());
    aba1.add(northAba1, BorderLayout.NORTH);
    JPanel chartsPanel = new JPanel(new GridLayout(0, 2));
    aba1.add(chartsPanel, BorderLayout.CENTER);
    chartsPanel.add(new ChartPanel(chart));
    chartsPanel.add(new ChartPanel(chartSegGamma));
    aba1.add(south, BorderLayout.SOUTH);

    JPanel aba2 = new JPanel(new BorderLayout());
    aba2.add(northAba2, BorderLayout.NORTH);
    aba2.add(chartPanel = new ChartPanel(sigmaProfileChart), BorderLayout.CENTER);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("gamma", aba1);
    tabbedPane.addTab("sigma", aba2);
    add(tabbedPane, BorderLayout.CENTER);

    //      cosmosac.setAEffPrime(6.596176570595075);
    //      cosmosac.setCoord(11.614599507917934);
    //      cosmosac.setVnorm(56.36966406129967);
    //      cosmosac.setAnorm(41.56058649432742);
    //      cosmosac.setCHB(65330.19484947528);
    //      cosmosac.setSigmaHB(0.008292411048046008);

    //Display the window.
    setSize(800, 600);
    setLocationRelativeTo(null);
    modelBox.setSelectedIndex(0);
    setVisible(true);

    // test for a mixture
    //      addList("WATER");
    //      addList("H3O+1");
    //      addList("OH-1");
    //      addList("CL-1");
    //      addList("OXYGEN");
    //      addList("sec-butylamine");
    //      addList("hydrogen-fluoride");
    //      addList("ACETONE");
    //      addList("METHANOL");
    //      addList("ACETONE.opt");
    //      addList("METHANOL.opt");
    //      addList("METHYL-ETHYL-KETONE");
    //      addList("ETHANOL");
    //      addList("N-HEPTANE");
    //      addList("PROPIONIC-ACID");
    //      addList("EMIM");
    //      addList("NTF2");
    //      addList("DCA");
    //      addList("N-OCTANE");
    addList("ETHYLENE CARBONATE");
    addList("BENZENE");
    addList("TOLUENE");
    removeButton.setEnabled(true);
}

From source file:edu.umich.robot.ViewerApplication.java

public ViewerApplication(String[] args) {
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);

    Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig();
    if (config == null)
        System.exit(1);//from w w  w  .  j av  a2 s .  c  o m

    setupViewerConfig(config);
    viewer = new Viewer(config);
    viewer.getVisCanvas().getViewManager().setInterfaceMode(3);

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            frame.dispose();

            try {
                Thread.sleep(500);
            } catch (InterruptedException ignored) {
            }
            System.exit(0); // No way to shut down april threads
        }
    });
    frame.setLayout(new BorderLayout());

    viewerView = new ViewerView(viewer.getVisCanvas());

    // TODO SoarApril
    // viewer.getVisCanvas().setDrawGround(true);

    frame.add(viewerView, BorderLayout.CENTER);

    Preferences windowPrefs = getWindowPreferences();
    if (windowPrefs.get("x", null) != null) {
        frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0),
                windowPrefs.getInt("width", 800), windowPrefs.getInt("height", 800));
    } else {
        frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0),
                windowPrefs.getInt("width", 600), windowPrefs.getInt("height", 600));
        frame.setLocationRelativeTo(null); // center
    }

    frame.getRootPane().registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);

    frame.pack();

    frame.setVisible(true);

    String[] splinters = config.getStrings("splinters", new String[0]);
    for (String s : splinters) {
        addViewRobot(s);
        addViewLidars(s);
        addViewWaypoints(s);

        // TODO SoarApril
        addViewTrajectory(s);
    }
}

From source file:dmh.kuebiko.view.NoteStackFrame.java

/**
 * Create the frame.//from  w w w. j ava 2 s .  c o m
 */
public NoteStackFrame(NoteManager noteMngr) {
    this.noteMngr = noteMngr;

    // Setup the various actions for the frame.
    noteMngr.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            boolean stackChanged = (Boolean) arg;
            toggleUnsavedChangeIndicator(stackChanged);
            if (!stackChanged) {
                notePanel.getHuxleyUiManager().resetTextChanged();
            }
        }
    });

    ActionObserverUtil.registerEnMass(actionMngr, observable, new NewNoteAction(this), new OpenNoteAction(this),
            new DeleteNoteAction(this), new RenameNoteAction(this), new SaveStackAction(this));

    // Build the menus.
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    newNoteMenuItem = new JMenuItem(actionMngr.getAction(NewNoteAction.class));
    fileMenu.add(newNoteMenuItem);

    JMenuItem openNoteMenuItem = new JMenuItem(actionMngr.getAction(OpenNoteAction.class));
    fileMenu.add(openNoteMenuItem);

    deleteNoteMenuItem = new JMenuItem(actionMngr.getAction(DeleteNoteAction.class));
    fileMenu.add(deleteNoteMenuItem);

    renameNoteMenuItem = new JMenuItem(actionMngr.getAction(RenameNoteAction.class));
    fileMenu.add(renameNoteMenuItem);

    fileMenu.addSeparator();

    newStackMenuItem = new JMenuItem(actionMngr.getAction(NewStackAction.class));
    fileMenu.add(newStackMenuItem);

    openStackMenuItem = new JMenuItem(actionMngr.getAction(OpenStackAction.class));
    fileMenu.add(openStackMenuItem);

    fileMenu.addSeparator();

    closeMenuItem = new JMenuItem("Close");
    closeMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    closeMenuItem.setEnabled(false);
    fileMenu.add(closeMenuItem);

    closeAllMenuItem = new JMenuItem("Close All");
    closeAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,
            InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    closeAllMenuItem.setEnabled(false);
    fileMenu.add(closeAllMenuItem);

    fileMenu.addSeparator();

    saveMenuItem = new JMenuItem(actionMngr.getAction(SaveStackAction.class));
    fileMenu.add(saveMenuItem);

    saveAllMenuItem = new JMenuItem("Save All");
    saveAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
            InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    saveAllMenuItem.setEnabled(false);
    fileMenu.add(saveAllMenuItem);

    editMenu = new JMenu("Edit");
    menuBar.add(editMenu);

    undoMenuItem = new JMenuItem("Undo");
    undoMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(undoMenuItem);

    redoMenuItem = new JMenuItem("Redo"); // FIXME mac-specific keyboard shortcut
    redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
            InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(redoMenuItem);

    editMenu.addSeparator();

    cutMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CutAction.class));
    cutMenuItem.setText("Cut");
    cutMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(cutMenuItem);

    copyMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CopyAction.class));
    copyMenuItem.setText("Copy");
    copyMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(copyMenuItem);

    pasteMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.PasteAction.class));
    pasteMenuItem.setText("Paste");
    pasteMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(pasteMenuItem);

    textMenu = new JMenu("Text");
    menuBar.add(textMenu);

    JMenu windowMenu = new JMenu("Window");
    menuBar.add(windowMenu);

    initialize();
    additionalSetup();
}

From source file:JXButtonPanel.java

private void init() {
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new JXButtonPanelFocusTraversalPolicy());
    ActionListener actionHandler = new ActionHandler();
    registerKeyboardAction(actionHandler, ActionHandler.FORWARD, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    registerKeyboardAction(actionHandler, ActionHandler.FORWARD, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    registerKeyboardAction(actionHandler, ActionHandler.BACKWARD, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    registerKeyboardAction(actionHandler, ActionHandler.BACKWARD, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    setGroupSelectionFollowFocus(true);/*from www. j  a v  a  2s  .  c  om*/
}

From source file:org.nekorp.workflow.desktop.view.AppMainWindow.java

/**
 * call this somewhere in your GUI construction
 *//*w  ww  .  j  av  a 2  s .com*/
private void setupKeyShortcut() {
    KeyStroke key1 = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK);
    actionMap.put(key1, new AbstractAction("guardar") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (editorMonitor.hasChange()) {
                try {
                    aplication.guardaServicio();
                } catch (IllegalArgumentException ex) {
                    //no lo guardo.
                }
            }
        }
    });
    //        key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
    //        actionMap.put(key1, new AbstractAction("deshacer") {
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                if (editorMonitor.hasChange()) {
    //                    editorMonitor.undo();
    //                }
    //            }
    //        });
    //        key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK);
    //        actionMap.put(key1, new AbstractAction("rehacer") {
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                editorMonitor.redo();
    //            }
    //        });
    // add more actions..

    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);
            if (actionMap.containsKey(keyStroke)) {
                final Action a = actionMap.get(keyStroke);
                final ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), null);
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        a.actionPerformed(ae);
                    }
                });
                return true;
            }
            return false;
        }
    });
}