List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:table.FrequencyTablePanel.java
public String doSaveAs(File f) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter);//from w w w. jav a 2 s .c o m String filename = ""; int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (!filename.endsWith(".png")) { filename = filename + ".png"; } saveTableAsPNG(new File(filename), this.table, getWidth(), getHeight()); } return filename; }
From source file:com.genericworkflownodes.knime.nodes.io.OutputFileNodeDialog.java
/** * New pane for configuring MimeFileExporter node dialog. *//* ww w . j av a 2 s . 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:task5.deneme.java
private void btn_chooseImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_chooseImageActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop"); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try {/*www . ja va 2 s .c o m*/ img = ImageIO.read(selectedFile); getRGBs(); } catch (IOException ex) { Logger.getLogger(deneme.class.getName()).log(Level.SEVERE, null, ex); } } r = red.toArray(); g = green.toArray(); b = blue.toArray(); // // if(red.indexOf(0)==-1 || red.indexOf(255)==-1){ // red.sort(null); // System.out.println("Before Streching... Min and Max Value..." ); // System.out.println(red.get(0)+" "+red.get(red.size()-1)); // contrastR= red.get(red.size()-1)- red.get(0); // int fmin=red.get(0); // int fmax=red.get(red.size()-1); // for (int i = 0; i < red.size(); i++) { // int temp2=0; // if(((int)r[i])<=fmin) // temp2=0; // else if(fmin<=((int)r[i]) && ((int)r[i])<= fmax){ // double temp=((((int)r[i])- fmin)/(contrastR)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)r[i])>=fmax){ // temp2=255; // } // r[i]=temp2; // } // ArrayList<Integer> tempp = new ArrayList<>(); // for (Object r1 : r) { // tempp.add((int) r1); // } // tempp.sort(null); // System.out.println("After Stretching... Min and Max Value..."); // System.out.println(tempp.get(0) + " " + tempp.get(tempp.size() - 1)); // } // // // // // // if(green.indexOf(0)==-1 || green.indexOf(255)==-1){ // green.sort(null); // contrastG= green.get(green.size()-1)- green.get(0); // int fmin=green.get(0); // int fmax=green.get(green.size()-1); // for (int i = 0; i < green.size(); i++) { // int temp2=0; // if(((int)g[i])<=fmin) // temp2=0; // else if(fmin<=((int)g[i]) && ((int)g[i])<= fmax){ // double temp=((((int)g[i])- fmin)/(contrastG)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)g[i])>=fmax){ // temp2=255; // } // g[i]=temp2; // } // } // if(blue.indexOf(0)==-1 || blue.indexOf(255)==-1){ // blue.sort(null); // contrastB= blue.get(blue.size()-1)- blue.get(0); // int fmin=blue.get(0); // int fmax=blue.get(blue.size()-1); // for (int i = 0; i < blue.size(); i++) { // int temp2=0; // if(((int)b[i])<=fmin) // temp2=0; // else if(fmin<=((int)b[i]) && ((int)b[i])<= fmax){ // double temp=((((int)b[i])- fmin)/(contrastB)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)b[i])>=fmax){ // temp2=255; // } // b[i]=temp2; // } // } display(); }
From source file:com.johnson3yo.dubem.plugin.ArtifactWizardMojo.java
private void updateAppServletXml_JFileChooser(String functionName) throws IOException, JDOMException { getLog().info("please select app-servlet.xml from foundation-guiwar "); JFileChooser fc = new JFileChooser(); int retValue = fc.showOpenDialog(new JPanel()); if (retValue == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(f); Element rootNode = document.getRootElement(); List<Element> list = rootNode.getChildren("component-scan", Namespace.getNamespace("http://www.springframework.org/schema/context")); Element e = list.get(0);//from w w w . jav a 2 s.c o m String cnt = "<context:exclude-filter type=\"regex\" expression=\"pegasus\\.module\\." + functionName.toLowerCase() + "\\..*\" />"; e.addContent(cnt); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()) { @Override public String escapeElementEntities(String str) { return str; } }; Writer writer = new OutputStreamWriter(new FileOutputStream(f), "utf-8"); outputter.output(document, writer); writer.close(); } else { getLog().info("Next time select a file."); System.exit(1); } }
From source file:net.menthor.editor.v2.util.Util.java
public static File chooseFile(Component parent, String lastPath, String dialogTitle, String fileDescription, String fileExtension, String fileExtension2, boolean checkOverrideFile) throws IOException { JFileChooser fileChooser = createChooser(lastPath, checkOverrideFile); fileChooser.setDialogTitle(dialogTitle); FileNameExtensionFilter filter = new FileNameExtensionFilter(fileDescription, fileExtension, fileExtension2);/* w w w .j av a 2s .c om*/ fileChooser.addChoosableFileFilter(filter); if (SystemUtil.onWindows()) fileChooser.setFileFilter(filter); fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showDialog(parent, "Ok") == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (!(file.getName().endsWith("." + fileExtension)) && !(file.getName().endsWith("." + fileExtension2))) { file = new File(file.getCanonicalFile() + "." + fileExtension2); } else { file = new File(file.getCanonicalFile() + ""); } return file; } else { return null; } }
From source file:BeanContainer.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); //w w w . j ava2 s . com JMenu mFile = new JMenu("File"); JMenuItem mItem = new JMenuItem("New..."); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { Thread newthread = new Thread() { public void run() { String result = (String)JOptionPane.showInputDialog( BeanContainer.this, "Please enter class name to create a new bean", "Input", JOptionPane.INFORMATION_MESSAGE, null, null, m_className); repaint(); if (result==null) return; try { m_className = result; Class cls = Class.forName(result); Object obj = cls.newInstance(); if (obj instanceof Component) { m_activeBean = (Component)obj; m_activeBean.addFocusListener( BeanContainer.this); m_activeBean.requestFocus(); getContentPane().add(m_activeBean); } validate(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( BeanContainer.this, "Error: "+ex.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } } }; newthread.start(); } }; mItem.addActionListener(lst); mFile.add(mItem); mItem = new JMenuItem("Load..."); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { Thread newthread = new Thread() { public void run() { m_chooser.setCurrentDirectory(m_currentDir); m_chooser.setDialogTitle( "Please select file with serialized bean"); int result = m_chooser.showOpenDialog( BeanContainer.this); repaint(); if (result != JFileChooser.APPROVE_OPTION) return; m_currentDir = m_chooser.getCurrentDirectory(); File fChoosen = m_chooser.getSelectedFile(); try { FileInputStream fStream = new FileInputStream(fChoosen); ObjectInput stream = new ObjectInputStream(fStream); Object obj = stream.readObject(); if (obj instanceof Component) { m_activeBean = (Component)obj; m_activeBean.addFocusListener( BeanContainer.this); m_activeBean.requestFocus(); getContentPane().add(m_activeBean); } stream.close(); fStream.close(); validate(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( BeanContainer.this, "Error: "+ex.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } repaint(); } }; newthread.start(); } }; mItem.addActionListener(lst); mFile.add(mItem); mItem = new JMenuItem("Save..."); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { Thread newthread = new Thread() { public void run() { if (m_activeBean == null) return; m_chooser.setDialogTitle( "Please choose file to serialize bean"); m_chooser.setCurrentDirectory(m_currentDir); int result = m_chooser.showSaveDialog( BeanContainer.this); repaint(); if (result != JFileChooser.APPROVE_OPTION) return; m_currentDir = m_chooser.getCurrentDirectory(); File fChoosen = m_chooser.getSelectedFile(); try { FileOutputStream fStream = new FileOutputStream(fChoosen); ObjectOutput stream = new ObjectOutputStream(fStream); stream.writeObject(m_activeBean); stream.close(); fStream.close(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( BeanContainer.this, "Error: "+ex.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } } }; newthread.start(); } }; mItem.addActionListener(lst); mFile.add(mItem); mFile.addSeparator(); mItem = new JMenuItem("Exit"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; mItem.addActionListener(lst); mFile.add(mItem); menuBar.add(mFile); JMenu mEdit = new JMenu("Edit"); mItem = new JMenuItem("Delete"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_activeBean == null) return; Object obj = m_editors.get(m_activeBean); if (obj != null) { BeanEditor editor = (BeanEditor)obj; editor.dispose(); m_editors.remove(m_activeBean); } getContentPane().remove(m_activeBean); m_activeBean = null; validate(); repaint(); } }; mItem.addActionListener(lst); mEdit.add(mItem); mItem = new JMenuItem("Properties..."); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_activeBean == null) return; Object obj = m_editors.get(m_activeBean); if (obj != null) { BeanEditor editor = (BeanEditor)obj; editor.setVisible(true); editor.toFront(); } else { BeanEditor editor = new BeanEditor(m_activeBean); m_editors.put(m_activeBean, editor); } } }; mItem.addActionListener(lst); mEdit.add(mItem); menuBar.add(mEdit); JMenu mLayout = new JMenu("Layout"); ButtonGroup group = new ButtonGroup(); mItem = new JRadioButtonMenuItem("FlowLayout"); mItem.setSelected(true); lst = new ActionListener() { public void actionPerformed(ActionEvent e){ getContentPane().setLayout(new FlowLayout()); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("GridLayout"); lst = new ActionListener() { public void actionPerformed(ActionEvent e){ int col = 3; int row = (int)Math.ceil(getContentPane(). getComponentCount()/(double)col); getContentPane().setLayout(new GridLayout(row, col, 10, 10)); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("BoxLayout - X"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new BoxLayout( getContentPane(), BoxLayout.X_AXIS)); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("BoxLayout - Y"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new BoxLayout( getContentPane(), BoxLayout.Y_AXIS)); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("DialogLayout"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new DialogLayout()); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); menuBar.add(mLayout); return menuBar; }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public void openPDF(boolean isInternalR, File pdf, Component comp) throws FileNotFoundException { if (isInternalR) { try {/* w w w . j av a 2 s . co m*/ Desktop.getDesktop().open(pdf); } catch (Exception ex) { log.info(ex.getMessage()); String msg = "Unable to open PDF format through java. Would you like to save " + pdf.getAbsoluteFile() + " in a new location?"; JOptionPane pane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, null, JOptionPane.YES_OPTION); JDialog dialog = pane.createDialog(comp, "Report PDF"); dialog.setVisible(true); Object choice = pane.getValue(); if (choice.equals(JOptionPane.YES_OPTION)) { jfcFiles = new JFileChooser(); jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int state = jfcFiles.showSaveDialog(comp); if (state == JFileChooser.APPROVE_OPTION) { File file = checkFileExtension(".pdf"); log.info("Opening: " + file.getName() + "."); if (file != null) pdf.renameTo(file); } else { log.info("Open command cancelled by user."); } } } } }
From source file:aurelienribon.gdxsetupui.ui.panels.ConfigUpdatePanel.java
private void browse() { String path = Ctx.cfgUpdate.destinationPath; JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this); JFileChooser chooser = new JFileChooser(new File(path)); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select the core project folder"); if (chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { pathField.setText(chooser.getSelectedFile().getPath()); updateConfig(chooser.getSelectedFile()); updatePanel();/* ww w. j a v a2 s . com*/ } }
From source file:fll.scheduler.ChooseChallengeDescriptor.java
private void initComponents() { getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1;/* ww w . j a va 2s. c o m*/ gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; final JTextArea instructions = new JTextArea( "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.", 3, 40); instructions.setEditable(false); instructions.setWrapStyleWord(true); instructions.setLineWrap(true); getContentPane().add(instructions, gbc); gbc = new GridBagConstraints(); mCombo = new JComboBox<DescriptionInfo>(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(mCombo, gbc); mCombo.setRenderer(new DescriptionInfoRenderer()); mCombo.setEditable(false); final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo(); for (final DescriptionInfo info : descriptions) { mCombo.addItem(info); } mFileField = new JLabel(); gbc = new GridBagConstraints(); gbc.weightx = 1; getContentPane().add(mFileField, gbc); final JButton chooseButton = new JButton("Choose File"); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(chooseButton, gbc); chooseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mFileField.setText(null); final JFileChooser fileChooser = new JFileChooser(); final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" }); fileChooser.setFileFilter(filter); final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File selectedFile = fileChooser.getSelectedFile(); mFileField.setText(selectedFile.getAbsolutePath()); } } }); final Box buttonPanel = new Box(BoxLayout.X_AXIS); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(buttonPanel, gbc); buttonPanel.add(Box.createHorizontalGlue()); final JButton ok = new JButton("Ok"); buttonPanel.add(ok); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { // use the selected description if nothing is entered in the file box final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex()); if (null != descriptionInfo) { mSelected = descriptionInfo.getURL(); } final String text = mFileField.getText(); if (!StringUtils.isEmpty(text)) { final File file = new File(text); if (file.exists()) { try { mSelected = file.toURI().toURL(); } catch (final MalformedURLException e) { throw new FLLInternalException("Can't turn file into URL?", e); } } } setVisible(false); } }); final JButton cancel = new JButton("Cancel"); buttonPanel.add(cancel); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mSelected = null; setVisible(false); } }); pack(); }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected File promptUserForNewFile(String wavePath) { JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP3s and WAVs", "mp3", "wav"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);//ww w . ja v a 2 s . c o m chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { DefaultMutableTreeNode selectedFile = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); //Strip caps and spaces out of filenames. The item sound parser seems to have trouble with them. String destFileName = chosenFile.getFileName().toString().toLowerCase().replace(" ", "_"); Path destPath = Paths.get(installDir, "/dota/sound/" + getCustomSoundPathString() + destFileName); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); String waveString = selectedFile.getUserObject().toString(); int startIndex = -1; int endIndex = -1; if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); waveString = waveString.replace(waveStringFilePath, "\"" + getCustomSoundPathString() + destFileName + "\""); selectedFile.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }