List of usage examples for javax.swing JFileChooser OPEN_DIALOG
int OPEN_DIALOG
To view the source code for javax.swing JFileChooser OPEN_DIALOG.
Click Source Link
JFileChooser
supports an "Open" file operation. From source file:org.kepler.gui.kar.ViewManifestAction.java
/** * Invoked when an action occurs./*from ww w .ja v a 2s. c o m*/ * *@param e * ActionEvent */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); File karFile = null; if (archiveFileToOpen != null) { karFile = archiveFileToOpen; } else { // ask the user what file to open // Create a file filter that accepts .kar files. ExtensionFilenameFilter filter = new ExtensionFilenameFilter(".kar", "kar"); // Avoid white boxes in file chooser, see // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3801 JFileChooserBugFix jFileChooserBugFix = new JFileChooserBugFix(); Color background = null; PtFileChooser chooser = null; try { background = jFileChooserBugFix.saveBackground(); chooser = new PtFileChooser(parent, "Choose archive", JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(LocalRepositoryManager.getInstance().getSaveRepository()); chooser.addChoosableFileFilter(filter); int returnVal = chooser.showDialog(parent, "Open"); if (returnVal == JFileChooser.APPROVE_OPTION) { // process the given kar file karFile = chooser.getSelectedFile(); } } finally { jFileChooserBugFix.restoreBackground(background); } } if (karFile != null) { try { KarManifestViewer kmv = new KarManifestViewer(); kmv.initialize(new KARFile(karFile)); kmv.setSize(new Dimension(800, 400)); kmv.setLocation(parent.getLocation()); kmv.setVisible(true); } catch (Exception exc) { exc.printStackTrace(); } } }
From source file:org.pentaho.reporting.designer.core.editor.styles.styleeditor.StyleDefinitionUtilities.java
/** * Invoked when an action occurs.//from w w w. j a v a2 s . c o m */ public static void openStyleDefinition(final StyleDefinitionEditorContext context) { final FileFilter filter = new FilesystemFilter(new String[] { DEFAULT_EXTENSION }, Messages.getString("StyleDefinitionUtilities.FileDescription"), true); final CommonFileChooser fileChooser = FileChooserService.getInstance().getFileChooser(FILE_CHOOSER_TYPE); fileChooser.setFilters(new FileFilter[] { filter }); fileChooser.setAllowMultiSelection(true); if (fileChooser.showDialog(context.getParent(), JFileChooser.OPEN_DIALOG) == false) { return; } final File[] selectedFiles = fileChooser.getSelectedFiles(); for (int i = 0, selectedFilesLength = selectedFiles.length; i < selectedFilesLength; i++) { final File selectedFile = selectedFiles[i]; SwingUtilities.invokeLater(new OpenReportTask(selectedFile, context)); } }
From source file:org.piraso.ui.base.ImportDialog.java
private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed File home = new File(System.getProperty("user.home")); File pirasoDir = new File(home, "piraso"); if (!pirasoDir.isDirectory()) { pirasoDir.mkdirs();//from w w w . ja v a 2s .c om } JFileChooser browserFileChooser = new FileChooserBuilder("piraso-dir") .setTitle(NbBundle.getMessage(ImportDialog.class, "ImportDialog.browser.title")) .setDefaultWorkingDirectory(pirasoDir).setFileFilter(new PirasoSettingsFileFilter()) .createFileChooser(); browserFileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = browserFileChooser.showDialog(this, NbBundle.getMessage(ImportDialog.class, "ImportDialog.browser.approveText")); if (JFileChooser.APPROVE_OPTION == result) { selectedFile = browserFileChooser.getSelectedFile(); txtSourceFile.setText(browserFileChooser.getSelectedFile().getAbsolutePath()); try { settings = JacksonUtils.MAPPER.readValue(selectedFile, ObjectEntrySettings.class); } catch (IOException e) { ErrorManager.getDefault().notify(e); return; } refresh(); } }
From source file:org.piraso.ui.base.OpenMonitorInstanceDialog.java
private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed File home = new File(System.getProperty("user.home")); File pirasoDir = new File(home, "piraso"); File pirasoSaveDir = new File(pirasoDir, "saved"); if (!pirasoSaveDir.isDirectory()) { pirasoSaveDir.mkdirs();/*from w ww .j a v a2 s .c o m*/ } JFileChooser browserFileChooser = new FileChooserBuilder("piraso-saved-dir") .setTitle(NbBundle.getMessage(OpenMonitorInstanceDialog.class, "OpenMonitorInstanceDialog.browser.title")) .setFileFilter(new PirasoFileFilter()).setDefaultWorkingDirectory(pirasoSaveDir) .createFileChooser(); browserFileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = browserFileChooser.showDialog(this, NbBundle.getMessage(OpenMonitorInstanceDialog.class, "OpenMonitorInstanceDialog.browser.approveText")); if (JFileChooser.APPROVE_OPTION == result) { selectedFile = browserFileChooser.getSelectedFile(); txtSourceFile.setText(browserFileChooser.getSelectedFile().getAbsolutePath()); refreshButtons(); } }
From source file:org.ut.biolab.medsavant.client.annotation.InstallAnnotationWizard.java
private AbstractWizardPage getChoosePage() { return new DefaultWizardPage(PAGENAME_CHOOSE) { {/*from www. j av a 2 s. c o m*/ chooseContainer = ViewUtil.getClearPanel(); chooseContainer.setLayout(new BorderLayout()); chooseTitleLabel = new JLabel(); repoChoosePanel = populateRepositoryPanel(this); fileChoosePanel = new PathField(JFileChooser.OPEN_DIALOG); fileChoosePanel.setFileFilters(ExtensionFileFilter.createFilters(new String[] { "gz", "zip" })); fileChoosePanel.getTextField().addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent ce) { if (!fileChoosePanel.getTextField().getText().isEmpty()) { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } else { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } } }); addComponent(chooseTitleLabel); addComponent(chooseContainer); setSourceFromRepo(true, this); } @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.NEXT); //Sstem.out.println("Disabling next button"); if (!hasAnnotations) { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } } }; }
From source file:org.wandora.application.gui.topicpanels.ProcessingTopicPanel.java
private void autorunFileButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_autorunFileButtonMouseReleased fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setDialogTitle("Select Processing sketch"); int answer = fc.showDialog(Wandora.getWandora(), "Select"); if (answer == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f != null) { autoRunFileTextField.setText(f.getAbsolutePath()); autoRunFileRadioButton.setSelected(true); }/*from w w w.j a v a2s. com*/ } }
From source file:org.wandora.application.gui.topicpanels.ProcessingTopicPanel.java
public void loadSketchFromFile() { fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setDialogTitle("Open Processing Sketch"); int answer = fc.showDialog(Wandora.getWandora(), "Open"); if (answer == SimpleFileChooser.APPROVE_OPTION) { File scriptFile = fc.getSelectedFile(); try {//from w w w .j a v a 2 s. com String script = IObox.loadFile(scriptFile); currentSketchFile = scriptFile.getAbsolutePath(); if (script != null) { processingEditor.setText(script); saveCurrentSketchToOptions(); } } catch (Exception e) { e.printStackTrace(); WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Exception '" + e.getMessage() + "' occurred while restoring Processing sketch from file '" + scriptFile.getName() + "'.", "Can't restore R script", WandoraOptionPane.INFORMATION_MESSAGE); } } }
From source file:org.wandora.application.gui.topicpanels.RTopicPanel.java
private void autoRunFileBrowseButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_autoRunFileBrowseButtonMouseReleased fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setDialogTitle("Select R Script"); int answer = fc.showDialog(Wandora.getWandora(), "Select"); if (answer == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f != null) { autoRunFileTextField.setText(f.getAbsolutePath()); autoRunFileRadioButton.setSelected(true); }//from w w w .j ava 2s . co m } }
From source file:org.wandora.application.gui.topicpanels.RTopicPanel.java
private void loadScriptFromFile() { fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setDialogTitle("Open R Script"); int answer = fc.showDialog(Wandora.getWandora(), "Open"); if (answer == SimpleFileChooser.APPROVE_OPTION) { File scriptFile = fc.getSelectedFile(); try {//from w ww . j a v a 2 s . co m String script = IObox.loadFile(scriptFile); currentScriptFile = scriptFile.getAbsolutePath(); if (script != null) { rEditor.setText(script); } } catch (Exception e) { e.printStackTrace(); WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Exception '" + e.getMessage() + "' occurred while restoring R script from file '" + scriptFile.getName() + "'.", "Can't restore R script", WandoraOptionPane.INFORMATION_MESSAGE); } } }
From source file:pcgen.gui2.converter.panel.WriteDirectoryPanel.java
@Override public void setupDisplay(JPanel panel, final CDOMObject pc) { panel.setLayout(layout);/*from ww w.jav a2 s .co m*/ Component label = new JLabel("Please select the Directory where Converted files should be written: "); AbstractButton button = new JButton("Browse..."); button.setMnemonic('r'); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(path.getParentFile()); chooser.setSelectedFile(path); while (true) { int open = chooser.showOpenDialog(null); if (open == JFileChooser.APPROVE_OPTION) { File fileToOpen = chooser.getSelectedFile(); if (fileToOpen.isDirectory() && fileToOpen.canRead() && fileToOpen.canWrite()) { path = fileToOpen; pc.put(ObjectKey.WRITE_DIRECTORY, path); fileLabel.setText(path.getAbsolutePath()); PCGenSettings context = PCGenSettings.getInstance(); context.setProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, path.getAbsolutePath()); showWarning(); break; } JOptionPane.showMessageDialog(null, "Selection must be a valid " + "(readable & writeable) Directory"); chooser.setCurrentDirectory(path.getParentFile()); } else if (open == JFileChooser.CANCEL_OPTION) { break; } } } }); panel.add(label); panel.add(fileLabel); panel.add(button); panel.add(warningLabel); showWarning(); layout.putConstraint(SpringLayout.NORTH, label, 50, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.NORTH, fileLabel, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.NORTH, button, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.WEST, label, 25, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.WEST, fileLabel, 25, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.EAST, button, -50, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.NORTH, warningLabel, 20, SpringLayout.SOUTH, fileLabel); layout.putConstraint(SpringLayout.WEST, warningLabel, 25, SpringLayout.WEST, panel); fileLabel.setText(path.getAbsolutePath()); }