javax.swing.JFileChooser Java Examples

The following examples show how to use javax.swing.JFileChooser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: bug8021253.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {

        file = getTempFile();

        final JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 300);

        fileChooser = new JFileChooser(file.getParentFile());
        fileChooser.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                defaultKeyPressed = true;
                frame.dispose();
            }
        });

        frame.getContentPane().add(BorderLayout.CENTER, fileChooser);
        frame.setSize(fileChooser.getPreferredSize());
        frame.setVisible(true);
    }
 
Example #2
Source File: RTopicPanel.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
private void saveScriptToFile() {
    File scriptFile = null;
    try {
        fc.setDialogTitle("Save R script");
        fc.setDialogType(JFileChooser.SAVE_DIALOG);
        int answer = fc.showDialog(Wandora.getWandora(), "Save");
        if(answer == SimpleFileChooser.APPROVE_OPTION) {
            scriptFile = fc.getSelectedFile();
            String scriptCode = rEditor.getText();
            FileUtils.writeStringToFile(scriptFile, scriptCode, null);
            currentScriptSource = FILE_SOURCE;
        }
    }
    catch(Exception e) {
        WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Exception '"+e.getMessage()+"' occurred while storing R script to file '"+scriptFile.getName()+"'.", "Can't save R script", WandoraOptionPane.INFORMATION_MESSAGE);
    }
}
 
Example #3
Source File: FitBuilder.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads fit functions from an XML file chosen by the user.
 * 
 * @return the path to the file opened, or null if none
 */
private String loadFits() {
 	if (chooser==null) {
 		chooser = OSPRuntime.getChooser();
     for (FileFilter filter: chooser.getChoosableFileFilters()) {
     	if (filter.getDescription().toLowerCase().indexOf("xml")>-1) { //$NON-NLS-1$
         chooser.setFileFilter(filter);
     		break;
     	}
     }
 	}
   int result = chooser.showOpenDialog(FitBuilder.this);
   if(result==JFileChooser.APPROVE_OPTION) {
     OSPRuntime.chooserDir = chooser.getCurrentDirectory().toString();
     String fileName = chooser.getSelectedFile().getAbsolutePath();
     return loadFits(fileName, false);
   }
   return null;
}
 
Example #4
Source File: ClassPathFormImpl.java    From jmkvpropedit with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ClassPathFormImpl(Bindings bindings, JFileChooser fc) {
	bindings.addOptComponent("classPath", ClassPath.class, _classpathCheck)
			.add("classPath.mainClass", _mainclassField)
			.add("classPath.paths", _classpathList);
	_fileChooser = fc;

	ClasspathCheckListener cpl = new ClasspathCheckListener();
	_classpathCheck.addChangeListener(cpl);
	cpl.stateChanged(null);

	_classpathList.setModel(new DefaultListModel());
	_classpathList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
	_classpathList.addListSelectionListener(new ClasspathSelectionListener());

	_newClasspathButton.addActionListener(new NewClasspathListener());
	_acceptClasspathButton.addActionListener(
			new AcceptClasspathListener(_classpathField));
	_removeClasspathButton.addActionListener(new RemoveClasspathListener());
	_importClasspathButton.addActionListener(new ImportClasspathListener());
	_classpathUpButton.addActionListener(new MoveUpListener());
	_classpathDownButton.addActionListener(new MoveDownListener());
}
 
Example #5
Source File: LoadProxiesListener.java    From LambdaAttack with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent) {
    int returnVal = fileChooser.showOpenDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Path proxyFile = fileChooser.getSelectedFile().toPath();
        LambdaAttack.getLogger().log(Level.INFO, "Opening: {0}.", proxyFile.getFileName());

        botManager.getThreadPool().submit(() -> {
            try {
                List<Proxy> proxies = Files.lines(proxyFile).distinct().map((line) -> {
                    String host = line.split(":")[0];
                    int port = Integer.parseInt(line.split(":")[1]);

                    InetSocketAddress address = new InetSocketAddress(host, port);
                    return new Proxy(Type.SOCKS, address);
                }).collect(Collectors.toList());

                LambdaAttack.getLogger().log(Level.INFO, "Loaded {0} proxies", proxies.size());

                botManager.setProxies(proxies);
            } catch (Exception ex) {
                LambdaAttack.getLogger().log(Level.SEVERE, null, ex);
            }
        });
    }
}
 
Example #6
Source File: ImageFileChooser.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * Ouvre la boîte de dialogue de choix de fichier image.
 * <br>Retourne le fichier choisi, ou null si annulé.
 * @param parent Component
 * @param openOrSave boolean
 * @param fileName String
 * @return File
 */
public static File chooseImage(Component parent, boolean openOrSave, String fileName) {
	final int result;
	if (fileName != null) {
		IMAGE_FILE_CHOOSER.setSelectedFile(new File(fileName));
	}
	if (openOrSave) {
		result = IMAGE_FILE_CHOOSER.showOpenDialog(parent);
	} else {
		result = IMAGE_FILE_CHOOSER.showSaveDialog(parent);
	}
	if (result == JFileChooser.APPROVE_OPTION) {
		File file = IMAGE_FILE_CHOOSER.getSelectedFile();
		file = IMAGE_FILE_CHOOSER.checkFile(file);
		return file;
	}
	return null;
}
 
Example #7
Source File: AnnotatorOpenEventHandler.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Action performed.
 *
 * @param event the event
 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
 */
@Override
public void actionPerformed(ActionEvent event) {
  try {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Load AE specifier file");
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (this.main.getAnnotOpenDir() != null) {
      fileChooser.setCurrentDirectory(this.main.getAnnotOpenDir());
    }
    int rc = fileChooser.showOpenDialog(this.main);
    if (rc == JFileChooser.APPROVE_OPTION) {
      this.main.loadAEDescriptor(fileChooser.getSelectedFile());
    }
    this.main.setAllAnnotationViewerItemEnable(false);
  } finally {
    this.main.resetCursor();
  }
}
 
Example #8
Source File: SSHKeysPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private File openFile() {
    String home = System.getProperty("user.home"); // NOI18N
    JFileChooser chooser = new JFileChooser(home);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileHidingEnabled(false);
    int dlgResult = chooser.showOpenDialog(this);
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example #9
Source File: PlotTab.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
private String getDirectory(String type, int filter) {
    BaseDirectoryChooser gnuPlotDir = new BaseDirectoryChooser();
    gnuPlotDir.setFileSelectionMode(filter);
    int selection = -1;
    if (type.equals("open")) 
        selection = gnuPlotDir.showOpenDialog(this);
    if (selection == JFileChooser.APPROVE_OPTION) {

        try {
            return gnuPlotDir.getSelectedFile().getAbsolutePath();

        } catch (Exception exp) {
        }

    }
    return "";
}
 
Example #10
Source File: Preferences.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
private Component createLocationSector() {
    JPanel panel = new JPanel(new BorderLayout());
    location = new JTextField();
    location.setPreferredSize(new Dimension(180, location
            .getPreferredSize().height));
    JButton button = new JButton("...");
    button.setToolTipText("Base.Location.ToolTip");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(location.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showOpenDialog(Preferences.this) == JFileChooser.APPROVE_OPTION) {
                location.setText(chooser.getSelectedFile()
                        .getAbsolutePath());
            }

        }
    });
    panel.add(location, BorderLayout.CENTER);
    panel.add(button, BorderLayout.EAST);
    return panel;
}
 
Example #11
Source File: AbstractFileSelectionAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Selects a file to use as target for the operation.
 *
 * @param selectedFile
 *          the selected file.
 * @param dialogType
 *          the dialog type.
 * @param appendExtension
 *          true, if the file extension should be added if necessary, false if the unmodified filename should be used.
 * @return the selected and approved file or null, if the user canceled the operation
 */
protected File performSelectFile( final File selectedFile, final int dialogType, final boolean appendExtension ) {
  if ( this.fileChooser == null ) {
    this.fileChooser = createFileChooser();
  }

  this.fileChooser.setSelectedFile( selectedFile );
  this.fileChooser.setDialogType( dialogType );
  final int option = this.fileChooser.showDialog( this.parent, null );
  if ( option == JFileChooser.APPROVE_OPTION ) {
    final File selFile = this.fileChooser.getSelectedFile();
    String selFileName = selFile.getAbsolutePath();
    if ( StringUtils.endsWithIgnoreCase( selFileName, getFileExtension() ) == false ) {
      selFileName = selFileName + getFileExtension();
    }
    return new File( selFileName );
  }
  return null;
}
 
Example #12
Source File: FPortecle.java    From portecle with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Let the user choose a certificate file to export to.
 *
 * @param basename default filename (without extension)
 * @return The chosen file or null if none was chosen
 */
private File chooseExportCertFile(String basename)
{
	JFileChooser chooser = FileChooserFactory.getX509FileChooser(basename);

	File fLastDir = m_lastDir.getLastDir();
	if (fLastDir != null)
	{
		chooser.setCurrentDirectory(fLastDir);
	}

	chooser.setDialogTitle(RB.getString("FPortecle.ExportCertificate.Title"));
	chooser.setMultiSelectionEnabled(false);

	int iRtnValue = chooser.showDialog(this, RB.getString("FPortecle.Export.button"));
	if (iRtnValue == JFileChooser.APPROVE_OPTION)
	{
		return chooser.getSelectedFile();
	}
	return null;
}
 
Example #13
Source File: FileSelector.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the selected.
 *
 * @param s the new selected
 */
public void setSelected(String s) {
  field.setText(s);
  previousValue = s;
  if (s == null || s.length() == 0) {
    s = System.getProperty("user.dir");
  }
  File file = new File(s);

  //only modify file chooser if it has already been created
  if (this.fileChooser != null) {
    if (this.fileChooser.getFileSelectionMode() == JFileChooser.FILES_ONLY && file.isDirectory()) {
      this.fileChooser.setCurrentDirectory(file);
    } else {
      this.fileChooser.setSelectedFile(file);
    }
  }
}
 
Example #14
Source File: ExportTool.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
void createFileChooser() {
  formats = new Hashtable<String, ExportFormat>();
  registerFormat(new ExportGnuplotFormat());
  registerFormat(new ExportXMLFormat());
  // Set the "filesOfTypeLabelText" to "File Format:"
  Object oldFilesOfTypeLabelText = UIManager.put("FileChooser.filesOfTypeLabelText", //$NON-NLS-1$
    ToolsRes.getString("ExportTool.FileChooser.Label.FileFormat"));                  //$NON-NLS-1$
  // Create a new FileChooser
  fc = new JFileChooser(OSPRuntime.chooserDir);
  // Reset the "filesOfTypeLabelText" to previous value
  UIManager.put("FileChooser.filesOfTypeLabelText", oldFilesOfTypeLabelText);          //$NON-NLS-1$
  fc.setDialogType(JFileChooser.SAVE_DIALOG);
  fc.setDialogTitle(ToolsRes.getString("ExportTool.FileChooser.Title"));               //$NON-NLS-1$
  fc.setApproveButtonText(ToolsRes.getString("ExportTool.FileChooser.Button.Export")); // Set export formats //$NON-NLS-1$
  setChooserFormats();
}
 
Example #15
Source File: VersionInfoFormImpl.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
public VersionInfoFormImpl(Bindings bindings, JFileChooser fc) {
	_languageCombo.setModel(new DefaultComboBoxModel(LanguageID.sortedValues()));
	bindings.addOptComponent("versionInfo", VersionInfo.class, _versionInfoCheck)
			.add("versionInfo.fileVersion", _fileVersionField)
			.add("versionInfo.productVersion", _productVersionField)
			.add("versionInfo.fileDescription", _fileDescriptionField)
			.add("versionInfo.internalName", _internalNameField)
			.add("versionInfo.originalFilename", _originalFilenameField)
			.add("versionInfo.productName", _productNameField)
			.add("versionInfo.txtFileVersion", _txtFileVersionField)
			.add("versionInfo.txtProductVersion", _txtProductVersionField)
			.add("versionInfo.companyName", _companyNameField)
			.add("versionInfo.copyright", _copyrightField)
			.add("versionInfo.trademarks", _trademarksField)
			.add("versionInfo.languageIndex", _languageCombo, VersionInfo.DEFAULT_LANGUAGE_INDEX)
	;
}
 
Example #16
Source File: ExportMenu.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
private void exportUnitCharts() {
  final JFileChooser chooser = new JFileChooser();
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  final File rootDir = new File(SystemProperties.getUserDir());
  final String defaultFileName =
      FileNameUtils.removeIllegalCharacters(gameData.getGameName()) + "_unit_stats.html";
  chooser.setSelectedFile(new File(rootDir, defaultFileName));
  if (chooser.showSaveDialog(frame) != JOptionPane.OK_OPTION) {
    return;
  }
  try (Writer writer =
      Files.newBufferedWriter(chooser.getSelectedFile().toPath(), StandardCharsets.UTF_8)) {
    writer.write(
        HelpMenu.getUnitStatsTable(gameData, uiContext)
            .replaceAll("</?p>|</tr>", "$0\r\n")
            .replaceAll("(?i)<img[^>]+/>", ""));
  } catch (final IOException e1) {
    log.log(
        Level.SEVERE,
        "Failed to write unit stats: " + chooser.getSelectedFile().getAbsolutePath(),
        e1);
  }
}
 
Example #17
Source File: MainFrame.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
private void menuNewProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNewProjectActionPerformed
  final JFileChooser folderChooser = new JFileChooser();
  folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  folderChooser.setDialogTitle("Create project folder");
  folderChooser.setDialogType(JFileChooser.SAVE_DIALOG);
  folderChooser.setApproveButtonText("Create");
  folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  if (folderChooser.showSaveDialog(Main.getApplicationFrame()) == JFileChooser.APPROVE_OPTION) {
    final File file = folderChooser.getSelectedFile();
    if (file.isDirectory()) {
      if (file.list().length > 0) {
        DialogProviderManager.getInstance().getDialogProvider().msgError(this, "File '" + file.getName() + "' already exists and non-empty!");
      } else {
        prepareAndOpenProjectFolder(file);
      }
    } else if (file.mkdirs()) {
      prepareAndOpenProjectFolder(file);
    } else {
      LOGGER.error("Can't create folder : " + file); //NOI18N
      DialogProviderManager.getInstance().getDialogProvider().msgError(this, "Can't create folder: " + file);
    }
  }
}
 
Example #18
Source File: ProductLocationsPane.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    final FolderChooser folderChooser = new FolderChooser();
    final Preferences preferences = SnapApp.getDefault().getPreferences();
    String lastDir = preferences.get(PROPERTY_KEY_LAST_OPEN_TS_DIR, SystemUtils.getUserHomeDir().getPath());

    folderChooser.setCurrentDirectory(new File(lastDir));

    final int result = folderChooser.showOpenDialog(ProductLocationsPane.this);
    if (result != JFileChooser.APPROVE_OPTION) {
        return;
    }

    File currentDir = folderChooser.getSelectedFolder();
    model.addDirectory(currentDir, recursive);
    if (currentDir != null) {
        preferences.put(PROPERTY_KEY_LAST_OPEN_TS_DIR, currentDir.getAbsolutePath());
    }

}
 
Example #19
Source File: ChartPanel.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart
 * in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
public void doSaveAs() throws IOException {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs);
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
                localizationResources.getString("PNG_Image_Files"), "png");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);

    int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
                getWidth(), getHeight());
    }
}
 
Example #20
Source File: GuiUtils.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a replay file preview accessory for a JFileChooser.
 * @param fileChooser file chooser to create the accessory for
 * @return a replay file preview accessory for JFileChoosers
 */
public static JComponent createReplayFilePreviewAccessory( final JFileChooser fileChooser ) {
	final ReplayInfoBox replayInfoBox = new ReplayInfoBox();
	
	fileChooser.addPropertyChangeListener( new PropertyChangeListener() {
		@Override
		public void propertyChange( final PropertyChangeEvent event ) {
			if ( JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals( event.getPropertyName() ) ) {
				final File file = (File) event.getNewValue();
				if ( file == null || file.isDirectory() )
					return;
				replayInfoBox.setReplayFile( file );
			}
		}
	} );
	
	return replayInfoBox;
}
 
Example #21
Source File: FileChooserBuilderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSetSelectionApprover() throws Exception {
    FileChooserBuilder instance = new FileChooserBuilder("i");
    File tmp = getWorkDir();
    assertTrue ("Environment is insane", tmp.exists() && tmp.isDirectory());
    File sel = new File(tmp, "tmp" + System.currentTimeMillis());
    if (!sel.exists()) {
        assertTrue (sel.createNewFile());
    }
    instance.setDefaultWorkingDirectory(tmp);
    SA sa = new SA();
    instance.setSelectionApprover(sa);
    JFileChooser ch = instance.createFileChooser();
    ch.setSelectedFile(sel);
    ch.approveSelection();
    sa.assertApproveInvoked(sel);
}
 
Example #22
Source File: ExportUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void showExportDialog(final JFileChooser fileChooser, final Component parent, final ExportProvider[] providers) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (fileChooser.showDialog(parent, BUTTON_EXPORT) != JFileChooser.APPROVE_OPTION) return;

            File targetFile = fileChooser.getSelectedFile();
            FileFilter filter = fileChooser.getFileFilter();

            for (ExportProvider provider : providers) {
                FormatFilter format = provider.getFormatFilter();
                if (filter.equals(format)) {
                    targetFile = checkFileExtension(targetFile, format.getExtension());
                    if (checkFileExists(targetFile)) provider.export(targetFile);
                    else showExportDialog(fileChooser, parent, providers);
                    break;
                }
            }
        }
    });
}
 
Example #23
Source File: FileNameComponent.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setMultiSelectionEnabled(false);

  String currentPath = txtFilename.getText();
  if (currentPath.length() > 0) {
    File currentFile = new File(currentPath);
    File currentDir = currentFile.getParentFile();
    if (currentDir != null && currentDir.exists())
      fileChooser.setCurrentDirectory(currentDir);
  }

  int returnVal = fileChooser.showDialog(MZmineCore.getDesktop().getMainWindow(), "Select file");

  if (returnVal == JFileChooser.APPROVE_OPTION) {
    String selectedPath = fileChooser.getSelectedFile().getAbsolutePath();
    txtFilename.setText(selectedPath);
  }
}
 
Example #24
Source File: DebugMenu.java    From whyline with MIT License 5 votes vote down vote up
private void generateUsageStatistics() throws IOException {

		String methodname = JOptionPane.showInputDialog(whylineUI, "Which method is the bug in (e.g., \"java/lang/Character.isDefined(C)Z\")?");
		if(methodname == null) return;
		String[] names = methodname.split("\\.");
		
		if(names.length != 2) {
			JOptionPane.showMessageDialog(whylineUI, "Couldn't split into class and method name");
			return;
		}
		Classfile buggyClass = whylineUI.getTrace().getClassfileByName(QualifiedClassName.get(names[0]));
		if(buggyClass == null) {
			JOptionPane.showMessageDialog(whylineUI, "Couldn't find class " + names[0]);
			return;
		}
		MethodInfo buggyMethod = buggyClass.getDeclaredMethodByNameAndDescriptor(names[1]);
		if(buggyMethod == null) {
			JOptionPane.showMessageDialog(whylineUI, "Couldn't find method " + names[1] + " in " + names[0]);
			return;
		}
				
		JFileChooser chooser = new JFileChooser(whylineUI.getTrace().getPath());
		chooser.setDialogTitle("Select a folder that contains the usage logs to analyze");
		chooser.setFileHidingEnabled(true);
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

		int choice = chooser.showOpenDialog(whylineUI);
		
		if(choice != JFileChooser.APPROVE_OPTION) return;
		
		File folder = chooser.getSelectedFile();

		Usage usage = new Usage(whylineUI.getTrace(), folder, buggyMethod);

		JOptionPane.showMessageDialog(whylineUI, "Saved 'results.csv' in " + folder.getName());

	}
 
Example #25
Source File: JFileChooserOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JFileChooser.rescanCurrentDirectory()} through queue
 */
public void rescanCurrentDirectory() {
    runMapping(new MapVoidAction("rescanCurrentDirectory") {
        @Override
        public void map() {
            ((JFileChooser) getSource()).rescanCurrentDirectory();
        }
    });
}
 
Example #26
Source File: bug8062561.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkFileChooser() throws Exception {
    if (System.getSecurityManager() == null) {
        throw new RuntimeException("Security manager is not set!");
    }

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
            fileChooserIsShown = true;
            System.out.println("Start file chooser: " + fileChooserIsShown);
        }
    });

    long time = System.currentTimeMillis();
    while (fileChooser == null) {
        if (System.currentTimeMillis() - time >= 10000) {
            throw new RuntimeException("FileChoser is not shown!");
        }
        Thread.sleep(500);
    }

    Thread.sleep(500);
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);
    System.exit(0);
}
 
Example #27
Source File: ExportEnviGcpFileAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private JFileChooser createFileChooser() {
    String lastDirPath = Config.instance().load().preferences().get(GCP_EXPORT_DIR_PREFERENCES_KEY,
                                                                    SystemUtils.getUserHomeDir().getPath());
    SnapFileChooser fileChooser = new SnapFileChooser();

    HelpCtx.setHelpIDString(fileChooser, getHelpCtx().getHelpID());
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setCurrentDirectory(new File(lastDirPath));

    fileChooser.setFileFilter(
            new SnapFileFilter(GCP_FILE_DESCRIPTION, GCP_FILE_EXTENSION, GCP_FILE_DESCRIPTION));
    fileChooser.setDialogTitle(Bundle.CTL_ExportEnviGcpFileAction_DialogTitle());
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    return fileChooser;
}
 
Example #28
Source File: JFileChooserOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JFileChooser.getFileSelectionMode()} through queue
 */
public int getFileSelectionMode() {
    return (runMapping(new MapIntegerAction("getFileSelectionMode") {
        @Override
        public int map() {
            return ((JFileChooser) getSource()).getFileSelectionMode();
        }
    }));
}
 
Example #29
Source File: ModuleSuiteDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onOK() {
    ToolAdapterOperatorDescriptor[] selection = ((AdapterListModel) this.operatorsTable.getModel()).getSelectedItems();
    if (selection.length > 0) {
        this.descriptor = this.descriptorForm.applyChanges();
        final Map<OSFamily, org.esa.snap.core.gpf.descriptor.dependency.Bundle> bundles = this.bundleForm.applyChanges();
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (fileChooser.showOpenDialog(getButton(ID_OTHER)) == JFileChooser.APPROVE_OPTION) {
            File targetFolder = fileChooser.getSelectedFile();
            final String nbmName = this.descriptor.getName() + ".nbm";
            ProgressWorker worker = new ProgressWorker("Export Module Suite", "Creating NetBeans module suite " + nbmName,
                    () -> {
                        try {
                            ModulePackager.packModules(this.descriptor, new File(targetFolder, nbmName), bundles, selection);
                            Dialogs.showInformation(String.format(Bundle.MSG_Export_Complete_Text(), targetFolder.getAbsolutePath()), null);
                        } catch (IOException e) {
                            SystemUtils.LOG.warning(e.getMessage());
                            Dialogs.showError(e.getMessage());
                        }
                    });
            worker.executeWithBlocking();
            super.onOK();
        }
    } else {
        Dialogs.showWarning("Please select at least one adapter");
    }
}
 
Example #30
Source File: DelegatingChooserUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Returns dirchooser for DIRECTORIES_ONLY, default filechooser for other
 * selection modes.
 */
private static Class<?> getCurChooser (JFileChooser fc) {
    if (fc.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
        return DirectoryChooserUI.class;
    }
    return Module.getOrigChooser();
}