javax.swing.ListSelectionModel#getLeadSelectionIndex ( )源码实例Demo

下面列出了javax.swing.ListSelectionModel#getLeadSelectionIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: OutlineView.java
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});
    }
}
 
源代码2 项目: netbeans   文件: ETable.java
/**
 * 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;
}
 
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);

  }
 
源代码4 项目: pdfxtk   文件: MultiColumnListUI.java
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;
   }
 
源代码5 项目: pdfxtk   文件: MultiColumnListUI.java
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;
   }
 
源代码6 项目: tcpmon   文件: Listener.java
/**
 * 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();
        }
    }
}