Example usage for weka.gui ConverterFileChooser showOpenDialog

List of usage examples for weka.gui ConverterFileChooser showOpenDialog

Introduction

In this page you can find the example usage for weka.gui ConverterFileChooser showOpenDialog.

Prototype

@Override
public int showOpenDialog(Component parent) 

Source Link

Document

Pops up an "Open File" file chooser dialog.

Usage

From source file:meka.gui.explorer.classify.OpenTestData.java

License:Open Source License

/**
 * Returns the action lister to use in the menu.
 *
 * @return          the listener//w w w .j  a  va 2  s  .co  m
 */
public ActionListener getActionListener(final ClassifyTab owner) {
    return new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ConverterFileChooser filechooser;
            if (!hasSessionValue(owner, SESSION_KEY_FILECHOOSER)) {
                filechooser = GUIHelper.newConverterFileChooser();
                ExtensionFileFilter filter = new ExtensionFileFilter(".model", "Model files (*.model)");
                filechooser.addChoosableFileFilter(filter);
                filechooser.setFileFilter(filter);
                filechooser.setAcceptAllFileFilterUsed(true);
                setSessionValue(owner, SESSION_KEY_FILECHOOSER, filechooser);
            } else {
                filechooser = (ConverterFileChooser) getSessionValue(owner, SESSION_KEY_FILECHOOSER);
            }
            if (filechooser.showOpenDialog(owner) != ConverterFileChooser.APPROVE_OPTION)
                return;
            AbstractFileLoader loader = filechooser.getLoader();
            try {
                Instances data = loader.getDataSet();
                if (data != null)
                    owner.setTestData(data);
            } catch (Exception ex) {
                String msg = "Failed to load file: " + filechooser.getSelectedFile();
                System.err.println(msg);
                ex.printStackTrace();
                JOptionPane.showMessageDialog(owner, msg + "\n" + ex, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    };
}