List of usage examples for weka.core.converters AbstractFileSaver setFile
@Override public void setFile(File outputFile) throws IOException
From source file:adams.gui.visualization.instance.plotpopup.SaveVisible.java
License:Open Source License
/** * Returns a popup menu for the table of the container list. * * @param panel the affected panel/*w ww. j a v a 2 s. co m*/ * @param e the mouse event * @param menu the popup menu to customize */ @Override public void customize( DataContainerPanelWithContainerList<Instance, InstanceContainerManager, InstanceContainer> panel, MouseEvent e, JPopupMenu menu) { JMenuItem item; item = new JMenuItem("Save visible...", GUIHelper.getIcon("save.gif")); item.addActionListener((ActionEvent ae) -> { WekaFileChooser fc = new WekaFileChooser(); int retval = fc.showSaveDialog(panel); if (retval != WekaFileChooser.APPROVE_OPTION) return; weka.core.Instances dataset = null; for (InstanceContainer c : panel.getTableModelContainers(true)) { if (dataset == null) dataset = new weka.core.Instances(c.getData().getDatasetHeader(), 0); dataset.add((weka.core.Instance) c.getData().toInstance().copy()); } if (dataset == null) return; AbstractFileSaver saver = fc.getWriter(); saver.setInstances(dataset); try { saver.setFile(fc.getSelectedFile().getAbsoluteFile()); saver.writeBatch(); } catch (Exception ex) { ex.printStackTrace(); GUIHelper.showErrorMessage(panel, "Error saving instances:\n" + ex); } }); menu.add(item); }
From source file:adams.gui.visualization.instances.InstancesTable.java
License:Open Source License
/** * Exports the data.//from www . jav a2 s. c o m * * @param range what data to export */ protected void saveAs(TableRowRange range) { int retVal; AbstractFileSaver saver; File file; Instances original; Instances data; int[] selRows; int i; retVal = m_FileChooser.showSaveDialog(InstancesTable.this); if (retVal != WekaFileChooser.APPROVE_OPTION) return; saver = m_FileChooser.getWriter(); file = m_FileChooser.getSelectedFile(); original = getInstances(); switch (range) { case ALL: data = original; break; case SELECTED: data = new Instances(original, 0); selRows = getSelectedRows(); for (i = 0; i < selRows.length; i++) data.add((Instance) original.instance(getActualRow(selRows[i])).copy()); break; case VISIBLE: data = new Instances(original, 0); for (i = 0; i < getRowCount(); i++) data.add((Instance) original.instance(getActualRow(i)).copy()); break; default: throw new IllegalStateException("Unhandled range type: " + range); } try { saver.setFile(file); saver.setInstances(data); saver.writeBatch(); } catch (Exception ex) { GUIHelper.showErrorMessage(InstancesTable.this, "Failed to save data (" + range + ") to: " + file, ex); } }
From source file:meka.gui.explorer.Explorer.java
License:Open Source License
/** * Saves the data to the specified file. * * @param file the file to save the data to * @param saver the saver to use, determines it automatically if null *///from w w w .j av a 2s. c o m public void save(File file, AbstractFileSaver saver) { if (saver == null) saver = ConverterUtils.getSaverForFile(file); try { log(null, "Saving: " + file); saver.setInstances(m_Data); if ((saver.retrieveFile() == null) || !saver.retrieveFile().equals(file)) saver.setFile(file); saver.writeBatch(); m_CurrentFile = file; log(null, "Saved successfully: " + file); } catch (Exception e) { handleException(null, "Failed to save data to '" + file + "':", e); JOptionPane.showMessageDialog(this, "Failed to save dataset to '" + file + "':\n" + e, "Error saving", JOptionPane.ERROR_MESSAGE); } updateMenu(); }