List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser()
JFileChooser
pointing to the user's default directory. From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public void openPDF(boolean isInternalR, File pdf, Component comp) throws FileNotFoundException { if (isInternalR) { try {/* ww w. ja v a 2 s. c om*/ Desktop.getDesktop().open(pdf); } catch (Exception ex) { log.info(ex.getMessage()); String msg = "Unable to open PDF format through java. Would you like to save " + pdf.getAbsoluteFile() + " in a new location?"; JOptionPane pane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, null, JOptionPane.YES_OPTION); JDialog dialog = pane.createDialog(comp, "Report PDF"); dialog.setVisible(true); Object choice = pane.getValue(); if (choice.equals(JOptionPane.YES_OPTION)) { jfcFiles = new JFileChooser(); jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int state = jfcFiles.showSaveDialog(comp); if (state == JFileChooser.APPROVE_OPTION) { File file = checkFileExtension(".pdf"); log.info("Opening: " + file.getName() + "."); if (file != null) pdf.renameTo(file); } else { log.info("Open command cancelled by user."); } } } } }
From source file:com.johnson3yo.dubem.plugin.ArtifactWizardMojo.java
private void updateAppServletXml_JFileChooser(String functionName) throws IOException, JDOMException { getLog().info("please select app-servlet.xml from foundation-guiwar "); JFileChooser fc = new JFileChooser(); int retValue = fc.showOpenDialog(new JPanel()); if (retValue == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(f); Element rootNode = document.getRootElement(); List<Element> list = rootNode.getChildren("component-scan", Namespace.getNamespace("http://www.springframework.org/schema/context")); Element e = list.get(0);//from ww w . j a va2s . c o m String cnt = "<context:exclude-filter type=\"regex\" expression=\"pegasus\\.module\\." + functionName.toLowerCase() + "\\..*\" />"; e.addContent(cnt); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()) { @Override public String escapeElementEntities(String str) { return str; } }; Writer writer = new OutputStreamWriter(new FileOutputStream(f), "utf-8"); outputter.output(document, writer); writer.close(); } else { getLog().info("Next time select a file."); System.exit(1); } }
From source file:com.unicorn.co226.ui.patient.AddStudentForm.java
/** * Creates new form AddStudentForm/*from w w w . j av a 2s .c om*/ */ public AddStudentForm(java.awt.Frame parent, boolean modal) { super(parent, modal); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { Logger.getLogger(WaitingList.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(WaitingList.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(WaitingList.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedLookAndFeelException ex) { Logger.getLogger(WaitingList.class.getName()).log(Level.SEVERE, null, ex); } this.parent = parent; dateFormat = new SimpleDateFormat("yyyy-MM-dd"); initComponents(); setLocationRelativeTo(parent); medicalPhotos = new File[] {}; maskFormatterMap = new HashMap<>(); try { maskFormatterMap.put("ENG", new MaskFormatter("E-##-###")); MaskFormatter maskFormatter = new MaskFormatter("A-##-###"); maskFormatter.setValidCharacters("A"); maskFormatterMap.put("ART", maskFormatter); maskFormatterMap.put("SCI", new MaskFormatter("S-##-###")); maskFormatterMap.put("MED", new MaskFormatter("M-##-###")); maskFormatterMap.put("AHS", new MaskFormatter("AHS-##-###")); maskFormatterMap.put("MGT", new MaskFormatter("MGT-##-###")); maskFormatterMap.put("VET", new MaskFormatter("V-##-###")); maskFormatterMap.put("AGR", new MaskFormatter("AG-##-###")); maskFormatterMap.put("DEN", new MaskFormatter("D-##-###")); } catch (ParseException ex) { Logger.getLogger(AddStudentForm.class.getName()).log(Level.SEVERE, null, ex); } //dobDatePicker.setDate(new Date(90, 1, 1)); dobDatePicker.setFormats(dateFormat, new SimpleDateFormat("yyyy"), new SimpleDateFormat("yyyy/MM/dd")); fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); fileChooser.setFileFilter(new FileNameExtensionFilter("Images", "jpg", "png")); try { String nextId = IdGen.getNextId("Patient", "id", "P"); idTextField.setText(nextId); } catch (ClassNotFoundException ex) { Logger.getLogger(AddStudentForm.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(AddStudentForm.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java
static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter, final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) { Window window = GuiUtil.getOwnerWindow(comp); boolean anyButtons = false; final JCheckBox keepOnTop; if (window == null) { keepOnTop = null;/*ww w . j av a 2 s .c o m*/ } else { anyButtons = true; keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true); keepOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.setAlwaysOnTop(keepOnTop.isSelected()); } }); window.setAlwaysOnTop(keepOnTop.isSelected()); // buttons.add(keepOnTop); final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { keepOnTop.setSelected(window.isAlwaysOnTop()); } }; window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); } }); } final JButton cameraButton; if (snapshotter == null) { cameraButton = null; } else { Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) { @Override public void actionPerformed(ActionEvent e) { if (chooser == null) { chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (!f.isFile()) { return true; } String loname = f.getName().toLowerCase(); for (String sfx : imageSuffixes) { if (loname.endsWith(sfx)) { return true; } } return false; } @Override public String getDescription() { return Msg.DESC_IMAGE_FILE(); } }); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) { File file = chooser.getSelectedFile(); snapshotter.execute(file); } } }; ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$ if (icon != null) { cameraAction.putValue(Action.SMALL_ICON, icon); cameraAction.putValue(Action.NAME, null); } anyButtons = true; cameraButton = new JButton(cameraAction); } final JButton refreshButton; if (visToolDataProvider == null) { refreshButton = null; } else { anyButtons = true; refreshButton = new JButton(Msg.ACTION_REFRESH()); ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$ if (icon != null) { refreshButton.setIcon(icon); // don't remove the name } refreshButton.setForeground(Color.RED); refreshButton.setEnabled(false); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (visToolDataProvider.refreshData()) { refreshButton.setEnabled(false); } } }); visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() { @Override public void visToolDataChanged(Object source) { refreshButton.setEnabled(true); } }); } VisToolToolBar toolBar = null; if (anyButtons) { toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton); toolBar.setFloatable(floatable); } return toolBar; }
From source file:JuliaSet3.java
public void save() throws IOException { // Find a factory object for printing Printable objects to PostScript. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; String format = "application/postscript"; StreamPrintServiceFactory factory = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, format)[0];/* ww w . j av a2 s . c o m*/ // Ask the user to select a file and open the selected file JFileChooser chooser = new JFileChooser(); if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; File f = chooser.getSelectedFile(); FileOutputStream out = new FileOutputStream(f); // Obtain a PrintService that prints to that file StreamPrintService service = factory.getPrintService(out); // Do the printing with the method below printToService(service, null); // And close the output file. out.close(); }
From source file:presenter.MainPresenter.java
@Override public void loadEmissionsequenceFromFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); if (fc.showOpenDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try {//ww w.j a v a2s . c o m this.emissionsequenceModel = new EmissionsequenceModel( new Scanner(file).useDelimiter("\\A").next()); this.model = null; this.displayStatus("File was read successfully!"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:cmsc105_mp2.Plot.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try {//from www . ja va 2 s .c o m ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png")); } catch (IOException ex) { System.out.println("Unable to Print!"); } } }
From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java
protected void openConfig() { JFileChooser fileChooser = new JFileChooser(); File file = new File("."); fileChooser.setCurrentDirectory(file); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(new XmlFileFilter()); int showOpenDialog = fileChooser.showOpenDialog(this); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { configHandler.setConfigFile(fileChooser.getSelectedFile().getAbsolutePath()); getProxyConfigPanel().update();//from www.j av a2 s. co m } }
From source file:mineria.UI.java
public UI() { this.setLayout(new GridBagLayout()); Label lblnodatos = new Label("NoDatos: "); Label label = new Label("BD: "); JTextField filename = new JTextField("/Users/eduardomartinez/Documents/mineria/representacion.txt"); JTextField nodatos = new JTextField(); nodatos.setText("500"); JTextField funcion = new JTextField("6"); JTextField individuos = new JTextField("200"); JTextField enteros = new JTextField("1"); JTextField decimales = new JTextField("40"); JTextField variables = new JTextField("6"); JTextField Pc = new JTextField("0.9"); JTextField Pm = new JTextField("0.01"); JTextField generaciones = new JTextField("100"); JTextField minimiza = new JTextField("0"); Label lblfuncion = new Label("funcion: "); Label lblindividuos = new Label("individuos: "); Label lblenteros = new Label("enteros: "); Label lbldecimales = new Label("decimales: "); Label lblvariables = new Label("variables: "); Label lblpc = new Label("Pc: "); Label lblpm = new Label("Pm: "); Label lblgeneraciones = new Label("generaciones: "); Label lblminimiza = new Label("[0 Min/1 Max] : "); /*/* ww w . ja v a 2s. c om*/ FN=funcion; N =individuos; E =bits_enteros; D =bits_decimales; V =variables; Pc=porcentaje_cruza; Pm=porcentaje_muta; G =generaciones; MM=minimiza; */ JButton openBtn = new JButton("Open BD"); JButton ejecutarEGA = new JButton("Ejecutar EGA"); JTextField resultado = new JTextField(); Label fitness = new Label("fitness: "); XYSeriesCollection datosSerie = new XYSeriesCollection(); AGF agf = new AGF(2); EGA ega = new EGA(); JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title "X", // x axis label "Y", // y axis label datosSerie, // data ***-----PROBLEM------*** PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // create and display a frame... ChartPanel panelChart = new ChartPanel(chart); //leer BD openBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //datosSerie.removeAllSeries(); if (filename.getText().length() > 0) { agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText())); createDataset(datosSerie, agf.data, "Datos"); chart.fireChartChanged(); } else { JFileChooser openFile = new JFileChooser(); int rVal = openFile.showOpenDialog(null); if (rVal == JFileChooser.APPROVE_OPTION) { filename.setText(openFile.getSelectedFile().getAbsolutePath()); agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText())); //createDataset(datosSerie, agf.data, "Datos"); //chart.fireChartChanged(); } if (rVal == JFileChooser.CANCEL_OPTION) { filename.setText(""); //dir.setText(""); } } } }); ejecutarEGA.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //datosSerie.removeAllSeries(); if (datosSerie.getSeriesCount() > 1) datosSerie.removeSeries(1); int fn = Integer.parseInt(funcion.getText()); int n = Integer.parseInt(individuos.getText()); int e = Integer.parseInt(enteros.getText()); int d = Integer.parseInt(decimales.getText()); int v = Integer.parseInt(variables.getText()); double pc = Double.parseDouble(Pc.getText()); double pm = Double.parseDouble(Pm.getText()); int g = Integer.parseInt(generaciones.getText()); int mm = Integer.parseInt(minimiza.getText()); ega.setParams(fn, n, e, d, v, pc, pm, g, mm); Resultado res = ega.ejecutarAlgoritmoGenetico(agf); resultado.setText(String.valueOf(res.getFitnessSemental())); res.creaArchivo(); createDataset(datosSerie, res.getFenotipoSemental(), "Centros"); Shape cross = ShapeUtilities.createDiagonalCross(5, 1); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesShape(1, cross); renderer.setSeriesPaint(1, Color.blue); chart.fireChartChanged(); } }); //ejecutar AG GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 2; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblnodatos, gbc); gbc.gridx = 3; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(nodatos, gbc); gbc.gridx = 2; gbc.gridy = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(filename, gbc); gbc.gridx = 3; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(openBtn, gbc); gbc.gridx = 2; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(fitness, gbc); gbc.gridx = 3; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(resultado, gbc); gbc.gridx = 2; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(ejecutarEGA, gbc); //-----------------PARAMETROS gbc.gridx = 0; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblfuncion, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(funcion, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblindividuos, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(individuos, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblenteros, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(enteros, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lbldecimales, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(decimales, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblvariables, gbc); gbc.gridx = 1; gbc.gridy = 4; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(variables, gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblpc, gbc); gbc.gridx = 1; gbc.gridy = 5; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(Pc, gbc); gbc.gridx = 0; gbc.gridy = 6; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblpm, gbc); gbc.gridx = 1; gbc.gridy = 6; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(Pm, gbc); gbc.gridx = 0; gbc.gridy = 7; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblgeneraciones, gbc); gbc.gridx = 1; gbc.gridy = 7; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(generaciones, gbc); gbc.gridx = 0; gbc.gridy = 8; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblminimiza, gbc); gbc.gridx = 1; gbc.gridy = 8; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(minimiza, gbc); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 9; gbc.gridheight = 2; gbc.gridwidth = 4; this.add(panelChart, gbc); this.setTitle("File Chooser"); this.pack(); }
From source file:com.db4o.sync4o.ui.Db4oSyncSourceConfigPanel.java
/** * Default constructor is required by Funambol Admin UI *///from ww w. j a v a 2 s. co m public Db4oSyncSourceConfigPanel() { setupControls(); // now we install our event handlers and we are ready to go... // handler to update the SyncClassConfigTree upon a change // in database file _dbFileLocateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { final JFileChooser fc = new JFileChooser(); int rc = fc.showOpenDialog(Db4oSyncSourceConfigPanel.this); if (JFileChooser.APPROVE_OPTION == rc) { File f = fc.getSelectedFile(); _dbFileValue.setText(f.getPath()); Db4oSyncSourceConfigPanel.this.refreshClassConfigsFromFile(); } } catch (Exception ex) { StringWriter s = new StringWriter(); PrintWriter w = new PrintWriter(s); ex.printStackTrace(w); notifyError(new AdminException(s.toString())); } } }); // handler for the "Add" or "Update" button _confirmButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { validateValues(); updateSyncSource(); if (getState() == STATE_INSERT) { Db4oSyncSourceConfigPanel.this.actionPerformed(new ActionEvent( Db4oSyncSourceConfigPanel.this, ACTION_EVENT_INSERT, event.getActionCommand())); } else { Db4oSyncSourceConfigPanel.this.actionPerformed(new ActionEvent( Db4oSyncSourceConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand())); } } catch (Exception e) { notifyError(new AdminException(e.getMessage())); } } }); }