Java Code Examples for javax.swing.ListSelectionModel#getLeadSelectionIndex()

The following examples show how to use javax.swing.ListSelectionModel#getLeadSelectionIndex() . 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
Source File: OutlineView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Selection(ListSelectionModel sm) {
    selectionMode = sm.getSelectionMode();
    anchor = sm.getAnchorSelectionIndex();
    lead = sm.getLeadSelectionIndex();
    int min = sm.getMinSelectionIndex();
    int max = sm.getMaxSelectionIndex();
    int i1 = -1;
    for (int i = min; i <= max; i++) {
        if (sm.isSelectedIndex(i)) {
            if (i1 == -1) {
                i1 = i;
            }
        } else {
            if (i1 != -1) {
                intervals.add(new int[] { i1, i});
                i1 = -1;
            }
        }
    }
    if (i1 != -1) {
        intervals.add(new int[] { i1, max});
    }
}
 
Example 2
Source File: ETable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Convert indices of selected rows to model.
 */
private SelectedRows getSelectedRowsInModel() {
    SelectedRows sr = new SelectedRows();
    int rows[] = getSelectedRows();
    sr.rowsInView = rows;
    int[] modelRows = new int[rows.length];
    for (int i = 0; i < rows.length; i++) {
        modelRows[i] = convertRowIndexToModel(rows[i]);
    }
    //System.err.println("getSelectedRowsInModel() sets new rows from view: "+
    //        Arrays.toString(rows)+" to model rows: "+Arrays.toString(modelRows));
    sr.rowsInModel = modelRows;
    ListSelectionModel rsm = getSelectionModel();
    sr.anchorInView = rsm.getAnchorSelectionIndex();
    sr.leadInView = rsm.getLeadSelectionIndex();
    int rc = getRowCount();
    sr.anchorInModel = (sr.anchorInView < rc) ? convertRowIndexToModel(sr.anchorInView) : -1;
    sr.leadInModel = (sr.leadInView < rc) ? convertRowIndexToModel(sr.leadInView) : -1;
    return sr;
}
 
Example 3
Source File: InterpolatingLookupPaintScaleSetupDialog.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void valueChanged(ListSelectionEvent event) {

    if (event.getValueIsAdjusting())
      return;

    ListSelectionModel lsm = (ListSelectionModel) event.getSource();

    int index = lsm.getLeadSelectionIndex();
    if (index < 0) {
      return;
    }
    Double value = lookupTable.keySet().toArray(new Double[0])[index];
    Color color = lookupTable.get(value);
    fieldValue.setValue(value);
    buttonColor.setBackground(color);

  }
 
Example 4
Source File: MultiColumnListUI.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
protected int getNextIndex() {
     int index = list.getLastVisibleIndex();
     ListSelectionModel lsm = list.getSelectionModel();

     if (index == -1) {
// Will happen if size < viewport size.
index = list.getModel().getSize() - 1;
     }
     if (lsm.getLeadSelectionIndex() == index) {
Rectangle visRect = list.getVisibleRect();
visRect.y += visRect.height + visRect.height - 1;
index = list.locationToIndex(visRect.getLocation());
if (index == -1) {
  index = list.getModel().getSize() - 1;
}
     }
     return index;
   }
 
Example 5
Source File: MultiColumnListUI.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
protected int getNextIndex() {
     int index = list.getFirstVisibleIndex();
     ListSelectionModel lsm = list.getSelectionModel();

     if (lsm.getLeadSelectionIndex() == index) {
Rectangle visRect = list.getVisibleRect();
visRect.y = Math.max(0, visRect.y - visRect.height);
index = list.locationToIndex(visRect.getLocation());
     }
     return index;
   }
 
Example 6
Source File: Listener.java    From tcpmon with Apache License 2.0 4 votes vote down vote up
/**
 * Method save
 */
public void save() {
    JFileChooser dialog = new JFileChooser(".");
    int rc = dialog.showSaveDialog(this);
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            File file = dialog.getSelectedFile();
            FileOutputStream out = new FileOutputStream(file);
            ListSelectionModel lsm =
                    connectionTable.getSelectionModel();
            rc = lsm.getLeadSelectionIndex();
            int n = 0;
            for (Iterator i = connections.iterator(); i.hasNext();
                 n++) {
                Connection conn = (Connection) i.next();
                if (lsm.isSelectedIndex(n + 1)
                        || (!(i.hasNext())
                        && (lsm.getLeadSelectionIndex() == 0))) {
                    rc = Integer.parseInt(portField.getText());
                    out.write("\n==============\n".getBytes());
                    out.write(((TCPMon.getMessage("listenPort01",
                            "Listen Port:")
                            + " " + rc + "\n")).getBytes());
                    out.write((TCPMon.getMessage("targetHost01",
                            "Target Host:")
                            + " " + hostField.getText()
                            + "\n").getBytes());
                    rc = Integer.parseInt(tPortField.getText());
                    out.write(((TCPMon.getMessage("targetPort01",
                            "Target Port:")
                            + " " + rc + "\n")).getBytes());
                    out.write((("==== "
                            + TCPMon.getMessage("request01", "Request")
                            + " ====\n")).getBytes());
                    out.write(conn.inputText.getText().getBytes());
                    out.write((("==== "
                            + TCPMon.getMessage("response00", "Response")
                            + " ====\n")).getBytes());
                    out.write(conn.outputText.getText().getBytes());
                    out.write("\n==============\n".getBytes());
                }
            }
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}