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.igormaznitsa.zxpoly.MainForm.java
private File chooseFileForSave(final String title, final File initial, final FileFilter filter) { final JFileChooser chooser = new JFileChooser(initial); chooser.addChoosableFileFilter(filter); chooser.setAcceptAllFileFilterUsed(true); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(title);/*from w ww.ja va2 s. c o m*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); final File result; if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } else { result = null; } return result; }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.controls.ClusteringControl.java
public void init() { maxCluster = state.growingLayer.getXSize() * state.growingLayer.getYSize(); spinnerNoCluster = new JSpinner(new SpinnerNumberModel(1, 1, maxCluster, 1)); spinnerNoCluster.addChangeListener(new ChangeListener() { @Override/*from w w w . j a va2 s . co m*/ public void stateChanged(ChangeEvent e) { numClusters = (Integer) ((JSpinner) e.getSource()).getValue(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { st = m.get(numClusters).sticky; } else { st = false; } sticky.setSelected(st); redrawClustering(); } }); JPanel clusterPanel = UiUtils.makeBorderedPanel(new FlowLayout(FlowLayout.LEFT, 10, 0), "Clusters"); sticky.setToolTipText( "Marks this number of clusters as sticky for a certain leve; the next set of clusters will have a smaller boundary"); sticky.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { st = sticky.isSelected(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { ClusterElementsStorage c = m.get(numClusters); c.sticky = st; // System.out.println("test"); // ((ClusterElementsStorageNode)m.get(numClusters)).sticky = st; redrawClustering(); } } }); colorCluster = new JCheckBox("colour", state.colorClusters); colorCluster.setToolTipText("Fill the clusters in colours"); colorCluster.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.colorClusters = colorCluster.isSelected(); // TODO: Palette anzeigen (?) redrawClustering(); } }); UiUtils.fillPanel(clusterPanel, new JLabel("#"), spinnerNoCluster, sticky, colorCluster); getContentPane().add(clusterPanel, c.nextRow()); dendogramPanel = UiUtils.makeBorderedPanel(new GridLayout(0, 1), "Dendogram"); getContentPane().add(dendogramPanel, c.nextRow()); JPanel numLabelPanel = UiUtils.makeBorderedPanel(new GridBagLayout(), "Labels"); GridBagConstraintsIFS gcLabels = new GridBagConstraintsIFS(); labelSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1)); labelSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { numLabels = (Integer) ((JSpinner) e.getSource()).getValue(); state.clusterWithLabels = numLabels; redrawClustering(); } }); this.showValues = new JCheckBox("values", state.labelsWithValues); this.showValues.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.labelsWithValues = showValues.isSelected(); redrawClustering(); } }); int start = new Double((1 - state.clusterByValue) * 100).intValue(); valueQe = new JSlider(0, 100, start); valueQe.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int byValue = ((JSlider) e.getSource()).getValue(); state.clusterByValue = 1 - byValue / 100; redrawClustering(); } }); numLabelPanel.add(new JLabel("# Labels"), gcLabels); numLabelPanel.add(labelSpinner, gcLabels.nextCol()); numLabelPanel.add(showValues, gcLabels.nextCol()); numLabelPanel.add(valueQe, gcLabels.nextRow().setGridWidth(3).setFill(GridBagConstraints.HORIZONTAL)); getContentPane().add(numLabelPanel, c.nextRow()); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(0, new JLabel("by Value")); labelTable.put(100, new JLabel("by Qe")); valueQe.setToolTipText("Method how to select representative labels - by QE, or the attribute values"); valueQe.setLabelTable(labelTable); valueQe.setPaintLabels(true); final JComboBox initialisationBox = new JComboBox(KMeans.InitType.values()); initialisationBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object o = mapPane.getMap().getClusteringTreeBuilder(); if (o instanceof KMeansTreeBuilder) { ((KMeansTreeBuilder) o).reInit((KMeans.InitType) initialisationBox.getSelectedItem()); // FIXME: is this call needed? mapPane.getMap().getCurrentClusteringTree().getAllClusteringElements(); redrawClustering(); } } }); getContentPane().add(UiUtils.fillPanel(kmeansInitialisationPanel, new JLabel("k-Means initialisation"), initialisationBox), c.nextRow()); JPanel borderPanel = new TitledCollapsiblePanel("Border", new GridLayout(1, 4), true); JSpinner borderSpinner = new JSpinner( new SpinnerNumberModel(ClusteringTree.INITIAL_BORDER_WIDTH_MAGNIFICATION_FACTOR, 0.1, 5, 0.1)); borderSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { state.clusterBorderWidthMagnificationFactor = ((Double) ((JSpinner) e.getSource()).getValue()) .floatValue(); redrawClustering(); } }); borderPanel.add(new JLabel("width")); borderPanel.add(borderSpinner); borderPanel.add(new JLabel("colour")); buttonColour = new JButton(""); buttonColour.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new ClusterBoderColorChooser(state.parentFrame, state.clusterBorderColour, ClusteringControl.this); } }); buttonColour.setBackground(state.clusterBorderColour); borderPanel.add(buttonColour); getContentPane().add(borderPanel, c.nextRow()); JPanel evaluationPanel = new TitledCollapsiblePanel("Cluster Evaluation", new GridLayout(3, 2), true); evaluationPanel.add(new JLabel("quality measure")); qualityMeasureButton = new JButton(); qualityMeasureButton.setText("ent/pur calc"); qualityMeasureButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("doing entropy here"); ClusteringTree clusteringTree = state.mapPNode.getClusteringTree(); if (clusteringTree == null) { // we have not clustered yet return; } // System.out.println(clusteringTree.getChildrenCount()); // FIXME put this in a method and call it on numcluster.change() SOMLibClassInformation classInfo = state.inputDataObjects.getClassInfo(); ArrayList<ClusterNode> clusters = clusteringTree.getNodesAtLevel(numClusters); System.out.println(clusters.size()); // EntropyMeasure.computeEntropy(clusters, classInfo); EntropyAndPurityCalculator eapc = new EntropyAndPurityCalculator(clusters, classInfo); // FIXME round first entropyLabel.setText(String.valueOf(eapc.getEntropy())); purityLabel.setText(String.valueOf(eapc.getPurity())); } }); evaluationPanel.add(qualityMeasureButton); GridBagConstraintsIFS gcEval = new GridBagConstraintsIFS(); evaluationPanel.add(new JLabel("entropy"), gcEval); evaluationPanel.add(new JLabel("purity"), gcEval.nextCol()); entropyLabel = new JLabel("n/a"); purityLabel = new JLabel("n/a"); evaluationPanel.add(entropyLabel, gcEval.nextRow()); evaluationPanel.add(purityLabel, gcEval.nextCol()); getContentPane().add(evaluationPanel, c.nextRow()); JPanel panelButtons = new JPanel(new GridLayout(1, 4)); JButton saveButton = new JButton("Save"); saveButton.setFont(smallFont); saveButton.setMargin(SMALL_INSETS); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser; if (state.fileChooser.getSelectedFile() != null) { fileChooser = new JFileChooser(state.fileChooser.getSelectedFile().getPath()); } else { fileChooser = new JFileChooser(); } fileChooser.addChoosableFileFilter(clusteringFilter); fileChooser.addChoosableFileFilter(xmlFilter); File filePath = ExportUtils.getFilePath(ClusteringControl.this, fileChooser, "Save Clustering and Labels"); if (filePath != null) { if (xmlFilter.accept(filePath)) { LabelXmlUtils.saveLabelsToFile(state.mapPNode, filePath); } else { try { FileOutputStream fos = new FileOutputStream(filePath); GZIPOutputStream gzipOs = new GZIPOutputStream(fos); PObjectOutputStream oos = new PObjectOutputStream(gzipOs); oos.writeObjectTree(mapPane.getMap().getCurrentClusteringTree()); oos.writeObjectTree(mapPane.getMap().getManualLabels()); oos.writeInt(state.clusterWithLabels); oos.writeBoolean(state.labelsWithValues); oos.writeDouble(state.clusterByValue); oos.writeObject(spinnerNoCluster.getValue()); oos.close(); } catch (Exception ex) { ex.printStackTrace(); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(saveButton); JButton loadButton = new JButton("Load"); loadButton.setFont(smallFont); loadButton.setMargin(SMALL_INSETS); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = getFileChooser(); fileChooser.setName("Open Clustering"); fileChooser.addChoosableFileFilter(xmlFilter); fileChooser.addChoosableFileFilter(clusteringFilter); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Open"); if (returnVal == JFileChooser.APPROVE_OPTION) { File filePath = fileChooser.getSelectedFile(); if (xmlFilter.accept(filePath)) { PNode restoredLabels = null; try { restoredLabels = LabelXmlUtils.restoreLabelsFromFile(fileChooser.getSelectedFile()); PNode manual = state.mapPNode.getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = restoredLabels.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } manual.addChildren(tmp); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Successfully loaded cluster labels."); } catch (Exception e1) { e1.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading cluster labels: " + e1.getMessage()); } } else { try { FileInputStream fis = new FileInputStream(filePath); GZIPInputStream gzipIs = new GZIPInputStream(fis); ObjectInputStream ois = new ObjectInputStream(gzipIs); ClusteringTree tree = (ClusteringTree) ois.readObject(); PNode manual = (PNode) ois.readObject(); PNode all = mapPane.getMap().getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = manual.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } all.addChildren(tmp); state.clusterWithLabels = ois.readInt(); labelSpinner.setValue(state.clusterWithLabels); state.labelsWithValues = ois.readBoolean(); showValues.setSelected(state.labelsWithValues); state.clusterByValue = ois.readDouble(); valueQe.setValue(new Double((1 - state.clusterByValue) * 100).intValue()); mapPane.getMap().buildTree(tree); spinnerNoCluster.setValue(ois.readObject()); ois.close(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Successfully loaded clustering."); } catch (Exception ex) { ex.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading clustering: " + ex.getMessage()); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(loadButton); JButton exportImages = new JButton("Export"); exportImages.setFont(smallFont); exportImages.setMargin(SMALL_INSETS); exportImages.setToolTipText("Export labels as images (not yet working)"); exportImages.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); if (CommonSOMViewerStateData.fileNamePrefix != null && !CommonSOMViewerStateData.fileNamePrefix.equals("")) { fileChooser.setCurrentDirectory(new File(CommonSOMViewerStateData.fileNamePrefix)); } else { fileChooser.setCurrentDirectory(state.getFileChooser().getCurrentDirectory()); } fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.getSelectedFile() != null) { // reusing the dialog fileChooser.setSelectedFile(null); } fileChooser.setName("Choose path"); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Choose path"); if (returnVal == JFileChooser.APPROVE_OPTION) { // save images String path = fileChooser.getSelectedFile().getAbsolutePath(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing label images to " + path); } } }); panelButtons.add(exportImages); JButton deleteManual = new JButton("Delete"); deleteManual.setFont(smallFont); deleteManual.setMargin(SMALL_INSETS); deleteManual.setToolTipText("Delete manually added labels."); deleteManual.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.mapPNode.getManualLabels().removeAllChildren(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Manual Labels deleted."); } }); panelButtons.add(deleteManual); c.anchor = GridBagConstraints.NORTH; this.getContentPane().add(panelButtons, c.nextRow()); this.setVisible(true); }
From source file:gui.TheGui.java
private String saveAs() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);/*from w w w .j av a 2s . co m*/ fc.setAcceptAllFileFilterUsed(false); OpenFileFilter m3u_filter = new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format"); OpenFileFilter xspf_filter = new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format"); if (playlistType == PlaylistType.M3U) { fc.addChoosableFileFilter(new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format")); } else { fc.addChoosableFileFilter(new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format")); } int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); filePath = file.getPath(); jTextArea1.append("Saving: " + file.getName() + "." + newline); if (playlistType == PlaylistType.M3U) { return file.getPath() + ".m3u"; } else { return file.getPath() + ".xspf"; } } else { jTextArea1.append("Save command cancelled by user." + newline); return null; } }
From source file:com.igormaznitsa.zxpoly.MainForm.java
private File chooseFileForOpen(final String title, final File initial, final AtomicReference<FileFilter> selectedFilter, final FileFilter... filter) { final JFileChooser chooser = new JFileChooser(initial); for (final FileFilter f : filter) { chooser.addChoosableFileFilter(f); }// w ww. ja va2 s. co m chooser.setAcceptAllFileFilterUsed(false); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(title); chooser.setFileFilter(filter[0]); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); final File result; if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); if (selectedFilter != null) { selectedFilter.set(chooser.getFileFilter()); } } else { result = null; } return result; }
From source file:gui.TheGui.java
private String saveAs() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);//from ww w . j a v a 2s .c o m fc.setAcceptAllFileFilterUsed(false); OpenFileFilter m3u_filter = new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format"); OpenFileFilter xspf_filter = new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format"); if (playlistType == PlaylistType.M3U) fc.addChoosableFileFilter(new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format")); else fc.addChoosableFileFilter(new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format")); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); filePath = file.getPath(); jTextArea1.append("Saving: " + file.getName() + "." + newline); if (playlistType == PlaylistType.M3U) return file.getPath() + ".m3u"; else return file.getPath() + ".xspf"; } else { jTextArea1.append("Save command cancelled by user." + newline); return null; } }
From source file:ctPrincipal.Principal.java
private File openImagem(String Dir, boolean lista) { JFileChooser fileChooser = new JFileChooser(); BufferedImage buff = null;/* w w w .ja v a2 s .c o m*/ String caminho = null; try { caminho = new File(".").getCanonicalPath() + Dir; } catch (IOException ex) { Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex); } fileChooser.setCurrentDirectory(new File(caminho)); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Images", "jpg", "png", "gif", "bmp")); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setMultiSelectionEnabled(true); int result = fileChooser.showOpenDialog(getComponent(0)); if (result == JFileChooser.APPROVE_OPTION) { if (lista) { File[] selectedFile = fileChooser.getSelectedFiles(); arquivos = new String[selectedFile.length]; for (int i = 0; i < selectedFile.length; i++) { selectedFile[i].setReadable(Boolean.TRUE); arquivos[i] = selectedFile[i].getAbsolutePath(); } jLTotal.setText("Total de Imagens : " + arquivos.length); } else { File selectedFile = fileChooser.getSelectedFile(); return selectedFile; } } return null; }
From source file:electroStaticUI.ElectroStaticUIContainer.java
private void buildFileMenu() { //create Exit menu item exitItem = new JMenuItem("Exit"); exitItem.setMnemonic(KeyEvent.VK_X); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0);//from w ww . ja v a2s. c om } }); //open open = new JMenuItem("Open"); open.setMnemonic(KeyEvent.VK_P); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); int status = fChooser.showSaveDialog(null); } }); //close close = new JMenuItem("Close"); close.setMnemonic(KeyEvent.VK_C); //export export = new JMenuItem("Export"); export.setMnemonic(KeyEvent.VK_E); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); fChooser.setMultiSelectionEnabled(false); fChooser.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter svgFilter = new FileNameExtensionFilter("Save Vector Plot(svg)", ".svg"); FileNameExtensionFilter pngFilter = new FileNameExtensionFilter("Save Voltage Surface Plot(png)", ".png"); fChooser.addChoosableFileFilter(svgFilter); fChooser.addChoosableFileFilter(pngFilter); fChooser.setFileFilter(svgFilter); int status = fChooser.showSaveDialog(rootPane); if (status == JFileChooser.APPROVE_OPTION) { if (fChooser.getFileFilter() == svgFilter) { try { saveAsName = fChooser.getSelectedFile().getCanonicalPath(); Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (fChooser.getFileFilter() == pngFilter) { try { saveAsName = fChooser.getSelectedFile().getCanonicalPath(); Save.saveChart3dToPNG(DefaultValues.get3dChartToSave(), saveAsName); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); //save save = new JMenuItem("Save"); save.setMnemonic(KeyEvent.VK_S); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); int status = fChooser.showSaveDialog(null); if (status == JFileChooser.APPROVE_OPTION) { try { System.out.println("Height: " + displayPanel.getWidth()); System.out.println("Width: " + displayPanel.getHeight()); saveAsName = fChooser.getSelectedFile().getCanonicalPath(); Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); //saveAs saveAs = new JMenuItem("Save As"); saveAs.setMnemonic(KeyEvent.VK_A); saveAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); int status = fChooser.showSaveDialog(null); if (status == JFileChooser.APPROVE_OPTION) try { System.out.println("Height: " + displayPanel.getWidth()); System.out.println("Width: " + displayPanel.getHeight()); saveAsName = fChooser.getSelectedFile().getCanonicalPath(); System.out.println(saveAsName); Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } try { Save.saveChartToSVG(UserInput.getElectricFieldChart(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); //JMenu object for file menu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); //fileMenu.add(newFile); //fileMenu.add(open); //fileMenu.add(close); fileMenu.add(export); //fileMenu.add(save); //fileMenu.add(saveAs); fileMenu.add(exitItem); }
From source file:net.sf.nmedit.nomad.core.Nomad.java
public void fileSave(boolean saveAs) { Document d = pageContainer.getSelection(); if (d == null) return;/*from ww w. j av a 2 s . c o m*/ if (!saveAs) { Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); FileService useService = null; while (iter.hasNext()) { FileService fs = iter.next(); if (fs.isDirectSaveOperationSupported(d)) { useService = fs; break; } } if (useService != null) { useService.save(d, useService.getAssociatedFile(d)); return; } } JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(lastSaveInFolderLocation); chooser.setMultiSelectionEnabled(false); Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); while (iter.hasNext()) { FileService fs = iter.next(); boolean add = (saveAs && fs.isSaveOperationSupported(d)) || ((!saveAs) && fs.isDirectSaveOperationSupported(d)); if (add) chooser.addChoosableFileFilter(fs.getFileFilter()); } File sfile = d.getFile(); if (sfile == null && d.getTitle() != null) sfile = new File(d.getTitle()); if (sfile != null) chooser.setSelectedFile(sfile); if (!(chooser.showSaveDialog(mainWindow) == JFileChooser.APPROVE_OPTION)) return; FileService service = FileServiceTool.lookupFileService(chooser); if (service != null) { File newFile = chooser.getSelectedFile(); if (newFile == null) return; if (newFile.exists() && JOptionPane.showConfirmDialog(mainWindow, "Overwrite existing file '" + newFile.getAbsolutePath() + "' ?", "File already exists.", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return; service.save(d, newFile); lastSaveInFolderLocation = newFile.getParentFile(); } else { JOptionPane.showMessageDialog(mainWindow, "Could not find service to save file."); } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format.//www. j av a 2 s . c o m * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs); ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(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"; } } ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight()); } }
From source file:com.commander4j.db.JDBUserReport.java
private String promptUserforSave() { JFileChooser saveTYPE = new JFileChooser(); String filename = getExportFilename(); if (isPromptSaveAsRequired()) { try {/*w w w . j av a2s. co m*/ File f = new File(new File(getExportFilename()).getCanonicalPath()); saveTYPE.setCurrentDirectory(f); if (getDestination().equals("EXCEL")) saveTYPE.addChoosableFileFilter(new JFileFilterXLS()); if (getDestination().equals("JASPER_REPORT")) saveTYPE.addChoosableFileFilter(new JFileFilterPDF()); if (getDestination().equals("PDF")) saveTYPE.addChoosableFileFilter(new JFileFilterPDF()); if (getDestination().equals("CSV")) saveTYPE.addChoosableFileFilter(new JFileFilterCSV()); if (getDestination().equals("ACCESS")) saveTYPE.addChoosableFileFilter(new JFileFilterMDB()); saveTYPE.setSelectedFile(new File(getExportFilename())); int result = saveTYPE.showSaveDialog(Common.mainForm); if (result == 0) { File selectedFile; selectedFile = saveTYPE.getSelectedFile(); if (selectedFile != null) { filename = selectedFile.getAbsolutePath(); } } } catch (Exception ex) { } } return filename; }