List of usage examples for javax.swing JFileChooser setCurrentDirectory
@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir)
From source file:maltcms.ui.nb.pipelineRunner.options.LocalMaltcmsExecutionPanel.java
private void selectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectActionPerformed FileChooserBuilder fcb = new FileChooserBuilder(LocalMaltcmsExecutionPanel.class); fcb.setFilesOnly(false);/*from w w w .java2 s . co m*/ fcb.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } return file.getName().equals("maltcms.jar"); } @Override public String getDescription() { return "maltcms.jar"; } }); fcb.setSelectionApprover(new FileChooserBuilder.SelectionApprover() { @Override public boolean approve(File[] files) { // boolean approve = false; for (File f : files) { if (f.getName().equals("maltcms.jar")) { return true; } } return false; } }); JFileChooser jfc = fcb.createFileChooser(); if (!maltcmsInstallationPath.getText().isEmpty()) { File basedir = new File(maltcmsInstallationPath.getText()); jfc.setCurrentDirectory(basedir); } int ret = jfc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); maltcmsInstallationPath.setText(f.getParent()); checkVersion(f.getParentFile().getAbsolutePath()); controller.changed(); } }
From source file:pcd3.View.java
private void pilihGambarCitraMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pilihGambarCitraMouseClicked final String path = "./Citra Images/form.1"; javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); chooser.setCurrentDirectory(new File(path)); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public final static String jpeg = "jpeg"; public final String jpg = "jpg"; public final String gif = "gif"; public final String tiff = "tiff"; public final String tif = "tif"; public final String png = "png"; /*Get the extension of a file.*/ public String getExtension(java.io.File f) { String ext = null;// w w w . j a va2 s . com String s = f.getName(); int i = s.lastIndexOf('.'); if (i > 0 && i < s.length() - 1) { ext = s.substring(i + 1).toLowerCase(); } return ext; } @Override public String getDescription() { return "All Images extensions (jpg, gif, tiff, tif, png)"; } @Override public boolean accept(java.io.File f) { if (f.isDirectory()) { return true; } String extension = getExtension(f); if (extension != null) { return extension.equals(tiff) || extension.equals(tif) || extension.equals(gif) || extension.equals(jpeg) || extension.equals(jpg) || extension.equals(png); } return false; } }); if (chooser.showDialog(this, " Open ") == javax.swing.JFileChooser.APPROVE_OPTION) { java.io.File file = chooser.getSelectedFile(); String filePath = file.toString(); try { final BufferedImage bimg = ImageIO.read(new File(filePath)); namaCitra.setText("Nama Citra : " + file.getName()); Thread t = new Thread() { @Override public void run() { imageFormSiji.setImage(bimg); imageFormSiji.imageToGray(1); imageFormSiji.setHistogram(); int jumlah = 0; DefaultCategoryDataset chartBarAwal = new DefaultCategoryDataset(); DefaultCategoryDataset chartBarHasil = new DefaultCategoryDataset(); //barChartData.setva for (int i = 0; i < imageFormSiji.getHistogram().size(); i++) { System.out.println(imageFormSiji.getHistogram().get(i).getRgb() + " = " + imageFormSiji.getHistogram().get(i).getJumlah() + " = " + imageFormSiji.getHistogram().get(i).getJumlahKumulatif() + " = " + imageFormSiji.getHistogram().get(i).getHasilEkualisasi()); jumlah += imageFormSiji.getHistogram().get(i).getJumlah(); chartBarAwal.setValue(imageFormSiji.getHistogram().get(i).getJumlah(), "aha", "" + imageFormSiji.getHistogram().get(i).getRgb()); chartBarHasil.setValue(imageFormSiji.getHistogram().get(i).getHasilEkualisasi(), "aha", "" + imageFormSiji.getHistogram().get(i).getRgb()); } JFreeChart chartSiji = ChartFactory.createBarChart("Histogam Citra Awal", "RGB", "Jumlah", chartBarAwal, PlotOrientation.VERTICAL, false, true, false); JFreeChart chartLoro = ChartFactory.createBarChart("Histogram Citra Ekualisasi", "RGB", "Jumlah", chartBarHasil, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryPlotSiji = chartSiji.getCategoryPlot(); CategoryPlot categoryPlotLoro = chartLoro.getCategoryPlot(); categoryPlotSiji.setRangeGridlinePaint(Color.orange); categoryPlotLoro.setRangeGridlinePaint(Color.orange); ChartPanel cpanelSiji = new ChartPanel(chartSiji); ChartPanel cpanelLoro = new ChartPanel(chartLoro); chartAwal.removeAll(); chartAwal.add(cpanelSiji); chartAwal.validate(); chartEkualisasi.removeAll(); chartEkualisasi.add(cpanelLoro); chartEkualisasi.validate(); System.out.println("Jumlah = " + jumlah); citraLabel.setText(""); citraGrayLabel.setText(""); citraEkualisasi.setText(""); citraLabel.setIcon(new ImageIcon(bimg.getScaledInstance(230, 230, 0))); //resetCitra(); ukuranCitra.setText("Ukuran Citra : " + imageFormSiji.getTinggi() + " x " + imageFormSiji.getLebar() + ""); imageFormSiji.setSmoothingImage(); imageFormSiji.setSharpeningImage(); citraEkualisasi.setIcon( new ImageIcon(imageFormSiji.getEqualImage().getScaledInstance(230, 230, 0))); citraGrayLabel.setIcon( new ImageIcon(imageFormSiji.getGrayImage().getScaledInstance(230, 230, 0))); citraSmoothingHasil.setIcon(new ImageIcon(imageFormSiji.getSmoothingImage())); citraSharpheningHasil.setIcon(new ImageIcon(imageFormSiji.getSharpeningImage())); } }; t.start(); } catch (IOException e) { javax.swing.JOptionPane.showMessageDialog(this, "File Tidak Ditemukan " + e); } } }
From source file:jmemorize.gui.swing.frames.MainFrame.java
@Override public File determineLessonFileToOpen() { // from determineLessonFile(file): final File lessonFile; final JFileChooser chooser = new JFileChooser(); try {//from w w w . j a v a 2 s . co m chooser.setCurrentDirectory(Settings.loadLastDirectory()); } catch (final Exception ioe) { Main.logThrowable("Could not load last directory", ioe); chooser.setCurrentDirectory(null); } chooser.setFileFilter(MainFrame.FILE_FILTER); final int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { lessonFile = chooser.getSelectedFile(); } else { lessonFile = null; } return lessonFile; }
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); }// ww w. j a va 2 s .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: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 2 s . c om*/ 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);// ww w . ja va 2 s .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(".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:de.fhg.igd.mapviewer.server.file.FileTiler.java
/** * Ask the user for an image file for that a tiled map shall be created *//*from ww w . j a v a 2 s .co m*/ 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:jboost.visualization.HistogramFrame.java
private File selectPDFFile() { File fFile = new File("default.pdf"); JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(new FileFilter() { public boolean accept(File f) { String path = f.getAbsolutePath(); if (f.isDirectory() || path.endsWith(".pdf")) return true; else/*from w w w. j av a 2s.com*/ return false; } public String getDescription() { return "PDF Files"; } }); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return null; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) return null; } return fFile; } else { return null; } }
From source file:jboost.visualization.HistogramFrame.java
private File selectDumpFile() { File fFile = new File("ExamplesDumpFile.txt"); JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(new FileFilter() { public boolean accept(File f) { String path = f.getAbsolutePath(); if (f.isDirectory() || path.endsWith(".txt")) return true; else//from ww w .j a va 2 s. c om return false; } public String getDescription() { return "Text Files"; } }); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return null; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) return null; } return fFile; } else { return null; } }
From source file:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java
private void autoruninstalljButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoruninstalljButton1ActionPerformed boolean success = false; JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Prepare card..."); File startFile = new File(System.getProperty("user.dir")); //Get the current directory // Find System Root while (!FileSystemView.getFileSystemView().isFileSystemRoot(startFile)) { startFile = startFile.getParentFile(); }//w w w. j av a 2 s . c o m jfc.setCurrentDirectory(startFile); int origDriveChooserRetVal = jfc.showDialog(rootPane, "Open"); if (origDriveChooserRetVal == JFileChooser.APPROVE_OPTION) { try { File myfile = new File(jfc.getSelectedFile().getAbsolutePath(), "autorun.sh"); myfile.createNewFile(); FileOutputStream fos; try { fos = new FileOutputStream(myfile); IOUtils.copy(getClass().getResourceAsStream( "/de/quadrillenschule/azocamsyncd/ftpservice/res/autorun.sh"), fos); fos.close(); success = true; } catch (FileNotFoundException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } if (!success) { JOptionPane.showMessageDialog(rootPane, "The WiFi is SD card could not be written to. Please check if you selected the right card and it is not write-protected.", "SD card could not be prepared", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(rootPane, "The WiFi SD card is prepared for operating an FTP and Telnet server.", "Success!", JOptionPane.INFORMATION_MESSAGE); step0jCheckBox.setSelected(true); step0jCheckBox.setText("Done"); updateSelectedPanel(1); } }