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:com.original.widget.OPicture.java
/** * very simple method to select an image file. * Please be advised that we will create our own file chooser in the * near future. Since in our system, people will be not encouraged to * access the physical file./*from w w w .j a v a2 s . c o m*/ * * Of course, we need to discuss how to handle this issue. * @return */ private File chooseImgFile() { JFileChooser chooser = new JFileChooser("."); FileFilter imgType = new OriExtFileFilter("Image files", new String[] { ".jpg", ".gif", ".jpeg", ".png" }); chooser.addChoosableFileFilter(imgType); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(imgType); int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); return f; } return null; }
From source file:org.nekorp.workflow.desktop.view.EvidenciaEventoView.java
private void nuevaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevaActionPerformed try {/*from w ww . j a v a 2 s .c o m*/ JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Imagen", "jpg", "jpeg", "png"); chooser.setFileFilter(filter); String homePath = System.getProperty("user.home"); File f = new File(new File(homePath).getCanonicalPath()); chooser.setSelectedFile(f); int returnVal = chooser.showOpenDialog(this.mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); BufferedImage img = ImageIO.read(chooser.getSelectedFile()); img = imageService.resizeToStandarSize(img); BufferedImage thumb = imageService.getThumbnail(img); EvidenciaVB nuevaEvidencia = new EvidenciaVB(); nuevaEvidencia.setImage(imageService.guardarImagen(img)); nuevaEvidencia.setThumbnail(imageService.guardarImagen(thumb)); ThumbnailView thumbview = new ThumbnailView(thumb, this); thumbview.setEditableStatus(editable); thumbs.add(thumbview); modelo.add(nuevaEvidencia); previewContent.add(thumbview); this.ignore.add(modelo); actualizaModelo(); selectEvent(thumbview); this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } } catch (IOException ex) { EvidenciaEventoView.LOGGER.error("Error al seleccionar archivo de imagen", ex); } }
From source file:calendarexportplugin.exporter.CalExporter.java
/** * Shows a file chooser for calendar Files. * * @return selected File//from w ww . java2 s.c o m * @param programs * programs that are exported */ private File chooseFile(Program[] programs) { JFileChooser select = new JFileChooser(); ExtensionFileFilter vCal = new ExtensionFileFilter(mExtension, mExtensionFilter); select.addChoosableFileFilter(vCal); String ext = "." + mExtension; if (mSavePath != null) { select.setSelectedFile(new File(mSavePath)); select.setFileFilter(vCal); } // check if all programs have same title. if so, use as filename String fileName = programs[0].getTitle(); for (int i = 1; i < programs.length; i++) { if (!programs[i].getTitle().equals(fileName)) { fileName = ""; } } fileName = CalendarToolbox.cleanFilename(fileName); if (StringUtils.isNotEmpty(fileName)) { if (mSavePath == null) { mSavePath = ""; } select.setSelectedFile(new File((new File(mSavePath).getParent()) + File.separator + fileName + ext)); } if (select.showSaveDialog( CalendarExportPlugin.getInstance().getBestParentFrame()) == JFileChooser.APPROVE_OPTION) { String filename = select.getSelectedFile().getAbsolutePath(); if (!filename.toLowerCase().endsWith(ext)) { if (filename.endsWith(".")) { filename = filename.substring(0, filename.length() - 1); } filename = filename + ext; } return new File(filename); } return null; }
From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java
@Override public void actionPerformed(final ActionEvent event) { super.actionPerformed(event); final String command = event.getActionCommand(); if ("SAVE_EMF".equals(command)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("EMF Image", "EMF"); chooser.setFileFilter(filter); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getPath(); if (!file.toLowerCase().endsWith(".emf")) file += ".emf"; int width = (int) this.getSize().getWidth(); int height = (int) this.getSize().getHeight(); // Save image SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EMF); new Thread(SI).start(); }/*ww w. j a va2 s . co m*/ } if ("SAVE_EPS".equals(command)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("EPS Image", "EPS"); chooser.setFileFilter(filter); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getPath(); if (!file.toLowerCase().endsWith(".eps")) file += ".eps"; int width = (int) this.getSize().getWidth(); int height = (int) this.getSize().getHeight(); // Save image SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EPS); new Thread(SI).start(); } } }
From source file:jmap2gml.ScriptGui.java
/** * Formats the window, initializes the JMap2Script object, and sets up all * the necessary events.//from w ww .j ava 2s . co m */ public ScriptGui() { setTitle("jmap to gml script converter"); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setLayout(new GridBagLayout()); this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent we) { } @Override public void windowClosing(WindowEvent we) { saveConfig(); } @Override public void windowClosed(WindowEvent we) { } @Override public void windowIconified(WindowEvent we) { } @Override public void windowDeiconified(WindowEvent we) { } @Override public void windowActivated(WindowEvent we) { } @Override public void windowDeactivated(WindowEvent we) { } }); GridBagConstraints c = new GridBagConstraints(); setResizable(true); setIconImage((new ImageIcon("spikeup.png")).getImage()); jta = new JTextArea(38, 30); loadConfig(); JScrollPane jsp = new JScrollPane(jta); jsp.setRowHeaderView(new TextLineNumber(jta)); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); jsp.setSize(jsp.getWidth(), 608); // menu bar JMenuBar menubar = new JMenuBar(); // file menu JMenu file = new JMenu("File"); // load button JMenuItem load = new JMenuItem("Load jmap"); load.addActionListener(ae -> { JFileChooser fileChooser = new JFileChooser(prevDirectory); fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap")); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); prevDirectory = selectedFile.getAbsolutePath(); jm2s = new ScriptFromJmap(selectedFile.getPath(), false); jta.setText(""); jta.append(jm2s.toString()); jta.setCaretPosition(0); writeFile.setEnabled(true); drawPanel.setItems(jta.getText().split("\n")); } }); // add load to file menu file.add(load); // button to save script to file writeFile = new JMenuItem("Write file"); writeFile.addActionListener(ae -> { if (jm2s != null) { PrintWriter out; try { File f = new File( jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml"); out = new PrintWriter(f); out.append(jm2s.toString()); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); writeFile.setEnabled(false); JMenuItem gmx = new JMenuItem("Export as gmx"); gmx.addActionListener(ae -> { String fn = String.format("%s.room.gmx", prevDirectory); JFileChooser fc = new JFileChooser(prevDirectory); fc.setSelectedFile(new File(fn)); fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx")); fc.showDialog(null, "Save"); File f = fc.getSelectedFile(); if (f != null) { try { GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f)); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); // add to file menu file.add(writeFile); file.add(gmx); // add file menu to the menubar menubar.add(file); // Edit menu // display menu JMenu display = new JMenu("Display"); JMenuItem update = new JMenuItem("Update"); update.addActionListener(ae -> { drawPanel.setItems(jta.getText().split("\n")); }); display.add(update); JMenuItem gridToggle = new JMenuItem("Toggle Grid"); gridToggle.addActionListener(ae -> { drawPanel.toggleGrid(); }); display.add(gridToggle); JMenuItem gridOptions = new JMenuItem("Modify Grid"); gridOptions.addActionListener(ae -> { drawPanel.modifyGrid(); }); display.add(gridOptions); menubar.add(display); // sets the menubar setJMenuBar(menubar); // add the text area to the window c.gridx = 0; c.gridy = 0; add(jsp, c); // initialize the preview panel drawPanel = new Preview(this); JScrollPane scrollPane = new JScrollPane(drawPanel); // add preview panel to the window c.gridx = 1; c.gridwidth = 2; add(scrollPane, c); pack(); setMinimumSize(this.getSize()); setLocationRelativeTo(null); setVisible(true); drawPanel.setItems(jta.getText().split("\n")); }
From source file:org.nekorp.workflow.desktop.view.AppLayoutView.java
private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed try {/*w w w . j a va2 s . c om*/ parametrosReporteGlobal.setFechaInicial(new Date()); parametrosReporteGlobal.setFechaFinal(new Date()); parametrosReporteGlobalDialogFactory.createDialog(mainFrame, true).setVisible(true); if (parametrosReporteGlobal.isEjecutar()) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx"); chooser.setFileFilter(filter); String homePath = System.getProperty("user.home"); File f = new File(new File(homePath + "/Reporte-Global" + ".xlsx").getCanonicalPath()); chooser.setSelectedFile(f); int returnVal = chooser.showSaveDialog(this.mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); ParametrosReporteGlobal param = new ParametrosReporteGlobal(); param.setDestination(chooser.getSelectedFile()); DateTime fechaInicial = new DateTime(parametrosReporteGlobal.getFechaInicial()); DateTime fechaFinal = new DateTime(parametrosReporteGlobal.getFechaFinal()); fechaFinal = new DateTime(fechaFinal.getYear(), fechaFinal.getMonthOfYear(), fechaFinal.getDayOfMonth(), fechaFinal.hourOfDay().getMaximumValue(), fechaFinal.minuteOfHour().getMaximumValue(), fechaFinal.secondOfMinute().getMaximumValue(), fechaFinal.millisOfSecond().getMaximumValue(), fechaFinal.getZone()); param.setFechaInicial(fechaInicial); param.setFechaFinal(fechaFinal); this.aplication.generaReporteGlobal(param); } } } catch (IOException ex) { AppLayoutView.LOGGER.error("Exploto al tratar de generar el reporte global", ex); } finally { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.dialogs.hexeditors.DialogEditSVGImageValue.java
private void buttonLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLoadActionPerformed final JFileChooser openDialog = new JFileChooser(lastOpenedFile); openDialog.setDialogTitle("Select SVG file"); openDialog.setAcceptAllFileFilterUsed(true); openDialog.setFileFilter(Utils.SVG_FILE_FILTER); if (openDialog.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { lastOpenedFile = openDialog.getSelectedFile(); try {//from ww w . j a va 2 s . c o m final SVGImage img = new SVGImage(lastOpenedFile); this.value.setImage(img); this.panelPreview.removeAll(); this.panelPreview.add( new JLabel(new ImageIcon( img.rasterize(PREVIEW_SIZE, PREVIEW_SIZE, BufferedImage.TYPE_INT_ARGB))), BorderLayout.CENTER); this.panelPreview.revalidate(); this.panelPreview.repaint(); this.buttonOk.setEnabled(true); this.buttonSaveAs.setEnabled(true); } catch (IOException ex) { Log.error("Can't rasterize image [" + lastOpenedFile + ']', ex); JOptionPane.showMessageDialog(this, "Can't load the file, may be it is not a SVG file", "Can't load the file", JOptionPane.ERROR_MESSAGE); } } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.LoadGenericDRDataController.java
/** * Private methods//from w ww.j ava 2 s . c o m */ //init view private void initDataLoadingPanel() { dataLoadingPanel = new DRDataLoadingPanel(); /** * Action Listeners. */ //Popup file selector and import and parse the file dataLoadingPanel.getChooseFileButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Open a JFile Chooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle( "Choose a tabular file (XLS, XLSX, CSV, TSV) for the import of the experiment"); // to select only appropriate files fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } int index = f.getName().lastIndexOf("."); String extension = f.getName().substring(index + 1); return extension.equals("xls") || extension.equals("xlsx") || extension.equals("csv") || extension.equals("tsv"); } @Override public String getDescription() { return (".xls, .xlsx, .csv and .tsv files"); } }); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setAcceptAllFileFilterUsed(false); // in response to the button click, show open dialog int returnVal = fileChooser.showOpenDialog(dataLoadingPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = fileChooser.getSelectedFile(); // // create and execute a new swing worker with the selected file for the import // ImportExperimentSwingWorker importExperimentSwingWorker = new ImportExperimentSwingWorker(chosenFile); // importExperimentSwingWorker.execute(); parseDRFile(chosenFile); if (doseResponseController.getImportedDRDataHolder().getDoseResponseData() != null) { dataLoadingPanel.getFileLabel().setText(chosenFile.getAbsolutePath()); doseResponseController.getGenericDRParentPanel().getNextButton().setEnabled(true); } } else { JOptionPane.showMessageDialog(dataLoadingPanel, "Command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } } }); dataLoadingPanel.getLogTransformCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { doseResponseController.setLogTransform(true); } else { doseResponseController.setLogTransform(false); } } }); }
From source file:ch.bfh.lca._15h.server.gui.MainWindowServer.java
private String getPath() { String text = ""; FileNameExtensionFilter filter = null; String path = ""; if (this.activeModule.equals("table")) { filter = new FileNameExtensionFilter("EXCEL File", "xlsx"); text = "Wo mchten Sie das Excel ersellen?"; } else {//from w w w. j a va2s . com filter = new FileNameExtensionFilter("JPEG File", "jpg"); text = "Wo mchten Sie das Bild ersellen?"; } // JFileChooser-Objekt erstellen JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(filter); // Dialog zum Speichern von Dateien anzeigen int resultValue = chooser.showDialog(null, text); if (resultValue != JFileChooser.ABORT) { path = chooser.getSelectedFile().getAbsolutePath(); } return path; }
From source file:Simulator.java
private void init() { setSize(400, 400);/*from w w w . j av a 2 s .c o m*/ treeMap = new JMapViewerTree("Zones"); // Listen to the map viewer for user operations so components will // receive events and update map().addJMVListener(this); setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); JPanel panel = new JPanel(new BorderLayout()); JPanel panelTop = new JPanel(); JPanel panelBottom = new JPanel(); JPanel helpPanel = new JPanel(); mperpLabelName = new JLabel("Meters/Pixels: "); mperpLabelValue = new JLabel(String.format("%s", map().getMeterPerPixel())); zoomLabel = new JLabel("Zoom: "); zoomValue = new JLabel(String.format("%s", map().getZoom())); add(panel, BorderLayout.NORTH); add(helpPanel, BorderLayout.SOUTH); panel.add(panelTop, BorderLayout.NORTH); panel.add(panelBottom, BorderLayout.SOUTH); JLabel helpLabel = new JLabel( "Use right mouse button to move,\n " + "left double click or mouse wheel to zoom."); helpPanel.add(helpLabel); JButton button = new JButton("Fit GPS Markers"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { map().setDisplayToFitMapMarkers(); } }); panelBottom.add(button); JButton openButton = new JButton("Open GPS File"); openButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser openFileDlg = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text"); openFileDlg.setFileFilter(filter); if (openFileDlg.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File file = openFileDlg.getSelectedFile(); //This is where a real application would open the file. System.out.println("Opening: " + file.getAbsolutePath() + "."); plotPoints(file.getAbsolutePath()); } else { System.out.println("Open command cancelled by user."); } } }); panelBottom.add(openButton); final JCheckBox showMapMarker = new JCheckBox("Map markers visible"); showMapMarker.setSelected(map().getMapMarkersVisible()); showMapMarker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { map().setMapMarkerVisible(showMapMarker.isSelected()); } }); panelBottom.add(showMapMarker); panelTop.add(zoomLabel); panelTop.add(zoomValue); panelTop.add(mperpLabelName); panelTop.add(mperpLabelValue); add(treeMap, BorderLayout.CENTER); }