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:pcd3.View.java
private void pilihGambarCitraMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pilihGambarCitraMouseClicked final String path = "./Citra Images/form.1"; javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); chooser.setCurrentDirectory(new File(path)); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public final static String jpeg = "jpeg"; public final String jpg = "jpg"; public final String gif = "gif"; public final String tiff = "tiff"; public final String tif = "tif"; public final String png = "png"; /*Get the extension of a file.*/ public String getExtension(java.io.File f) { String ext = null;//from w ww . jav a 2s .com String s = f.getName(); int i = s.lastIndexOf('.'); if (i > 0 && i < s.length() - 1) { ext = s.substring(i + 1).toLowerCase(); } return ext; } @Override public String getDescription() { return "All Images extensions (jpg, gif, tiff, tif, png)"; } @Override public boolean accept(java.io.File f) { if (f.isDirectory()) { return true; } String extension = getExtension(f); if (extension != null) { return extension.equals(tiff) || extension.equals(tif) || extension.equals(gif) || extension.equals(jpeg) || extension.equals(jpg) || extension.equals(png); } return false; } }); if (chooser.showDialog(this, " Open ") == javax.swing.JFileChooser.APPROVE_OPTION) { java.io.File file = chooser.getSelectedFile(); String filePath = file.toString(); try { final BufferedImage bimg = ImageIO.read(new File(filePath)); namaCitra.setText("Nama Citra : " + file.getName()); Thread t = new Thread() { @Override public void run() { imageFormSiji.setImage(bimg); imageFormSiji.imageToGray(1); imageFormSiji.setHistogram(); int jumlah = 0; DefaultCategoryDataset chartBarAwal = new DefaultCategoryDataset(); DefaultCategoryDataset chartBarHasil = new DefaultCategoryDataset(); //barChartData.setva for (int i = 0; i < imageFormSiji.getHistogram().size(); i++) { System.out.println(imageFormSiji.getHistogram().get(i).getRgb() + " = " + imageFormSiji.getHistogram().get(i).getJumlah() + " = " + imageFormSiji.getHistogram().get(i).getJumlahKumulatif() + " = " + imageFormSiji.getHistogram().get(i).getHasilEkualisasi()); jumlah += imageFormSiji.getHistogram().get(i).getJumlah(); chartBarAwal.setValue(imageFormSiji.getHistogram().get(i).getJumlah(), "aha", "" + imageFormSiji.getHistogram().get(i).getRgb()); chartBarHasil.setValue(imageFormSiji.getHistogram().get(i).getHasilEkualisasi(), "aha", "" + imageFormSiji.getHistogram().get(i).getRgb()); } JFreeChart chartSiji = ChartFactory.createBarChart("Histogam Citra Awal", "RGB", "Jumlah", chartBarAwal, PlotOrientation.VERTICAL, false, true, false); JFreeChart chartLoro = ChartFactory.createBarChart("Histogram Citra Ekualisasi", "RGB", "Jumlah", chartBarHasil, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryPlotSiji = chartSiji.getCategoryPlot(); CategoryPlot categoryPlotLoro = chartLoro.getCategoryPlot(); categoryPlotSiji.setRangeGridlinePaint(Color.orange); categoryPlotLoro.setRangeGridlinePaint(Color.orange); ChartPanel cpanelSiji = new ChartPanel(chartSiji); ChartPanel cpanelLoro = new ChartPanel(chartLoro); chartAwal.removeAll(); chartAwal.add(cpanelSiji); chartAwal.validate(); chartEkualisasi.removeAll(); chartEkualisasi.add(cpanelLoro); chartEkualisasi.validate(); System.out.println("Jumlah = " + jumlah); citraLabel.setText(""); citraGrayLabel.setText(""); citraEkualisasi.setText(""); citraLabel.setIcon(new ImageIcon(bimg.getScaledInstance(230, 230, 0))); //resetCitra(); ukuranCitra.setText("Ukuran Citra : " + imageFormSiji.getTinggi() + " x " + imageFormSiji.getLebar() + ""); imageFormSiji.setSmoothingImage(); imageFormSiji.setSharpeningImage(); citraEkualisasi.setIcon( new ImageIcon(imageFormSiji.getEqualImage().getScaledInstance(230, 230, 0))); citraGrayLabel.setIcon( new ImageIcon(imageFormSiji.getGrayImage().getScaledInstance(230, 230, 0))); citraSmoothingHasil.setIcon(new ImageIcon(imageFormSiji.getSmoothingImage())); citraSharpheningHasil.setIcon(new ImageIcon(imageFormSiji.getSharpeningImage())); } }; t.start(); } catch (IOException e) { javax.swing.JOptionPane.showMessageDialog(this, "File Tidak Ditemukan " + e); } } }
From source file:fll.subjective.SubjectiveFrame.java
/** * Prompt the user for a file./*from w ww . jav a2 s. co m*/ * * @param title the title on the chooser dialog * @return the file if accepted, null if canceled */ private File chooseSubjectiveFile(final String title) { final File initialDirectory = getInitialDirectory(); final JFileChooser fileChooser = new JFileChooser(initialDirectory); fileChooser.setDialogTitle(title); fileChooser.setFileFilter(new BasicFileFilter("FLL Subjective Data Files", "fll")); final int state = fileChooser.showOpenDialog(this); if (JFileChooser.APPROVE_OPTION == state) { final File file = fileChooser.getSelectedFile(); setInitialDirectory(file); return file; } else { return null; } }
From source file:com.ejie.uda.jsonI18nEditor.Editor.java
public void showImportDialog() { String path = null;/* w w w . j a v a 2s . co m*/ if (resourcesDir != null) { path = resourcesDir.toString(); } JFileChooser fc = new JFileChooser(path); fc.setDialogTitle(MessageBundle.get("dialogs.import.title")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new FileNameExtensionFilter("json i18n file", "json")); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { importResources(Paths.get(fc.getSelectedFile().getPath())); } }
From source file:gui.InboxPanel.java
private void openVerifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openVerifyButtonActionPerformed JFileChooser chooser = new JFileChooser(); int retrieval = chooser.showOpenDialog(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Public file", "pub"); chooser.setFileFilter(filter); if (retrieval == JFileChooser.APPROVE_OPTION) { FileInputStream fis = null; try {/*from w ww . j a va 2 s. c o m*/ File file = chooser.getSelectedFile(); Path path = Paths.get(file.getAbsolutePath()); fis = new FileInputStream(file); //Construct BufferedReader from InputStreamReader BufferedReader br = new BufferedReader(new InputStreamReader(fis)); try { String x = br.readLine(); String y = br.readLine(); publickey = new BigPoint(new BigInteger(x), new BigInteger(y)); System.out.println("Public key : " + publickey.getX() + publickey.getY()); br.close(); } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fis.close(); } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Persists out the timelord file and allows the user to choose where * the file should go./*from w w w .jav a 2 s . c o m*/ * * @param rwClassName the name of the RW class * (e.g. "net.chaosserver.timelord.data.ExcelDataReaderWriter") * @param userSelect allows the user to select where the file should * be persisted. */ public void writeTimeTrackData(String rwClassName, boolean userSelect) { try { Class<?> rwClass = Class.forName(rwClassName); TimelordDataReaderWriter timelordDataRW = (TimelordDataReaderWriter) rwClass.newInstance(); int result = JFileChooser.APPROVE_OPTION; File outputFile = timelordDataRW.getDefaultOutputFile(); if (timelordDataRW instanceof TimelordDataReaderWriterUI) { TimelordDataReaderWriterUI timelordDataReaderWriterUI = (TimelordDataReaderWriterUI) timelordDataRW; timelordDataReaderWriterUI.setParentFrame(applicationFrame); JDialog configDialog = timelordDataReaderWriterUI.getConfigDialog(); configDialog.pack(); configDialog.setLocationRelativeTo(applicationFrame); configDialog.setVisible(true); } if (userSelect) { if (OsUtil.isMac()) { FileDialog fileDialog = new FileDialog(applicationFrame, "Select File", FileDialog.SAVE); fileDialog.setDirectory(outputFile.getParent()); fileDialog.setFile(outputFile.getName()); fileDialog.setVisible(true); if (fileDialog.getFile() != null) { outputFile = new File(fileDialog.getDirectory(), fileDialog.getFile()); } } else { JFileChooser fileChooser = new JFileChooser(outputFile.getParentFile()); fileChooser.setSelectedFile(outputFile); fileChooser.setFileFilter(timelordDataRW.getFileFilter()); result = fileChooser.showSaveDialog(applicationFrame); if (result == JFileChooser.APPROVE_OPTION) { outputFile = fileChooser.getSelectedFile(); } } } if (result == JFileChooser.APPROVE_OPTION) { timelordDataRW.writeTimelordData(getTimelordData(), outputFile); } } catch (Exception e) { JOptionPane.showMessageDialog(applicationFrame, "Error writing to file.\n" + "Do you have the output file open?", "Save Error", JOptionPane.ERROR_MESSAGE, applicationIcon); if (log.isErrorEnabled()) { log.error("Error persisting file", e); } } }
From source file:edu.synth.SynthHelper.java
public String openDialogFileChooser(String path, boolean dirOnly, String name, String button, String filterType) {/*from w ww .j av a2s . c o m*/ JFileChooser fileOpen = new JFileChooser(); if (!path.isEmpty()) fileOpen.setCurrentDirectory(new File(path)); else fileOpen.setCurrentDirectory(new File(".")); if (dirOnly) fileOpen.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else { fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); switch (filterType) { case "abn": FileFilter filter = new FileNameExtensionFilter("*.abn - Abundances file", "abn"); fileOpen.setFileFilter(filter); break; case "model": filter = new FileNameExtensionFilter("*.atl - Kurucz's format model file", "atl"); fileOpen.setFileFilter(filter); break; case "lns": filter = new FileNameExtensionFilter("*.lns - Lines file", "lns"); fileOpen.setFileFilter(filter); break; } } fileOpen.setDialogTitle(name); fileOpen.setApproveButtonText(button); int returnVal = fileOpen.showOpenDialog(fileOpen); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedPath = fileOpen.getSelectedFile(); if (selectedPath != null) return selectedPath.getAbsolutePath(); } return ""; }
From source file:dylemator.UserList.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed if (this.filenameCombo.getSelectedIndex() == 0) return;/*from w w w . j av a 2 s . c o m*/ String sheetName = (String) this.filenameCombo.getSelectedItem(); Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet(sheetName); Row headerRow = sheet.createRow(0); String[] headers = exportData.get(0); int numOfColumns = headers.length; for (int i = 0; i < numOfColumns; i++) { Cell cell = headerRow.createCell(i); cell.setCellValue(headers[i]); } int rowCount = exportData.size(); for (int rownum = 1; rownum < rowCount; rownum++) { Row row = sheet.createRow(rownum); String[] values = exportData.get(rownum); for (int i = 0; i < numOfColumns; i++) { Cell cell = row.createCell(i); cell.setCellValue(values[i]); } } String defaultFilename = "Export.xlsx"; JFileChooser f = new JFileChooser(System.getProperty("user.dir")); f.setSelectedFile(new File(defaultFilename)); f.setDialogTitle("Wybierz nazw dla pliku eksportu"); f.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter ff = new FileFilter() { @Override public boolean accept(File file) { if (file.getName().endsWith(".xlsx")) return true; return false; } @Override public String getDescription() { return ""; } }; f.setFileFilter(ff); File file = null; int save = f.showSaveDialog(this); if (save == JFileChooser.APPROVE_OPTION) file = f.getSelectedFile(); else return; FileOutputStream out; try { out = new FileOutputStream(file); wb.write(out); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ispd.gui.JResultados.java
private void jButtonSalvarTracesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarTracesActionPerformed FiltroDeArquivos filtro = new FiltroDeArquivos("Workload Model of Simulation", ".wmsx", true); JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setFileFilter(filtro); int returnVal = jFileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser.getSelectedFile(); if (!file.getName().endsWith(".wmsx")) { File temp = new File(file.toString() + ".wmsx"); file = temp;//from w w w .j av a 2 s . c om } TraceXML interpret = new TraceXML(file.getAbsolutePath()); interpret.geraTraceSim(tarefas); } }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
protected SimpleAction createSaveScriptAsAction() { return new SimpleAction("Save as", "Save script as", "document-save-as-2-16x16.png") { @Override//from w w w . j av a 2s . co m public void actionPerformed(ActionEvent e) { validateScriptData(); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter( AppConstants.ORG_NAME + " script (" + ScriptConstants.FILE_EXT.toLowerCase() + ")", ScriptConstants.FILE_EXT)); File file = ScriptEditor.this.file; if (file == null) { file = createDefaultFilename(); } if (file == null) { file = PreferencesManager.getSingleton().getScriptsDirectory(); } // ensure absolute if (file != null) { file = file.getAbsoluteFile(); } // ensure have filename if (file != null && file.isDirectory()) { file = new File(file, createDefaultPathlessFilename()); } if (file != null) { chooser.setCurrentDirectory(file.getParentFile()); chooser.setSelectedFile(file); } if (chooser.showSaveDialog(ScriptEditor.this) == JFileChooser.APPROVE_OPTION) { save(chooser.getSelectedFile()); } } }; }
From source file:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java
private void openTable() { this.checkToSave(); DataCenter.minerals = new HashMap<Integer, Vector<Point>>(); this.clearJTable(); try {//from w ww . jav a 2 s .com File currentDir = new File(System.getProperty("user.dir")); JFileChooser openDialgo = new JFileChooser(currentDir); FileNameExtensionFilter filter = new FileNameExtensionFilter("MTF File", "mtf", "mtf"); openDialgo.setFileFilter(filter); int response = openDialgo.showOpenDialog(this); if (response == openDialgo.APPROVE_OPTION) { this.openTable(openDialgo.getSelectedFile()); } } catch (Exception e) { } }