meka.gui.explorer.classify.EditTestData.java Source code

Java tutorial

Introduction

Here is the source code for meka.gui.explorer.classify.EditTestData.java

Source

/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * EditTestData.java
 * Copyright (C) 2016 University of Waikato, Hamilton, NZ
 */

package meka.gui.explorer.classify;

import meka.gui.explorer.ClassifyTab;
import weka.core.Instances;
import weka.gui.ViewerDialog;

import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Menu item for loading a model from disk.
 *
 * @author FracPete (fracpete at waikato dot ac dot nz)
 * @version $Revision$
 */
public class EditTestData extends AbstractClassifyTabMenuItem {

    /** the session key for the model filechooser. */
    public final static String SESSION_KEY_MODELCHOOSER = "modelchooser";

    /**
     * Returns the group of the plugin. Used for the grouping the menu items.
     *
     * @return          the group
     */
    public String getGroup() {
        return "Test data";
    }

    /**
     * Returns the name of the plugin. Used for the menu item text.
     *
     * @return          the name
     */
    public String getName() {
        return "Edit test data...";
    }

    /**
     * Returns the name of the icon to use.
     *
     * @return          the name of the icon, null if none to use
     */
    public String getIcon() {
        return "report.gif";
    }

    /**
     * Returns the action lister to use in the menu.
     *
     * @return          the listener
     */
    public ActionListener getActionListener(final ClassifyTab owner) {
        return new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ViewerDialog dialog;
                int result;
                Instances copy;
                Instances newInstances;

                copy = new Instances(owner.getTestData());
                dialog = new ViewerDialog(null);
                dialog.setSize(800, 600);
                dialog.setLocationRelativeTo(owner);
                result = dialog.showDialog(copy);
                if (result == ViewerDialog.APPROVE_OPTION) {
                    // if class was not set before, reset it again after use of filter
                    newInstances = dialog.getInstances();
                    if (owner.getTestData().classIndex() < 0)
                        newInstances.setClassIndex(-1);
                    owner.setTestData(newInstances);

                }
            }
        };
    }

    /**
     * Updates the menu item using the current state of the tab.
     *
     * @param owner the tab that the menu item belongs to
     * @param menuitem the menu item to update (was generated by this class)
     */
    @Override
    public void update(ClassifyTab owner, JMenuItem menuitem) {
        menuitem.setEnabled(owner.getTestData() != null);
    }
}