Java Code Examples for javax.swing.DefaultListSelectionModel

The following examples show how to use javax.swing.DefaultListSelectionModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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;
}
 
Example 2
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);
}
 
Example 3
Source Project: netbeans   Source File: StatefulActionProcessorTest.java    License: Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 4
Source Project: netbeans   Source File: ProfilerTable.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
@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());
}
 
Example 6
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();
        }
    });
}
 
Example 7
Source Project: pgptool   Source File: KeysTableView.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 8
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;
}
 
Example 9
@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());
}
 
Example 10
Source Project: pcgen   Source File: SkillInfoTab.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@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;
}
 
Example 11
Source Project: visualvm   Source File: ProfilerTable.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 12
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();
    }
 
Example 13
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;
}
 
Example 14
/**
 * 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];
}
 
Example 15
/**
 * 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]);
    }
}
 
Example 16
/**
 * 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];
}
 
Example 17
/**
 * 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]);
    }
}
 
Example 18
Source Project: ghidra   Source File: GTableColumnModel.java    License: Apache License 2.0 5 votes vote down vote up
GTableColumnModel(GTable table) {
	this.table = table;
	setSelectionModel(new DefaultListSelectionModel());
	setColumnMargin(1);
	invalidateWidthCache();
	setColumnSelectionAllowed(false);
	columnModelState = createTableColumnModelState();
}
 
Example 19
/**
 * 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];
}
 
Example 20
/**
 * 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]);
    }
}
 
Example 21
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);
}
 
Example 22
Source Project: JDKSourceCode1.8   Source File: DefaultTreeSelectionModel.java    License: MIT License 5 votes vote down vote up
/**
 * 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];
}
 
Example 23
Source Project: JDKSourceCode1.8   Source File: DefaultTreeSelectionModel.java    License: MIT License 5 votes vote down vote up
/**
 * 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]);
    }
}
 
Example 24
/**
 * 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];
}
 
Example 25
/**
 * 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]);
    }
}
 
Example 26
Source Project: netbeans   Source File: StatefulActionProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 27
/**
 * 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];
}
 
Example 28
/**
 * 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]);
    }
}
 
Example 29
Source Project: Bytecoder   Source File: DefaultTreeSelectionModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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]);
    }
}
 
Example 30
/**
 * 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]);
    }
}