private void btnTomarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTomarFotoActionPerformed // TODO add your handling code here: FileNameExtensionFilter filtro = new FileNameExtensionFilter("Formatos de Archivo JPEG(*.JPG;*.JPEG)","jpg","jpeg"); jFileChooser1.addChoosableFileFilter(filtro); jFileChooser1.setFileFilter(filtro); File Nombre =new File(txtNombre.getText()+" "+txtApellido.getText()+".jpg"); jFileChooser1.setSelectedFile(Nombre); jFileChooser1.setDialogTitle("Guardar Imagen"); File ruta = new File("C:/Imagenes"); jFileChooser1.setCurrentDirectory(ruta); int returnVal = jFileChooser1.showSaveDialog(null); if (returnVal == jFileChooser1.APPROVE_OPTION) { File file = jFileChooser1.getSelectedFile(); Highgui.imwrite(file.getPath(), frame); } else { System.out.println("File access cancelled by user."); } }
private void btn_AdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AdicionarActionPerformed // TODO add your handling code here: JFileChooser fc = new JFileChooser(); FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes()); fc.setFileFilter(imageFilter); int result = fc.showOpenDialog(null); if(result == JFileChooser.APPROVE_OPTION){ try { String path = fc.getSelectedFile().getAbsolutePath(); imagens.add(new ImageIcon(path)); if(!auxImagens.contains(imagens.get(imagens.size() - 1))){ auxImagens.add(imagens.get(imagens.size() - 1)); } JOptionPane.showMessageDialog(this, "Imagem carregada com sucesso!"); } catch(Exception e){ JOptionPane.showMessageDialog(null, "Ocorreu um erro ao carregar a imagem!", "Erro", JOptionPane.ERROR_MESSAGE); } } jsl_Slider.setMaximum(Math.max(0, imagens.size() - 1)); }
private void btn_CarregarImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CarregarImagemActionPerformed // TODO add your handling code here: JFileChooser fc = new JFileChooser(); FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes()); fc.setFileFilter(imageFilter); int result = fc.showOpenDialog(null); if(result == JFileChooser.APPROVE_OPTION){ try { String path = fc.getSelectedFile().getAbsolutePath(); imagens.add(new ImageIcon(path)); JOptionPane.showMessageDialog(this, "Imagem carregada com sucesso!"); } catch(Exception e){ JOptionPane.showMessageDialog(null, "Ocorreu um erro ao carregar a imagem!", "Erro", JOptionPane.ERROR_MESSAGE); } } }
public void saveFileAs() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new FileNameExtensionFilter("Lang871 Code Files", "871")); // Setting file type filter fileChooser.setSelectedFile(new File("קוד.871")); // Setting suggested file name fileChooser.setCurrentDirectory(new File("C:\\Users\\גלעד\\Desktop\\אביב\\מסמכים\\תכנות\\Java\\src\\com\\aviv871\\edu\\Lang871")); // TODO: change to desktop and save the last location the user used if(fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File file; if(!fileChooser.getSelectedFile().getName().endsWith(".871")) file = new File(fileChooser.getSelectedFile() + ".871"); else file = fileChooser.getSelectedFile(); writeToFile(file); codeFile = file; } }
private ExploreNetwork initCxfDBNetwork() throws FileNotFoundException { ExploreNetwork cxfDBNetwork = null; FileChooser fc = new FileChooser(); fc.setDialogTitle("Select a CXF file"); fc.setFileFilter(new FileNameExtensionFilter(".cxf files", "cxf")); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { ch.ethz.sg.cuttlefish.gui.Cuttlefish.currentDirectory = fc .getCurrentDirectory(); System.out .println("Current directory: " + fc.getCurrentDirectory()); networkFile = fc.getSelectedFile(); cxfDBNetwork = new ExploreNetwork(); cxfDBNetwork.connect(new CxfNetwork(networkFile)); cxfDBNetwork.setNetworkLoaded(true); } else { System.out.println("Input cancelled by user"); } return cxfDBNetwork; }
@Override public void addChoosableFileFilter(FileFilter filter) { super.addChoosableFileFilter(filter); if (!FX_AVAILABLE || filter == null) { return; } if (filter.getClass().equals(FileNameExtensionFilter.class)) { FileNameExtensionFilter f = (FileNameExtensionFilter) filter; List<String> ext = new ArrayList<>(); for (String extension : f.getExtensions()) { ext.add(extension.replaceAll("^\\*?\\.?(.*)$", "*.$1")); } fileChooser.getExtensionFilters() .add(new FileChooser.ExtensionFilter(f.getDescription(), ext)); } }
/** * Creates and initialized a {@link JFileChooser} for selecting the export target * @return the {@link JFileChooser} */ protected JFileChooser getJFileChooser() { // --- Create and initialize the JFileChooser ------- JFileChooser jFileChooser = new JFileChooser(); List<FileNameExtensionFilter> filtersList = this.getFileNameExtensionFilters(); for (FileNameExtensionFilter filter : filtersList) { jFileChooser.addChoosableFileFilter(filter); } jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jFileChooser.setMultiSelectionEnabled(false); jFileChooser.setAcceptAllFileFilterUsed(false); File proposedFile = new File(this.getProposedFileName()); jFileChooser.setSelectedFile(proposedFile); jFileChooser.setCurrentDirectory(proposedFile); return jFileChooser; }
private void jl_Imagen_ContactsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jl_Imagen_ContactsMouseClicked // TODO add your handling code here: jl_Imagen_Contacts.setText(""); JFileChooser fc = new JFileChooser(); FileFilter filtro = new FileNameExtensionFilter("Imagenes", "png", "jpg", "jpeg", "gif"); fc.setFileFilter(filtro); File Archivo; int op = fc.showOpenDialog(this); if (op == JFileChooser.APPROVE_OPTION) { Archivo = fc.getSelectedFile(); RutaImagen = Archivo.getPath(); System.out.println(Archivo.getPath()); Image Img = Toolkit.getDefaultToolkit().createImage(Archivo.getPath()).getScaledInstance(180, 229, 0); this.jl_Imagen_Contacts.setIcon(new ImageIcon(Img)); } }
private BrowsableNetwork initFileNetwork(String name, String extension) throws IOException { BrowsableNetwork network = null; JFileChooser fc = new FileChooser(); fc.setDialogTitle("Select a " + name + " file"); if (extension != null && !extension.isEmpty()) { fc.setFileFilter(new FileNameExtensionFilter("." + extension + " files", extension)); } int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { networkFile = fc.getSelectedFile(); network = new BrowsableNetwork(); network.load(networkFile); network.setNetworkLoaded(true); } else { System.out.println("Input cancelled by user"); } return network; }
private static File getFile(Component parentComponent, File parentDirectory, FileNameExtensionFilter fileExtensionFilter, int fileSelectionMode, boolean saveDialog, String suggestedFileName) throws FileNotChosenException { File file = null; if(parentDirectory != null) fc.setCurrentDirectory(parentDirectory); fc.setSelectedFile(suggestedFileName != null ? new File(suggestedFileName) : new File("")); fc.setFileFilter(fileExtensionFilter); fc.setFileSelectionMode(fileSelectionMode); int returnVal; if(saveDialog) returnVal = fc.showSaveDialog(parentComponent); else returnVal = fc.showOpenDialog(parentComponent); if (returnVal == JFileChooser.APPROVE_OPTION) file = fc.getSelectedFile(); else throw new FileNotChosenException(); return file; }
private void openMenuActionPerformed(java.awt.event.ActionEvent evt) { FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text"); openChooser.setFileFilter(filter); openChooser.showOpenDialog(saveBtn); if (openChooser.getSelectedFile() == null) return; String text = ""; try { for (String line : Files.readAllLines(Paths.get(openChooser.getSelectedFile().getPath()))) { text += line + "\n"; } } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); return; } filePaths.add(openChooser.getSelectedFile().getPath()); javax.swing.JTextArea newTextArea = new javax.swing.JTextArea(text); newTextArea.setLineWrap(true); javax.swing.JScrollPane scroll = new javax.swing.JScrollPane(newTextArea); editTabs.addTab(openChooser.getSelectedFile().getName(), scroll); }
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { FileChooser fc = new FileChooser(); fc.setDialogTitle("Output to file..."); fc.setFileFilter(new FileNameExtensionFilter(".tex files", "tex")); int returnVal = fc.showSaveDialog(networkPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { tikzExporter.setOutputFile(fc.getSelectedFile()); exportButton.setEnabled(true); String filePath = ""; try { filePath = fc.getSelectedFile().getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } fileTextField.setText(filePath); } this.toFront(); }
/** * Ask the user for a file to load or write to. Uses the AWT FileDialog on * macOS and the JFileChooser on other platforms. Makes sure the dialog is * displayed in the event dispatch thread. * * @param frame A Frame for which to display the dialog. Cannot be null. * @param message A message that will be displayed in the dialog. * @param defaultFile The default file name. * @param load Pass true if an existing file for reading should be selected. * Pass false if a new file for writing should be specified. * @param ext A file extension that is required when selecting a file name * for saving a file. Can be null. * @param filter filter used on Windows by the file chooser to filter out * files from the user's view. * @return A path to the file, including the file name. */ public static String askFile(final java.awt.Frame frame, final String message, final String defaultFile, final boolean load, final String ext, final FileNameExtensionFilter filter) { GUI gui = new GUI(); gui.frame = frame; gui.message = message; gui.defaultFile = defaultFile; gui.load = load; gui.ext = ext; gui.filter = filter; // make sure we run in the event dispatch thread. SwingThreadUtils.invokeAndWait(gui); return gui.filePath; }
private void saveProjectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveProjectMenuItemActionPerformed // ask for file path if the document has never been saved or if its // path is invalid. String ext = ika.mapanalyst.ApplicationInfo.getDocumentExtension(); if (filePath == null || !new java.io.File(filePath).exists()) { filePath = FileUtils.askFile(this, "Save Project", exportFileName(ext), false, ext, new FileNameExtensionFilter("MapAnalyst", ext)); } if (filePath == null) { return; // user canceled } // Don't move this to saveProject(). The path with the correct extension // has to be stored. filePath = ika.utils.FileUtils.forceFileNameExtension(filePath, ext); // the user canceled if filePath is null if (filePath != null) { saveProject(filePath); cleanDirty(); String fileName = FileUtils.getFileNameWithoutExtension(filePath); setTitle(fileName + (Sys.isWindows() ? " - MapAnalyst" : "")); MainWindow.updateAllMenusOfAllWindows(); } }
/** * Вызывает диалог выбора файла. * * @param parent Относительно чего показывать форму диалога. * @param title Заголовок диалогового окна. * @param description Описание фильтра, например "Файлы XML(*.xml)". * @param extension Фильтр по расширению файлов, например "xml". * @return Полное имя файла или null если не выбрали. */ public static String getFileName(Component parent, String title, String description, String extension) { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(Locales.getInstance().getLangCurrent()); fileChooser.resetChoosableFileFilters(); final FileNameExtensionFilter filter = new FileNameExtensionFilter(description, extension); fileChooser.setFileFilter(filter); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDialogTitle(title); if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { if (fileChooser.getSelectedFile().exists()) { return fileChooser.getSelectedFile().getAbsolutePath(); } } return null; }
private void saveLevelAs() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Save as..."); fc.setFileFilter(new FileNameExtensionFilter("Pekka Kana 2 Level", "map", "MAP")); if (Data.currentFile == null) { fc.setSelectedFile(new File(Settings.EPISODES_PATH)); } else { fc.setSelectedFile(Data.currentFile); } int res = fc.showSaveDialog(frame); if (res == JFileChooser.APPROVE_OPTION) { saveLevel(fc.getSelectedFile()); } }
public void initCxfNetwork(CxfNetwork cxfNetwork) { JFileChooser fc = new FileChooser(); fc.setDialogTitle("Select a CXF file"); fc.setFileFilter(new FileNameExtensionFilter(".cxf files", "cxf")); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { ch.ethz.sg.cuttlefish.gui2.Cuttlefish.currentDirectory = fc.getCurrentDirectory(); System.out.println("Current directory: " + fc.getCurrentDirectory()); File file = fc.getSelectedFile(); cxfNetwork.load(file); cxfNetwork.setNetworkLoaded(true); } else { System.out.println("Input cancelled by user"); } }
private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed try { JFileChooser jfc = new JFileChooser(); jfc.setDialogTitle("Registerauszug speichern"); jfc.setFileFilter(new FileNameExtensionFilter("TEXT FILES", "txt", "text")); if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw); DataSetter ds = new DataSetter(); ds.writeToFile(bw, it); } } catch (HeadlessException | IOException e) { JOptionPane.showMessageDialog(this, "Error: IO"); } }
/** * Loads a convolutional neural network (CNN) trained using DeapLearnToolbox * for Matlab (https://github.com/rasmusbergpalm/DeepLearnToolbox) that was * exported using Danny Neil's XML Matlab script cnntoxml.m. * */ synchronized public void doLoadApsDvsNetworkFromXML() { JFileChooser c = new JFileChooser(lastApsDvsNetXMLFilename); FileFilter filt = new FileNameExtensionFilter("XML File", "xml"); c.addChoosableFileFilter(filt); c.setFileFilter(filt); c.setSelectedFile(new File(lastApsDvsNetXMLFilename)); int ret = c.showOpenDialog(chip.getAeViewer()); if (ret != JFileChooser.APPROVE_OPTION) { return; } lastApsDvsNetXMLFilename = c.getSelectedFile().toString(); putString("lastAPSNetXMLFilename", lastApsDvsNetXMLFilename); try { apsDvsNet.loadFromXMLFile(c.getSelectedFile()); dvsSubsampler = new DvsFramerSingleFrame(chip); dvsSubsampler.setFromNetwork(apsDvsNet); } catch (Exception ex) { Logger.getLogger(DavisDeepLearnCnnProcessor_HJ.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't load net from this file, caught exception " + ex + ". See console for logging.", "Bad network file", JOptionPane.WARNING_MESSAGE); } }
synchronized public void doLoadGroundTruthFromTXT() { JFileChooser c = new JFileChooser(gtFilename); c.setDialogTitle("Choose ground truth bounding box file"); FileFilter filt = new FileNameExtensionFilter("TXT File", "txt"); c.addChoosableFileFilter(filt); c.setFileFilter(filt); c.setSelectedFile(new File(gtFilename)); int ret = c.showOpenDialog(chip.getAeViewer()); if (ret != JFileChooser.APPROVE_OPTION) { return; } gtFilename = c.getSelectedFile().toString(); putString("GTFilename", gtFilename); gtFilenameShort = gtFilename.substring(0, 5) + "..." + gtFilename.substring(gtFilename.lastIndexOf(File.separator)); try { this.loadBoundingBoxes(c.getSelectedFile()); } catch (Exception ex) { JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't read bounding box file" + ex + ". See console for logging.", "Bad bounding box file", JOptionPane.WARNING_MESSAGE); } }
public void doLoadNetworkFromXML() throws IOException { JFileChooser c = new JFileChooser(lastXMLFilename); FileFilter filt = new FileNameExtensionFilter("XML File", "xml"); c.addChoosableFileFilter(filt); c.setSelectedFile(new File(lastXMLFilename)); int ret = c.showOpenDialog(chip.getAeViewer()); if (ret != JFileChooser.APPROVE_OPTION) { return; } lastXMLFilename = c.getSelectedFile().toString(); putString("lastXMLFilename", lastXMLFilename); if (spike!=batch) { loadFromXMLFile(c.getSelectedFile()); }else{ log.info("Please select exact one way of processing input."); } }
synchronized public void doLoadFordVIDataFile() { JFileChooser c = new JFileChooser(lastFordVIFile); FileFilter filt = new FileNameExtensionFilter("Ford Vehicle Interface (VI) data file", "dat"); c.addChoosableFileFilter(filt); c.setFileFilter(filt); c.setSelectedFile(new File(lastFordVIFile)); int ret = c.showOpenDialog(chip.getAeViewer()); if (ret != JFileChooser.APPROVE_OPTION) { return; } lastFordVIFile = c.getSelectedFile().toString(); putString("lastFordVIFile", lastFordVIFile); try { fordViFile = c.getSelectedFile(); fordViInputStream = new BufferedInputStream(new FileInputStream(fordViFile)); fordViStates = readFordViJsonStream(fordViInputStream); } catch (Exception ex) { Logger.getLogger(DavisClassifierCNNProcessor.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't load from this file, caught exception " + ex + ". See console for logging.", "Bad data file", JOptionPane.WARNING_MESSAGE); } }
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { String output = networkPanel.getNetwork().getNetworkFileName(); if (output == null || output.isEmpty()) output = "network"; output += ".tex"; JFileChooser fc = new JFileChooser(output); fc.setDialogTitle("Output to file..."); fc.setFileFilter(new FileNameExtensionFilter(".tex files", "tex")); int returnVal = fc.showSaveDialog(networkPanel); try { if (returnVal == JFileChooser.APPROVE_OPTION) { exportButton.setEnabled(true); outputFile = fc.getSelectedFile(); fileTextField.setText(outputFile.getAbsolutePath()); } } catch (Exception e) { e.printStackTrace(); } this.toFront(); }
synchronized public void loadFromXML() { this.setProcessingEnabled(false); JFileChooser c = new JFileChooser(this.getLastRNNXMLFile()); FileFilter filter = new FileNameExtensionFilter("XML File", "xml"); c.addChoosableFileFilter(filter); c.setFileFilter(filter); c.setSelectedFile(new File(this.getLastRNNXMLFile())); int ret = c.showOpenDialog(chip.getAeViewer()); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = c.getSelectedFile(); try { this.rnnetwork.loadFromXML(f); this.setLastRNNXMLFile(f.toString()); putString("lastRNNXMLFile", this.getLastRNNXMLFile()); // this.testNumpyData.rnnetwork.loadFromXML(c.getSelectedFile()); //debug } catch (Exception e) { log.log(Level.WARNING, "Couldn't upload the xml file, please check. Caught exception {0}", e); } this.resetFilter(); }
private File openFileDialogAndGetFile(String tip, String key, String type, String... ext) { File file = null; JFileChooser c = new JFileChooser(lastNetworkFilename); File f = new File(lastNetworkFilename); c.setCurrentDirectory(new File(getString("lastNetworkPathname", ""))); c.setToolTipText(tip); FileFilter filt = new FileNameExtensionFilter(type, ext); c.addChoosableFileFilter(filt); c.setFileFilter(filt); c.setSelectedFile(new File(lastNetworkFilename)); int ret = c.showOpenDialog(chip.getAeViewer()); if (ret != JFileChooser.APPROVE_OPTION) { return null; } lastNetworkFilename = c.getSelectedFile().toString(); putString(key, lastNetworkFilename); lastNetworkPathname = f.getPath(); putString("lastNetworkPathname", lastNetworkPathname); file = c.getSelectedFile(); return file; }
private void saveTransitionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveTransitionsActionPerformed JFileChooser fc = new JFileChooser(); int returnVal; fc.setDialogType(JFileChooser.SAVE_DIALOG); //set a default filename fc.setSelectedFile(new File("state_transitions.csv")); //Set an extension filter fc.setFileFilter(new FileNameExtensionFilter("CSV file","csv")); returnVal = fc.showSaveDialog(null); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } File stateCSVFile = fc.getSelectedFile(); String filename = stateCSVFile.getAbsolutePath(); try { app.getStateLogger().setFilename(filename); app.getStateLogger().saveLogFile(); } catch (IOException ex) { IJ.error("Could not save file: " + filename); } }
private void peticionAbrirEscenario() { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. FileNameExtensionFilter filter = new FileNameExtensionFilter("ficheros xml","xml","txt" ); jFileChooser1.setFileFilter(filter); jFileChooser1.setCurrentDirectory(new File(directorioPersistencia)); jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = jFileChooser1.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = jFileChooser1.getSelectedFile(); escenarioActualComp = persistencia.obtenerInfoEscenarioSimulacion(selectedFile.getAbsolutePath()); escenarioActualComp.setGestorEscenarios(gestionEscComp); visualizarEscenario(escenarioActualComp); // fileName = selectedFile.getName(); // enviariamos el fichero a la persistencia para que nos diera el contenido // se visualiza un escenario a partir de la informaci�n almacenada System.out.println("Ejecuto accion sobre el fichero "+selectedFile.getAbsolutePath()); } else { System.out.println("File access cancelled by user."); } }
private void initReferenceLabel() { imageChooser.setFileFilter(new FileNameExtensionFilter("Image", "jpg", "png", "gif", "bmp")); referenceLabel = new JLabel() { @Override public void paint(Graphics grphcs) { super.paint(grphcs); paintPage(grphcs); } }; referenceLabel.setHorizontalAlignment(SwingConstants.CENTER); referenceLabel.setComponentPopupMenu(referencePopup); jScrollPane2.setViewportView(referenceLabel); offsetAdapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { setOffsetMarker(e); } }; referenceLabel.addMouseListener(offsetAdapter); }
@Override public void loadWorld() { FileSystemView vueSysteme = FileSystemView.getFileSystemView(); File defaut = vueSysteme.getDefaultDirectory(); JFileChooser fileChooser = new JFileChooser(defaut); fileChooser.showDialog(this, "Load"); if(fileChooser.getSelectedFile() != null){ File file = new File(fileChooser.getSelectedFile().getAbsolutePath()); FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "Map Loader"); fileChooser.setFileFilter(filter); try { this.mapDao.addMap(WorldLoader.genRawMapFILE(file)); } catch (Exception e) { e.printStackTrace(); } } }
private static File openFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new FileNameExtensionFilter("Lang871 Code Files", "871")); // Setting file type filter fileChooser.setCurrentDirectory(new File("C:\\Users\\גלעד\\Desktop\\אביב\\מסמכים\\תכנות\\Java\\src\\com\\aviv871\\edu\\Lang871")); // TODO: change to desktop and save the last location the user used if(fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { if(fileChooser.getSelectedFile().getName().endsWith(".871")) return fileChooser.getSelectedFile(); else UIManager.consoleInstance.printErrorMessage("זהו לא קובץ קוד 871. !"); } return null; }
private FileFilter createFileFilter(String description, boolean showExtensionInDescription, String... extensions) { if (showExtensionInDescription) { description = createFileNameFilterDescriptionFromExtensions( description, extensions); } return new FileNameExtensionFilter(description, extensions); }
/** * Creates a filter by extension * * @param name * @param extensions * @return FileNameExtensionFilter */ private static FileNameExtensionFilter byExtension(String name, String... extensions) { String extensionsList = String.join(",", Arrays.asList(extensions) .stream() .map(string -> "." + string) .collect(Collectors.toList())); return new FileNameExtensionFilter(name + " (" + extensionsList + ')', extensions); }
private void botaAdicionarImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaAdicionarImagemActionPerformed new Thread() { @Override public void run() { JFileChooser escolherArquivo = new JFileChooser(); escolherArquivo.setMaximumSize(new java.awt.Dimension(800, 600)); escolherArquivo.setMinimumSize(new java.awt.Dimension(800, 600)); escolherArquivo.setPreferredSize(new java.awt.Dimension(800, 600)); FileFilter filter = new FileNameExtensionFilter("Imagens em JPEG", "jpg", "jpeg"); FileFilter filter2 = new FileNameExtensionFilter("Imagens em PNG", "png"); FileFilter filter3 = new FileNameExtensionFilter("Imagens em GIF", "gif"); escolherArquivo.addChoosableFileFilter(filter); escolherArquivo.addChoosableFileFilter(filter2); escolherArquivo.addChoosableFileFilter(filter3); escolherArquivo.setAcceptAllFileFilterUsed(false); escolherArquivo.setMultiSelectionEnabled(false); int resultado = escolherArquivo.showOpenDialog(null); if (resultado == escolherArquivo.CANCEL_OPTION) { System.out.println("Escolha de arquivos cancelada"); } else { String path = escolherArquivo.getSelectedFile().getPath(); System.out.println("Arquivo: [" + path + "] selecionado"); dao.uploadNPC(path); } } }.start(); }
@Messages("LBL_zip_files=ZIP files") private void zipButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zipButtonActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileNameExtensionFilter(LBL_zip_files(), "zip", "jar")); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { zipField.setText(fc.getSelectedFile().getAbsolutePath()); firePropertyChange("validity", null, null); } }
private void bSeleniumServerJarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSeleniumServerJarActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(new FileNameExtensionFilter("Jar File", "jar")); chooser.setSelectedFile(new File(tfSeleniumServerJar.getText().trim())); if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) { tfSeleniumServerJar.setText(chooser.getSelectedFile().getAbsolutePath()); updateValidity(); } }
private void bUserExtensionFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUserExtensionFileActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(new FileNameExtensionFilter("Javascript File", "js")); chooser.setSelectedFile(new File(tfUserExtensionFile.getText().trim())); if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) { tfUserExtensionFile.setText(chooser.getSelectedFile().getAbsolutePath()); } }
/** * Provides a list of {@link FileNameExtensionFilter}s for a {@link JFileChooser} dialog. Can be overridden by * subclasses to customize the list of available filters. * @return The list of {@link FileNameExtensionFilter}s */ protected List<FileNameExtensionFilter> getFileNameExtensionFilters() { List<FileNameExtensionFilter> filtersList = new ArrayList<FileNameExtensionFilter>(); // --- Prepare file type filters ----------------------------- String projectFileSuffix = Application.getGlobalInfo().getFileEndProjectZip(); FileNameExtensionFilter projectFileFilter = new FileNameExtensionFilter(Language.translate("Agent.GUI Projekt-Datei") + " (*." + projectFileSuffix + ")", projectFileSuffix); filtersList.add(projectFileFilter); FileNameExtensionFilter zipFileFilter = new FileNameExtensionFilter(Language.translate("Zip-Datei") + " (*.zip)", "zip"); filtersList.add(zipFileFilter); FileNameExtensionFilter tarGzFileFilter = new FileNameExtensionFilter(Language.translate("Tar.gz-Datei") + " (*.tar.gz)", "tar.gz"); filtersList.add(tarGzFileFilter); return filtersList; }
public static File ShowDlgSaveDiagrama(JComponent form, Diagrama diag) { JFileChooser f = new JFileChooser(); //f.setDialogTitle(Editor.fromConfiguracao.getValor("Controler.dlg.modelo.salvar")); f.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter("BrModelo(bin)", Arquivo.brM3); FileFilter filter2 = new FileNameExtensionFilter("BrModelo(xml)", Arquivo.xml); f.addChoosableFileFilter(filter); f.addChoosableFileFilter(filter2); f.setAcceptAllFileFilterUsed(false); f.setFileFilter(filter); if (dir.isEmpty()) dir = System.getProperty("user.dir"); f.setCurrentDirectory(new File(dir + ".")); f.setDialogTitle(Editor.fromConfiguracao.getValor("Controler.MSG_SAVE_TITLE") + " " + diag.getNomeFormatado()); if (!diag.getNome().isEmpty()){ f.setSelectedFile(new File(diag.getNome())); } //f.setApproveButtonText(Editor.fromConfiguracao.getValor("Controler.dlg.modelo.salvar")); int returnVal = f.showSaveDialog(form); //int returnVal = f.showDialog(form, Editor.fromConfiguracao.getValor("Controler.dlg.modelo.salvar")); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = f.getSelectedFile(); String ext = Arquivo.getExtension(file); if (ext == null) { ext = ""; } String arq = file.getAbsolutePath(); dir = f.getCurrentDirectory().getAbsolutePath(); if (f.getFileFilter().equals(filter) && !Arquivo.brM3.toUpperCase().equals(ext.toUpperCase())) { return new File(arq + "." + Arquivo.brM3); } if (f.getFileFilter().equals(filter2) && !Arquivo.xml.toUpperCase().equals(ext.toUpperCase())) { return new File(arq + "." + Arquivo.xml); } return file; } else { return null; } }
public SaveAs_Action(JFreeChart ed, String text, ImageIcon icon, String desc) { // String desc, Integer mnemonic) { like mnemomnic=KeyEvent.VK_AT // will be updated after "escape" command mode is introduced // (like in "vi") super(text, icon); TEdit = ed; putValue(SHORT_DESCRIPTION, desc); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setFileFilter(new FileNameExtensionFilter("..jpg, ..jpeg, ..png", "jpg", "jpeg","png")); //fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("supported image formats", "jpg", "jpeg","png")); //fileChooser.setAcceptAllFileFilterUsed(true); // putValue(MNEMONIC_KEY, mnemonic); //change it after "escape" is done }
public SaveAs_Action3D(Drawable3D ed, String text, ImageIcon icon, String desc) { // String desc, Integer mnemonic) { like mnemomnic=KeyEvent.VK_AT // will be updated after "escape" command mode is introduced // (like in "vi") super(text, icon); TEdit = ed; putValue(SHORT_DESCRIPTION, desc); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setFileFilter(new FileNameExtensionFilter("..jpg, ..jpeg, ..png", "jpg", "jpeg","png")); //fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("supported image formats", "jpg", "jpeg","png")); //fileChooser.setAcceptAllFileFilterUsed(true); // putValue(MNEMONIC_KEY, mnemonic); //change it after "escape" is done }