List of usage examples for javax.swing JFileChooser getCurrentDirectory
public File getCurrentDirectory()
From source file:com.stanley.captioner.MainFrame.java
private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed {//GEN-HEADEREND:event_addButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg"); fileChooser.setFileFilter(filter);//w w w. ja v a 2s. c o m if (lastAddDirectory != null) { fileChooser.setCurrentDirectory(lastAddDirectory); } int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastAddDirectory = fileChooser.getCurrentDirectory(); DefaultTableModel model = (DefaultTableModel) videoTable.getModel(); File files[] = fileChooser.getSelectedFiles(); for (File file : files) { boolean alreadyExists = false; for (int i = model.getRowCount() - 1; i >= 0; i--) { String path = (String) model.getValueAt(i, 0); if (file.getAbsolutePath().equals(path)) { alreadyExists = true; } } if (!alreadyExists) { model.addRow(getVideoInfo(file)); } } } }
From source file:de.fhg.igd.mapviewer.server.file.FileTiler.java
/** * Ask the user for an image file for that a tiled map shall be created *//*from w w w . j a v a 2 s .com*/ public void run() { JFileChooser fileChooser = new JFileChooser(); // load current dir fileChooser.setCurrentDirectory( new File(pref.get(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath()))); // open int returnVal = fileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { // save current dir pref.put(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath()); // get file File imageFile = fileChooser.getSelectedFile(); // get image dimension Dimension size = getSize(imageFile); log.info("Image size: " + size); // ask for min tile size int minTileSize = 0; while (minTileSize <= 0) { try { minTileSize = Integer.parseInt( JOptionPane.showInputDialog("Minimal tile size", String.valueOf(DEF_MIN_TILE_SIZE))); } catch (Exception e) { minTileSize = 0; } } // determine min map width int width = size.width; while (width / 2 > minTileSize && width % 2 == 0) { width = width / 2; } int minMapWidth = width; // min map width log.info("Minimal map width: " + minMapWidth); // determine min map height int height = size.height; while (height / 2 > minTileSize && height % 2 == 0) { height = height / 2; // min map height } int minMapHeight = height; log.info("Minimal map height: " + minMapHeight); // ask for min map size int minMapSize = 0; while (minMapSize <= 0) { try { minMapSize = Integer.parseInt( JOptionPane.showInputDialog("Minimal map size", String.valueOf(DEF_MIN_MAP_SIZE))); } catch (Exception e) { minMapSize = 0; } } // determine zoom levels int zoomLevels = 1; width = size.width; height = size.height; while (width % 2 == 0 && height % 2 == 0 && width / 2 >= Math.max(minMapWidth, minMapSize) && height / 2 >= Math.max(minMapHeight, minMapSize)) { zoomLevels++; width = width / 2; height = height / 2; } log.info("Number of zoom levels: " + zoomLevels); // determine tile width width = minMapWidth; int tileWidth = minMapWidth; for (int i = 3; i < Math.sqrt(minMapWidth) && width > minTileSize;) { tileWidth = width; if (width % i == 0) { width = width / i; } else i++; } // determine tile height height = minMapHeight; int tileHeight = minMapHeight; for (int i = 3; i < Math.sqrt(minMapHeight) && height > minTileSize;) { tileHeight = height; if (height % i == 0) { height = height / i; } else i++; } // create tiles for each zoom level if (JOptionPane.showConfirmDialog(null, "Create tiles (" + tileWidth + "x" + tileHeight + ") for " + zoomLevels + " zoom levels?", "Create tiles", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { int currentWidth = size.width; int currentHeight = size.height; File currentImage = imageFile; Properties properties = new Properties(); properties.setProperty(PROP_TILE_WIDTH, String.valueOf(tileWidth)); properties.setProperty(PROP_TILE_HEIGHT, String.valueOf(tileHeight)); properties.setProperty(PROP_ZOOM_LEVELS, String.valueOf(zoomLevels)); List<File> files = new ArrayList<File>(); for (int i = 0; i < zoomLevels; i++) { int mapWidth = currentWidth / tileWidth; int mapHeight = currentHeight / tileHeight; log.info("Creating tiles for zoom level " + i); log.info("Map width: " + currentWidth + " pixels, " + mapWidth + " tiles"); log.info("Map height: " + currentHeight + " pixels, " + mapHeight + " tiles"); // create tiles tile(currentImage, TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + "%d", TILE_FILE_EXTENSION, tileWidth, tileHeight); // add files to list for (int num = 0; num < mapWidth * mapHeight; num++) { files.add(new File(imageFile.getParentFile().getAbsolutePath() + File.separator + TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + num + TILE_FILE_EXTENSION)); } // store map width and height at current zoom properties.setProperty(PROP_MAP_WIDTH + i, String.valueOf(mapWidth)); properties.setProperty(PROP_MAP_HEIGHT + i, String.valueOf(mapHeight)); // create image for next zoom level currentWidth /= 2; currentHeight /= 2; // create temp image file name File nextImage = suffixFile(imageFile, i + 1); // resize image convert(currentImage, nextImage, currentWidth, currentHeight, 100); // delete previous temp file if (!currentImage.equals(imageFile)) { if (!currentImage.delete()) { log.warn("Error deleting " + imageFile.getAbsolutePath()); } } currentImage = nextImage; } // delete previous temp file if (!currentImage.equals(imageFile)) { if (!currentImage.delete()) { log.warn("Error deleting " + imageFile.getAbsolutePath()); } } // write properties file File propertiesFile = new File( imageFile.getParentFile().getAbsolutePath() + File.separator + MAP_PROPERTIES_FILE); try { FileWriter propertiesWriter = new FileWriter(propertiesFile); try { properties.store(propertiesWriter, "Map generated from " + imageFile.getName()); // add properties file to list files.add(propertiesFile); } finally { propertiesWriter.close(); } } catch (IOException e) { log.error("Error writing map properties file", e); } // add a converter properties file String convProperties = askForPath(fileChooser, new ExactFileFilter(CONVERTER_PROPERTIES_FILE), "Select a converter properties file"); File convFile = null; if (convProperties != null) { convFile = new File(convProperties); files.add(convFile); } // create jar file log.info("Creating jar archive..."); if (createJarArchive(replaceExtension(imageFile, MAP_ARCHIVE_EXTENSION), files)) { log.info("Archive successfully created, deleting tiles..."); // don't delete converter properties if (convFile != null) files.remove(files.size() - 1); // delete files for (File file : files) { if (!file.delete()) { log.warn("Error deleting " + file.getAbsolutePath()); } } } log.info("Fin."); } } }
From source file:gui.InboxPanel.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {//www . j a v a 2 s . c o m String name = GmailAPI.getAttachmentFilename(curId); System.out.println(name); if (name == "None") { JOptionPane.showMessageDialog(this, "No file attached on this email"); } else { JFileChooser chooser = new JFileChooser(); File defFile = new File(name); chooser.setSelectedFile(defFile); int filesave = chooser.showSaveDialog(null); if (filesave == JFileChooser.APPROVE_OPTION) { //chooser.getSelectedFile().se File file = chooser.getCurrentDirectory(); GmailAPI.getAttachments(GmailAPI.service, GmailAPI.USER, curId, file.getAbsolutePath(), chooser.getSelectedFile().getName()); } } } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java
private void topngjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topngjButtonActionPerformed // Save chart as a PNG image JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Save chart"); KeelFileFilter fileFilter = new KeelFileFilter(); fileFilter.addExtension("png"); fileFilter.setFilterName("PNG images (.png)"); chooser.setFileFilter(fileFilter);/*from w w w . j a va 2s. c o m*/ chooser.setCurrentDirectory(Path.getFilePath()); int opcion = chooser.showSaveDialog(this); Path.setFilePath(chooser.getCurrentDirectory()); if (opcion == JFileChooser.APPROVE_OPTION) { String nombre = chooser.getSelectedFile().getAbsolutePath(); if (!nombre.toLowerCase().endsWith(".png")) { // Add correct extension nombre += ".png"; } File tmp = new File(nombre); if (!tmp.exists() || JOptionPane.showConfirmDialog(this, "File " + nombre + " already exists. Do you want to replace it?", "Confirm", JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) { try { chart2.setBackgroundPaint(Color.white); ChartUtilities.saveChartAsPNG(new File(nombre), chart2, 1024, 768); } catch (Exception exc) { } } } }
From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java
private void topdfjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topdfjButtonActionPerformed // Save chart as a PDF file JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Save chart"); KeelFileFilter fileFilter = new KeelFileFilter(); fileFilter.addExtension("pdf"); fileFilter.setFilterName("PDF images (.pdf)"); chooser.setFileFilter(fileFilter);/*from w w w . j av a 2s .com*/ chooser.setCurrentDirectory(Path.getFilePath()); int opcion = chooser.showSaveDialog(this); Path.setFilePath(chooser.getCurrentDirectory()); if (opcion == JFileChooser.APPROVE_OPTION) { String nombre = chooser.getSelectedFile().getAbsolutePath(); if (!nombre.toLowerCase().endsWith(".pdf")) { // Add correct extension nombre += ".pdf"; } File tmp = new File(nombre); if (!tmp.exists() || JOptionPane.showConfirmDialog(this, "File " + nombre + " already exists. Do you want to replace it?", "Confirm", JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(nombre)); document.addAuthor("KEEL"); document.addSubject("Attribute comparison"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(550, 412); Graphics2D g2 = tp.createGraphics(550, 412, new DefaultFontMapper()); Rectangle2D r2D = new Rectangle2D.Double(0, 0, 550, 412); chart2.setBackgroundPaint(Color.white); chart2.draw(g2, r2D); g2.dispose(); cb.addTemplate(tp, 20, 350); document.close(); } catch (Exception exc) { } } } }
From source file:com.mirth.connect.client.ui.panels.export.MessageExportPanel.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }//from w w w.j a v a2s. c om } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } rootPathTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDoseResponseController.java
/** * Ask user to choose for a directory and invoke swing worker for creating * PDF report//w ww . jav a2 s . c om * * @throws IOException */ protected void createPdfReport() throws IOException { Experiment experiment = areaMainController.getExperiment(); // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooseDirectory.setSelectedFile(new File("Dose Response Report " + experiment.toString() + " - " + experiment.getProject().toString() + ".pdf")); // in response to the button click, show open dialog int returnVal = chooseDirectory.showSaveDialog(areaMainController.getDataAnalysisPanel()); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); DoseResponseReportSwingWorker doseResponseReportSwingWorker = new DoseResponseReportSwingWorker( directory, chooseDirectory.getSelectedFile().getName()); doseResponseReportSwingWorker.execute(); } else { areaMainController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.dfki.av.sudplan.vis.wiz.DataSourceSelectionPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser jfc = new JFileChooser(); jfc.addChoosableFileFilter(new FileNameExtensionFilter("ESRI Shapfile (*.shp)", "shp", "Shp", "SHP")); jfc.addChoosableFileFilter(new FileNameExtensionFilter("Zip file (*.zip)", "zip", "ZIP", "Zip")); XMLConfiguration xmlConfig = Configuration.getXMLConfiguration(); String path = xmlConfig.getString("sudplan3D.working.dir"); File dir;/*w ww . ja v a 2s . c o m*/ if (path != null) { dir = new File(path); if (dir.exists()) { jfc.setCurrentDirectory(dir); } } int retValue = jfc.showOpenDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); if (f != null) { jLabel1.setText(f.getAbsolutePath()); file = f; } } else { if (log.isDebugEnabled()) { log.debug("No shp file selected."); } } dir = jfc.getCurrentDirectory(); path = dir.getAbsolutePath(); xmlConfig.setProperty("sudplan3D.working.dir", path); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDoseResponseController.java
/** * Ask user to choose for a directory and invoke swing worker for creating * PDF report/* www .j a v a 2 s .c om*/ * * @throws IOException */ protected void createPdfReport() throws IOException { // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // needs more information chooseDirectory.setSelectedFile( new File("Dose Response Report " + importedDRDataHolder.getExperimentNumber() + ".pdf")); // in response to the button click, show open dialog // TEST WHETHER THIS PARENT PANEL/FRAME IS OKAY int returnVal = chooseDirectory.showSaveDialog(cellMissyController.getCellMissyFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); DoseResponseReportSwingWorker doseResponseReportSwingWorker = new DoseResponseReportSwingWorker( directory, chooseDirectory.getSelectedFile().getName()); doseResponseReportSwingWorker.execute(); } else { cellMissyController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java
/** * *//*from w w w .j a v a 2 s. c o m*/ public void open() { // Create a file chooser with the current directory set to the // application home String prefsDir = super.getApplication().getApplicationPreferencesDirectory().getAbsolutePath(); JFileChooser fileDialog = new JFileChooser(prefsDir); fileDialog.setFileFilter(connectionFileFilter); // Show it int ret = fileDialog.showOpenDialog(this); // If we've approved the selection then process if (ret == fileDialog.APPROVE_OPTION) { PreferencesStore.put(PREF_CONNECTION_FILE_DIRECTORY, fileDialog.getCurrentDirectory().getAbsolutePath()); // Get the file File f = fileDialog.getSelectedFile(); open(f); } }