Java 类javax.swing.DefaultListSelectionModel 实例源码

项目:incubator-netbeans    文件:ProfilerTable.java   
public void setFixedColumnSelection(final int column) {
    if (fixedSelectionColumn == column) return;

    if (column == -1) {
        getColumnModel().setSelectionModel(new DefaultListSelectionModel());
    } else {
        getColumnModel().setSelectionModel(new DefaultListSelectionModel() {
            public void setSelectionInterval(int index0, int index1) {
                int index = convertColumnIndexToView(column);
                super.setSelectionInterval(index, index);
            }
        });
    }

    fixedSelectionColumn = column;
}
项目:JavaGraph    文件:HelpFactory.java   
private JComponent createSyntaxPanel(Logic logic) {
    final JList<String> list = new JList<>();
    DefaultListModel<String> model = new DefaultListModel<>();
    Map<String,String> docMap = FormulaParser.getDocMap(logic);
    for (Map.Entry<String,String> entry : docMap.entrySet()) {
        model.addElement(entry.getKey());
    }
    list.setModel(model);
    list.setCellRenderer(new MyCellRenderer(docMap));
    list.addMouseListener(new DismissDelayer(list));
    list.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            super.setSelectionInterval(-1, -1);
        }
    });
    JPanel result = new JPanel(new BorderLayout());
    result.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
    result.add(new JLabel("<html><b>Syntax:"), BorderLayout.NORTH);
    result.add(new JScrollPane(list), BorderLayout.CENTER);
    return result;
}
项目:JavaGraph    文件:StringDialog.java   
private JComponent createSyntaxPanel() {
    final JList<String> list = new JList<>();
    DefaultListModel<String> model = new DefaultListModel<>();
    for (Map.Entry<String,String> entry : this.docMap.entrySet()) {
        model.addElement(entry.getKey());
    }
    list.setModel(model);
    list.setCellRenderer(new MyCellRenderer(this.docMap));
    list.addMouseListener(new DismissDelayer(list));
    list.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            super.setSelectionInterval(-1, -1);
        }
    });
    JPanel result = new JPanel(new BorderLayout());
    result.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
    result.add(new JLabel("<html><b>Syntax:"), BorderLayout.NORTH);
    result.add(new JScrollPane(list), BorderLayout.CENTER);
    return result;
}
项目:openjdk-jdk10    文件:SelectEditTableCell.java   
private static void createUI(final String lookAndFeelString)
        throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            String[][] data = {{"Foo"}};
            String[] cols = {"One"};
            table = new JTable(data, cols);
            table.setSelectionMode(
                    DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            frame = new JFrame(lookAndFeelString);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(table);
            frame.pack();
            frame.setSize(500, frame.getSize().height);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            frame.toFront();
        }
    });
}
项目:TrackMeIfYouCanChat    文件:NewMulticastFrame.java   
/**
 * Creates new form NewMulticast
 */

public NewMulticastFrame() {
    initComponents();
    jList1.setModel(Client.model1);//set the curent active users
    jList1.setFixedCellWidth(80);
    jList1.setSelectionModel(new DefaultListSelectionModel() {//enable multiple selection without holding ctrl key
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (super.isSelectedIndex(index0)) {
                super.removeSelectionInterval(index0, index1);
            } else {
                super.addSelectionInterval(index0, index1);
            }
        }
    }); 
    this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
    new Heartbeat(Client.nickname,Client.i2p_dest);
}
项目:openjdk9    文件:SelectEditTableCell.java   
private static void createUI(final String lookAndFeelString)
        throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            String[][] data = {{"Foo"}};
            String[] cols = {"One"};
            table = new JTable(data, cols);
            table.setSelectionMode(
                    DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            frame = new JFrame(lookAndFeelString);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(table);
            frame.pack();
            frame.setSize(500, frame.getSize().height);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            frame.toFront();
        }
    });
}
项目:Pac-Man    文件:ObjetiveSelectorPanel.java   
public ObjetiveSelectorPanel(String[] options, int[] indices) {

        listCurrentObjs = new JList<String>(options);
        listCurrentObjs.setVisibleRowCount(4);
        listCurrentObjs.setSelectionModel(new DefaultListSelectionModel() {
            private static final long serialVersionUID = 1L;

            @Override
            public void setSelectionInterval(int index0, int index1) {
                if(super.isSelectedIndex(index0)) {
                    super.removeSelectionInterval(index0, index1);
                }
                else {
                    super.addSelectionInterval(index0, index1);
                }
            }
        });
        listCurrentObjs.setSelectedIndices(indices);

        JScrollPane scrollPane = new JScrollPane(listCurrentObjs);
        add(scrollPane);
    }
项目:jBPMNSuite    文件:OperationPanel.java   
public OperationPanel(ModelerFile file) {
    this(null, true);

    this.file = file;
    definition = (TDefinitions) file.getDefinitionElement();

    error_ListModel = new ErrorListModel();
    error_List.setModel(error_ListModel);
    error_List.setSelectionModel(new DefaultListSelectionModel() {
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0)) {
                super.removeSelectionInterval(index0, index1);
            } else {
                super.addSelectionInterval(index0, index1);
            }
        }
    });

}
项目:GitDirStat    文件:InvertSelectionAction.java   
@Override
public void actionPerformed(ActionEvent e) {
    int size = listModel.getSize();
    listSelectionModel.setValueIsAdjusting(true);
    ListSelectionModelMemento listSelectionModelMemento = new ListSelectionModelMemento();
    listSelectionModelMemento.save(listSelectionModel);
    DefaultListSelectionModel oldSelection = new DefaultListSelectionModel();
    listSelectionModelMemento.restore(oldSelection);

    listSelectionModel.clearSelection();
    for (int i = 0; i < size; i++) {
        if (!oldSelection.isSelectedIndex(i)) {
            listSelectionModel.addSelectionInterval(i, i);
        }
    }
    listSelectionModel.setValueIsAdjusting(false);
}
项目:NBModeler    文件:CustomAttributeEditortest.java   
public CustomAttributeEditortest(Object value, PropertyEditor editor, PropertyEnv env) {
    this.env = env;
    this.editor = editor;
    this.env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
    this.env.addPropertyChangeListener(this);

    initComponents();

    DefaultListSelectionModel dlsm = (DefaultListSelectionModel) this.jTableAttribute.getSelectionModel();
    dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            jTablePropertiesListSelectionValueChanged(e);
        }
    });

    if (value != null && value instanceof Map) {
        this.setPropertiesMap((Map) value);
    } else if (value != null && value instanceof List) {
        this.setPropertiesList((List) value);
    }
}
项目:NBModeler    文件:CustomAttributeEditor.java   
public CustomAttributeEditor(Object value, PropertyEditor editor, PropertyEnv env) {
    this.env = env;
    this.editor = editor;
    this.env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
    this.env.addPropertyChangeListener(this);

    initComponents();

    DefaultListSelectionModel dlsm = (DefaultListSelectionModel) this.jTableAttribute.getSelectionModel();
    dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            jTablePropertiesListSelectionValueChanged(e);
        }
    });

    if (value != null && value instanceof Map) {
        this.setPropertiesMap((Map) value);
    } else if (value != null && value instanceof List) {
        this.setPropertiesList((List) value);
    }
}
项目:swingx    文件:BasicXListUI.java   
public boolean isEnabled(Object c) {
    Object name = getName();
    if (name == SELECT_PREVIOUS_COLUMN_CHANGE_LEAD ||
            name == SELECT_NEXT_COLUMN_CHANGE_LEAD ||
            name == SELECT_PREVIOUS_ROW_CHANGE_LEAD ||
            name == SELECT_NEXT_ROW_CHANGE_LEAD ||
            name == SELECT_FIRST_ROW_CHANGE_LEAD ||
            name == SELECT_LAST_ROW_CHANGE_LEAD ||
            name == SCROLL_UP_CHANGE_LEAD ||
            name == SCROLL_DOWN_CHANGE_LEAD) {

        // discontinuous selection actions are only enabled for
        // DefaultListSelectionModel
        return c != null && ((JList)c).getSelectionModel()
                                instanceof DefaultListSelectionModel;
    }

    return true;
}
项目:swingx    文件:ListSelectionIssues.java   
/**
     * sanity: understand DefaultListSelectionModel behaviour.
     * 
     * Is it allowed that event.getFirstIndex < 0? This happens in 
     * table.clearLeadAnchor
     *
     */
    public void testEventsONLeadAnchorAfterClearSelection() {
        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
        int selected = 5;
        selectionModel.setSelectionInterval(selected, selected);
        assertEquals(selected, selectionModel.getAnchorSelectionIndex());
        assertEquals(selected, selectionModel.getLeadSelectionIndex());
//        selectionModel.setLeadAnchorNotificationEnabled(false);
        ListSelectionReport report = new ListSelectionReport();
        selectionModel.addListSelectionListener(report);
        // following lines are copied from table.clearLeadAnchor()
//        selectionModel.setValueIsAdjusting(true);
        selectionModel.clearSelection();
        assertEquals(1, report.getEventCount());
        assertTrue(report.getLastEvent(false).getFirstIndex() >= 0);
        report.clear();
        selectionModel.setAnchorSelectionIndex(-1);
        assertEquals(1, report.getEventCount());
        assertTrue(report.getLastEvent(false).getFirstIndex() >= 0);
        report.clear();

        selectionModel.setLeadSelectionIndex(-1);
        assertEquals(1, report.getEventCount());
        assertTrue(report.getLastEvent(false).getFirstIndex() >= 0);
        report.clear();
    }
项目:swingx    文件:ListSelectionIssues.java   
/**
 * sanity: understand DefaultListSelectionModel behaviour.
 * 
 * Is it allowed that event.getFirstIndex < 0? This happens in 
 * table.clearLeadAnchor
 *
 */
public void testEventONLeadAnchorAfterClearSelection() {
    DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    int selected = 5;
    selectionModel.setSelectionInterval(selected, selected);
    assertEquals(selected, selectionModel.getAnchorSelectionIndex());
    assertEquals(selected, selectionModel.getLeadSelectionIndex());
    selectionModel.setLeadAnchorNotificationEnabled(false);
    ListSelectionReport report = new ListSelectionReport();
    selectionModel.addListSelectionListener(report);
    // following lines are copied from table.clearLeadAnchor()
    selectionModel.setValueIsAdjusting(true);
    selectionModel.clearSelection();
    selectionModel.setAnchorSelectionIndex(-1);
    selectionModel.setLeadSelectionIndex(-1);
    assertEquals("", 0, report.getEventCount(true));
    selectionModel.setValueIsAdjusting(false);
    ListSelectionEvent event = report.getLastEvent(true);  
    assertEquals(5, event.getFirstIndex());
}
项目:oStorybook    文件:AbstractTable.java   
@Override
public void valueChanged(ListSelectionEvent e) {
    DefaultListSelectionModel selectionModel = (DefaultListSelectionModel) e.getSource();
    int count = selectionModel.getMaxSelectionIndex() - selectionModel.getMinSelectionIndex() + 1;
    if (count > 1) {
        btEdit.setEnabled(false);
        btCopy.setEnabled(false);
        btDelete.setEnabled(allowMultiDelete);
        if (hasOrder) {
            btOrderUp.setEnabled(false);
            btOrderDown.setEnabled(false);
        }
        return;
    }
    int row = selectionModel.getMinSelectionIndex();
    AbstractEntity entity = getEntityFromRow(row);
    boolean b=true;
    if (entity == null) b=false;
    btEdit.setEnabled(b);
    btCopy.setEnabled(b);
    btDelete.setEnabled(b);
    if (hasOrder) {
        btOrderUp.setEnabled(b);
        btOrderDown.setEnabled(b);
    }
}
项目:SE-410-Project    文件:AbstractTable.java   
@Override
public void valueChanged(ListSelectionEvent e) {
    DefaultListSelectionModel selectionModel = (DefaultListSelectionModel) e.getSource();
    int count = selectionModel.getMaxSelectionIndex() - selectionModel.getMinSelectionIndex() + 1;
    if (count > 1) {
        btEdit.setEnabled(false);
        btCopy.setEnabled(false);
        btDelete.setEnabled(allowMultiDelete);
        if (hasOrder) {
            btOrderUp.setEnabled(false);
            btOrderDown.setEnabled(false);
        }
        return;
    }
    int row = selectionModel.getMinSelectionIndex();
    AbstractEntity entity = getEntityFromRow(row);
    boolean b=true;
    if (entity == null) b=false;
    btEdit.setEnabled(b);
    btCopy.setEnabled(b);
    btDelete.setEnabled(b);
    if (hasOrder) {
        btOrderUp.setEnabled(b);
        btOrderDown.setEnabled(b);
    }
}
项目:GitDirStat    文件:InvertSelectionAction.java   
@Override
public void actionPerformed(ActionEvent e) {
    int size = listModel.getSize();
    listSelectionModel.setValueIsAdjusting(true);
    ListSelectionModelMemento listSelectionModelMemento = new ListSelectionModelMemento();
    listSelectionModelMemento.save(listSelectionModel);
    DefaultListSelectionModel oldSelection = new DefaultListSelectionModel();
    listSelectionModelMemento.restore(oldSelection);

    listSelectionModel.clearSelection();
    for (int i = 0; i < size; i++) {
        if (!oldSelection.isSelectedIndex(i)) {
            listSelectionModel.addSelectionInterval(i, i);
        }
    }
    listSelectionModel.setValueIsAdjusting(false);
}
项目:ireport-fork    文件:JRPropertiesMapPropertyCustomEditor.java   
public JRPropertiesMapPropertyCustomEditor (Object value, PropertyEditor editor, PropertyEnv env) {
    this.env = env;
    this.editor = editor;
    this.env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
    this.env.addPropertyChangeListener(this);

    initComponents();

    DefaultListSelectionModel dlsm =  (DefaultListSelectionModel)this.jTableProperties.getSelectionModel();
    dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e)  {
            jTablePropertiesListSelectionValueChanged(e);
        }
    });  

    if (value instanceof JRPropertiesMap && value != null)
    {
        setPropertiesMap((JRPropertiesMap)value);
    }
    else if (value instanceof List && value != null)
    {
        setPropertiesList((List)value);
    }
}
项目:ireport-fork    文件:JRImportsPropertyCustomEditor.java   
public JRImportsPropertyCustomEditor (Object value, PropertyEditor editor, PropertyEnv env) {
    this.env = env;
    this.editor = editor;
    this.env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
    this.env.addPropertyChangeListener(this);

    initComponents();

    DefaultListSelectionModel dlsm =  (DefaultListSelectionModel)this.jTableProperties.getSelectionModel();
    dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e)  {
            jTablePropertiesListSelectionValueChanged(e);
        }
    });  

    if (value != null && value.getClass().isArray() && value.getClass().getComponentType().equals(String.class))
    {
        setImports((String[])value);
    }
}
项目:ireport-fork    文件:MeterIntervalsPanel.java   
private void jButtonMoveUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveUpActionPerformed
    if (jTable1.getSelectedRow() > 0) {
        DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
        int[] indices = jTable1.getSelectedRows();
        for (int i=indices.length-1; i>=0; --i) {
            if (indices[i] == 0) continue;

            Object val = jTable1.getValueAt( indices[i], 0);
            dtm.removeRow(indices[i]);
            dtm.insertRow(indices[i]-1, new Object[5]  );
            setRowValues( (JRMeterInterval)val, indices[i]-1);
            indices[i]--;
        }

        DefaultListSelectionModel dlsm = (DefaultListSelectionModel)jTable1.getSelectionModel();
        dlsm.setValueIsAdjusting(true);
        dlsm.clearSelection();
        for (int i=0; i<indices.length; ++i) {
            dlsm.addSelectionInterval(indices[i],  indices[i]);
        }
        dlsm.setValueIsAdjusting( false );
    }
}
项目:ireport-fork    文件:MeterIntervalsPanel.java   
private void jButtonMoveDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveDownActionPerformed
    if (jTable1.getSelectedRowCount() > 0) {
        DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
        int[] indices = jTable1.getSelectedRows();
        for (int i=indices.length-1; i>=0; --i) {
            if (indices[i] >= (jTable1.getRowCount() -1)) continue;

            Object val = jTable1.getValueAt( indices[i], 0);
            dtm.removeRow(indices[i]);
            dtm.insertRow(indices[i]+1, new Object[5]  );
            setRowValues( (JRMeterInterval)val, indices[i]+1);
            indices[i]++;
        }

        DefaultListSelectionModel dlsm = (DefaultListSelectionModel)jTable1.getSelectionModel();
        dlsm.setValueIsAdjusting(true);
        dlsm.clearSelection();
        for (int i=0; i<indices.length; ++i) {
            dlsm.addSelectionInterval(indices[i],  indices[i]);
        }
        dlsm.setValueIsAdjusting( false );
    }
}
项目:ireport-fork    文件:ListOfValuesDialog.java   
private void jButtonUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpActionPerformed
    if (jTableLOV.getSelectedRow() >= 0)
    {
        DefaultTableModel dtm = (DefaultTableModel)jTableLOV.getModel();
        int[] indices = jTableLOV.getSelectedRows();
        for (int i=0; i<indices.length; ++i)
        {
            if (indices[i] == 0) continue;
            dtm.moveRow(indices[i], indices[i],  indices[i]-1);
            ((DefaultListSelectionModel)jTableLOV.getSelectionModel()).removeIndexInterval(indices[i],indices[i]);
            indices[i]--;
            ((DefaultListSelectionModel)jTableLOV.getSelectionModel()).addSelectionInterval(indices[i],indices[i]);

        }
    }
}
项目:svarog    文件:CheckBoxList.java   
/**
 * Constructor. Creates and initializes new CheckBoxList.
 */
public CheckBoxList() {
    super();

    setCellRenderer(new CheckBoxListCellRenderer());
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    setSelectionModel(new DefaultListSelectionModel() {

        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (super.isSelectedIndex(index0)) {
                super.removeSelectionInterval(index0, index1);
            } else {
                super.addSelectionInterval(index0, index1);
            }
        }
    });
}
项目:findbugs-all-the-bugs    文件:SorterTableColumnModel.java   
public SorterTableColumnModel(Sortables[] columnHeaders) {

        MainFrame mainFrame = MainFrame.getInstance();
        int x = 0;
        for (Sortables c : columnHeaders) {
            if (!c.isAvailable(mainFrame))
                continue;
            shown.add(c);

            TableColumn tc = makeTableColumn(x, c);
            columnList.add(tc);
            x++;
        }
        dlsm = new DefaultListSelectionModel();
        dlsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        orderUpdate();
        check();
    }
项目:r2cat    文件:MatchesTable.java   
@Override
public void valueChanged(ListSelectionEvent e) {
    super.valueChanged(e);

    // avoid interference with the update method.
    if (!selectionByUpdate) {
        // wait until the selection has settled
        if (!e.getValueIsAdjusting()) {
            DefaultListSelectionModel lsm = (DefaultListSelectionModel) e
                    .getSource();

            int modelIndex;
            for (int i = 0; i < matches.size(); i++) {
                modelIndex = this.convertRowIndexToModel(i);
                matches.getMatchAt(modelIndex).setSelected(
                        lsm.isSelectedIndex(i));
            }
            matches.markQueriesWithSelectedAps();
            this.ignoreUpdate = true;
            matches.notifyObservers(NotifyEvent.MARK);
            this.ignoreUpdate = false;
        }

    }
}
项目:r2cat    文件:PrimerTable.java   
@Override
public void valueChanged(ListSelectionEvent e) {
    super.valueChanged(e);

    // avoid interference with the update method.
    if (!selectionByUpdate) {
        // wait until the selection has settled
        if (!e.getValueIsAdjusting()) {
            matches.unmarkAllAlignments();
            matches.unmarkAllQueries();

            DefaultListSelectionModel lsm = (DefaultListSelectionModel) e
                    .getSource();

            int modelIndex = 0;
            for (int i = 0; i < matches.getQueries().size(); i++) {
                modelIndex = this.convertRowIndexToModel(i);
                matches.markQuery(modelIndex, lsm.isSelectedIndex(i));
            }
            this.ignoreUpdate = true;
            matches.notifyObservers(NotifyEvent.MARK);
            this.ignoreUpdate = false;
        }

    }
}
项目:r2cat    文件:SequenceOrderTable.java   
@Override
public void valueChanged(ListSelectionEvent e) {
    super.valueChanged(e);

    // avoid interference with the update method.
    if (!selectionByUpdate) {
        // wait until the selection has settled
        if (!e.getValueIsAdjusting()) {
            matches.unmarkAllAlignments();
            matches.unmarkAllQueries();

            DefaultListSelectionModel lsm = (DefaultListSelectionModel) e
                    .getSource();

            int modelIndex = 0;
            for (int i = 0; i < matches.getQueries().size(); i++) {
                modelIndex = this.convertRowIndexToModel(i);
                matches.markQuery(modelIndex, lsm.isSelectedIndex(i));
            }
            this.ignoreUpdate = true;
            matches.notifyObservers(NotifyEvent.MARK);
            this.ignoreUpdate = false;
        }

    }
}
项目:SmartStocks    文件:StockAnalysisPanel.java   
public void valueChanged(ListSelectionEvent e) {
    DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource();
    ListSelectionListener[] listListeners = source.getListSelectionListeners();

    Boolean valueIsAdjusting = e.getValueIsAdjusting();

    // Check which table changed value
    if (source == stockSymbolTableSelectionModel) {
        if (source.isSelectionEmpty()) {
            predictButton_prediction.setEnabled(false);
            plotStockButton_predict.setEnabled(false);
        } else if (valueIsAdjusting == false) {
            predictButton_prediction.setEnabled(true);
            plotStockButton_predict.setEnabled(true);
        }
    } else {
        if (source.isSelectionEmpty()) {
            deleteSymbolButton_Management_Symbols.setEnabled(false);
        } else {
            deleteSymbolButton_Management_Symbols.setEnabled(true);
        }
    }
}
项目:desktopclient-java    文件:ComponentUtils.java   
@SuppressWarnings("unchecked")
ParticipantsList() {
    mModel = new DefaultListModel<>();
    this.setModel(mModel);
    this.setFixedCellHeight(25);

    this.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if(super.isSelectedIndex(index0)) {
                super.removeSelectionInterval(index0, index1);
            } else {
                super.addSelectionInterval(index0, index1);
            }
        }
    });

    this.setCellRenderer(new CellRenderer());
}
项目:desktopclient-java    文件:ComponentUtils.java   
@SuppressWarnings("unchecked")
MemberList(boolean selectable) {
    mModel = new DefaultListModel<>();
    this.setModel(mModel);
    this.setFixedCellHeight(25);

    this.setEnabled(selectable);
    if (selectable) {
        this.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        this.setSelectionModel(new DefaultListSelectionModel() {
            @Override
            public void setSelectionInterval(int index0, int index1) {
                if(super.isSelectedIndex(index0)) {
                    super.removeSelectionInterval(index0, index1);
                } else {
                    super.addSelectionInterval(index0, index1);
                }
            }
        });
    }

    this.setCellRenderer(new CellRenderer());
}
项目:pdm-viewer    文件:TableInfoPanel.java   
private void initEvents() {
    // item selection
    this.modelTable.getSelectionModel().addListSelectionListener(
            new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    // show comment
                    DefaultListSelectionModel lse = (DefaultListSelectionModel) e
                            .getSource();
                    if (lse.getMinSelectionIndex() > -1
                            && lse.getMinSelectionIndex() <= tm.getCols()
                                    .size()) {
                        ColumnModel colMod = tm.getCols().get(
                                lse.getMinSelectionIndex());
                        commentTa.setText(colMod.getComment());
                        commentTa.updateUI();
                    }
                }
            });
}
项目:sweetsnake    文件:PlayersList.java   
/**
 * 
 */
public PlayersList() {
    super();

    setSelectionModel(new DefaultListSelectionModel() {

        /** The serial version UID */
        private static final long serialVersionUID = 3305919865692499917L;

        /*
         * (non-Javadoc)
         * 
         * @see javax.swing.DefaultListSelectionModel#setSelectionInterval(int, int)
         */
        @Override
        public void setSelectionInterval(final int index0, final int index1) {
            if (super.isSelectedIndex(index0)) {
                super.removeSelectionInterval(index0, index1);
            } else {
                super.addSelectionInterval(index0, index1);
            }
        }
    });
}
项目:TerraJ    文件:CameraPosDialog.java   
public void valueChanged(ListSelectionEvent e)
{
    final DefaultListSelectionModel dlsm =
        (DefaultListSelectionModel) cameraTable.getSelectionModel();
    final CameraTableModel model =
        (CameraTableModel) cameraTable.getModel();

    // can always delete or goto if something is selected
    deleteButton.setEnabled(!dlsm.isSelectionEmpty());
    gotoButton.setEnabled(!dlsm.isSelectionEmpty());

    // can only move up / down if not already at top or bottom
    if (dlsm.isSelectionEmpty())
    {
        upButton.setEnabled(false);
        downButton.setEnabled(false);
    }
    else
    {
        upButton.setEnabled(dlsm.getMinSelectionIndex() > 0);
        downButton.setEnabled(
            dlsm.getMinSelectionIndex() < (model.getRowCount() - 1));
    }
}
项目:TerraJ    文件:CameraPosDialog.java   
/**
 * Creates new form CameraPosDialog
 *
 * @param parent The parent object for this form
 * @param modal Indicates whether this is a modal dialog
 */
public CameraPosDialog(AbstractTerrainViewerFrame parent, boolean modal)
{
    super(parent, modal);
    initComponents();

    final DefaultListSelectionModel dlsm =
        (DefaultListSelectionModel) cameraTable.getSelectionModel();

    dlsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dlsm.addListSelectionListener(new MySelectionListener());
    cameraTable.addMouseListener(new MyMouseListener());

    ((DefaultCellEditor) cameraTable.getDefaultEditor(String.class)).setClickCountToStart(
        1);
}
项目:incubator-netbeans    文件:TaskModel.java   
TaskModel(Executor eventExecutor) {
    selectionModel = new DefaultListSelectionModel();
    model = new DefaultListModel();
    dataListeners = new LinkedHashSet<ListDataListener>();
    selectionListeners = new LinkedHashSet<ListSelectionListener>();
    TaskListener list = new TaskListener();
    model.addListDataListener(list);
    selectionModel.addListSelectionListener(list);
    this.eventExecutor = eventExecutor;
}
项目:PackagePlugin    文件:MainFrame.java   
/**
 * 表选择事件处理
 * <p>
 * @param e
 */
public void tableValueChanged(ListSelectionEvent e) {
    DefaultListSelectionModel t = (DefaultListSelectionModel) e.getSource();
    if (t.equals(tablesList.getSelectionModel())) {
        try {
            if (tablesList.getSelectedRowCount() <= 0) {
                return;
            }
            String info1 = "当前数据库:" + lastDatabase;
            info1 += " 共计" + tablesList.getModel().getRowCount() + "张表";
            info1 += "共选中表" + tablesList.getSelectedRowCount() + "(未选中时将当前数据库所有表进行生成)";
            databaseInfoBar.setText(info1);
        } catch (Exception ex) {
            showIbatisInfo(ex.getLocalizedMessage());
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    } else if (t.equals(detailTable.getSelectionModel())) {
        if (detailTable.getSelectedRowCount() > 0 && e.getValueIsAdjusting()) {
            statusLabel.setText("共选择了" + logTable.getSelectedRowCount() + "条日志,共选择了" + detailTable.getSelectedRowCount() + "个文件(不选择默认全部[" + detailTable.getRowCount() + "])");
        }
    } else if (t.equals(logTable.getSelectionModel())) {
        if (logTable.getSelectedRowCount() > 0 && e.getValueIsAdjusting()) {
            int[] cols = logTable.getSelectedRows();
            DefaultTableModel mod = (DefaultTableModel) detailTable.getModel();
            mod.setRowCount(0);
            Map<String, SVNLogEntryPath> map = new HashMap<>();
            for (int i : cols) {
                i = logTable.convertRowIndexToModel(i);//排序后要转移行号
                Object key1 = logTable.getModel().getValueAt(i, 1);
                map.putAll(detailData.get(Long.valueOf(key1.toString())));
            }
            for (Map.Entry<String, SVNLogEntryPath> entrySet : map.entrySet()) {
                SVNLogEntryPath path1 = entrySet.getValue();
                mod.addRow(new Object[]{path1.getPath(), getType(path1.getType()), path1.getCopyPath(), getCopyRevision(path1.getCopyRevision())});
            }
            statusLabel.setText("共选择了" + logTable.getSelectedRowCount() + "条日志,共选择了" + detailTable.getSelectedRowCount() + "个文件(不选择默认全部[" + detailTable.getRowCount() + "])");
        }
    }
}
项目:OpenJSharp    文件:DefaultTreeSelectionModel.java   
/**
 * Creates a new instance of DefaultTreeSelectionModel that is
 * empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.
 */
public DefaultTreeSelectionModel() {
    listSelectionModel = new DefaultListSelectionModel();
    selectionMode = DISCONTIGUOUS_TREE_SELECTION;
    leadIndex = leadRow = -1;
    uniquePaths = new Hashtable<TreePath, Boolean>();
    lastPaths = new Hashtable<TreePath, Boolean>();
    tempPaths = new TreePath[1];
}
项目:OpenJSharp    文件:DefaultTreeSelectionModel.java   
/**
 * Makes sure the currently selected <code>TreePath</code>s are valid
 * for the current selection mode.
 * If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code>
 * and a <code>RowMapper</code> exists, this will make sure all
 * the rows are contiguous, that is, when sorted all the rows are
 * in order with no gaps.
 * If the selection isn't contiguous, the selection is
 * reset to contain the first set, when sorted, of contiguous rows.
 * <p>
 * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and
 * more than one TreePath is selected, the selection is reset to
 * contain the first path currently selected.
 */
protected void insureRowContinuity() {
    if(selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION &&
       selection != null && rowMapper != null) {
        DefaultListSelectionModel lModel = listSelectionModel;
        int                       min = lModel.getMinSelectionIndex();

        if(min != -1) {
            for(int counter = min,
                    maxCounter = lModel.getMaxSelectionIndex();
                    counter <= maxCounter; counter++) {
                if(!lModel.isSelectedIndex(counter)) {
                    if(counter == min) {
                        clearSelection();
                    }
                    else {
                        TreePath[] newSel = new TreePath[counter - min];
                        int selectionIndex[] = rowMapper.getRowsForPaths(selection);
                        // find the actual selection pathes corresponded to the
                        // rows of the new selection
                        for (int i = 0; i < selectionIndex.length; i++) {
                            if (selectionIndex[i]<counter) {
                                newSel[selectionIndex[i]-min] = selection[i];
                            }
                        }
                        setSelectionPaths(newSel);
                        break;
                    }
                }
            }
        }
    }
    else if(selectionMode == TreeSelectionModel.SINGLE_TREE_SELECTION &&
            selection != null && selection.length > 1) {
        setSelectionPath(selection[0]);
    }
}
项目:jdk8u-jdk    文件:DefaultTreeSelectionModel.java   
/**
 * Creates a new instance of DefaultTreeSelectionModel that is
 * empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.
 */
public DefaultTreeSelectionModel() {
    listSelectionModel = new DefaultListSelectionModel();
    selectionMode = DISCONTIGUOUS_TREE_SELECTION;
    leadIndex = leadRow = -1;
    uniquePaths = new Hashtable<TreePath, Boolean>();
    lastPaths = new Hashtable<TreePath, Boolean>();
    tempPaths = new TreePath[1];
}
项目:jdk8u-jdk    文件:DefaultTreeSelectionModel.java   
/**
 * Makes sure the currently selected <code>TreePath</code>s are valid
 * for the current selection mode.
 * If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code>
 * and a <code>RowMapper</code> exists, this will make sure all
 * the rows are contiguous, that is, when sorted all the rows are
 * in order with no gaps.
 * If the selection isn't contiguous, the selection is
 * reset to contain the first set, when sorted, of contiguous rows.
 * <p>
 * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and
 * more than one TreePath is selected, the selection is reset to
 * contain the first path currently selected.
 */
protected void insureRowContinuity() {
    if(selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION &&
       selection != null && rowMapper != null) {
        DefaultListSelectionModel lModel = listSelectionModel;
        int                       min = lModel.getMinSelectionIndex();

        if(min != -1) {
            for(int counter = min,
                    maxCounter = lModel.getMaxSelectionIndex();
                    counter <= maxCounter; counter++) {
                if(!lModel.isSelectedIndex(counter)) {
                    if(counter == min) {
                        clearSelection();
                    }
                    else {
                        TreePath[] newSel = new TreePath[counter - min];
                        int selectionIndex[] = rowMapper.getRowsForPaths(selection);
                        // find the actual selection pathes corresponded to the
                        // rows of the new selection
                        for (int i = 0; i < selectionIndex.length; i++) {
                            if (selectionIndex[i]<counter) {
                                newSel[selectionIndex[i]-min] = selection[i];
                            }
                        }
                        setSelectionPaths(newSel);
                        break;
                    }
                }
            }
        }
    }
    else if(selectionMode == TreeSelectionModel.SINGLE_TREE_SELECTION &&
            selection != null && selection.length > 1) {
        setSelectionPath(selection[0]);
    }
}