类javax.swing.DefaultListSelectionModel源码实例Demo

下面列出了怎么用javax.swing.DefaultListSelectionModel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: pcgen   文件: AbilityChooserTab.java
public Hashtable<Object, Object> createState(CharacterFacade character,
	ListFacade<AbilityCategory> categories, ListFacade<AbilityCategory> fullCategoryList, String title)
{
	Hashtable<Object, Object> state = new Hashtable<>();
	CategoryTableModel categoryTableModel =
			new CategoryTableModel(character, fullCategoryList, categoryBar, categoryTable);
	state.put(CategoryTableModel.class, categoryTableModel);

	ListSelectionModel listModel = new DefaultListSelectionModel();
	listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	state.put(ListSelectionModel.class, listModel);
	state.put(AbilityTreeTableModel.class, new AbilityTreeTableModel(character, categories));
	state.put(AvailableAbilityTreeViewModel.class, new AvailableAbilityTreeViewModel(character, listModel, title));
	state.put(InfoHandler.class, new InfoHandler(character));
	state.put(TreeRendererHandler.class, new TreeRendererHandler(character));
	state.put(AddAction.class, new AddAction(character));
	state.put(RemoveAction.class, new RemoveAction(character));
	state.put(AbilityFilterHandler.class, new AbilityFilterHandler(character));
	state.put(CategoryFilterHandler.class, new CategoryFilterHandler(categoryTableModel));
	return state;
}
 
源代码2 项目: snap-desktop   文件: EndmemberFormModel.java
public EndmemberFormModel(AppContext appContext) {
    this.appContext = appContext;
    endmemberListModel = new DefaultListModel<>();
    endmemberListSelectionModel = new DefaultListSelectionModel();
    endmemberListSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    endmemberListModel.addListDataListener(new EndmemberListDataListener());
    endmemberListSelectionModel.addListSelectionListener(new EndmemberListSelectionListener());
    addAction = new AddAction();
    removeAction = new RemoveAction();
    clearAction = new ClearAction();
    exportAction = new ExportAction();
    endmemberDiagram = new Diagram();
    endmemberDiagram.setXAxis(new DiagramAxis("Wavelength", ""));
    endmemberDiagram.setYAxis(new DiagramAxis("Radiation", ""));
    endmemberDiagram.setDrawGrid(false);
    propertyChangeSupport = new PropertyChangeSupport(this);
}
 
源代码3 项目: netbeans   文件: StatefulActionProcessorTest.java
public void testCustomContextAwareInstance() {
    Action a = Actions.forID("Foo", "test.ListAction");
    DefaultListSelectionModel model = new DefaultListSelectionModel();
    
    InstanceContent localContent1 = new InstanceContent();
    AbstractLookup localLookup1 = new AbstractLookup(localContent1);
    
    Action la = ((ContextAwareAction)a).createContextAwareInstance(localLookup1);
    
    assertFalse(a.isEnabled());
    assertFalse(la.isEnabled());
    
    localContent1.add(model);
    
    assertFalse(a.isEnabled());
    assertTrue(la.isEnabled());
    assertFalse((Boolean)la.getValue(Action.SELECTED_KEY));
    
    // checks that the context-bound instance changes its selected state
    // if the model changes (relevant property change event is fired)
    model.setSelectionInterval(1, 2);
    assertTrue((Boolean)la.getValue(Action.SELECTED_KEY));
}
 
源代码4 项目: 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;
}
 
源代码5 项目: 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());
}
 
源代码6 项目: openjdk-jdk9   文件: 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();
        }
    });
}
 
源代码7 项目: pgptool   文件: KeysTableView.java
private JScrollPane initTableComponent() {
	table = new JTable();

	// Adjust some visual appearence
	table.setRowHeight(22);
	table.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

	// Add listeners
	selectionModel = new DefaultListSelectionModel();
	selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
	selectionModel.addListSelectionListener(rowSelectionListener);
	table.setSelectionModel(selectionModel);
	table.addMouseListener(listMouseListener);
	initTableKeyListener();

	// Envelope in scrollpane
	scrollPane = new JScrollPane();
	scrollPane.addMouseListener(listMouseListener);
	scrollPane.setViewportView(table);
	return scrollPane;
}
 
源代码8 项目: pgptool   文件: HistoryQuickSearchView.java
private JScrollPane initTableComponent() {
	table = new JTable();

	// Adjust some visual appearance
	table.setRowHeight(22);
	table.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

	// Add listeners
	selectionModel = new DefaultListSelectionModel();
	selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
	selectionModel.addListSelectionListener((evt) -> pm.setSelected(getSelectedRow()));
	table.setSelectionModel(selectionModel);
	table.addMouseListener(listMouseListener);

	table.getActionMap().put("confirmRow", enterAction);
	table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirmRow");

	// Envelope in scrollpane
	scrollPane = new JScrollPane();
	scrollPane.setViewportView(table);
	return scrollPane;
}
 
源代码9 项目: 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());
}
 
源代码10 项目: pcgen   文件: SkillInfoTab.java
@Override
public ModelMap createModels(final CharacterFacade character)
{
	Objects.requireNonNull(character);
	ModelMap models = new ModelMap();

	ListSelectionModel listModel = new DefaultListSelectionModel();
	listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	models.put(ListSelectionModel.class, listModel);
	models.put(SkillPointTableModel.class, new SkillPointTableModel(character));
	models.put(SkillTreeViewModel.class, new SkillTreeViewModel(character, listModel));
	models.put(FilterHandler.class, new FilterHandler(character, listModel));
	models.put(InfoHandler.class, new InfoHandler(character));
	models.put(LevelSelectionHandler.class, new LevelSelectionHandler(character, listModel));
	models.put(SkillRankSpinnerEditor.class, new SkillRankSpinnerEditor(character, listModel));

	SkillSheetHandler skillSheetHandler = new SkillSheetHandler(character);
	models.put(SkillSheetHandler.class, skillSheetHandler);
	models.put(SkillFilterHandler.class, new SkillFilterHandler(character, skillSheetHandler));
	return models;
}
 
源代码11 项目: visualvm   文件: 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;
}
 
源代码12 项目: spotbugs   文件: 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();
    }
 
源代码13 项目: pcgen   文件: AbilityChooserTab.java
public Hashtable<Object, Object> createState(CharacterFacade character,
	ListFacade<AbilityCategory> categories, ListFacade<AbilityCategory> fullCategoryList, String title)
{
	Hashtable<Object, Object> state = new Hashtable<>();
	CategoryTableModel categoryTableModel =
			new CategoryTableModel(character, fullCategoryList, categoryBar, categoryTable);
	state.put(CategoryTableModel.class, categoryTableModel);

	ListSelectionModel listModel = new DefaultListSelectionModel();
	listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	state.put(ListSelectionModel.class, listModel);
	state.put(AbilityTreeTableModel.class, new AbilityTreeTableModel(character, categories));
	state.put(AvailableAbilityTreeViewModel.class, new AvailableAbilityTreeViewModel(character, listModel, title));
	state.put(InfoHandler.class, new InfoHandler(character));
	state.put(TreeRendererHandler.class, new TreeRendererHandler(character));
	state.put(AddAction.class, new AddAction(character));
	state.put(RemoveAction.class, new RemoveAction(character));
	state.put(AbilityFilterHandler.class, new AbilityFilterHandler(character));
	state.put(CategoryFilterHandler.class, new CategoryFilterHandler(categoryTableModel));
	return state;
}
 
/**
 * 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];
}
 
/**
 * 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]);
    }
}
 
/**
 * 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];
}
 
/**
 * 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]);
    }
}
 
源代码18 项目: ghidra   文件: GTableColumnModel.java
GTableColumnModel(GTable table) {
	this.table = table;
	setSelectionModel(new DefaultListSelectionModel());
	setColumnMargin(1);
	invalidateWidthCache();
	setColumnSelectionAllowed(false);
	columnModelState = createTableColumnModelState();
}
 
源代码19 项目: TencentKona-8   文件: 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];
}
 
源代码20 项目: TencentKona-8   文件: 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]);
    }
}
 
源代码21 项目: VideoConference   文件: ClientListPanel.java
void createListModel()
{
    list_model=new javax.swing.DefaultListModel();
    list_online_clients = new javax.swing.JList(list_model);
    list_online_clients.setBorder(javax.swing.BorderFactory.createTitledBorder("Buddy List"));

    dlsm=new DefaultListSelectionModel();
    dlsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 list_online_clients.setSelectionModel(dlsm);
    this.setLayout(new BorderLayout());
    this.add(list_online_clients,BorderLayout.CENTER);
}
 
/**
 * 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];
}
 
/**
 * 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]);
    }
}
 
源代码24 项目: openjdk-jdk8u   文件: 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];
}
 
源代码25 项目: openjdk-jdk8u   文件: 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]);
    }
}
 
源代码26 项目: netbeans   文件: StatefulActionProcessorTest.java
public void testCustomListenerAction() {
    Action a = Actions.forID("Foo", "test.ListAction");
    DefaultListSelectionModel model = new DefaultListSelectionModel();
    
    assertFalse(a.isEnabled());
    assertFalse((Boolean)a.getValue(Action.SELECTED_KEY));
    
    lookupContent.add(model);
    assertTrue(a.isEnabled());
    assertFalse((Boolean)a.getValue(Action.SELECTED_KEY));
    
    model.addSelectionInterval(1, 1);
    assertTrue(a.isEnabled());
    assertTrue((Boolean)a.getValue(Action.SELECTED_KEY));
}
 
/**
 * 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];
}
 
/**
 * 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]);
    }
}
 
源代码29 项目: Bytecoder   文件: 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]);
    }
}
 
源代码30 项目: jdk8u-dev-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]);
    }
}
 
 类所在包
 同包方法