List of usage examples for javax.swing JFileChooser setSelectedFile
@BeanProperty(preferred = true) public void setSelectedFile(File file)
From source file:org.nekorp.workflow.desktop.view.FormatoProgramacionView.java
private void importarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importarActionPerformed try {/*from w w w . java2 s.co m*/ JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx"); 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)); this.application.importarArchivo(chooser.getSelectedFile()); this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } } catch (IOException ex) { FormatoProgramacionView.LOGGER.error(ex); } }
From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java
private boolean exportDocument(final JFileChooser chooser, final int row) { try {/*from w w w .j a v a 2s.c o m*/ final DocumentInfo di = this.getDocumentInRow(row); final byte[] content = this.store.getDocument(di); chooser.setSelectedFile(new File(this.makeFilenameFor(di))); final int result = chooser.showSaveDialog(this.table); if (result != JFileChooser.APPROVE_OPTION) { return true; } FileUtils.writeByteArrayToFile(chooser.getSelectedFile(), content); this.store.markAsRead(di); this.store.writeMetadata(); } catch (final GeneralSecurityException e) { this.gui.showError(e); } catch (final IOException e) { this.gui.showError(e); } return false; }
From source file:dylemator.UserResultList.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed if (this.filenameCombo.getSelectedIndex() == 0) return;/*from w w w.ja v a2 s. c o m*/ String sheetName = (String) this.filenameCombo.getSelectedItem(); Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet(sheetName); Row headerRow = sheet.createRow(0); String[] headers = exportData.get(0); int numOfColumns = headers.length; for (int i = 0, j = 0; i < numOfColumns; i++) { if (i == 1 || i == 2 || i == 3) // opuszcz. date, imie, nazwisko continue; Cell cell = headerRow.createCell(j++); cell.setCellValue(headers[i]); } int rowCount = exportData.size(); for (int rownum = 1; rownum < rowCount; rownum++) { Row row = sheet.createRow(rownum); String[] values = exportData.get(rownum); for (int i = 0, j = 0; i < numOfColumns; i++) { if (i == 1 || i == 2 || i == 3) // opuszcz. date, imie, nazwisko continue; Cell cell = row.createCell(j++); cell.setCellValue(values[i]); } } String defaultFilename = "Export.xlsx"; JFileChooser f = new JFileChooser(System.getProperty("user.dir")); f.setSelectedFile(new File(defaultFilename)); f.setDialogTitle("Wybierz nazw dla pliku eksportu"); f.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter ff = new FileFilter() { @Override public boolean accept(File file) { if (file.getName().endsWith(".xlsx")) return true; return false; } @Override public String getDescription() { return ""; } }; f.setFileFilter(ff); File file = null; int save = f.showSaveDialog(this); if (save == JFileChooser.APPROVE_OPTION) file = f.getSelectedFile(); else return; FileOutputStream out; try { out = new FileOutputStream(file); wb.write(out); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:marytts.tools.voiceimport.DatabaseImportMain.java
protected void askIfSave() throws IOException { if (bnl.hasChanged()) { int answer = JOptionPane.showOptionDialog(this, "Do you want to save the list of basenames?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (answer == JOptionPane.YES_OPTION) { JFileChooser fc = new JFileChooser(); fc.setSelectedFile(new File(db.getProp(db.BASENAMEFILE))); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { bnl.write(fc.getSelectedFile()); }// w w w .j a v a2 s . c om } } else { System.exit(0); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java
/** * Initialize the work package calendar panel inclusive the listeners. *//* w w w .j a va2 s . c o m*/ private void init() { List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser())); Collections.sort(userWp, new APLevelComparator()); dataset = createDataset(userWp); chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPopupMenu popup = new JPopupMenu(); JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine())); miSave.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS chooser.setSelectedFile(new File("chart-" //NON-NLS + System.currentTimeMillis() + ".jpg")); int returnVal = chooser.showSaveDialog(reference); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File outfile = chooser.getSelectedFile(); ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(), chartPanel.getWidth()); Controller.showMessage( LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath())); } catch (IOException e) { Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError()); } } } }); popup.add(miSave); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }); chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawWidth(9999); chartPanel.setPreferredSize( new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size())); chartPanel.setPopupMenu(null); this.setLayout(new BorderLayout()); this.removeAll(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(chartPanel, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); GanttRenderer.setDefaultShadowsVisible(false); GanttRenderer.setDefaultBarPainter(new BarPainter() { @Override public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col, final RectangularShape rect, final RectangleEdge arg5) { String wpName = (String) dataset.getColumnKey(col); int i = 0; int spaceCount = 0; while (wpName.charAt(i++) == ' ' && spaceCount < 17) { spaceCount++; } g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15)); g.fill(rect); g.setColor(Color.black); g.setStroke(new BasicStroke()); g.draw(rect); } @Override public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2, final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) { } }); ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() { private static final long serialVersionUID = -6078915091070733812L; public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); } }); }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Get")) { if (lstHybris.getSelectedIndex() >= 0) { try { System.out.println("Retrieving " + lstHybris.getSelectedValue() + "..."); byte[] retrieved = cm.hybris.get(lstHybris.getSelectedValue()); if (retrieved != null) { JFileChooser fc = new JFileChooser( System.getProperty("user.home") + File.separator + "Desktop"); fc.setSelectedFile(new File("RETRIEVED_" + lstHybris.getSelectedValue())); int returnVal = fc.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileUtils.writeByteArrayToFile(file, retrieved); System.out.println("Saved: " + file.getName() + "."); }/*w w w .java2s . co m*/ } else JOptionPane.showMessageDialog(frame, "Hybris could not download the file.", "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Put")) { JFileChooser fc = new JFileChooser(System.getProperty("user.home") + File.separator + "Desktop"); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.println("Putting: " + file.getName() + "."); byte[] array; try { array = FileUtils.readFileToByteArray(file); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.HYBRIS, file.getName(), array)) .start(); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Delete")) { if (lstHybris.getSelectedIndex() >= 0) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS, lstHybris.getSelectedValue(), null)).start(); System.out.println("Removed " + lstHybris.getSelectedValue() + " from Hybris."); } } }
From source file:com.swg.parse.docx.OpenFolderAction.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }/* www . ja v a2 s . co m*/ int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); JFrame jf = new JFrame("Progress Bar"); Container Jcontent = jf.getContentPane(); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(0); progressBar.setStringPainted(true); Jcontent.add(progressBar, BorderLayout.NORTH); jf.setSize(300, 60); jf.setVisible(true); //we needed a new thread for a functional progress bar on the JFrame new Thread(new Runnable() { public void run() { if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; FileFilter fileFilter = new WildcardFileFilter("*.docx"); File[] files = selectedFile.listFiles(fileFilter); double cnt = 0, cnt2 = 0; //number of how many .docx is in the folder for (File f : files) { if (!f.getAbsolutePath().contains("~")) cnt2++; } for (File f : files) { cnt++; pathToTxtFile = f.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); //---------------------------------------------------- String zipFilePath = "C:\\Users\\fja2\\Desktop\\junk\\Test\\test.zip"; String destDirectory = "C:\\Users\\fja2\\Desktop\\junk\\Test " + cnt; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(f, zip); unzipper.UnzipUtility(zip, directory); zip.delete(); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\PXT1\\Desktop\\test\\Pictures\\" + f.getName() + "\\" + fil.getName())); } FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //---------------------------------------------------- //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = f.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content = ""; String POIContent = ""; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, f.getAbsolutePath(), version, (int) cnt); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } double tempProg = (cnt / cnt2) * 100; progressBar.setValue((int) tempProg); System.gc(); } } else { //do nothing } } }).start(); System.gc(); }
From source file:com.swg.parse.docx.OpenWord.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setAcceptAllFileFilterUsed(false); //this authorize only .docx selection fc.addChoosableFileFilter(new DocxFileFilter()); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }/*from w ww .j a v a 2 s . c om*/ int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); String zipFilePath = "C:\\Users\\KXK3\\Documents\\ZipTest\\test.zip"; String destDirectory = "C:\\Users\\KXK3\\Documents\\ZipTest\\temp"; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(selectedFile, zip); unzipper.UnzipUtility(zip, directory); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\KXK3\\Documents\\ZipTest\\Pictures\\" + fil.getName())); } zip.delete(); FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content; String POIContent; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, selectedFile.getAbsolutePath(), version, 1); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } } else { //do nothing } }
From source file:jpad.MainEditor.java
public void saveAs() { if (_isOSX || ostype == ostype.Linux || ostype == ostype.Other) { saveAs_OSX_Nix();// ww w . j a v a2 s .c om saveFile(curFile); } else /* Windows */ { JFileChooser fc = new JFileChooser(); if (curFile != null) fc.setSelectedFile(new File(curFile)); else fc.setSelectedFile(new File("Untitled.txt")); fc.setDialogTitle("Save Text File"); fc.setFileFilter(new FileNameExtensionFilter("Plain Text Files", "txt")); int returnval = fc.showSaveDialog(this); if (returnval == 0) { curFile = fc.getSelectedFile().getAbsolutePath(); if (!curFile.endsWith(".txt")) curFile = curFile + ".txt"; hasChanges = false; hasSavedToFile = true; saveFile(curFile); } } }
From source file:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java
private void localStorageDirjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localStorageDirjButton1ActionPerformed boolean success = false; JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setSelectedFile(new File(gp.getProperty(CamSyncProperties.LOCALSTORAGE_PATH))); if (jfc.showDialog(jPanel1, "Choose as local directory") == JFileChooser.APPROVE_OPTION) { File f = new File(jfc.getSelectedFile().getAbsolutePath(), "azocamsynctest"); success = f.mkdir();/*from w ww . j av a 2s . com*/ success = f.delete(); gp.setProperty(CamSyncProperties.LOCALSTORAGE_PATH, jfc.getSelectedFile().getAbsolutePath()); } if (success) { JOptionPane.showMessageDialog(rootPane, "You've setup the path for incoming files.\nAll configuration steps are performed now.\n Let's start the service!", "Success!", JOptionPane.INFORMATION_MESSAGE); step2jCheckBox.setSelected(true); step2jCheckBox.setText("Success"); this.setVisible(false); } else { JOptionPane.showConfirmDialog(rootPane, "This directory cannot read &write. Please choose another one.", "Local storage directory not working", JOptionPane.WARNING_MESSAGE); } }