List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter
public FileNameExtensionFilter(String description, String... extensions)
From source file:com.openbravo.pos.imports.JPanelCSVImport.java
private void jbtnDbDriverLibActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDbDriverLibActionPerformed resetFields();// w w w.j a v a 2 s.co m // If CSV.last_file is null then use c:\ otherwise use saved dir JFileChooser chooser = new JFileChooser(last_folder == null ? "C:\\" : last_folder); FileNameExtensionFilter filter = new FileNameExtensionFilter("csv files", "csv"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File csvFile = chooser.getSelectedFile(); // check if a file was selected if (csvFile == null) { return; } File current_folder = chooser.getCurrentDirectory(); // If we have a file lets save the directory for later use if it's different from the old if (last_folder == null || !last_folder.equals(current_folder.getAbsolutePath())) { AppConfig CSVConfig = new AppConfig(config_file); CSVConfig.load(); CSVConfig.setProperty("CSV.last_folder", current_folder.getAbsolutePath()); last_folder = current_folder.getAbsolutePath(); try { CSVConfig.save(); } catch (IOException ex) { Logger.getLogger(JPanelCSVImport.class.getName()).log(Level.SEVERE, null, ex); } } String csv = csvFile.getName(); if (!(csv.trim().equals(""))) { csvFileName = csvFile.getAbsolutePath(); jFileName.setText(csvFileName); } }
From source file:client.welcome2.java
private void SupplierUploadContractButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupplierUploadContractButtonActionPerformed try {/*from w w w .ja va 2 s . c o m*/ JFileChooser supplier_chooser = new JFileChooser(); supplier_chooser.setDialogTitle("Open a File"); FileNameExtensionFilter docFilter = new FileNameExtensionFilter("Word Files", "docx"); FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter("PDF Documents", "pdf"); supplier_chooser.addChoosableFileFilter(docFilter); supplier_chooser.addChoosableFileFilter(pdfFilter); int result = supplier_chooser.showOpenDialog(null); if (result == 0) { File f = supplier_chooser.getSelectedFile(); filename_supplier = f.getAbsolutePath(); SupplierUploadText.setText(filename_supplier); f.getAbsoluteFile(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:client.welcome2.java
private void SupplierUploadContractButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupplierUploadContractButton1ActionPerformed try {// w ww . ja v a2 s.c o m JFileChooser supplier_chooser = new JFileChooser(); supplier_chooser.setDialogTitle("Open a File"); FileNameExtensionFilter docFilter = new FileNameExtensionFilter("Word Files", "docx"); FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter("PDF Documents", "pdf"); supplier_chooser.addChoosableFileFilter(docFilter); supplier_chooser.addChoosableFileFilter(pdfFilter); int result = supplier_chooser.showOpenDialog(null); if (result == 0) { File f = supplier_chooser.getSelectedFile(); supplier_filename_update = f.getAbsolutePath(); SupplierUploadText1.setText(supplier_filename_update); f.getAbsoluteFile(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:de.bfs.radon.omsimulation.gui.OMPanelSimulation.java
/** * Initialises the interface of the simulation panel. *///from w ww. jav a2 s . c om protected void initialize() { setLayout(null); btnStart = new JButton("Start"); btnStart.addActionListener(this); btnStart.setBounds(616, 326, 124, 23); btnStart.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(btnStart); progressBarSimulation = new JProgressBar(); progressBarSimulation.setBounds(10, 475, 730, 23); progressBarSimulation.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); progressBarSimulation.setVisible(false); add(progressBarSimulation); lblSelectOmbfile = new JLabel("Open OMB-File"); lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectOmbfile.setBounds(10, 36, 132, 14); add(lblSelectOmbfile); lblOmsFile = new JLabel("Save OMS-File"); lblOmsFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblOmsFile.setBounds(174, 272, 120, 14); add(lblOmsFile); txtOmsFile = new JTextField(); txtOmsFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmsFile(txtOmsFile.getText()); } }); txtOmsFile.setBounds(304, 269, 302, 20); txtOmsFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(txtOmsFile); txtOmsFile.setColumns(10); btnBrowseOms = new JButton("Browse"); btnBrowseOms.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String oms; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("oms")) { oms = ""; } else { oms = ".oms"; } txtOmsFile.setText(file.getAbsolutePath() + oms); setOmsFile(file.getAbsolutePath() + oms); } } }); btnBrowseOms.setBounds(616, 268, 124, 23); btnBrowseOms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(btnBrowseOms); lblWarning = new JLabel("This could take a while, grab a coffee!"); lblWarning.setBounds(421, 94, 319, 15); lblWarning.setForeground(new Color(255, 0, 0, 255)); lblWarning.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblWarning); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setBounds(10, 65, 132, 14); lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblSelectProject); lblSimulationType = new JLabel("Simulation Type"); lblSimulationType.setBounds(10, 94, 132, 14); lblSimulationType.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblSimulationType); lblCampaigns = new JLabel("campaigns"); lblCampaigns.setBounds(421, 122, 185, 14); lblCampaigns.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblCampaigns); lblRatio = new JLabel("Ratio"); lblRatio.setBounds(174, 152, 44, 14); lblRatio.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblRatio); lblPercent = new JLabel("%"); lblPercent.setBounds(246, 302, 360, 14); lblPercent.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblPercent); spnrRandomCampaigns = new JSpinner(); spnrRandomCampaigns.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { setRandomCampaigns((Integer) spnrRandomCampaigns.getValue()); } }); spnrRandomCampaigns.setModel(new SpinnerNumberModel(10000, 10, 100000, 1)); spnrRandomCampaigns.setBounds(304, 119, 107, 22); spnrRandomCampaigns.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRandomCampaigns); spnrRatio3 = new JSpinner(); spnrRatio3.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio3.isSelected()) { setRatio3((Integer) spnrRatio3.getValue()); } else { setRatio3(0); spnrRatio3.setEnabled(false); } } }); spnrRatio3.setModel(new SpinnerNumberModel(2, 0, 10000, 1)); spnrRatio3.setBounds(330, 149, 81, 22); spnrRatio3.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio3); spnrRatio4 = new JSpinner(); spnrRatio4.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio4.isSelected()) { setRatio4((Integer) spnrRatio4.getValue()); } else { setRatio4(0); spnrRatio4.setEnabled(false); } } }); spnrRatio4.setModel(new SpinnerNumberModel(5, 0, 10000, 1)); spnrRatio4.setBounds(330, 179, 81, 22); spnrRatio4.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio4); spnrRatio5 = new JSpinner(); spnrRatio5.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio5.isSelected()) { setRatio5((Integer) spnrRatio5.getValue()); } else { setRatio5(0); spnrRatio5.setEnabled(false); } } }); spnrRatio5.setModel(new SpinnerNumberModel(20, 0, 10000, 1)); spnrRatio5.setBounds(330, 209, 81, 22); spnrRatio5.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio5); spnrRatio6 = new JSpinner(); spnrRatio6.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio6.isSelected()) { setRatio6((Integer) spnrRatio6.getValue()); } else { setRatio6(0); spnrRatio6.setEnabled(false); } } }); spnrRatio6.setModel(new SpinnerNumberModel(73, 0, 10000, 1)); spnrRatio6.setBounds(330, 239, 81, 22); spnrRatio6.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio6); spnrRandomNoise = new JSpinner(); spnrRandomNoise.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRandomNoise.isSelected()) { setRandomNoise((Integer) spnrRandomNoise.getValue()); } else { setRandomNoise(0); spnrRandomNoise.setEnabled(false); } } }); spnrRandomNoise.setModel(new SpinnerNumberModel(5, 0, 20, 1)); spnrRandomNoise.setBounds(153, 299, 83, 22); spnrRandomNoise.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRandomNoise); chckbxRatio3 = new JCheckBox("3 of 6"); chckbxRatio3.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio3.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio3.setEnabled(true); } } else { setRatio3(0); spnrRatio3.setEnabled(false); } } }); chckbxRatio3.setBounds(237, 149, 80, 23); chckbxRatio3.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio3); chckbxRatio4 = new JCheckBox("4 of 6"); chckbxRatio4.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio4.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio4.setEnabled(true); } } else { setRatio4(0); spnrRatio4.setEnabled(false); } } }); chckbxRatio4.setBounds(237, 179, 80, 23); chckbxRatio4.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio4); chckbxRatio5 = new JCheckBox("5 of 6"); chckbxRatio5.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio5.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio5.setEnabled(true); } } else { setRatio5(0); spnrRatio5.setEnabled(false); } } }); chckbxRatio5.setBounds(237, 209, 80, 23); chckbxRatio5.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio5); chckbxRatio6 = new JCheckBox("6 of 6"); chckbxRatio6.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio6.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio6.setEnabled(true); } } else { setRatio6(0); spnrRatio6.setEnabled(false); } } }); chckbxRatio6.setBounds(237, 239, 80, 23); chckbxRatio6.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio6); chckbxRandomNoise = new JCheckBox("Random noise"); chckbxRandomNoise.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRandomNoise.isSelected()) { if (chckbxRandomNoise.isEnabled()) { spnrRandomNoise.setEnabled(true); } } else { setRandomNoise(0); spnrRandomNoise.setEnabled(false); } } }); chckbxRandomNoise.setBounds(10, 299, 137, 23); chckbxRandomNoise.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRandomNoise); btnRefresh = new JButton("Load"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxSelectProject.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); progressBarSimulation.setVisible(true); progressBarSimulation.setStringPainted(true); progressBarSimulation.setIndeterminate(true); refreshTask = new Refresh(); refreshTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnRefresh.setBounds(616, 61, 124, 23); btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(btnRefresh); lblHelp = new JLabel( "Select an OMB-Object file to run simulations. Limited random simulations can be saved as OMS-Simulation files used for analysis."); lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblHelp.setForeground(Color.GRAY); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); txtOmbFile.setColumns(10); btnBrowseOmb = new JButton("Browse"); btnBrowseOmb.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnBrowseOmb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); btnBrowseOmb.setBounds(616, 32, 124, 23); add(btnBrowseOmb); rdbtnSystematic = new JRadioButton("Systematic all campaigns"); rdbtnSystematic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (rdbtnSystematic.isSelected()) { setSystematic(true); rdbtnRandom.setSelected(false); chckbxRatio6.setEnabled(false); chckbxRatio5.setEnabled(false); chckbxRatio4.setEnabled(false); chckbxRatio3.setEnabled(false); spnrRatio6.setEnabled(false); spnrRatio5.setEnabled(false); spnrRatio4.setEnabled(false); spnrRatio3.setEnabled(false); spnrRandomCampaigns.setEnabled(false); lblRatio.setEnabled(false); lblCampaigns.setEnabled(false); lblOmsFile.setEnabled(false); lblWarning.setVisible(true); txtOmsFile.setEnabled(false); btnBrowseOms.setEnabled(false); } else { setSystematic(false); rdbtnRandom.setSelected(true); } } }); rdbtnSystematic.setBounds(152, 90, 259, 23); rdbtnSystematic.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(rdbtnSystematic); rdbtnRandom = new JRadioButton("Random"); rdbtnRandom.setSelected(true); rdbtnRandom.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (rdbtnRandom.isSelected()) { setSystematic(false); rdbtnSystematic.setSelected(false); chckbxRatio6.setEnabled(true); chckbxRatio5.setEnabled(true); chckbxRatio4.setEnabled(true); chckbxRatio3.setEnabled(true); spnrRandomCampaigns.setEnabled(true); lblRatio.setEnabled(true); lblCampaigns.setEnabled(true); lblOmsFile.setEnabled(true); lblWarning.setVisible(false); txtOmsFile.setEnabled(true); btnBrowseOms.setEnabled(true); } else { setSystematic(true); rdbtnSystematic.setSelected(true); } } }); rdbtnRandom.setBounds(152, 119, 142, 23); rdbtnRandom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(rdbtnRandom); comboBoxSelectProject = new JComboBox<OMBuilding>(); comboBoxSelectProject.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { boolean b = false; if (comboBoxSelectProject.isEnabled()) { if (comboBoxSelectProject.getSelectedItem() != null) { b = true; setSelectedObject((OMBuilding) comboBoxSelectProject.getSelectedItem()); setProjectName(getSelectedObject().getName()); } else { b = false; } } else { b = false; } progressBarSimulation.setEnabled(b); btnStart.setEnabled(b); chckbxRandomNoise.setEnabled(b); rdbtnRandom.setEnabled(b); rdbtnSystematic.setEnabled(b); lblPercent.setEnabled(b); lblRatio.setEnabled(b); lblSimulationType.setEnabled(b); lblCampaigns.setEnabled(b); } }); comboBoxSelectProject.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { boolean b = false; if (comboBoxSelectProject.isEnabled()) { if (comboBoxSelectProject.getSelectedItem() != null) { b = true; setSelectedObject((OMBuilding) comboBoxSelectProject.getSelectedItem()); setProjectName(getSelectedObject().getName()); } else { b = false; } } else { b = false; } progressBarSimulation.setEnabled(b); btnStart.setEnabled(b); chckbxRandomNoise.setEnabled(b); rdbtnRandom.setEnabled(b); rdbtnSystematic.setEnabled(b); lblPercent.setEnabled(b); lblRatio.setEnabled(b); lblSimulationType.setEnabled(b); lblCampaigns.setEnabled(b); } }); comboBoxSelectProject.setBounds(152, 61, 454, 22); comboBoxSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(comboBoxSelectProject); btnStart.setEnabled(false); chckbxRandomNoise.setEnabled(false); chckbxRatio6.setEnabled(false); chckbxRatio5.setEnabled(false); chckbxRatio4.setEnabled(false); chckbxRatio3.setEnabled(false); spnrRandomNoise.setEnabled(false); spnrRatio6.setEnabled(false); spnrRatio5.setEnabled(false); spnrRatio4.setEnabled(false); spnrRatio3.setEnabled(false); spnrRandomCampaigns.setEnabled(false); rdbtnRandom.setEnabled(false); rdbtnSystematic.setEnabled(false); lblPercent.setEnabled(false); lblRatio.setEnabled(false); lblSimulationType.setEnabled(false); lblCampaigns.setEnabled(false); lblOmsFile.setEnabled(false); txtOmsFile.setEnabled(false); btnBrowseOms.setEnabled(false); spnrRatio6.setValue(73); spnrRatio5.setValue(20); spnrRatio4.setValue(5); spnrRatio3.setValue(2); spnrRandomNoise.setValue(5); lblWarning.setVisible(false); }
From source file:app.RunApp.java
/** * Action of Add button in Multiple datasets tab * /*ww w . ja v a 2 s .c o m*/ * @param evt Event */ private void buttonAddMultipleDatasetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddMultipleDatasetsActionPerformed //Choose dataset final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); FileNameExtensionFilter fname = new FileNameExtensionFilter(".arff", "arff"); chooser.setFileFilter(fname); final int returnVal = chooser.showOpenDialog(this); progressBar.setIndeterminate(true); progressFrame.setVisible(true); progressFrame.repaint(); new Thread(new Runnable() { @Override public void run() { // do the long-running work here loadMultiDataset(returnVal, chooser); // at the end: SwingUtilities.invokeLater(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressFrame.setVisible(false); progressFrame.repaint(); }//run }); //invokeLater } }).start(); }
From source file:app.RunApp.java
/** * Action of Choose file button on Principal tab * //w w w .j a v a 2 s. co m * @param evt Event */ private void buttonChooseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChooseFileActionPerformed final JFileChooser jfile1 = new JFileChooser(); jfile1.setLocale(Locale.UK); jfile1.repaint(); FileNameExtensionFilter fname = new FileNameExtensionFilter(".arff", "arff"); jfile1.setFileFilter(fname); final boolean deleteXML = false; final int returnVal = jfile1.showOpenDialog(this); progressBar.setIndeterminate(true); progressFrame.setVisible(true); progressFrame.repaint(); new Thread(new Runnable() { @Override public void run() { // do the long-running work here loadDataset(returnVal, jfile1, deleteXML); // at the end: SwingUtilities.invokeLater(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressFrame.setVisible(false); progressFrame.repaint(); }//run }); //invokeLater } }).start(); }
From source file:app.RunApp.java
/** * Action of Save table button in MVML tab * /*from www. j av a 2s . co m*/ * @param evt Event */ private void buttonSaveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveTableActionPerformed if (jTable2.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); if (f1.getDescription().equals(".csv")) { try { String path = file.getAbsolutePath() + ".csv"; BufferedWriter bw = new BufferedWriter(new FileWriter(path)); PrintWriter wr = new PrintWriter(bw); ResultsIOUtils.saveMVTableCsv(wr, jTable2, views, dataset); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:app.RunApp.java
/** * Save heatmap graph as image/*from ww w .j a v a 2s . c o m*/ * * @throws AWTException * @throws IOException */ private void saveHeatmapGraph() throws AWTException, IOException { BufferedImage image = new Robot().createScreenCapture( new Rectangle(panelHeatmap.getLocationOnScreen().x + 31, panelHeatmap.getLocationOnScreen().y + 31, panelHeatmap.getWidth() - 61, panelHeatmap.getHeight() - 61)); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".png", "png"); fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); fc.addChoosableFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png"); ImageIO.write(image, "png", file); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Save co-ocurrence graph as image/*from w w w . j av a 2s .c o m*/ * * @throws AWTException * @throws IOException */ private void saveCoocurrenceGraph() throws AWTException, IOException { BufferedImage image = new Robot().createScreenCapture(new Rectangle( panelCoOcurrenceRight.getLocationOnScreen().x, panelCoOcurrenceRight.getLocationOnScreen().y, panelCoOcurrenceRight.getWidth(), panelCoOcurrenceRight.getHeight())); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".png", "png"); fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); fc.addChoosableFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png"); ImageIO.write(image, "png", file); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Action for Save button from principal tab * /*from w w w . j a va 2 s. co m*/ * @param evt Event * @param jtable Table * @throws IOException */ private void buttonSaveActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) throws IOException { ArrayList<String> metricsList = getMetricsSelectedPrincipal(jtable); if (dataset == null) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); // extension txt FileNameExtensionFilter fname = new FileNameExtensionFilter(".txt", "txt"); FileNameExtensionFilter fname2 = new FileNameExtensionFilter(".csv", "csv"); FileNameExtensionFilter fname3 = new FileNameExtensionFilter(".arff", ".arff"); FileNameExtensionFilter fname4 = new FileNameExtensionFilter(".tex", ".tex"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.addChoosableFileFilter(fname); fc.addChoosableFileFilter(fname2); fc.addChoosableFileFilter(fname3); fc.addChoosableFileFilter(fname4); fc.setFileFilter(fname); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); String path; BufferedWriter bw; PrintWriter wr; switch (f1.getDescription()) { case ".txt": path = file.getAbsolutePath() + ".txt"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMetricsTxt(wr, metricsList, dataset, tableMetrics); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".tex": path = file.getAbsolutePath() + ".tex"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMetricsTex(wr, metricsList, tableMetrics); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".csv": path = file.getAbsolutePath() + ".csv"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMetricsCsv(wr, metricsList, dataset, tableMetrics); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".arff": path = file.getAbsolutePath() + ".arff"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMetricsArff(wr, metricsList, dataset, tableMetrics); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; default: break; } Toolkit.getDefaultToolkit().beep(); } }