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:paquete.HollywoodUI.java
private void btn_buscar_fotoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_buscar_fotoMouseClicked JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(new File("./")); FileFilter filtro = new FileNameExtensionFilter("Jpg, Png", "jpg", "png"); jfc.setFileFilter(filtro); File archivo = null;/*from w ww.jav a2 s . co m*/ try { int op = jfc.showOpenDialog(this.add_actor); if (op == JFileChooser.APPROVE_OPTION) { archivo = jfc.getSelectedFile(); } BufferedImage imagen = ImageIO.read(archivo); Image img; img = Toolkit.getDefaultToolkit().createImage(imagen.getSource()) .getScaledInstance(label_profile.getWidth(), label_profile.getHeight(), 0); label_profile.setIcon(new ImageIcon(img)); this.temp.setFoto_actor(resize(imagen, 54, 54)); } catch (Exception e) { JOptionPane.showMessageDialog(add_actor, "Error al intentar abrir archivo", "ERROR", JOptionPane.ERROR_MESSAGE); } }
From source file:pcgen.gui2.dialog.ExportDialog.java
private void export(boolean pdf) { UIPropertyContext context = UIPropertyContext.createContext("ExportDialog"); final JFileChooser fcExport = new JFileChooser(); fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY); File baseDir = null;/*from ww w. j a v a2 s . com*/ { String path; if (pdf) { path = context.getProperty(PDF_EXPORT_DIR_PROP); } else { path = context.getProperty(HTML_EXPORT_DIR_PROP); } if (path != null) { baseDir = new File(path); } } if (baseDir == null || !baseDir.isDirectory()) { baseDir = SystemUtils.getUserHome(); } fcExport.setCurrentDirectory(baseDir); URI uri = fileList.getSelectedValue(); String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf); if (pdf) { FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("xml".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else { String desc = extension + " Files (*." + extension + ")"; fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension)); } String name; File path; if (!partyBox.isSelected()) { CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem(); path = character.getFileRef().get(); if (path != null) { path = path.getParentFile(); } else { path = new File(PCGenSettings.getPcgDir()); } name = character.getTabNameRef().get(); if (StringUtils.isEmpty(name)) { name = character.getNameRef().get(); } } else { path = new File(PCGenSettings.getPcgDir()); name = "Entire Party"; } if (pdf) { fcExport.setSelectedFile(new File(path, name + ".pdf")); } else { fcExport.setSelectedFile(new File(path, name + "." + extension)); } fcExport.setDialogTitle("Export " + name); if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { return; } final File outFile = fcExport.getSelectedFile(); if (pdf) { context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent()); } else { context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent()); } if (StringUtils.isEmpty(outFile.getName())) { pcgenFrame.showErrorMessage("PCGen", "You must set a filename."); return; } if (outFile.isDirectory()) { pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file."); return; } if (outFile.exists() && !SettingsHandler.getAlwaysOverwrite()) { int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION); if (reallyClose != JOptionPane.YES_OPTION) { return; } } if (pdf) { new PDFExporter(outFile, extension, name).execute(); } else { if (!printToFile(outFile)) { String message = "The character export failed. Please see the log for details."; pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message); return; } maybeOpenFile(outFile); Globals.executePostExportCommandStandard(outFile.getAbsolutePath()); } }
From source file:pcgui.SetupParametersPanel.java
/** * Create the frame./* ww w . ja v a 2s . c o m*/ * * @param switcher * * @param rootFrame */ public SetupParametersPanel(final PanelSwitcher switcher, JFrame rootFrame) { this.rootFrame = rootFrame; setLayout(new BorderLayout()); JLabel headingLabel = new JLabel("Setup Parameters"); headingLabel.setFont(new Font("Tahoma", Font.BOLD, 16)); add(headingLabel, BorderLayout.NORTH); JButton saveBtn = new JButton("Save"); final JButton runModifiedBtn = new JButton("Run"); runModifiedBtn.setEnabled(false); runModifiedBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { runModel(); } }); saveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //creating separate copy of model so that changes in one doesn't effect other ArrayList<ArrayList<Object>> mod = new ArrayList<ArrayList<Object>>(model.getData()); //call save model of modelsaver //TODO add visualization list and save to excel using similar method as below //TODO add modelname, should contain .xls/.xlsx extension SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss"); outputFile = importedFile.toString().replace(".mos", "") + "_" + sdf.format(new Date()) + "_FEORA_solution.xlsx"; ModelSaver.saveInputModel(mod, outputFile); runModifiedBtn.setEnabled(true); } }); JLabel label = new JLabel("Enter count of random value runs"); repeatCount = new JTextField(); repeatCount.setToolTipText("Enter count for which each combination of step variables is run "); repeatCount.setText("1"); repeatCount.setPreferredSize(new Dimension(100, 20)); JPanel runConfig = new JPanel(); runConfig.setLayout(new GridLayout(2, 2)); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.CENTER; JPanel configCount = new JPanel(new FlowLayout()); JPanel configButtons = new JPanel(new FlowLayout()); configCount.add(label); configCount.add(repeatCount); JButton btnLoadSavedConfiguration = new JButton("Load Saved Configuration"); btnLoadSavedConfiguration.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser jFileChooser = new JFileChooser(); File workingDirectory = new File(System.getProperty("user.dir")); jFileChooser.setCurrentDirectory(workingDirectory); jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { // TODO Auto-generated method stub return "Excel solution files"; } @Override public boolean accept(File f) { // TODO Auto-generated method stub return f.isDirectory() || f.getName().endsWith(".xls") || f.getName().endsWith(".xlsx"); } }); int returnVal = jFileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser.getSelectedFile(); // This is where a real application would open the file. if (file.getName().endsWith(".xls") || file.getName().endsWith(".xlsx")) { String fileName = file.getAbsolutePath(); List<List<String>> savedConfig = ModelSaver.loadInputConfigFromExcel(fileName); ArrayList<Symbol> symList = new ArrayList<Symbol>(); int i = 0; for (List<String> list : savedConfig) { //ignore the header row if (i > 0) { System.out.println("VariableName=" + list.get(0)); System.out.println("Datatype=" + list.get(1)); System.out.println("Type=" + list.get(2)); System.out.println("Value=" + list.get(3)); System.out.println("ExternalFile=" + list.get(4)); System.out.println("ExcelRange=" + list.get(5)); System.out.println("DistributionFunction=" + list.get(6)); System.out.println("OutputTracket=" + list.get(7)); Symbol sym = new Symbol<>(); sym.name = list.get(0); sym.typeString = list.get(1); sym.mode = list.get(2); sym.set(list.get(3)); sym.externalFile = list.get(4); sym.excelFileRange = list.get(5); sym.distFunction = list.get(6); sym.trackingEnabled = Boolean.parseBoolean(list.get(7)); symList.add(sym); } i++; } initParamList(symList, parser); } } else { // System.out.println("Open command cancelled by user."); } } }); configButtons.add(btnLoadSavedConfiguration); configButtons.add(saveBtn); configButtons.add(runModifiedBtn); runConfig.add(configCount); runConfig.add(configButtons); add(runConfig, BorderLayout.SOUTH); setVisible(true); }
From source file:pdfreader.PDFReader.java
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) { listOfSelectedRegionInRectangle = new ArrayList<TaggedRegion>(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(currentDir); ExtensionFileFilter pdfFilter = new ExtensionFileFilter(new String[] { "PDF" }, "PDF Files"); chooser.setFileFilter(pdfFilter); int result = chooser.showOpenDialog(PDFReader.this); if (result == JFileChooser.APPROVE_OPTION) { name = chooser.getSelectedFile().getPath(); System.out.println(name); nameOfFile = chooser.getSelectedFile().getName(); currentDir = new File(name).getParentFile(); try {//from ww w . java2 s . co m openPDFFile(""); } catch (Exception e) { e.printStackTrace(); } } }
From source file:phex.gui.common.FileDialogHandler.java
private static JFileChooser initDefaultChooser(String title, String approveBtnText, char approveBtnMnemonic, FileFilter filter, int mode, File currentDirectory, String notifyPopupTitle, String notifyPopupShortMessage) { JFileChooser chooser = new JFileChooser(); if (notifyPopupTitle != null || notifyPopupShortMessage != null) { displayNotificationPopup(chooser, notifyPopupTitle, notifyPopupShortMessage); }// w w w . ja v a 2 s .c om if (currentDirectory != null) { chooser.setCurrentDirectory(currentDirectory); } if (filter != null) { chooser.setFileFilter(filter); } chooser.setFileSelectionMode(mode); chooser.setDialogTitle(title); chooser.setApproveButtonText(approveBtnText); chooser.setApproveButtonMnemonic(approveBtnMnemonic); return chooser; }
From source file:picocash.Picocash.java
@Action(enabledProperty = "accountsAvailable") public void exportAll() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new BackupFileFilter()); int retValue = fileChooser.showSaveDialog(getMainFrame()); if (retValue == JFileChooser.APPROVE_OPTION) { String fileName = fileChooser.getSelectedFile().getAbsolutePath(); if (!fileName.endsWith(".mbck")) { fileName = fileName + ".mbck"; }//from w w w . j av a2 s .co m List<Account> allAccounts = Services.getSelectedPersistenceMan().getAllAccounts(); List<Payee> allPayees = Services.getSelectedPersistenceMan().getAllPayees(); List<Category> allCategories = Services.getSelectedPersistenceMan().getAllCategories(); List<Transaction> allTransactions = Services.getSelectedPersistenceMan().getAllTransactions(); ModelExporter exporter = new ModelExporter(fileName); exporter.setAccounts(allAccounts); exporter.setCategories(allCategories); exporter.setPayees(allPayees); exporter.setTransactions(allTransactions); try { exporter.export(); } catch (Exception ex) { log.info("exception occured while exporting:", ex); } } }
From source file:picocash.Picocash.java
@Action public void importAll() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new BackupFileFilter()); int retValue = fileChooser.showOpenDialog(getMainFrame()); if (retValue == JFileChooser.APPROVE_OPTION) { Services.getSelectedPersistenceMan().clear(); try {//from w ww . j a v a 2 s . c o m ModelImporter importer = new ModelImporter(fileChooser.getSelectedFile().getAbsolutePath()); importer.read(); List<Account> allAccounts = importer.getAllAccounts(); List<Payee> allPayees = importer.getAllPayees(); List<Category> allCategories = importer.getAllCategories(); List<Transaction> allTransactions = importer.getAllTransactions(); setChangesAvailable(true); } catch (Exception ex) { log.info("excpetion occurd while importing [" + fileChooser.getSelectedFile().getAbsolutePath() + "]", ex); } } }
From source file:pl.edu.pw.appt.GUI.java
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Zapisz plik jako..."); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki UMLDump (*.umldump)", "umldump"); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(xmlfilter); DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss"); fileChooser.setSelectedFile(new File(df.format(new Date()))); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); if (!FilenameUtils.getExtension(fileToSave.getName()).equalsIgnoreCase("umldump")) { fileToSave = new File(fileToSave.getParentFile(), FilenameUtils.getBaseName(fileToSave.getName()) + ".umldump"); }/* w w w . j a v a 2 s . co m*/ try { FileHandler.saveFile(Paths.get(fileToSave.getAbsolutePath()), server.messages.toString(selectSystem.getSelectedItem().toString())); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Nie udao si zapisa pliku.", "Wystpi bd", JOptionPane.ERROR_MESSAGE); } } }
From source file:pl.edu.pw.appt.GUI.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki UMLDump (*.umldump)", "umldump"); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(xmlfilter); int returnValue = fileChooser.showOpenDialog(this); String data = null;/*ww w .j a v a 2 s .c om*/ if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try { data = FileHandler.getFile(Paths.get(selectedFile.getAbsolutePath())); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Nie udao si otworzy pliku.", "Wystpi bd", JOptionPane.ERROR_MESSAGE); } server.messages.clear(selectedFile.getName()); String[] lines = data.split("[\\r?\\n]+"); for (String line : lines) { String[] parts = line.split("-"); if (parts.length < 8) { break; } Message message = new Message(parts[0], parts[1], parts[2], parts[3], parts[5], parts[4], parts[6], parts[7]); server.messages.add(selectedFile.getName(), message); } if (((DefaultComboBoxModel) selectSystem.getModel()).getIndexOf(selectedFile.getName()) == -1) { selectSystem.addItem(selectedFile.getName()); selectSystem.setSelectedItem(selectedFile.getName()); } else { selectSystem.setSelectedItem(selectedFile.getName()); } updateUml(server.messages.toUml(selectedFile.getName(), startMsg.getText(), stopMsg.getText())); } }
From source file:pl.edu.pw.appt.GUI.java
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Zapisz obraz jako..."); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki BMP (*.bmp)", "bmp"); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(xmlfilter); DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss"); fileChooser.setSelectedFile(new File(df.format(new Date()))); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); if (!FilenameUtils.getExtension(fileToSave.getName()).equalsIgnoreCase("bmp")) { fileToSave = new File(fileToSave.getParentFile(), FilenameUtils.getBaseName(fileToSave.getName()) + ".bmp"); }//from w w w. j a v a 2 s .c o m try { ImageIO.write((RenderedImage) image, "bmp", fileToSave); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Nie udao si zapisa obrazu.", "Wystpi bd", JOptionPane.ERROR_MESSAGE); } } }