Java Code Examples for javax.swing.JFileChooser.showSaveDialog()

The following are Jave code examples for showing how to use showSaveDialog() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sic-public   File: SettingsFrame.java   View Source Code Vote up 8 votes
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // Imprimir
    try{
        JFileChooser fcPick = new JFileChooser();
        int returnVal = fcPick.showSaveDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fcPick.getSelectedFile();
            new MainFrame().setFile(file);
            if(file.getName().contains(".txt")){
                //writer.writeIt(file, factura.toString());
                //new MainFrame().setFile(file);
            }else{
                //writer.writeIt(file.getPath()+".txt", factura.toString());
            }

        }
        
    }catch(Exception e){
        showMessageDialog(null, "Error: por favor verifique la ruta de su archivo.");
        
    }

}
 
Example 2
Project: PekaED   File: PekaEDGUI.java   View Source Code Vote up 6 votes
private void saveLevelAs() {
	JFileChooser fc = new JFileChooser();
	fc.setDialogTitle("Save as...");
	
	fc.setFileFilter(new FileNameExtensionFilter("Pekka Kana 2 Level", "map", "MAP"));
	
	if (Data.currentFile == null) {
		fc.setSelectedFile(new File(Settings.EPISODES_PATH));
	} else {
		fc.setSelectedFile(Data.currentFile);
	}
	
	int res = fc.showSaveDialog(frame);
	
	if (res == JFileChooser.APPROVE_OPTION) {
		saveLevel(fc.getSelectedFile());
	}
}
 
Example 3
Project: scratch-bench   File: MainMenu.java   View Source Code Vote up 6 votes
private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed

        JFileChooser fileChooser=new JFileChooser();
		fileChooser.setDialogTitle("Speciify a file to Save");
		int userSelection=fileChooser.showSaveDialog(this);
		if(userSelection==JFileChooser.APPROVE_OPTION)
		{
			File fileToSave=fileChooser.getSelectedFile();
			fileToSave.getAbsolutePath();
        if(!fileToSave.exists())
        {
                            try {
                                fileToSave.createNewFile();
                            } catch (IOException ex) {
                                Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
                            }
        }
			paintToPDF(editorPanes.get(tabbedPane.getSelectedIndex()),fileToSave);
		}
// TODO add your handling code here:
    }
 
Example 4
Project: zooracle   File: FileUtils.java   View Source Code Vote up 6 votes
public static String saveFile(Component component, String choosertitle, String startDirectory)
{
	JFileChooser chooser = new JFileChooser(); 
	chooser.setCurrentDirectory(new java.io.File(startDirectory!=null?".":startDirectory));
	chooser.setDialogTitle(choosertitle);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.setAcceptAllFileFilterUsed(false);
	
	if (chooser.showSaveDialog(component) == JFileChooser.APPROVE_OPTION) { 
		System.out.println("getCurrentDirectory(): "  +  chooser.getCurrentDirectory());
		System.out.println("getSelectedFile() : "  +  chooser.getSelectedFile());
		return chooser.getSelectedFile().toString();
	}
	else {
		System.out.println("No Selection ");
		return null;
	}
	
}
 
Example 5
Project: Bachelor-Thesis   File: GUIControls.java   View Source Code Vote up 6 votes
private void takeScreenShot() {	
	try {
		JFileChooser fc = new JFileChooser();
		fc.setSelectedFile(new File(SCREENSHOT_FILE + 
				"." + SCREENSHOT_FILE_TYPE));
		int retVal = fc.showSaveDialog(this);
		if (retVal == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();
			BufferedImage i = new BufferedImage(this.pf.getWidth(), 
					this.pf.getHeight(), BufferedImage.TYPE_INT_RGB);
			Graphics2D g2 = i.createGraphics();

			this.pf.paint(g2);	// paint playfield to buffered image
			ImageIO.write(i, SCREENSHOT_FILE_TYPE, file);
		}
	} 
	catch (Exception e) {
		JOptionPane.showMessageDialog(gui.getParentFrame(), 
				"screenshot failed (problems with output file?)",
				"Exception", JOptionPane.ERROR_MESSAGE);
	}
}
 
Example 6
Project: JITRAX   File: FileDialog.java   View Source Code Vote up 5 votes
/**
 * Returns as a string the content of a chosen file.
 * @param dialogTitle
 * @return
 */
public String importFileContent(String dialogTitle) {
	JFileChooser fileChooser = new JFileChooser();
	String filePath;
	int userSelection;
	
	fileChooser.setDialogTitle(dialogTitle);
	userSelection = fileChooser.showSaveDialog(null);
	
	if (userSelection == JFileChooser.APPROVE_OPTION) {
		filePath = fileChooser.getSelectedFile().getAbsolutePath();
		
		// Read file
		byte[] encoded;
		
		try {
			encoded = Files.readAllBytes(Paths.get(filePath));
			return new String(encoded, StandardCharsets.UTF_8);
		}
		
		catch (IOException e) {
			e.printStackTrace();
		} 
	}
	
	return null;
}
 
Example 7
Project: incubator-netbeans   File: ChangeImportFolder.java   View Source Code Vote up 5 votes
private void folderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_folderButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        folderField.setText(fc.getSelectedFile().getAbsolutePath());
        firePropertyChange("validity", null, null);
    }
}
 
Example 8
Project: jaer   File: AbstractAviWriter.java   View Source Code Vote up 5 votes
synchronized public void doStartRecordingAndSaveAVIAs() {
    if (aviOutputStream != null) {
        JOptionPane.showMessageDialog(null, "AVI output stream is already opened");
        return;
    }
    JFileChooser c = new JFileChooser(lastFileName);
    c.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".avi");
        }

        @Override
        public String getDescription() {
            return "AVI (Audio Video Interleave) Microsoft video file";
        }
    });
    c.setSelectedFile(new File(lastFileName));
    int ret = c.showSaveDialog(null);
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    if (!c.getSelectedFile().getName().toLowerCase().endsWith(".avi")) {
        String newName = c.getSelectedFile().toString() + ".avi";
        c.setSelectedFile(new File(newName));
    }
    lastFileName = c.getSelectedFile().toString();
    
    if (c.getSelectedFile().exists()) {
        int r = JOptionPane.showConfirmDialog(null, "File " + c.getSelectedFile().toString() + " already exists, overwrite it?");
        if (r != JOptionPane.OK_OPTION) {
            return;
        }
    }
    openAVIOutputStream(c.getSelectedFile(), additionalComments);
}
 
Example 9
Project: xdman   File: XDMMainWindow.java   View Source Code Vote up 5 votes
public void renameFile(DownloadListItem item, int row) {
	if (item.state == IXDMConstants.COMPLETE) {
		showMessageBox(getString("DWN_FINISHED"), getString("DEFAULT_TITLE"), JOptionPane.ERROR_MESSAGE);
	} else {
		String file, folder;
		JFileChooser jfc = XDMFileChooser.getFileChooser(JFileChooser.FILES_ONLY,
				new File(item.saveto, item.filename));
		if (jfc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
			return;
		}
		file = jfc.getSelectedFile().getName();
		folder = jfc.getSelectedFile().getParent();
		if (item.mgr != null) {
			if (item.mgr.getState() == IXDMConstants.ASSEMBLING) {
				showMessageBox(getString("DWN_ASSEMBLING"), getString("DEFAULT_TITLE"), JOptionPane.ERROR_MESSAGE);
			} else {
				item.mgr.setDestdir(folder);
				item.mgr.setFileName(file);
			}
		}
		item.filename = file;
		item.saveto = folder;
		list.downloadStateChanged();

		model.fireTableDataChanged();// model.fireListItemUpdated(row);
	}
}
 
Example 10
Project: geomapapp   File: GMAProfile.java   View Source Code Vote up 5 votes
int askOverWrite() {
	JFileChooser chooser = MapApp.getFileChooser();
	int ok = JOptionPane.NO_OPTION;
	while( true ) {
		ok = JOptionPane.showConfirmDialog(dialog,
			"File exists. Overwrite?",
			"Overwrite?",
			JOptionPane.YES_NO_CANCEL_OPTION);
		if( ok!=JOptionPane.NO_OPTION) return ok;
		ok = chooser.showSaveDialog(dialog);
		if( ok==JFileChooser.CANCEL_OPTION ) return JOptionPane.CANCEL_OPTION;
		if( !chooser.getSelectedFile().exists() ) return JOptionPane.YES_OPTION;
	}
}
 
Example 11
Project: sstore-soft   File: AbstractViewer.java   View Source Code Vote up 5 votes
protected String showSaveDialog(String title, String dir, IOFileFilter filter, File defaultFile) throws Exception {
    JFileChooser chooser = new JFileChooser(dir);
    chooser.setFileFilter(filter);
    chooser.setDialogTitle(title);
    if (defaultFile != null) chooser.setSelectedFile(defaultFile);
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return (chooser.getSelectedFile().toString());
    }
    return (null);
}
 
Example 12
Project: java-course   File: FIleFactory.java   View Source Code Vote up 5 votes
/**
 * Opens a file from disk.
 * 
 * @param frame
 *            Parent frame.
 * @return Opened file.
 */
public static File getFile(JVDraw frame) {
    JFileChooser fc = new JFileChooser("./");
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileNameExtensionFilter(".jvd", "jvd"));
    int status = fc.showSaveDialog(frame);

    if (status == JFileChooser.OPEN_DIALOG) {
        return setExtension(fc.getSelectedFile(), ".jvd");
    }
    return null;
}
 
Example 13
Project: HBaseClient   File: MenuExportStructureDataAction.java   View Source Code Vote up 5 votes
@Override
public void onClick(ActionEvent arg0)
{
    List<String> v_TableNames = this.getHBase().getTableNames();
    
    if ( JavaHelp.isNull(v_TableNames) )
    {
        this.getAppFrame().showHintInfo("数据库中不存在表" ,Color.BLUE);
        return;
    }
    
    
    File         v_SaveFile    = new File(this.getHBase().getHBaseIP() + ".txt");
    JFileChooser v_FileChooser = new JFileChooser();
    v_FileChooser.setSelectedFile(v_SaveFile);
    
    try
    {
        // 不知道为什么非要sleep一下才再在多次反复打开对话窗口时不出异常,保证每次都能打开对话窗口。
        // 测试环境:Mac 10.12.5、Java 1.6、Eclipse 4.3.2
        Thread.sleep(10);
    }
    catch (Exception exce)
    {
        // Nothing.
    }
    
    int v_Result = v_FileChooser.showSaveDialog(this.getAppFrame());
    if ( v_Result == JFileChooser.APPROVE_OPTION )
    {
        v_SaveFile = v_FileChooser.getSelectedFile();
        
        this.writeContents(v_TableNames ,v_SaveFile);
    }
}
 
Example 14
Project: jdk8u-jdk   File: J2DBench.java   View Source Code Vote up 4 votes
public static boolean saveResults(String title, String desc) {
    lastResults.setTitle(title);
    lastResults.setDescription(desc);
    JFileChooser fc = getFileChooser();
    int ret = fc.showSaveDialog(guiFrame);
    if (ret == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        boolean append = false;
        if (file.exists()) {
            if (!file.isFile()) {
                System.err.println("Cannot save results to a directory!");
                return false;
            }
            ret = JOptionPane.showOptionDialog
                (guiFrame,
                 new String[] {
                     "The file '"+file.getName()+"' already exists!",
                     "",
                     "Do you wish to overwrite or append to this file?",
                 },
                 "File exists!",
                 JOptionPane.DEFAULT_OPTION,
                 JOptionPane.WARNING_MESSAGE,
                 null, new String[] {
                     "Overwrite",
                     "Append",
                     "Cancel",
                 }, "Cancel");
            if (ret == 0) {
                append = false;
            } else if (ret == 1) {
                append = true;
            } else {
                return false;
            }
        }
        String reason = saveResults(file, append);
        if (reason == null) {
            return true;
        } else {
            System.err.println(reason);
        }
    }
    return false;
}
 
Example 15
Project: zencash-swing-wallet-ui   File: DataTable.java   View Source Code Vote up 4 votes
private void exportToCSV()
	throws IOException
{
       final String ENCODING = "UTF-8";
	
	JFileChooser fileChooser = new JFileChooser();
	fileChooser.setDialogTitle("Export data to CSV file...");
	fileChooser.setFileFilter(new FileNameExtensionFilter("CSV Files (*.csv)", "csv"));
	 
	int result = fileChooser.showSaveDialog(this.getRootPane().getParent());
	 
	if (result != JFileChooser.APPROVE_OPTION) 
	{
	    return;
	}
	
	File f = fileChooser.getSelectedFile();
	
	FileOutputStream fos = new FileOutputStream(f);
	fos.write(new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF } );
	
	// Write header
	StringBuilder header = new StringBuilder();
	for (int i = 0; i < this.getColumnCount(); i++)
	{
		String columnName = this.getColumnName(i);
		header.append(columnName);
		
		if (i < (this.getColumnCount() - 1))
		{
			header.append(",");
		}
	}
	header.append("\n");
	fos.write(header.toString().getBytes(ENCODING));
	
	// Write rows
	for (int row = 0; row < this.getRowCount(); row++)
	{
		StringBuilder rowBuf = new StringBuilder();
		for (int col = 0; col < this.getColumnCount(); col++)
		{
			rowBuf.append(this.getValueAt(row, col).toString());
			
			if (col < (this.getColumnCount() - 1))
			{
				rowBuf.append(",");
			}
		}
		rowBuf.append("\n");
		fos.write(rowBuf.toString().getBytes(ENCODING));
	}
	
	fos.close();
	
	JOptionPane.showMessageDialog(
		this.getRootPane().getParent(), 
		"The data has been exported successfully as CSV to location:\n" +
		f.getCanonicalPath(),
		"Export successful...", JOptionPane.INFORMATION_MESSAGE);
}
 
Example 16
Project: geomapapp   File: XMap.java   View Source Code Vote up 4 votes
public void saveJPEGImage() throws IOException {
	JFileChooser chooser = MapApp.getFileChooser();
	int ok = chooser.showSaveDialog(getTopLevelAncestor());
	if(ok==chooser.CANCEL_OPTION) return;
	saveJPEGImage( chooser.getSelectedFile() );
}
 
Example 17
Project: geomapapp   File: MapLocations.java   View Source Code Vote up 4 votes
public void addLocation() {
	double zoom = map.getZoom();
	Rectangle2D r = map.getClipRect2D();
	Point2D.Double p = new Point2D.Double(
			r.getX()+.5*r.getWidth(),
			r.getY()+.5*r.getHeight() );
	p = (Point2D.Double)map.getProjection().getRefXY(p);

	JTextField nameF = new JTextField("A Place");
	JPanel panel = new JPanel(new GridLayout(0,1,2,2));
	JLabel label = new JLabel("Enter Place Name");
	panel.add(label);
	panel.add(nameF);
	panel.add(list);
	panel.add(save);
	if( locFile!=null )panel.add(newSave);
	int ok = JOptionPane.showConfirmDialog( 
			map.getTopLevelAncestor(),
			panel,
			"add/save location",
			JOptionPane.OK_CANCEL_OPTION,
			JOptionPane.PLAIN_MESSAGE);
	if( ok==JOptionPane.CANCEL_OPTION ) return;
	MapLocation loc = new MapLocation( 
			nameF.getText(), 
			p.getX(),
			p.getY(),
			zoom);
	if( list.isSelected() ) addLocation( loc );
	if( save.isSelected() ) {
		if( locFile==null ) {
			JFileChooser chooser = MapApp.getFileChooser();
			chooser.setSelectedFile( new File(
				chooser.getCurrentDirectory(),
				"locations.txt"));
			ok = chooser.showSaveDialog(map.getTopLevelAncestor());
			if( ok==chooser.CANCEL_OPTION )return;
			locFile = chooser.getSelectedFile();
			save.setText("save to "+locFile.getName());
		}
		try {
			PrintStream out = new PrintStream(
				new FileOutputStream( 
				locFile, true ));
			out.println(nameF.getText()
				+"\t"+ p.getX()
				+"\t"+ p.getY()
				+"\t"+ zoom);
			out.close();
		} catch(IOException ex) {
			JOptionPane.showMessageDialog(
				map.getTopLevelAncestor(),
				"Save Failed:\n"+ex.getMessage());
			locFile = null;
		}
	}
}
 
Example 18
Project: AgentWorkbench   File: ProjectExportController.java   View Source Code Vote up 4 votes
/**
 * Exports the current project. The export settings are requested from the user.
 */
public void exportProject() {

	// --- If the project is not set, select the project first --
	if (this.project == null) {
		this.project = this.selectProjectForExport();
		// --- Return if the project selection was canceled -----
		if (this.project == null)
			return;
	}

	// --- Show a dialog to configure the export ----------------
	ProjectExportDialog projectExportDialog = new ProjectExportDialog(project);

	if (projectExportDialog.isCanceled() == false) {

		// --- Get the export settings from the dialog ----------
		this.exportSettings = projectExportDialog.getExportSettings();

		// --- Select the export destination --------------------
		JFileChooser chooser = this.getJFileChooser();
		if (chooser.showSaveDialog(Application.getMainWindow()) == JFileChooser.APPROVE_OPTION) {

			File targetFile = chooser.getSelectedFile();
			Application.getGlobalInfo().setLastSelectedFolder(targetFile.getParentFile());

			// --- Check if the file already exists -------------
			if (targetFile.exists() == true) {
				String optionTitle = targetFile.getName() + ": " + Language.translate("Datei überschreiben?");
				String optionMsg = Language.translate("Die Datei existiert bereits. Wollen Sie diese Datei überschreiben?");
				int answer = JOptionPane.showConfirmDialog(Application.getMainWindow(), optionMsg, optionTitle, JOptionPane.YES_NO_OPTION);
				if (answer == JOptionPane.YES_OPTION) {
					targetFile.delete();
				} else {
					return;
				}
			}

			// --- Set the target file --------------------------
			this.exportSettings.setTargetFile(targetFile);
			// --- Do the export --------------------------------
			this.exportProject(exportSettings);
		}
	}
}
 
Example 19
Project: QN-ACTR-Release   File: CustomDialog.java   View Source Code Vote up 4 votes
File saveFileDialog(File file) {
	FileFilter fFileFilter = new FileFilter() {
		@Override
		public boolean accept(File f) {
			return f.getName().toLowerCase().endsWith(".csv") || f.isDirectory();
		}

		@Override
		public String getDescription() {
			return "Comma delimited (*.csv)";
		}
	};

	JFileChooser fc = new JFileChooser();

	// Start in current directory
	fc.setCurrentDirectory(file);

	// Set filter for Java source files.
	fc.setFileFilter(fFileFilter);

	// Set to a default name for save.
	fc.setSelectedFile(file);

	// Open chooser dialog
	int result = fc.showSaveDialog(this);

	if (result == JFileChooser.CANCEL_OPTION) {
		return null;
	} else if (result == JFileChooser.APPROVE_OPTION) {
		file = fc.getSelectedFile();
		if (file.exists()) {
			int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION,
					JOptionPane.QUESTION_MESSAGE);
			if (response == JOptionPane.CANCEL_OPTION) {
				return null;
			}
		}
		return file;
	} else {
		return null;
	}
}
 
Example 20
Project: jaer   File: SingleOrStereoCameraCalibration.java   View Source Code Vote up 4 votes
synchronized public void doSaveCalibration() {
	if (!calibrated) {
		JOptionPane.showMessageDialog(null, "No calibration yet");
		return;
	}
	JFileChooser j = new JFileChooser();
	j.setCurrentDirectory(new File(dirPath));
	j.setApproveButtonText("Select folder");
	j.setDialogTitle("Select a folder to store calibration XML files");
	j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
	int ret = j.showSaveDialog(null);
	if (ret != JFileChooser.APPROVE_OPTION) {
		return;
	}
	dirPath = j.getSelectedFile().getPath();
	putString("dirPath", dirPath);
	serializeMat(dirPath, "cameraMatrix", cameraMatrix);
	serializeMat(dirPath, "distortionCoefs", distortionCoefs);

	serializeMat(dirPath, "cameraMatrix2", cameraMatrix2);
	serializeMat(dirPath, "distortionCoefs2", distortionCoefs2);

	serializeMat(dirPath, "rotationVectorsfinal", rotationVectorsfinal);
	serializeMat(dirPath, "translationVectorsfinal", translationVectorsfinal);

	serializeMat(dirPath, "EssentialMat", EssentialMat);
	serializeMat(dirPath, "FundamentalMat", FundamentalMat);

	serializeMat(dirPath, "P1", P1);
	serializeMat(dirPath, "P2", P2);

	serializeMat(dirPath, "R1", R1);
	serializeMat(dirPath, "R2", R2);

	serializeMat(dirPath, "Q", Q);


	//cameraMatrix2, distortionCoefs2, imgSize, rotationVectorsfinal, translationVectorsfinal,EssentialMat, FundamentalMat,
	saved = true;
	generateCalibrationString();
}