List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:com.orange.atk.graphAnalyser.LectureJATKResult.java
/** * add all graph from a directory//from w w w. j a v a 2s. co m * */ private void openDirectoryAction(ActionEvent evt) { ConfigFile configFile = null; String JATKpath = Platform.getInstance().getJATKPath(); String pathihmconfig = JATKpath + Platform.FILE_SEPARATOR + "log" + Platform.FILE_SEPARATOR + "ConfigIHM.cfg"; File ihmconfig = new File(pathihmconfig); configFile = new ConfigFile(ihmconfig); //get a value from confile String Scriptpath = getvalueconfigfile(pathihmconfig, "path_READGRAPH"); //open JfileChooser final JFileChooser fc = new JFileChooser(Scriptpath); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(jMenu1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); Scriptpath = file.getAbsolutePath(); if (Scriptpath != null) configFile.setOption("path_READGRAPH", Scriptpath); configFile.saveConfigFile(); //clean graph cleanlistElement(); analyzerGraphs.createMyDataset(file.getPath()); mapPerfGraph = analyzerGraphs.getMapPerfGraph(); mapAction = analyzerGraphs.getMapAction(); addPerformanceslist(); addMarkerlist(); //Add listener on list of graph and markers setListenerMarkerGraph(); //Crosshair Value Renderer et model setRendererandModelSeries(); } }
From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java
private void loadLicenseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadLicenseButtonActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("License File", "lic")); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); License license = License.loadFromFile(file); if (license != null) try { licenseManager.setLicense(license); updateLicenseInfo();// w ww.jav a2s . c om } catch (IOException e) { GUIUtils.displayError(this, "Error updating license. You may need to reload the license next time you start EventManager"); } else GUIUtils.displayError(this, "Error while loading license file"); } }
From source file:net.sf.jabref.openoffice.AutoDetectPaths.java
private boolean autoDetectPaths() { if (OS.WINDOWS) { List<File> progFiles = findProgramFilesDir(); File sOffice = null;/* w w w .ja v a 2s . c om*/ List<File> sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { if (fileSearchCancelled) { return false; } sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { sofficeFiles.add(sOffice); } } if (sOffice == null) { JOptionPane.showMessageDialog(parent, Localization.lang( "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Localization.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } if (sofficeFiles.size() > 1) { // More than one file found DefaultListModel<File> mod = new DefaultListModel<>(); for (File tmpfile : sofficeFiles) { mod.addElement(tmpfile); } JList<File> fileList = new JList<>(mod); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.setSelectedIndex(0); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref")); b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1); b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3); b.add(fileList).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { sOffice = fileList.getSelectedValue(); } } else { sOffice = sofficeFiles.get(0); } return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe"); } else if (OS.OS_X) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName()) || "LibreOffice.app".equals(file.getName()))) { rootDir = file; break; } } } File sOffice = findFileDir(rootDir, SOFFICE_BIN); if (fileSearchCancelled) { return false; } if (sOffice == null) { return false; } else { return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN); } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File(usrRoot), SOFFICE); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), SOFFICE); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), SOFFICE); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } else if (inOpt != null) { if (inUsr == null) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref ")); b.add(Localization.lang( "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:")) .xy(1, 1); b.add(optRB).xy(1, 3); b.add(usrRB).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } } } } return false; }
From source file:my.swingconnect.SwingConnectUI.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed //To BROWSE A FILE FROM THE DIRECTORY JFileChooser chooser = new JFileChooser(); //To enable showing hidden file chooser.setFileHidingEnabled(false); //To Enable selecting directory or files chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //To enable multiple file selections chooser.setMultiSelectionEnabled(true); //Choice of user to save or open a file chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setDialogTitle("Choose a file..."); //To user to select a file if (chooser.showOpenDialog(SwingConnectUI.this) == JFileChooser.APPROVE_OPTION) { targetFile = chooser.getSelectedFile(); String directory = targetFile.getPath(); jTextField4.setText(targetFile.toString()); // files = new File("/Users/pradil90/Desktop/207dropbox").listFiles(); files = new File(directory).listFiles(); for (File file : files) { if (file.isFile()) { results.add(file.getAbsolutePath()); // results.add(file.getName()); System.out.println(file); count++;// w w w . java 2 s . c o m System.out.println(count); } } results.remove(0); jButton3.setEnabled(true); } }
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 av a 2 s . c o 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:jatoo.app.App.java
private File select(final File currentDirectory, final int fileSelectionMode) { JFileChooser fileChooser = new JFileChooser(currentDirectory); fileChooser.setFileSelectionMode(fileSelectionMode); int returnValue = fileChooser.showOpenDialog(window); if (returnValue == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile(); }// w w w .j a v a2 s . c o m return null; }
From source file:gov.nij.er.ui.EntityResolutionDemo.java
private void handleLoadExcelDataCommand() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override/* ww w . ja v a2s .c om*/ public boolean accept(File f) { String name = f.getName(); return f.isDirectory() || name.endsWith(".xls") || name.endsWith(".xlsx"); } @Override public String getDescription() { return "Excel Workbooks (*.xls, *.xlsx)"; } }); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = fc.getSelectedFile(); try { new UIBlockingTask(new RunnableTask() { public void run() throws Exception { loadExcelData(file); } }).execute(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:generadorqr.jifrNuevoQr.java
void CargarImagen(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarfoto = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("JPG", "jpg"); jfchCargarfoto.setFileFilter(filtro); resultado = jfchCargarfoto.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarfoto.getSelectedFile(); try {//from w w w . j a va 2 s .c om tempImagen[identificador] = fichero.getPath(); tempNombreArchivo[identificador] = fichero.getName(); ImageIcon icon = new ImageIcon(fichero.toString()); Icon icono = new ImageIcon(icon.getImage().getScaledInstance(label.getWidth(), label.getHeight(), Image.SCALE_DEFAULT)); label.setText(null); label.setIcon(icono); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }
From source file:generadorqr.jifrNuevoQr.java
void CargarVideo(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarVideo = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("MP4", "mp4"); jfchCargarVideo.setFileFilter(filtro); resultado = jfchCargarVideo.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarVideo.getSelectedFile(); try {//from w ww . j a v a 2s.c o m tempVideo = fichero.getPath(); tempNombreMultimedia[identificador] = fichero.getName(); label.setText(tempNombreMultimedia[identificador]); if (label.getText().length() > 10) label.setText(tempNombreMultimedia[identificador].substring(0, 10) + "...mp4"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }
From source file:generadorqr.jifrNuevoQr.java
void CargarAudio(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarVideo = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("MP3", "mp3"); jfchCargarVideo.setFileFilter(filtro); resultado = jfchCargarVideo.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarVideo.getSelectedFile(); try {//from w w w .ja v a2s. co m tempAudio = fichero.getPath(); tempNombreMultimedia[identificador] = fichero.getName(); label.setText(tempNombreMultimedia[identificador]); if (label.getText().length() > 10) label.setText(tempNombreMultimedia[identificador].substring(0, 10) + "...mp3"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }