List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:it.unibas.spicygui.controllo.tree.ActionExportQuery.java
public void actionPerformed(ActionEvent e) { this.executeInjection(); JFileChooser chooser = vista.getFileChooserSalvaFileGenerico(); File file;/*from w w w .ja va2s . co m*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.EXPORT)); if (returnVal == JFileChooser.APPROVE_OPTION) { FileWriter writer = null; try { file = chooser.getSelectedFile(); writer = new FileWriter(file); writer.write(this.textArea.getText()); writer.flush(); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(Costanti.class, Costanti.EXPORT_OK)); } catch (IOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } finally { try { writer.close(); } catch (IOException ex) { } } } }
From source file:graph.plotter.BarMenu.java
/** * This method works for choosing file path /*w w w .jav a2 s . c o m*/ */ private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed JFileChooser jf = new JFileChooser(); jf.showOpenDialog(null); File file = jf.getSelectedFile(); String f = file.getAbsolutePath(); jTextField3.setText(f); }
From source file:it.unibas.spicygui.controllo.spicy.ActionLoadComaCorrespondences.java
@Override public void performAction() { executeInjection();// w w w .j a v a2 s .c o m Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); if (mappingTask.getCandidateCorrespondences().size() != 0 && mappingTask.isToBeSaved()) { NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Confirmation( NbBundle.getMessage(Costanti.class, Costanti.DISCARD_CANDIDATE_CORRESPONDENCES), DialogDescriptor.YES_NO_OPTION); DialogDisplayer.getDefault().notify(notifyDescriptor); if (notifyDescriptor.getValue().equals(NotifyDescriptor.NO_OPTION) || notifyDescriptor.getValue().equals(NotifyDescriptor.CLOSED_OPTION)) { return; } } mappingTask.clearCandidateCorrespondences(); JFileChooser chooser = vista.getFileChooserApriTXT(); File file; int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); if (returnVal == JFileChooser.APPROVE_OPTION) { try { file = chooser.getSelectedFile(); String absoluteFile = file.getPath(); List<ValueCorrespondence> valueCorrespondences = dAOComaCorrespondences.loadComaCorrespondences( absoluteFile, mappingTask.getSourceProxy().getDataSource(), mappingTask.getTargetProxy().getDataSource()); mappingTask.setCandidateCorrespondences(valueCorrespondences); SpicyTopComponent spicyTopComponent = scenario .getSpicyTopComponent();/*SpicyTopComponent.findInstance();*/ if (spicyTopComponent.getJLayeredPane().isAnalizzato()) { spicyTopComponent.drawConnections(); } else { spicyTopComponent.drawScene(); } spicyTopComponent.resetSlider(); actionViewSpicy.performAction(); spicyTopComponent.creaSlider(); enableActions(); IOProvider.getDefault().getIO(Costanti.FLUSSO_SPICY, false).select(); if (logger.isDebugEnabled()) logger.debug("--------------Candidate correspondences---------------"); for (ValueCorrespondence correspondence : mappingTask.getCandidateCorrespondences()) { logger.info(correspondence); } return; } catch (DAOException ex) { DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } } }
From source file:com.itd.dbmrgdao.TestTime7.java
@Ignore @org.junit.Test//from w w w . j av a 2 s . com public void test() throws ParseException { String newTab = "\t"; String[] sysidLine; JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); String fileName = f.getAbsolutePath(); try { FileReader reader = new FileReader(fileName); BufferedReader br = new BufferedReader(reader); String strLine; String sysid = null, scdate = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null, otEnd = null; String scode = "1985"; StringBuilder insertSQL = new StringBuilder( "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p2end) VALUES "); StringBuilder deleteSQL = new StringBuilder("DELETE FROM scandata WHERE (sc_sysid,scdate) IN ("); // read from select file for (strLine = br.readLine(); strLine != null; strLine = br.readLine()) { System.out.println(strLine); } while ((strLine = br.readLine()) != null) { String[] parts = strLine.split(" "); // check if not first record or sysid change will save in table scandata if (sysid != null && !sysid.equals(parts[0])) { deleteSQL = deleteSQL.append(" ('").append(sysid).append("','").append(scdate).append("'),"); insertSQL = insertSQL.append(" ('").append(sysid).append("','").append(scode).append("','") .append(scdate).append("','").append(p1Start).append("','").append(p2End).append("'),"); p1Start = null; p1End = null; p2Start = null; p2End = null; otStart = null; otEnd = null; } //clear sysid = parts[0]; scdate = new StringBuffer(parts[1]).insert(parts[1].length() - 2, "-").toString(); scdate = new StringBuffer(scdate).insert(scdate.length() - 5, "-").toString(); String timeString = new StringBuffer(parts[5]).insert(parts[5].length() - 2, ":").toString(); if (parts[6].equals("01")) { p1Start = CompareTime(p1Start, timeString, "01"); } else { p2End = CompareTime(p2End, timeString, "04"); } } deleteSQL = deleteSQL.append(" ('").append(sysid).append("','").append(scdate).append("'))"); insertSQL = insertSQL.append(" ('").append(sysid).append("','").append(scode).append("','") .append(scdate).append("','").append(p1Start).append("','").append(p2End).append("')"); scanDao.executeSQL(deleteSQL.toString()); scanDao.executeSQL(insertSQL.toString()); br.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:techtonic.Exports.java
private void saveExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveExportActionPerformed format = (jpg.isSelected()) ? "jpg" : "png"; JFileChooser jfc = new JFileChooser(); int returnValue = jfc.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = jfc.getSelectedFile(); String cv = selectedFile.getName(); try {/*from ww w . j a va 2 s . c o m*/ eWidth = Integer.parseInt(width.getText().trim()); } catch (NumberFormatException nfe) { width.requestFocus(); return; } try { eHeight = Integer.parseInt(height.getText().trim()); } catch (NumberFormatException nfe) { width.requestFocus(); return; } try { ChartUtilities.saveChartAsJPEG(new File(Techtonic.getDefaultDirectory(), cv + "." + format), Techtonic.getFreeChart(), eWidth, eHeight); Techtonic.seteHeight(eHeight); Techtonic.seteWidth(eWidth); Techtonic.setFileName(name); Techtonic.setFileFormat(format); Techtonic.getStatusBar().setForeground(Color.blue); Techtonic.getStatusBar().setText("File Exported"); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Problem exporting file"); Techtonic.getStatusBar().setForeground(Color.red); Techtonic.getStatusBar().setText("File not exported"); } this.dispose(); } else { } }
From source file:com.reelfx.controller.AbstractController.java
public void askForAndSaveRecording() { JFileChooser fileSelect = new JFileChooser(); int returnVal = fileSelect.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileSelect.getSelectedFile(); saveRecording(file);/* w ww .ja va2 s . co m*/ } }
From source file:com.itd.dbmrgdao.TestTime3.java
@Ignore @org.junit.Test/*from w w w . ja v a 2 s. c o m*/ public void test() throws ParseException { String newTab = "\t"; String[] sysidLine; JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); String fileName = f.getAbsolutePath(); try { FileReader reader = new FileReader(fileName); BufferedReader br = new BufferedReader(reader); String strLine; String sysid = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null, otEnd = null; Date scdate = null; // read from select file while ((strLine = br.readLine()) != null) { String[] parts = strLine.split(" "); // check if not first record or sysid change will save in table scandata if (sysid != null && !sysid.equals(parts[0])) { // rule if whatever employee register will get standard hour 8 hrs // if (p1Start != null || p2End != null) { // ScanRule scanRule = scanDao.findScanRuleBySysId(sysid); // p1Start = scanRule.getP1start(); // p2End = scanRule.getP2end(); // } // set up data in entity ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate); ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart, otEnd); // remove old record (key is sysid and scdate) gennericDao.remove(scanData); gennericDao.create(scanData); //clear p1Start = null; p1End = null; p2Start = null; p2End = null; otStart = null; otEnd = null; } sysid = parts[0]; scdate = new SimpleDateFormat("yyyyMMdd", Locale.US).parse(parts[1]); String timeString = new StringBuffer(parts[5]).insert(parts[5].length() - 2, ":").toString(); if (parts[6].equals("01")) { p1Start = CompareTime(p1Start, timeString, "01"); } else { p2End = CompareTime(p2End, timeString, "04"); } } //last line // if (p1Start != null || p2End != null) { // ScanRule scanRule = scanDao.findScanRuleBySysId(sysid); // p1Start = scanRule.getP1start(); // p2End = scanRule.getP2end(); // } ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate); ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart, otEnd); gennericDao.remove(scanData); gennericDao.create(scanData); br.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:MyViewChooser.java
public MyViewChooser() { super("File View Test Frame"); setSize(350, 200);// w ww . j ava 2s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); parent = this; Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton openButton = new JButton("Open"); final JLabel statusbar = new JLabel("Output of your selection will go here"); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser chooser = new JFileChooser(); // Ok, set up our own file view for the chooser chooser.setFileView(new ThumbNailFileView(MyViewChooser.this)); int option = chooser.showOpenDialog(parent); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You chose " + chooser.getSelectedFile().getName()); } else { statusbar.setText("You cancelled."); } } }); c.add(openButton); c.add(statusbar); }
From source file:org.cytoscape.dyn.internal.graphMetrics.GraphMetricsResultsPanel.java
/** * // w ww . j a v a 2s .co m */ public void saveData() { JFileChooser saveFileDialog = new JFileChooser(); int save = saveFileDialog.showSaveDialog(null); if (save == JFileChooser.APPROVE_OPTION) { FileWriter writer = null; try { File file = saveFileDialog.getSelectedFile(); if (file.exists()) { if (JOptionPane.showConfirmDialog(null, "The specified file already exists. Do you want to overwrite it?", "Warning - File Exists", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { writer = new FileWriter(file); for (int i = 0; i < this.dataset.getSeriesCount(); i++) { writer.write(this.dataset.getSeries(i).getKey().toString() + "\n"); for (int j = 0; j < this.dataset.getSeries(i).getItemCount(); j++) { writer.write(this.dataset.getSeries(i).getDataItem(j).toString() + "\n"); } } } } else { writer = new FileWriter(file); for (int i = 0; i < this.dataset.getSeriesCount(); i++) { writer.write(this.dataset.getSeries(i).getKey().toString() + "\n"); for (int j = 0; j < this.dataset.getSeries(i).getItemCount(); j++) { writer.write(this.dataset.getSeries(i).getDataItem(j).toString() + "\n"); } } } } catch (Exception e) { e.printStackTrace(); } try { writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.floreantpos.bo.actions.DataImportAction.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = DataExportAction.getFileChooser(); int option = fileChooser.showOpenDialog(com.floreantpos.util.POSUtil.getBackOfficeWindow()); if (option != JFileChooser.APPROVE_OPTION) { return;//w ww. jav a 2 s.c om } File file = fileChooser.getSelectedFile(); try { importMenuItemsFromFile(file); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), Messages.getString("DataImportAction.1")); //$NON-NLS-1$ } catch (Exception e1) { PosLog.error(getClass(), e1); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), e1.getMessage()); } }