Exemplo n.º 1
0
  /**
   * When called it will traverse all visible leaves in the browseTree and collapse them if they
   * have been open for too long and are not selected.
   */
  private void collapseOldNodes() {
    Stack<ListableEntry> toConsider =
        new Stack<
            ListableEntry>(); // this is a stack of expanded nodes that need their children (and
                              // themselves) to be considered.
    toConsider.push(fs.getBrowseRoot()); // we know these are always expanded, and uncollapsable.
    toConsider.push(fs.getSearchRoot()); // "               "                    "

    // a) mark all uncollapsable nodes
    TreePath[] selecteds = browseTree.getSelectionPaths();
    if (selecteds != null) {
      for (TreePath selected : selecteds) {
        for (Object toMark :
            selected.getPath()) { // a selected nodes and their ancestors are not collapsable.
          expandedTimes.put(toMark, System.currentTimeMillis());
        }
      }
    }

    // b) collapse old expanded nodes.
    while (!toConsider.empty()) {
      for (FileSystemEntry child : toConsider.pop().getAllChildren()) {
        if (browseTree.isExpanded(child.getPath())) {
          toConsider.push(child);
          if (System.currentTimeMillis() - expandedTimes.get(child)
              > FS2Constants.CLIENT_BROWSETREE_COLLAPSE_INTERVAL) {
            browseTree.collapsePath(child.getPath());
            expandedTimes.remove(child);
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  JSplitPane createBrowseSection() {
    spinner = new LoadingAnimationHelper();
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setContinuousLayout(true);
    fs = frame.gui.ssvr.getIndexNodeCommunicator().getFileSystem();

    browseTree = new JTree(fs);

    // Allows the filesystem to keep refreshing directories we have visible:
    fs.setPathRequired(
        new PathRequired() {
          @Override
          public boolean required(TreePath path) {
            return browseTree.isExpanded(path);
          }
        });
    fs.addTreeModelListener(spinner);

    browseTree.setCellRenderer(browseTreeRenderer = new BrowseTreeCellRenderer());
    browseTree.addTreeSelectionListener(this);
    browseTree.addMouseMotionListener(this);
    browseTree.addMouseListener(this);
    browseTree.addTreeExpansionListener(this);
    browseTree.setRootVisible(false);
    browseTree.expandPath(fs.getBrowseRoot().getPath());

    JScrollPane treeView = new JScrollPane(browseTree);
    treeView.setMinimumSize(new Dimension(100, 100));
    splitPane.setLeftComponent(treeView);

    filesTable = new FancierTable(fs, frame.gui.conf, CK.FILES_TABLE_COLWIDTHS);
    filesTable.addMouseListener(this);
    filesTable.getSelectionModel().addListSelectionListener(this);
    filesTable.getColumn(fs.getColumnName(0)).setCellRenderer(new FilesTableNameRenderer());

    JScrollPane filesView = new JScrollPane(filesTable);
    splitPane.setRightComponent(filesView);
    splitPane.setDividerLocation(frame.gui.conf.getInt(CK.FILES_DIVIDER_LOCATION));
    splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, this);

    return splitPane;
  }