private void changeDirectory(File dir) {
    JFileChooser fc = getFileChooser();
    // Traverse shortcuts on Windows
    if (dir != null && FilePane.usesShellFolder(fc)) {
      try {
        ShellFolder shellFolder = ShellFolder.getShellFolder(dir);

        if (shellFolder.isLink()) {
          File linkedTo = shellFolder.getLinkLocation();

          // If linkedTo is null we try to use dir
          if (linkedTo != null) {
            if (fc.isTraversable(linkedTo)) {
              dir = linkedTo;
            } else {
              return;
            }
          } else {
            dir = shellFolder;
          }
        }
      } catch (FileNotFoundException ex) {
        return;
      }
    }
    fc.setCurrentDirectory(dir);
    if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES
        && fc.getFileSystemView().isFileSystem(dir)) {

      setFileName(dir.getAbsolutePath());
    }
  }
 protected void uninstallDefaults(JFileChooser fc) {
   uninstallIcons(fc);
   uninstallStrings(fc);
   if (fc.getTransferHandler() instanceof UIResource) {
     fc.setTransferHandler(null);
   }
 }
  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());
    }
  }
 protected void uninstallListeners(JFileChooser fc) {
   if (propertyChangeListener != null) {
     fc.removePropertyChangeListener(propertyChangeListener);
   }
   fc.removePropertyChangeListener(getModel());
   SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
   SwingUtilities.replaceUIActionMap(fc, null);
 }
Beispiel #5
0
 private void saveAs() {
   if (saveFC == null) {
     saveFC = new SaveDataFileChooser();
   }
   int ret = saveFC.showSaveDialog(this);
   if (ret == JFileChooser.APPROVE_OPTION) {
     saveDataToFile(saveFC.getSelectedFile());
   }
 }
    public void showOpenDialog() {
      JFileChooser fc = new JFileChooser(Configuration.getUserHomeDirectory());
      fc.addChoosableFileFilter(new VPFFileFilter());

      int retVal = fc.showOpenDialog(this);
      if (retVal != JFileChooser.APPROVE_OPTION) return;

      File file = fc.getSelectedFile();
      this.addVPFLayer(file);
    }
 protected void installDefaults(JFileChooser fc) {
   installIcons(fc);
   installStrings(fc);
   usesSingleFilePane = UIManager.getBoolean("FileChooser.usesSingleFilePane");
   readOnly = UIManager.getBoolean("FileChooser.readOnly");
   TransferHandler th = fc.getTransferHandler();
   if (th == null || th instanceof UIResource) {
     fc.setTransferHandler(defaultTransferHandler);
   }
   LookAndFeel.installProperty(fc, "opaque", Boolean.FALSE);
 }
 private void resetGlobFilter() {
   if (actualFileFilter != null) {
     JFileChooser chooser = getFileChooser();
     FileFilter currentFilter = chooser.getFileFilter();
     if (currentFilter != null && currentFilter.equals(globFilter)) {
       chooser.setFileFilter(actualFileFilter);
       chooser.removeChoosableFileFilter(globFilter);
     }
     actualFileFilter = null;
   }
 }
  protected void installListeners(JFileChooser fc) {
    propertyChangeListener = createPropertyChangeListener(fc);
    if (propertyChangeListener != null) {
      fc.addPropertyChangeListener(propertyChangeListener);
    }
    fc.addPropertyChangeListener(getModel());

    InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
    ActionMap actionMap = getActionMap();
    SwingUtilities.replaceUIActionMap(fc, actionMap);
  }
 public int getApproveButtonMnemonic(JFileChooser fc) {
   int mnemonic = fc.getApproveButtonMnemonic();
   if (mnemonic > 0) {
     return mnemonic;
   } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
     return openButtonMnemonic;
   } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
     return saveButtonMnemonic;
   } else {
     return mnemonic;
   }
 }
 private String fileNameString(File file) {
   if (file == null) {
     return null;
   } else {
     JFileChooser fc = getFileChooser();
     if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
       return file.getPath();
     } else {
       return file.getName();
     }
   }
 }
 public String getApproveButtonText(JFileChooser fc) {
   String buttonText = fc.getApproveButtonText();
   if (buttonText != null) {
     return buttonText;
   } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
     return openButtonText;
   } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
     return saveButtonText;
   } else {
     return null;
   }
 }
 /** Returns the title of this dialog */
 public String getDialogTitle(JFileChooser fc) {
   String dialogTitle = fc.getDialogTitle();
   if (dialogTitle != null) {
     return dialogTitle;
   } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
     return openDialogTitleText;
   } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
     return saveDialogTitleText;
   } else {
     return getApproveButtonText(fc);
   }
 }
  public void installUI(JComponent c) {
    accessoryPanel = new JPanel(new BorderLayout());
    filechooser = (JFileChooser) c;

    createModel();

    clearIconCache();

    installDefaults(filechooser);
    installComponents(filechooser);
    installListeners(filechooser);
    filechooser.applyComponentOrientation(filechooser.getComponentOrientation());
  }
 /** Effectue differentes actions en fonction du bouton que l'on clique */
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals("Réinitialiser")) {
     this.maGrille.viderTabCases();
   } else if (e.getActionCommand().equals("Aléatoire")) {
     this.maGrille.remplirAleatTabCases();
   } else if (e.getActionCommand().equals("Chemin")) {
     this.etat = (byte) 0;
     this.indication.setEtat((byte) 0);
   } else if (e.getActionCommand().equals("Mur")) {
     this.etat = (byte) 1;
     this.indication.setEtat((byte) 1);
   } else if (e.getActionCommand().equals("Perso")) {
     this.etat = (byte) 2;
     this.indication.setEtat((byte) 2);
   } else if (e.getActionCommand().equals("Sortie")) {
     this.etat = (byte) 3;
     this.indication.setEtat((byte) 3);
   } else if (e.getActionCommand().equals("Sauvegarder")) {
     /* appel de la methode mapSaver */
     JFileChooser chooser = new JFileChooser("./MAP/");
     FileNameExtensionFilter filter = new FileNameExtensionFilter("Labyrinthe file (.lab)", "lab");
     chooser.setFileFilter(filter);
     int returnval = chooser.showOpenDialog(null);
     if (returnval == JFileChooser.APPROVE_OPTION) {
       System.out.println("You chose to save this file: " + chooser.getSelectedFile().getName());
       MapSaver map =
           new MapSaver(
               chooser.getSelectedFile(),
               (byte) this.maGrille.getTaille(),
               this.maGrille.getPosThesee(),
               this.maGrille.getPosSortie(),
               this.maGrille.getTabCases());
     } else {
       System.out.println("saving file aborded!");
     }
   } else if (e.getActionCommand().equals("Retour")) {
     /* retour au menu precedent */
     this.oldFenetre.setVisible(true);
     this.oldFenetre.repaint();
     this.maGrille.setClosed();
   }
   if (maGrille.estValide()) {
     this.sauvegarder.setEnabled(true);
   } else {
     this.sauvegarder.setEnabled(false);
   }
 }
  public JFileChooser createFileChooser() {
    // create a filechooser
    JFileChooser fc = new JFileChooser();
    if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) {
      fc.setDragEnabled(true);
    }

    // set the current directory to be the images directory
    File swingFile = new File("resources/images/About.jpg");
    if (swingFile.exists()) {
      fc.setCurrentDirectory(swingFile);
      fc.setSelectedFile(swingFile);
    }

    return fc;
  }
Beispiel #17
0
  /**
   * Constructs a new TranslatorComponent with the given filters of the source and destination
   * files.
   */
  public TranslatorComponent(FileFilter sourceFilter, FileFilter destFilter) {
    this.sourceFilter = sourceFilter;
    this.destFilter = destFilter;
    init();
    jbInit();
    source.setName("Source");
    destination.setName("Destination");

    sourceFileChooser = new JFileChooser();
    sourceFileChooser.setFileFilter(sourceFilter);

    destFileChooser = new JFileChooser();
    destFileChooser.setFileFilter(destFilter);

    source.enableUserInput();
    destination.disableUserInput();
  }
    public void actionPerformed(ActionEvent e) {
      if (readOnly) {
        return;
      }
      JFileChooser fc = getFileChooser();
      File currentDirectory = fc.getCurrentDirectory();

      if (!currentDirectory.exists()) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderParentDoesntExistText,
            newFolderParentDoesntExistTitleText,
            JOptionPane.WARNING_MESSAGE);
        return;
      }

      File newFolder;
      try {
        newFolder = fc.getFileSystemView().createNewFolder(currentDirectory);
        if (fc.isMultiSelectionEnabled()) {
          fc.setSelectedFiles(new File[] {newFolder});
        } else {
          fc.setSelectedFile(newFolder);
        }
      } catch (IOException exc) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderErrorText + newFolderErrorSeparator + exc,
            newFolderErrorText,
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      fc.rescanCurrentDirectory();
    }
  /** Open a file and load the image. */
  public void openFile() {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    String[] extensions = ImageIO.getReaderFileSuffixes();
    chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions));
    int r = chooser.showOpenDialog(this);
    if (r != JFileChooser.APPROVE_OPTION) return;

    try {
      Image img = ImageIO.read(chooser.getSelectedFile());
      image =
          new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
      image.getGraphics().drawImage(img, 0, 0, null);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(this, e);
    }
    repaint();
  }
Beispiel #20
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
    }
  }
Beispiel #21
0
  // saves the destination file
  private void saveDest() {
    int returnVal = destFileChooser.showDialog(this, "Save Destination File");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      if (destFileChooser.getSelectedFile().exists()) {
        Object[] options = {"Yes", "No", "Cancel"};
        int pressedButtonValue =
            JOptionPane.showOptionDialog(
                (JFrame) this,
                "File exists. Replace it ?",
                "Question",
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[2]);

        if (pressedButtonValue != JOptionPane.YES_OPTION) return;
      }

      String fileName = destFileChooser.getSelectedFile().getAbsolutePath();
      notifyHackTranslatorListeners(HackTranslatorEvent.SAVE_DEST, fileName);
    }
  }
Beispiel #22
0
 public static File saveFile(String ext) {
   JFileChooser fileChooser = new JFileChooser("Save as...");
   fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
   FileFilter filter = new FileNameExtensionFilter(ext, ext);
   fileChooser.setAcceptAllFileFilterUsed(false);
   fileChooser.setFileFilter(filter);
   fileChooser.showSaveDialog(null);
   return fileChooser.getSelectedFile();
 }
Beispiel #23
0
  public DirectorySize() {
    super(new BorderLayout());

    // Create the log first, because the action listeners
    // need to refer to it.
    log = new JTextArea(50, 100);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);

    // Create a file chooser
    fc = new JFileChooser();

    // Uncomment one of the following lines to try a different
    // file selection mode.  The first allows just directories
    // to be selected (and, at least in the Java look and feel,
    // shown).  The second allows both files and directories
    // to be selected.  If you leave these lines commented out,
    // then the default mode (FILES_ONLY) will be used.
    //
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    // fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    // Create the open button.  We use the image from the JLF
    // Graphics Repository (but we extracted it from the jar).
    openButton = new JButton("Open Folder...");
    openButton.addActionListener(this);

    // Create the save button.  We use the image from the JLF
    // Graphics Repository (but we extracted it from the jar).
    saveButton = new JButton("Clear Log...");
    saveButton.addActionListener(this);

    // For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel(); // use FlowLayout
    buttonPanel.add(openButton);
    buttonPanel.add(saveButton);

    // Add the buttons and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(logScrollPane, BorderLayout.CENTER);
  }
  protected void installStrings(JFileChooser fc) {
    super.installStrings(fc);

    Locale l = fc.getLocale();

    enterFileNameLabelText = UIManager.getString("FileChooser.enterFileNameLabelText", l);
    enterFileNameLabelMnemonic = UIManager.getInt("FileChooser.enterFileNameLabelMnemonic");

    filesLabelText = UIManager.getString("FileChooser.filesLabelText", l);
    filesLabelMnemonic = UIManager.getInt("FileChooser.filesLabelMnemonic");

    foldersLabelText = UIManager.getString("FileChooser.foldersLabelText", l);
    foldersLabelMnemonic = UIManager.getInt("FileChooser.foldersLabelMnemonic");

    pathLabelText = UIManager.getString("FileChooser.pathLabelText", l);
    pathLabelMnemonic = UIManager.getInt("FileChooser.pathLabelMnemonic");

    filterLabelText = UIManager.getString("FileChooser.filterLabelText", l);
    filterLabelMnemonic = UIManager.getInt("FileChooser.filterLabelMnemonic");
  }
Beispiel #25
0
    @Override
    public void approveSelection() {
      File file = getSelectedFile();
      if (file != null) {
        FileFilter filter = getFileFilter();
        if (filter != null && filter instanceof FileNameExtensionFilter) {
          String[] extensions = ((FileNameExtensionFilter) filter).getExtensions();

          boolean goodExt = false;
          for (String ext : extensions) {
            if (file.getName().toLowerCase().endsWith("." + ext.toLowerCase())) {
              goodExt = true;
              break;
            }
          }
          if (!goodExt) {
            file = new File(file.getParent(), file.getName() + "." + extensions[0]);
          }
        }

        if (file.exists()) {
          String okStr = Messages.FILE_CHOOSER_FILE_EXISTS_OK_OPTION;
          String cancelStr = Messages.FILE_CHOOSER_FILE_EXISTS_CANCEL_OPTION;
          int ret =
              JOptionPane.showOptionDialog(
                  this,
                  Resources.format(Messages.FILE_CHOOSER_FILE_EXISTS_MESSAGE, file.getName()),
                  Messages.FILE_CHOOSER_FILE_EXISTS_TITLE,
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.WARNING_MESSAGE,
                  null,
                  new Object[] {okStr, cancelStr},
                  okStr);
          if (ret != JOptionPane.OK_OPTION) {
            return;
          }
        }
        setSelectedFile(file);
      }
      super.approveSelection();
    }
  protected void installStrings(JFileChooser fc) {

    Locale l = fc.getLocale();
    newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText", l);
    newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator", l);

    newFolderParentDoesntExistTitleText =
        UIManager.getString("FileChooser.newFolderParentDoesntExistTitleText", l);
    newFolderParentDoesntExistText =
        UIManager.getString("FileChooser.newFolderParentDoesntExistText", l);

    fileDescriptionText = UIManager.getString("FileChooser.fileDescriptionText", l);
    directoryDescriptionText = UIManager.getString("FileChooser.directoryDescriptionText", l);

    saveButtonText = UIManager.getString("FileChooser.saveButtonText", l);
    openButtonText = UIManager.getString("FileChooser.openButtonText", l);
    saveDialogTitleText = UIManager.getString("FileChooser.saveDialogTitleText", l);
    openDialogTitleText = UIManager.getString("FileChooser.openDialogTitleText", l);
    cancelButtonText = UIManager.getString("FileChooser.cancelButtonText", l);
    updateButtonText = UIManager.getString("FileChooser.updateButtonText", l);
    helpButtonText = UIManager.getString("FileChooser.helpButtonText", l);
    directoryOpenButtonText = UIManager.getString("FileChooser.directoryOpenButtonText", l);

    saveButtonMnemonic = getMnemonic("FileChooser.saveButtonMnemonic", l);
    openButtonMnemonic = getMnemonic("FileChooser.openButtonMnemonic", l);
    cancelButtonMnemonic = getMnemonic("FileChooser.cancelButtonMnemonic", l);
    updateButtonMnemonic = getMnemonic("FileChooser.updateButtonMnemonic", l);
    helpButtonMnemonic = getMnemonic("FileChooser.helpButtonMnemonic", l);
    directoryOpenButtonMnemonic = getMnemonic("FileChooser.directoryOpenButtonMnemonic", l);

    saveButtonToolTipText = UIManager.getString("FileChooser.saveButtonToolTipText", l);
    openButtonToolTipText = UIManager.getString("FileChooser.openButtonToolTipText", l);
    cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText", l);
    updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText", l);
    helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText", l);
    directoryOpenButtonToolTipText =
        UIManager.getString("FileChooser.directoryOpenButtonToolTipText", l);
  }
Beispiel #27
0
  public void actionPerformed(ActionEvent e) {
    String cmd = (e.getActionCommand());

    if (cmd.equals(aboutItem.getText()))
      JOptionPane.showMessageDialog(
          this,
          "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS",
          "About imageLab",
          JOptionPane.INFORMATION_MESSAGE);
    else if (cmd.equals(quitItem.getText())) System.exit(0);
    else if (cmd.equals(openItem.getText())) {
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2 = new Picture(chooser.getSelectedFile().getName());
          pic1 = new Picture(pic2.width(), pic2.height());
          lab.setIcon(pic2.getJLabel().getIcon());
          sliderPanel.setVisible(false);
          pack();
          repaint();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Open Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } else if (cmd.equals(saveItem.getText())) {
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2.save(chooser.getSelectedFile().getName());
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Save Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
Beispiel #28
0
 // loads a source file
 private void loadSource() {
   int returnVal = sourceFileChooser.showDialog(this, "Load Source File");
   if (returnVal == JFileChooser.APPROVE_OPTION)
     notifyHackTranslatorListeners(
         HackTranslatorEvent.SOURCE_LOAD, sourceFileChooser.getSelectedFile().getAbsolutePath());
 }
 public FilePreviewer(JFileChooser fc) {
   setPreferredSize(new Dimension(100, 50));
   fc.addPropertyChangeListener(this);
   setBorder(new BevelBorder(BevelBorder.LOWERED));
 }
Beispiel #30
0
 public void setDestinationName(String name) {
   destFileChooser.setName(name);
   destFileChooser.setSelectedFile(new File(name));
 }