List of usage examples for javax.swing SwingUtilities isRightMouseButton
public static boolean isRightMouseButton(MouseEvent anEvent)
From source file:xtrememp.PlaylistManager.java
private void initComponents() { JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false);/* w ww .j a v a 2 s . c o m*/ openPlaylistButton = new JButton(Utilities.DOCUMENT_OPEN_ICON); openPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.OpenPlaylist")); openPlaylistButton.addActionListener(this); toolBar.add(openPlaylistButton); savePlaylistButton = new JButton(Utilities.DOCUMENT_SAVE_ICON); savePlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.SavePlaylist")); savePlaylistButton.addActionListener(this); toolBar.add(savePlaylistButton); toolBar.addSeparator(); addToPlaylistButton = new JButton(Utilities.LIST_ADD_ICON); addToPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.AddToPlaylist")); addToPlaylistButton.addActionListener(this); toolBar.add(addToPlaylistButton); remFromPlaylistButton = new JButton(Utilities.LIST_REMOVE_ICON); remFromPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.RemoveFromPlaylist")); remFromPlaylistButton.addActionListener(this); remFromPlaylistButton.setEnabled(false); toolBar.add(remFromPlaylistButton); clearPlaylistButton = new JButton(Utilities.EDIT_CLEAR_ICON); clearPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.ClearPlaylist")); clearPlaylistButton.addActionListener(this); clearPlaylistButton.setEnabled(false); toolBar.add(clearPlaylistButton); toolBar.addSeparator(); moveUpButton = new JButton(Utilities.GO_UP_ICON); moveUpButton.setToolTipText(tr("MainFrame.PlaylistManager.MoveUp")); moveUpButton.addActionListener(this); moveUpButton.setEnabled(false); toolBar.add(moveUpButton); moveDownButton = new JButton(Utilities.GO_DOWN_ICON); moveDownButton.setToolTipText(tr("MainFrame.PlaylistManager.MoveDown")); moveDownButton.addActionListener(this); moveDownButton.setEnabled(false); toolBar.add(moveDownButton); toolBar.addSeparator(); mediaInfoButton = new JButton(Utilities.MEDIA_INFO_ICON); mediaInfoButton.setToolTipText(tr("MainFrame.PlaylistManager.MediaInfo")); mediaInfoButton.addActionListener(this); mediaInfoButton.setEnabled(false); toolBar.add(mediaInfoButton); toolBar.add(Box.createHorizontalGlue()); searchTextField = new SearchTextField(15); searchTextField.setMaximumSize(new Dimension(120, searchTextField.getPreferredSize().height)); searchTextField.getTextField().getDocument().addDocumentListener(new SearchFilterListener()); toolBar.add(searchTextField); toolBar.add(Box.createHorizontalStrut(6)); this.add(toolBar, BorderLayout.NORTH); playlistTable = new JTable(playlistTableModel, playlistTableColumnModel); playlistTable.setDefaultRenderer(String.class, new PlaylistCellRenderer()); playlistTable.setActionMap(null); playlistTable.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { if (SwingUtilities.isRightMouseButton(ev) || (MouseInfo.getNumberOfButtons() == 1 && ev.isControlDown())) { playlistTableColumnModel.getPopupMenu().show(playlistTable.getTableHeader(), ev.getX(), ev.getY()); return; } int clickedColumn = playlistTableColumnModel.getColumnIndexAtX(ev.getX()); PlaylistTableColumn playlistColumn = playlistTableColumnModel.getColumn(clickedColumn); playlistTableColumnModel.resetAll(playlistColumn.getModelIndex()); playlistColumn.setSortOrderUp(!playlistColumn.isSortOrderUp()); playlistTableModel.sort(playlistColumn.getComparator()); colorizeRow(); } }); playlistTable.setFillsViewportHeight(true); playlistTable.setShowGrid(false); playlistTable.setRowSelectionAllowed(true); playlistTable.setColumnSelectionAllowed(false); playlistTable.setDragEnabled(false); playlistTable.setFont(playlistTable.getFont().deriveFont(Font.BOLD)); playlistTable.setIntercellSpacing(new Dimension(0, 0)); playlistTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); playlistTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { int selectedRow = playlistTable.rowAtPoint(ev.getPoint()); if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) { if (selectedRow != -1) { playlist.setCursorPosition(selectedRow); controlListener.acOpenAndPlay(); } } } }); playlistTable.getSelectionModel().addListSelectionListener(this); playlistTable.getColumnModel().getSelectionModel().addListSelectionListener(this); playlistTable.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // View Media Info if (e.getKeyCode() == KeyEvent.VK_I && e.getModifiers() == KeyEvent.CTRL_MASK) { viewMediaInfo(); } // Select all else if (e.getKeyCode() == KeyEvent.VK_A && e.getModifiers() == KeyEvent.CTRL_MASK) { playlistTable.selectAll(); } else if (e.getKeyCode() == KeyEvent.VK_UP) { // Move selected track(s) up if (e.getModifiers() == KeyEvent.ALT_MASK) { moveUp(); } // Select previous track else { if (playlistTable.getSelectedRow() > 0) { int previousRowIndex = playlistTable.getSelectedRow() - 1; playlistTable.clearSelection(); playlistTable.addRowSelectionInterval(previousRowIndex, previousRowIndex); makeRowVisible(previousRowIndex); } } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { // Move selected track(s) down if (e.getModifiers() == KeyEvent.ALT_MASK) { moveDown(); } // Select next track else { if (playlistTable.getSelectedRow() < playlistTable.getRowCount() - 1) { int nextRowIndex = playlistTable.getSelectedRow() + 1; playlistTable.clearSelection(); playlistTable.addRowSelectionInterval(nextRowIndex, nextRowIndex); makeRowVisible(nextRowIndex); } } } // Play selected track else if (e.getKeyCode() == KeyEvent.VK_ENTER) { int selectedRow = playlistTable.getSelectedRow(); if (selectedRow != -1) { playlist.setCursorPosition(selectedRow); controlListener.acOpenAndPlay(); } } // Add new tracks else if (e.getKeyCode() == KeyEvent.VK_INSERT) { addFilesDialog(false); } // Delete selected tracks else if (e.getKeyCode() == KeyEvent.VK_DELETE) { remove(); } } }); XtremeMP.getInstance().getMainFrame().setDropTarget(new DropTarget(playlistTable, this)); JScrollPane ptScrollPane = new JScrollPane(playlistTable); ptScrollPane.setActionMap(null); this.add(ptScrollPane, BorderLayout.CENTER); }