List of usage examples for javax.swing JFileChooser addChoosableFileFilter
@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter)
From source file:com.ficeto.esp.EspExceptionDecoder.java
private void createAndUpload() { if (!PreferencesData.get("target_platform").contentEquals("esp8266") && !PreferencesData.get("target_platform").contentEquals("esp32") && !PreferencesData.get("target_platform").contentEquals("ESP31B")) { System.err.println();//from www .j ava 2 s. c o m editor.statusError("Not Supported on " + PreferencesData.get("target_platform")); return; } String tc = "esp32"; if (PreferencesData.get("target_platform").contentEquals("esp8266")) { tc = "lx106"; } TargetPlatform platform = BaseNoGui.getTargetPlatform(); String gccPath = PreferencesData.get("runtime.tools.xtensa-" + tc + "-elf-gcc.path"); if (gccPath == null) { gccPath = platform.getFolder() + "/tools/xtensa-" + tc + "-elf"; } String addr2line; if (PreferencesData.get("runtime.os").contentEquals("windows")) addr2line = "xtensa-" + tc + "-elf-addr2line.exe"; else addr2line = "xtensa-" + tc + "-elf-addr2line"; tool = new File(gccPath + "/bin", addr2line); if (!tool.exists() || !tool.isFile()) { System.err.println(); editor.statusError("ERROR: " + addr2line + " not found!"); return; } elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".ino.elf"); if (!elf.exists() || !elf.isFile()) { elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".cpp.elf"); if (!elf.exists() || !elf.isFile()) { //lets give the user a chance to select the elf final JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new ElfFilter()); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showDialog(editor, "Select ELF"); if (returnVal == JFileChooser.APPROVE_OPTION) { elf = fc.getSelectedFile(); } else { editor.statusError("ERROR: elf was not found!"); System.err.println("Open command cancelled by user."); return; } } } JFrame.setDefaultLookAndFeelDecorated(true); frame = new JFrame("Exception Decoder"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); inputArea = new JTextArea("Paste your stack trace here", 16, 60); inputArea.setLineWrap(true); inputArea.setWrapStyleWord(true); inputArea.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "commit"); inputArea.getActionMap().put("commit", new CommitAction()); inputArea.getDocument().addDocumentListener(this); frame.getContentPane().add(new JScrollPane(inputArea), BorderLayout.PAGE_START); outputText = ""; outputArea = new JTextPane(); outputArea.setContentType("text/html"); outputArea.setEditable(false); outputArea.setBackground(null); outputArea.setBorder(null); outputArea.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); outputArea.setText(outputText); JScrollPane outputScrollPane = new JScrollPane(outputArea); outputScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); outputScrollPane.setPreferredSize(new Dimension(640, 200)); outputScrollPane.setMinimumSize(new Dimension(10, 10)); frame.getContentPane().add(outputScrollPane, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:org.jax.maanova.plot.SaveChartAction.java
/** * {@inheritDoc}/*from w w w . j a va 2 s . co m*/ */ public void actionPerformed(ActionEvent e) { JFreeChart myChart = this.chart; Dimension mySize = this.size; if (myChart == null || mySize == null) { LOG.severe("Failed to save graph image because of a null value"); MessageDialogUtilities.errorLater(Maanova.getInstance().getApplicationFrame(), "Internal error: Failed to save graph image.", "Image Save Failed"); } else { // use the remembered starting dir MaanovaApplicationConfigurationManager configurationManager = MaanovaApplicationConfigurationManager .getInstance(); JMaanovaApplicationState applicationState = configurationManager.getApplicationState(); FileType rememberedJaxbImageDir = applicationState.getRecentImageExportDirectory(); File rememberedImageDir = null; if (rememberedJaxbImageDir != null && rememberedJaxbImageDir.getFileName() != null) { rememberedImageDir = new File(rememberedJaxbImageDir.getFileName()); } // select the image file to save JFileChooser fileChooser = new JFileChooser(rememberedImageDir); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setApproveButtonText("Save Graph"); fileChooser.setDialogTitle("Save Graph as Image"); fileChooser.setMultiSelectionEnabled(false); fileChooser.addChoosableFileFilter(PngFileFilter.getInstance()); fileChooser.setFileFilter(PngFileFilter.getInstance()); int response = fileChooser.showSaveDialog(Maanova.getInstance().getApplicationFrame()); if (response == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); // tack on the extension if there isn't one // already if (!PngFileFilter.getInstance().accept(selectedFile)) { String newFileName = selectedFile.getName() + "." + PngFileFilter.PNG_EXTENSION; selectedFile = new File(selectedFile.getParentFile(), newFileName); } if (selectedFile.exists()) { // ask the user if they're sure they want to overwrite String message = "Exporting the graph image to " + selectedFile.getAbsolutePath() + " will overwrite an " + " existing file. Would you like to continue anyway?"; if (LOG.isLoggable(Level.FINE)) { LOG.fine(message); } boolean overwriteOk = MessageDialogUtilities .confirmOverwrite(Maanova.getInstance().getApplicationFrame(), selectedFile); if (!overwriteOk) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("overwrite canceled"); } return; } } try { ChartUtilities.saveChartAsPNG(selectedFile, myChart, mySize.width, mySize.height); File parentDir = selectedFile.getParentFile(); if (parentDir != null) { // update the "recent image directory" ObjectFactory objectFactory = new ObjectFactory(); FileType latestJaxbImageDir = objectFactory.createFileType(); latestJaxbImageDir.setFileName(parentDir.getAbsolutePath()); applicationState.setRecentImageExportDirectory(latestJaxbImageDir); } } catch (Exception ex) { LOG.log(Level.SEVERE, "failed to save graph image", ex); } } } }
From source file:com.sf.energy.transfer.form.DataConfiguration.java
/** * ??/* w ww . ja v a 2 s .com*/ * @param evt ? */ private void scanActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser fc = new JFileChooser(); File directory = new File(dir); // ?? fc.setCurrentDirectory(directory); fc.setDialogTitle(""); // FileNameExtensionFilter filter1 = new FileNameExtensionFilter(".xls", "xls"); fc.addChoosableFileFilter(filter1); FileNameExtensionFilter filter2 = new FileNameExtensionFilter(".dmp", "dmp"); fc.addChoosableFileFilter(filter1); // fc.setFileFilter(fc.getAcceptAllFileFilter()); int intRetVal = fc.showOpenDialog(new JFrame()); // ? if (intRetVal == JFileChooser.APPROVE_OPTION) { // ? dir = fc.getSelectedFile().getPath(); // filePath.setText(dir); } }
From source file:MyFormApp.java
private void AddbuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddbuttonMouseClicked // TODO add your handling code here: //? ?/*from w ww. j av a2 s. c o m*/ JFileChooser fileChooser = new JFileChooser(); //? fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Documents", "pdf"));//?pdf fileChooser.setAcceptAllFileFilterUsed(false); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) {//???? File selectedFile = fileChooser.getSelectedFile(); try { pdfToimage(selectedFile); //??? } catch (IOException ex) { Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(selectedFile.getName()); //?? File source = new File("" + selectedFile); File dest = new File(PATH + selectedFile.getName()); //copy file conventional way using Stream long start = System.nanoTime(); //copy files using apache commons io start = System.nanoTime(); int a = i + 1; String imagename = FilenameUtils.removeExtension(selectedFile.getName()); model.addElement(new Book(selectedFile.getName(), "" + a, imagename, PATH)); //list i = i + 1; jList2.setModel(model); jList2.setCellRenderer(new BookRenderer()); try { copyFileUsingApacheCommonsIO(source, dest); //? } catch (IOException ex) { Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Time taken by Apache Commons IO Copy = " + (System.nanoTime() - start)); } }
From source file:org.pgptool.gui.ui.importkey.KeyImporterPm.java
public MultipleFilesChooserDialog getSourceFileChooser() { if (sourceFileChooser == null) { sourceFileChooser = new MultipleFilesChooserDialog(findRegisteredWindowIfAny(), appProps, BROWSE_FOLDER) {//from ww w .ja va 2s. c om @Override protected void doFileChooserPostConstruct(JFileChooser ofd) { super.doFileChooserPostConstruct(ofd); ofd.setDialogTitle(Messages.get("action.importKey")); ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter(keyFilesFilter); ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); } private FileFilter keyFilesFilter = new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory() || !f.isFile()) { return true; } if (!isExtension(f.getName(), EXTENSIONS)) { return false; } // NOTE: Although it gives best results -- I have a // slight concern that this might be too heavy operation // to perform thorough -- check for each file // contents. My hope is that since we're checking only // key files it shouldn't be a problem. Non-key files // with same xtensions will not take a long time to fail try { Key readKey = keyFilesOperations.readKeyFromFile(f.getAbsolutePath()); Preconditions.checkState(readKey != null, "Key wasn't parsed"); Key existingKey = keyRingService.findKeyById(readKey.getKeyInfo().getKeyId()); if (existingKey == null) { return true; } if (!existingKey.getKeyData().isCanBeUsedForDecryption() && readKey.getKeyData().isCanBeUsedForDecryption()) { return true; } return false; } catch (Throwable t) { // in this case it's not an issue. So it's debug // level log.debug( "File is not accepte for file chooser becasue was not able to read it as a key", t); } return false; } private boolean isExtension(String fileName, String[] extensions) { String extension = FilenameUtils.getExtension(fileName); if (!StringUtils.hasText(extension)) { return false; } for (String ext : extensions) { if (ext.equalsIgnoreCase(extension)) { return true; } } return false; } @Override public String getDescription() { return "Key files (.asc, .bpg)"; } }; }; } return sourceFileChooser; }
From source file:table.TablePanel.java
public String doSaveAs(File f) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG Image Files", "png"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter);//from w w w. j av a 2s . co m String filename = ""; int option = fileChooser.showSaveDialog(this.parent); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (!filename.endsWith(".png")) { filename = filename + ".png"; } saveTableAsPNG(new File(filename), this.table, parent.getWidth(), parent.getHeight()); } return filename; }
From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java
/** * Show a dialog to export//from w w w .j ava 2s . c o m * a CSV-file that contains the * shown {@link TransactionSum}s * for each month, year or day. */ protected void showExportCSVDialog() { JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(true); fc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(final File aF) { return aF.isDirectory() || aF.getName().endsWith(".csv"); } @Override public String getDescription() { return "CSV-file"; } }); int dialogResult = fc.showSaveDialog(this); if (dialogResult != JFileChooser.APPROVE_OPTION) { return; } File file = fc.getSelectedFile(); if (file.exists()) { int confirmation = JOptionPane.showConfirmDialog(this, "File exists. Replace file?"); if (confirmation != JOptionPane.YES_OPTION) { showExportCSVDialog(); return; } } ExportGranularities gran = (ExportGranularities) myExportGranularityCombobox.getSelectedItem(); try { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); exportCSV(file, gran); } finally { setCursor(Cursor.getDefaultCursor()); } }
From source file:net.sf.profiler4j.console.Console.java
public void openProject() { if (client.isConnected()) { int ret = JOptionPane.showConfirmDialog(mainFrame, "Proceed and disconnect?", "Open Profiling Project", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; }//from ww w . j a v a 2 s. co m } if (checkUnsavedChanges()) { return; } if (client.isConnected()) { disconnect(); if (client.isConnected()) { return; } } JFileChooser fc = new JFileChooser(lastDir); fc.addChoosableFileFilter(projectFilter); if (fc.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { File selFile = fc.getSelectedFile(); SAXBuilder builder = new SAXBuilder(); Document doc = null; try { doc = builder.build(selFile); } catch (JDOMException e) { error("XML Error", e); } catch (IOException e) { error("I/O Error", e); } if (doc != null) { Project p = new Project(); Element el = doc.getRootElement(); p.setHostname(el.getChildText("Host")); p.setPort(Integer.parseInt(el.getChildText("Port"))); Element rulesEl = el.getChild("Rules"); p.setAccess(Rule.AccessOption.valueOf(rulesEl.getAttributeValue("access"))); p.setBeanprops(Boolean.parseBoolean(rulesEl.getAttributeValue("beanProps"))); p.getRules().clear(); for (Iterator i = rulesEl.getChildren("Rule").iterator(); i.hasNext();) { Element r = (Element) i.next(); Rule rule = new Rule(r.getText(), Rule.Action.valueOf(r.getAttributeValue("action"))); p.getRules().add(rule); } // Backwards compatible way to read the export pattern // If it is not there, we leave the defaults as they are, // otherwise we set the saved setting. Element export = el.getChild(PROJECT_XML_ELEMENT__EXPORT_PATTERN); if (null != export) { String enabled = export.getAttributeValue(PROJECT_XML_ATTRIBUTE__ENABLED); p.setExportAutomaticallyEnabled(Boolean.valueOf(enabled)); p.setExportPattern(export.getAttributeValue(PROJECT_XML_ATTRIBUTE__PATTERN)); } p.setFile(selFile); p.clearChanged(); this.project = p; lastDir = selFile.getParentFile(); } } }
From source file:net.sf.profiler4j.console.Console.java
/** * Saves the current project./* w w w .j a v a 2 s. com*/ * * @param saveAs force the user to select a file name even * @return <code>true</code> if the user has cancelled (only in the case of save as) */ public boolean saveProject(boolean saveAs) { if (project.getFile() == null || saveAs) { JFileChooser fc = new JFileChooser(lastDir); fc.setDialogTitle("Save Project As"); fc.addChoosableFileFilter(projectFilter); if (fc.showSaveDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (!f.getName().endsWith(".p4j")) { f = new File(f.getAbsolutePath() + ".p4j"); } project.setFile(f); } else { return true; } } Element rootEl = new Element("Profiler4jProject"); Document doc = new Document(rootEl); rootEl.addContent(new Element("Host").setText(project.getHostname())); rootEl.addContent(new Element("Port").setText(String.valueOf(project.getPort()))); Element rulesEl = new Element("Rules"); rootEl.addContent(rulesEl); rulesEl.setAttribute("access", project.getAccess().name()); rulesEl.setAttribute("beanProps", String.valueOf(project.isBeanprops())); for (Rule rule : project.getRules()) { rulesEl.addContent( new Element("Rule").setText(rule.getPattern()).setAttribute("action", rule.getAction().name())); } Element exportPatternEl = new Element(PROJECT_XML_ELEMENT__EXPORT_PATTERN); String enabled = String.valueOf(project.isExportAutomaticallyEnabled()); exportPatternEl.setAttribute(PROJECT_XML_ATTRIBUTE__ENABLED, enabled); exportPatternEl.setAttribute(PROJECT_XML_ATTRIBUTE__PATTERN, project.getExportPattern()); rootEl.addContent(exportPatternEl); try { FileWriter fw = new FileWriter(project.getFile()); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(doc, fw); fw.close(); project.clearChanged(); } catch (IOException e) { error("I/O Error", e); } return false; }
From source file:net.sf.mzmine.chartbasics.gui.swing.EChartPanel.java
/** * Opens a file chooser and gives the user an opportunity to save the chart in PNG format. * * @throws IOException if there is an I/O error. *//* w w w . ja v a 2s.c om*/ @Override public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs()); FileNameExtensionFilter filter = new FileNameExtensionFilter( localizationResources.getString("PNG_Image_Files"), "png"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(), getChartRenderingInfo()); } }