public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(FileChooserDemo.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        log.append("Opening: " + file.getName() + "." + newline);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      int returnVal = fc.showSaveDialog(FileChooserDemo.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would save the file.
        log.append("Saving: " + file.getName() + "." + newline);
      } else {
        log.append("Save command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
    }
  }
Beispiel #2
0
  private void PrettyPrint(File file, TreeMap<String, Long> sortedMap) {

    //        Long size = 0L;
    //        ArrayList<Long> values = new ArrayList<Long>(sortedMap.values());

    Long total = 0L;
    for (Long value : sortedMap.values()) {
      total = total + value; // Can also be done by total += value;
    }

    log.append(file.getName() + ": " + readableFileSize(total) + "\n\n");
    for (Map.Entry<String, Long> entry : sortedMap.entrySet()) {
      log.append("[ " + readableFileSize(entry.getValue()) + " ]");
      log.append(" --> " + entry.getKey() + "\n");
    }
    //        log.append(sortedMap + "\n");
  }
Beispiel #3
0
  public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(DirectorySize.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        ListSubDirectorySizes(file);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      log.setText(""); // reset
    }
  }