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:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * FileOpen Dialog/* ww w .j a v a2s .c om*/ * @param title * @param name * @param ext * @return */ private static String getFile(final String title, final String[] name, final String[] ext) { // User Chooses a Path and Name for the html Output File JFileChooser fc = new JFileChooser("."); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setDialogTitle(title); fc.setFileFilter(new FileFilter() { public String getDescription() { StringBuffer str = new StringBuffer(); for (String n : name) str.append(n + ""); return (str.toString()); } public boolean accept(File f) { for (String e : ext) if (f.isDirectory() || f.getName().toLowerCase().endsWith(e)) return (true); return false; } }); int state = fc.showOpenDialog(null); if (state == JFileChooser.APPROVE_OPTION) return (fc.getSelectedFile().getPath()); return (null); }
From source file:com.ficeto.esp.EspExceptionDecoder.java
private void createAndUpload() { if (!PreferencesData.get("target_platform").contentEquals("esp8266") && !PreferencesData.get("target_platform").contentEquals("esp32") && !PreferencesData.get("target_platform").contentEquals("ESP31B")) { System.err.println();//from w w w . j a v a 2 s . co m editor.statusError("Not Supported on " + PreferencesData.get("target_platform")); return; } String tc = "esp32"; if (PreferencesData.get("target_platform").contentEquals("esp8266")) { tc = "lx106"; } TargetPlatform platform = BaseNoGui.getTargetPlatform(); String gccPath = PreferencesData.get("runtime.tools.xtensa-" + tc + "-elf-gcc.path"); if (gccPath == null) { gccPath = platform.getFolder() + "/tools/xtensa-" + tc + "-elf"; } String addr2line; if (PreferencesData.get("runtime.os").contentEquals("windows")) addr2line = "xtensa-" + tc + "-elf-addr2line.exe"; else addr2line = "xtensa-" + tc + "-elf-addr2line"; tool = new File(gccPath + "/bin", addr2line); if (!tool.exists() || !tool.isFile()) { System.err.println(); editor.statusError("ERROR: " + addr2line + " not found!"); return; } elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".ino.elf"); if (!elf.exists() || !elf.isFile()) { elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".cpp.elf"); if (!elf.exists() || !elf.isFile()) { //lets give the user a chance to select the elf final JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new ElfFilter()); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showDialog(editor, "Select ELF"); if (returnVal == JFileChooser.APPROVE_OPTION) { elf = fc.getSelectedFile(); } else { editor.statusError("ERROR: elf was not found!"); System.err.println("Open command cancelled by user."); return; } } } JFrame.setDefaultLookAndFeelDecorated(true); frame = new JFrame("Exception Decoder"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); inputArea = new JTextArea("Paste your stack trace here", 16, 60); inputArea.setLineWrap(true); inputArea.setWrapStyleWord(true); inputArea.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "commit"); inputArea.getActionMap().put("commit", new CommitAction()); inputArea.getDocument().addDocumentListener(this); frame.getContentPane().add(new JScrollPane(inputArea), BorderLayout.PAGE_START); outputText = ""; outputArea = new JTextPane(); outputArea.setContentType("text/html"); outputArea.setEditable(false); outputArea.setBackground(null); outputArea.setBorder(null); outputArea.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); outputArea.setText(outputText); JScrollPane outputScrollPane = new JScrollPane(outputArea); outputScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); outputScrollPane.setPreferredSize(new Dimension(640, 200)); outputScrollPane.setMinimumSize(new Dimension(10, 10)); frame.getContentPane().add(outputScrollPane, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:fusion.Fusion.java
private static void setSameAsLinksFile() throws IOException { JFileChooser dialogue = new JFileChooser(new File(".")); File fichier;/*from w w w.j a v a 2s .c o m*/ if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { fichier = dialogue.getSelectedFile(); sameAsLinksFile = fichier.getPath(); } }
From source file:at.tuwien.ifs.feature.evaluation.SimilarityRetrievalGUI.java
private void initButtonSaveResults() { btnSaveResults = new JButton("Save as ..."); btnSaveResults.setEnabled(false); // can't save right away, need a first search btnSaveResults.addActionListener(new ActionListener() { @Override//from ww w. j a v a 2 s.com public void actionPerformed(ActionEvent e) { fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (fileChooser.getSelectedFile() != null) { // reusing the dialog fileChooser.setSelectedFile(null); } int returnVal = fileChooser.showDialog(SimilarityRetrievalGUI.this, "Save results to file ..."); if (returnVal == JFileChooser.APPROVE_OPTION) { try { PrintWriter w = FileUtils.openFileForWriting("Results file", fileChooser.getSelectedFile().getAbsolutePath()); TableModel model = resultsTable.getModel(); // column headers for (int col = 0; col < model.getColumnCount(); col++) { w.print(model.getColumnName(col) + "\t"); } w.println(); // write each data row for (int row = 0; row < model.getRowCount(); row++) { for (int col = 0; col < model.getColumnCount(); col++) { w.print(model.getValueAt(row, col) + "\t"); } w.println(); } w.flush(); w.close(); JOptionPane.showMessageDialog(SimilarityRetrievalGUI.this, "Successfully wrote to file " + fileChooser.getSelectedFile().getAbsolutePath(), "Results stored", JOptionPane.INFORMATION_MESSAGE); } catch (IOException e1) { e1.printStackTrace(); } } } }); }
From source file:firmadigital.Parametros.java
private void cmdExaminarAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarAlmacenActionPerformed JFileChooser fileChooser = new JFileChooser(); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getAbsolutePath(); txtUbicacionAlmacenCertificado.setText(selectedFile); }/*from w w w .j a va 2 s.c om*/ }
From source file:edu.mit.fss.examples.member.gui.CommSubsystemPanel.java
/** * Exports this panel's connectivity dataset. *//*from w ww. j ava2s .co m*/ private void exportDataset() { if (JFileChooser.APPROVE_OPTION == fileChooser.showSaveDialog(this)) { File f = fileChooser.getSelectedFile(); if (!f.exists() || JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Overwrite existing file " + f.getName() + "?", "File Exists", JOptionPane.YES_NO_OPTION)) { logger.info("Exporting dataset to file " + f.getPath() + "."); try { BufferedWriter bw = Files.newBufferedWriter(Paths.get(f.getPath()), Charset.defaultCharset()); StringBuilder b = new StringBuilder(); // synchronize on map for thread safety synchronized (connectSeriesMap) { for (Transmitter tx : connectSeriesMap.keySet()) { TimeSeries s = connectSeriesMap.get(tx); b.append(tx.getName()).append(" Connectivity\n").append("Time, Value\n"); for (int j = 0; j < s.getItemCount(); j++) { b.append(s.getTimePeriod(j).getStart().getTime()).append(", ").append(s.getValue(j)) .append("\n"); } } } bw.write(b.toString()); bw.close(); } catch (IOException e) { logger.error(e); } } } }
From source file:modnlp.capte.AlignmentInterfaceWS.java
public void actionPerformed(ActionEvent e) { //Handle open button action. if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(AlignmentInterfaceWS.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would open the file. sourceFile = file.getAbsolutePath(); log.append("Source File: " + sourceFile + "." + newline); } else {/*from ww w . j av a 2 s . c om*/ log.append("Open command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } //deleteSegment else if (e.getSource() == deleteSegment) { Object[] o; String ivalue; int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select at least one row"); JOptionPane.showMessageDialog(edit, "Please select at least one row"); } else { System.out.println("Deleting rows..."); for (int i = selected.length - 1; i > -1; i--) { em.removeRow(selected[i]); //update numbers System.out.println("Removed row " + selected[i]); } } //Table should update itself automatically } else if (e.getSource() == moveUp) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length > 1) { System.out.println("You can only move one segment at a time!"); JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!"); } else if (selected[0] == 0) { System.out.println("Can't move up anymore!"); JOptionPane.showMessageDialog(edit, "Can't move up anymore!"); } else { System.out.println("Moving " + selected[0]); em.moveSegmentUp(selected[0]); //Table should repaint } } else if (e.getSource() == moveDown) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length > 1) { System.out.println("You can only move one segment at a time!"); JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!"); } else if (selected[0] == em.getRowCount() - 1) { System.out.println("Can't move down anymore!"); JOptionPane.showMessageDialog(edit, "Can't move down anymore"); } else { System.out.println("Moving " + selected[0]); em.moveSegmentDown(selected[0]); //Table should repaint } } else if (e.getSource() == mergeSource) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 2 || selected.length > 2) { System.out.println("Please select two rows to merge "); JOptionPane.showMessageDialog(edit, "Please select two rows to merge"); } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) { System.out.println("Can only merge adjacent rows"); JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows"); } else { System.out.println("Merging source in rows " + selected[0] + " " + selected[1]); em.mergeSource(selected[0], selected[1]); } } else if (e.getSource() == mergeTarget) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 2 || selected.length > 2) { System.out.println("Please select two rows to merge "); JOptionPane.showMessageDialog(edit, "Please select two rows to merge"); } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) { System.out.println("Can only merge adjacent rows"); JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows"); } else { System.out.println("Merging target in " + selected[0] + " " + selected[1]); em.mergeTarget(selected[0], selected[1]); } } else if (e.getSource() == newSegment) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select a position to insert at:"); JOptionPane.showMessageDialog(edit, "Please select a position to insert at"); } else { System.out.println("Inserting new segment at " + (selected[0] + 1)); //insert empty string array Object[] sa = new Object[6]; sa[0] = ""; sa[1] = ""; sa[2] = "0.0"; sa[3] = new Boolean(false); sa[4] = "0"; sa[5] = em.getValueAt((selected[0]), 5) + "(+)"; em.insertRow(sa, (selected[0] + 1)); } } else if (e.getSource() == lockSelected) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select some rows to lock:"); JOptionPane.showMessageDialog(edit, "Please select some rows to lock:"); } else { //lock selected rows for (int i = 0; i < selected.length; i++) { em.lockRow(selected[i]); System.out.println("Locking row " + selected[i]); } } } else if (e.getSource() == unlockSelected) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select some rows to unlock:"); JOptionPane.showMessageDialog(edit, "Please select some rows to unlock:"); } else { //lock selected rows for (int i = 0; i < selected.length; i++) { em.unlockRow(selected[i]); System.out.println("Unlocking row " + selected[i]); } } } else if (e.getSource() == reAlign) { // if(true){ // JOptionPane.showMessageDialog(edit,"This feature is currently disabled"); // }else{ reNumber++; ExampleTableModel em = (ExampleTableModel) table.getModel(); // Get list of locked segments // Find lowest locked segment // Realign from lowest locked segment // Join the realigned bit back up with the locked bit // refresh the table int lowestlock = 0; Vector<Object[]> slice = new Vector<Object[]>(); Vector<Object[]> result = new Vector<Object[]>(); Vector<Object[]> locked = new Vector<Object[]>(); Boolean b = new Boolean(true); for (int i = 0; i < em.getRowCount(); i++) { b = (Boolean) em.getValueAt(i, 3); if (b.booleanValue() == true) { lowestlock = i; } } //get slice of table for realignment System.out.println("The lowest lock point is " + (lowestlock)); System.out.println("Realigning from row:" + (lowestlock + 1) + " to : " + em.getRowCount()); System.out.println("Total size of realign array =:" + (em.getRowCount() - (lowestlock))); //Get locked bits for (int h = 0; h < lowestlock + 1; h++) { locked.add(em.getRow(h)); } //Get bits to realign for (int j = lowestlock + 1; j < em.getRowCount(); j++) { slice.add(em.getRow(j)); } //flush em.flush(); for (int z = 0; z < locked.size(); z++) { em.insertRow(locked.get(z), z); } // System.out.println("Total size of array after bits removed = " + (em.getRowCount())); //get the directory where the source files came from File parent = new File(sourceFile).getParentFile(); String dir = parent.getAbsolutePath(); //create files File sf = null; File tf = null; try { sf = File.createTempFile("source", "tmp"); tf = File.createTempFile("target", "tmp"); } catch (IOException ef) { ef.printStackTrace(); } System.out.println("Writing temp file:" + sf.getName()); System.out.println("Writing temp file:" + tf.getName()); // File mf = new File("merged.tmp"); //get absolute paths String sourceF = sf.getAbsolutePath(); String targetF = tf.getAbsolutePath(); //String alignF = mf.getAbsolutePath(); //write out source and target to files //NEW write files to server and return string String alignment = ""; AlignerUtils.reWriteAlignment(targetF, sourceF, slice); try { alignment = AlignerUtils.MultiPartFileUpload(targetF, sourceF); } catch (IOException es) { es.printStackTrace(); } //convert the String to a Vector form result = AlignerUtils.StringToData(alignment, true, reNumber); // append the resultant file to the table //System.out.println("Total size of array before bits inserted = " + (em.getRowCount())); for (int y = 0, z = em.getRowCount(); y < result.size(); y++, z++) { em.insertRow(result.get(y), z); System.out.println("Inserting at position: " + z); System.out.println("Inserting from position: " + y); } // System.out.println("Total size of array after bits inserted = " + (em.getRowCount())); // } } else if (e.getSource() == saveButton) { int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would save the file. targetFile = file.getAbsolutePath(); log.append("Target File " + targetFile + "." + newline); } else { log.append("Save command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } else if (e.getSource() == export) { int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); outputFile = file.getAbsolutePath(); //aserver.writeAlignment(targetFile,data); AlignerUtils.writeAlignment(outputFile, data); log.append(newline + "Saving " + outputFile + "." + newline); } else { log.append("Save command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } else if (e.getSource() == alignButton) { if (sl.getText().length() >= 2 && tl.getText().length() >= 2) { log.append("Attempting to align texts"); sourcel = sl.getText(); targetl = tl.getText(); String aligned = ""; try { aligned = AlignerUtils.MultiPartFileUpload(sourceFile, targetFile); } catch (IOException ed) { ed.printStackTrace(); } //Convert string to alignment format data = AlignerUtils.StringToData(aligned, false, 0); int i = 0; // // AlreadyRun = true; if (i == 0) { //log.setCaretPosition(log.getDocument().getLength()); log.append("\nAutomatic alignment successful!"); log.append("\nOpening display window......"); //Set up the editor window JFrame edit = new JFrame("Alignment Editor"); cols = new Vector<String>(); cols.add("Source"); cols.add("Target"); cols.add("Score"); cols.add("Lock"); cols.add("Index"); cols.add("Orig"); System.out.println("Size of data array " + data.size()); System.out.println(data.get(0)[0]); ex = new ExampleTableModel(cols, data); //ex.addTableModelListener(this); table = new JTable(ex); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); TableColumnModel cmodel = table.getColumnModel(); cmodel.getColumn(0).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(1).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(2).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(4).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(5).setCellRenderer(new TextAreaRenderer()); TextAreaEditor textEditor = new TextAreaEditor(); textEditor.addCellEditorListener(this); cmodel.getColumn(0).setCellEditor(textEditor); cmodel.getColumn(1).setCellEditor(textEditor); cmodel.getColumn(2).setCellEditor(textEditor); cmodel.getColumn(4).setCellEditor(textEditor); cmodel.getColumn(5).setCellEditor(textEditor); mergeTarget = new JButton("Merge target"); mergeSource = new JButton("Merge source"); export = new JButton("Export to File"); newSegment = new JButton("Create New Segment"); deleteSegment = new JButton("Delete Selected"); moveUp = new JButton("Move Segment Up"); moveDown = new JButton("Move Segment Down"); lockSelected = new JButton("Lock Selected"); unlockSelected = new JButton("Unlock Selected"); reAlign = new JButton("Realign"); reAlign.addActionListener(this); lockSelected.addActionListener(this); unlockSelected.addActionListener(this); mergeSource.addActionListener(this); mergeTarget.addActionListener(this); export.addActionListener(this); newSegment.addActionListener(this); deleteSegment.addActionListener(this); moveUp.addActionListener(this); moveDown.addActionListener(this); JPanel control = new JPanel(); JPanel manipulate = new JPanel(); control.add(moveUp); control.add(moveDown); control.add(mergeTarget); control.add(mergeSource); //control.add(export); control.add(newSegment); control.add(deleteSegment); manipulate.add(reAlign); manipulate.add(lockSelected); manipulate.add(unlockSelected); manipulate.add(export); edit.add(control, BorderLayout.PAGE_START); edit.add(manipulate, BorderLayout.PAGE_END); JScrollPane scr = new JScrollPane(table); // JTable rowTable = new FirstRowNumberTable(table); //scr.add(table); //scr.setRowHeaderView(rowTable); //scr.setCorner(JScrollPane.UPPER_LEFT_CORNER, rowTable.getTableHeader()); scr.repaint(); edit.add(scr, BorderLayout.CENTER); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); edit.setSize(screenSize.width - 4, screenSize.height - 50); int totwidth = screenSize.width - 50; table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); cmodel.getColumn(0).setPreferredWidth((totwidth / 36) * 15); cmodel.getColumn(1).setPreferredWidth((totwidth / 36) * 15); cmodel.getColumn(2).setPreferredWidth(totwidth / 36 * 2); cmodel.getColumn(3).setPreferredWidth(totwidth / 36 * 2); cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2); cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2); edit.validate(); // Make sure layout is ok //edit.setSize(1024,700); edit.setVisible(true); } else { //log.setCaretPosition(log.getDocument().getLength()); log.append("\nAutomatic alignment unsuccessful..check error logs"); } } else { log.append("Please enter valid two letter language codes"); } log.setCaretPosition(log.getDocument().getLength()); } }
From source file:org.nekorp.workflow.desktop.view.EvidenciaEventoView.java
private void nuevaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevaActionPerformed try {//from ww w. jav a2 s .co m JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Imagen", "jpg", "jpeg", "png"); chooser.setFileFilter(filter); String homePath = System.getProperty("user.home"); File f = new File(new File(homePath).getCanonicalPath()); chooser.setSelectedFile(f); int returnVal = chooser.showOpenDialog(this.mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); BufferedImage img = ImageIO.read(chooser.getSelectedFile()); img = imageService.resizeToStandarSize(img); BufferedImage thumb = imageService.getThumbnail(img); EvidenciaVB nuevaEvidencia = new EvidenciaVB(); nuevaEvidencia.setImage(imageService.guardarImagen(img)); nuevaEvidencia.setThumbnail(imageService.guardarImagen(thumb)); ThumbnailView thumbview = new ThumbnailView(thumb, this); thumbview.setEditableStatus(editable); thumbs.add(thumbview); modelo.add(nuevaEvidencia); previewContent.add(thumbview); this.ignore.add(modelo); actualizaModelo(); selectEvent(thumbview); this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } } catch (IOException ex) { EvidenciaEventoView.LOGGER.error("Error al seleccionar archivo de imagen", ex); } }
From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java
/** * //from w ww .j a v a 2 s .com */ protected void saveScript(boolean saveAs) { if (local) { int showOpenDialog = loadChooser.showSaveDialog(ScriptFilterRunner.this); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { saveScript(loadChooser.getSelectedFile()); } } else { storeScript(saveAs); } }
From source file:EscribirCorreo.java
private void subir1FieldMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_subir1FieldMousePressed // TODO add your handling code here: // Buscar archivo para subir JFileChooser subir = new JFileChooser(); int opcion = subir.showOpenDialog(null); if (opcion == JFileChooser.APPROVE_OPTION) { archivo = subir.getSelectedFile().getPath(); nombre = subir.getSelectedFile().getName(); subir1Field.setText(archivo); }/* w w w . j a v a 2 s. c om*/ }