コード例 #1
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));
  }
コード例 #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);
  }
コード例 #3
0
  /** deletes the currently selected instance */
  public void deleteInstance() {
    int index;

    index = m_TableArff.getSelectedRow();
    if (index == -1) return;

    ((ArffSortedTableModel) m_TableArff.getModel()).deleteInstanceAt(index);
  }
コード例 #4
0
  /** deletes all the currently selected instances */
  public void deleteInstances() {
    int[] indices;

    if (m_TableArff.getSelectedRow() == -1) return;

    indices = m_TableArff.getSelectedRows();
    ((ArffSortedTableModel) m_TableArff.getModel()).deleteInstances(indices);
  }
コード例 #5
0
  /**
   * returns the instances of the panel, if none then NULL
   *
   * @return the instances of the panel
   */
  public Instances getInstances() {
    Instances result;

    result = null;

    if (m_TableArff.getModel() != null)
      result = ((ArffSortedTableModel) m_TableArff.getModel()).getInstances();

    return result;
  }
コード例 #6
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));
  }
コード例 #7
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));
  }
コード例 #8
0
  /** sets the relation name */
  private void createName() {
    ArffSortedTableModel model;

    model = (ArffSortedTableModel) m_TableArff.getModel();
    if ((model != null) && (model.getInstances() != null))
      m_LabelName.setText("Relation: " + model.getInstances().relationName());
    else m_LabelName.setText("");
  }
コード例 #9
0
  /** performs an undo action */
  public void undo() {
    if (canUndo()) {
      ((ArffSortedTableModel) m_TableArff.getModel()).undo();

      // notify about update
      notifyListener();
    }
  }
コード例 #10
0
  /**
   * Invoked when a mouse button has been pressed and released on a component
   *
   * @param e the mouse event
   */
  public void mouseClicked(MouseEvent e) {
    int col;
    boolean popup;

    col = m_TableArff.columnAtPoint(e.getPoint());
    popup =
        ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1))
            || ((e.getButton() == MouseEvent.BUTTON1)
                && (e.getClickCount() == 1)
                && e.isAltDown()
                && !e.isControlDown()
                && !e.isShiftDown());
    popup = popup && (getInstances() != null);

    if (e.getSource() == m_TableArff.getTableHeader()) {
      m_CurrentCol = col;

      // Popup-Menu
      if (popup) {
        e.consume();
        setMenu();
        initPopupMenus();
        m_PopupHeader.show(e.getComponent(), e.getX(), e.getY());
      }
    } else if (e.getSource() == m_TableArff) {
      // Popup-Menu
      if (popup) {
        e.consume();
        setMenu();
        initPopupMenus();
        m_PopupRows.show(e.getComponent(), e.getX(), e.getY());
      }
    }

    // highlihgt column
    if ((e.getButton() == MouseEvent.BUTTON1)
        && (e.getClickCount() == 1)
        && (!e.isAltDown())
        && (col > -1)) {
      m_TableArff.setSelectedColumn(col);
    }
  }
コード例 #11
0
  /** creates all the components in the frame */
  protected void createPanel() {
    JScrollPane pane;

    setLayout(new BorderLayout());

    menuItemMean = new JMenuItem("Get mean...");
    menuItemMean.addActionListener(this);
    menuItemSetAllValues = new JMenuItem("Set all values to...");
    menuItemSetAllValues.addActionListener(this);
    menuItemSetMissingValues = new JMenuItem("Set missing values to...");
    menuItemSetMissingValues.addActionListener(this);
    menuItemReplaceValues = new JMenuItem("Replace values with...");
    menuItemReplaceValues.addActionListener(this);
    menuItemRenameAttribute = new JMenuItem("Rename attribute...");
    menuItemRenameAttribute.addActionListener(this);
    menuItemAttributeAsClass = new JMenuItem("Attribute as class");
    menuItemAttributeAsClass.addActionListener(this);
    menuItemDeleteAttribute = new JMenuItem("Delete attribute");
    menuItemDeleteAttribute.addActionListener(this);
    menuItemDeleteAttributes = new JMenuItem("Delete attributes...");
    menuItemDeleteAttributes.addActionListener(this);
    menuItemSortInstances = new JMenuItem("Sort data (ascending)");
    menuItemSortInstances.addActionListener(this);
    menuItemOptimalColWidth = new JMenuItem("Optimal column width (current)");
    menuItemOptimalColWidth.addActionListener(this);
    menuItemOptimalColWidths = new JMenuItem("Optimal column width (all)");
    menuItemOptimalColWidths.addActionListener(this);

    // row popup
    menuItemUndo = new JMenuItem("Undo");
    menuItemUndo.addActionListener(this);
    menuItemCopy = new JMenuItem("Copy");
    menuItemCopy.addActionListener(this);
    menuItemSearch = new JMenuItem("Search...");
    menuItemSearch.addActionListener(this);
    menuItemClearSearch = new JMenuItem("Clear search");
    menuItemClearSearch.addActionListener(this);
    menuItemDeleteSelectedInstance = new JMenuItem("Delete selected instance");
    menuItemDeleteSelectedInstance.addActionListener(this);
    menuItemDeleteAllSelectedInstances = new JMenuItem("Delete ALL selected instances");
    menuItemDeleteAllSelectedInstances.addActionListener(this);

    // table
    m_TableArff = new ArffTable();
    m_TableArff.setToolTipText("Right click (or left+alt) for context menu");
    m_TableArff.getTableHeader().addMouseListener(this);
    m_TableArff
        .getTableHeader()
        .setToolTipText(
            "<html><b>Sort view:</b> left click = ascending / Shift + left click = descending<br><b>Menu:</b> right click (or left+alt)</html>");
    m_TableArff.getTableHeader().setDefaultRenderer(new ArffTableCellRenderer());
    m_TableArff.addChangeListener(this);
    m_TableArff.addMouseListener(this);
    pane = new JScrollPane(m_TableArff);
    add(pane, BorderLayout.CENTER);

    // relation name
    m_LabelName = new JLabel();
    add(m_LabelName, BorderLayout.NORTH);
  }
コード例 #12
0
  /**
   * displays the given instances, i.e. creates a tab with the title TAB_INSTANCES. if one already
   * exists it closes it.<br>
   * if a different instances object is used here, don't forget to clear the undo-history by calling
   * <code>clearUndo()</code>
   *
   * @param data the instances to display
   * @see #TAB_INSTANCES
   * @see #clearUndo()
   */
  public void setInstances(Instances data) {
    ArffSortedTableModel model;

    m_Filename = TAB_INSTANCES;

    createTitle();
    model = new ArffSortedTableModel(data);
    model.setShowAttributeIndex(m_ShowAttributeIndex);

    m_TableArff.setModel(model);
    clearUndo();
    setChanged(false);
    createName();
  }
コード例 #13
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));
  }
コード例 #14
0
  /**
   * loads the specified file into the table
   *
   * @param filename the file to load
   */
  private void loadFile(String filename) {
    ArffSortedTableModel model;

    this.m_Filename = filename;

    createTitle();

    if (filename.equals("")) {
      model = null;
    } else {
      model = new ArffSortedTableModel(filename);
      model.setShowAttributeIndex(getShowAttributeIndex());
    }

    m_TableArff.setModel(model);
    setChanged(false);
    createName();
  }
コード例 #15
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));
  }
コード例 #16
0
  /** adds the current state of the instances to the undolist */
  public void addUndoPoint() {
    ((ArffSortedTableModel) m_TableArff.getModel()).addUndoPoint();

    // update menu
    setMenu();
  }
コード例 #17
0
  /** sorts the instances via the currently selected column */
  public void sortInstances() {
    if (m_CurrentCol == -1) return;

    ((ArffSortedTableModel) m_TableArff.getModel()).sortInstances(m_CurrentCol);
  }
コード例 #18
0
 /**
  * returns whether the model is read-only
  *
  * @return true if model is read-only
  */
 public boolean isReadOnly() {
   if (m_TableArff == null) return true;
   else return ((ArffSortedTableModel) m_TableArff.getModel()).isReadOnly();
 }
コード例 #19
0
 /**
  * sets whether the model is read-only
  *
  * @param value if true the model is set to read-only
  */
 public void setReadOnly(boolean value) {
   if (m_TableArff != null) ((ArffSortedTableModel) m_TableArff.getModel()).setReadOnly(value);
 }
コード例 #20
0
 /**
  * Sets whether to display the attribute index in the header.
  *
  * @param value if true then the attribute indices are displayed in the table header
  */
 public void setShowAttributeIndex(boolean value) {
   m_ShowAttributeIndex = value;
   if (m_TableArff != null)
     ((ArffSortedTableModel) m_TableArff.getModel()).setShowAttributeIndex(value);
 }
コード例 #21
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();
  }
コード例 #22
0
 /**
  * returns whether undo support is enabled
  *
  * @return true if undo is enabled
  */
 public boolean isUndoEnabled() {
   return ((ArffSortedTableModel) m_TableArff.getModel()).isUndoEnabled();
 }
コード例 #23
0
 /**
  * sets whether undo support is enabled
  *
  * @param enabled whether to enable/disable undo support
  */
 public void setUndoEnabled(boolean enabled) {
   ((ArffSortedTableModel) m_TableArff.getModel()).setUndoEnabled(enabled);
 }
コード例 #24
0
 /** removes the undo history */
 public void clearUndo() {
   ((ArffSortedTableModel) m_TableArff.getModel()).clearUndo();
 }
コード例 #25
0
 /**
  * returns whether an undo is possible
  *
  * @return true if undo is possible
  */
 public boolean canUndo() {
   return ((ArffSortedTableModel) m_TableArff.getModel()).canUndo();
 }