javax.swing.JFileChooser#CANCEL_OPTION源码实例Demo

下面列出了javax.swing.JFileChooser#CANCEL_OPTION 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: views-widgets-samples   文件: CycleView.java
public static void save(ActionEvent e, CycleView graph) {
  int w = graph.getWidth();
  int h = graph.getHeight();
  BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  graph.paint(img.createGraphics());
  JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.home")));
  int c = chooser.showSaveDialog(graph);
  if (c == JFileChooser.CANCEL_OPTION) {
    System.out.println("cancel");
    return;
  }
  try {
    File f = chooser.getSelectedFile();
    ImageIO.write(img, "png", f);
    System.out.println(f.getAbsolutePath());

    Desktop.getDesktop().open(f.getParentFile());
  } catch (IOException e1) {
    e1.printStackTrace();
  }
}
 
源代码2 项目: marvinproject   文件: PluginTester.java
private void saveImage(){
	int result;
	String path=null;
	
	JFileChooser chooser = new JFileChooser();
	chooser.setDialogType(JFileChooser.SAVE_DIALOG);
	result = chooser.showSaveDialog(this);
	
	if(result == JFileChooser.CANCEL_OPTION){
		return;
	}

	try{
		path = chooser.getSelectedFile().getCanonicalPath();
		newImage.update();
		MarvinImageIO.saveImage(imagePanel.getImage(), path);
	}
	catch(Exception e){
		e.printStackTrace();
	}
}
 
源代码3 项目: dctb-utfpr-2018-1   文件: TestaArquivo3.java
public void abrirarquivo() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int result = fileChooser.showOpenDialog(null);
    if (result == JFileChooser.CANCEL_OPTION) {
        return;
    }
    arquivo = fileChooser.getSelectedFile();
    System.out.println(arquivo);

    if (arquivo == null || arquivo.getName().equals("")) {
        JOptionPane.showMessageDialog(null, "Nome de Arquivo Inválido", "Nome de Arquivo Inválido", JOptionPane.ERROR_MESSAGE);
    } else {
        try {
            entrada = new BufferedReader(new FileReader(arquivo));
        } catch (IOException ioException) {
            JOptionPane.showMessageDialog(null, "Error ao Abrir Arquivo", "Erro", JOptionPane.ERROR_MESSAGE);
        }
    }
}
 
源代码4 项目: importer-exporter   文件: ReliefBalloonPanel.java
private void loadFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		browseText.setText(exportString);
		internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
		internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
	}
	catch (Exception e) {
		//
	}
}
 
public static void save(ActionEvent e, CycleView graph) {
  int w = graph.getWidth();
  int h = graph.getHeight();
  BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  graph.paint(img.createGraphics());
  JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.home")));
  int c = chooser.showSaveDialog(graph);
  if (c == JFileChooser.CANCEL_OPTION) {
    System.out.println("cancel");
    return;
  }
  try {
    File f = chooser.getSelectedFile();
    ImageIO.write(img, "png", f);
    System.out.println(f.getAbsolutePath());

    Desktop.getDesktop().open(f.getParentFile());
  } catch (IOException e1) {
    e1.printStackTrace();
  }
}
 
源代码6 项目: importer-exporter   文件: ThreeDBalloonPanel.java
private void loadFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		browseText.setText(exportString);
		internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
		internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
	}
	catch (Exception e) {
		//
	}
}
 
private void loadFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		browseText.setText(exportString);
		internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
		internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
	}
	catch (Exception e) {
		//
	}
}
 
private void loadFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		browseText.setText(exportString);
		internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
		internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
	}
	catch (Exception e) {
		//
	}
}
 
源代码9 项目: tectonicus   文件: FileBrowserLine.java
@Override
public void actionPerformed(ActionEvent e)
{
	final int result = browseDialog.showDialog(parent, browseLabel);
	if (result == JFileChooser.APPROVE_OPTION)
	{
		file = browseDialog.getSelectedFile();
	}
	else if (result == JFileChooser.CANCEL_OPTION)
	{
		
	}
	else if (result == JFileChooser.ERROR_OPTION)
	{
		
	}
	
	ignoreTextEvents = true;
	
	setText(file.getAbsolutePath());
	
	ignoreTextEvents = false;
	
	onFileChanged();
}
 
源代码10 项目: open-ig   文件: AnimPlay.java
/**
 * Save animation as Wav.
 */
private static void doSaveAsPng() {
	if (current == null) {
		return;
	}
	JFileChooser fc = new JFileChooser(lastSavePath);
	fc.setAcceptAllFileFilterUsed(true);
	fc.setFileFilter(new FileNameExtensionFilter("PNG files", "PNG"));
	if (fc.showSaveDialog(frame) == JFileChooser.CANCEL_OPTION) {
		return;
	}
	final File sel = fc.getSelectedFile();
	lastSavePath = sel.getParentFile();
	
	saveAsPNGWorker(current, sel, true, frame);
}
 
源代码11 项目: appinventor-extensions   文件: AIMerger.java
private String getFileToOpen() {
  JFileChooser projectFC = new JFileChooser(browserPath);
  int validPath = projectFC.showOpenDialog(myCP);
  if (validPath == JFileChooser.ERROR_OPTION || validPath == JFileChooser.CANCEL_OPTION) {
    return null;
  } else {
    return projectFC.getSelectedFile().toString();
  }
}
 
源代码12 项目: importer-exporter   文件: XSLTransformationPanel.java
private void browseStylesheet(StylesheetComponent component) {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(Language.I18N.getString("common.pref.xslt.label.file"));

    FileNameExtensionFilter filter = new FileNameExtensionFilter("XSLT Stylesheet (*.xsl)", "xsl");
    chooser.addChoosableFileFilter(filter);
    chooser.addChoosableFileFilter(chooser.getAcceptAllFileFilter());
    chooser.setFileFilter(filter);

    File currentDirectory = null;
    String stylesheet = component.stylesheet.getText().trim();
    if (!stylesheet.isEmpty()) {
        Path path = Paths.get(stylesheet).getParent();
        if (path != null)
            currentDirectory = path.toFile();
    }

    if (currentDirectory == null) {
        if (lastPath != null)
            currentDirectory = lastPath;
        else
            currentDirectory = ClientConstants.IMPEXP_HOME.resolve(ClientConstants.XSLT_TEMPLATES_DIR).toFile();
    }

    chooser.setCurrentDirectory(currentDirectory);

    int result = chooser.showOpenDialog(getTopLevelAncestor());
    if (result != JFileChooser.CANCEL_OPTION) {
        component.stylesheet.setText(chooser.getSelectedFile().getAbsolutePath());
        lastPath = chooser.getCurrentDirectory();
    }
}
 
源代码13 项目: JCEditor   文件: AreaDeTexto.java
/**
* Este método faz com que o usuário escolha um arquivo para então salva-lo.
* Será usado em duas situações, caso o usuário ainda não tenha salvo o arquivo
* (o arquivo é nulo) ou quando o usuário pressionar o botão de salvar como.
*/
public void salvarComo() {
	if (fileChooser().showSaveDialog(this) == JFileChooser.CANCEL_OPTION) {
		return;
	} else {
		setArquivo(fileChooser().getSelectedFile());
		extensao(fileChooser().getSelectedFile());
			if (arquivo.exists()) {
				JOptionPane.showMessageDialog(this, "Sobrescrever?");
			}
		salvar(texto);
		extensao(arquivo);
	}
}
 
源代码14 项目: RobotBuilder   文件: RobotTree.java
public void load() {
    if (OKToClose()) {
        int result = fileChooser.showOpenDialog(MainFrame.getInstance());
        if (result == JFileChooser.CANCEL_OPTION) {
            return;
        } else if (result == JFileChooser.ERROR_OPTION) {
            return;
        } else if (result == JFileChooser.APPROVE_OPTION) {
            setFilePath(fileChooser.getSelectedFile().getAbsolutePath());
        }
        load(new File(filePath));
    }
}
 
源代码15 项目: basicv2   文件: VisualMospeed.java
private void loadProgram() {
	JFileChooser fc = new JFileChooser();
	if (lastDir != null) {
		fc.setCurrentDirectory(lastDir);
	}
	int ret = fc.showOpenDialog(frame);
	if (ret == JFileChooser.CANCEL_OPTION || ret == JFileChooser.ERROR_OPTION) {
		compile.setEnabled(code != null && code.length > 0);
		return;
	}
	load(fc.getSelectedFile());
}
 
源代码16 项目: importer-exporter   文件: ImportLogPanel.java
private String browseFile(String title, String oldDir) {
	JFileChooser chooser = new JFileChooser();
	chooser.setDialogTitle(title);
	chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	chooser.setCurrentDirectory(new File(oldDir));

	int result = chooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return "";
	String browseString = chooser.getSelectedFile().toString();
	return browseString;
}
 
源代码17 项目: mzmine2   文件: ProjectParametersImporter.java
private File chooseFile() {
  JFileChooser chooser = new JFileChooser();

  FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT & CSV files", "txt", "csv");
  chooser.setDialogTitle("Please select a file containing project parameter values for files.");
  chooser.setFileFilter(filter);
  int returnVal = chooser.showOpenDialog(desktop.getMainWindow());
  if (returnVal == JFileChooser.CANCEL_OPTION) {
    return null;
  }

  return chooser.getSelectedFile();
}
 
源代码18 项目: CEC-Automatic-Annotation   文件: OnClickListener.java
public void handleSaveAsFile() {
	// FileDialog fileDialog = new
	// FileDialog(getJFrame(),"保存...",FileDialog.SAVE);
	// fileDialog.setVisible(true);
	// String fileName = fileDialog.getDirectory()+fileDialog.getFile();
	// 设置对话框的风格
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e1) {
		MyLogger.logger.info("设置对话框风格出错!" + e1.getMessage());
		e1.printStackTrace();
	}
	JFileChooser jFileChooser = new JFileChooser();
	// jFileChooser.setMultiSelectionEnabled(true);//如果要多选的话,设置这句话即可
	// 设置默认的保存文件名称
	// jFileChooser.setSelectedFile(new
	// File(getTitleContent().getText().toString()));
	int result = jFileChooser.showSaveDialog(null);
	switch (result) {
	case JFileChooser.APPROVE_OPTION:
		// 这一种方法是把显示内容中的标题取出来作为文件名,暂不采用
		// filePath = jFileChooser.getCurrentDirectory() + File.separator +
		// getTitleContent().getText() + ".xml";
		// 这一种方法是把用户输入的作为保存的文件名
		filePath = jFileChooser.getCurrentDirectory() + File.separator + jFileChooser.getSelectedFile().getName() + ".xml";
		MyLogger.logger.info("改变路径之后,文件的保存路径=" + filePath);
		MyLogger.logger.info("Approve (Open or Save) was clicked ");
		MyLogger.logger.info("这是绝对路径:" + jFileChooser.getSelectedFile().getAbsolutePath());
		writeToFile(filePath);
		break;
	case JFileChooser.CANCEL_OPTION:
		MyLogger.logger.info("Cancle or the close-dialog icon was clicked");
		break;
	case JFileChooser.ERROR_OPTION:
		MyLogger.logger.error("Error...");
		break;
	}
}
 
源代码19 项目: osp   文件: VideoIO.java
/**
 * Displays a file chooser and returns the chosen files.
 *
 * @param type may be "open", "open video", "save", "insert image"
 * @return the files, or null if no files chosen
 */
public static File[] getChooserFiles(String type) {
  JFileChooser chooser = getChooser();
  chooser.setMultiSelectionEnabled(false);
  chooser.setAcceptAllFileFilterUsed(true);
  int result = JFileChooser.CANCEL_OPTION;
  if(type.toLowerCase().equals("open")) { // open any file //$NON-NLS-1$
    chooser.addChoosableFileFilter(videoFileFilter);
    chooser.setFileFilter(chooser.getAcceptAllFileFilter());
    result = chooser.showOpenDialog(null);
  } 
  else if(type.toLowerCase().equals("open video")) { // open video //$NON-NLS-1$
    chooser.addChoosableFileFilter(videoFileFilter);
    result = chooser.showOpenDialog(null);
  } 
  else if(type.toLowerCase().equals("save")) { // save any file //$NON-NLS-1$
  	// note this sets no file filters but does include acceptAll
    // also sets file name to "untitled"
    String filename = MediaRes.getString("VideoIO.FileName.Untitled"); //$NON-NLS-1$
   chooser.setSelectedFile(new File(filename+"."+defaultXMLExt)); //$NON-NLS-1$
    result = chooser.showSaveDialog(null);
  } 
  else if(type.toLowerCase().equals("insert image")) { //$NON-NLS-1$
    chooser.setMultiSelectionEnabled(true);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.addChoosableFileFilter(imageFileFilter);
    chooser.setSelectedFile(new File("")); //$NON-NLS-1$
    result = chooser.showOpenDialog(null);
    File[] files = chooser.getSelectedFiles();
    chooser.removeChoosableFileFilter(imageFileFilter);
    chooser.setSelectedFile(new File(""));  //$NON-NLS-1$
    if(result==JFileChooser.APPROVE_OPTION) {
      return files;
    }
  }
  if(result==JFileChooser.APPROVE_OPTION) {
  	File file = chooser.getSelectedFile();
    chooser.removeChoosableFileFilter(videoFileFilter);
    chooser.setSelectedFile(new File(""));  //$NON-NLS-1$
    return new File[] {file};
  }
  return null;
}
 
源代码20 项目: gate-core   文件: CollectionSelectionDialog.java
/** This method is called when the user press the CANCEL button*/
private void doCancel(){
  buttonPressed = JFileChooser.CANCEL_OPTION;
  this.setVisible(false);
}