List of usage examples for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION
int MULTIPLE_INTERVAL_SELECTION
To view the source code for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.
Click Source Link
From source file:ro.nextreports.designer.querybuilder.SelectionColumnPanel.java
private void buildUI() { setLayout(new GridBagLayout()); final DBViewer viewer = Globals.getDBViewer(); schemaCombo = new JComboBox(); schemaCombo.setPreferredSize(comboDim); schemaCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { String schema = (String) e.getItem(); shownColumnModel.clear();/*from ww w . jav a2 s . c o m*/ columnModel.clear(); tableModel.clear(); try { DBInfo dbInfo = viewer.getDBInfo(schema, DBInfo.TABLES | DBInfo.VIEWS); List<DBTable> tables = dbInfo.getTables(); Collections.sort(tables); for (DBTable table : tables) { tableModel.addElement(table); } } catch (NextSqlException ex) { LOG.error(ex.getMessage(), ex); ex.printStackTrace(); } } }); try { List<String> schemas = viewer.getSchemas(); String schemaName = viewer.getUserSchema(); Collections.sort(schemas); boolean added = false; for (String schema : schemas) { if (DefaultSchemaManager.getInstance().isVisible( DefaultDataSourceManager.getInstance().getConnectedDataSource().getName(), schema)) { added = true; schemaCombo.addItem(schema); } } if ((schema == null) || schema.equals(DefaultDBViewer.NO_SCHEMA_NAME)) { schema = DefaultDBViewer.NO_SCHEMA_NAME;//viewer.getUserSchema(); } if (!added) { schemaCombo.addItem(schema); } schemaCombo.setSelectedItem(schema); } catch (NextSqlException e) { LOG.error(e.getMessage(), e); e.printStackTrace(); } // create table list tableList = new JXList(tableModel); tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableList.setCellRenderer(new DBTableCellRenderer()); // create column list columnList = new JXList(columnModel); if (singleSelection) { columnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } columnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList = new JXList(shownColumnModel); if (singleSelection) { shownColumnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } addDoubleClick(); shownColumnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { if ((mouseEvent.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(new DeselectListAction(shownColumnList)); popupMenu.add(menuItem); popupMenu.show((Component) mouseEvent.getSource(), mouseEvent.getX(), mouseEvent.getY()); } } }); tableList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { int index = tableList.getSelectedIndex(); if (index == -1) { return; } DBTable table = (DBTable) tableModel.getElementAt(index); try { List<DBColumn> columns = null; try { columns = viewer.getColumns(table.getSchema(), table.getName()); } catch (MalformedTableNameException e1) { Show.error("Malformed table name : " + table.getName()); return; } Collections.sort(columns); columnModel.clear(); shownColumnModel.clear(); for (DBColumn column : columns) { columnModel.addElement(column); shownColumnModel.addElement(column); } } catch (NextSqlException e1) { LOG.error(e1.getMessage(), e1); e1.printStackTrace(); Show.error(e1); } } } }); columnList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { shownColumnList.clearSelection(); } }); scrTable = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrTable.setPreferredSize(scrDim); scrTable.setMinimumSize(scrDim); scrTable.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.tables"))); scrColumn = new JScrollPane(columnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrColumn.setPreferredSize(scrDim); scrColumn.setMinimumSize(scrDim); scrColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.columns"))); scrShownColumn = new JScrollPane(shownColumnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrShownColumn.setPreferredSize(scrDim); scrShownColumn.setMinimumSize(scrDim); scrShownColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.shown.columns"))); JPanel schemaPanel = new JPanel(); schemaPanel.setLayout(new BoxLayout(schemaPanel, BoxLayout.X_AXIS)); schemaPanel.add(new JLabel("Schema")); schemaPanel.add(Box.createHorizontalStrut(5)); schemaPanel.add(schemaCombo); add(schemaPanel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(scrTable, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); add(scrColumn, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); if (show) { add(scrShownColumn, new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Setup instance components//w w w . j a v a 2s. co m */ private void setupComponents() { table = new JTable(); cellRenderer = new ColoredCellRenderer(); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setColumnSelectionAllowed(true); table.setRowSelectionAllowed(true); table.setCellSelectionEnabled(true); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDefaultRenderer(new Object().getClass(), cellRenderer); table.getTableHeader().setToolTipText(Resources.getString("tipClickHeaderToSort")); maxRows = new JComboBox(); maxRows.setEditable(false); ((DefaultComboBoxModel) maxRows.getModel()).addElement(Resources.getString("proNoLimit")); ((DefaultComboBoxModel) maxRows.getModel()).addElement("50"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("100"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("500"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("1000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("5000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("10000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("20000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("30000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("50000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("100000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("200000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("500000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("1000000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("1500000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("2000000"); ((DefaultComboBoxModel) maxRows.getModel()).addElement("3000000"); maxRows.setSelectedItem("100"); }
From source file:xtrememp.PlaylistManager.java
private void initComponents() { JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false);/*from ww w . ja v a 2 s. co 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); }