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:org.prom5.analysis.performance.PerformanceAnalysisGUI.java
/** * Creates a filechooser where the user can select the (comma-seperated) * file that he wants to export to. If this file already exists, permission * to overwrite is requested, else a new file is created to which the * time-metrics of the selected place/transitions are exported. * *//*from ww w. j a v a2 s.c o m*/ private void exportObjectMetrics() { //create and initialize the file chooser final JFileChooser fc = new JFileChooser(); NameFilter filt1 = new NameFilter(".csv"); NameFilter filt2 = new NameFilter(".txt"); fc.addChoosableFileFilter(filt1); fc.addChoosableFileFilter(filt2); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filt1); //check whether a place is selected int result = fc.showDialog(this, "Export"); if (result == 0) { //Export-button was pushed File selectedFile = fc.getSelectedFile(); if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) { //create new file, with filetype added to it selectedFile = new File( selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1)); } if (!selectedFile.exists()) { if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) { //actually perform export of place time-metrics exportPlaceMetrics(selectedFile); } else { if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) { //actually perform export of transition time-metrics exportTransitionMetrics(selectedFile); } else { //actually perform export of activity time-metrics exportActivityMetrics(selectedFile); } } } else { //file already exist, open a confirm dialog containing a //'Yes' Button as well as a 'No' button int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?", "Confirm Dialog", 0); if (overwrite == 0) { //user has selected Yes if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) { //actually perform export of place time-metrics exportPlaceMetrics(selectedFile); } else { if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) { //actually perform export of transition time-metrics exportTransitionMetrics(selectedFile); } else { //actually perform export of activity time-metrics exportActivityMetrics(selectedFile); } } } } } }
From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java
/** * Creates a filechooser where the user can select the (comma-seperated) * file that he wants to export to. If this file already exists, permission * to overwrite is requested, else a new file is created to which the * throughput times of the selected process instances are exported. * *//* ww w . jav a2s. c om*/ private void exportProcessMetrics() { //create and initialize the file chooser final JFileChooser fc = new JFileChooser(); NameFilter filt1 = new NameFilter(".csv"); NameFilter filt2 = new NameFilter(".txt"); fc.addChoosableFileFilter(filt1); fc.addChoosableFileFilter(filt2); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filt1); //check whether a place is selected int result = fc.showDialog(this, "Export"); if (result == 0) { //Export-button was pushed File selectedFile = fc.getSelectedFile(); if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) { //create new file, with filetype added to it selectedFile = new File( selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1)); } if (!selectedFile.exists()) { try { //actually export the throughput times to the file replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort, advancedSettings[0]); } catch (IOException ex) { Message.add("IO exception: " + ex.toString(), 2); } } else { //file already exist, open a confirm dialog containing a //'Yes' Button as well as a 'No' button int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?", "Confirm Dialog", 0); if (overwrite == 0) { //user has selected Yes try { //actually export the throughput times to the file replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort, advancedSettings[0]); } catch (IOException ex) { Message.add("IO exception: " + ex.toString(), 2); } } } } }
From source file:org.p_vcd.ui.VcdDialog.java
private void selectFileButton() { JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);/*from w w w.j a v a 2 s.c om*/ fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter( new FileNameExtensionFilter("images and videos", Parameters.get().getImageAndVideoExtensions())); File def = Parameters.get().getDefaultDir_QuerySelection(); if (def != null) fc.setCurrentDirectory(def); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { Parameters.get().updateDefaultDir_QuerySelection(fc.getCurrentDirectory()); queryFile = fc.getSelectedFile(); lbl_queryFile.setText(queryFile.getAbsolutePath()); radio_queryFile.setSelected(true); } }
From source file:org.richie.codeGen.ui.CodeGenMainUI.java
/** * /*from w w w . j a v a 2 s . c o m*/ */ private void openPdmFile() { JFileChooser jfc = new JFileChooser();// LastOperateVo lastOperateVo = null; try { lastOperateVo = GlobalData.getLastOperateVo(); } catch (Exception e2) { log.error("??", e2); } if (lastOperateVo != null && lastOperateVo.getPdmFilePath() != null) { jfc.setCurrentDirectory(new File(lastOperateVo.getPdmFilePath()));// ?d } else { jfc.setCurrentDirectory(new File("d:\\"));// ?d } jfc.setFileSelectionMode(0);// ? jfc.setFileFilter(new FileFilter() { public boolean accept(File f) { if (f.getName().endsWith(".pdm") || f.isDirectory()) { return true; } return false; } public String getDescription() { return "pdm(*.pdm)"; } }); int state = jfc.showOpenDialog(null); if (state == 1) { return; } else { File f = jfc.getSelectedFile(); initTree(f.getAbsolutePath()); try { if (lastOperateVo == null) { lastOperateVo = new LastOperateVo(); } lastOperateVo.setPdmFilePath(f.getAbsolutePath()); GlobalData.saveLastOperateVo(); } catch (Exception e1) { log.error("???pdm", e1); } } }
From source file:org.rvsnoop.ui.RvSnoopApplication.java
@Override protected void startup() { setMainFrame(injector.getInstance(Application.class).getFrame()); final JFrame frame = getMainFrame(); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new FrameClosingListener()); addExitListener(new MaybeExit()); ApplicationActionMap actionMap = getContext().getActionMap(); JMenu fileMenu = frame.getJMenuBar().getMenu(0); fileMenu.addSeparator();//from w ww .j av a 2 s. c o m fileMenu.add(actionMap.get("quit")); frame.getJMenuBar().add(createHelpMenu()); getContext().getResourceMap().injectComponents(frame); if (AppHelper.getPlatform() == PlatformType.OS_X) { configureMacOsEventHandlers(); } if (initialProjectFile == null) { final JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ProjectFileFilter()); final int option = chooser.showDialog(null, "Open Project"); initialProjectFile = chooser.getSelectedFile(); if (JFileChooser.APPROVE_OPTION != option || initialProjectFile == null) { exit(); } } show(frame); injector.getInstance(ProjectService.class).openProject(initialProjectFile); }
From source file:org.scify.talkandplay.gui.users.UserFormPanel.java
private void uploadImageLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uploadImageLabelMouseClicked userImage = ""; JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter( new FileNameExtensionFilter("Image Files", "png", "jpg", "jpeg", "JPG", "JPEG", "gif")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { userImage = chooser.getSelectedFile().getAbsolutePath(); uploadImageLabel.setIcon(guiHelper.getIcon(userImage)); }/*from www . j a v a 2 s .c om*/ }
From source file:org.signserver.admin.gui.AddWorkerDialog.java
private void filePathBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathBrowseButtonActionPerformed final JFileChooser chooser = new JFileChooser(); final File baseDir = SignServerAdminGUIApplication.getBaseDir(); final String basedirPath = baseDir.getAbsolutePath(); final File sampleDir = new File(basedirPath + File.separator + "doc" + File.separator + "sample-configs"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setCurrentDirectory(sampleDir.isDirectory() ? sampleDir : baseDir); chooser.setFileFilter(new FileNameExtensionFilter("Properties files", "properties")); final int res = chooser.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { final File file = chooser.getSelectedFile(); filePathTextField.setText(file.getAbsolutePath()); fileSelected = true;// www . ja v a 2s. c om } updateControls(); }
From source file:org.slage.handlers.SaveWithChooserDialog.java
/** Save the object */ protected void fire() { if (getTarget() instanceof org.slage.SlageGame == false) setTarget(org.slage.Slage.getCurrentGame()); org.slage.SlageGame game = (org.slage.SlageGame) getTarget(); game.pause();//from w ww. ja va2 s . c om javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); chooser.addComponentListener(game.getFrame()); int iReturn = -1; try { chooser.setFileFilter(org.slage.xml.XMLProcessor.XMLFilter); iReturn = chooser.showSaveDialog(game.getFrame()); } catch (Exception ex) { LOG.warn(ex); game.resume(); } if (iReturn == JFileChooser.APPROVE_OPTION) { String strFile = chooser.getSelectedFile().getAbsolutePath(); if (strFile.toUpperCase().endsWith(".XML") == false) strFile = strFile + ".XML"; if (strFile != null && getTarget() != null) { try { XMLProcessor.save(strFile, getTarget()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } game.resume(); }
From source file:org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.java
private String searchForFile() { String filePath = null;//from w ww . jav a 2 s.co m JFileChooser fc = new JFileChooser(); fc.setDragEnabled(false); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); String[] EXTENSION = new String[] { "txt", "idx", "hash", "Hash", "kdb" }; //NON-NLS FileNameExtensionFilter filter = new FileNameExtensionFilter( NbBundle.getMessage(this.getClass(), "HashDbManager.fileNameExtensionFilter.title"), EXTENSION); fc.setFileFilter(filter); fc.setMultiSelectionEnabled(false); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); try { filePath = f.getCanonicalPath(); } catch (IOException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.WARNING, "Couldn't get selected file path", ex); //NON-NLS } } return filePath; }
From source file:org.squidy.designer.Designer.java
/** * Initializes menu bar./*w ww . j a v a2 s. co m*/ */ private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu workspace = new JMenu("Workspace"); workspace.add(new AbstractAction("Open from...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); int option = fileChooser.showOpenDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { // Stop replacing workspace if currently running. if (data != null) { data.getWorkspace().stop(); } File workspaceFile = fileChooser.getSelectedFile(); if (storage instanceof LocalJAXBStorage) { ((LocalJAXBStorage) storage).setWorkspaceFile(workspaceFile); load(); } else { try { data = ModelViewHandler.getModelViewHandler().load(new FileInputStream(workspaceFile)); WorkspaceShape workspace = data.getWorkspaceShape(); workspace.setModel(data); workspace.setStorageHandler(Designer.this); workspace.initialize(); LayoutConstraint lc = workspace.getLayoutConstraint(); workspace.setScale(lc.getScale()); workspace.setOffset(lc.getX(), lc.getY()); getCanvas().getLayer().addChild(workspace); zoomToZoomedShape(data); } catch (SquidyException e1) { e1.printStackTrace(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } } } } }); workspace.add(new AbstractAction("Export as...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); if (storage instanceof LocalJAXBStorage) { fileChooser.setSelectedFile(((LocalJAXBStorage) storage).getWorkspaceFile()); } int option = fileChooser.showSaveDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { File workspaceFile = fileChooser.getSelectedFile(); try { ModelViewHandler.getModelViewHandler().save(new FileOutputStream(workspaceFile), data); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); JMenu options = new JMenu("Options"); rendering.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { VisualShape.setRenderPrimitiveRect(rendering.isSelected()); data.setRenderPrimitiveRect(rendering.isSelected()); storage.store(data); repaint(); } }); options.add(rendering); JMenu storage = new JMenu("Storage"); ButtonGroup group = new ButtonGroup(); final JRadioButtonMenuItem storageLocalJAXB = new JRadioButtonMenuItem("Local JAXB"); storageLocalJAXB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageLocalJAXB.isSelected()) { setStorageMode(StorageMode.FILE); } } }); storage.add(storageLocalJAXB); group.add(storageLocalJAXB); final JRadioButtonMenuItem storageBaseX = new JRadioButtonMenuItem("BaseX"); storageBaseX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageBaseX.isSelected()) { setStorageMode(StorageMode.BASEX); } } }); storageBaseX.setSelected(storageType.equals(BaseXStorage.class)); storage.add(storageBaseX); group.add(storageBaseX); options.add(storage); menuBar.add(workspace); menuBar.add(options); setJMenuBar(menuBar); }