コード例 #1
0
 @Override
 public Table<?> toTable(JGrid grid) {
   ListSelectionModel r = grid.getSelectionModel();
   ListSelectionModel c = grid.getColumnModel().getSelectionModel();
   return !r.isSelectionEmpty() && !c.isSelectionEmpty()
       ? copy2(
           grid.getModel(),
           Range.closed(r.getMinSelectionIndex(), r.getMaxSelectionIndex()),
           Range.closed(c.getMinSelectionIndex(), c.getMaxSelectionIndex()),
           rowHeader,
           columnHeader)
       : new Table<>(0, 0);
 }
 @Override
 public void validate(Problems problems, String compName, ListSelectionModel model) {
   if (model.isSelectionEmpty()) {
     wrapped.validate(problems, compName, new Integer[0]);
   } else {
     List<Integer> list =
         new ArrayList<Integer>(model.getMaxSelectionIndex() + 1 - model.getMinSelectionIndex());
     for (int i = model.getMinSelectionIndex(); i <= model.getMaxSelectionIndex(); ++i) {
       if (model.isSelectedIndex(i)) {
         list.add(i);
       }
     }
     wrapped.validate(problems, compName, list.toArray(new Integer[list.size()]));
   }
 }
コード例 #3
0
    public void valueChanged(ListSelectionEvent e) {
      ListSelectionModel lsm = (ListSelectionModel) e.getSource();

      int firstIndex = e.getFirstIndex();
      int lastIndex = e.getLastIndex();
      boolean isAdjusting = e.getValueIsAdjusting();
      output.append(
          "Event for indexes "
              + firstIndex
              + " - "
              + lastIndex
              + "; isAdjusting is "
              + isAdjusting
              + "; selected indexes:");

      if (lsm.isSelectionEmpty()) {
        output.append(" <none>");
      } else {
        // Find out which indexes are selected.
        int minIndex = lsm.getMinSelectionIndex();
        int maxIndex = lsm.getMaxSelectionIndex();
        for (int i = minIndex; i <= maxIndex; i++) {
          if (lsm.isSelectedIndex(i)) {
            output.append(" " + i);
          }
        }
      }
      output.append(newline);
      output.setCaretPosition(output.getDocument().getLength());
    }
コード例 #4
0
 public void update(final AnActionEvent event) {
   final ListSelectionModel selectionModel = list.getSelectionModel();
   final int lastSelectedIndex = selectionModel.getMaxSelectionIndex();
   event
       .getPresentation()
       .setEnabled((lastSelectedIndex >= 0) && (lastSelectedIndex < (listModel.size() - 1)));
 }
コード例 #5
0
    public void actionPerformed(ActionEvent e) {
      /*
       * This method can be called only if
       * there's a valid selection,
       * so go ahead and remove whatever's selected.
       */

      ListSelectionModel lsm = list.getSelectionModel();
      int firstSelected = lsm.getMinSelectionIndex();
      int lastSelected = lsm.getMaxSelectionIndex();
      listModel.removeRange(firstSelected, lastSelected);

      int size = listModel.size();

      if (size == 0) {
        // List is empty: disable delete, up, and down buttons.
        deleteButton.setEnabled(false);
        upButton.setEnabled(false);
        downButton.setEnabled(false);

      } else {
        // Adjust the selection.
        if (firstSelected == listModel.getSize()) {
          // Removed item in last position.
          firstSelected--;
        }
        list.setSelectedIndex(firstSelected);
      }
    }
コード例 #6
0
  @Override
  public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) {
      return;
    }
    configurationPanel.removeAll();
    ListSelectionModel m = (ListSelectionModel) e.getSource();
    // single selection, so max selection index is the only one selected.
    selectedIndex = m.getMaxSelectionIndex();

    JPanel panel = new DefaultReportConfigurationPanel();
    ReportModule module = modules.get(selectedIndex);
    boolean generalModuleSelected = false;
    if (module instanceof GeneralReportModule) {
      JPanel generalPanel = ((GeneralReportModule) module).getConfigurationPanel();
      panel = (generalPanel == null) ? new JPanel() : generalPanel;
      generalModuleSelected = true;
    }

    descriptionTextPane.setText(module.getDescription());
    configurationPanel.add(panel, BorderLayout.CENTER);
    configurationPanel.revalidate();

    wizPanel.setNext(!generalModuleSelected);
    wizPanel.setFinish(generalModuleSelected);
  }
コード例 #7
0
 /**
  * Set the selection behavior for a OneToManyIndexMap.
  *
  * @param allSelected This only applies to OneToManyIndexMaps, if true all destination indices
  *     must be selected in order for the source index to be selected, if false then the source
  *     index is selected if any of its associated destination indices are selected.
  */
 public void setAllSelected(boolean allSelected) {
   this.allSelected = allSelected;
   if (map != null && !map.isOneToOne()) {
     selListener.valueChanged(
         new ListSelectionEvent(
             src, src.getMinSelectionIndex(), src.getMaxSelectionIndex(), false));
   }
 }
コード例 #8
0
 private Collection<SimpleMatch> getSelectedFromTable() {
   ListSelectionModel lsm = matchTable.getSelectionModel();
   Collection<SimpleMatch> selMatches = new HashSet<>();
   for (int i = lsm.getMinSelectionIndex(); i <= lsm.getMaxSelectionIndex(); i++) {
     if (lsm.isSelectedIndex(i) && i < matches.size()) {
       selMatches.add(matches.get(i));
     }
   }
   return selMatches;
 }
コード例 #9
0
 public Date getSelectionEndTime() {
   if ((mySelectionModel != null) && (mySelectionModel.getMaxSelectionIndex() >= 0)) {
     HistorySpan selectionSpan = null;
     for (int i = mySelectionModel.getMinSelectionIndex();
         i <= mySelectionModel.getMaxSelectionIndex();
         ++i) {
       if (selectionSpan == null) {
         selectionSpan = new HistorySpan((HistoryItem) myList.get(i));
       } else {
         selectionSpan.absorb(
             (Date) ((HistoryItem) myList.get(i)).getProperty(HistoryItem.BEGIN_DATE),
             (Date) ((HistoryItem) myList.get(i)).getProperty(HistoryItem.END_DATE));
       }
     }
     return selectionSpan.getEnd();
   } else {
     return new Date(0);
   }
 }
  private void changeSelection() {
    ListSelectionModel model = myTable.getSelectionModel();
    AutomatonEditorPanel<T, S> panel = getEditorPanel();
    panel.clearSelection();

    int min = model.getMinSelectionIndex(), max = model.getMaxSelectionIndex();
    if (min < 0) return;
    for (int i = min; i <= max; i++)
      if (model.isSelectedIndex(i) && myObjectMap.containsKey(i))
        panel.selectObject(myObjectMap.get(i));
  }
コード例 #11
0
 private JLabel renderTableCell(int rowIndex, int columnIndex) {
   TableCellRenderer cellRenderer = table.getCellRenderer(rowIndex, columnIndex);
   Object cellValue = table.getValueAt(rowIndex, columnIndex);
   ListSelectionModel selectionModel = table.getSelectionModel();
   boolean selected =
       rowIndex >= selectionModel.getMinSelectionIndex()
           && rowIndex <= selectionModel.getMaxSelectionIndex();
   return (JLabel)
       cellRenderer.getTableCellRendererComponent(
           table, cellValue, selected, false, rowIndex, columnIndex);
 }
コード例 #12
0
 /**
  * Method scrollToVisible
  *
  * @param aTable JTable
  */
 private void scrollToVisible(JTable aTable) {
   final ListSelectionModel lsm = aTable.getSelectionModel();
   final int first = lsm.getMinSelectionIndex();
   final int last = lsm.getMaxSelectionIndex();
   if (first != -1) {
     final Rectangle bounds = getRowBounds(aTable, first, last);
     if (!isVerticallyVisible(aTable, bounds)) {
       // Is SwingUtilities.invokeLater needed ???
       aTable.scrollRectToVisible(bounds);
     }
   }
 }
コード例 #13
0
 /**
  * Link two ListSelectionModels so that selections in either will be reflected in the other. If a
  * map is given, it provides the mapping of indices between the two ListSelectionModels.
  *
  * @param model1 One of the ListSelectionModels to link together.
  * @param model2 The other ListSelectionModels to link together.
  * @param map If not null, this provides the mapping of indices between the two
  *     ListSelectionModels.
  * @param allSelected Sets the selection behavior for a OneToManyIndexMap.
  * @see #setAllSelected
  */
 public IndexMapSelection(
     ListSelectionModel model1, ListSelectionModel model2, IndexMap map, boolean allSelected) {
   this.src = model1;
   this.dst = model2;
   this.map = map;
   this.allSelected = allSelected;
   if (src.getMinSelectionIndex() >= 0) {
     selListener.valueChanged(
         new ListSelectionEvent(
             src, src.getMinSelectionIndex(), src.getMaxSelectionIndex(), false));
   }
   src.addListSelectionListener(selListener);
   dst.addListSelectionListener(selListener);
 }
コード例 #14
0
  /**
   * Returns the number of columns selected.
   *
   * @return the number of columns selected
   */
  public int getSelectedColumnCount() {
    if (selectionModel != null) {
      int iMin = selectionModel.getMinSelectionIndex();
      int iMax = selectionModel.getMaxSelectionIndex();
      int count = 0;

      for (int i = iMin; i <= iMax; i++) {
        if (selectionModel.isSelectedIndex(i)) {
          count++;
        }
      }
      return count;
    }
    return 0;
  }
コード例 #15
0
  protected final boolean areSelectedItemsRemovable(@NotNull ListSelectionModel selectionMode) {
    int minSelectionIndex = selectionMode.getMinSelectionIndex();
    int maxSelectionIndex = selectionMode.getMaxSelectionIndex();
    if (minSelectionIndex < 0 || maxSelectionIndex < 0) {
      return false;
    }

    List<T> items = getItems();
    for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) {
      if (itemEditor.isRemovable(items.get(i))) {
        return true;
      }
    }
    return false;
  }
コード例 #16
0
 /**
  * Save the selection so it can be restored after sorting.
  *
  * @param aTable
  * @return List
  */
 private List saveSelection(JTable aTable) {
   final ListSelectionModel lsm = aTable.getSelectionModel();
   final RowTableModel tm = (RowTableModel) aTable.getModel();
   final int first = lsm.getMinSelectionIndex();
   final int last = lsm.getMaxSelectionIndex();
   final List objs = new ArrayList();
   if (first != -1) {
     for (int i = first; i <= last; i++) {
       if (lsm.isSelectedIndex(i)) {
         objs.add(tm.getRow(i));
       }
     }
   }
   return objs;
 }
コード例 #17
0
ファイル: NodeStatusPanel.java プロジェクト: ekiwi/tinyos-1.x
  private List<Node> getSelectedNodes() {
    List<Node> selectedNodes = new Vector<Node>();
    NodeStatusTableModel myTableModel = (NodeStatusTableModel) getModel();

    ListSelectionModel lsm = getSelectionModel();
    int minIndex = lsm.getMinSelectionIndex();
    int maxIndex = lsm.getMaxSelectionIndex();

    for (int i = minIndex; i <= maxIndex; i++) {
      if (lsm.isSelectedIndex(i)) {
        // System.out.println("row " + i + " is selected");
        Node currNode = myTableModel.getNode(i);
        if (currNode != null) selectedNodes.add(currNode);
      }
    }

    return selectedNodes;
  }
コード例 #18
0
  private static int[] getSelectedIndices(ListSelectionModel sm) {
    final int iMinIndex = sm.getMinSelectionIndex();
    final int iMaxIndex = sm.getMaxSelectionIndex();

    if ((iMinIndex < 0) || (iMaxIndex < 0)) {
      return new int[0];
    }

    final int[] aiTemp = new int[1 + (iMaxIndex - iMinIndex)];
    int i = 0;
    for (int iIndex = iMinIndex; iIndex <= iMaxIndex; iIndex++) {
      if (sm.isSelectedIndex(iIndex)) {
        aiTemp[i++] = iIndex;
      }
    }
    final int[] result = new int[i];
    System.arraycopy(aiTemp, 0, result, 0, i);
    return result;
  }
コード例 #19
0
  /**
   * Returns an array of all of the selected indices in increasing order.
   *
   * @return all of the selected indices, in increasing order
   * @see #removeSelectionInterval
   * @see #addListSelectionListener
   */
  public int[] getCheckBoxListSelectedIndices() {
    ListSelectionModel listSelectionModel = getCheckBoxListSelectionModel();
    int iMin = listSelectionModel.getMinSelectionIndex();
    int iMax = listSelectionModel.getMaxSelectionIndex();

    if ((iMin < 0) || (iMax < 0)) {
      return new int[0];
    }

    int[] temp = new int[1 + (iMax - iMin)];
    int n = 0;
    for (int i = iMin; i <= iMax; i++) {
      if (listSelectionModel.isSelectedIndex(i)) {
        temp[n] = i;
        n++;
      }
    }
    int[] indices = new int[n];
    System.arraycopy(temp, 0, indices, 0, n);
    return indices;
  }
コード例 #20
0
  @Override
  public void valueChanged(ListSelectionEvent e) {
    JList<?> list = (JList<?>) e.getSource();
    ListModel<?> model = list.getModel();

    ListSelectionModel listSelectionModel = list.getSelectionModel();

    int minSelectionIndex = listSelectionModel.getMinSelectionIndex();
    int maxSelectionIndex = listSelectionModel.getMaxSelectionIndex();

    StringBuilder textBuilder = new StringBuilder();

    for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) {
      if (listSelectionModel.isSelectedIndex(i)) {
        Object elementAt = model.getElementAt(i);
        formatElement(elementAt, textBuilder, i);
      }
    }

    setText(textBuilder.toString());
  }
コード例 #21
0
  /**
   * Returns an array of selected columns. If <code>selectionModel</code> is <code>null</code>,
   * returns an empty array.
   *
   * @return an array of selected columns or an empty array if nothing is selected or the <code>
   *     selectionModel</code> is <code>null</code>
   */
  public int[] getSelectedColumns() {
    if (selectionModel != null) {
      int iMin = selectionModel.getMinSelectionIndex();
      int iMax = selectionModel.getMaxSelectionIndex();

      if ((iMin == -1) || (iMax == -1)) {
        return new int[0];
      }

      int[] rvTmp = new int[1 + (iMax - iMin)];
      int n = 0;
      for (int i = iMin; i <= iMax; i++) {
        if (selectionModel.isSelectedIndex(i)) {
          rvTmp[n++] = i;
        }
      }
      int[] rv = new int[n];
      System.arraycopy(rvTmp, 0, rv, 0, n);
      return rv;
    }
    return new int[0];
  }
コード例 #22
0
ファイル: TableUtils.java プロジェクト: hanyuqianye/bluebell
  /**
   * Gets the selected rows view indexes.
   *
   * @param table the table.
   * @return the view indexes.
   */
  public static List<Integer> getSelectedViewIndexes(JTable table) {

    Assert.notNull(table, TableUtils.TABLE);

    final List<Integer> viewIndexes = new ArrayList<Integer>();
    final ListSelectionModel selectionModel = table.getSelectionModel();

    // There should be unless one selected entity
    if (selectionModel.isSelectionEmpty()) {
      return viewIndexes;
    }

    // Iterate between selected entities
    final int min = selectionModel.getMinSelectionIndex();
    final int max = selectionModel.getMaxSelectionIndex();

    for (int idx = min; idx <= max; ++idx) {
      if (selectionModel.isSelectedIndex(idx)) {
        viewIndexes.add(idx);
      }
    }

    return viewIndexes;
  }
コード例 #23
0
 public void valueChanged(ListSelectionEvent e) {
   ListSelectionModel lsm = (ListSelectionModel) e.getSource();
   int minIndex = lsm.getMinSelectionIndex();
   int maxIndex = lsm.getMaxSelectionIndex();
   if (minIndex == maxIndex) table.startEditingRow(minIndex);
 }
コード例 #24
0
 void updateValuePairsActions(ListSelectionModel selectionModel) {
   this.removeAction.setEnabled(!selectionModel.isSelectionEmpty());
   this.editAction.setEnabled(
       !selectionModel.isSelectionEmpty()
           && selectionModel.getMinSelectionIndex() == selectionModel.getMaxSelectionIndex());
 }
コード例 #25
0
        public void valueChanged(ListSelectionEvent e) {
          if (!e.getValueIsAdjusting() && cur == null) { // prevent recursion
            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
            cur = lsm;
            ListSelectionModel rfl; // reflect changes in other model
            int mn = lsm.getMinSelectionIndex();
            int mx = lsm.getMaxSelectionIndex();
            if (lsm == src) {
              rfl = dst;
            } else {
              rfl = src;
            }
            int min = 0;
            int max =
                map == null
                    ? lsm.getMaxSelectionIndex()
                    : lsm == src ? map.getSrcSize() : map.getDstSize();
            BitSet bidx = null;
            if (map != null && !map.isOneToOne()) {
              bidx = new BitSet(max + 1);
            }
            rfl.setValueIsAdjusting(true);
            if (map == null) {
              rfl.clearSelection();
            }

            for (int i = min; i <= max; i++) {
              if (map == null) {
                if (lsm.isSelectedIndex(i)) {
                  rfl.addSelectionInterval(i, i);
                } else {
                  rfl.removeSelectionInterval(i, i);
                }
              } else if (map.isOneToOne()) {
                int j = lsm == src ? map.getDst(i) : map.getSrc(i);
                if (j < 0) continue;
                if (lsm.isSelectedIndex(i)) {
                  rfl.addSelectionInterval(j, j);
                } else {
                  rfl.removeSelectionInterval(j, j);
                }
              } else {
                // How to deal with OneToMany mapping?
                // All dst indices selected -> select src index
                // Any dst indices selected -> select src index
                //
                if (!bidx.get(i)) {
                  bidx.set(i); // Flag this index as visited
                  // Get the set of destination indices
                  int di[] = lsm == src ? map.getDsts(i) : map.getSrcs(i);
                  if (di != null) {
                    for (int j = 0; j < di.length; j++) {
                      if (di[j] < 0) continue;
                      // Get the set of source indices for each destination index
                      int si[] = lsm == dst ? map.getDsts(di[j]) : map.getSrcs(di[j]);
                      if (si != null) {
                        boolean allSet = true;
                        boolean anySet = false;
                        for (int k = 0; k < si.length; k++) {
                          bidx.set(si[k]); // Flag this index as visited
                          allSet &= lsm.isSelectedIndex(si[k]);
                          anySet |= lsm.isSelectedIndex(si[k]);
                        }
                        if (allSet || (!allSelected && anySet)) {
                          rfl.addSelectionInterval(di[j], di[j]);
                        } else {
                          rfl.removeSelectionInterval(di[j], di[j]);
                        }
                      }
                    }
                  }
                }
              }
            }
            rfl.setValueIsAdjusting(false);
            cur = null;
          }
        }