List of usage examples for weka.experiment Experiment read
public static Experiment read(String filename) throws Exception
From source file:adams.gui.goe.WekaExperimentFileEditor.java
License:Open Source License
/** * Gets the custom editor component./*from ww w. j a v a2 s . c o m*/ * * @return a value of type 'Component' */ protected JComponent createCustomEditor() { WekaExperimentFile currentFile; JPanel panel; m_PanelEditor = new BasePanel(); m_PanelEditor.setLayout(new GridLayout(3, 1)); m_PanelEditor.setBorder(BorderFactory.createEmptyBorder()); // file m_PanelFile = new FileChooserPanel(); currentFile = (WekaExperimentFile) getValue(); if (currentFile == null) currentFile = new WekaExperimentFile(System.getProperty("user.dir")); m_PanelFile.setCurrent(currentFile); m_PanelFile.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { File file = m_PanelFile.getCurrent(); m_ButtonEdit.setEnabled(!file.isDirectory()); } }); panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); panel.add(m_PanelFile); m_PanelEditor.add(panel); // edit m_ButtonEdit = new BaseButton("Edit"); m_ButtonEdit.setMnemonic('E'); m_ButtonEdit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PlaceholderFile file = new PlaceholderFile(m_PanelFile.getCurrent()); Experiment exp = null; if (file.exists()) { try { exp = Experiment.read(file.getAbsolutePath()); } catch (Exception ex) { ex.printStackTrace(); exp = null; } } if (exp == null) exp = newExperiment(); SimpleSetupDialog dlg; if (m_PanelEditor.getParentDialog() != null) dlg = new SimpleSetupDialog(m_PanelEditor.getParentDialog()); else dlg = new SimpleSetupDialog(m_PanelEditor.getParentFrame()); dlg.setExperiment(exp); dlg.setLocationRelativeTo(dlg.getOwner()); dlg.setVisible(true); try { Experiment.write(new PlaceholderFile(m_PanelFile.getCurrent()).getAbsolutePath(), dlg.getExperiment()); } catch (Exception ex) { ex.printStackTrace(); GUIHelper.showErrorMessage(dlg.getOwner(), "Couldn't save WEKA experiment file:\n" + m_PanelFile.getCurrent() + "\nReason:\n" + ex.getMessage(), "Save WEKA Experiment"); } } }); panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); panel.add(m_ButtonEdit); m_PanelEditor.add(panel); // buttons m_ButtonOK = new BaseButton("OK"); m_ButtonOK.setMnemonic('O'); m_ButtonOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setValue(new WekaExperimentFile(m_PanelFile.getCurrent())); m_PanelEditor.closeParent(); } }); m_ButtonCancel = new BaseButton("Cancel"); m_ButtonCancel.setMnemonic('C'); m_ButtonCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { m_PanelEditor.closeParent(); } }); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(m_ButtonOK); panel.add(m_ButtonCancel); m_PanelEditor.add(panel); return m_PanelEditor; }