List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:Simulator.java
private void init() { setSize(400, 400);/*w w w . j av a 2 s. co m*/ treeMap = new JMapViewerTree("Zones"); // Listen to the map viewer for user operations so components will // receive events and update map().addJMVListener(this); setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); JPanel panel = new JPanel(new BorderLayout()); JPanel panelTop = new JPanel(); JPanel panelBottom = new JPanel(); JPanel helpPanel = new JPanel(); mperpLabelName = new JLabel("Meters/Pixels: "); mperpLabelValue = new JLabel(String.format("%s", map().getMeterPerPixel())); zoomLabel = new JLabel("Zoom: "); zoomValue = new JLabel(String.format("%s", map().getZoom())); add(panel, BorderLayout.NORTH); add(helpPanel, BorderLayout.SOUTH); panel.add(panelTop, BorderLayout.NORTH); panel.add(panelBottom, BorderLayout.SOUTH); JLabel helpLabel = new JLabel( "Use right mouse button to move,\n " + "left double click or mouse wheel to zoom."); helpPanel.add(helpLabel); JButton button = new JButton("Fit GPS Markers"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { map().setDisplayToFitMapMarkers(); } }); panelBottom.add(button); JButton openButton = new JButton("Open GPS File"); openButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser openFileDlg = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text"); openFileDlg.setFileFilter(filter); if (openFileDlg.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File file = openFileDlg.getSelectedFile(); //This is where a real application would open the file. System.out.println("Opening: " + file.getAbsolutePath() + "."); plotPoints(file.getAbsolutePath()); } else { System.out.println("Open command cancelled by user."); } } }); panelBottom.add(openButton); final JCheckBox showMapMarker = new JCheckBox("Map markers visible"); showMapMarker.setSelected(map().getMapMarkersVisible()); showMapMarker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { map().setMapMarkerVisible(showMapMarker.isSelected()); } }); panelBottom.add(showMapMarker); panelTop.add(zoomLabel); panelTop.add(zoomValue); panelTop.add(mperpLabelName); panelTop.add(mperpLabelValue); add(treeMap, BorderLayout.CENTER); }
From source file:fll.scheduler.ChooseChallengeDescriptor.java
private void initComponents() { getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1;//from w w w . j av a 2 s .co m gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; final JTextArea instructions = new JTextArea( "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.", 3, 40); instructions.setEditable(false); instructions.setWrapStyleWord(true); instructions.setLineWrap(true); getContentPane().add(instructions, gbc); gbc = new GridBagConstraints(); mCombo = new JComboBox<DescriptionInfo>(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(mCombo, gbc); mCombo.setRenderer(new DescriptionInfoRenderer()); mCombo.setEditable(false); final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo(); for (final DescriptionInfo info : descriptions) { mCombo.addItem(info); } mFileField = new JLabel(); gbc = new GridBagConstraints(); gbc.weightx = 1; getContentPane().add(mFileField, gbc); final JButton chooseButton = new JButton("Choose File"); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(chooseButton, gbc); chooseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mFileField.setText(null); final JFileChooser fileChooser = new JFileChooser(); final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" }); fileChooser.setFileFilter(filter); final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File selectedFile = fileChooser.getSelectedFile(); mFileField.setText(selectedFile.getAbsolutePath()); } } }); final Box buttonPanel = new Box(BoxLayout.X_AXIS); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(buttonPanel, gbc); buttonPanel.add(Box.createHorizontalGlue()); final JButton ok = new JButton("Ok"); buttonPanel.add(ok); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { // use the selected description if nothing is entered in the file box final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex()); if (null != descriptionInfo) { mSelected = descriptionInfo.getURL(); } final String text = mFileField.getText(); if (!StringUtils.isEmpty(text)) { final File file = new File(text); if (file.exists()) { try { mSelected = file.toURI().toURL(); } catch (final MalformedURLException e) { throw new FLLInternalException("Can't turn file into URL?", e); } } } setVisible(false); } }); final JButton cancel = new JButton("Cancel"); buttonPanel.add(cancel); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mSelected = null; setVisible(false); } }); pack(); }
From source file:carolina.pegaLatLong.LatLong.java
private void geraCsv(List<InformacaoGerada> gerados) throws IOException { JFileChooser escolha = new JFileChooser(); escolha.setAcceptAllFileFilterUsed(false); escolha.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int i = escolha.showSaveDialog(null); if (i != 1) { System.err.println(escolha.getSelectedFile().getPath() + "\\teste.txt"); String caminho = escolha.getSelectedFile().getPath(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(caminho + "\\teste.csv"), StandardCharsets.ISO_8859_1)); //FileWriter arquivo = new FileWriter(caminho + "\\teste.csv"); //PrintWriter writer = new PrintWriter(arquivo); writer.write("Endereco;Latitude;Longitude"); writer.newLine();/*from ww w . j av a2 s.c o m*/ gerados.stream().forEach((gerado) -> { try { System.err.println(gerado.getEnderecoFormatado() + ";" + gerado.getLatitude() + ";" + gerado.getLongitude() + "\n"); writer.write(gerado.getEnderecoFormatado() + ";" + gerado.getLatitude() + ";" + gerado.getLongitude()); writer.newLine(); } catch (IOException ex) { System.err.println("Erro"); } }); writer.close(); JOptionPane.showMessageDialog(null, "Finalizado!"); } }
From source file:dialog.DialogFunctionUser.java
private void btnUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUploadActionPerformed JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showDialog(null, "Upload avatar"); if (result == JFileChooser.APPROVE_OPTION) { mAvatar = fileChooser.getSelectedFile(); if (!PictureUtil.isPicture(mAvatar)) { JOptionPane.showMessageDialog(null, "?y khng phi l nh", "Error", JOptionPane.ERROR_MESSAGE); mAvatar = null;//from w w w .j av a 2 s .co m } else { PictureUtil.setPicture(lbAvatar, mAvatar); } } }
From source file:InterfaceModule.JRobert.java
private void exportToFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportToFileActionPerformed JFileChooser chooser = new JFileChooser(System.getProperty("user.dir") + "/saves/"); chooser.setDialogTitle("Salve o relatrio"); File fileToSave;/*from www.ja va 2 s.com*/ int selection = chooser.showSaveDialog(this); if (selection == JFileChooser.APPROVE_OPTION) fileToSave = chooser.getSelectedFile(); else return; try { FileWriter fr = new FileWriter(fileToSave); BufferedWriter bw = new BufferedWriter(fr); String[] text = jTextArea1.getText().split("\n"); for (String s : text) { bw.write(s); bw.newLine(); } bw.close(); fr.close(); } catch (IOException e) { } }
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;/*from w w w .jav a 2 s .com*/ 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:aurelienribon.gdxsetupui.ui.panels.ConfigUpdatePanel.java
private void browse() { String path = Ctx.cfgUpdate.destinationPath; JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this); JFileChooser chooser = new JFileChooser(new File(path)); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select the core project folder"); if (chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { pathField.setText(chooser.getSelectedFile().getPath()); updateConfig(chooser.getSelectedFile()); updatePanel();//from w ww. j a v a2 s .c om } }
From source file:carolina.pegaLatLong.LatLong.java
private void btnCarregaTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCarregaTxtActionPerformed // TODO add your handling code here JFileChooser escolhe = new JFileChooser(); // escolhe.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // escolhe.setAcceptAllFileFilterUsed(false); int i = escolhe.showOpenDialog(null); if (i != 1) { String caminho = escolhe.getSelectedFile().getPath(); edtTxt.setText(escolhe.getSelectedFile().getName()); btnCarregaTxt.setEnabled(false); new Thread(new Runnable() { @Override/* ww w .ja va 2 s . c om*/ public void run() { try { buscaLtLong(carregaRetorna(caminho)); } catch (IOException ex) { Logger.getLogger(LatLong.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(LatLong.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } }
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;// w w w . j a v a2s. 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:ca.uhn.hl7v2.testpanel.ui.conn.Hl7ConnectionPanel.java
private static void chooseKeystore(Component theParentController, JTextField theTextbox) { String directory = Prefs.getInstance().getInterfaceHohSecurityKeystoreDirectory(); directory = StringUtils.defaultString(directory, "."); JFileChooser chooser = new JFileChooser(directory); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setDialogTitle("Select a Java Keystore"); int result = chooser.showOpenDialog(theParentController); if (result == JFileChooser.APPROVE_OPTION) { Prefs.getInstance().setInterfaceHohSecurityKeystoreDirectory(chooser.getSelectedFile().getParent()); theTextbox.setText(chooser.getSelectedFile().getAbsolutePath()); }/*from w ww. j av a 2s .c o m*/ }