当前位置: 首页>>代码示例>>Java>>正文


Java JFileChooser.CANCEL_OPTION属性代码示例

本文整理汇总了Java中javax.swing.JFileChooser.CANCEL_OPTION属性的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.CANCEL_OPTION属性的具体用法?Java JFileChooser.CANCEL_OPTION怎么用?Java JFileChooser.CANCEL_OPTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.swing.JFileChooser的用法示例。


在下文中一共展示了JFileChooser.CANCEL_OPTION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFile

private File getFile(int reply, JFileChooser chooser, JTextField field, File oldFile)
{
	switch( reply )
	{
		case JFileChooser.ERROR_OPTION: {
			JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this), "Error retrieving file", "Error",
				JOptionPane.ERROR_MESSAGE);
			field.setText("");
			return null;
		}
		case JFileChooser.APPROVE_OPTION: {
			File file = chooser.getSelectedFile();
			field.setText(file.getPath());
			return file;
		}
		case JFileChooser.CANCEL_OPTION: {
			return oldFile;
		}
	}
	field.setText("");
	return null;
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:ImportPage.java

示例2: doLoadHistogram

final synchronized public void doLoadHistogram() {
        JFileChooser fileChooser = new JFileChooser();
        String lastFilePath = getString("lastFile", System.getProperty("user.dir") );
        // get the last folder
//            fileChooser.setFileFilter(datFileFilter);
        File f=new File(lastFilePath);
        fileChooser.setCurrentDirectory(f);
        fileChooser.setSelectedFile(f);
        int retValue = fileChooser.showOpenDialog(fileChooser);
        if (retValue == JFileChooser.CANCEL_OPTION) {
            return;
        }
        File file = fileChooser.getSelectedFile();
        putString("lastFile",file.getPath());
        loadHistogramFromFile(file);
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:16,代码来源:Histogram2DFilter.java

示例3: doSaveHistogram

synchronized public void doSaveHistogram() {
        if (histmax == 0 || histogram == null) {
            log.warning("no histogram to save");
            return;
        }
        try {
            JFileChooser fileChooser = new JFileChooser();
            String lastFilePath = getFilePath();
            if(!lastFilePath.endsWith(HISTOGRAM_FILE_NAME_EXTENSION))lastFilePath=lastFilePath+HISTOGRAM_FILE_NAME_EXTENSION;
            // get the last folder
//            fileChooser.setFileFilter(datFileFilter);
            File f=new File(lastFilePath);
            fileChooser.setCurrentDirectory(f);
            fileChooser.setSelectedFile(f);
            int retValue = fileChooser.showOpenDialog(fileChooser);
            if (retValue == JFileChooser.CANCEL_OPTION) {
                return;
            }
            File file = fileChooser.getSelectedFile();
            saveHistogramToFile(file);
        } catch (IOException e) {
            log.warning("couldn't save histogram: " + e);
        }

    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:25,代码来源:Histogram2DFilter.java

示例4: importImage

public void importImage(MapApp mapApp) {
	JFileChooser chooser = MapApp.getFileChooser();
	for (FileFilter ff : supportedImageSources)
		chooser.setFileFilter(ff);
	chooser.setFileFilter(allSources);
	
	int c = chooser.showOpenDialog(mapApp.getFrame());
	if (c == JFileChooser.CANCEL_OPTION) return;
	
	File file = chooser.getSelectedFile();
	if (file == null) return;
	
	if (file.getName().toLowerCase().endsWith(".kml"))
		importKMZ(mapApp, file, false);
	else if (file.getName().toLowerCase().endsWith(".kmz"))
		importKMZ(mapApp, file, true);
	else
		importImage(mapApp, file);
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:19,代码来源:ImportImageLayer.java

示例5: showSaveDialog

@Override
    public int showSaveDialog(Component parent) throws HeadlessException {
        if (!FX_AVAILABLE) {
            return super.showSaveDialog(parent);
        }

        final CountDownLatch latch = new CountDownLatch(1);

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
//                parent.setEnabled(false);
                if (isDirectorySelectionEnabled()) {
                    currentFile = directoryChooser.showDialog(null);
                } else {
                    currentFile = fileChooser.showSaveDialog(null);
                }
                latch.countDown();
//                parent.setEnabled(true);
            }

        });
        try {
            latch.await();
        } catch (InterruptedException ex) {
            throw new RuntimeException(ex);
        }

        if (currentFile != null) {
            return JFileChooser.APPROVE_OPTION;
        } else {
            return JFileChooser.CANCEL_OPTION;
        }
    }
 
开发者ID:veluria,项目名称:NativeJFileChooser,代码行数:34,代码来源:NativeJFileChooser.java

示例6: loadFile

public void loadFile(){
	type = UnknownDataSet.ASCII_FILE;
	jfc.setFileFilter(null);
	int c = jfc.showOpenDialog(this);
	if (c==JFileChooser.CANCEL_OPTION || c == JFileChooser.ERROR_OPTION) return;
	path = jfc.getSelectedFile().getPath();
	loadFile(jfc.getSelectedFile());
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:8,代码来源:OtherDBInputDialog.java

示例7: saveFileDialog

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;
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:40,代码来源:CustomDialog.java

示例8: loadModel

/**
 * Shows a Load window and loads chosen model inside specified model data file
 * @param modelData data file where information should be stored. Note that <b>its type
 * must be compatible with defaultFilter chosen in the constructor</b>, otherwise a
 * ClassCastException will be thrown
 * @param parent parent component of loading window
 * @return SUCCESS on success, CANCELLED if loading is cancelled,
 * FAILURE if an error occurs and WARNING is one or more warnings are generated due to
 * format conversion
 * @throws ClassCastException if modelData is not of instance of the correct class
 * @see #getFailureMotivation getFailureMotivation()
 */
public int loadModel(Component parent) {
	warnings.clear();
	int status;
	status = this.showOpenDialog(parent);
	if (status == JFileChooser.CANCEL_OPTION) {
		return CANCELLED;
	} else if (status == JFileChooser.ERROR_OPTION) {
		failureMotivation = "Error selecting input file";
		return FAILURE;
	}

	f = dialog.getSelectedFile();

	try {
		if (defaultFilter == LOG) {

		}

	} catch (Exception e) {
		e.printStackTrace();
		failureMotivation = e.getClass().getName() + ": " + e.getMessage();
		return FAILURE;
	}
	// If no warnings were found, report success
	if (warnings.size() > 0) {
		return WARNING;
	} else {
		return SUCCESS;
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:42,代码来源:Loader.java

示例9: getFileToOpen

private String getFileToOpen() {
  JFileChooser projectFC = new JFileChooser();
  int validPath = projectFC.showOpenDialog(myCP);
  if (validPath == JFileChooser.ERROR_OPTION || validPath == JFileChooser.CANCEL_OPTION) {
    return null;
  } else {
    return projectFC.getSelectedFile().toString();
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:9,代码来源:AIMerger.java

示例10: chooseSavedGames

private void chooseSavedGames() {
  fc.setMultiSelectionEnabled(true);
  if (JFileChooser.CANCEL_OPTION != fc.showOpenDialog(this)) {
    File[] selectedFiles = fc.getSelectedFiles();
    if (selectedFiles != null) {
      savedGamesModel.clear();
      for (int i = 0; i < selectedFiles.length; i++) {
        savedGamesModel.addElement(selectedFiles[i]);
      }
    }
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:12,代码来源:SavedGameUpdaterDialog.java

示例11: getFileToOpen

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();
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:9,代码来源:AIMerger.java

示例12: exportASCII

public void exportASCII(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;
	
	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	File f=new File(desc.name.replace(":", "")+".txt");
	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 {
		BufferedWriter out = new BufferedWriter(new FileWriter(f));
		//don't include Plot column
		for (int i=1;i<dataT.getColumnCount();i++)
			out.write(dataT.getColumnName(i)+"\t");
		out.write("\n");
		
		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;
		}
			
		for (int i=0;i<ind.length;i++) {
			for (int j=1; j<dataT.getColumnCount();j++) {
				Object o = dataT.getValueAt(ind[i], j);
				if (o instanceof String && ((String)o).equals("NaN")) o = "";
				out.write(o+"\t");
			}
			out.write("\n");
		}
		out.close();
	} catch (IOException ex){

	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:48,代码来源:UnknownDataSet.java

示例13: saveMenuActionPerformed

private void saveMenuActionPerformed(java.awt.event.ActionEvent evt) {                                         
    if (editTabs.getTabCount() == 0) {
        return;
    }
    String filePath;
    if (filePaths.get(editTabs.getSelectedIndex()).equals("notSet")) {
        int result = saveChooser.showSaveDialog(this);
        if(result == JFileChooser.CANCEL_OPTION)
            return;
        if (saveChooser.getSelectedFile() == null)
            return;
        filePath = saveChooser.getSelectedFile().getPath();
        editTabs.setTitleAt(editTabs.getSelectedIndex(), saveChooser.getSelectedFile().getName());
        filePaths.set(editTabs.getSelectedIndex(), filePath);
    } else {
        filePath = filePaths.get(editTabs.getSelectedIndex());
        editTabs.setTitleAt(editTabs.getSelectedIndex(), saveChooser.getSelectedFile().getName());
    }
    javax.swing.JTextArea textComp = (javax.swing.JTextArea) editTabs.getSelectedComponent();
    String text = textComp.getText();
    text = text.replaceAll("(?!\\r)\\n", "\r\n");
    try {
        Files.write(Paths.get(filePath), text.getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:GTextEditor,项目名称:GTextEditor,代码行数:27,代码来源:Main.java

示例14: getLayerSessionChooser

public static void getLayerSessionChooser() throws IOException{	
	JFileChooser sessionImport = new JFileChooser
	(System.getProperty("user.home") + "/Desktop");
	sessionImport.setDialogTitle("Import Layer Session");
	sessionImport.setAcceptAllFileFilterUsed(true);
	sessionImport.setFileFilter(new FileFilter() {
		public boolean accept(File file) {
			String fileName = file.getName().toLowerCase();
			if (fileName.endsWith(".xml")) {
				return true;
			}
			return false;
			}
		public String getDescription() {
			return "XML file (*.xml)";
		}
	});
	sessionImport.setFileSelectionMode(JFileChooser.FILES_ONLY);
	int code = sessionImport.showOpenDialog(map.getParent());
	if(code==JFileChooser.CANCEL_OPTION){
		doImport = false;
		return;
	}else if(code==JFileChooser.APPROVE_OPTION){
		File f =sessionImport.getSelectedFile();
		String fs = f.toString();
		importLayerSession(fs);
		doImport = true;
	}

}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:30,代码来源:LayerManager.java

示例15: saveProfile

void saveProfile(String fmt) {
	
	JFileChooser chooser = MapApp.getFileChooser();
	String defaultFileName = list.getSelectedValue().toString().replace(" ", "_") + "." + fmt;
	chooser.setSelectedFile(new File(defaultFileName));
	int ok = chooser.showSaveDialog(map.getTopLevelAncestor());
	if( ok==JFileChooser.CANCEL_OPTION ) return;
	File file = chooser.getSelectedFile();
	if( file.exists() ) {
		ok = askOverWrite();
		if( ok==JOptionPane.CANCEL_OPTION ) return;
	}

	//get the image from the graph
	BufferedImage image = graph.getFullImage();
	Graphics g = image.getGraphics();
	graph.paint(g);

	try {
		String name = file.getName();
		int sIndex = name.lastIndexOf(".");
		String suffix = sIndex<0
			? fmt
			: name.substring( sIndex+1 );
		if( !ImageIO.getImageWritersBySuffix(suffix).hasNext())suffix = fmt;

		if ( chooser.getSelectedFile().getPath().endsWith(fmt) ) {
			ImageIO.write(image, suffix, file);
		}
		else {
			ImageIO.write(image, suffix, new File(file.getPath() + fmt) );
		}

	} catch(IOException e) {
		JOptionPane.showMessageDialog(null,
				" Save failed: "+e.getMessage(),
				" Save failed",
				 JOptionPane.ERROR_MESSAGE);
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:40,代码来源:Digitizer.java


注:本文中的javax.swing.JFileChooser.CANCEL_OPTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。