private void jButtonMoveUpActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButtonMoveUpActionPerformed

    if (jTable1.getSelectedRow() > 0) {
      DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
      int[] indices = jTable1.getSelectedRows();
      for (int i = indices.length - 1; i >= 0; --i) {
        if (indices[i] == 0) continue;

        Object val = jTable1.getValueAt(indices[i], 0);
        dtm.removeRow(indices[i]);
        dtm.insertRow(indices[i] - 1, new Object[5]);
        setRowValues((MeterInterval) val, indices[i] - 1);
        indices[i]--;
      }

      DefaultListSelectionModel dlsm = (DefaultListSelectionModel) jTable1.getSelectionModel();
      dlsm.setValueIsAdjusting(true);
      dlsm.clearSelection();
      for (int i = 0; i < indices.length; ++i) {
        dlsm.addSelectionInterval(indices[i], indices[i]);
      }
      dlsm.setValueIsAdjusting(false);
    }
  } // GEN-LAST:event_jButtonMoveUpActionPerformed
 @Override
 public void setSelectionInterval(int index0, int index1) {
   if (adjusting) {
     return;
   } else if (isSelectedIndex(index1)) {
     super.removeSelectionInterval(index0, index1);
   } else {
     super.addSelectionInterval(index0, index1);
   }
   adjusting = getValueIsAdjusting();
 }
 public void addStylesFromSources(List<StyleSourceInfo> sources) {
   if (sources == null) return;
   for (StyleSourceInfo info : sources) {
     data.add(info.url);
   }
   sort();
   fireTableDataChanged();
   selectionModel.clearSelection();
   for (StyleSourceInfo info : sources) {
     int pos = data.indexOf(info.url);
     if (pos >= 0) {
       selectionModel.addSelectionInterval(pos, pos);
     }
   }
 }
示例#4
0
  private void addSelectionInterval(int index0, int index1, boolean clear) {
    System.err.println(
        "DSM: addSelectionInterval(" + index0 + " - " + index1 + ": clear = " + clear + ")");

    int start = Math.min(index0, index1);
    int end = Math.max(index0, index1);
    boolean oldValue = getValueIsAdjusting();

    setValueIsAdjusting(true);

    if (clear) {
      delegate.clearSelection();
    }

    for (int i = start; i <= end; i++) {
      int modelIndex = sortedModel.convertRowIndexToModel(i);
      delegate.addSelectionInterval(modelIndex, modelIndex);
    }

    setValueIsAdjusting(oldValue);
    fireSelectionChanged(
        new ListSelectionEvent(this, 0, sortedModel.getRowCount() - 1, getValueIsAdjusting()));
  }