List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter
public FileNameExtensionFilter(String description, String... extensions)
From source file:app.RunApp.java
/** * Action for Save button from multiple datasets tab * /*from w w w. java2s . c o m*/ * @param evt Event * @param jtable Table * @throws IOException */ private void buttonSaveActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) throws IOException { ArrayList<String> metricsList = getSelectedMetricsMulti(jtable); if (listDatasets == null || listDatasets.isEmpty() || datasetNames.isEmpty()) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE); return; } //JFileChooser save JFileChooser fc = new JFileChooser(); 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.saveMultiMetricsTxt(wr, metricsList, datasetNames, tableMetricsMulti); 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.saveMultiMetricsTex(wr, metricsList, datasetNames, tableMetricsMulti); 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.saveMultiMetricsCsv(wr, metricsList, datasetNames, tableMetricsMulti); 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.saveMultiMetricsArff(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; default: break; } Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Action for Export button// ww w . j ava 2s .c om * * @param evt Event * @param jtable Table */ private void buttonExportActionPerformed(java.awt.event.ActionEvent evt, JTable jtable) { if (jtable.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); switch (comboBoxLabelsInformation.getSelectedIndex()) { case 1: ResultsIOUtils.saveTableLabelsetsFrequencyCsv(wr, jtable, labelsetStringsByFreq); break; case 6: ResultsIOUtils.saveTableLabelsetsIRCsv(wr, jtable, labelsetStringByIR); break; default: ResultsIOUtils.saveTableCsv(wr, jtable); break; } 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
/** * Action for Export button//from w w w.ja v a2 s. c o m * * @param evt Event * @param jtable Table * @param columns Columns * @param table Table type */ private void buttonExportActionPerformed(java.awt.event.ActionEvent evt, JTable jtable, JTable columns, String table) { if (jtable.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(); //Saving csv chi_phi if (f1.getDescription().equals(".csv")) { BufferedWriter bw; PrintWriter wr; try { String path = file.getAbsolutePath() + ".csv"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); switch (table) { case "ChiPhi": ResultsIOUtils.saveChiPhiTableCsv(wr, chiPhiCoefficients, dataset.getLabelNames()); break; case "Coocurrence": ResultsIOUtils.saveCoocurrenceTableCsv(wr, coocurrenceCoefficients, dataset.getLabelNames()); break; case "Heatmap": ResultsIOUtils.saveHeatmapTableCsv(wr, heatmapCoefficients, dataset.getLabelNames()); break; default: JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); break; } 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:nl.detoren.ijsco.ui.Mainscreen.java
private void addMenubar() { // Menu bar met 1 niveau Mainscreen ms = this; JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("Bestand"); // File menu//from w w w . ja va 2 s . c om JMenuItem item; /* item = new JMenuItem("Openen..."); item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); //controller.leesBestand(file.getAbsolutePath()); ms.repaint(); } } }); filemenu.add(item); */ /* item = new JMenuItem("Opslaan"); item.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //controller.saveState(true, "save"); } }); filemenu.add(item); */ filemenu.addSeparator(); item = new JMenuItem("Instellingen..."); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actieInstellingen(); } }); item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); filemenu.add(item); filemenu.addSeparator(); item = new JMenuItem("Afsluiten"); item.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { controller.saveState(false, null); System.exit(EXIT_ON_CLOSE); } }); filemenu.add(item); menubar.add(filemenu); /** * Toernooi menu */ JMenu toernooimenu = new JMenu("Toernooi"); item = new JMenuItem("Toernooiinformatie"); item.setAccelerator(KeyStroke.getKeyStroke('T', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); bewerkToernooi(); hoofdPanel.repaint(); } }); toernooimenu.add(item); menubar.add(toernooimenu); /** * Spelersdatabase menu */ JMenu spelermenu = new JMenu("Spelersdatabase"); item = new JMenuItem("OSBO JSON lijst ophalen (Online)"); item.setAccelerator(KeyStroke.getKeyStroke('J', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); leeslijstOnline("www.osbo.nl", "/jeugd/currentratings.json"); hoofdPanel.repaint(); } }); spelermenu.add(item); item = new JMenuItem("OSBO htmllijst ophalen !verouderd! (Online)"); item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); leeslijstOnline("www.osbo.nl", "/jeugd/jrating.htm"); hoofdPanel.repaint(); } }); spelermenu.add(item); item = new JMenuItem("OSBO/IJSCO compatible lijst inlezen (Bestand)"); item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesOSBOlijstBestand(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); spelermenu.add(item); /* item = new JMenuItem("Groslijst CSV inlezen (Bestand) N/A"); item.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesCSV(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); spelermenu.add(item); */ menubar.add(spelermenu); JMenu deelnemersmenu = new JMenu("Deelnemers"); item = new JMenuItem("Wis Deelnemerslijst"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser wisDeelnemers(); hoofdPanel.repaint(); } }); deelnemersmenu.add(item); item = new JMenuItem("Importeren Deelnemerslijst"); item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesDeelnemers(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); deelnemersmenu.add(item); item = new JMenuItem("Export Deelnemerslijst (JSON)"); item.setAccelerator(KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JSON", "json"); fc.setFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showSaveDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); schrijfDeelnemers(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); deelnemersmenu.add(item); menubar.add(deelnemersmenu); JMenu uitslagenmenu = new JMenu("Uitslagen"); Component hs = this; item = new JMenuItem("Importeer uitslagenbestand"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(hs); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); status.groepenuitslagen = (GroepsUitslagen) new ExcelImport().importeerUitslagen(file); OutputUitslagen ou = new OutputUitslagen(); ou.exportuitslagen(status.groepenuitslagen); IJSCOController.t().wisUitslagen(); ou.exportJSON(status.groepenuitslagen); GroepsUitslagen verwerkteUitslag = new Uitslagverwerker() .verwerkUitslag(status.groepenuitslagen); logger.log(Level.INFO, verwerkteUitslag.ToString()); new OutputUitslagen().exporteindresultaten(verwerkteUitslag); JOptionPane.showMessageDialog(null, "Uitslagen geimporteerd en bestanden aangemaakt."); } hoofdPanel.repaint(); } }); uitslagenmenu.add(item); menubar.add(uitslagenmenu); JMenu osbomenu = new JMenu("OSBO"); item = new JMenuItem("Verstuur uitslagen handmatig."); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser SendAttachmentInEmail SAIM = new SendAttachmentInEmail(); SAIM.sendAttachement("Uitslagen.json"); hoofdPanel.repaint(); } }); osbomenu.add(item); menubar.add(osbomenu); JMenu helpmenu = new JMenu("Help"); item = new JMenuItem("Verstuur logging"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser SendAttachmentInEmail SAIM = new SendAttachmentInEmail(); SAIM.sendAttachement("IJSCO_UI.log"); hoofdPanel.repaint(); } }); helpmenu.add(item); item = new JMenuItem("About"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AboutDialog ad = new AboutDialog(ms); ad.setVisible(true); hoofdPanel.repaint(); } }); helpmenu.add(item); menubar.add(helpmenu); /* JMenu indelingMenu = new JMenu("Indeling"); //item = new JMenuItem("Automatisch aan/uit"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //actieAutomatisch(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak wedstrijdgroep"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieMaakWedstrijdgroep(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak speelschema"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evetn) { //actieMaakSpeelschema(); } }); indelingMenu.add(item); //item = new JMenuItem("Bewerk speelschema"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //updateAutomatisch(false); // ResultaatDialoog //actieBewerkSchema(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Export"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //actieExport(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Vul uitslagen in"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieVoerUitslagenIn(); } }); indelingMenu.add(item); //item = new JMenuItem("Externe spelers"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieExterneSpelers(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak nieuwe stand"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieUpdateStand(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Volgende ronde"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieVolgendeRonde(); } }); indelingMenu.add(item); menubar.add(indelingMenu); */ /* JMenu overigmenu = new JMenu("Overig"); //item = new JMenuItem("Reset punten"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //controller.resetPunten(); hoofdPanel.repaint(); } }); overigmenu.add(item); menubar.add(overigmenu); */ this.setJMenuBar(menubar); }
From source file:nl.fontys.sofa.limo.view.project.actions.ExportChainAction.java
private void openFileChooser() throws HeadlessException, IOException { JFileChooser fc = new ChainSaveFileChooser(); FileNameExtensionFilter chainFilter = new FileNameExtensionFilter("Supply chains (*.lsc)", "lsc"); if (supplyChain.getFilepath() != null) { //This happens if a supply chain is loaded. fc.setCurrentDirectory(new File(supplyChain.getFilepath())); }// w w w .j av a 2 s. c o m fc.setFileFilter(chainFilter); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setSelectedFile(new File(FilenameUtils.removeExtension(supplyChain.getName()))); // This sets the name without the extension int result = fc.showOpenDialog(null); String fileName = fc.getSelectedFile().getName(); //name with extension if (result == JFileChooser.APPROVE_OPTION) { //If folder is selected than save the supply chain. supplyChain.setName(fileName); File file = fc.getSelectedFile(); supplyChain.saveToFile(file.getAbsolutePath() + ".lsc"); } else { //If no folder is selected throw an exception so the saving process is cancelled. throw new IOException("The supply chain " + supplyChain.getName() + " is invalid."); } }
From source file:org.bimserver.client.Client.java
void checkout(SRevision revision) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("IFC File", "ifc")); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); FileOutputStream fileOutputStream; try {/*from ww w. j av a2 s. com*/ fileOutputStream = new FileOutputStream(selectedFile); checkout(revision, fileOutputStream, true); } catch (FileNotFoundException e) { LOGGER.error("", e); } } }
From source file:org.bimserver.client.Client.java
public void download(SRevision revision) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("IFC File", "ifc")); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); try {// w w w. j av a2s . c o m FileOutputStream fileOutputStream = new FileOutputStream(selectedFile); download(revision.getOid(), fileOutputStream, true); } catch (FileNotFoundException e) { LOGGER.error("", e); } } }
From source file:org.domainmath.gui.MainFrame.java
/** * Creates file chooser dialog box and allows the user to select files * and importData selected files in fileTab. *///from w ww.ja va 2 s . co m public void open() { JFileChooser fc = new JFileChooser(); // set current directory. if (fileTab.getTabCount() > 0) { File f = new File(fileTab.getToolTipTextAt(fileTab.getSelectedIndex())); fc.setCurrentDirectory(f.getParentFile()); } else { fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); } FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files (*.m)", "m"); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filter); fc.setMultiSelectionEnabled(true); fc.setFileView(new ScriptFileView()); File file1[]; int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file1 = fc.getSelectedFiles(); this.setCurrentDirFileTab(fc.getCurrentDirectory().getAbsolutePath()); for (int i = 0; i < file1.length; i++) { if (!fileNameList.contains(file1[i].getAbsolutePath())) { open(file1[i], i); } else { System.out.println(file1[i].getAbsolutePath() + " already open!"); } } } }
From source file:org.domainmath.gui.MainFrame.java
public void saveHistoryAs() { JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files (*.m)", "m"); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); fc.setFileFilter(filter);//from w w w . j av a 2 s.co m fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Save As"); File file_save; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getAbsolutePath(); if (!path.endsWith(".m")) { file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m"); saveHistory(file_save); } else { file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m"); saveHistory(file_save); } } }
From source file:org.drools.mas.SimpleClient.java
private void menuSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSaveAsActionPerformed JFileChooser saveFileChooser = new JFileChooser(); saveFileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Model File", "mod")); int showDialog = saveFileChooser.showDialog(this, "Save"); if (showDialog == JFileChooser.APPROVE_OPTION) { try {/* ww w.j a v a 2 s.c om*/ File selectedFile = saveFileChooser.getSelectedFile(); if (selectedFile.exists()) { int showConfirmDialog = JOptionPane.showConfirmDialog(this, "The file '" + selectedFile.getCanonicalPath() + "' already exstits. Do you want to continue?"); if (showConfirmDialog != JOptionPane.OK_OPTION) { return; } } if (!selectedFile.getName().endsWith(".mod")) { selectedFile = new File(selectedFile.getAbsolutePath() + ".mod"); } String content = ObjectSerializerFactory.getObjectSerializerInstance() .serialize(this.factTableModel.getFacts()); IOUtils.copy(new ByteArrayInputStream(content.getBytes()), new FileOutputStream(selectedFile)); JOptionPane.showMessageDialog(this, "File Saved!"); this.setTitle(selectedFile.getName()); } catch (Exception ex) { Logger.getLogger(SimpleClient.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(this, "Error saving file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }