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
    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

      if (value instanceof FileSystemEntry) {
        FileSystemEntry fse = (FileSystemEntry) value;
        if (fse.isLoadingNode) {
          setIcon(spinner.getSpinner());
        } else {
          if (fse.isSearch()) {
            setSearch(fse);
          } else {
            if (expanded) {
              setIcon(openIcon);
            } else setIcon(closedIcon);
          }
        }
      } else if (value instanceof FileSystemRoot.SearchesRoot) {
        setSearch((ListableEntry) value);
      } else {
        setIcon(openIcon);
      }
      return this;
    }
Exemplo n.º 3
0
  @Override
  public void mouseClicked(MouseEvent e) {
    if (e.getSource() == filesTable) {
      if (e.getClickCount() == 2
          && e.getModifiersEx()
              == 0) { // the modifiers test is to prevent absurd clicks like "b1, b3" registering as
                      // double-clicks.
        if (filesTable.getSelectedRow() >= 0) {
          FileSystemEntry clicked =
              fs.getEntryForRow(filesTable.convertRowIndexToModel(filesTable.getSelectedRow()));
          if (clicked.isDirectory()) {
            // Go into the directory:
            TreePath pathToClicked = clicked.getPath();
            browseTree.setSelectionPath(pathToClicked);
            browseTree.scrollPathToVisible(pathToClicked);
            browseTree.setSelectionPath(
                pathToClicked); // the first one may have expanded the node and changed the
                                // selection, so ensure the node we want is actually selected.
          } else {
            downloadToDirectory(Arrays.asList(new FileSystemEntry[] {clicked}), null, null);
            frame.setStatusHint(
                new StatusHint(
                    frame.gui.util.getImage("tick"), clicked.getName() + " queued for download!"));
          }
        }
      }
    }
    if (e.getSource() == browseTree) {
      // remove a search if they clicked on the searches icon.
      if (lastOnIcon
          && lastInspectedFSE instanceof FileSystemEntry
          && ((FileSystemEntry) lastInspectedFSE).isSearch()) {
        fs.removeSearch((FileSystemEntry) lastInspectedFSE);

        lastInspectedFSE = null; // doesn't exist anymore.
        lastOnIcon = false;
        mouseMoved(
            new MouseEvent(
                browseTree,
                0,
                System.currentTimeMillis(),
                0,
                e.getX(),
                e.getY(),
                0,
                false)); // simulate the mouse moving to update status bar and icons.
      }
      // remove all searches if the clicked the searchroot:
      if (lastInspectedFSE == fs.getSearchRoot()) {
        fs.removeAllSearches();
      }
    }
  }
Exemplo n.º 4
0
  /**
   * Queues the selected downloads in the Download Controller's queue.
   *
   * <p>This will popup a magic progress dialog if it will take more than half a second.
   *
   * @param toDownload The filesystementries to download.
   * @param target the directory to download them into, or null to use the default.
   */
  void downloadToDirectory(
      Collection<FileSystemEntry> toDownload, String prefixDirectory, File target) {
    long totalSize = 0;
    for (FileSystemEntry e : toDownload) {
      totalSize += e.getSize();
    }

    DownloadSubmissionListener dsl =
        getDSLForDownloadBatch(
            totalSize,
            prefixDirectory == null
                ? "Queueing downloads..."
                : "Queueing downloads into '" + prefixDirectory + "'...");
    if (target == null) {
      frame.gui.dc.getQueue().submitToDefault(toDownload, prefixDirectory, dsl);
    } else {
      frame.gui.dc.getQueue().submit(target, toDownload, prefixDirectory, dsl);
    }
  }
Exemplo n.º 5
0
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

      FileSystemEntry fse = fs.getEntryForRow(filesTable.convertRowIndexToModel(row));
      if (fse.isLoadingNode) {
        setIcon(spinner.getSpinner());
      } else {
        if (fse.isDirectory()) {
          if (fse.isSearch()) {
            setIcon(search);
          } else {
            setIcon(dir);
          }
        } else {
          setIcon(frame.gui.util.getIconForType(frame.gui.util.guessType(value.toString())));
        }
      }
      return this;
    }
Exemplo n.º 6
0
  void setTableStatusHint() {
    if (browseTree.getSelectionPath() == null) {
      return;
    }

    if (!(browseTree.getSelectionPath().getLastPathComponent() instanceof FileSystemEntry)) return;
    FileSystemEntry fse = ((FileSystemEntry) browseTree.getSelectionPath().getLastPathComponent());

    int[] selected = filesTable.getSelectedRows();
    if (selected == null || selected.length == 0) {
      if (fse.getFiles() != null)
        frame.setStatusHint(
            "Directories: "
                + fse.getChildCount()
                + ", Files: "
                + fse.getFiles().size()
                + ", Total size: "
                + Util.niceSize(fse.getSize()));
    } else {
      long size = 0;
      int dirs = 0;
      int files = 0;
      for (int i : selected) {
        FileSystemEntry current = fs.getEntryForRow(filesTable.convertRowIndexToModel(i));
        size += current.getSize();
        if (current.isDirectory()) dirs++;
        else files++;
      }
      frame.setStatusHint(
          "(selection) Directories: "
              + dirs
              + ", Files: "
              + files
              + ", Total size: "
              + Util.niceSize(size));
    }
  }