Ejemplo n.º 1
0
  /** deletes the currently selected attribute */
  public void deleteAttribute() {
    ArffSortedTableModel model;

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

    model = (ArffSortedTableModel) m_TableArff.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));
  }
Ejemplo n.º 2
0
  /** calculates the mean of the given numeric column */
  private void calcMean() {
    ArffSortedTableModel model;
    int i;
    double mean;

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

    model = (ArffSortedTableModel) m_TableArff.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_TableArff.getPlainColumnName(m_CurrentCol)
            + "':\n\t"
            + Utils.doubleToString(mean, 3),
        JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.PLAIN_MESSAGE);
  }
Ejemplo n.º 3
0
  /** sets the enabled/disabled state of the menu items */
  private void setMenu() {
    boolean isNumeric;
    boolean hasColumns;
    boolean hasRows;
    boolean attSelected;
    ArffSortedTableModel model;
    boolean isNull;

    model = (ArffSortedTableModel) m_TableArff.getModel();
    isNull = (model.getInstances() == null);
    hasColumns = !isNull && (model.getInstances().numAttributes() > 0);
    hasRows = !isNull && (model.getInstances().numInstances() > 0);
    attSelected = hasColumns && (m_CurrentCol > 0);
    isNumeric = attSelected && (model.getAttributeAt(m_CurrentCol).isNumeric());

    menuItemUndo.setEnabled(canUndo());
    menuItemCopy.setEnabled(true);
    menuItemSearch.setEnabled(true);
    menuItemClearSearch.setEnabled(true);
    menuItemMean.setEnabled(isNumeric);
    menuItemSetAllValues.setEnabled(attSelected);
    menuItemSetMissingValues.setEnabled(attSelected);
    menuItemReplaceValues.setEnabled(attSelected);
    menuItemRenameAttribute.setEnabled(attSelected);
    menuItemDeleteAttribute.setEnabled(attSelected);
    menuItemDeleteAttributes.setEnabled(attSelected);
    menuItemSortInstances.setEnabled(hasRows && attSelected);
    menuItemDeleteSelectedInstance.setEnabled(hasRows && m_TableArff.getSelectedRow() > -1);
    menuItemDeleteAllSelectedInstances.setEnabled(
        hasRows && (m_TableArff.getSelectedRows().length > 0));
  }
Ejemplo n.º 4
0
  /** renames the current attribute */
  public void renameAttribute() {
    ArffSortedTableModel model;
    String newName;

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

    model = (ArffSortedTableModel) m_TableArff.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));
  }
Ejemplo n.º 5
0
  /**
   * sets the current attribute as class attribute, i.e. it moves it to the end of the attributes
   */
  public void attributeAsClass() {
    ArffSortedTableModel model;

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

    model = (ArffSortedTableModel) m_TableArff.getModel();

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

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