MyPathChooser(String name, final JTextField path, int fileSelectionMode) {
      super(name);

      final JFrame chooserFrame = this;

      setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

      final JFileChooser chooser = new JFileChooser(path.getText());

      chooser.setFileSelectionMode(fileSelectionMode);
      getContentPane().add(chooser);
      chooser.setFileHidingEnabled(true);
      pack();
      setVisible(true);

      chooser.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String command = e.getActionCommand();
              if (command.equals(JFileChooser.APPROVE_SELECTION)) {
                path.setText(chooser.getSelectedFile().getAbsolutePath().replace('\\', '/'));
                // and pretend like you typed a key:
                path.getKeyListeners()[0].keyReleased(new KeyEvent(path, 0, 0, 0, 0, ' '));
              }
              chooserFrame.setVisible(false);
            }
          });
    }
Пример #2
0
  public static void showLoadShapesDialog(Component owner, ShapeControl shapeControl) {
    try {
      JFileChooser fileChooser = new JFileChooser();
      fileChooser.setDialogTitle("Load shapes");
      FileNameExtensionFilter filter = new FileNameExtensionFilter("Shapes list", "shp");
      fileChooser.setFileFilter(filter);
      fileChooser.addChoosableFileFilter(filter);
      fileChooser.setFileHidingEnabled(false);

      if (fileChooser.showOpenDialog(owner) == JFileChooser.APPROVE_OPTION) {
        File fileToLoad = fileChooser.getSelectedFile();
        if (!fileToLoad.exists() && !fileToLoad.getName().endsWith(".shp")) {
          JOptionPane.showMessageDialog(
              owner,
              "You have to load an .shp file!",
              "Wrong file type!",
              JOptionPane.WARNING_MESSAGE);
        } else {
          loadShapes(fileToLoad, shapeControl);
        }
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          owner,
          "Error while loading file!\n\n" + e.getMessage(),
          "Error on loading!",
          JOptionPane.WARNING_MESSAGE);
    }
  }
Пример #3
0
  void importB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));

    JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Insert file"));
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
    chooser.setPreferredSize(new Dimension(550, 375));
    String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
    if (lastSel != null) chooser.setCurrentDirectory(new java.io.File(lastSel));
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;

    Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile().getPath());

    File f = chooser.getSelectedFile();
    new HTMLFileImport(f, editor);
  }
Пример #4
0
  // $$ modif from Oury
  private static JFileChooser getFileChooser(Component owner, int mode) {
    JFileChooser chooser = null;
    String last = /*Jext*/ AbstractEditorPanel.getProperty("lastdir." + mode);
    if (last == null) last = /*Jext*/ AbstractEditorPanel.getHomeDirectory();

    if (owner instanceof AbstractEditorPanel) {
      chooser = ((/*Jext*/ AbstractEditorPanel) owner).getFileChooser(mode);
      if (
      /*Jext*/ AbstractEditorPanel.getBooleanProperty("editor.dirDefaultDialog")
          && mode != SCRIPT) {
        String file =
            ((AbstractEditorPanel) owner)
                // $$ from Seb [[
                // .getTextArea()
                // $$ from Seb ]]
                .getCurrentFile();
        if (file != null) chooser.setCurrentDirectory(new File(file));
      } else chooser.setCurrentDirectory(new File(last));
    } else {
      chooser = new JFileChooser(last);
      if (mode == SAVE) chooser.setDialogType(JFileChooser.SAVE_DIALOG);
      else chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    }

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileHidingEnabled(true);

    return chooser;
  }
Пример #5
0
  /** Constructs a new UI. */
  public UI() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException ignored) {
    }
    setTitle("ScrabbleBot");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fileChooser.setFileHidingEnabled(true);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileFilter(fileExtensionFilter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    menuBar.setLayout(new GridLayout(1, 5));
    bestMove.addActionListener(UI.this);
    bestMove.setFocusable(false);
    menuBar.add(bestMove);
    tilesInHand.addActionListener(UI.this);
    tilesInHand.setFocusable(false);
    menuBar.add(tilesInHand);
    newGame.addActionListener(UI.this);
    newGame.setFocusable(false);
    menuBar.add(newGame);
    loadGame.addActionListener(UI.this);
    loadGame.setFocusable(false);
    menuBar.add(loadGame);
    saveGame.addActionListener(UI.this);
    saveGame.setFocusable(false);
    menuBar.add(saveGame);
    setJMenuBar(menuBar);
    add(game.getBoard());
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(final WindowEvent e) {
            if (game.getBoard().hasValidContent()) {
              saveGame();
            }
          }
        });
    pack();
    setLocationRelativeTo(getOwner());
    setResizable(false);
    setVisible(true);
  }
  private void localizarButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_localizarButtonActionPerformed

    try {
      JFileChooser chooser = null;
      if (StringHelper.isBlank(field.getText())) {
        chooser = new JFileChooser(System.getProperty("user.home"));
      } else {
        chooser = new JFileChooser(field.getText());
      }

      FileNameExtensionFilter extension = new FileNameExtensionFilter("Arquivo Xml (*.xml)", "xml");
      chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      chooser.setAcceptAllFileFilterUsed(false);
      chooser.setFileFilter(extension);
      chooser.setFileHidingEnabled(true);
      chooser.setMultiSelectionEnabled(true);

      chooser.setApproveButtonText("Abrir");

      int choice = chooser.showOpenDialog(this);

      if (choice == JFileChooser.APPROVE_OPTION) {
        File oneFile = chooser.getSelectedFile();

        String path = null;
        path = oneFile.getPath();
        String nomeArquivo = StringHelper.substringAfterLast(path, SO.getSepArqSO());
        String caminhoArq = StringHelper.substringBeforeLast(path, SO.getSepArqSO());
        if (defaultListModel.contains(new InfoArq(nomeArquivo, caminhoArq))) {
          throw new Exception("O arquivo com este mesmo caminho ja existe na lista abaixo!");
        }
        field.setText(path.substring(0, path.lastIndexOf(SO.getSepArqSO())));

        File[] files = chooser.getSelectedFiles();
        for (File file : files) {
          defaultListModel.addElement(
              new InfoArq(
                  file.getName(),
                  StringHelper.substringBeforeLast(file.getPath(), SO.getSepArqSO())));
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      JMessageUtil.showInfoMessage(this, ex.getMessage());
    }
  } // GEN-LAST:event_localizarButtonActionPerformed
Пример #7
0
 public static boolean checkBrowser() {
   AppList appList = MimeTypesList.getAppList();
   String bpath = appList.getBrowserExec();
   if (bpath != null) if (new File(bpath).isFile()) return true;
   JFileChooser chooser = new JFileChooser();
   chooser.setFileHidingEnabled(false);
   chooser.setDialogTitle(Local.getString("Select the web-browser executable"));
   chooser.setAcceptAllFileFilterUsed(true);
   chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
   /*java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_RESOURCE_FILE");
   if (lastSel != null)
       chooser.setCurrentDirectory(lastSel);*/
   if (chooser.showOpenDialog(App.getFrame()) != JFileChooser.APPROVE_OPTION) return false;
   appList.setBrowserExec(chooser.getSelectedFile().getPath());
   CurrentStorage.get().storeMimeTypesList();
   return true;
 }
Пример #8
0
  /**
   * Displays to the user the option to either load an existing file or to start a new game. Until
   * either option is fully chosen (successfully choosing an input file, simply clicking "New File",
   * or closing the Load/New dialog), the options are shown again and again.
   *
   * @return <code>Game</code> object representing input data chosen by user
   */
  private static Game startOptions() {

    JFileChooser fc = new JFileChooser(".");
    fc.setFileHidingEnabled(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    boolean optionChosen = false;

    Object[] options = {"Load File", "New File"};

    do {
      int n =
          JOptionPane.showOptionDialog(
              null,
              "Would you like to load" + "\n or start a new file?",
              null,
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              options[0]);

      switch (n) {
        case 0: //  User chose to load a file
          int retVal = fc.showOpenDialog(null);

          if (retVal == JFileChooser.APPROVE_OPTION) {
            return new Game(fc.getSelectedFile());
          } // if a file was chosen

          break;

        case 1: //  User chose to start a new file
          String name = JOptionPane.showInputDialog("Please input game name:", "New Game");
          return new Game(name);

        case -1: //  User cancelled:
          System.exit(0);
      } //  switch

    } while (!optionChosen);

    return null;
  } // end startOptions() method
Пример #9
0
 /**
  * Returns the existing file chooser. Everything in the file chooser is reset except current
  * directory.
  *
  * @return a file chooser if the application has a GUI, otherwise null
  */
 public JFileChooser getFileChooser() {
   if (isHead()) {
     if (fileChooser == null) {
       fileChooser = new FileChooser(null);
       fileChooser.setPreferredSize(UIParameters.getInstance().getFileChooserDimension());
     } else {
       // restore to defaults
       fileChooser.resetChoosableFileFilters();
       fileChooser.setDialogTitle(FileChooser.DEFAULT_TITLE);
       fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
       fileChooser.setFileFilter(null);
       fileChooser.setFileHidingEnabled(true);
       fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
       fileChooser.setMultiSelectionEnabled(false);
       fileChooser.setSelectedFile(new File(""));
     }
     return fileChooser;
   }
   return null;
 }
Пример #10
0
  public static File startFileChooser(Component component, File selectedFile) {
    // Create a file chooser
    final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileHidingEnabled(true);
    fc.setAcceptAllFileFilterUsed(false);
    if (selectedFile != null) fc.setSelectedFile(selectedFile);
    fc.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(final File file) {
            if (file.isDirectory()) return true;
            String ext = Utils.getExtension(file);
            if (ext != null && ext.equals(Utils.XLS)) {
              return true;
            }
            return false;
          }

          @Override
          public String getDescription() {
            return "Excel *.xls";
          }
        });
    // In response to a button click:
    final int returnVal = fc.showOpenDialog(component);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      // This is where a real application would open the file.
      Log.d("Opening: " + file.getName() + ".");
      return file;
    } else {
      Log.d("Open command cancelled by user.");
    }
    return null;
  }
Пример #11
0
  void exportB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Save in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.saveButtonText", Local.getString("Save"));
    UIManager.put("FileChooser.saveButtonToolTipText", Local.getString("Save selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));

    JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Export note"));
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.XHTML));
    chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
    // chooser.addChoosableFileFilter(new
    // AllFilesFilter(AllFilesFilter.RTF));
    String lastSel = (String) Context.get("LAST_SELECTED_EXPORT_FILE");
    if (lastSel != null) chooser.setCurrentDirectory(new File(lastSel));

    FileExportDialog dlg =
        new FileExportDialog(App.getFrame(), Local.getString("Export note"), chooser);
    String enc = (String) Context.get("EXPORT_FILE_ENCODING");
    if (enc != null) dlg.encCB.setSelectedItem(enc);
    String templ = (String) Context.get("EXPORT_TEMPLATE");
    if (templ != null) dlg.templF.setText(templ);
    String xhtml = (String) Context.get("EXPORT_XHTML");
    if ((xhtml != null) && (xhtml.equalsIgnoreCase("YES"))) dlg.xhtmlChB.setSelected(true);
    String num = (String) Context.get("EXPORT_NUMENT");
    if ((num != null) && (num.equalsIgnoreCase("YES"))) dlg.numentChB.setSelected(true);
    Dimension dlgSize = new Dimension(550, 475);
    dlg.setSize(dlgSize);
    Dimension frmSize = App.getFrame().getSize();
    Point loc = App.getFrame().getLocation();
    dlg.setLocation(
        (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setVisible(true);
    if (dlg.CANCELLED) return;

    Context.put("LAST_SELECTED_EXPORT_FILE", chooser.getSelectedFile().getPath());
    Context.put("EXPORT_FILE_ENCODING", dlg.encCB.getSelectedItem());
    Context.put("EXPORT_NUMENT", dlg.numentChB.isSelected() ? "YES" : "NO");
    Context.put("EXPORT_XHTML", dlg.xhtmlChB.isSelected() ? "YES" : "NO");
    String template = null;
    if (dlg.usetemplChB.isSelected() && dlg.templF.getText().length() > 0) {
      template = dlg.templF.getText();
      Context.put("EXPORT_TEMPLATE", template);
    }
    /*
     * if (chooser.getFileFilter().getDescription().equals("Rich Text
     * Format")) new RTFFileExport(chooser.getSelectedFile(),
     * editor.document); else
     */
    int ei = dlg.encCB.getSelectedIndex();
    enc = null;
    if (ei == 1) enc = "UTF-8";
    File f = chooser.getSelectedFile();
    new HTMLFileExport(
        f,
        editor.document,
        CurrentNote.get(),
        enc,
        dlg.numentChB.isSelected(),
        template,
        dlg.xhtmlChB.isSelected());
  }
Пример #12
0
  /** Called for button presses and checkbox toggles. */
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();

    // the source of the event is the add files button
    // so we need to let the user add some files!
    if (src == addFiles) {
      // create an appropriate file chooser
      JFileChooser myTempFileChooser = new JFileChooser((new File("")).getAbsolutePath());
      myTempFileChooser.setMultiSelectionEnabled(true);
      myTempFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      myTempFileChooser.setFileHidingEnabled(true);

      // open the file chooser and get the user's selctions
      int returnCode = myTempFileChooser.showOpenDialog(this);

      // use the return info to add files if the
      // user selected any in the file chooser
      if (returnCode == JFileChooser.APPROVE_OPTION) {
        // grab the files the user selected
        File[] selectedFiles = myTempFileChooser.getSelectedFiles();

        // pull the files into the list
        changeFilesInList.importFileData(list, selectedFiles);
      }
    }

    // the source of the event was the process button
    else if (src == process) {
      if (((DefaultListModel) list.getModel()).size() == 0) return;

      setComponentsEnabled(false);
      final ThumbMaker tm = this;
      Thread t =
          new Thread(
              new Runnable() {
                public void run() {
                  tm.process();
                  setComponentsEnabled(true);
                }
              });
      t.start();

      // because we can't do it on quit, we are going to save
      // all the preference values when the user processes a set
      // of images
      savePreferences();
    }

    // the source of the event was the remove button
    else if (src == remove) {
      DefaultListModel model = (DefaultListModel) list.getModel();
      while (true) {
        int ndx = list.getSelectedIndex();
        if (ndx < 0) break;
        model.removeElementAt(ndx);
      }
    }

    // the source of the event was the preserve aspect check box
    else if (src == aspect) {
      boolean b = aspect.isSelected();
      colorLabel.setEnabled(b);
      colorBox.setEnabled(b);
      redLabel.setEnabled(b);
      red.setEnabled(b);
      redValue.setEnabled(b);
      greenLabel.setEnabled(b);
      green.setEnabled(b);
      greenValue.setEnabled(b);
      blueLabel.setEnabled(b);
      blue.setEnabled(b);
      blueValue.setEnabled(b);
    }

    // the source of the event is the "..." button,
    // we need to let the user select a destination file
    else if (src == dotDotDot) {
      // create an appropriate file chooser
      JFileChooser myTempFileChooser =
          new JFileChooser(new File(output.getText()).getAbsolutePath());
      myTempFileChooser.setMultiSelectionEnabled(false);
      myTempFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      myTempFileChooser.setFileHidingEnabled(true);

      // open the file chooser and get the user's selctions
      int returnCode = myTempFileChooser.showOpenDialog(this);

      // use the return info to set the directory if the
      // user selected one in the file chooser
      if (returnCode == JFileChooser.APPROVE_OPTION) {
        // grab the file the user selected
        File selectedFile = myTempFileChooser.getSelectedFile();

        // stuff the file path into the text field
        output.setText(selectedFile.getAbsolutePath());
      }
    }
  }