/** 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); }
/** * 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); } }