use of javax.swing.filechooser.FileFilter in project jdk8u_jdk by JetBrains.
the class BasicFileChooserUI method resetGlobFilter.
private void resetGlobFilter() {
if (actualFileFilter != null) {
JFileChooser chooser = getFileChooser();
FileFilter currentFilter = chooser.getFileFilter();
if (currentFilter != null && currentFilter.equals(globFilter)) {
chooser.setFileFilter(actualFileFilter);
chooser.removeChoosableFileFilter(globFilter);
}
actualFileFilter = null;
}
}
use of javax.swing.filechooser.FileFilter in project bytecode-viewer by Konloch.
the class BytecodeViewer method checkHotKey.
/**
* Checks the hotkeys
*
* @param e
*/
public static void checkHotKey(KeyEvent e) {
if (System.currentTimeMillis() - last <= (4000))
return;
if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
JFileChooser fc = new JFileChooser();
try {
fc.setSelectedFile(new File(BytecodeViewer.lastDirectory));
} catch (Exception e2) {
}
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory())
return true;
String extension = MiscUtils.extension(f.getAbsolutePath());
if (extension != null)
if (extension.equals("jar") || extension.equals("zip") || extension.equals("class") || extension.equals("apk") || extension.equals("dex"))
return true;
return false;
}
@Override
public String getDescription() {
return "APKs, DEX, Class Files or Zip/Jar Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
BytecodeViewer.lastDirectory = fc.getSelectedFile().getAbsolutePath();
try {
BytecodeViewer.viewer.setIcon(true);
BytecodeViewer.openFiles(new File[] { fc.getSelectedFile() }, true);
BytecodeViewer.viewer.setIcon(false);
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
}
} else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
BytecodeViewer.resetWorkSpace(true);
} else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
Thread t = new Thread() {
public void run() {
BytecodeViewer.compile(true);
}
};
t.start();
} else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return;
}
new RunOptions().setVisible(true);
} else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return;
}
Thread t = new Thread() {
public void run() {
if (viewer.autoCompileSmali.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip");
if (file.exists()) {
JOptionPane pane = new JOptionPane("Are you sure you wish to overwrite this existing file?");
Object[] options = new String[] { "Yes", "No" };
pane.setOptions(options);
JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Overwrite File");
dialog.setVisible(true);
Object obj = pane.getValue();
int result = -1;
for (int k = 0; k < options.length; k++) if (options[k].equals(obj))
result = k;
if (result == 0) {
file.delete();
} else {
return;
}
}
final File file2 = file;
BytecodeViewer.viewer.setIcon(true);
Thread t = new Thread() {
@Override
public void run() {
JarUtils.saveAsJar(BytecodeViewer.getLoadedBytes(), file2.getAbsolutePath());
BytecodeViewer.viewer.setIcon(false);
}
};
t.start();
}
}
};
t.start();
} else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
if (viewer.workPane.getCurrentViewer() != null)
viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer());
}
}
use of javax.swing.filechooser.FileFilter in project vcell by virtualcell.
the class ChooseFile method showBioModelXMLFileChooser.
/**
* Insert the method's description here.
* Creation date: (5/31/2004 6:04:14 PM)
*/
private File showBioModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
BioModel bioModel = (BioModel) hashTable.get("documentToExport");
JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
SelectorExtensionFilter forceFileFilter = null;
{
Object obj = hashTable.get(FORCE_FILE_FILTER);
if (obj != null) {
VCAssert.ofType(obj, SelectorExtensionFilter.class);
forceFileFilter = (SelectorExtensionFilter) obj;
VCAssert.assertTrue(forceFileFilter.supports(Selector.FULL_MODEL), "only " + Selector.FULL_MODEL + " filters supported for force file filter");
}
}
if (topLevelWindowManager == null) {
throw new RuntimeException("toplLevelWindowManager required");
}
File defaultPath = userPreferences.getCurrentDialogPath();
// JFileChooser fileChooser = new JFileChooser(defaultPath);
VCFileChooser fileChooser = new VCFileChooser(defaultPath);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
final SimulationContext[] simContexts = bioModel.getSimulationContexts();
boolean spatialDeterministicSim = false;
boolean nonspatialDeterministicSim = false;
boolean stochasticSim = false;
@SuppressWarnings("unused") boolean // add logic to set this
bnglSim = false;
for (SimulationContext sc : simContexts) {
if (sc.getApplicationType() == Application.NETWORK_STOCHASTIC) {
stochasticSim = true;
} else {
if (sc.getGeometry().getDimension() > 0) {
spatialDeterministicSim = true;
} else {
nonspatialDeterministicSim = true;
}
}
}
FileFilter defaultFileFilter;
if (forceFileFilter == null) {
List<FileFilter> dlist = FileFilters.supports(SelectorExtensionFilter.Selector.DEFAULT);
VCAssert.assertTrue(dlist.size() == 1, "Exactly one filter must be designated default");
defaultFileFilter = dlist.get(0);
// use a set to avoid duplicated entries; TreeSet show listing is alphabetical
Set<FileFilter> filters = new TreeSet<>();
filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.FULL_MODEL));
if (spatialDeterministicSim) {
filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.DETERMINISTIC, SelectorExtensionFilter.Selector.SPATIAL));
}
if (nonspatialDeterministicSim) {
filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.DETERMINISTIC, SelectorExtensionFilter.Selector.NONSPATIAL));
}
if (stochasticSim) {
filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.STOCHASTIC));
}
/*add BNGL selector here
if (bnglSim) {
filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.BNGL));
}
*/
fileChooser.addChoosableFileFilter(defaultFileFilter);
for (FileFilter f : filters) {
if (f == defaultFileFilter) {
continue;
}
fileChooser.addChoosableFileFilter(f);
}
/*
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_12);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_21);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_22);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_23);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_24);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_31_CORE);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_31_SPATIAL);
// fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CELLML);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SEDML);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_VCML);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MATLABV6);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SMOLDYN_INPUT);
*/
} else {
defaultFileFilter = forceFileFilter;
}
// remove all selectors
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
// Set the default file filter...
fileChooser.setFileFilter(defaultFileFilter);
fileChooser.setSelectedFile(new java.io.File(TokenMangler.fixTokenStrict(bioModel.getName())));
fileChooser.setDialogTitle("Export Virtual Cell BioModel As...");
if (fileChooser.showSaveDialog(currentWindow) != JFileChooser.APPROVE_OPTION) {
// user didn't choose save
throw UserCancelException.CANCEL_FILE_SELECTION;
}
File selectedFile = fileChooser.getSelectedFile();
FileFilter gfileFilter = fileChooser.getFileFilter();
VCAssert.ofType(gfileFilter, SelectorExtensionFilter.class);
// only ExtensionFilters should have been added;
SelectorExtensionFilter fileFilter = (SelectorExtensionFilter) gfileFilter;
if (selectedFile == null) {
// no file selected (no name given)
throw UserCancelException.CANCEL_FILE_SELECTION;
}
final File fileUserSpecified = selectedFile.getCanonicalFile();
// /
String selectedFileName = recordAndRemoveExtension(selectedFile.getPath());
if (extensionUserProvided != null && !extensionUserProvided.isEmpty() && !extensionUserProvided.startsWith(".")) {
extensionUserProvided = "." + extensionUserProvided;
}
if (fileFilter.isValidExtension(extensionUserProvided)) {
selectedFileName += extensionUserProvided;
} else {
selectedFileName += fileFilter.getPrimaryExtension();
}
selectedFile = new File(selectedFileName);
checkForOverwrites(selectedFile, topLevelWindowManager.getComponent(), userPreferences);
// put the filter in the hash so the export task knows what to do...
hashTable.put(FILE_FILTER, fileFilter);
if (fileFilter.supports(SelectorExtensionFilter.Selector.FULL_MODEL)) {
// nothing more to do in this case
resetPreferredFilePath(selectedFile, userPreferences);
return selectedFile;
}
// ArrayList<String> applicableAppNameList = new ArrayList<String>();
ArrayList<SimulationContext> applicableSimContexts = new ArrayList<>();
for (SimulationContext sc : simContexts) {
if (sc.getGeometry().getDimension() == 0) {
if (!fileFilter.supports(SelectorExtensionFilter.Selector.NONSPATIAL)) {
continue;
}
} else if (!fileFilter.supports(SelectorExtensionFilter.Selector.SPATIAL)) {
continue;
}
if (sc.getApplicationType() == Application.NETWORK_STOCHASTIC) {
if (!fileFilter.supports(SelectorExtensionFilter.Selector.STOCHASTIC)) {
continue;
}
} else if (!fileFilter.supports(SelectorExtensionFilter.Selector.DETERMINISTIC)) {
continue;
}
applicableSimContexts.add(sc);
}
/*
{} else {
// all apps
for (int i=0;i<simContexts.length;i++){
applicableAppNameList.add(simContexts[i].getName());
}
}
*/
SimulationContext chosenSimContext = null;
if (applicableSimContexts.size() == 1) {
chosenSimContext = applicableSimContexts.get(0);
} else /*
else if (!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_PDF.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_12.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_21.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_22.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_23.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_24.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_CORE.getDescription()) &&
!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL.getDescription())) {
if(fileFilter.getDescription().equals(FileFilters.FILE_FILTER_BNGL.getDescription())) {
boolean hasReactions = bioModel.getModel().getReactionSteps().length > 0 ? true : false;
System.out.println(hasReactions);
if(hasReactions) { // mixed
String errMsg = "Simple Reactions cannot be exported to .bngl format.";
errMsg += "<br>Some information will be lost.";
errMsg += "<br><br>Continue anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(topLevelWindowManager.getComponent(), errMsg, "Exporting to .bngl", dialogButton);
if (returnCode != JOptionPane.YES_OPTION) {
throw UserCancelException.CANCEL_FILE_SELECTION;
}
}
}
//String[] applicationNames = (String[])org.vcell.util.BeanUtils.getArray(applicableAppNameList,String.class);
} */
{
// String[] applicationNames = applicableAppNameList.toArray(new String[applicableAppNameList.size()]);
SimContextAdapter[] scarray = adapt(applicableSimContexts);
Object choice = PopupGenerator.showListDialog(topLevelWindowManager, scarray, "Please select Application");
if (choice == null) {
throw UserCancelException.CANCEL_FILE_SELECTION;
}
VCAssert.ofType(choice, SimContextAdapter.class);
SimContextAdapter sca = (SimContextAdapter) choice;
chosenSimContext = sca.simCtx;
}
hashTable.put(SIM_CONTEXT, chosenSimContext);
// boolean isSbml = fileFilter.supports(SelectorExtensionFilter.Selector.SBML);
if (fileFilter.requiresMoreChoices()) {
ExtensionFilter.ChooseContext ctx = new ExtensionFilter.ChooseContext(hashTable, topLevelWindowManager, currentWindow, chosenSimContext, selectedFile, selectedFileName);
fileFilter.askUser(ctx);
}
{
boolean showConfirm = false;
final boolean someContextsFiltered = simContexts.length > applicableSimContexts.size();
showConfirm = someContextsFiltered;
if (!showConfirm) {
final File fileAfterProcessing = selectedFile.getCanonicalFile();
if (!fileAfterProcessing.equals(fileUserSpecified)) {
final String nameUserSpecified = fileUserSpecified.getCanonicalPath();
final String nameAfterProcessing = fileAfterProcessing.getCanonicalPath();
if (FilenameUtils.indexOfExtension(nameUserSpecified) > 0) {
// have extension on user path
showConfirm = true;
} else {
// don't prompt if user left extension off
String nameAfterNoExtension = FilenameUtils.getFullPath(nameAfterProcessing) + FilenameUtils.getBaseName(nameAfterProcessing);
if (!nameAfterNoExtension.equals(nameUserSpecified)) {
showConfirm = true;
}
}
}
}
if (showConfirm) {
final String exportDesc = fileFilter.getShortDescription();
StringBuilder sb = new StringBuilder();
List<SimulationContext> all = new ArrayList<>(Arrays.asList(simContexts));
all.removeAll(applicableSimContexts);
if (!all.isEmpty()) {
SimContextAdapter[] removed = adapt(all);
sb.append("The following simulations are not supported by ");
sb.append(exportDesc);
sb.append(" and have been removed: ");
sb.append(StringUtils.join(removed, ", "));
sb.append(".\n\n");
}
SimContextAdapter[] included = adapt(applicableSimContexts);
sb.append("Export model with simulations ");
sb.append(StringUtils.join(included, ", "));
sb.append(" to file of type ");
sb.append(exportDesc);
sb.append(' ');
sb.append(selectedFile.getCanonicalPath());
sb.append('?');
String reply = DialogUtils.showOKCancelWarningDialog(currentWindow, "Verify Export", sb.toString());
if (!SimpleUserMessage.OPTION_OK.equals(reply)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
}
resetPreferredFilePath(selectedFile, userPreferences);
return selectedFile;
}
use of javax.swing.filechooser.FileFilter in project jgnash by ccavanaugh.
the class DatabasePathAction method databaseNameAction.
public static String databaseNameAction(final Component parent, final Type type, @NotNull final DataStoreType... dataStoreTypes) {
final String[] ext = new String[dataStoreTypes.length];
for (int i = 0; i < dataStoreTypes.length; i++) {
ext[i] = dataStoreTypes[i].getDataStore().getFileExt();
}
final ResourceBundle rb = ResourceUtils.getBundle();
final StringBuilder description = new StringBuilder(rb.getString("Label.jGnashFiles") + " (");
for (int i = 0; i < dataStoreTypes.length; i++) {
description.append("*");
description.append(dataStoreTypes[i].getDataStore().getFileExt());
if (i < dataStoreTypes.length - 1) {
description.append(", ");
}
}
description.append(')');
Preferences pref = Preferences.userNodeForPackage(DatabasePathAction.class);
JFileChooser chooser = new JFileChooser(pref.get(LAST_DIR, null));
final FileFilter filter = new DataStoreFilter(description.toString(), ext);
chooser.addChoosableFileFilter(filter);
chooser.setFileFilter(filter);
chooser.setMultiSelectionEnabled(false);
chooser.setApproveButtonText(rb.getString("Button.Ok"));
if (type == Type.OPEN) {
chooser.setDialogTitle(rb.getString("Title.Open"));
} else {
chooser.setDialogTitle(rb.getString("Title.NewFile"));
}
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
pref.put(LAST_DIR, chooser.getCurrentDirectory().getAbsolutePath());
try {
return chooser.getSelectedFile().getAbsolutePath();
} catch (Exception e) {
Logger.getAnonymousLogger().warning(e.toString());
}
}
return "";
}
use of javax.swing.filechooser.FileFilter in project android-classyshark by google.
the class ClassySharkPanel method onMappingsButtonPressed.
@Override
public void onMappingsButtonPressed() {
final JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return true;
}
@Override
public String getDescription() {
return "";
}
});
fc.setCurrentDirectory(CurrentFolderConfig.INSTANCE.getCurrentDirectory());
int returnVal = fc.showOpenDialog(this);
toolbar.setText("");
if (returnVal == JFileChooser.APPROVE_OPTION) {
File resultFile = fc.getSelectedFile();
readMappingFile(resultFile);
}
}
Aggregations