예제 #1
0
  /** deletes the chosen attributes */
  public void deleteAttributes() {
    ListSelectorDialog dialog;
    ArffSortedTableModel 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 = (ArffSortedTableModel) m_TableArff.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));
  }
예제 #2
0
  /**
   * Returns a panel to be displayed with the AboutAction.
   *
   * @return the panel with some information on the scripting panel
   */
  protected JPanel getAboutPanel() {
    JPanel result;
    JPanel panel;

    result = new JPanel(new BorderLayout());
    result.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // image
    result.add(
        new JLabel(ComponentHelper.getImageIcon(IMAGES_DIR + "/jython_medium.png")),
        BorderLayout.CENTER);

    // links
    panel = new JPanel(new GridLayout(5, 1));
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    result.add(panel, BorderLayout.SOUTH);

    panel.add(new JLabel("Jython homepage"));
    panel.add(BrowserHelper.createLink("http://www.jython.org/", null));
    panel.add(new JLabel(" "));
    panel.add(new JLabel("Weka and Jython"));
    panel.add(BrowserHelper.createLink("http://weka.wikispaces.com/Using+Weka+from+Jython", null));

    return result;
  }
예제 #3
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));
  }
예제 #4
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);
  }
예제 #5
0
  /** searches for a string in the cells */
  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);
  }
예제 #6
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));
  }
예제 #7
0
 /**
  * Returns an icon to be used in a frame.
  *
  * @return the icon
  */
 public ImageIcon getIcon() {
   return ComponentHelper.getImageIcon(IMAGES_DIR + "/jython_small.png");
 }
예제 #8
0
  /**
   * sets the specified values in a column to a new value
   *
   * @param o the menu item
   */
  private void setValues(Object o) {
    String msg;
    String title;
    String value;
    String valueNew;
    int i;
    ArffSortedTableModel 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_TableArff.getParent(), title, msg, m_LastSearch);

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

    m_LastSearch = value;

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

    model = (ArffSortedTableModel) m_TableArff.getModel();
    model.setNotificationEnabled(false);

    // undo
    addUndoPoint();
    model.setUndoEnabled(false);
    String valueCopy = value;
    // set value
    for (i = 0; i < m_TableArff.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))
        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_TableArff.repaint();
  }