List of usage examples for javax.swing JFileChooser showDialog
@SuppressWarnings("deprecation") public int showDialog(Component parent, String approveButtonText) throws HeadlessException
From source file:it.unibas.spicygui.controllo.datasource.ActionAddTargetInstanceXml.java
@Override public void performAction() { JFileChooser chooser = vista.getFileChooserApriXML(); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); InstancesTopComponent viewInstancesTopComponent = scenario.getInstancesTopComponent(); File file;// ww w . j a v a2 s .c o m int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.LOAD)); if (returnVal == JFileChooser.APPROVE_OPTION) if (scenario.getMappingTask().getSourceProxy().getType().equalsIgnoreCase("XML")) { try { file = chooser.getSelectedFile(); DAOXsd daoXsd = new DAOXsd(); daoXsd.loadInstance(mappingTask.getTargetProxy(), file.getAbsolutePath()); scenario.addTargetInstance(file.getAbsolutePath()); if (!viewInstancesTopComponent.isRipulito()) { //viewInstancesTopComponent.clearTarget(); viewInstancesTopComponent.createTargetInstanceTree(); viewInstancesTopComponent.requestActive(); StatusDisplayer.getDefault() .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.ADD_INSTANCE_OK)); } } catch (DAOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } } else { DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.CSV_INST_NOTIF), DialogDescriptor.ERROR_MESSAGE)); } }
From source file:it.unibas.spicygui.controllo.datasource.ActionAddSourceInstanceXml.java
@Override public void performAction() { JFileChooser chooser = vista.getFileChooserApriXML(); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); InstancesTopComponent viewInstancesTopComponent = scenario.getInstancesTopComponent(); File file;/*from w w w .ja va 2 s . co m*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.LOAD)); if (returnVal == JFileChooser.APPROVE_OPTION) if (scenario.getMappingTask().getSourceProxy().getType().equalsIgnoreCase("XML")) { try { file = chooser.getSelectedFile(); DAOXsd daoXsd = new DAOXsd(); daoXsd.loadInstance(mappingTask.getSourceProxy(), file.getAbsolutePath()); scenario.addSourceInstance(file.getAbsolutePath()); if (!viewInstancesTopComponent.isRipulito()) { viewInstancesTopComponent.clearSource(); viewInstancesTopComponent.createSourceInstanceTree(); viewInstancesTopComponent.requestActive(); StatusDisplayer.getDefault() .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.ADD_INSTANCE_OK)); } } catch (DAOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } } else { DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.CSV_INST_NOTIF), DialogDescriptor.ERROR_MESSAGE)); } }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Selects a file (path).//from ww w. j a v a 2 s.c o m * * @param lang * language * @return chosen file path */ public String selectFile(NatLang lang) { JFileChooser fileChooser = new JFileChooser(lastFilePath); fileChooser.setLocale(lang.getLocale()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setToolTipText(lang.getText("selectFile")); fileChooser.setDialogTitle(lang.getText("selectFile")); fileChooser.showDialog(null, lang.getText("selectFile")); File f = fileChooser.getSelectedFile(); if (f != null) { lastFilePath = f.getPath(); return lastFilePath; } else { return null; } }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Selects a directory (path)./* w w w.j av a2 s . c om*/ * * @param lang * language * @return chosen directory path */ public String selectDirectory(NatLang lang) { JFileChooser dirChooser = new JFileChooser(lastDirectoryPath); dirChooser.setLocale(lang.getLocale()); dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); dirChooser.setToolTipText(lang.getText("selectDirectory")); dirChooser.setDialogTitle(lang.getText("selectDirectory")); dirChooser.showDialog(null, lang.getText("selectDirectory")); File f = dirChooser.getSelectedFile(); if (f != null) { lastDirectoryPath = f.getPath(); return lastDirectoryPath; } else { return null; } }
From source file:net.sf.keystore_explorer.gui.actions.SignCsrAction.java
private File chooseCsrFile() { JFileChooser chooser = FileChooserFactory.getCsrFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("SignCsrAction.ChooseCsr.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(frame, res.getString("SignCsrAction.ChooseCsr.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File importFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(importFile); return importFile; }//from w ww. j a v a2s. c o m return null; }
From source file:utilities.GraphViewer.java
public void actionPerformed(ActionEvent e) { // Evenement button parcourir if (e.getSource() == this.parcourir) { JFileChooser fileopen = new JFileChooser(); FiltreSimple filter = new FiltreSimple("Fichier res", "res"); fileopen.addChoosableFileFilter(filter); int ret = fileopen.showDialog(null, "Open file"); if (ret == JFileChooser.APPROVE_OPTION) { File file = fileopen.getSelectedFile(); System.out.println(file.getPath()); this.addSensor(file.getPath()); }// w ww.j a v a2 s .com } else { JCheckBox check; for (int i = 0; i < this.sensors.size(); i++) { check = sensors.get(i); if (e.getSource() == check) { if (check.isSelected()) { if (!this.isExist(check)) { String s = check.getText(); s = s.substring(1); ajouterFichier(this.db.getPath(check.getText())); sensors1.addLast(check); this.graphe.revalidate(); } } else { this.removeSerie(check.getText()); sensors1.remove(check); this.graphe.revalidate(); } break; } } } }
From source file:net.sf.keystore_explorer.gui.actions.ExamineFileAction.java
private File chooseFile() { JFileChooser chooser = FileChooserFactory.getCertFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("ExamineFileAction.ExamineFile.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(frame, res.getString("ExamineFileAction.ExamineFile.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File openFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(openFile); return openFile; }//from w w w . ja v a 2s . c om return null; }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCoverage.java
public CCSHubSelectionCoverage(final String title, List<Double> coverSourceNum) { super(title); this.title = title; final XYDataset dataset = createDataset(coverSourceNum); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;//ww w. j av a 2 s .co m public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCo2Coverage.java
public CCSHubSelectionCo2Coverage(final String title, List<Double> coverSourceNum) { super(title); this.title = title; final XYDataset dataset = createDataset(coverSourceNum); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;//from w w w. jav a 2 s . c o m public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCost.java
public CCSHubSelectionCost(final String title, Map<Integer, List<Double>> data) { super(title); this.title = title; final XYDataset dataset = createDataset(data); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;/* ww w . j a v a 2s . c om*/ public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }