List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java
/** * Initialize the work package calendar panel inclusive the listeners. *//* w w w . j a v a 2s .com*/ private void init() { List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser())); Collections.sort(userWp, new APLevelComparator()); dataset = createDataset(userWp); chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPopupMenu popup = new JPopupMenu(); JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine())); miSave.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS chooser.setSelectedFile(new File("chart-" //NON-NLS + System.currentTimeMillis() + ".jpg")); int returnVal = chooser.showSaveDialog(reference); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File outfile = chooser.getSelectedFile(); ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(), chartPanel.getWidth()); Controller.showMessage( LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath())); } catch (IOException e) { Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError()); } } } }); popup.add(miSave); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }); chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawWidth(9999); chartPanel.setPreferredSize( new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size())); chartPanel.setPopupMenu(null); this.setLayout(new BorderLayout()); this.removeAll(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(chartPanel, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); GanttRenderer.setDefaultShadowsVisible(false); GanttRenderer.setDefaultBarPainter(new BarPainter() { @Override public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col, final RectangularShape rect, final RectangleEdge arg5) { String wpName = (String) dataset.getColumnKey(col); int i = 0; int spaceCount = 0; while (wpName.charAt(i++) == ' ' && spaceCount < 17) { spaceCount++; } g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15)); g.fill(rect); g.setColor(Color.black); g.setStroke(new BasicStroke()); g.draw(rect); } @Override public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2, final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) { } }); ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() { private static final long serialVersionUID = -6078915091070733812L; public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); } }); }
From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java
private JFileChooser createFileChoser() { JFileChooser fileChooser = new JFileChooser(); // Set the text of the button fileChooser.setApproveButtonText("Import"); // Set the tool tip fileChooser.setApproveButtonToolTipText("Import configuration file"); //Filter .json files FileFilter filter = new FileNameExtensionFilter(".json files", "json"); fileChooser.setFileFilter(filter); fileChooser.setCurrentDirectory(new File(local_path)); return fileChooser; }
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;//from www . 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: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 .ja v a 2s.com 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:table.FrequencyTablePanel.java
public String doSaveAs(File f) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); String filename = ""; int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (!filename.endsWith(".png")) { filename = filename + ".png"; }/* www. ja v a 2s .c o m*/ saveTableAsPNG(new File(filename), this.table, getWidth(), getHeight()); } return filename; }
From source file:CompareFiles.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); // folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter); int returnvalue = folder.showSaveDialog(this); File myfolder = null;//from w w w. ja va 2 s . c o m if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); jLabel2.setText(myfolder.toString()); } }
From source file:colectordedatos.resultados.java
private void Exportar_a_ExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exportar_a_ExcelActionPerformed if (jTable1.getRowCount() > 0) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos de excel", "xls"); chooser.setFileFilter(filter); chooser.setDialogTitle("Guardar archivo"); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { List<JTable> tb = new ArrayList<JTable>(); List<String> nom = new ArrayList<String>(); tb.add(jTable1);// ww w .ja v a 2s .c o m nom.add("Reporte de Errores"); String file = chooser.getSelectedFile().toString().concat(".xls"); try { exportaraexcel e = new exportaraexcel(new File(file), tb, nom); if (e.export()) { JOptionPane.showMessageDialog(null, "Los datos fueron exportados a excel en el directorio seleccionado", "Mensaje de Informacion", JOptionPane.INFORMATION_MESSAGE); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Hubo un error " + e.getMessage(), " Error", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(this, "No hay datos para exportar", "Mensaje de error", JOptionPane.ERROR_MESSAGE); } }
From source file:com.akman.excel.view.frmSelectImage.java
private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSelectImageActionPerformed {//GEN-HEADEREND:event_btnSelectImageActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("Select The Image"); chooser.setMultiSelectionEnabled(false); int res = chooser.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { //Saving file inside the file File file = chooser.getSelectedFile(); // if(!file.equals(filter)) // { // JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE); // return; // } //System.out.println(file.getAbsolutePath()); ImageIcon image = new ImageIcon(file.getAbsolutePath()); fileName = file.getAbsolutePath(); // Get Width And Height of PicLabel Rectangle rect = lblImage.getBounds(); //System.out.println(lblImage.getBounds()); //Scaling the image to fit in the picLabel Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); //converting the image back to image icon to make an acceptable picLabel image = new ImageIcon(scaledimage); lblImage.setIcon(image);/*from w w w . ja v a2 s. co m*/ txtPath.setText(fileName); try { File images = new File(fileName); FileInputStream fis = new FileInputStream(images); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } person_image = bos.toByteArray(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:com.itd.dbmrgdao.TestTime_newscanner.java
@Ignore @org.junit.Test/*from w ww .j a v a2s . co m*/ public void test() throws ParseException { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); String fileName = f.getAbsolutePath(); try { FileReader reader = new FileReader(fileName); BufferedReader br = new BufferedReader(reader); String strLine; Boolean result = updateScanFileRoundUp2(br); br.close(); } catch (IOException ex) { } }
From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java
private void createDataConversionRulesList() { Vector<String> columnNames = new Vector<String>(); columnNames.add(labels.getString("dateConversion.valueRead")); columnNames.add(labels.getString("dateConversion.valueConverted")); dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames); dm.addRow(new Vector<String>()); dm.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1 && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0)) && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) { dm.removeRow(ruleTable.getEditingRow()); }/* ww w .j a v a2s .c o m*/ if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) { if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0)) && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) { dm.addRow(new Vector<String>()); } } if (ruleTable.getEditingColumn() == 1) { if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)) && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) { createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1); } } } }); ruleTable = new JTable(dm); oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames); JButton saveButton = new JButton(labels.getString("saveBtn")); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ruleTable.isEditing()) { ruleTable.getCellEditor().stopCellEditing(); } Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector(); for (int i = 0; i < data.size() - 1; i++) { Vector<String> vector = data.elementAt(i); if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) { createOptionPaneForIsoDate(i, 1); } } xmlFilehandler.saveDataToFile(data, FILENAME); saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"), new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()))); } }); JButton closeButton = new JButton(labels.getString("quit")); closeButton.addActionListener(new ActionListener() { // boolean cancel = true; public void actionPerformed(ActionEvent e) { /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1)); if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) { cancel = showUnsavedChangesDialog(); } else { for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) { for (int j = 0; j <= 1; j++) { System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j)); if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) { cancel = showUnsavedChangesDialog(); } } } } if (cancel) {*/ dispose(); // } } }); JButton downloadButton = new JButton(labels.getString("downloadBtn")); downloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ruleTable.isEditing()) { ruleTable.getCellEditor().stopCellEditing(); } Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector(); File currentLocation = new File(retrieveFromDb.retrieveOpenLocation()); JFileChooser fileChooser = new JFileChooser(currentLocation); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml")); int returnedVal = fileChooser.showSaveDialog(getParent()); if (returnedVal == JFileChooser.APPROVE_OPTION) { String fileName = fileChooser.getSelectedFile().toString(); if (!fileName.endsWith(".xml")) { fileName = fileName + ".xml"; } xmlFilehandler.saveDataToFile(data, fileName); //additionally save data to standard file xmlFilehandler.saveDataToFile(data, FILENAME); saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"), new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()))); } } }); JPanel contentPanel = new JPanel(new BorderLayout()); contentPanel.add(new JScrollPane(ruleTable)); saveMessage = new JLabel(); contentPanel.add(saveMessage, BorderLayout.SOUTH); JPanel buttonPanel = new JPanel(new GridLayout(1, 3)); buttonPanel.add(saveButton); buttonPanel.add(closeButton); buttonPanel.add(downloadButton); JPanel pane = new JPanel(new BorderLayout()); pane.add(contentPanel, BorderLayout.PAGE_START); pane.add(buttonPanel, BorderLayout.PAGE_END); add(pane); }