Example usage for weka.gui ComponentHelper showInputBox

List of usage examples for weka.gui ComponentHelper showInputBox

Introduction

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

Prototype

public static String showInputBox(Component parent, String title, String msg, Object initialValue) 

Source Link

Document

pops up an input dialog

Usage

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

License:Open Source License

/**
 * sets the specified values in a column to a new value
 *
 * @param o the menu item/*from  ww w  .  j ava2  s .c  o m*/
 */
private void setValues(Object o) {
    String msg;
    String title;
    String value;
    String valueNew;
    int i;
    DataSortedTableModel model;

    value = "";
    valueNew = "";

    if (o == menuItemSetMissingValues) {
        title = "Replace missing values...";
        msg = "New value for MISSING values";
    } else if (o == menuItemSetAllValues) {
        title = "Set all values...";
        msg = "New value for ALL values";
    } else if (o == menuItemReplaceValues) {
        title = "Replace values...";
        msg = "Old value";
    } else {
        return;
    }

    value = ComponentHelper.showInputBox(m_TableData.getParent(), title, msg, m_LastSearch);

    // cancelled?
    if (value == null) {
        return;
    }

    m_LastSearch = value;

    // replacement
    if (o == menuItemReplaceValues) {
        valueNew = ComponentHelper.showInputBox(m_TableData.getParent(), title, "New value", m_LastReplace);
        if (valueNew == null) {
            return;
        }
        m_LastReplace = valueNew;
    }

    model = (DataSortedTableModel) m_TableData.getModel();
    model.setNotificationEnabled(false);

    // undo
    addUndoPoint();
    model.setUndoEnabled(false);
    String valueCopy = value;
    String valueNewCopy = valueNew;
    // set value
    for (i = 0; i < m_TableData.getRowCount(); i++) {
        if (o == menuItemSetAllValues) {
            if (valueCopy.equals("NaN") || valueCopy.equals("?")) {
                value = null;
            }
            model.setValueAt(value, i, m_CurrentCol);
        } else if ((o == menuItemSetMissingValues) && model.isMissingAt(i, m_CurrentCol)) {
            model.setValueAt(value, i, m_CurrentCol);
        } else if ((o == menuItemReplaceValues) && model.getValueAt(i, m_CurrentCol).toString().equals(value)) {
            if (valueNewCopy.equals("NaN") || valueNewCopy.equals("?")) {
                valueNew = null;
            }
            model.setValueAt(valueNew, i, m_CurrentCol);
        }

    }
    model.setUndoEnabled(true);
    model.setNotificationEnabled(true);
    model.notifyListener(
            new TableModelEvent(model, 0, model.getRowCount(), m_CurrentCol, TableModelEvent.UPDATE));

    // refresh
    m_TableData.repaint();
}

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

License:Open Source License

/**
 * renames the current attribute//from  ww w. j a  va2s. c  om
 */
public void renameAttribute() {
    DataSortedTableModel model;
    String newName;

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

    model = (DataSortedTableModel) m_TableData.getModel();

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

    newName = ComponentHelper.showInputBox(getParent(), "Rename attribute...", "Enter new Attribute name",
            model.getAttributeAt(m_CurrentCol).name());
    if (newName == null) {
        return;
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    model.renameAttributeAt(m_CurrentCol, newName);
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

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

License:Open Source License

/**
 * searches for a string in the cells/*from   w w w.  ja  va 2  s . c  om*/
 */
public void search() {
    String searchString;

    // display dialog
    searchString = ComponentHelper.showInputBox(getParent(), "Search...", "Enter the string to search for",
            m_LastSearch);
    if (searchString != null) {
        m_LastSearch = searchString;
    }

    getTable().setSearchString(searchString);
}