List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java
private void iconButtonActionPerformed(ActionEvent e) { File currentFile;// w w w.jav a 2s.com String projetRoot = ScenarioUtils.getScenarioDir().getParentFile().getAbsolutePath(); if (userStyleData.getIconFile2D() != null) currentFile = new File(userStyleData.getIconFile2D()); else currentFile = new File(projetRoot); if (!currentFile.exists()) currentFile = currentFile.getParentFile(); shapeComboBox.setEnabled(false); iconColorbutton.setEnabled(false); File chosenFile; JFileChooser chooser = new JFileChooser(currentFile); // TODO Projections: init from viz registry data entries if (displayType.equals(DisplayType.TWO_D)) { chooser.setFileFilter(new IconFile2DFilter()); chooser.showOpenDialog(this); chosenFile = chooser.getSelectedFile(); if (chosenFile != null) { iconButton.setFont(iconButton.getFont().deriveFont(Font.BOLD)); userStyleData.setIconFile2D(makeRelativePath(chosenFile.getAbsolutePath())); iconButton.setText("Icon Set"); preview.setIconFile(chosenFile); disableColorButtons(); } } else { chooser.setFileFilter(new ModelFile3DFilter()); chooser.showOpenDialog(this); chosenFile = chooser.getSelectedFile(); if (chosenFile != null) { iconButton.setFont(iconButton.getFont().deriveFont(Font.BOLD)); userStyleData.setModelFile3D(makeRelativePath(chosenFile.getAbsolutePath())); iconButton.setText("Model Set"); } } }
From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java
private void textureButtonActionPerformed(ActionEvent e) { File currentFile;/*from w w w. ja va2s. co m*/ if (userStyleData.getTextureFile3D() != null) currentFile = new File(userStyleData.getTextureFile3D()); else currentFile = new File("/"); if (!currentFile.exists()) currentFile = currentFile.getParentFile(); JFileChooser chooser = new JFileChooser(currentFile); chooser.setFileFilter(new IconFile2DFilter()); chooser.showOpenDialog(this); File chosenFile = chooser.getSelectedFile(); if (chosenFile != null) { userStyleData.setTextureFile3D(chosenFile.getAbsolutePath()); textureButton.setFont(textureButton.getFont().deriveFont(Font.BOLD)); textureButton.setText("Texture Set"); disableColorButtons(); } }
From source file:richtercloud.document.scanner.gui.DocumentScanner.java
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files", "pdf"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); final File selectedFile = chooser.getSelectedFile(); if (returnVal != JFileChooser.APPROVE_OPTION) { return;/*w w w . j ava 2s.com*/ } OCREngine oCREngine = DocumentScanner.this.retrieveOCREngine(); if (oCREngine == null) { //a warning in form of a dialog has been given return; } try { List<BufferedImage> images = this.mainPanel.retrieveImages(selectedFile); if (images == null) { LOGGER.debug("image retrieval has been canceled, discontinuing adding document"); return; } this.mainPanel.addDocument(images, selectedFile); } catch (DocumentAddException | InterruptedException | ExecutionException ex) { handleException(ex, "Exception during adding new document"); } }
From source file:ru.goodfil.catalog.ui.forms.FilterWindow.java
private void btnUploadImageActionPerformed() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter( new FileNameExtensionFilter("? (*.png, *.gif, *.jpg)", "png", "gif", "jpg")); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File destinationFile = fileChooser.getSelectedFile(); Assert.notNull(destinationFile); Assert.isTrue(destinationFile.exists()); Assert.isTrue(destinationFile.isFile()); String targetDirectory = Services.getPropertiesService() .getProperty(PropertiesService.IMAGES_DIRECTORY_PATH); if (targetDirectory == null) { UIUtils.error(//from w ww . j a v a 2 s . c om " ? - ? ?. " + "\n? ??!"); return; } else { File directory = new File(targetDirectory); if (!directory.isDirectory() || !directory.exists()) { UIUtils.error( " ? - ? ?. " + "\n? ??!"); return; } try { File targetFile = new File(targetDirectory + File.separator + destinationFile.getName()); FileUtils.copyFile(destinationFile, targetFile); tbImage.setText(destinationFile.getName()); UIUtils.info(" !"); } catch (IOException e) { UIUtils.error( "? ? ? . ? ??."); e.printStackTrace(); } } } }
From source file:ru.goodfil.catalog.ui.forms.MainWindow.java
/** * //ww w.j a v a2 s.c om * * @param e */ private void saveAsMenuItemActionPerformed(ActionEvent e) { try { JFileChooser fileChooser = new JFileChooser(); fileChooser.setSelectedFile(new File(new File("~/GoodwillCatalog.h2.db").getCanonicalPath())); fileChooser.setFileFilter(new FileNameExtensionFilter(" (*.h2.db)", "db")); int result = fileChooser.showSaveDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File destinationFile = fileChooser.getSelectedFile(); if (destinationFile != null) { sessionProvider.close(); File database = new File(SessionFactoryHolder.getDatabasePathWithPrefix()); try { FileUtils.copyFile(database, destinationFile); } catch (IOException e1) { e1.printStackTrace(); UIUtils.error("? ? ? !"); } sessionProvider.init(); } } } catch (Exception e2) { e2.printStackTrace(); } }
From source file:sc.fiji.kappa.gui.CurvesExporter.java
public void export(boolean exportAveragePerCurve) throws IOException { JFileChooser kappaExport = new JFileChooser(); String dirPath = frame.getImageStack().getOriginalFileInfo().directory; if (dirPath != null) { String kappaPath = FilenameUtils.removeExtension(frame.getImageStack().getOriginalFileInfo().fileName); kappaPath += ".csv"; File fullPath = new File(dirPath, kappaPath); kappaExport.setSelectedFile(fullPath); }//from w w w. jav a 2 s .c o m kappaExport.setFileFilter(new FileNameExtensionFilter("CSV File", "csv")); kappaExport.setDialogTitle("Export Curve Data"); // Handles export button action. int returnVal = kappaExport.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = kappaExport.getSelectedFile(); exportToFile(file, exportAveragePerCurve); } }
From source file:schemagenerator.DBbeheer.java
private void jbAddImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddImageActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filterPNG = new FileNameExtensionFilter("PNG bestanden", "png"); chooser.setFileFilter(filterPNG); chooser.showOpenDialog(null);/*from w ww. jav a 2 s. c o m*/ File f = chooser.getSelectedFile(); filename = f.getAbsolutePath(); jtfPad.setText(filename); try { File image = new File(filename); FileInputStream fis = new FileInputStream(image); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } oefening_image = bos.toByteArray(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } }
From source file:scrabble.frmStartup.java
private void btnOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFileActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser.setFileFilter(new FileNameExtensionFilter("Archivos XML", "xml", "xml")); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); txtFilePath.setText(selectedFile.getAbsolutePath()); }/*from w ww .j a v a2 s .c o m*/ }
From source file:se.cambio.cds.gdl.editor.controller.GDLEditor.java
public void saveCompiledGuideAsObject(byte[] compiledGuide, Guide guide) { GDLEditor controller = EditorManager.getActiveGDLEditor(); String idGuide = controller.getIdGuide(); if (idGuide == null) { idGuide = GDLEditorLanguageManager.getMessage("Guide"); }/*from w w w. ja v a 2 s.c o m*/ if (compiledGuide != null) { try { String guideSource = controller.serializeCurrentGuide(); if (guideSource != null) { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( GDLEditorLanguageManager.getMessage("Guide"), new String[] { "guide" }); fileChooser.setDialogTitle(GDLEditorLanguageManager.getMessage("SaveGuideAsObjectSD")); fileChooser.setFileFilter(filter); File file = new File( fileChooser.getFileSystemView().getDefaultDirectory() + "/" + idGuide + ".guide"); fileChooser.setSelectedFile(file); int result = fileChooser.showSaveDialog(EditorManager.getActiveEditorWindow()); File guideFile = fileChooser.getSelectedFile(); if (result != JFileChooser.CANCEL_OPTION) { idGuide = guideFile.getName(); if (idGuide.endsWith(".guide")) { idGuide = idGuide.substring(0, idGuide.length() - 6); } GuideDTO guideDTO = new GuideDTO(idGuide, guideSource, IOUtils.getBytes(guide), compiledGuide, true, Calendar.getInstance().getTime()); ObjectOutputStream output = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream(guideFile))); try { output.writeObject(guideDTO); } catch (Exception e) { ExceptionHandler.handle(e); } finally { output.close(); } } } } catch (Exception e) { ExceptionHandler.handle(e); } } }
From source file:se.cambio.cds.util.ExportUtils.java
public static void exportToHTML(Window owner, Guide guide, String lang) { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML", new String[] { "html" }); fileChooser.setDialogTitle(OpenEHRLanguageManager.getMessage("ExportToHTML")); fileChooser.setFileFilter(filter); File selectedFile = new File(guide.getId() + ".html"); fileChooser.setSelectedFile(selectedFile); int result = fileChooser.showSaveDialog(owner); if (result != JFileChooser.CANCEL_OPTION) { try {// w ww .j a va2 s. co m selectedFile = fileChooser.getSelectedFile(); FileWriter fstream = new FileWriter(selectedFile); BufferedWriter out = new BufferedWriter(fstream); out.write(convertToHTML(guide, lang)); out.close(); } catch (IOException e) { ExceptionHandler.handle(e); } catch (InternalErrorException e) { ExceptionHandler.handle(e); } } }