List of usage examples for javax.swing JFileChooser FILES_ONLY
int FILES_ONLY
To view the source code for javax.swing JFileChooser FILES_ONLY.
Click Source Link
From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java
protected void browseFile(JTextField dirField) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String selectedFilePath = selectedFile.getAbsolutePath(); dirField.setText(selectedFilePath); }/*from ww w. ja v a 2 s . c om*/ }
From source file:org.pgptool.gui.ui.tools.browsefs.ExistingFileChooserDialog.java
private JFileChooser buildFileChooserDialog() { JFileChooser ofd = new JFileChooser(); ofd.setFileSelectionMode(JFileChooser.FILES_ONLY); ofd.setAcceptAllFileFilterUsed(true); ofd.setMultiSelectionEnabled(false); ofd.setDialogTitle(Messages.get("action.chooseExistingFile")); ofd.setApproveButtonText(Messages.get("action.choose")); suggestInitialDirectory(ofd);//from w ww . j a va 2s . c o m doFileChooserPostConstruct(ofd); return ofd; }
From source file:edu.umich.robot.ViewerApplication.java
private Config promptForConfig() { JFileChooser fc = new JFileChooser("config"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt"); fc.setFileFilter(filter);/*from w w w. j a va 2s . co m*/ fc.setMultiSelectionEnabled(false); int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { try { return new ConfigFile(fc.getSelectedFile().getAbsolutePath()); } catch (IOException e) { logger.error(e.getMessage()); } } return null; }
From source file:org.pgptool.gui.ui.tools.browsefs.MultipleFilesChooserDialog.java
private JFileChooser buildFileChooserDialog() { JFileChooser ofd = new JFileChooser(); ofd.setFileSelectionMode(JFileChooser.FILES_ONLY); ofd.setAcceptAllFileFilterUsed(true); ofd.setMultiSelectionEnabled(true);//from w w w . j a v a2 s. c om ofd.setDialogTitle(Messages.get("action.chooseExistingFile")); ofd.setApproveButtonText(Messages.get("action.choose")); suggestInitialDirectory(ofd); doFileChooserPostConstruct(ofd); return ofd; }
From source file:com.bwc.ora.OraUtils.java
public static File selectFile(boolean openDialog, Component parent, int selectorType, String selectDescription, String extensionDescription, String... extentions) { File prevLocation = fc.getSelectedFile() != null ? fc.getSelectedFile().getParentFile() : null; fc = new JFileChooser(prevLocation); fc.setMultiSelectionEnabled(false);/*w ww . j a va 2s .c o m*/ fc.setFileSelectionMode(selectorType); if (selectorType == JFileChooser.FILES_ONLY) { fc.setFileFilter(new FileNameExtensionFilter(extensionDescription, extentions)); } fc.setAcceptAllFileFilterUsed(false); fc.setApproveButtonText("Select"); fc.setDialogTitle("Select " + selectDescription + "..."); int returnVal = openDialog ? fc.showOpenDialog(parent) : fc.showSaveDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { if (selectorType == JFileChooser.FILES_ONLY) { System.out.println("pwd: " + fc.getCurrentDirectory()); return openDialog ? loadFile(fc.getSelectedFile()) : fc.getSelectedFile(); } else if (selectorType == JFileChooser.DIRECTORIES_ONLY) { return loadDir(fc.getSelectedFile()); } else { throw new IllegalArgumentException( "Can't handle loading of files or directories at the same time!"); } } else { return null; } }
From source file:org.pgptool.gui.ui.tools.browsefs.SaveFileChooserDialog.java
private JFileChooser prepareFileChooser() { JFileChooser ofd = new JFileChooser(); ofd.setFileSelectionMode(JFileChooser.FILES_ONLY); ofd.setMultiSelectionEnabled(false); ofd.setDialogTitle(Messages.get(dialogTitleCode)); ofd.setApproveButtonText(Messages.get(approvalButtonTextCode)); onFileChooserPostConstrct(ofd);//from w ww . j av a2s .c o m suggestTarget(ofd); return ofd; }
From source file:com.genericworkflownodes.knime.nodes.io.OutputFileNodeDialog.java
/** * New pane for configuring MimeFileExporter node dialog. */// w ww.jav a 2s .c o m public OutputFileNodeDialog(final String settingsName) { this.settingsName = settingsName; dialogPanel = new JPanel(); componentContainer = new JPanel(); textField = new JTextField(); textField.setPreferredSize(new Dimension(300, textField.getPreferredSize().height)); searchButton = new JButton("Browse"); searchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser jfc = new JFileChooser(); if (!"".equals(textField.getText().trim()) && new File(textField.getText().trim()).getParent() != null) { jfc.setCurrentDirectory(new File(textField.getText().trim()).getParentFile()); } jfc.setAcceptAllFileFilterUsed(false); jfc.setFileFilter(extensionFilter); // int returnVal = jfc.showSaveDialog(dialogPanel); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = jfc.showDialog(dialogPanel, "Select output file"); if (returnVal == JFileChooser.APPROVE_OPTION) { // validate extension if (!extensionFilter.accept(jfc.getSelectedFile())) { String message = "The selected output file has an invalid file extension.\n"; if (extensionFilter.getExtensions().length == 1) { message += "Please choose a file with extension: " + extensionFilter.getExtensions()[0]; } else { message += "Please choose a file with on of the following extensions: "; message += StringUtils.join(extensionFilter.getExtensions(), ", "); } JOptionPane.showMessageDialog(getPanel(), message, "Selected Output File is invalid.", JOptionPane.WARNING_MESSAGE); } textField.setText(jfc.getSelectedFile().getAbsolutePath()); } } }); setLayout(); addComponents(); addTab("Choose File", dialogPanel); }
From source file:de.fionera.javamailer.gui.mainView.controllerMain.java
/** * Adds the Actionlisteners to the Mainview * * @param viewMain The Mainview//from w w w.j a v a 2s .c o m */ private void addActionListener(viewMain viewMain) { /** * Changes the Amount in the AmountLabel when the slider is moved */ viewMain.getSetMailSettingsPanel().getSliderAmountMails().addChangeListener(e -> { Main.amountMails = ((JSlider) e.getSource()).getValue(); viewMain.getSetMailSettingsPanel().getLabelNumberAmountMails() .setText("" + ((JSlider) e.getSource()).getValue()); }); /** * Changes the Delay in the DelayLabel when the slider is moved */ viewMain.getSetMailSettingsPanel().getSliderDelayMails().addChangeListener(e -> { Main.delayMails = ((JSlider) e.getSource()).getValue(); viewMain.getSetMailSettingsPanel().getLabelNumberDelayMails() .setText("" + ((JSlider) e.getSource()).getValue()); }); /** * Closes the Program, when close is clicked */ viewMain.getCloseItem().addActionListener(e -> System.exit(0)); /** * Opens the Settings when the settingsbutton is clicked */ viewMain.getSettingsItem().addActionListener(e -> new controllerSettings()); /** * Save current Setup */ viewMain.getSaveSettings().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); JFrame parentFrame = new JFrame(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub"); jChooser.setFileFilter(filter); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.setDialogTitle("Select Setup"); int userSelection = jChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(jChooser.getSelectedFile() + ".jms"); saveSetup(viewMain, fileToSave, new ObjectMapper()); } }); /** * Load Setup */ viewMain.getLoadSettings().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub"); jChooser.setFileFilter(filter); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.setDialogTitle("Select Setup"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { if (file.getName().endsWith("jms")) { try { loadSetup(viewMain, file, new ObjectMapper()); } catch (Exception error) { error.printStackTrace(); } } } }); /** * Opens the Open File dialog and start the Parsing of it */ viewMain.getSelectRecipientsPanel().getSelectExcelFileButton().addActionListener(e -> { DefaultTableModel model; JFileChooser jChooser = new JFileChooser(); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel 97 - 2003 (.xls)", "xls")); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel (.xlsx)", "xlsx")); jChooser.setDialogTitle("Select only Excel workbooks"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { parseFilesForImport parseFilesForImport = new parseFilesForImport(); if (file.getName().endsWith("xls")) { ArrayList returnedData = parseFilesForImport.parseXLSFile(file); model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1)); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable() .setPreferredSize(new Dimension(tableWidth, tableHeight)); } else if (file.getName().endsWith("xlsx")) { ArrayList returnedData = parseFilesForImport.parseXLSXFile(file); model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1)); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable() .setPreferredSize(new Dimension(tableWidth, tableHeight)); } else { JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error", JOptionPane.ERROR_MESSAGE); model = new DefaultTableModel(); } } else { model = new DefaultTableModel(); } viewMain.getSelectRecipientsPanel().getTable().setModel(model); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable().setPreferredSize(new Dimension(tableWidth, tableHeight)); viewMain.getCheckAllSettings().getLabelRecipientsAmount().setText("" + model.getRowCount()); viewMain.getCheckAllSettings().getLabelTimeAmount() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue() * viewMain.getSelectRecipientsPanel().getTable().getRowCount() / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue() + " Seconds"); }); /** * Starts the sending of th Mails, when the send button is clicked */ viewMain.getCheckAllSettings().getSendMails().addActionListener(e -> { String subject = viewMain.getSetMailSettingsPanel().getFieldSubject().getText(); Sender sender = (Sender) viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem(); JTable table = viewMain.getSelectRecipientsPanel().getTable(); if (table != null && sender != null && !subject.equals("")) { new sendMails(viewMain); } }); /** * Clears the Table on buttonclick */ viewMain.getSelectRecipientsPanel().getClearTableButton().addActionListener(e -> { viewMain.getSelectRecipientsPanel().getTable().setModel(new DefaultTableModel()); viewMain.getSelectRecipientsPanel().getTable().setBackground(null); }); /** * Removes a single Row on menu click in the editMailPanel */ viewMain.getSelectRecipientsPanel().getDeleteRow().addActionListener(e -> { ((DefaultTableModel) viewMain.getSelectRecipientsPanel().getTable().getModel()) .removeRow(viewMain.getSelectRecipientsPanel().getTable().getSelectedRowCount()); viewMain.getSelectRecipientsPanel().getTable().setBackground(null); }); /** * The Changes the displayed Value when the Time in the Timespinner is getting changed. */ viewMain.getSetMailSettingsPanel().getTimeSpinner().addChangeListener(e -> { parseDate.parseDate(viewMain); viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, " + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining"); viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString()); viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate()); }); viewMain.getSetMailSettingsPanel().getDatePicker().addActionListener(e -> { parseDate.parseDate(viewMain); viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, " + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining"); viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString()); viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate()); }); /** * Actionevent for the Edit Sender Button */ viewMain.getSetMailSettingsPanel().getButtonEditSender() .addActionListener(e -> new controllerEditSender(controllerMain)); /** * Actionevent for the Import Button in the EditMail View */ viewMain.getEditMailPanel().getImportWord().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Word 97 - 2003 (.doc)", "doc")); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("HTML File (.html)", "html")); jChooser.setDialogTitle("Select only Word Documents"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { parseFilesForImport parseFilesForImport = new parseFilesForImport(); if (file.getName().endsWith("doc")) { String returnedData = parseFilesForImport.parseDOCFile(file); viewMain.getEditMailPanel().setEditorText(returnedData); } else if (file.getName().endsWith("html")) { String content = ""; try { content = Jsoup.parse(file, "UTF-8").toString(); } catch (IOException e1) { e1.printStackTrace(); } viewMain.getEditMailPanel().setEditorText(content); } else { JOptionPane.showMessageDialog(null, "Please select a Document file.", "Error", JOptionPane.ERROR_MESSAGE); } } }); /** * The Tab Changelistener * The first if Statement sets the Labels on the Checkallsettings Panel to the right Values */ viewMain.getTabbedPane().addChangeListener(e -> { if (viewMain.getTabbedPane().getSelectedComponent() == viewMain.getCheckAllSettings()) { viewMain.getCheckAllSettings().getLabelMailBelow() .setText(viewMain.getEditMailPanel().getEditorText()); //Displays the Mail viewMain.getCheckAllSettings().getLabelRecipientsAmount() .setText("" + viewMain.getSelectRecipientsPanel().getTable().getModel().getRowCount()); //Displays the Amount of Recipients if (viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem() != null) { viewMain.getCheckAllSettings().getLabelFromInserted().setText( viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem().toString()); } else { viewMain.getCheckAllSettings().getLabelFromInserted().setText("Select a Sender first"); } viewMain.getCheckAllSettings().getLabelSubjectInserted() .setText(viewMain.getSetMailSettingsPanel().getFieldSubject().getText()); //Displays the Subject if (viewMain.getSetMailSettingsPanel().getCheckBoxDelayMails().isSelected()) { viewMain.getCheckAllSettings().getLabelDelay().setVisible(true); viewMain.getCheckAllSettings().getLabelAmount().setVisible(true); viewMain.getCheckAllSettings().getLabelTime().setVisible(true); viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(true); viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(true); viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(true); viewMain.getCheckAllSettings().getLabelDelayNumber() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()); //The Delay Number viewMain.getCheckAllSettings().getLabelAmountNumber() .setText("" + viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()); //The Amount of Mail in one package viewMain.getCheckAllSettings().getLabelTimeAmount() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue() * viewMain.getSelectRecipientsPanel().getTable().getRowCount() / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue() + " Seconds"); //The Time the Sending needs } else { viewMain.getCheckAllSettings().getLabelDelay().setVisible(false); viewMain.getCheckAllSettings().getLabelAmount().setVisible(false); viewMain.getCheckAllSettings().getLabelTime().setVisible(false); viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(false); viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(false); viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(false); } if (viewMain.getSetMailSettingsPanel().getCheckBoxSendLater().isSelected()) { viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(true); viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(true); viewMain.getCheckAllSettings().getLabelSendingAt() .setText(viewMain.getSetMailSettingsPanel().getDate().toString()); } else { viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(false); viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(false); } } }); }
From source file:org.jax.maanova.plot.SaveChartAction.java
/** * {@inheritDoc}// w w w . ja v a 2s.c o m */ public void actionPerformed(ActionEvent e) { JFreeChart myChart = this.chart; Dimension mySize = this.size; if (myChart == null || mySize == null) { LOG.severe("Failed to save graph image because of a null value"); MessageDialogUtilities.errorLater(Maanova.getInstance().getApplicationFrame(), "Internal error: Failed to save graph image.", "Image Save Failed"); } else { // use the remembered starting dir MaanovaApplicationConfigurationManager configurationManager = MaanovaApplicationConfigurationManager .getInstance(); JMaanovaApplicationState applicationState = configurationManager.getApplicationState(); FileType rememberedJaxbImageDir = applicationState.getRecentImageExportDirectory(); File rememberedImageDir = null; if (rememberedJaxbImageDir != null && rememberedJaxbImageDir.getFileName() != null) { rememberedImageDir = new File(rememberedJaxbImageDir.getFileName()); } // select the image file to save JFileChooser fileChooser = new JFileChooser(rememberedImageDir); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setApproveButtonText("Save Graph"); fileChooser.setDialogTitle("Save Graph as Image"); fileChooser.setMultiSelectionEnabled(false); fileChooser.addChoosableFileFilter(PngFileFilter.getInstance()); fileChooser.setFileFilter(PngFileFilter.getInstance()); int response = fileChooser.showSaveDialog(Maanova.getInstance().getApplicationFrame()); if (response == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); // tack on the extension if there isn't one // already if (!PngFileFilter.getInstance().accept(selectedFile)) { String newFileName = selectedFile.getName() + "." + PngFileFilter.PNG_EXTENSION; selectedFile = new File(selectedFile.getParentFile(), newFileName); } if (selectedFile.exists()) { // ask the user if they're sure they want to overwrite String message = "Exporting the graph image to " + selectedFile.getAbsolutePath() + " will overwrite an " + " existing file. Would you like to continue anyway?"; if (LOG.isLoggable(Level.FINE)) { LOG.fine(message); } boolean overwriteOk = MessageDialogUtilities .confirmOverwrite(Maanova.getInstance().getApplicationFrame(), selectedFile); if (!overwriteOk) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("overwrite canceled"); } return; } } try { ChartUtilities.saveChartAsPNG(selectedFile, myChart, mySize.width, mySize.height); File parentDir = selectedFile.getParentFile(); if (parentDir != null) { // update the "recent image directory" ObjectFactory objectFactory = new ObjectFactory(); FileType latestJaxbImageDir = objectFactory.createFileType(); latestJaxbImageDir.setFileName(parentDir.getAbsolutePath()); applicationState.setRecentImageExportDirectory(latestJaxbImageDir); } } catch (Exception ex) { LOG.log(Level.SEVERE, "failed to save graph image", ex); } } } }
From source file:com.mirth.connect.client.ui.AttachmentExportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }/*ww w . ja v a2s .c om*/ } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }