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(String s) 

Source Link

Document

Parses a string and returns a KeyStroke.

Usage

From source file:net.sf.mzmine.modules.visualization.tic.TICPlot.java

public TICPlot(final ActionListener listener) {

    super(null, true);

    // Initialize.
    visualizer = listener;//from w  w w  . j a va 2s. c  o  m
    labelsVisible = 1;
    havePeakLabels = false;
    numOfDataSets = 0;
    numOfPeaks = 0;
    showSpectrumRequest = false;

    // Set cursor.
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    // Y-axis label.
    final String yAxisLabel;
    if (listener instanceof TICVisualizerWindow) {

        yAxisLabel = ((TICVisualizerWindow) listener).getPlotType() == PlotType.BASEPEAK ? "Base peak intensity"
                : "Total ion intensity";
    } else {

        yAxisLabel = "Base peak intensity";
    }

    // Initialize the chart by default time series chart from factory.
    final JFreeChart chart = ChartFactory.createXYLineChart("", // title
            "Retention time", // x-axis label
            yAxisLabel, // y-axis label
            null, // data set
            PlotOrientation.VERTICAL, // orientation
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // Title.
    chartTitle = chart.getTitle();
    chartTitle.setFont(TITLE_FONT);
    chartTitle.setMargin(TITLE_TOP_MARGIN, 0.0, 0.0, 0.0);

    // Subtitle.
    chartSubTitle = new TextTitle();
    chartSubTitle.setFont(SUBTITLE_FONT);
    chartSubTitle.setMargin(TITLE_TOP_MARGIN, 0.0, 0.0, 0.0);
    chart.addSubtitle(chartSubTitle);

    // Disable maximum size (we don't want scaling).
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // Legend constructed by ChartFactory.
    final LegendTitle legend = chart.getLegend();
    legend.setItemFont(LEGEND_FONT);
    legend.setFrame(BlockBorder.NONE);

    // Set the plot properties.
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(AXIS_OFFSET);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // Set grid properties.
    plot.setDomainGridlinePaint(GRID_COLOR);
    plot.setRangeGridlinePaint(GRID_COLOR);

    // Set cross-hair (selection) properties.
    if (listener instanceof TICVisualizerWindow) {

        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        plot.setDomainCrosshairPaint(CROSS_HAIR_COLOR);
        plot.setRangeCrosshairPaint(CROSS_HAIR_COLOR);
        plot.setDomainCrosshairStroke(CROSS_HAIR_STROKE);
        plot.setRangeCrosshairStroke(CROSS_HAIR_STROKE);
    }

    // Set the x-axis (retention time) properties.
    final NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(MZmineCore.getConfiguration().getRTFormat());
    xAxis.setUpperMargin(AXIS_MARGINS);
    xAxis.setLowerMargin(AXIS_MARGINS);

    // Set the y-axis (intensity) properties.
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());

    // Set default renderer properties.
    defaultRenderer = new TICPlotRenderer();
    defaultRenderer.setBaseShapesFilled(true);
    defaultRenderer.setDrawOutlines(false);
    defaultRenderer.setUseFillPaint(true);
    defaultRenderer.setBaseItemLabelPaint(LABEL_COLOR);

    // Set label generator
    final XYItemLabelGenerator labelGenerator = new TICItemLabelGenerator(this);
    defaultRenderer.setBaseItemLabelGenerator(labelGenerator);
    defaultRenderer.setBaseItemLabelsVisible(true);

    // Set toolTipGenerator
    final XYToolTipGenerator toolTipGenerator = new TICToolTipGenerator();
    defaultRenderer.setBaseToolTipGenerator(toolTipGenerator);

    // Set focus state to receive key events.
    setFocusable(true);

    // Register key handlers.
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("LEFT"), listener, "MOVE_CURSOR_LEFT");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("RIGHT"), listener, "MOVE_CURSOR_RIGHT");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("SPACE"), listener, "SHOW_SPECTRUM");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('+'), this, "ZOOM_IN");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('-'), this, "ZOOM_OUT");

    // Add items to popup menu.
    final JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();

    if (listener instanceof TICVisualizerWindow) {

        popupMenu.add(new ExportPopUpMenu((TICVisualizerWindow) listener));
        popupMenu.addSeparator();
        popupMenu.add(new AddFilePopupMenu((TICVisualizerWindow) listener));
        popupMenu.add(new RemoveFilePopupMenu((TICVisualizerWindow) listener));
        popupMenu.add(new ExportPopUpMenu((TICVisualizerWindow) listener));
        popupMenu.addSeparator();
    }

    GUIUtils.addMenuItem(popupMenu, "Toggle showing peak values", this, "SHOW_ANNOTATIONS");
    GUIUtils.addMenuItem(popupMenu, "Toggle showing data points", this, "SHOW_DATA_POINTS");

    if (listener instanceof TICVisualizerWindow) {
        popupMenu.addSeparator();
        GUIUtils.addMenuItem(popupMenu, "Show spectrum of selected scan", listener, "SHOW_SPECTRUM");
    }

    popupMenu.addSeparator();

    GUIUtils.addMenuItem(popupMenu, "Set axes range", this, "SETUP_AXES");

    if (listener instanceof TICVisualizerWindow) {

        GUIUtils.addMenuItem(popupMenu, "Set same range to all windows", this, "SET_SAME_RANGE");
    }
}

From source file:com.haulmont.cuba.desktop.App.java

protected void initLookAndFeelDefaults() {
    InputMapUIResource inputMap = (InputMapUIResource) UIManager.getLookAndFeelDefaults()
            .get("FormattedTextField.focusInputMap");
    inputMap.remove(KeyStroke.getKeyStroke("ESCAPE"));
}

From source file:burlov.ultracipher.swing.MainPanel.java

public Action getDeleteEntryAction() {
    Action ret = new AbstractAction("deleteEntryAction") {

        /**/*from  w  w w .j ava  2 s .c  om*/
         *
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteCurrentEntry();
        }
    };
    ret.putValue(Action.NAME, "Delete entry");
    ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D"));
    return ret;
}

From source file:burlov.ultracipher.swing.MainPanel.java

public Action getNewEntryAction() {
    Action ret = new AbstractAction("deleteEntryAction") {

        /**// w  w  w.j a  v  a2s  .  c  o m
         *
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            getEditDataPanel().setEditable(true);
            newEntry();
        }
    };
    ret.putValue(Action.NAME, "New entry");
    ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control N"));
    return ret;
}

From source file:DragPictureDemo2.java

public DTPicture(Image image) {
    super(image);
    addMouseMotionListener(this);

    //Add the cut/copy/paste key bindings to the input map.
    //Note that this step is redundant if you are installing
    //menu accelerators that cause these actions to be invoked.
    //DragPictureDemo does not use menu accelerators and, since
    //the default value of installInputMapBindings is true,
    //the bindings are installed. DragPictureDemo2 does use
    //menu accelerators and so calls setInstallInputMapBindings
    //with a value of false. Your program would do one or the
    //other, but not both.
    if (installInputMapBindings) {
        InputMap imap = this.getInputMap();
        imap.put(KeyStroke.getKeyStroke("ctrl X"), TransferHandler.getCutAction().getValue(Action.NAME));
        imap.put(KeyStroke.getKeyStroke("ctrl C"), TransferHandler.getCopyAction().getValue(Action.NAME));
        imap.put(KeyStroke.getKeyStroke("ctrl V"), TransferHandler.getPasteAction().getValue(Action.NAME));
    }// w w w . j a  v  a2  s. c om

    //Add the cut/copy/paste actions to the action map.
    //This step is necessary because the menu's action listener
    //looks for these actions to fire.
    ActionMap map = this.getActionMap();
    map.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
    map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction());
    map.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
}

From source file:eu.europeana.sip.gui.SipCreatorGUI.java

private JPanel createFinishedPanel() {
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    Action finishedAction = new FinishedAction(this);
    ((JComponent) getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke("ESCAPE"), "finished");
    ((JComponent) getContentPane()).getActionMap().put("finished", finishedAction);
    JButton hide = new JButton(finishedAction);
    panel.add(hide);//  w ww .j  a  v a2s . c  om
    return panel;
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferHandler.java

public static void registerWith(SpreadSheet spreadSheet) {
    NodeListTransferHandler handler = new NodeListTransferHandler(spreadSheet);
    //          if (c instanceof SpreadSheet){
    //             SpreadSheet spreadSheet=(SpreadSheet)c;
    //             handler.setSpreadSheet(spreadSheet);
    //          }
    spreadSheet.setTransferHandler(handler);

    InputMap imap = spreadSheet.getInputMap();
    imap.put(KeyStroke.getKeyStroke("ctrl X"), NodeListTransferHandler.getCutAction().getValue(Action.NAME));
    imap.put(KeyStroke.getKeyStroke("ctrl C"), NodeListTransferHandler.getCopyAction().getValue(Action.NAME));
    imap.put(KeyStroke.getKeyStroke("ctrl V"), NodeListTransferHandler.getPasteAction().getValue(Action.NAME));
    //c.setInputMap(JComponent.WHEN_FOCUSED,imap);

    ActionMap amap = spreadSheet.getActionMap();
    amap.put(NodeListTransferHandler.getCutAction().getValue(Action.NAME),
            NodeListTransferHandler.getCutAction());
    amap.put(NodeListTransferHandler.getCopyAction().getValue(Action.NAME),
            NodeListTransferHandler.getCopyAction());
    amap.put(NodeListTransferHandler.getPasteAction().getValue(Action.NAME),
            NodeListTransferHandler.getPasteAction());

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * Adds Up/Down Focus Traversal Keys to the form.
 *///from w ww.java  2s . com
protected void addArrowTraversalKeys() {
    Set<AWTKeyStroke> set = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    KeyStroke forward = KeyStroke.getKeyStroke("DOWN");
    set = new HashSet<AWTKeyStroke>(set);
    set.add(forward);
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);

    set = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    KeyStroke backward = KeyStroke.getKeyStroke("UP");
    set = new HashSet<AWTKeyStroke>(set);
    set.add(backward);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);
}

From source file:edu.pdi2.visual.PDI.java

private void initGUI() {
    try {/*from   ww  w  .ja  v a  2s  .  co  m*/
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        this.setTitle("Procesamiento Digital de Imagenes"); //$NON-NLS-1$
        getContentPane().setBackground(new java.awt.Color(212, 208, 200));
        this.setResizable(false);
        this.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent evt) {
                thisFocusGained(evt);
            }
        });
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu1 = new JMenu();
                jMenuBar1.add(jMenu1);
                jMenu1.setText("File"); //$NON-NLS-1$
                {
                    jMenuItem1 = new JMenuItem();
                    // jMenu1.add(jMenuItem1);
                    jMenu1.add(getJMenuOpenImage());
                    jMenu1.add(getJSeparator1());
                    jMenu1.add(getJMenuItemExit());

                    jMenuItem1.setText("Open Image"); //$NON-NLS-1$
                    jMenuItem1.addMouseListener(new MouseAdapter() {
                        public void mouseReleased(MouseEvent evt) {
                            jMenuItem1MouseReleased(evt);
                        }

                    });
                }
            }
            {
                jMenu3 = new JMenu();
                jMenuBar1.add(jMenu3);
                jMenuBar1.add(getJMenuView());
                jMenu3.setText("Options"); //$NON-NLS-1$
                jMenu3.setEnabled(false);
                {
                    jMenuItem3 = new JMenuItem();
                    jMenu3.add(getJMenuItem2());
                    jMenu3.add(jMenuItem3);
                    jMenuItem3.setText("False Color Image"); //$NON-NLS-1$
                    jMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            menuFalseColorActionPerformed(evt);
                        }
                    });
                }
                {
                    jMenuItem4 = new JMenuItem();
                    jMenu3.add(jMenuItem4);
                    jMenuItem4.setText("Mesh"); //$NON-NLS-1$
                    jMenuItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jMenuItem4ActionPerformed(evt);
                        }
                    });
                }
                {
                    jMenu4 = new JMenu();
                    jMenu3.add(jMenu4);
                    jMenu3.add(getJMenuItem5());
                    jMenu3.add(getJGenerarSignature());
                    jMenu4.setText("Image"); //$NON-NLS-1$
                    {
                        jmiCorrectedReflectance = new JMenuItem();
                        jMenu4.add(jmiCorrectedReflectance);
                        jmiCorrectedReflectance.setText("Corrected Reflectance"); //$NON-NLS-1$
                        jmiCorrectedReflectance.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed 1")); //$NON-NLS-1$
                        jmiCorrectedReflectance.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jmiCorrectedRadianceActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jmiCorrectedRadiance = new JMenuItem();
                        jMenu4.add(jmiCorrectedRadiance);
                        jmiCorrectedRadiance.setText("Corrected Radiance"); //$NON-NLS-1$
                        jmiCorrectedRadiance.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed 2"));
                        jmiCorrectedRadiance.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jmiCorrectedReflectanceActionPerformed(evt);
                            }
                        });
                    }
                }
            }
        }
        // First we create the instance of DisplayThumbnail with a 0.1
        // scale.
        // dt.setBorder(BorderFactory.createTitledBorder(""));
        // We must register mouse motion listeners to it !

        // Now we create the instance of DisplayJAI to show the region
        // corresponding to the viewport.

        // Set it size.
        {
            image = new JPanel();

            getContentPane().add(image);
            image.setBounds(1, 10, 590, dHeight + 10);
            {
                dj = new DisplayJAIWithAnnotations();
                image.add(dj);
                dj.setBounds(0, 0, dWidth, dHeight);
                dj.setPreferredSize(new Dimension(dWidth, dHeight));
                dj.setMinimumSize(new Dimension(dWidth, dHeight));
                dj.setMaximumSize(new Dimension(dWidth, dHeight));
                dj.setBorder(BorderFactory.createTitledBorder(""));
                dj.addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent evt) {
                        djMousePressed(evt);
                    }
                });
                dj.addMouseMotionListener(new MouseMotionAdapter() {
                    public void mouseMoved(MouseEvent evt) {
                        djMouseMoved(evt);
                    }

                    public void mouseDragged(MouseEvent evt) {
                        djMouseDragged(evt);
                    }
                });
            }
            getContentPane().add(getLatLon());
        }

        pack();
        this.setSize(604, 579);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.mirth.connect.client.ui.Mirth.java

public static void initUIManager() {
    try {/*from   ww w  .j  a v a2s . c  o  m*/
        PlasticLookAndFeel.setPlasticTheme(new MirthTheme());
        PlasticXPLookAndFeel look = new PlasticXPLookAndFeel();
        UIManager.setLookAndFeel(look);
        UIManager.put("win.xpstyle.name", "metallic");
        LookAndFeelAddons.setAddon(WindowsLookAndFeelAddons.class);

        /*
         * MIRTH-1225 and MIRTH-2019: Create alternate key bindings if CTRL is not the same as
         * the menu shortcut key (i.e. COMMAND on OSX)
         */
        if (InputEvent.CTRL_MASK != Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) {
            createAlternateKeyBindings();
        }

        if (SystemUtils.IS_OS_MAC) {
            OSXAdapter.setAboutHandler(Mirth.class, Mirth.class.getDeclaredMethod("aboutMac", (Class[]) null));
            OSXAdapter.setQuitHandler(Mirth.class, Mirth.class.getDeclaredMethod("quitMac", (Class[]) null));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // keep the tooltips from disappearing
    ToolTipManager.sharedInstance().setDismissDelay(3600000);

    // TabbedPane defaults
    // UIManager.put("TabbedPane.selected", new Color(0xffffff));
    // UIManager.put("TabbedPane.background",new Color(225,225,225));
    // UIManager.put("TabbedPane.tabAreaBackground",new Color(225,225,225));
    UIManager.put("TabbedPane.highlight", new Color(225, 225, 225));
    UIManager.put("TabbedPane.selectHighlight", new Color(0xc3c3c3));
    UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0, 0, 0, 0));

    // TaskPane defaults
    UIManager.put("TaskPane.titleBackgroundGradientStart", new Color(0xffffff));
    UIManager.put("TaskPane.titleBackgroundGradientEnd", new Color(0xffffff));

    // Set fonts
    UIManager.put("TextPane.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ToggleButton.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Panel.font", UIConstants.DIALOG_FONT);
    UIManager.put("PopupMenu.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("OptionPane.font", UIConstants.DIALOG_FONT);
    UIManager.put("Label.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Tree.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ScrollPane.font", UIConstants.DIALOG_FONT);
    UIManager.put("TextField.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Viewport.font", UIConstants.DIALOG_FONT);
    UIManager.put("MenuBar.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("FormattedTextField.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("DesktopIcon.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TableHeader.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ToolTip.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("PasswordField.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TaskPane.font", UIConstants.TEXTFIELD_BOLD_FONT);
    UIManager.put("Table.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TabbedPane.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ProgressBar.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("CheckBoxMenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ColorChooser.font", UIConstants.DIALOG_FONT);
    UIManager.put("Button.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TextArea.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Spinner.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("RadioButton.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TitledBorder.font", UIConstants.TEXTFIELD_BOLD_FONT);
    UIManager.put("EditorPane.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("RadioButtonMenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ToolBar.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("MenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("CheckBox.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("JXTitledPanel.title.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Menu.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ComboBox.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("JXLoginPanel.banner.font", UIConstants.BANNER_FONT);
    UIManager.put("List.font", UIConstants.TEXTFIELD_PLAIN_FONT);

    InputMap im = (InputMap) UIManager.get("Button.focusInputMap");
    im.put(KeyStroke.getKeyStroke("pressed ENTER"), "pressed");
    im.put(KeyStroke.getKeyStroke("released ENTER"), "released");

    try {
        UIManager.put("wizard.sidebar.image",
                ImageIO.read(com.mirth.connect.client.ui.Frame.class.getResource("images/wizardsidebar.png")));
    } catch (IOException e) {
        e.printStackTrace();
    }
}