/** * 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 */ public void save(File file, AbstractFileSaver saver) { if (saver == null) saver = ConverterUtils.getSaverForFile(file); try { saver.setInstances(m_Data); if ((saver.retrieveFile() == null) || !saver.retrieveFile().equals(file)) saver.setFile(file); saver.writeBatch(); m_CurrentFile = file; } catch (Exception e) { System.err.println("Failed to save data to '" + file + "':"); e.printStackTrace(); JOptionPane.showMessageDialog( this, "Failed to save dataset to '" + file + "':\n" + e, "Error saving", JOptionPane.ERROR_MESSAGE); } updateMenu(); }
@Override public void closingOK() { m_saver.getConfig().setHDFSHost(m_hdfsHostText.getText()); m_saver.getConfig().setHDFSPort(m_hdfsPortText.getText()); m_saver.setHDFSPath(m_hdfsPathText.getText()); m_saver.setDFSReplicationFactor(m_dfsReplicationText.getText()); m_saver.setSaver((AbstractFileSaver) m_baseSaverEditor.getValue()); m_saver.setFilePrefix(m_filePrefixText.getText()); }
/** * saves the data with the specified saver * * @param saver the saver to use for storing the data * @param inst the data to save */ public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) { if (m_IOThread == null) { m_IOThread = new Thread() { @Override public void run() { try { m_Log.statusMessage("Saving to file..."); saver.setInstances(inst); saver.writeBatch(); m_Log.statusMessage("OK"); } catch (Exception ex) { ex.printStackTrace(); m_Log.logMessage(ex.getMessage()); } m_IOThread = null; } }; m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority m_IOThread.start(); } else { JOptionPane.showMessageDialog(this, "Can't save at this time,\n" + "currently busy with other IO", "Saving instances", JOptionPane.WARNING_MESSAGE); } }
/** * returns the loader that was chosen by the user, can be null in case the * user aborted the dialog or the save dialog was shown. * * @return the chosen loader, if any */ public AbstractFileLoader getLoader() { configureCurrentConverter(LOADER_DIALOG); if (m_CurrentConverter instanceof AbstractFileSaver) { return null; } else { return (AbstractFileLoader) m_CurrentConverter; } }
/** * returns the saver that was chosen by the user, can be null in case the user * aborted the dialog or the open dialog was shown. * * @return the chosen saver, if any */ public AbstractFileSaver getSaver() { configureCurrentConverter(SAVER_DIALOG); if (m_CurrentConverter instanceof AbstractFileLoader) { return null; } else { return (AbstractFileSaver) m_CurrentConverter; } }
/** * For testing the file chooser. * * @param args the commandline options - ignored * @throws Exception if something goes wrong with loading/saving */ public static void main(String[] args) throws Exception { ConverterFileChooser fc; int retVal; AbstractFileLoader loader; AbstractFileSaver saver; Instances data; fc = new ConverterFileChooser(); retVal = fc.showOpenDialog(null); // load file if (retVal == ConverterFileChooser.APPROVE_OPTION) { loader = fc.getLoader(); data = loader.getDataSet(); retVal = fc.showSaveDialog(null); // save file if (retVal == ConverterFileChooser.APPROVE_OPTION) { saver = fc.getSaver(); saver.setInstances(data); saver.writeBatch(); } else { System.out.println("Saving aborted!"); } } else { System.out.println("Loading aborted!"); } }
/** * saves the data with the specified saver * * @param saver the saver to use for storing the data * @param inst the data to save */ public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) { if (m_IOThread == null) { m_IOThread = new Thread() { public void run() { try { m_Log.statusMessage("Saving to file..."); saver.setInstances(inst); saver.writeBatch(); m_Log.statusMessage("OK"); } catch (Exception ex) { ex.printStackTrace(); m_Log.logMessage(ex.getMessage()); } m_IOThread = null; } }; m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority m_IOThread.start(); } else { JOptionPane.showMessageDialog(this, "Can't save at this time,\n" + "currently busy with other IO", "Saving instances", JOptionPane.WARNING_MESSAGE); } }
/** * returns the loader that was chosen by the user, can be null in case the * user aborted the dialog or the save dialog was shown. * * @return the chosen loader, if any */ public AbstractFileLoader getLoader() { configureCurrentConverter(LOADER_DIALOG); if (m_CurrentConverter instanceof AbstractFileSaver) return null; else return (AbstractFileLoader) m_CurrentConverter; }
/** * returns the saver that was chosen by the user, can be null in case the * user aborted the dialog or the open dialog was shown. * * @return the chosen saver, if any */ public AbstractFileSaver getSaver() { configureCurrentConverter(SAVER_DIALOG); if (m_CurrentConverter instanceof AbstractFileLoader) return null; else return (AbstractFileSaver) m_CurrentConverter; }
/** * saves the data with the specified saver * * @param saver the saver to use for storing the data * @param inst the data to save */ public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) { if (m_IOThread == null) { m_IOThread = new Thread() { public void run() { try { m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_Log_StatusMessage_Text_First")); saver.setInstances(inst); saver.writeBatch(); m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_Log_StatusMessage_Text_Second")); } catch (Exception ex) { ex.printStackTrace(); m_Log.logMessage(ex.getMessage()); } m_IOThread = null; } }; m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority m_IOThread.start(); } else { JOptionPane.showMessageDialog(this, Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_JOptionPaneShowMessageDialog_Text_First"), Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_JOptionPaneShowMessageDialog_Text_Second"), JOptionPane.WARNING_MESSAGE); } }
/** * returns the loader that was chosen by the user, can be null in case the * user aborted the dialog or the save dialog was shown * * @return the chosen loader, if any */ public AbstractFileLoader getLoader() { configureCurrentConverter(LOADER_DIALOG); if (m_CurrentConverter instanceof AbstractFileSaver) return null; else return (AbstractFileLoader) m_CurrentConverter; }
/** * returns the saver that was chosen by the user, can be null in case the * user aborted the dialog or the open dialog was shown * * @return the chosen saver, if any */ public AbstractFileSaver getSaver() { configureCurrentConverter(SAVER_DIALOG); if (m_CurrentConverter instanceof AbstractFileLoader) return null; else return (AbstractFileSaver) m_CurrentConverter; }
/** * For testing the file chooser * * @param args the commandline options - ignored * @throws Exception if something goes wrong with loading/saving */ public static void main(String[] args) throws Exception { ConverterFileChooser fc; int retVal; AbstractFileLoader loader; AbstractFileSaver saver; Instances data; fc = new ConverterFileChooser(); retVal = fc.showOpenDialog(null); // load file if (retVal == ConverterFileChooser.APPROVE_OPTION) { loader = fc.getLoader(); data = loader.getDataSet(); retVal = fc.showSaveDialog(null); // save file if (retVal == ConverterFileChooser.APPROVE_OPTION) { saver = fc.getSaver(); saver.setInstances(data); saver.writeBatch(); } else { System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +Messages.getInstance().getString("ConverterFileChooser_Main_Text_First")); } } else { System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +Messages.getInstance().getString("ConverterFileChooser_Main_Text_Second")); } }
/** * initializes the GUI. * * @param dialogType the type of dialog to setup the GUI for */ protected void initGUI(int dialogType) { Vector<ExtensionFileFilter> list; int i; boolean acceptAll; // backup current state acceptAll = isAcceptAllFileFilterUsed(); // setup filters resetChoosableFileFilters(); setAcceptAllFileFilterUsed(acceptAll); if (dialogType == LOADER_DIALOG) { list = filterNonCoreLoaderFileFilters(m_LoaderFileFilters); } else { list = filterSaverFileFilters(filterNonCoreSaverFileFilters(m_SaverFileFilters)); } for (i = 0; i < list.size(); i++) { addChoosableFileFilter(list.get(i)); } if (list.size() > 0) { if ((m_LastFilter == null) || (!list.contains(m_LastFilter))) { setFileFilter(list.get(0)); } else { setFileFilter(m_LastFilter); } } // listener if (m_Listener != null) { removePropertyChangeListener(m_Listener); } m_Listener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { // filter changed if (evt.getPropertyName().equals(FILE_FILTER_CHANGED_PROPERTY)) { updateCurrentConverter(); } } }; addPropertyChangeListener(m_Listener); // initial setup if (dialogType == LOADER_DIALOG) { m_Editor.setClassType(AbstractFileLoader.class); m_Editor.setValue(new weka.core.converters.ArffLoader()); } else { m_Editor.setClassType(AbstractFileSaver.class); m_Editor.setValue(new weka.core.converters.ArffSaver()); } updateCurrentConverter(); }
/** * initializes the GUI. * * @param dialogType the type of dialog to setup the GUI for */ protected void initGUI(int dialogType) { Vector<ExtensionFileFilter> list; int i; boolean acceptAll; // backup current state acceptAll = isAcceptAllFileFilterUsed(); // setup filters resetChoosableFileFilters(); setAcceptAllFileFilterUsed(acceptAll); if (dialogType == LOADER_DIALOG) list = filterNonCoreLoaderFileFilters(m_LoaderFileFilters); else list = filterSaverFileFilters(filterNonCoreSaverFileFilters(m_SaverFileFilters)); for (i = 0; i < list.size(); i++) { addChoosableFileFilter(list.get(i)); } if (list.size() > 0) { if ( (m_LastFilter == null) || (!list.contains(m_LastFilter)) ) setFileFilter(list.get(0)); else setFileFilter(m_LastFilter); } // listener if (m_Listener != null) removePropertyChangeListener(m_Listener); m_Listener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // filter changed if (evt.getPropertyName().equals(FILE_FILTER_CHANGED_PROPERTY)) { updateCurrentConverter(); } } }; addPropertyChangeListener(m_Listener); // initial setup if (dialogType == LOADER_DIALOG) { m_Editor.setClassType(AbstractFileLoader.class); m_Editor.setValue(new weka.core.converters.ArffLoader()); } else { m_Editor.setClassType(AbstractFileSaver.class); m_Editor.setValue(new weka.core.converters.ArffSaver()); } updateCurrentConverter(); }