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

The following are Jave code examples for showing how to use getSelectedFile() 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.
Example 1
Project: jaer   File: BiasgenFrame.java   Source Code and License Vote up 6 votes
/**
 * Shows a file dialog from which to import preferences for biases from the
 * tree.
 */
public void importPreferencesDialog() {
    JFileChooser chooser = new JFileChooser();
    XMLFileFilter filter = new XmlAedatFileFilter();
    
    String lastFilePath = prefs.get("BiasgenFrame.lastFile", defaultFolder);
    lastFile = new File(lastFilePath);
    chooser.setFileFilter(filter);
    chooser.setCurrentDirectory(lastFile);
    int retValue = chooser.showOpenDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        try {
            lastFile = chooser.getSelectedFile();
            importPreferencesFromFile(lastFile);
        } catch (Exception fnf) {
            log.warning(fnf.toString());
        }
    }
    //        resend(); // shouldn't be necessary with the batch edit start/end in biasgen.importPreferences
}
 
Example 2
Project: incubator-netbeans   File: BasicBrandingPanel.java   Source Code and License Vote up 6 votes
private URL browseIcon( ImagePreview preview ) {
    URL res = null;
    JFileChooser chooser = UIUtil.getIconFileChooser();
    int ret = chooser.showDialog(this, NbBundle.getMessage(getClass(), "LBL_Select")); // NOI18N
    if (ret == JFileChooser.APPROVE_OPTION) {
        File file =  chooser.getSelectedFile();
        try {
            res = Utilities.toURI(file).toURL();
            preview.setImage(new ImageIcon(res));
            setModified();
        } catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return res;
}
 
Example 3
Project: javaportfolio   File: PortfolioDocument.java   Source Code and License Vote up 6 votes
public static File selectPortfolioDirectory(JFrame frame) {

		// Create a file chooser
		JFileChooser fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		fc.setLocale(new Locale("fi", "FI"));
		int returnVal = fc.showOpenDialog(frame);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();
			return file;
		}
		return null;
	}
 
Example 4
Project: incubator-netbeans   File: AddWebServiceDlg.java   Source Code and License Vote up 6 votes
private void jBtnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBrowseActionPerformed

    jRbnFilesystem.setSelected(false);
    jRbnFilesystem.setSelected(true);
    enableControls();

    JFileChooser chooser = new JFileChooser(previousDirectory);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
    chooser.setFileFilter(WSDL_FILE_FILTER);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File wsdlFile = chooser.getSelectedFile();
        jTxtLocalFilename.setText(wsdlFile.getAbsolutePath());
        previousDirectory = wsdlFile.getPath();
    }
}
 
Example 5
Project: java-course   File: FIleFactory.java   Source Code and License Vote up 6 votes
/**
 * Opens a .jvd file, parse it and fill given drawing model with elements
 * from opened file.
 * 
 * @param model
 *            Drawing model.
 * @param frame
 *            Parent frame.
 * @return Opened file.
 */
public static File openJVDFile(DrawingModel model, JVDraw frame) {
    JFileChooser fc = new JFileChooser("./");
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileNameExtensionFilter(".jvd", "jvd"));
    int status = fc.showOpenDialog(frame);
    if (status == JFileChooser.OPEN_DIALOG) {
        File file = fc.getSelectedFile();
        if (!Files.isRegularFile(file.toPath())) {
            return null;
        }
        model.clear();
        readJVDFile(file, model);
        return file;
    }
    return null;
}
 
Example 6
Project: incubator-netbeans   File: ConnectionType.java   Source Code and License Vote up 5 votes
protected void onBrowse(JTextField txt) {
    File oldFile = FileUtil.normalizeFile(new File(txt.getText()));
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(Repository.class, "ACSD_BrowseCertFile"), oldFile); // NOI18N
    fileChooser.setDialogTitle(NbBundle.getMessage(Repository.class, "Browse_title"));                                            // NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.showDialog(this.getPanel(), NbBundle.getMessage(Repository.class, "OK_Button"));                                            // NOI18N
    File f = fileChooser.getSelectedFile();
    if (f != null) {
        txt.setText(f.getAbsolutePath());
    }
}
 
Example 7
Project: ISO8583   File: PnlMain.java   Source Code and License Vote up 5 votes
private boolean save() {
	
	boolean fileSaved = false;
	
	if (tabbedPane.getSelectedIndex() == 0)
		isoConfig.parseConfigToXML();
	else 
		isoConfig.parseXmlToConfig(this);
	
	if (txtFilePath.getText().equals("")) {
		JFileChooser file = new JFileChooser();
		file.setAcceptAllFileFilterUsed(false);
		file.setFileFilter(new FileNameExtensionFilter("xml files (*.xml)", "xml"));
		
		if (lastCurrentDirectory != null) 
			file.setCurrentDirectory(lastCurrentDirectory);
		
		if (file.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
			lastCurrentDirectory = file.getSelectedFile();
			txtFilePath.setText(file.getSelectedFile().getAbsolutePath());
			if (txtFilePath.getText().indexOf(".xml") < 0) txtFilePath.setText(txtFilePath.getText() +".xml");
		}
	}

	isoConfig.saveFile(this, txtFilePath.getText());
	fileSaved = (isoConfig.getXmlFilePath() != null);
	
	if (!fileSaved)
		JOptionPane.showMessageDialog(this, "You must inform a file to save.");

	return fileSaved;
}
 
Example 8
Project: FaceAnnotationTool   File: MainFrame.java   Source Code and License Vote up 5 votes
void loadImageList() {
	JFileChooser fc = new JFileChooser(recordedPath);
	int res = fc.showOpenDialog(this);
	if (res == JFileChooser.APPROVE_OPTION) {
		File f = fc.getSelectedFile();
		recordedPath = f.getParent();
		if (!IOTool.isTextFile(f)) {
			// not a readable text file
			JOptionPane.showMessageDialog(this,
					String.format("\"%s\" \nis not a txt file.", f.getAbsolutePath()).toString(), "Not a txt file",
					JOptionPane.WARNING_MESSAGE);
		} else {
			// read
			ArrayList<String> imgList = IOTool.readText(f);
			if (imgList == null) {
				// read failed
				JOptionPane.showMessageDialog(this,
						String.format("\"%s\" \ncannot be properly read.", f.getAbsolutePath()).toString(),
						"Reading failed", JOptionPane.WARNING_MESSAGE);
			} else {

				pathImgPair = IOTool.filterImageList(imgList, this);
				if (pathImgPair.size() == 0) {
					pathImgPair = null;
					return;
				}
				fillImageNameTable();
				leftTableSelectedRow = 0;
				imgListTH.setSelectedRow(leftTableSelectedRow);
				freezeReadImageListBtn();

			}
		}

	}
}
 
Example 9
Project: geomapapp   File: PDB.java   Source Code and License Vote up 5 votes
protected void saveAsExcel(Iterator it) {
	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	File f=new File("PDB_Export.xls");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==jfc.CANCEL_OPTION||c==jfc.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		WritableWorkbook wb = Workbook.createWorkbook(f);
		WritableSheet sheet = wb.createSheet("First Sheet", 0);

		int r = 0;
		while (it.hasNext()) {
			String[] split = it.next().toString().split("\\t");
			for (int i = 0; i < split.length; i++)
				sheet.addCell( new Label(i,r,split[i]) );
			r++;
		}

		wb.write();
		wb.close();
	} catch (Exception ex){
	}
}
 
Example 10
Project: jmt   File: CustomDialog.java   Source Code and License Vote up 5 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(Defaults.getWorkingPath());

	// 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 11
Project: tttclass   File: CommonUtil.java   Source Code and License Vote up 5 votes
public static String getFilePath()
{
	JFileChooser jfc = new JFileChooser();
	jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
	jfc.showDialog(new JLabel(), "确定");
	return jfc.getSelectedFile() == null ? null
			: jfc.getSelectedFile().getAbsolutePath();
}
 
Example 12
Project: jaer   File: FilterFrame.java   Source Code and License Vote up 5 votes
private void loadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMenuItemActionPerformed
           JFileChooser fileChooser = new JFileChooser();
           String lastFilePath = prefs.get("FilterFrame.lastFile", defaultFolder); // TODO seems to be same as for biases, should default to filterSettings folder of jAER
           lastFile = new File(lastFilePath);
           XMLFileFilter fileFilter = new XMLFileFilter();
           fileChooser.addChoosableFileFilter(fileFilter);
           fileChooser.setCurrentDirectory(lastFile); // sets the working directory of the chooser
           int retValue = fileChooser.showOpenDialog(this);
           if (retValue == JFileChooser.APPROVE_OPTION) {
               File f = fileChooser.getSelectedFile();
               loadFile(f);
           }
}
 
Example 13
Project: jaer   File: AEPlayer.java   Source Code and License Vote up 4 votes
/**
     * Called when user asks to open data file file dialog.
     */
    @Override
    public void openAEInputFileDialog() {
//        try{Thread.currentThread().sleep(200);}catch(InterruptedException e){}
        float oldScale = viewer.chipCanvas.getScale();
        fileChooser = new JFileChooser();
//            new TypeAheadSelector(fileChooser);
        //com.sun.java.plaf.windows.WindowsFileChooserUI;
//            fileChooser.addKeyListener(new KeyAdapter() {
//                public void keyTyped(KeyEvent e){
//                    System.out.println("keycode="+e.getKeyCode());
//                }
//            });
//            System.out.println("fileChooser.getUIClassID()="+fileChooser.getUIClassID());
//            KeyListener[] keyListeners=fileChooser.getKeyListeners();
        ChipDataFilePreview preview = new ChipDataFilePreview(fileChooser, viewer.getChip());
        // from book swing hacks
        new FileDeleter(fileChooser, preview);
        fileChooser.addPropertyChangeListener(preview);
        fileChooser.setAccessory(preview);
        String lastFilePath = AEViewer.prefs.get("AEViewer.lastFile", "");
        // get the last folder
        viewer.lastFile = new File(lastFilePath);
//            fileChooser.setFileFilter(datFileFilter);
        IndexFileFilter indexFileFilter = new IndexFileFilter();
        fileChooser.addChoosableFileFilter(indexFileFilter);
        DATFileFilter datFileFilter = new DATFileFilter();
        fileChooser.addChoosableFileFilter(datFileFilter);
        if (lastFilter == null) {
            fileChooser.setFileFilter(datFileFilter);
        } else {
            fileChooser.setFileFilter(lastFilter);
        }
        fileChooser.setCurrentDirectory(viewer.lastFile);
        // sets the working directory of the chooser
//            boolean wasPaused=isPaused();
        setPaused(true);
        try {
            int retValue = fileChooser.showOpenDialog(viewer);
            if (retValue == JFileChooser.APPROVE_OPTION) {
                lastFilter = fileChooser.getFileFilter();
                try {
                    viewer.lastFile = fileChooser.getSelectedFile();
                    if (viewer.lastFile != null) {
                        viewer.recentFiles.addFile(viewer.lastFile);
                    }
                    startPlayback(viewer.lastFile);
                } catch (IOException fnf) {
                    log.warning(fnf.toString());
                }
            } else {
                preview.showFile(null);
            }
        } catch (GLException e) {
            log.warning(e.toString());
            preview.showFile(null);
        }
        fileChooser = null;
//        viewer.chipCanvas.setScale(oldScale);
        // restore persistent scale so that we don't get tiny size on next startup
        setPaused(false);
    }
 
Example 14
Project: Kaeon-FUSION   File: IO.java   Source Code and License Vote up 4 votes
public static String openAsString() {

		JFileChooser chooser = new JFileChooser();
		int returnVal = chooser.showOpenDialog(null);

		if(returnVal == JFileChooser.APPROVE_OPTION) {

			File file = chooser.getSelectedFile();

			return readAsString(file);
		}

		return null;
	}
 
Example 15
Project: Squid   File: FileHelper.java   Source Code and License Vote up 4 votes
/**
 *
 * @param parentFrame
 * @param dialogTitle
 * @param directory
 * @param fileExtension
 * @param fractionFileName
 * @param nonMacFileFilter
 * @return
 */
public static File allPlatformSaveAs(
        Frame parentFrame,
        String dialogTitle,
        String directory,
        final String fileExtension,
        String fractionFileName,
        FileFilter nonMacFileFilter) {

    File selectedFile;

    JFileChooser fc = new JFileChooser();
    fc.setSelectedFile(new File(directory + File.separator + fractionFileName));
    fc.setFileFilter(nonMacFileFilter);
    fc.setDialogTitle(dialogTitle);

    // Show save dialog; this method does not return until the dialog is closed
    int result = fc.showSaveDialog(new Frame());
    if (result == JFileChooser.APPROVE_OPTION) {
        selectedFile = fc.getSelectedFile();
        // check for already exists
        int response = 0;
        if (selectedFile.exists()) {
            // Modal dialog with OK/cancel and a text field
            response = JOptionPane.showConfirmDialog(null,
                    new String[]{"The file exists.",
                        "Do you want to replace it?"
                    },
                    "ET Redux Warning",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (response == JOptionPane.NO_OPTION) {
                selectedFile = null;
            }
        }
    } else {
        selectedFile = null;
    }

    return selectedFile;
}
 
Example 16
Project: Wurst-MC-1.12-OF   File: ServerHook.java   Source Code and License Vote up 4 votes
public static void importServers(GuiMultiplayer guiMultiplayer)
{
	JFileChooser fileChooser =
		new JFileChooser(WurstFolders.SERVERLISTS.toFile())
		{
			@Override
			protected JDialog createDialog(Component parent)
				throws HeadlessException
			{
				JDialog dialog = super.createDialog(parent);
				dialog.setAlwaysOnTop(true);
				return dialog;
			}
		};
	fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.addChoosableFileFilter(
		new FileNameExtensionFilter("TXT files", "txt"));
	int action = fileChooser.showOpenDialog(FrameHook.getFrame());
	if(action == JFileChooser.APPROVE_OPTION)
		try
		{
			File file = fileChooser.getSelectedFile();
			BufferedReader load = new BufferedReader(new FileReader(file));
			int i = 0;
			for(String line = ""; (line = load.readLine()) != null;)
			{
				i++;
				guiMultiplayer.savedServerList.addServerData(
					new ServerData("Grief me #" + i, line, false));
				guiMultiplayer.savedServerList.saveServerList();
				guiMultiplayer.serverListSelector.setSelectedSlotIndex(-1);
				guiMultiplayer.serverListSelector
					.updateOnlineServers(guiMultiplayer.savedServerList);
			}
			load.close();
			guiMultiplayer.refreshServerList();
		}catch(IOException e)
		{
			e.printStackTrace();
			MiscUtils.simpleError(e, fileChooser);
		}
}
 
Example 17
Project: Dahlem_SER316   File: EditorPanel.java   Source Code and License Vote up 4 votes
void importB_actionPerformed(ActionEvent e) {
	// Fix until Sun's JVM supports more locales...
	UIManager.put("FileChooser.lookInLabelText", Local
			.getString("Look in:"));
	UIManager.put("FileChooser.upFolderToolTipText", Local
			.getString("Up One Level"));
	UIManager.put("FileChooser.newFolderToolTipText", Local
			.getString("Create New Folder"));
	UIManager.put("FileChooser.listViewButtonToolTipText", Local
			.getString("List"));
	UIManager.put("FileChooser.detailsViewButtonToolTipText", Local
			.getString("Details"));
	UIManager.put("FileChooser.fileNameLabelText", Local
			.getString("File Name:"));
	UIManager.put("FileChooser.filesOfTypeLabelText", Local
			.getString("Files of Type:"));
	UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
	UIManager.put("FileChooser.openButtonToolTipText", Local
			.getString("Open selected file"));
	UIManager
			.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
	UIManager.put("FileChooser.cancelButtonToolTipText", Local
			.getString("Cancel"));

	JFileChooser chooser = new JFileChooser();
	chooser.setFileHidingEnabled(false);
	chooser.setDialogTitle(Local.getString("Insert file"));
	chooser.setAcceptAllFileFilterUsed(false);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
	chooser.setPreferredSize(new Dimension(550, 375));
	String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
	if (lastSel != null)
		chooser.setCurrentDirectory(new java.io.File(lastSel));
	if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
		return;

	Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile()
			.getPath());

	File f = chooser.getSelectedFile();
	new HTMLFileImport(f, editor);
}
 
Example 18
Project: geomapapp   File: UnknownDataSet.java   Source Code and License Vote up 4 votes
public void exportExcelXLSX(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;

	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	String defaultName = desc.name.replace(":", "") + ".xlsx";

	if(defaultName.contains("Data Table ")){
		defaultName = defaultName.replace("Data Table ", "");
	}

	File f=new File(defaultName);
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION)break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		if (!f.getName().endsWith(".xlsx")){
			System.out.println(f.getName());
			JOptionPane.showMessageDialog(null, "Save did not complete. Must end in .xlsx. Try again.");
		}else{
			XSSFWorkbook xlsxWB = new XSSFWorkbook();
			CreationHelper createHelper = xlsxWB.getCreationHelper();
			XSSFSheet xlsxSheet1 = xlsxWB.createSheet("First Sheet");
			Row row = null;
			
			int[] ind;
			if (saveOption.equals("selection")) {
				ind = dataT.getSelectedRows();
			} else if (saveOption.equals("plottable")) {
				ind = getPlottableRows();
			} else {
				ind = new int[dataT.getRowCount()];
				for (int i=0; i<dataT.getRowCount(); i++) ind[i] = i;
			}
			int xlsxCol = dataT.getColumnCount();
			row = xlsxSheet1.createRow((0));
			//don't include Plot column
			for (int c=1; c<xlsxCol; c++){
				String columnName = dataT.getColumnName(c);
				row.createCell(c-1).setCellValue(columnName);
			}

			for (int r=1; r<=ind.length; r++){
				row = xlsxSheet1.createRow((r));
				for (int c=1; c<xlsxCol; c++){
					Object o = dataT.getValueAt(ind[r-1], c);
					String input1 = null;
					if(o instanceof String && ((String)o).equals("NaN")){
						o = "";
						input1 = o.toString();
						row.createCell(c-1).setCellValue(input1);
					}else if(o instanceof String){
						row.createCell(c-1).setCellValue((String)o);
					}
				}
			}
			FileOutputStream xlsxOut = new FileOutputStream(f);
			xlsxWB.write(xlsxOut);
			xlsxOut.close();
		}
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
Example 19
Project: HBaseClient   File: ExportActionListener.java   Source Code and License Vote up 4 votes
@Override
public void onClick(ActionEvent arg0)
{
    if ( JavaHelp.isNull(this.getAppFrame().getTableName()) )
    {
        this.getAppFrame().showHintInfo("请先选择要导出的表" ,Color.BLUE);
        return;
    }
    
    if ( this.getAppFrame().getRowCount() == 0 )
    {
        this.getAppFrame().showHintInfo("查询结果无数据,无法导出" ,Color.BLUE);
        return;
    }
    
    
    JTable        v_JTable      = (JTable)XJava.getObject("xtDataList");
    int []        v_RowIndexArr = v_JTable.getSelectedRows();
    StringBuilder v_FileName    = new StringBuilder();
    
    // 生成文件名称
    v_FileName.append(this.getTableName());
    if ( v_RowIndexArr.length <= 0 )
    {
        String v_Text = "";
        
        v_Text = ((JTextComponent)XJava.getObject("RowKey"))     .getText();
        if ( !JavaHelp.isNull(v_Text) )
        {
            v_FileName.append("_R.").append(v_Text.trim());
        }
        
        v_Text = ((JComboBox)     XJava.getObject("FamilyName")) .getSelectedItem().toString();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_F.").append(v_Text.trim());
        }
        
        v_Text = ((JComboBox)     XJava.getObject("ColumnName")) .getSelectedItem().toString();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_C.").append(v_Text.trim());
        }
        
        v_Text = ((JTextComponent)XJava.getObject("ColumnValue")).getText();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_V.").append(v_Text.trim());
        }
    }
    else
    {
        v_FileName.append("_CCount.").append(v_RowIndexArr.length);
        v_FileName.append("_").append(Date.getNowTime().getFull_ID());
    }
    v_FileName.append(".txt");
    
    
    
    File         v_SaveFile    = new File(v_FileName.toString());
    JFileChooser v_FileChooser = new JFileChooser();
    v_FileChooser.setSelectedFile(v_SaveFile);
    
    int v_Result = v_FileChooser.showSaveDialog(this.getAppFrame());
    if ( v_Result == JFileChooser.APPROVE_OPTION )
    {
        v_SaveFile = v_FileChooser.getSelectedFile();
        
        this.writeContents(v_JTable ,v_RowIndexArr ,v_SaveFile);
    }
}
 
Example 20
Project: OpenJSharp   File: J2DBench.java   Source Code and License 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;
}