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:it.unibas.spicygui.controllo.mapping.ActionExportTranslatedInstancesCsv.java
@Override public void performAction() { Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); JFileChooser chooser = vista.getFileChooserSalvaFolder(); File file;// www.j a va 2s . c o m int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.EXPORT)); if (returnVal == JFileChooser.APPROVE_OPTION) { try { file = chooser.getSelectedFile(); DAOCsv daoCsv = new DAOCsv(); daoCsv.exportTranslatedCSVinstances(mappingTask, file.getAbsolutePath(), scenario.getNumber()); //giannisk canonical tree not needed ////daoCsv.exportCanonicalCSVinstances(mappingTask.getMappingData().getCanonicalSolution().getDataSource(), file.getAbsolutePath()); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK))); //StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK)); } catch (DAOException ex) { logger.error(ex); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); } } }
From source file:kindleclippings.quizlet.QuizletSync.java
private static Map<String, List<Clipping>> readClippingsFile() throws IOException { // try to find it File cl = new File("/Volumes/Kindle/documents/My Clippings.txt"); if (!cl.canRead()) { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileNameExtensionFilter("Kindle Clippings", "txt")); int result = fc.showOpenDialog(null); if (result != JFileChooser.APPROVE_OPTION) { return null; }// ww w. jav a 2 s . c om cl = fc.getSelectedFile(); } Reader f = new InputStreamReader(new FileInputStream(cl), "UTF-8"); try { MyClippingsReader r = new MyClippingsReader(f); Map<String, List<Clipping>> books = new TreeMap<String, List<Clipping>>(); Clipping l; while ((l = r.readClipping()) != null) { if (l.getType() != ClippingType.highlight && l.getType() != ClippingType.note) { System.err.println("ignored " + l.getType() + " [" + l.getBook() + "]"); continue; } String lct = l.getContent().trim(); if (lct.length() == 0) { System.err.println("ignored empty " + l.getType() + " [" + l.getBook() + "]"); continue; } if (lct.length() < 10 || !lct.contains(" ")) { System.err.println( "ignored too short " + l.getType() + " " + l.getContent() + " [" + l.getBook() + "]"); continue; } List<Clipping> clippings = books.get(l.getBook()); if (clippings == null) { clippings = new ArrayList<Clipping>(); books.put(l.getBook(), clippings); } clippings.add(l); } return books; } finally { f.close(); } }
From source file:presenter.MainPresenter.java
@Override public void saveEmissionsequenceToFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); if (fc.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try {//from ww w.ja va 2 s .c o m FileWriter fw = new FileWriter(file); fw.write(this.emissionsequenceModel.toString()); fw.flush(); fw.close(); this.displayStatus("File was written successfully!"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:com.smanempat.controller.ControllerClassification.java
public void chooseFile(ActionEvent evt, JTextField txtFileDirectory, JTextField txtNumberOfK, JLabel labelJumlahData, JButton buttonProses, JTable tablePreview) { try {/*from w ww . j a v a 2 s . co m*/ JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter fileNameExtensionFilter = new FileNameExtensionFilter("Excel File", "xls", "xlsx"); fileChooser.setFileFilter(fileNameExtensionFilter); if (fileChooser.showOpenDialog(fileChooser) == JFileChooser.APPROVE_OPTION) { txtFileDirectory.setText(fileChooser.getSelectedFile().getAbsolutePath()); System.out.println("Good, File Chooser runing well!"); if (txtFileDirectory.getText().endsWith(".xls") || txtFileDirectory.getText().endsWith(".xlsx")) { showOnTable(evt, txtFileDirectory, tablePreview); labelJumlahData.setText(tablePreview.getRowCount() + " Data"); txtNumberOfK.setEnabled(true); txtNumberOfK.requestFocus(); buttonProses.setEnabled(true); } else { JOptionPane.showMessageDialog(null, "File dataset harus file spreadsheet dengan ekstensi *xls atau *.xlsx!", "Error", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png")); txtFileDirectory.setText(""); chooseFile(evt, txtFileDirectory, txtNumberOfK, labelJumlahData, buttonProses, tablePreview); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:br.usp.poli.lta.cereda.macro.ui.Editor.java
/** * Construtor./*from www.j a va 2 s. c o m*/ */ public Editor() { // define as configuraes de exibio super("Expansor de macros"); setPreferredSize(new Dimension(550, 550)); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setResizable(false); setLayout(new MigLayout()); // cria os botes e suas respectivas aes open = new JButton("Abrir", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/open.png"))); save = new JButton("Salvar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/save.png"))); run = new JButton("Executar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/play.png"))); clear = new JButton("Limpar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/clear.png"))); // cria uma janela de dilogo para abrir e salvar arquivos de texto chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivos de texto", "txt", "text"); chooser.setFileFilter(filter); // ao de abertura de arquivo open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int value = chooser.showOpenDialog(Editor.this); if (value == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { String content = FileUtils.readFileToString(file); input.setText(content); output.setText(""); } catch (Exception e) { } } } }); // ao de salvamento de arquivo save.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int value = chooser.showSaveDialog(Editor.this); if (value == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { FileUtils.writeStringToFile(file, input.getText(), Charset.forName("UTF-8")); output.setText(""); } catch (Exception e) { } } } }); // ao de limpeza da janela de sada clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { output.setText(""); } }); // ao de execuo do expansor de macros run.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { output.setText(MacroExpander.parse(input.getText())); } catch (Exception exception) { String out = StringUtils.rightPad("ERRO: ", 50, "-").concat("\n"); out = out.concat(WordUtils.wrap(exception.getMessage(), 50)).concat("\n"); out = out.concat(StringUtils.repeat(".", 50)).concat("\n"); output.setText(out); } } }); // tela de entrada do texto input = new RSyntaxTextArea(14, 60); input.setCodeFoldingEnabled(true); input.setWrapStyleWord(true); input.setLineWrap(true); RTextScrollPane iinput = new RTextScrollPane(input); add(iinput, "span 4, wrap"); // adiciona os botes add(open); add(save); add(run); add(clear, "wrap"); // tela de sada da expanso output = new RSyntaxTextArea(14, 60); output.setEditable(false); output.setCodeFoldingEnabled(true); output.setWrapStyleWord(true); output.setLineWrap(true); RTextScrollPane ioutput = new RTextScrollPane(output); add(ioutput, "span 4"); // ajustes finais pack(); setLocationRelativeTo(null); }
From source file:components.FileChooserDemo2.java
public void actionPerformed(ActionEvent e) { //Set up the file chooser. if (fc == null) { fc = new JFileChooser(); //Add a custom file filter and disable the default //(Accept All) file filter. fc.addChoosableFileFilter(new ImageFilter()); fc.setAcceptAllFileFilterUsed(false); //Add custom icons for file types. fc.setFileView(new ImageFileView()); //Add the preview pane. fc.setAccessory(new ImagePreview(fc)); }//from w ww .jav a 2 s . co m //Show it. int returnVal = fc.showDialog(FileChooserDemo2.this, "Attach"); //Process the results. if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.append("Attaching file: " + file.getName() + "." + newline); } else { log.append("Attachment cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); //Reset the file chooser for the next time it's shown. fc.setSelectedFile(null); }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.SaveChartDialog.java
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == btnCancel) { // Cancel button pressed -> close the window this.setVisible(false); this.dispose(); } else if (source == btnSave) { // Save button pressed -> choose file name and save the chart int saveIt = saveFileDialog.showSaveDialog(this); if (saveIt == JFileChooser.APPROVE_OPTION) { // Choose file name File file = saveFileDialog.getSelectedFile(); int width = getChosenWidth(); int height = getChosenHeight(); ExtensionFileFilter filter = null; try { filter = (ExtensionFileFilter) saveFileDialog.getFileFilter(); if (!filter.hasExtension(file)) { file = filter.appendExtension(file); }//w ww . j a va 2s .c o m } catch (ClassCastException ex) { // Try to infer the type of file by its extension FileFilter[] filters = saveFileDialog.getChoosableFileFilters(); for (int i = 0; i < filters.length; ++i) { if (filters[i] instanceof ExtensionFileFilter) { filter = (ExtensionFileFilter) filters[i]; if (filter.hasExtension(file)) { break; } filter = null; } } if (filter == null) { // Could not infer the type Utils.showErrorBox(this, Messages.DT_IOERROR, Messages.SM_AMBIGUOUSFTYPE); return; } } // Save the chart to the specified file name try { if (Utils.canSave(file, this)) { String ext = filter.getExtension(); if (ext.equals("jpeg")) { JFreeChartConn.saveAsJpeg(file, chart, width, height); } else if (ext.equals("png")) { JFreeChartConn.saveAsPng(file, chart, width, height); } else { // ext.equals("svg") JFreeChartConn.saveAsSvg(file, chart, width, height); } } } catch (IOException ex) { Utils.showErrorBox(this, Messages.DT_IOERROR, Messages.SM_OERROR); return; } this.setVisible(false); this.dispose(); } else if (saveIt == JFileChooser.ERROR_OPTION) { Utils.showErrorBox(this, Messages.DT_GUIERROR, Messages.SM_GUIERROR); } } }
From source file:jmap2gml.ScriptGui.java
/** * Formats the window, initializes the JMap2Script object, and sets up all * the necessary events.//from w w w .j a v a2s .co m */ public ScriptGui() { setTitle("jmap to gml script converter"); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setLayout(new GridBagLayout()); this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent we) { } @Override public void windowClosing(WindowEvent we) { saveConfig(); } @Override public void windowClosed(WindowEvent we) { } @Override public void windowIconified(WindowEvent we) { } @Override public void windowDeiconified(WindowEvent we) { } @Override public void windowActivated(WindowEvent we) { } @Override public void windowDeactivated(WindowEvent we) { } }); GridBagConstraints c = new GridBagConstraints(); setResizable(true); setIconImage((new ImageIcon("spikeup.png")).getImage()); jta = new JTextArea(38, 30); loadConfig(); JScrollPane jsp = new JScrollPane(jta); jsp.setRowHeaderView(new TextLineNumber(jta)); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); jsp.setSize(jsp.getWidth(), 608); // menu bar JMenuBar menubar = new JMenuBar(); // file menu JMenu file = new JMenu("File"); // load button JMenuItem load = new JMenuItem("Load jmap"); load.addActionListener(ae -> { JFileChooser fileChooser = new JFileChooser(prevDirectory); fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap")); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); prevDirectory = selectedFile.getAbsolutePath(); jm2s = new ScriptFromJmap(selectedFile.getPath(), false); jta.setText(""); jta.append(jm2s.toString()); jta.setCaretPosition(0); writeFile.setEnabled(true); drawPanel.setItems(jta.getText().split("\n")); } }); // add load to file menu file.add(load); // button to save script to file writeFile = new JMenuItem("Write file"); writeFile.addActionListener(ae -> { if (jm2s != null) { PrintWriter out; try { File f = new File( jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml"); out = new PrintWriter(f); out.append(jm2s.toString()); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); writeFile.setEnabled(false); JMenuItem gmx = new JMenuItem("Export as gmx"); gmx.addActionListener(ae -> { String fn = String.format("%s.room.gmx", prevDirectory); JFileChooser fc = new JFileChooser(prevDirectory); fc.setSelectedFile(new File(fn)); fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx")); fc.showDialog(null, "Save"); File f = fc.getSelectedFile(); if (f != null) { try { GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f)); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); // add to file menu file.add(writeFile); file.add(gmx); // add file menu to the menubar menubar.add(file); // Edit menu // display menu JMenu display = new JMenu("Display"); JMenuItem update = new JMenuItem("Update"); update.addActionListener(ae -> { drawPanel.setItems(jta.getText().split("\n")); }); display.add(update); JMenuItem gridToggle = new JMenuItem("Toggle Grid"); gridToggle.addActionListener(ae -> { drawPanel.toggleGrid(); }); display.add(gridToggle); JMenuItem gridOptions = new JMenuItem("Modify Grid"); gridOptions.addActionListener(ae -> { drawPanel.modifyGrid(); }); display.add(gridOptions); menubar.add(display); // sets the menubar setJMenuBar(menubar); // add the text area to the window c.gridx = 0; c.gridy = 0; add(jsp, c); // initialize the preview panel drawPanel = new Preview(this); JScrollPane scrollPane = new JScrollPane(drawPanel); // add preview panel to the window c.gridx = 1; c.gridwidth = 2; add(scrollPane, c); pack(); setMinimumSize(this.getSize()); setLocationRelativeTo(null); setVisible(true); drawPanel.setItems(jta.getText().split("\n")); }
From source file:io.albraga.namus.OverlaypdfUI.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed int returnVal = jFileChooser1.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser1.getSelectedFile(); try {//from w w w. j a v a2 s . com } catch (Exception ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } } else { System.out.println("File access cancelled by user."); } }
From source file:TextFileHandler.java
public File[] openFiles(String title) { File[] result = null;//from w w w.j a v a2s . co m JFileChooser chooser = new JFileChooser(new File(".")); if (title != null) chooser.setDialogTitle(title); chooser.setMultiSelectionEnabled(true); int retVal = chooser.showOpenDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFiles(); } return result; }