Exemple #1
0
 public static ActionCallback moveDown(final JTree tree) {
   final int size = tree.getRowCount();
   int row = getSelectedRow(tree);
   if (row < size - 1) {
     row++;
     return showAndSelect(tree, row, row + 2, row, getSelectedRow(tree));
   } else {
     return new ActionCallback.Done();
   }
 }
 private static void expandTree(final JTree tree) {
   int oldRowCount = 0;
   do {
     int rowCount = tree.getRowCount();
     if (rowCount == oldRowCount) break;
     oldRowCount = rowCount;
     for (int i = 0; i < rowCount; i++) {
       tree.expandRow(i);
     }
   } while (true);
 }
Exemple #3
0
 private static int getVisibleRowCount(final JTree tree) {
   final Rectangle visible = tree.getVisibleRect();
   int count = 0;
   for (int i = 0; i < tree.getRowCount(); i++) {
     final Rectangle bounds = tree.getRowBounds(i);
     if (visible.y <= bounds.y && visible.y + visible.height >= bounds.y + bounds.height) {
       count++;
     }
   }
   return count;
 }
Exemple #4
0
 public static void expandAll(final JTree tree) {
   tree.expandPath(new TreePath(tree.getModel().getRoot()));
   int oldRowCount = 0;
   do {
     int rowCount = tree.getRowCount();
     if (rowCount == oldRowCount) break;
     oldRowCount = rowCount;
     for (int i = 0; i < rowCount; i++) {
       tree.expandRow(i);
     }
   } while (true);
 }
Exemple #5
0
 private static int getFirstVisibleRow(final JTree tree) {
   final Rectangle visible = tree.getVisibleRect();
   int row = -1;
   for (int i = 0; i < tree.getRowCount(); i++) {
     final Rectangle bounds = tree.getRowBounds(i);
     if (visible.y <= bounds.y && visible.y + visible.height >= bounds.y + bounds.height) {
       row = i;
       break;
     }
   }
   return row;
 }
Exemple #6
0
 public static ActionCallback movePageDown(final JTree tree) {
   final int visible = getVisibleRowCount(tree);
   if (visible <= 0) {
     return moveEnd(tree);
   }
   final int size = tree.getRowCount();
   final int increment = visible - 1;
   final int index = Math.min(getSelectedRow(tree) + increment, size - 1);
   final int top = getFirstVisibleRow(tree) + increment;
   final int bottom = top + visible - 1;
   return showAndSelect(tree, top, bottom, index, getSelectedRow(tree));
 }
  public void addEngines() {
    ArrayList<Player> disPlayers = new ArrayList<Player>();
    ArrayList<Player> ordPlayers = new ArrayList<Player>();
    PMS r = PMS.get();

    for (String id : configuration.getEnginesAsList(r.getRegistry())) {
      // boolean matched = false;
      for (Player p : PlayerFactory.getAllPlayers()) {
        if (p.id().equals(id)) {
          ordPlayers.add(p);
          // matched = true;
        }
      }
    }

    for (Player p : PlayerFactory.getAllPlayers()) {
      if (!ordPlayers.contains(p)) {
        ordPlayers.add(p);
        disPlayers.add(p);
      }
    }

    for (Player p : ordPlayers) {
      TreeNodeSettings en = new TreeNodeSettings(p.name(), p, null);
      if (disPlayers.contains(p)) {
        en.setEnable(false);
      }
      JComponent jc = en.getConfigPanel();
      if (jc == null) {
        jc = buildEmpty();
      }
      jc.addComponentListener(
          new ComponentAdapter() {
            @Override
            public void componentShown(ComponentEvent e) {
              handleCardComponentChange(e.getComponent());
            }
          });
      tabbedPane.add(en.id(), jc);
      parent[p.purpose()].add(en);
    }

    for (int i = 0; i < tree.getRowCount(); i++) {
      tree.expandRow(i);
    }

    tree.setSelectionRow(0);
  }
Exemple #8
0
  public static void ensureSelection(JTree tree) {
    final TreePath[] paths = tree.getSelectionPaths();

    if (paths != null) {
      for (TreePath each : paths) {
        if (tree.getRowForPath(each) >= 0 && tree.isVisible(each)) {
          return;
        }
      }
    }

    for (int eachRow = 0; eachRow < tree.getRowCount(); eachRow++) {
      TreePath eachPath = tree.getPathForRow(eachRow);
      if (eachPath != null && tree.isVisible(eachPath)) {
        tree.setSelectionPath(eachPath);
        break;
      }
    }
  }
Exemple #9
0
 public static void collapseAll(final JTree tree, final int keepSelectionLevel) {
   final TreePath leadSelectionPath = tree.getLeadSelectionPath();
   // Collapse all
   int row = tree.getRowCount() - 1;
   while (row >= 0) {
     tree.collapseRow(row);
     row--;
   }
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
   tree.expandPath(new TreePath(root));
   if (leadSelectionPath != null) {
     final Object[] path = leadSelectionPath.getPath();
     final Object[] pathToSelect =
         new Object
             [path.length > keepSelectionLevel && keepSelectionLevel >= 0
                 ? keepSelectionLevel
                 : path.length];
     System.arraycopy(path, 0, pathToSelect, 0, pathToSelect.length);
     if (pathToSelect.length == 0) return;
     selectPath(tree, new TreePath(pathToSelect));
   }
 }
 /** Collapse the tree so that only the root node is visible. */
 public void collapseTree() {
   for (int i = 1; i < resultsTree.getRowCount(); ++i) {
     resultsTree.collapseRow(i);
   }
 }
Exemple #11
0
  public static ActionCallback showAndSelect(
      final JTree tree,
      int top,
      int bottom,
      final int row,
      final int previous,
      boolean addToSelection,
      final boolean scroll) {
    final TreePath path = tree.getPathForRow(row);

    if (path == null) return new ActionCallback.Done();

    final int size = tree.getRowCount();
    if (size == 0) {
      tree.clearSelection();
      return new ActionCallback.Done();
    }
    if (top < 0) {
      top = 0;
    }
    if (bottom >= size) {
      bottom = size - 1;
    }

    if (row >= tree.getRowCount()) return new ActionCallback.Done();

    if (!tree.isValid()) {
      tree.validate();
    }

    final Rectangle rowBounds = tree.getRowBounds(row);
    if (rowBounds == null) return new ActionCallback.Done();

    Rectangle topBounds = tree.getRowBounds(top);
    if (topBounds == null) {
      topBounds = rowBounds;
    }

    Rectangle bottomBounds = tree.getRowBounds(bottom);
    if (bottomBounds == null) {
      bottomBounds = rowBounds;
    }

    Rectangle bounds = topBounds.union(bottomBounds);
    bounds.x = rowBounds.x;
    bounds.width = rowBounds.width;

    final Rectangle visible = tree.getVisibleRect();
    if (visible.contains(bounds)) {
      bounds = null;
    } else {
      final Component comp =
          tree.getCellRenderer()
              .getTreeCellRendererComponent(
                  tree, path.getLastPathComponent(), true, true, false, row, false);

      if (comp instanceof SimpleColoredComponent) {
        final SimpleColoredComponent renderer = ((SimpleColoredComponent) comp);
        final Dimension scrollableSize = renderer.computePreferredSize(true);
        bounds.width = scrollableSize.width;
      }
    }

    final ActionCallback callback = new ActionCallback();

    if (!tree.isRowSelected(row)) {
      if (addToSelection) {
        tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
      } else {
        tree.setSelectionRow(row);
      }
    }

    if (bounds != null) {
      final Range<Integer> range = getExpandControlRange(tree, path);
      if (range != null) {
        int delta = bounds.x - range.getFrom().intValue();
        bounds.x -= delta;
        bounds.width -= delta;
      }

      if (visible.width < bounds.width) {
        bounds.width = visible.width;
      }

      final Rectangle b1 = bounds;
      final Runnable runnable =
          new Runnable() {
            public void run() {
              if (scroll) {
                tree.scrollRectToVisible(b1);
              }
              callback.setDone();
            }
          };

      if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
      } else {
        SwingUtilities.invokeLater(runnable);
      }
    } else {
      callback.setDone();
    }

    return callback;
  }
Exemple #12
0
 private static ActionCallback moveEnd(final JTree tree) {
   return showRowCentred(tree, tree.getRowCount() - 1);
 }