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, boolean onKeyRelease) 

Source Link

Document

Returns a shared instance of a KeyStroke, given a numeric key code and a set of modifiers, specifying whether the key is activated when it is pressed or released.

Usage

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

/**
 * Creates new form TribeTribeAttackFrame
 */// w  ww .  java  2  s  .  c  o  m
public TribeTribeAttackFrame() {
    initComponents();
    centerPanel = new GenericTestPanel();
    jMainPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jxAttackPlanerPanel);
    buildMenu();
    capabilityInfoPanel1.addActionListener(this, jSourcesTable);
    capabilityInfoPanel2.addActionListener(this, jResultsTable);

    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    Action noFind = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //no find
        }
    };
    jSourcesTable.getActionMap().put("find", noFind);
    jVictimTable.getActionMap().put("find", noFind);
    jResultsTable.getActionMap().put("find", noFind);

    jSourcesTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);
    jVictimTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);
    jResultsTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);

    jideTabbedPane1.setTabShape(JideTabbedPane.SHAPE_OFFICE2003);
    jideTabbedPane1.setTabColorProvider(JideTabbedPane.ONENOTE_COLOR_PROVIDER);
    jideTabbedPane1.setBoldActiveTab(true);
    TagManager.getSingleton().addManagerListener(TribeTribeAttackFrame.this);
    logPanel = new AlgorithmLogPanel();
    mLogFrame = new JFrame("Informationen zur Berechnung");
    mLogFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    mLogFrame.setLayout(new BorderLayout());
    mLogFrame.add(logPanel);
    mLogFrame.pack();
    mTroopSplitDialog = new TroopSplitDialog(TribeTribeAttackFrame.this, true);
    mSettingsPanel = new SettingsPanel(this);
    jSettingsContentPanel.add(mSettingsPanel, BorderLayout.CENTER);
    jAttackResultDetailsFrame.pack();
    jTargetResultDetailsFrame.pack();
    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(TribeTribeAttackFrame.this, DnDConstants.ACTION_COPY_OR_MOVE,
            TribeTribeAttackFrame.this);
    new DropTarget(jSourcesTable, TribeTribeAttackFrame.this);
    new DropTarget(jVictimTable, TribeTribeAttackFrame.this);
    for (MouseListener l : jAllTargetsComboBox.getMouseListeners()) {
        jAllTargetsComboBox.removeMouseListener(l);
    }
    jAllTargetsComboBox.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            fireAddFilteredTargetVillages();
        }
    });

    filterDialog = new TroopFilterDialog(this, true);

    // <editor-fold defaultstate="collapsed" desc="Add selection listeners">
    jVillageGroupList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterSourceVillagesByGroupEvent();
            }
        }
    });
    jSourceContinentList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterSourceContinentEvent();
            }
        }
    });
    jTargetTribeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByTribeEvent();
            }
        }
    });
    jTargetContinentList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByContinentEvent();
            }
        }
    });

    jTargetAllyList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByAllyEvent();
            }
        }
    });
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelp(jSourcePanel, "pages.attack_planer_source",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelp(jTargetPanel, "pages.attack_planer_target",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelp(mSettingsPanel, "pages.attack_planer_settings",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jResultFrame.getRootPane(), "pages.attack_planer_results",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jTargetResultDetailsFrame.getRootPane(),
                "pages.attack_planer_results_details_targets", GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jAttackResultDetailsFrame.getRootPane(),
                "pages.attack_planer_results_details_sources", GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.attack_planer",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * //from  w w w . ja v  a 2  s  .co  m
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

From source file:javazoom.jlgui.player.amp.PlayerUI.java

public void loadSkin() {
    log.info("Load PlayerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
    removeAll();//from w w  w. j  a  va  2s.  c o  m
    // Load skin specified in args
    if (ui.getPath() != null) {
        log.info("Load default skin from " + ui.getPath());
        ui.loadSkin(ui.getPath());
        config.setDefaultSkin(ui.getPath());
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        ui.loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        ClassLoader cl = getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        ui.loadSkin(sis);
    }
    // Background
    ImageBorder border = new ImageBorder();
    border.setImage(ui.getMainImage());
    setBorder(border);
    // Buttons        
    add(ui.getAcPrevious(), ui.getAcPrevious().getConstraints());
    ui.getAcPrevious().removeActionListener(this);
    ui.getAcPrevious().addActionListener(this);
    add(ui.getAcPlay(), ui.getAcPlay().getConstraints());
    ui.getAcPlay().removeActionListener(this);
    ui.getAcPlay().addActionListener(this);
    add(ui.getAcPause(), ui.getAcPause().getConstraints());
    ui.getAcPause().removeActionListener(this);
    ui.getAcPause().addActionListener(this);
    add(ui.getAcStop(), ui.getAcStop().getConstraints());
    ui.getAcStop().removeActionListener(this);
    ui.getAcStop().addActionListener(this);
    add(ui.getAcNext(), ui.getAcNext().getConstraints());
    ui.getAcNext().removeActionListener(this);
    ui.getAcNext().addActionListener(this);
    add(ui.getAcEject(), ui.getAcEject().getConstraints());
    ui.getAcEject().removeActionListener(this);
    ui.getAcEject().addActionListener(this);
    // EqualizerUI toggle
    add(ui.getAcEqualizer(), ui.getAcEqualizer().getConstraints());
    ui.getAcEqualizer().removeActionListener(this);
    ui.getAcEqualizer().addActionListener(this);
    // Playlist toggle
    add(ui.getAcPlaylist(), ui.getAcPlaylist().getConstraints());
    ui.getAcPlaylist().removeActionListener(this);
    ui.getAcPlaylist().addActionListener(this);
    // Shuffle toggle
    add(ui.getAcShuffle(), ui.getAcShuffle().getConstraints());
    ui.getAcShuffle().removeActionListener(this);
    ui.getAcShuffle().addActionListener(this);
    // Repeat toggle
    add(ui.getAcRepeat(), ui.getAcRepeat().getConstraints());
    ui.getAcRepeat().removeActionListener(this);
    ui.getAcRepeat().addActionListener(this);
    // Volume
    add(ui.getAcVolume(), ui.getAcVolume().getConstraints());
    ui.getAcVolume().removeChangeListener(this);
    ui.getAcVolume().addChangeListener(this);
    // Balance
    add(ui.getAcBalance(), ui.getAcBalance().getConstraints());
    ui.getAcBalance().removeChangeListener(this);
    ui.getAcBalance().addChangeListener(this);
    // Seek bar
    add(ui.getAcPosBar(), ui.getAcPosBar().getConstraints());
    ui.getAcPosBar().removeChangeListener(this);
    ui.getAcPosBar().addChangeListener(this);
    // Mono
    add(ui.getAcMonoIcon(), ui.getAcMonoIcon().getConstraints());
    // Stereo
    add(ui.getAcStereoIcon(), ui.getAcStereoIcon().getConstraints());
    // Title label
    add(ui.getAcTitleLabel(), ui.getAcTitleLabel().getConstraints());
    // Sample rate label
    add(ui.getAcSampleRateLabel(), ui.getAcSampleRateLabel().getConstraints());
    // Bit rate label
    add(ui.getAcBitRateLabel(), ui.getAcBitRateLabel().getConstraints());
    // Play icon
    add(ui.getAcPlayIcon(), ui.getAcPlayIcon().getConstraints());
    // Time icon
    add(ui.getAcTimeIcon(), ui.getAcTimeIcon().getConstraints());
    // MinuteH number
    add(ui.getAcMinuteH(), ui.getAcMinuteH().getConstraints());
    // MinuteL number
    add(ui.getAcMinuteL(), ui.getAcMinuteL().getConstraints());
    // SecondH number
    add(ui.getAcSecondH(), ui.getAcSecondH().getConstraints());
    // SecondL number
    add(ui.getAcSecondL(), ui.getAcSecondL().getConstraints());
    // TitleBar
    add(ui.getAcTitleBar(), ui.getAcTitleBar().getConstraints());
    add(ui.getAcMinimize(), ui.getAcMinimize().getConstraints());
    ui.getAcMinimize().removeActionListener(this);
    ui.getAcMinimize().addActionListener(this);
    add(ui.getAcExit(), ui.getAcExit().getConstraints());
    ui.getAcExit().removeActionListener(this);
    ui.getAcExit().addActionListener(this);
    // DSP
    if (ui.getAcAnalyzer() != null) {
        add(ui.getAcAnalyzer(), ui.getAcAnalyzer().getConstraints());
    }
    // Popup menu
    mainpopup = new JPopupMenu(ui.getResource("popup.title"));
    JMenuItem mi = new JMenuItem(Skin.TITLETEXT + "- JavaZOOM");
    //mi.removeActionListener(this);
    //mi.addActionListener(this);
    mainpopup.add(mi);
    mainpopup.addSeparator();
    JMenu playSubMenu = new JMenu(ui.getResource("popup.play"));
    miPlayFile = new JMenuItem(ui.getResource("popup.play.file"));
    miPlayFile.setActionCommand(PlayerActionEvent.MIPLAYFILE);
    miPlayFile.removeActionListener(this);
    miPlayFile.addActionListener(this);
    miPlayLocation = new JMenuItem(ui.getResource("popup.play.location"));
    miPlayLocation.setActionCommand(PlayerActionEvent.MIPLAYLOCATION);
    miPlayLocation.removeActionListener(this);
    miPlayLocation.addActionListener(this);
    playSubMenu.add(miPlayFile);
    playSubMenu.add(miPlayLocation);
    mainpopup.add(playSubMenu);
    mainpopup.addSeparator();
    miPlaylist = new JCheckBoxMenuItem(ui.getResource("popup.playlist"));
    miPlaylist.setActionCommand(PlayerActionEvent.MIPLAYLIST);
    if (config.isPlaylistEnabled())
        miPlaylist.setState(true);
    miPlaylist.removeActionListener(this);
    miPlaylist.addActionListener(this);
    mainpopup.add(miPlaylist);
    miEqualizer = new JCheckBoxMenuItem(ui.getResource("popup.equalizer"));
    miEqualizer.setActionCommand(PlayerActionEvent.MIEQUALIZER);
    if (config.isEqualizerEnabled())
        miEqualizer.setState(true);
    miEqualizer.removeActionListener(this);
    miEqualizer.addActionListener(this);
    mainpopup.add(miEqualizer);
    mainpopup.addSeparator();
    mi = new JMenuItem(ui.getResource("popup.preferences"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK, false));
    mi.setActionCommand(PlayerActionEvent.MIPREFERENCES);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    mainpopup.add(mi);
    JMenu skinsSubMenu = new JMenu(ui.getResource("popup.skins"));
    mi = new JMenuItem(ui.getResource("popup.skins.browser"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK, false));
    mi.setActionCommand(PlayerActionEvent.MISKINBROWSER);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    skinsSubMenu.add(mi);
    mi = new JMenuItem(ui.getResource("popup.skins.load"));
    mi.setActionCommand(PlayerActionEvent.MILOADSKIN);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    skinsSubMenu.add(mi);
    mainpopup.add(skinsSubMenu);
    JMenu playbackSubMenu = new JMenu(ui.getResource("popup.playback"));
    mi = new JMenuItem(ui.getResource("popup.playback.jump"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, 0, false));
    mi.setActionCommand(PlayerActionEvent.MIJUMPFILE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    playbackSubMenu.add(mi);
    mi = new JMenuItem(ui.getResource("popup.playback.stop"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 0, false));
    mi.setActionCommand(PlayerActionEvent.MISTOP);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    playbackSubMenu.add(mi);
    mainpopup.add(playbackSubMenu);
    mainpopup.addSeparator();
    mi = new JMenuItem(ui.getResource("popup.exit"));
    mi.setActionCommand(PlayerActionEvent.ACEXIT);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    mainpopup.add(mi);
    // Popup menu on TitleBar
    ui.getAcTitleBar().removeMouseListener(popupAdapter);
    popupAdapter = new PopupAdapter(mainpopup);
    ui.getAcTitleBar().addMouseListener(popupAdapter);
    // Popup menu on Eject button
    ejectpopup = new JPopupMenu();
    mi = new JMenuItem(ui.getResource("popup.eject.openfile"));
    mi.setActionCommand(PlayerActionEvent.MIPLAYFILE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    ejectpopup.add(mi);
    mi = new JMenuItem(ui.getResource("popup.eject.openlocation"));
    mi.setActionCommand(PlayerActionEvent.MIPLAYLOCATION);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    ejectpopup.add(mi);
    ui.getAcEject().removeMouseListener(ejectpopupAdapter);
    ejectpopupAdapter = new PopupAdapter(ejectpopup);
    ui.getAcEject().addMouseListener(ejectpopupAdapter);
    // EqualizerUI
    if (equalizerUI != null)
        equalizerUI.loadUI();
    if (playlistUI != null)
        playlistUI.loadUI();
    validate();
    loader.loaded();
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java

protected void updateOrderedShortcuts() {
    InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED);
    for (int i = 0; i < 9; i++) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + i, modifiersMask, false);
        inputMap.remove(keyStroke);/*from  w  ww.  j a  v a2  s  .  co  m*/
    }

    int index = 0;
    for (Action action : actionsOrder) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + index, modifiersMask, false);
        List<KeyStroke> keyStrokes = new LinkedList<>();
        keyStrokes.add(keyStroke);
        keyStrokesMap.put(action, keyStrokes);

        inputMap.put(keyStroke, action.getId());

        index++;
    }
}

From source file:com.github.fritaly.dualcommander.DualCommander.java

public DualCommander() {
    // TODO Generate a fat jar at build time
    super(String.format("Dual Commander %s", Utils.getApplicationVersion()));

    if (logger.isInfoEnabled()) {
        logger.info(String.format("Dual Commander %s", Utils.getApplicationVersion()));
    }/*from   w ww . jav  a  2  s  .com*/

    try {
        // Apply the JGoodies L&F
        UIManager.setLookAndFeel(new WindowsLookAndFeel());
    } catch (Exception e) {
        // Not supposed to happen
    }

    // Layout, columns & rows
    setLayout(new MigLayout("insets 0px", "[grow]0px[grow]", "[grow]0px[]"));

    // Create a menu bar
    final JMenu fileMenu = new JMenu("File");
    fileMenu.add(new JMenuItem(preferencesAction));
    fileMenu.add(new JSeparator());
    fileMenu.add(new JMenuItem(quitAction));

    final JMenu helpMenu = new JMenu("Help");
    helpMenu.add(new JMenuItem(aboutAction));

    final JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(helpMenu);

    setJMenuBar(menuBar);

    this.leftPane = new TabbedPane(preferences);
    this.leftPane.setName("Left");
    this.leftPane.addChangeListener(this);
    this.leftPane.addKeyListener(this);
    this.leftPane.addFocusListener(this);

    this.rightPane = new TabbedPane(preferences);
    this.rightPane.setName("Right");
    this.rightPane.addChangeListener(this);
    this.rightPane.addKeyListener(this);
    this.rightPane.addFocusListener(this);

    // Adding the 2 components to the same sizegroup ensures they always
    // keep the same width
    getContentPane().add(leftPane, "grow, sizegroup g1");
    getContentPane().add(rightPane, "grow, sizegroup g1, wrap");

    // The 7 buttons must all have the same width (they must belong to the
    // same size group)
    final JPanel buttonPanel = new JPanel(
            new MigLayout("insets 0px", StringUtils.repeat("[grow, sizegroup g1]", 7), "[grow]"));
    buttonPanel.add(viewButton, "grow");
    buttonPanel.add(editButton, "grow");
    buttonPanel.add(copyButton, "grow");
    buttonPanel.add(moveButton, "grow");
    buttonPanel.add(mkdirButton, "grow");
    buttonPanel.add(deleteButton, "grow");
    buttonPanel.add(quitButton, "grow");

    getContentPane().add(buttonPanel, "grow, span 2");

    // Register shortcuts at a global level (not on every component)
    final InputMap inputMap = this.leftPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0, true), "view");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0, true), "edit");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true), "copy");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0, true), "move");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0, true), "mkdir");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0, true), "delete");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.ALT_DOWN_MASK), "quit");

    final ActionMap actionMap = this.leftPane.getActionMap();
    actionMap.put("view", viewAction);
    actionMap.put("edit", editAction);
    actionMap.put("copy", copyAction);
    actionMap.put("move", moveAction);
    actionMap.put("mkdir", mkdirAction);
    actionMap.put("delete", deleteAction);
    actionMap.put("quit", quitAction);

    addWindowListener(this);
    addKeyListener(this);

    // Listen to preference change events
    this.preferences.addPropertyChangeListener(this);

    // Reload the last configuration and init the left & right panels
    // accordingly
    final Preferences prefs = Preferences.userNodeForPackage(this.getClass());

    // The user preferences must be loaded first because they're needed to
    // init the UI
    this.preferences.init(prefs.node("user.preferences"));
    this.leftPane.init(prefs.node("left.panel"));
    this.rightPane.init(prefs.node("right.panel"));

    if (logger.isInfoEnabled()) {
        logger.info("Loaded preferences");
    }

    // Init the buttons
    refreshButtons(this.leftPane.getActiveBrowser().getSelection());

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setExtendedState(JFrame.MAXIMIZED_BOTH);

    if (logger.isInfoEnabled()) {
        logger.info("UI initialized");
    }
}

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createCorpusButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("places/folder", IconSize.SMALL);

    String s1 = "Corpus";
    String s2 = "Enter corpus name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);/*w  w  w . java2  s .c  o m*/

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateCorpus", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel corpusNamePanel = new JPanel(new BorderLayout());
    corpusNamePanel.setOpaque(false);

    final JTextField corpusNameField = new JTextField();
    corpusNameField.setDocument(new NameDocument());
    corpusNameField.setText("Corpus Name");
    corpusNamePanel.add(corpusNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewCorpusAct = new PhonUIAction(this, "onCreateCorpus", corpusNameField);
    createNewCorpusAct.putValue(Action.SHORT_DESCRIPTION, "Create new corpus folder");
    createNewCorpusAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewCorpusAct);
    corpusNamePanel.add(createBtn, BorderLayout.EAST);

    corpusNameField.setAction(createNewCorpusAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(corpusNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            corpusNameField.requestFocus();
        }
    });

    return retVal;
}

From source file:net.jradius.client.gui.JRadiusSimulator.java

/**
 * This method initializes jMenuItem//  w w  w  .  ja  va2  s . co  m
 * 
 * @return javax.swing.JMenuItem
 */
private JMenuItem getSaveMenuItem() {
    if (saveMenuItem == null) {
        saveMenuItem = new JMenuItem();
        saveMenuItem.setText("Save");
        saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK, true));
        saveMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (configFileUrl.startsWith("file:///"))
                    saveConfigFile(configFileUrl.substring(7));
                else
                    doSaveAs();
            }
        });
    }
    return saveMenuItem;
}

From source file:net.jradius.client.gui.JRadiusSimulator.java

/**
 * This method initializes jMenuItem/*from w ww . ja  v  a  2  s  .c  o  m*/
 * 
 * @return javax.swing.JMenuItem
 */
private JMenuItem getOpenMenuItem() {
    if (openMenuItem == null) {
        openMenuItem = new JMenuItem();
        openMenuItem.setText("Open");
        openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK, true));
        openMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showOpenDialog(JRadiusSimulator.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = chooser.getSelectedFile();
                    try {
                        loadConfigFile("file:///" + file.getAbsolutePath());
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage(), "Error",
                                JOptionPane.ERROR_MESSAGE);
                        ex.printStackTrace();
                    }
                }
            }
        });
    }
    return openMenuItem;
}

From source file:jchrest.gui.Shell.java

private JMenu createShellMenu() {
    JMenuItem exit = new JMenuItem("Exit", new ImageIcon(Shell.class.getResource("icons/Stop16.gif")));
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);/*  w  ww . j  a  v  a 2  s. c o  m*/
        }
    });

    JMenu menu = new JMenu("Shell");
    menu.setMnemonic(KeyEvent.VK_S);
    menu.add(new AboutAction(this));
    menu.getItem(0).setMnemonic(KeyEvent.VK_A);
    menu.add(new LookFeelAction(this));
    menu.getItem(1).setMnemonic(KeyEvent.VK_T);
    menu.add(new JSeparator());
    menu.add(exit);
    menu.getItem(3).setMnemonic(KeyEvent.VK_X);

    menu.getItem(0).setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.CTRL_MASK, false));
    menu.getItem(3).setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.CTRL_MASK, false));
    return menu;
}

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createSessionButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("mimetypes/text-xml", IconSize.SMALL);

    String s1 = "Session";
    String s2 = "Enter session name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);//from  w  ww .  j  a v a  2s  .c om

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateSession", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel sessionNamePanel = new JPanel(new BorderLayout());
    sessionNamePanel.setOpaque(false);

    final JTextField sessionNameField = new JTextField();
    sessionNameField.setDocument(new NameDocument());
    sessionNameField.setText("Session Name");
    sessionNamePanel.add(sessionNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewSessionAct = new PhonUIAction(this, "onCreateSession", sessionNameField);
    createNewSessionAct.putValue(Action.SHORT_DESCRIPTION, "Create new session in selected corpus");
    createNewSessionAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewSessionAct);
    sessionNamePanel.add(createBtn, BorderLayout.EAST);

    sessionNameField.setAction(createNewSessionAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(sessionNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

        }

        @Override
        public void focusGained(FocusEvent e) {
            sessionNameField.requestFocus();
        }
    });

    return retVal;
}