下面列出了怎么用javax.swing.DefaultListSelectionModel的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
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);
}
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));
}
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;
}
@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());
}
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();
}
});
}
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;
}
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;
}
@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());
}
@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;
}
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;
}
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();
}
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]);
}
}
GTableColumnModel(GTable table) {
this.table = table;
setSelectionModel(new DefaultListSelectionModel());
setColumnMargin(1);
invalidateWidthCache();
setColumnSelectionAllowed(false);
columnModelState = createTableColumnModelState();
}
/**
* 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]);
}
}
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]);
}
}
/**
* 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]);
}
}
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]);
}
}
/**
* 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]);
}
}
/**
* 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]);
}
}