Search in sources :

Example 41 with ListSelectionModel

use of javax.swing.ListSelectionModel in project adempiere by adempiere.

the class MiniTable method toggleLeadRowChecked.

/**
     * Toggles the selection checkbox of the current lead row. Adds or removes the lead row from
     * the selection accordingly.  
     */
private void toggleLeadRowChecked() {
    // Check if the lead row is selected, if not, select it
    ListSelectionModel rsm = this.getSelectionModel();
    int leadRow = rsm.getLeadSelectionIndex();
    if (leadRow == -1)
        return;
    //  Toggle
    setRowChecked(leadRow, !isRowChecked(leadRow));
    if (isRowChecked(leadRow)) {
        if (isMultiSelection())
            rsm.addSelectionInterval(leadRow, leadRow);
        else
            rsm.setSelectionInterval(leadRow, leadRow);
    } else {
        rsm.removeSelectionInterval(leadRow, leadRow);
        rsm.setLeadSelectionIndex(leadRow);
    }
}
Also used : DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel)

Example 42 with ListSelectionModel

use of javax.swing.ListSelectionModel in project adempiere by adempiere.

the class MiniTable method toggleRowCheckedRange.

/**
     * Toggles the selection checkbox of a range or rows. Adds or removes the rows from
     * the selection accordingly.
     * @param index0 - one end of the range
     * @param index1 - the other end of the range. Can be less than, equal or greater than index0.
     */
private void toggleRowCheckedRange(int index0, int index1) {
    if (isMultiSelection()) {
        if (getKeyColumnIndex() >= 0) {
            int rows = this.getRowCount();
            if (this.getShowTotals())
                rows = rows - 1;
            if (index0 < 0 || index0 >= rows || index1 < 0 || index1 >= rows)
                return;
            ListSelectionModel rsm = this.getSelectionModel();
            int leadRow = rsm.getLeadSelectionIndex();
            int low = index0 <= index1 ? index0 : index1;
            int high = index0 <= index1 ? index1 : index0;
            // Limit the number of row selection events to once per change
            m_changingMultipleRows = true;
            for (int row = low; row <= high; row++) {
                toggleRowChecked(row);
            }
            //  Return the lead to its original location
            rsm.setLeadSelectionIndex(leadRow);
            fireRowSelectionEvent();
            m_changingMultipleRows = false;
        }
    }
}
Also used : DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel)

Example 43 with ListSelectionModel

use of javax.swing.ListSelectionModel in project pcgen by PCGen.

the class DescriptionInfoTab method createModels.

@Override
public ModelMap createModels(CharacterFacade character) {
    ModelMap models = new ModelMap();
    DefaultListModel listModel = new DefaultListModel();
    List<NoteInfoPane> notePaneList = new ArrayList<>();
    //$NON-NLS-1$
    PageItem firstPage = new PageItem(character, LanguageBundle.getString("in_descBiography"), bioPane);
    listModel.addElement(firstPage);
    //$NON-NLS-1$
    listModel.addElement(new PageItem(character, LanguageBundle.getString("in_portrait"), portraitPane));
    //$NON-NLS-1$
    listModel.addElement(new PageItem(character, LanguageBundle.getString("in_descCampHist"), histPane));
    models.put(ListModel.class, listModel);
    models.put(List.class, notePaneList);
    models.put(NoteListHandler.class, new NoteListHandler(character, listModel, notePaneList));
    ListSelectionModel model = new DefaultListSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    model.setSelectionInterval(0, 0);
    models.put(ListSelectionModel.class, model);
    models.put(PageHandler.class, new PageHandler(model, firstPage));
    models.put(AddAction.class, new AddAction(character));
    return models;
}
Also used : ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) NoteInfoPane(pcgen.gui2.tabs.bio.NoteInfoPane)

Example 44 with ListSelectionModel

use of javax.swing.ListSelectionModel in project pcgen by PCGen.

the class SkillInfoTab method createModels.

@Override
public ModelMap createModels(final CharacterFacade 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;
}
Also used : SkillPointTableModel(pcgen.gui2.tabs.skill.SkillPointTableModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) SkillTreeViewModel(pcgen.gui2.tabs.skill.SkillTreeViewModel)

Example 45 with ListSelectionModel

use of javax.swing.ListSelectionModel in project poi by apache.

the class SVSheetTable method setFormulaDisplay.

public void setFormulaDisplay(JTextComponent formulaDisplay) {
    ListSelectionModel rowSelMod = getSelectionModel();
    ListSelectionModel colSelMod = getColumnModel().getSelectionModel();
    if (formulaDisplay == null) {
        rowSelMod.removeListSelectionListener(formulaListener);
        colSelMod.removeListSelectionListener(formulaListener);
        formulaListener = null;
    }
    if (formulaDisplay != null) {
        formulaListener = new FormulaDisplayListener(formulaDisplay);
        rowSelMod.addListSelectionListener(formulaListener);
        colSelMod.addListSelectionListener(formulaListener);
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel)

Aggregations

ListSelectionModel (javax.swing.ListSelectionModel)80 BorderLayout (java.awt.BorderLayout)20 Dimension (java.awt.Dimension)20 JButton (javax.swing.JButton)20 JPanel (javax.swing.JPanel)19 ListSelectionEvent (javax.swing.event.ListSelectionEvent)19 ListSelectionListener (javax.swing.event.ListSelectionListener)19 ActionEvent (java.awt.event.ActionEvent)18 JTable (javax.swing.JTable)18 ActionListener (java.awt.event.ActionListener)17 Point (java.awt.Point)16 JScrollPane (javax.swing.JScrollPane)15 MouseEvent (java.awt.event.MouseEvent)14 MouseAdapter (java.awt.event.MouseAdapter)13 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)13 TableColumn (javax.swing.table.TableColumn)13 Insets (java.awt.Insets)12 TableModel (javax.swing.table.TableModel)11 TableRowSorter (javax.swing.table.TableRowSorter)10 FlowLayout (java.awt.FlowLayout)9