List of usage examples for javax.swing JFileChooser setDialogType
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.OPEN_DIALOG", "JFileChooser.SAVE_DIALOG", "JFileChooser.CUSTOM_DIALOG" }, description = "The type (open, save, custom) of the JFileChooser.") public void setDialogType(int dialogType)
From source file:simMPLS.ui.simulator.JVentanaHija.java
/** * Este mtodo se encarga de controlar que todo ocurre como debe con respecto al * escenario, cuando se pulsa en el men principal la opcin de "Guardar como..." * @since 1.0/*from ww w . ja va 2 s .co m*/ */ public void gestionarGuardarComo() { anotarDatosDeEscenario(); JFileChooser dialogoGuardar = new JFileChooser(); dialogoGuardar.setFileFilter(new JOSMFilter()); dialogoGuardar.setDialogType(JFileChooser.CUSTOM_DIALOG); dialogoGuardar.setApproveButtonMnemonic('A'); dialogoGuardar.setApproveButtonText(java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes") .getString("JVentanaHija.DialogoGuardar.OK")); dialogoGuardar.setDialogTitle(java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes") .getString("JVentanaHija.DialogoGuardar.Almacenar") + this.getTitle() + java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString("-")); dialogoGuardar.setAcceptAllFileFilterUsed(false); dialogoGuardar.setSelectedFile(new File(this.getTitle())); dialogoGuardar.setFileSelectionMode(JFileChooser.FILES_ONLY); int resultado = dialogoGuardar.showSaveDialog(VentanaPadre); if (resultado == JFileChooser.APPROVE_OPTION) { String ext = null; String nombreFich = dialogoGuardar.getSelectedFile().getPath(); int i = nombreFich.lastIndexOf('.'); if (i > 0 && i < nombreFich.length() - 1) { ext = nombreFich.substring(i + 1).toLowerCase(); } if (ext == null) { nombreFich += java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString(".osm"); } else { if (!ext.equals( java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString("osm"))) { nombreFich += java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes") .getString(".osm"); } } dialogoGuardar.setSelectedFile(new File(nombreFich)); escenario.setFile(dialogoGuardar.getSelectedFile()); this.escenario.setSaved(true); this.setTitle(this.escenario.obtenerFichero().getName()); TOSMSaver almacenador = new TOSMSaver(escenario); // JVentanaBooleana vb = new JVentanaBooleana(this.VentanaPadre, true, this.dispensadorDeImagenes); // vb.mostrarPregunta(java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString("JVentanaHija.PreguntaEmpotrarCRC")); // vb.show(); // boolean conCRC = vb.obtenerRespuesta(); // boolean correcto = almacenador.save(escenario.obtenerFichero(), conCRC); JVentanaBooleana vb = new JVentanaBooleana(this.VentanaPadre, true, this.dispensadorDeImagenes); vb.mostrarPregunta("Do you want to save the routing tables ?"); vb.show(); boolean saveTables = vb.obtenerRespuesta(); boolean correcto = almacenador.save(escenario.obtenerFichero(), false, saveTables); if (correcto) { this.escenario.setModified(false); this.escenario.setSaved(true); } } }
From source file:com.hexidec.ekit.EkitCore.java
/** * Method for obtaining a File for input/output using a JFileChooser dialog *///w w w .j a v a2s .com private File getFileFromChooser(String startDir, int dialogType, String[] exts, String desc) { JFileChooser jfileDialog = new JFileChooser(startDir); jfileDialog.setDialogType(dialogType); jfileDialog.setFileFilter(new MutableFilter(exts, desc)); int optionSelected = JFileChooser.CANCEL_OPTION; if (dialogType == JFileChooser.OPEN_DIALOG) { optionSelected = jfileDialog.showOpenDialog(this); } else if (dialogType == JFileChooser.SAVE_DIALOG) { optionSelected = jfileDialog.showSaveDialog(this); } else // default to an OPEN_DIALOG { optionSelected = jfileDialog.showOpenDialog(this); } if (optionSelected == JFileChooser.APPROVE_OPTION) { return jfileDialog.getSelectedFile(); } return (File) null; }
From source file:com.pianobakery.complsa.MainGui.java
public void createNewProjectFolder() { try {//from w ww . ja v a 2 s .co m JFrame frame = new JFrame(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(openFolder); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Create Folder"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setSelectedFile(new File("Workingfile")); frame.getContentPane().add(chooser); chooser.setApproveButtonText("Choose"); //Disable Save as ArrayList<JPanel> jpanels = new ArrayList<JPanel>(); for (Component c : chooser.getComponents()) { if (c instanceof JPanel) { jpanels.add((JPanel) c); } } jpanels.get(0).getComponent(0).setVisible(false); frame.pack(); frame.setLocationRelativeTo(null); int whatChoose = chooser.showSaveDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { File selFile = chooser.getSelectedFile(); File currDir = chooser.getCurrentDirectory(); Path parentDir = Paths.get(chooser.getCurrentDirectory().getParent()); String parentDirName = parentDir.getFileName().toString(); logger.debug("Chooser SelectedFile: " + selFile.toString()); logger.debug("getCurrentDirectory(): " + currDir.toString()); logger.debug("Chooser parentdir: " + parentDir); logger.debug("Parentdirname: " + parentDirName); if (selFile.getName().equals(parentDirName)) { wDir = currDir; } else { wDir = chooser.getSelectedFile(); } logger.debug("WDIR is: " + wDir.toString()); wDirText.setText(wDir.toString()); enableUIElements(true); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); logger.debug("Exeption: " + ex.toString()); } }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
private void buttonExportToCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExportToCSVActionPerformed final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(getLocaleMessage("save.statictic")); fc.setFileFilter(new FileFilter() { @Override/*from w w w . j a v a 2 s . c o m*/ public boolean accept(File f) { return !f.isFile() || f.getAbsolutePath().toLowerCase().endsWith(".csv"); } @Override public String getDescription() { return getLocaleMessage("files.type.csv"); } }); //fc.setCurrentDirectory(new File("config")); //fc.setSelectedFile(new File(configuration.getSystemName())); fc.setDialogType(JFileChooser.SAVE_DIALOG); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final File file; //This is where a real application would open the file. if (!fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".csv")) { file = new File(fc.getSelectedFile().getAbsoluteFile() + ".csv"); } else { file = fc.getSelectedFile(); } Spring.getInstance().getHt().getSessionFactory().openSession().doWork((Connection connection) -> { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dateChooserStartCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); final String std = Uses.format_for_rep.format(gc.getTime()); gc.setTime(dateChooserFinishCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); gc.add(GregorianCalendar.HOUR, 24); final String find = Uses.format_for_rep.format(gc.getTime()); final String sql = " SELECT " + " s.client_id as id, " + " concat(c.service_prefix , c.number) as num, " + " c.input_data as inp, " + " DATE_FORMAT(s.client_stand_time, '%d.%m.%y %H:%i') as stnd, " + " sv.name as srv, " + " DATE_FORMAT(s.user_start_time, '%d.%m.%y %H:%i') as strt, " + " DATE_FORMAT(s.user_finish_time, '%d.%m.%y %H:%i') as fin, " + " u.name as usr, " + " s.client_wait_period as wt, " + " s.user_work_period as wrk, " + " IFNULL(r.name, '') as res " + " FROM statistic s left join results r on s.results_id=r.id, clients c, users u, services sv " + " WHERE s.client_id=c.id and s.user_id=u.id and s.service_id=sv.id " + " and s.client_stand_time>='" + std + "' and s.client_stand_time<='" + find + "'"; try (ResultSet set = connection.createStatement().executeQuery(sql)) { final Writer writer; try { writer = new OutputStreamWriter(new FileOutputStream(file), "cp1251").append(""); writer.append(""); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.number")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.data")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.stand_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.service_name")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.start_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.finish_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.user")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.wait")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.work")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.result")); writer.append('\n'); while (set.next()) { writer.append(set.getString("id")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("num")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("inp")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("stnd")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append( set.getString("srv").replace(cbSeparateCSV.getSelectedItem().toString(), " ")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("strt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("fin")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("usr")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wrk")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("res")); writer.append('\n'); } //generate whatever data you want writer.flush(); writer.close(); } catch (IOException ex) { throw new ClientException(ex); } } JOptionPane.showMessageDialog(fc, getLocaleMessage("stat.saved"), getLocaleMessage("stat.saving"), JOptionPane.INFORMATION_MESSAGE); }); } }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showJFileChooser(Component target, boolean open) { JFileChooser chooser = new JFileChooser(previousDirectory); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(filter);//w ww . ja v a 2 s. c om chooser.setAcceptAllFileFilterUsed(filter == null); chooser.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG); int selection = chooser.showDialog(target, null); switch (selection) { case JFileChooser.APPROVE_OPTION: this.selected = chooser.getSelectedFile(); if (rememberPreviousLocation) { previousDirectory = chooser.getCurrentDirectory(); } return Result.APPROVE; case JFileChooser.CANCEL_OPTION: case JFileChooser.ERROR_OPTION: default: this.selected = null; return Result.ERROR; } }
From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java
/** * An action method that pops up a file chooser dialog to pick the * generation directory.//from w w w . j a v a 2 s. c o m */ public void selectOutputFolderAction() { JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder(); String currentDir = outputFolder.getText(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); // guess start directory if (!Util.isEmptyString(currentDir)) { chooser.setCurrentDirectory(new File(currentDir)); } else { FSPath lastDir = Application.getInstance().getFrameController().getLastDirectory(); lastDir.updateChooser(chooser); } int result = chooser.showOpenDialog(getView()); if (result == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); // update model String path = selected.getAbsolutePath(); outputFolder.setText(path); setOutputPath(path); } }
From source file:org.apache.cayenne.modeler.dialog.db.merge.MergerOptions.java
/** * Allows user to save generated SQL in a file. *//*w w w . j ava2 s . co m*/ public void storeSQLAction() { JFileChooser fc = new JFileChooser(); fc.setDialogType(JFileChooser.SAVE_DIALOG); fc.setDialogTitle("Save SQL Script"); Resource projectDir = getApplication().getProject().getConfigurationResource(); if (projectDir != null) { fc.setCurrentDirectory(new File(projectDir.getURL().getPath())); } if (fc.showSaveDialog(getView()) == JFileChooser.APPROVE_OPTION) { refreshGeneratorAction(); try { File file = fc.getSelectedFile(); FileWriter fw = new FileWriter(file); PrintWriter pw = new PrintWriter(fw); pw.print(textForSQL); pw.flush(); pw.close(); } catch (IOException ex) { reportError("Error Saving SQL", ex); } } }
From source file:org.apache.cayenne.modeler.dialog.pref.ClasspathPreferences.java
protected void chooseClassEntry(FileFilter filter, String title, int selectionMode) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(selectionMode); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setAcceptAllFileFilterUsed(true); getLastDirectory().updateChooser(chooser); if (filter != null) { chooser.addChoosableFileFilter(filter); }//from w w w . j ava 2 s .com chooser.setDialogTitle(title); File selected = null; int result = chooser.showOpenDialog(view); if (result == JFileChooser.APPROVE_OPTION) { selected = chooser.getSelectedFile(); } if (selected != null) { if (!classPathEntries.contains(selected.getAbsolutePath())) { // store last dir in preferences getLastDirectory().updateFromChooser(chooser); int len = classPathEntries.size(); int key = ++counter; String value = selected.getAbsolutePath(); addChangedPreferences(Integer.toString(key), value); classPathEntries.add(value); classPathKeys.add(Integer.toString(key)); tableModel.fireTableRowsInserted(len, len); } } }
From source file:org.geopublishing.geopublisher.GpUtil.java
/** * Performs a file OPEN choose as a fallback * /*from w ww .j a va 2s . c o m*/ * @param parent * component for the dialog (can be {@code null}) * @param startFolder * start folder for the chooser (if {@code null} "/" is used) * @param filter * defines which files can be selected. Only the last filter in * the list will be offered due to limitations * @return {@code null} if the dialog was not approved */ public static File chooseFileOpenFallback(Component parent, File startFolder, String title, FileExtensionFilter... filters) { if (startFolder == null) startFolder = new File("/"); if (startFolder.isFile()) startFolder = startFolder.getParentFile(); JFileChooser chooser = new JFileChooser(startFolder); chooser.setDialogType(JFileChooser.OPEN_DIALOG); if (filters != null) { chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(filters[0].toJFileChooserFilter()); } if (title != null) chooser.setDialogTitle(title); int ret = chooser.showOpenDialog(parent); if (ret == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); return null; }
From source file:org.neo4j.desktop.ui.BrowseForDatabaseActionListener.java
private File fileSelection() { File selectedFile = null;//from ww w.j a v a 2 s . c o m JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(DIRECTORIES_ONLY); fileChooser.setCurrentDirectory(new File(directoryDisplay.getText())); fileChooser.setDialogTitle("Select database"); fileChooser.setDialogType(CUSTOM_DIALOG); int choice = fileChooser.showOpenDialog(frame); if (choice == APPROVE_OPTION) { selectedFile = fileChooser.getSelectedFile(); } return selectedFile; }