Example usage for weka.gui ComponentHelper showMessageBox

List of usage examples for weka.gui ComponentHelper showMessageBox

Introduction

In this page you can find the example usage for weka.gui ComponentHelper showMessageBox.

Prototype

public static int showMessageBox(Component parent, String title, String msg, int buttons, int messageType) 

Source Link

Document

displays a message box with the given title, message, buttons and icon ant the dimension.

Usage

From source file:meka.gui.dataviewer.DataPanel.java

License:Open Source License

/**
 * calculates the mean of the given numeric column
 *///w ww  .ja  va 2 s  . c  o  m
private void calcMean() {
    DataSortedTableModel model;
    int i;
    double mean;

    // no column selected?
    if (m_CurrentCol == -1) {
        return;
    }

    model = (DataSortedTableModel) m_TableData.getModel();

    // not numeric?
    if (!model.getAttributeAt(m_CurrentCol).isNumeric()) {
        return;
    }

    mean = 0;
    for (i = 0; i < model.getRowCount(); i++) {
        mean += model.getInstances().instance(i).value(m_CurrentCol - 1);
    }
    mean = mean / model.getRowCount();

    // show result
    ComponentHelper.showMessageBox(
            getParent(), "Mean for attribute...", "Mean for attribute '"
                    + m_TableData.getPlainColumnName(m_CurrentCol) + "':\n\t" + Utils.doubleToString(mean, 3),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
}

From source file:meka.gui.dataviewer.DataPanel.java

License:Open Source License

/**
 * deletes the currently selected attribute
 *//*ww  w.ja  va 2  s .  c  om*/
public void deleteAttribute() {
    DataSortedTableModel model;

    // no column selected?
    if (m_CurrentCol == -1) {
        return;
    }

    model = (DataSortedTableModel) m_TableData.getModel();

    // really an attribute column?
    if (model.getAttributeAt(m_CurrentCol) == null) {
        return;
    }

    // really?
    if (ComponentHelper.showMessageBox(getParent(), "Confirm...",
            "Do you really want to delete the attribute '" + model.getAttributeAt(m_CurrentCol).name() + "'?",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
        return;
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    model.deleteAttributeAt(m_CurrentCol);
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

From source file:meka.gui.dataviewer.DataPanel.java

License:Open Source License

/**
 * deletes the chosen attributes//from ww  w .  j  av a2  s. c  o  m
 */
public void deleteAttributes() {
    ListSelectorDialog dialog;
    DataSortedTableModel model;
    Object[] atts;
    int[] indices;
    int i;
    JList list;
    int result;

    list = new JList(getAttributes());
    dialog = new ListSelectorDialog(null, list);
    result = dialog.showDialog();

    if (result != ListSelectorDialog.APPROVE_OPTION) {
        return;
    }

    atts = list.getSelectedValues();

    // really?
    if (ComponentHelper.showMessageBox(getParent(), "Confirm...",
            "Do you really want to delete these " + atts.length + " attributes?", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
        return;
    }

    model = (DataSortedTableModel) m_TableData.getModel();
    indices = new int[atts.length];
    for (i = 0; i < atts.length; i++) {
        indices[i] = model.getAttributeColumn(atts[i].toString());
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    model.deleteAttributes(indices);
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

From source file:meka.gui.dataviewer.DataTable.java

License:Open Source License

/**
 * returns the selected content in a StringSelection that can be copied to the
 * clipboard and used in Excel, if nothing is selected the whole table is
 * copied to the clipboard//  w ww .  ja v  a2 s .c  o m
 *
 * @return the current selection
 */
public StringSelection getStringSelection() {
    StringSelection result;
    int[] indices;
    int i;
    int n;
    StringBuffer tmp;

    result = null;

    // nothing selected? -> all
    if (getSelectedRow() == -1) {
        // really?
        if (ComponentHelper.showMessageBox(getParent(), "Question...",
                "Do you really want to copy the whole table?", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
            return result;
        }

        indices = new int[getRowCount()];
        for (i = 0; i < indices.length; i++) {
            indices[i] = i;
        }
    } else {
        indices = getSelectedRows();
    }

    // get header
    tmp = new StringBuffer();
    for (i = 0; i < getColumnCount(); i++) {
        if (i > 0) {
            tmp.append("\t");
        }
        tmp.append(getPlainColumnName(i));
    }
    tmp.append("\n");

    // get content
    for (i = 0; i < indices.length; i++) {
        for (n = 0; n < getColumnCount(); n++) {
            if (n > 0) {
                tmp.append("\t");
            }
            tmp.append(getValueAt(indices[i], n).toString());
        }
        tmp.append("\n");
    }

    result = new StringSelection(tmp.toString());

    return result;
}

From source file:meka.gui.dataviewer.DataTableModel.java

License:Open Source License

/**
 * loads the specified ARFF file//from  w  ww  .j  a  v  a  2s. co m
 *
 * @param filename the file to load
 * @param loaders optional varargs for a loader to use
 */
protected void loadFile(String filename, AbstractFileLoader... loaders) {
    AbstractFileLoader loader;
    Instances data;

    if (loaders == null || loaders.length == 0) {
        loader = ConverterUtils.getLoaderForFile(filename);
    } else {
        loader = loaders[0];
    }

    if (loader != null) {
        try {
            loader.setFile(new File(filename));
            data = loader.getDataSet();
            // fix class attributes definition in relation name if necessary
            MLUtils.fixRelationName(data);
            MLUtils.prepareData(data);
            setInstances(data);
        } catch (Exception e) {
            ComponentHelper.showMessageBox(null, "Error loading file...", e.toString(),
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
            System.out.println(e);
            setInstances(null);
        }
    }
}

From source file:meka.gui.dataviewer.DataViewer.java

License:Open Source License

/**
 * invoked when a window is in the process of closing
 *
 * @param e the window event//from  w w w  .  j a va 2  s.co m
 */
@Override
public void windowClosing(WindowEvent e) {
    int button;

    while (getMainPanel().getTabbedPane().getTabCount() > 0) {
        getMainPanel().closeFile(false);
    }

    if (getConfirmExit()) {
        button = ComponentHelper.showMessageBox(this, "Quit - " + getTitle(), "Do you really want to quit?",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (button == JOptionPane.YES_OPTION) {
            dispose();
        }
    } else {
        dispose();
    }

    if (getExitOnClose()) {
        System.exit(0);
    }
}