private void loadFile() {
    JFileChooser fileChooser = new JFileChooser();

    FileNameExtensionFilter filter =
        new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.setFileFilter(filter);

    if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
      fileChooser.setCurrentDirectory(
          new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
    } else {
      fileChooser.setCurrentDirectory(
          new File(internalBalloon.getBalloonContentPath().getStandardPath()));
    }
    int result = fileChooser.showSaveDialog(getTopLevelAncestor());
    if (result == JFileChooser.CANCEL_OPTION) return;
    try {
      String exportString = fileChooser.getSelectedFile().toString();
      browseText.setText(exportString);
      internalBalloon
          .getBalloonContentPath()
          .setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
      internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
    } catch (Exception e) {
      //
    }
  }
Esempio n. 2
0
  private void findPresentation() {
    JFileChooser fileChooser = new JFileChooser();
    if (lastDirectory_ != null) fileChooser.setCurrentDirectory(lastDirectory_);
    // if (imc.lecturnity.converter.ConverterWizard.USE_CUSTOM_COLORS)
    if (USE_CUSTOM_COLORS) fileChooser.setBackground(Wizard.BG_COLOR);
    LecturnityFileFilter lff = new LecturnityFileFilter();
    fileChooser.addChoosableFileFilter(lff);
    LpdFileFilter lpf = new LpdFileFilter();
    fileChooser.addChoosableFileFilter(lpf);
    EPresentationFileFilter eff = new EPresentationFileFilter();
    fileChooser.addChoosableFileFilter(eff);
    AofFileFilter aff = new AofFileFilter();
    fileChooser.addChoosableFileFilter(aff);
    fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.setFileFilter(lff);

    Dimension fcSize = fileChooser.getPreferredSize();
    fileChooser.setPreferredSize(new Dimension(fcSize.width + 100, fcSize.height + 50));

    int action = fileChooser.showOpenDialog(this);

    lastDirectory_ = fileChooser.getCurrentDirectory();

    if (action == fileChooser.APPROVE_OPTION) {
      File selectedFile = fileChooser.getSelectedFile();
      presentationFileField_.setText(selectedFile.getAbsolutePath());
    }
  }
Esempio n. 3
0
  /** Initialize the application. */
  public void initializeApp() {
    // Create and initialize the storage policy
    try {
      DefaultStoragePolicy storage = new DefaultStoragePolicy();
      setStoragePolicy(storage);

      FileFilter ff =
          new FileFilter() {
            public boolean accept(File file) {
              return GUIUtilities.getFileExtension(file).toLowerCase().equals("txt");
            }

            public String getDescription() {
              return "Text files";
            }
          };
      JFileChooser fc;
      fc = storage.getOpenFileChooser();
      fc.addChoosableFileFilter(ff);
      fc.setFileFilter(ff);

      fc = storage.getSaveFileChooser();
      fc.addChoosableFileFilter(ff);
      fc.setFileFilter(ff);
    } catch (SecurityException ex) {
      // FIXME: create a new "NoStoragePolicy"
    }

    setDocumentFactory(new TextDocument.Factory());
  }
Esempio n. 4
0
    public static File saveFileAs(JComponent parent) {
      File f = null;
      try {
        JFileChooser jfc = new JFileChooser();

        FileNameExtensionFilter csvfilter = new FileNameExtensionFilter("CSV", "csv");
        jfc.addChoosableFileFilter(csvfilter);

        FileNameExtensionFilter tsvfilter = new FileNameExtensionFilter("TSV", "tsv");
        jfc.addChoosableFileFilter(tsvfilter);

        FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("XML", "xml");
        jfc.addChoosableFileFilter(xmlfilter);

        FileNameExtensionFilter txtfilter = new FileNameExtensionFilter("Text", "txt");
        jfc.addChoosableFileFilter(txtfilter);

        FileNameExtensionFilter jsonfilter = new FileNameExtensionFilter("JSON", "json");
        jfc.addChoosableFileFilter(jsonfilter);

        jfc.setDialogTitle("VirtualSPARQLer: FileSaver");
        jfc.showSaveDialog(parent);
        f = jfc.getSelectedFile();
        f.createNewFile();
      } catch (IOException ex) {
        mylogger.log(Level.SEVERE, "Error: Can not save file: {0}", ex.getMessage());
      } finally {
        return f;
      }
    }
  public ExportStatisticsFile(List<MyObjectStatistics> valores) {

    JFileChooser jfc = new JFileChooser(lastPath);
    jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());

    // Adding required extensions (dbf, csv)
    dbfExtensionsSupported = new Hashtable<String, MyFileFilter>();
    csvExtensionsSupported = new Hashtable<String, MyFileFilter>();
    dbfExtensionsSupported.put(
        "dbf", new MyFileFilter("dbf", PluginServices.getText(this, "Ficheros_dbf"), "dbf"));
    csvExtensionsSupported.put(
        "csv", new MyFileFilter("csv", PluginServices.getText(this, "Ficheros_csv"), "csv"));

    Iterator<MyFileFilter> iter = csvExtensionsSupported.values().iterator();
    while (iter.hasNext()) {
      jfc.addChoosableFileFilter(iter.next());
    }

    iter = dbfExtensionsSupported.values().iterator();
    while (iter.hasNext()) {
      jfc.addChoosableFileFilter(iter.next());
    }

    // Opening a JFileCooser
    if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
        == JFileChooser.APPROVE_OPTION) {
      File endFile = jfc.getSelectedFile();
      if (endFile.exists()) { // File exists in the directory.
        int resp =
            JOptionPane.showConfirmDialog(
                (Component) PluginServices.getMainFrame(),
                PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo")
                    + "\n"
                    + endFile.getAbsolutePath(),
                PluginServices.getText(this, "guardar"),
                JOptionPane.YES_NO_OPTION); // Informing the user
        if (resp != JOptionPane.YES_OPTION) { // cancel pressed.
          return;
        }
      } // end if exits.
      MyFileFilter filter = (MyFileFilter) jfc.getFileFilter(); // dbf, csv
      endFile = filter.normalizeExtension(endFile); // "name" + "." +
      // "dbf", "name" +
      // "." + "csv"

      if (filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("csv") == 0) { // csv file
        exportToCSVFile(valores, endFile); // export to csv format
      } else if (filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("dbf")
          == 0) { // dbf file
        exportToDBFFile(valores, endFile); // export to dbf format
      }
    } // end if aprove option.
  }
 /** @param chooser the filechooser of which the filters will be set */
 public void setFileChooserFilters(JFileChooser chooser, String defaultName) {
   chooser.addChoosableFileFilter(defaultFilter);
   Iterator iter = otherFilters.iterator();
   while (iter.hasNext()) {
     chooser.addChoosableFileFilter((SuffixFilter) iter.next());
   }
   chooser.setFileFilter(defaultFilter);
   String fileName = defaultName + "." + defaultFilter.getSuffix();
   chooser.setSelectedFile(new File(fileName));
   chooser.addPropertyChangeListener(
       JFileChooser.FILE_FILTER_CHANGED_PROPERTY,
       new FileFilterChangedListener(chooser, defaultName));
 }
Esempio n. 7
0
 /** @param chooser the filechooser of which the filters will be set */
 public void setOpenFileChooserFilter(JFileChooser chooser) {
   MultitypeFileFilter mf = new MultitypeFileFilter();
   mf.add(defaultPersister);
   chooser.addChoosableFileFilter(mf);
   chooser.addChoosableFileFilter(defaultPersister);
   Iterator iter = otherPersisters.iterator();
   while (iter.hasNext()) {
     AbstractFilePersister ff = (AbstractFilePersister) iter.next();
     if (ff.isLoadEnabled()) {
       mf.add(ff);
       chooser.addChoosableFileFilter(ff);
     }
   }
   chooser.setFileFilter(mf);
 }
Esempio n. 8
0
  /**
   * @param chooser the filechooser of which the filters will be set
   * @param fileName the filename of the file to be saved (optional)
   */
  public void setSaveFileChooserFilters(JFileChooser chooser, String fileName) {

    chooser.addChoosableFileFilter(defaultPersister);
    AbstractFilePersister defaultFileFilter = defaultPersister;

    for (AbstractFilePersister fp : otherPersisters) {
      if (fp.isSaveEnabled() && !fp.equals(xmiPersister) && !fp.equals(xmlPersister)) {
        chooser.addChoosableFileFilter(fp);
        if (fileName != null && fp.isFileExtensionApplicable(fileName)) {
          defaultFileFilter = fp;
        }
      }
    }
    chooser.setFileFilter(defaultFileFilter);
  }
 /**
  * Updates the available FileFilter to "only uxf/pxf" or "all but uxf/pxf"
  *
  * @param ownXmlFormat If this param is set, only uxf/pxf is visible, otherwise all but uxf/pxf is
  *     visible
  */
 private void setAvailableFileFilters(boolean ownXmlFormat) {
   if (ownXmlFormat) {
     saveFileChooser.resetChoosableFileFilters();
     saveFileChooser.addChoosableFileFilter(filterxml);
   } else {
     saveFileChooser.resetChoosableFileFilters();
     saveFileChooser.addChoosableFileFilter(filterbmp);
     saveFileChooser.addChoosableFileFilter(filtereps);
     saveFileChooser.addChoosableFileFilter(filtergif);
     saveFileChooser.addChoosableFileFilter(filterjpg);
     saveFileChooser.addChoosableFileFilter(filterpdf);
     saveFileChooser.addChoosableFileFilter(filterpng);
     saveFileChooser.addChoosableFileFilter(filtersvg);
   }
 }
Esempio n. 10
0
  /**
   * Accionado quando se faz clique no botao para abrir um ficheiro RFP Permite selecionar um
   * ficheiro rfp escolhido pelo utilizador. Fecha o ficheiro actual caso este exista e faz um reset
   * ao conteu do actual da tabela, mostrando de seguida os novos conteudos do ficheiro escolhido.
   *
   * <p>É lançado uma excepção caso seja feito um duplo clique sem selecção.
   *
   * @param evt
   */
  private void jMenuItem2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem2ActionPerformed

    try {
      final JFileChooser fc = new JFileChooser();
      RFPFileFilter filter = new RFPFileFilter();
      fc.addChoosableFileFilter(filter);
      int returnVal = fc.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        File dir = fc.getCurrentDirectory();
        // fechar o ficheiro actual
        if (rfpFile != null && !rfpFile.isClosed()) rfpFile.closeRFP();

        resetTable();
        resetVariables();
        rfpFile = new RFPBinaryFile(file.getName(), dir.getPath());
        rfpFile.openRFP();
        rfpFile.readContents();
        nativePath = dir.getPath();
        showRFPContents();
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null,
          "Impossivel abrir o ficheiro rfp.",
          "Abrir Ficheiro RFP",
          JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jMenuItem2ActionPerformed
  public static JFileChooser createJFileChooser(final String... fileFilters) {
    final JFileChooser chooser = new JFileChooser();
    chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
    for (final String fileFilter : fileFilters) {
      final String[] fileFilterArr = StringUtils.split(fileFilter, "|");
      chooser.addChoosableFileFilter(
          new FileFilter() {
            @Override
            public boolean accept(final File f) {
              final String[] types = StringUtils.split(fileFilterArr[0], ";");
              if (types.length == 0) {
                return true;
              } else {
                if (!f.isFile()) {
                  return true;
                } else {
                  final String ext = FileUtils.getFilenameExtension(f.getPath());
                  for (final String type : types) {
                    if (type.equalsIgnoreCase(ext)) {
                      return true;
                    }
                  }
                  return false;
                }
              }
            }

            @Override
            public String getDescription() {
              return fileFilterArr.length > 1 ? fileFilterArr[1] : fileFilterArr[0];
            }
          });
    }
    return chooser;
  }
  public void EVENT_openhddlink(ActionEvent e) {
    JFileChooser fc = new JFileChooser("");
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(
        new FileFilter() {

          @Override
          public boolean accept(File pathname) {
            if (pathname.toString().endsWith("alliance") || pathname.isDirectory()) {
              return true;
            } else {
              return false;
            }
          }

          @Override
          public String getDescription() {
            return ("Alliance files");
          }
        });
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      String path = fc.getSelectedFile().getPath();
      downloadHddLink(path);
    }
  }
Esempio n. 13
0
  /**
   * This method allows the user to choose a input video file to get images from. It makes sure that
   * only video files are chosen and that they are valid. The user cannot get images from the video
   * if the file is not valid.
   */
  private void chooseVideoPressed() {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setCurrentDirectory(new java.io.File("."));

    fileChooser.setDialogTitle("Choose Video File");

    fileChooser.addChoosableFileFilter(SwingFileFilterFactory.newVideoFileFilter());

    // Allows files to be chosen only. Make sure they are video files in the extract part
    // fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    // put filter to ensure that only video files are chosen.
    fileChooser.setFileFilter(SwingFileFilterFactory.newVideoFileFilter());
    fileChooser.setAcceptAllFileFilterUsed(false);
    int returnValue = fileChooser.showOpenDialog(Images.this);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
      selectedFile = fileChooser.getSelectedFile();
      showVideo.setText("Video chosen: " + selectedFile.getName());
      InvalidCheck i = new InvalidCheck();
      boolean isValidMedia = i.invalidCheck(fileChooser.getSelectedFile().getAbsolutePath());
      // make sure that file is a valid media file.
      if (!isValidMedia) {
        JOptionPane.showMessageDialog(
            Images.this, "You have specified an invalid file.", "Error", JOptionPane.ERROR_MESSAGE);
        makeImages.setEnabled(false);
        return;
      } else {
        makeImages.setEnabled(true);
      }
    }
  }
Esempio n. 14
0
 /** Exports the Last Deployment to an html file Called by the GuiMain in an action event */
 public void exportLastDeployment(ArrayList<DeployedVirtualMachine> deployed, Component parent) {
   if (deployed.size() != 0) {
     FileSystemView fsv = FileSystemView.getFileSystemView();
     JFileChooser chooser = new JFileChooser(fsv.getRoots()[0]);
     chooser.addChoosableFileFilter(new ReportGeneratorFileFilter());
     chooser.setSelectedFile(new File("report.html"));
     int choice = chooser.showSaveDialog(parent);
     if (choice == JFileChooser.APPROVE_OPTION) {
       try {
         LOG.write("Creating report...");
         new ReportGenerator().makeReport(chooser.getSelectedFile(), deployed, this);
         LOG.write("Report saved at " + chooser.getSelectedFile().getAbsolutePath());
       } catch (Exception e) {
         LOG.write("Error in generating the report");
         LOG.printStackTrace(e);
       }
     }
   } else {
     JOptionPane.showMessageDialog(
         main,
         "No deployment data exists.  \nUse the Deployment Wizard to start a "
             + "new deployment before creating a deployment report.",
         "Could not create report",
         JOptionPane.ERROR_MESSAGE);
   }
 }
Esempio n. 15
0
    /**
     * create a file chooser populated with file filters for the given pathway importers / exporters
     */
    private void createFileFilters(Set<? extends PathwayIO> set) {
      jfc.setAcceptAllFileFilterUsed(false);

      SortedSet<PathwayIO> exporters =
          new TreeSet<PathwayIO>(
              new Comparator<PathwayIO>() {
                public int compare(PathwayIO o1, PathwayIO o2) {
                  return o1.getName().compareTo(o2.getName());
                }
              });
      exporters.addAll(set);

      PathwayFileFilter selectedFilter = null;
      for (PathwayIO exp : exporters) {
        PathwayFileFilter ff = new PathwayFileFilter(exp);
        jfc.addChoosableFileFilter(ff);
        if (exp instanceof GpmlFormat) {
          selectedFilter = ff;
        }
      }
      if (selectedFilter != null) {
        jfc.setFileFilter(selectedFilter);
        fileDialog.setFilenameFilter(selectedFilter);
      }
    }
  public BrowseActionListener(
      JTextField inputField,
      boolean isOpen,
      Component parent,
      boolean dirOnly,
      Reference<File> defaultDir) {

    this.defaultDir = defaultDir;
    this.textbox = inputField;
    this.isOpen = isOpen;
    this.parent = parent;

    jfc = new JFileChooser();
    jfc.setFileSelectionMode(dirOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);

    if (!dirOnly)
      jfc.addChoosableFileFilter(
          new FileFilter() {
            @Override
            public String getDescription() {
              return "Jars and zips only";
            }

            @Override
            public boolean accept(File arg0) {
              String fn = arg0.getName();
              return arg0.isDirectory() || fn.endsWith(".jar") || fn.endsWith(".zip");
            }
          });
  }
  /**
   * Actions-handling method.
   *
   * @param e The event.
   */
  public void actionPerformed(ActionEvent e) {
    // Prepares the file chooser
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(idata.getInstallPath()));
    fc.setMultiSelectionEnabled(false);
    fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
    // fc.setCurrentDirectory(new File("."));

    // Shows it
    try {
      if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // We handle the xml data writing
        File file = fc.getSelectedFile();
        FileOutputStream out = new FileOutputStream(file);
        BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120);
        parent.writeXMLTree(idata.xmlData, outBuff);
        outBuff.flush();
        outBuff.close();

        autoButton.setEnabled(false);
      }
    } catch (Exception err) {
      err.printStackTrace();
      JOptionPane.showMessageDialog(
          this,
          err.toString(),
          parent.langpack.getString("installer.error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
Esempio n. 18
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);
    }
  }
Esempio n. 19
0
 public File showDirectoryDialog() {
   JFileChooser fc = new JFileChooser();
   fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
   fc.addChoosableFileFilter(new OpenFileFilter("", ""));
   fc.showDialog(null, "選擇目錄");
   return fc.getSelectedFile();
 }
Esempio n. 20
0
 /**
  * 開啟檔案對話視窗
  *
  * @param filter 副檔名,檔案敘述 Ex:".jpg,圖片檔(JPG)"
  * @return
  */
 public File showOpenDialog(String filter) {
   JFileChooser fc = new JFileChooser();
   String[] filters = filter.split(",");
   fc.addChoosableFileFilter(new OpenFileFilter(filters[0], filters[1]));
   fc.showOpenDialog(null);
   return fc.getSelectedFile();
 }
Esempio n. 21
0
 public static File getFile(JComponent parent, FileNameExtensionFilter filter) {
   JFileChooser jfc = new JFileChooser();
   jfc.addChoosableFileFilter(filter);
   jfc.setDialogTitle("VirtualSPARQLer: FileChooser");
   jfc.showOpenDialog(parent);
   return jfc.getSelectedFile();
 }
Esempio n. 22
0
  private void importProjectAndData() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setApproveButtonText("Importa");
    fileChooser.setDialogTitle("Importa progetto e  dati");
    fileChooser.addChoosableFileFilter(new GenericFileFilter(".atd", "Arduino Trend Data"));
    int n = fileChooser.showOpenDialog(view);

    if (n == JFileChooser.APPROVE_OPTION) {

      try {
        project.importProjectAndData(fileChooser.getSelectedFile());
        file = null;
        inizializePens(project.getPenModels());
        modelListPens.update(null, null);
        view.setTitle(project.getTitle());
        view.trend.setModel(project.getTrendModel());
        view.trend.setMillsAtFirstRecord();
      } catch (IOException e) {
        view.popupErrorMessage(e.getMessage());
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        view.popupErrorMessage("File non trovato");
        e.printStackTrace();
      }
    }
  }
Esempio n. 23
0
  public void doLoad() {
    JFileChooser fc = new JFileChooser(m_fCurrentDirectory);

    fc.addChoosableFileFilter(
        new ExtensionsFilter(
            LocalRes.getIntString("label.imagefiles"), "png", "gif", "jpg", "jpeg", "bmp"));

    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      try {
        BufferedImage img = ImageIO.read(fc.getSelectedFile());
        if (img != null) {
          // compruebo que no exceda el tamano maximo.
          if (m_maxsize != null
              && (img.getHeight() > m_maxsize.height || img.getWidth() > m_maxsize.width)) {
            if (JOptionPane.showConfirmDialog(
                    this,
                    LocalRes.getIntString("message.resizeimage"),
                    LocalRes.getIntString("title.editor"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE)
                == JOptionPane.YES_OPTION) {
              // Redimensionamos la imagen para que se ajuste
              img = resizeImage(img);
            }
          }
          setImage(img);
          m_fCurrentDirectory = fc.getCurrentDirectory();
        }
      } catch (IOException eIO) {
      }
    }
  }
Esempio n. 24
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);
  }
  /** Selects a file to use as target for the report processing. */
  protected void performSelectFile() {
    if (fileChooser == null) {
      fileChooser = new JFileChooser();
      final FilesystemFilter filter =
          new FilesystemFilter(
              CSVDataExportDialog.CSV_FILE_EXTENSION,
              getResources().getString("csvexportdialog.csv-file-description")); // $NON-NLS-1$
      fileChooser.addChoosableFileFilter(filter);
      fileChooser.setMultiSelectionEnabled(false);
    }

    fileChooser.setSelectedFile(new File(getFilename()));
    final int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
      final File selFile = fileChooser.getSelectedFile();
      String selFileName = selFile.getAbsolutePath();

      // Test if ends on csv
      if (StringUtils.endsWithIgnoreCase(selFileName, CSVDataExportDialog.CSV_FILE_EXTENSION)
          == false) {
        selFileName = selFileName + CSVDataExportDialog.CSV_FILE_EXTENSION;
      }
      setFilename(selFileName);
    }
  }
Esempio n. 26
0
  public MainFrame() {
    super("GVmakerSE");
    keyBoard = new KeyBoard();
    gvm =
        JGVM.newGVM(
            new GvmConfig(),
            new DefaultFileModel(new FileSysSE("GVM_ROOT")),
            keyBoard.getKeyModel());
    screenPane = new ScreenPane(gvm);
    fileChooser = new JFileChooser("GVM_ROOT");
    fileChooser.addChoosableFileFilter(
        new FileFilter() {

          public boolean accept(File f) {
            if (f.isDirectory()) {
              return true;
            } else {
              return f.getName().toLowerCase().endsWith(".lav");
            }
          }

          public String getDescription() {
            return "GVmaker Application";
          }
        });

    msgLabel = new JLabel(" 结束");
    add(screenPane, BorderLayout.NORTH);
    add(msgLabel, BorderLayout.CENTER);
    add(keyBoard, BorderLayout.SOUTH);

    setJMenuBar(createMenuBar());
    pack();
    setResizable(false);
  }
Esempio n. 27
0
 private void saveBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == binFilter && !binFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + binFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       FileOutputStream output = new FileOutputStream(file);
       for (char i : binary) {
         output.write(i & 0xff);
         output.write((i >> 8) & 0xff);
       }
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
Esempio n. 28
0
    public void actionPerformed(ActionEvent ev) {

      try {

        String[] logFiles = new String[] {"log"};

        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Opening log file...");
        chooser.setMultiSelectionEnabled(false);
        chooser.addChoosableFileFilter(new SimpleFileFilter(logFiles, "Log files (*.log)"));
        chooser.setCurrentDirectory(workingDirectory);

        chooser.showOpenDialog(Utils.getActiveFrame());
        File file = chooser.getSelectedFile();
        logFilename = file.getAbsolutePath();
        System.out.println("Opened " + logFilename + "\n");

        File tmpDir = chooser.getCurrentDirectory();

        if (tmpDir != null) {
          workingDirectory = tmpDir;
        }

      } catch (Exception e) {
        System.err.println("Could not Open! \n");
      }
    }
Esempio n. 29
0
 private void saveSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       PrintStream output = new PrintStream(file);
       output.print(sourceTextarea.getText());
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
Esempio n. 30
0
  /** Handles the clicking of the <b>Add</b> button on the GUI. */
  public void handleOpen() {
    File defaultFile = new File(PCGenSettings.getPcgDir());
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(defaultFile);

    String[] pcgs = new String[] {FILENAME_PCG, FILENAME_PCP};
    SimpleFileFilter ff =
        new SimpleFileFilter(pcgs, LanguageBundle.getString("in_pcgen_file")); // $NON-NLS-1$
    chooser.addChoosableFileFilter(ff);
    chooser.setFileFilter(ff);
    chooser.setMultiSelectionEnabled(true);
    Component component = GMGenSystem.inst;
    Cursor originalCursor = component.getCursor();
    component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    int option = chooser.showOpenDialog(GMGenSystem.inst);

    if (option == JFileChooser.APPROVE_OPTION) {
      for (File selectedFile : chooser.getSelectedFiles()) {
        if (PCGFile.isPCGenCharacterOrPartyFile(selectedFile)) {
          messageHandler.handleMessage(
              new RequestOpenPlayerCharacterMessage(this, selectedFile, false));
        }
      }
    } else {
      /* this means the file is invalid */
    }

    GMGenSystem.inst.setCursor(originalCursor);
  }