Example usage for java.awt.event MouseEvent getComponent

List of usage examples for java.awt.event MouseEvent getComponent

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getComponent.

Prototype

public Component getComponent() 

Source Link

Document

Returns the originator of the event.

Usage

From source file:org.nuclos.client.ui.collect.searcheditor.SearchEditorController.java

/**
 * event: a mouse event occured on a node in the <code>view</code>
 * @param selPath the path of the node where the mouse event occured.
 * @param ev//  w  w  w  . ja  v  a  2 s  .com
 */
private void mouseEventOnNode(TreePath selPath, MouseEvent ev) {
    final SearchConditionTreeNode node = (SearchConditionTreeNode) selPath.getLastPathComponent();
    final JTree tree = (JTree) ev.getComponent();

    // select the node:
    tree.setSelectionPath(selPath);

    if (ev.isPopupTrigger()) {
        // show popup menu:
        final JPopupMenu popupMenu = this.getPopupMenu(node, tree);
        if (popupMenu != null) {
            popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
        }
    } else if (ev.getID() == MouseEvent.MOUSE_CLICKED) {
        if (ev.getButton() == MouseEvent.BUTTON1) {
            if (ev.getClickCount() == 2) {
                if (this.clctfproviderfactory == null) {
                    throw new IllegalStateException(
                            "No CollectableFieldsProviderFactory was defined for the search editor.");
                }
                // perform the node's default action:
                final Action actDefault = node.getDefaultTreeNodeAction(tree, this.clcteRoot,
                        this.clctfproviderfactory, this.additionalFields);
                if (actDefault != null) {
                    actDefault.actionPerformed(null);
                }
            }
        }
    }
}

From source file:medsavant.enrichment.app.RegionListAggregatePanel.java

private void createSearchableTable() {
    tablePanel = new SearchableTablePanel(pageName,
            new String[] { "Name", "Chromosome", "Start", "End", "Length", "Variants", "Variants / KB",
                    "Individuals" },
            new Class[] { String.class, String.class, Integer.class, Integer.class, Integer.class,
                    Integer.class, Double.class, Integer.class },
            new int[0], true, true, Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW,
            Integer.MAX_VALUE, new AggregationRetriever());

    tablePanel.getTable().addMouseListener(new MouseAdapter() {
        @Override//from   www  .  j  av  a  2s. c om
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                createPopup().show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    showShowCard();
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

@Override
public void mouseMoved(MouseEvent e) {
    if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED))
        return;//from   ww  w. j  a  v a 2  s  . c  om

    if (e.getComponent() instanceof ChartPanel) {
        ChartPanel chartPanel = (ChartPanel) e.getComponent();
        ChartEntity entity = findChartEntity(chartPanel, e);
        ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
        Button button = Button.getButton(e.getButton());

        // handle event
        handleEvent(new ChartGestureEvent(chartPanel, e, entity,
                new ChartGesture(gestureEntity, Event.MOVED, button)));
    }
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

@Override
public void mouseExited(MouseEvent e) {
    if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.EXITED))
        return;/*from  w ww . ja v  a2  s. c  o m*/

    if (e.getComponent() instanceof ChartPanel) {
        ChartPanel chartPanel = (ChartPanel) e.getComponent();
        ChartEntity entity = findChartEntity(chartPanel, e);
        ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
        Button button = Button.getButton(e.getButton());

        // handle event
        handleEvent(new ChartGestureEvent(chartPanel, e, entity,
                new ChartGesture(gestureEntity, Event.EXITED, button)));
    }
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

@Override
public void mousePressed(MouseEvent e) {
    if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.PRESSED))
        return;/*ww  w . ja va2s  .  c  o  m*/

    if (e.getComponent() instanceof ChartPanel) {
        ChartPanel chartPanel = (ChartPanel) e.getComponent();
        ChartEntity entity = findChartEntity(chartPanel, e);
        ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
        Button button = Button.getButton(e.getButton());
        // handle event
        lastDragEvent = new ChartGestureEvent(chartPanel, e, entity,
                new ChartGesture(gestureEntity, Event.PRESSED, button));
        handleEvent(lastDragEvent);
    }
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

@Override
public void mouseEntered(MouseEvent e) {
    if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.ENTERED))
        return;//from  ww  w.  j  ava 2 s. co  m

    if (e.getComponent() instanceof ChartPanel) {
        ChartPanel chartPanel = (ChartPanel) e.getComponent();
        ChartEntity entity = findChartEntity(chartPanel, e);
        ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
        Button button = Button.getButton(e.getButton());

        // handle event
        handleEvent(new ChartGestureEvent(chartPanel, e, entity,
                new ChartGesture(gestureEntity, Event.ENTERED, button)));
    }
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

@Override
public void mouseDragged(MouseEvent e) {
    if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.DRAGGED))
        return;/*from  ww  w  . j  a  v a 2 s .co  m*/

    if (e.getComponent() instanceof ChartPanel) {
        ChartPanel chartPanel = (ChartPanel) e.getComponent();
        // keep the same chartEntity
        ChartEntity entity = lastDragEvent.getEntity();
        ChartGesture.Entity gestureEntity = lastDragEvent.getGesture().getEntity();
        Button button = lastDragEvent.getGesture().getButton();

        // handle event
        lastDragEvent = new ChartGestureEvent(chartPanel, e, entity,
                new ChartGesture(gestureEntity, Event.DRAGGED, button));
        handleEvent(lastDragEvent);
    }
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

@Override
public void mouseReleased(MouseEvent e) {
    if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED))
        return;/*w ww  .j  a v  a  2s  . c  o  m*/

    if (e.getComponent() instanceof ChartPanel) {
        ChartPanel chartPanel = (ChartPanel) e.getComponent();
        ChartEntity entity = findChartEntity(chartPanel, e);
        ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
        Button button = Button.getButton(e.getButton());

        // last gesture was dragged? keep the same chartEntity
        if (lastDragEvent != null) {
            entity = lastDragEvent.getEntity();
            gestureEntity = lastDragEvent.getGesture().getEntity();
        }
        // handle event
        handleEvent(new ChartGestureEvent(chartPanel, e, entity,
                new ChartGesture(gestureEntity, Event.RELEASED, button)));

        // reset drag
        lastDragEvent = null;
    }
}

From source file:edu.harvard.mcz.imagecapture.DeterminationFrame.java

/**
 * This method initializes jTable   //ww  w.j  a  v  a2  s  .  c om
 *    
 * @return javax.swing.JTable   
 */
private JTable getJTable() {
    if (jTableDeterminations == null) {
        jTableDeterminations = new JTable();
        DeterminationTableModel model = new DeterminationTableModel();
        jTableDeterminations.setModel(model);
        if (determinations != null) {
            jTableDeterminations.setModel(determinations);
        }

        FilteringAgentJComboBox field = new FilteringAgentJComboBox();
        jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_IDENTIFIEDBY)
                .setCellEditor(new ComboBoxCellEditor(field));

        setTableColumnEditors();

        jTableDeterminations.setRowHeight(jTableDeterminations.getRowHeight() + 4);

        jTableDeterminations.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupDets.show(e.getComponent(), e.getX(), e.getY());
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupDets.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        jPopupDets = new JPopupMenu();
        JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
        mntmDeleteRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    log.debug(clickedOnDetsRow);
                    if (clickedOnDetsRow >= 0) {
                        int ok = JOptionPane.showConfirmDialog(thisFrame, "Delete the selected determination?",
                                "Delete Determination", JOptionPane.OK_CANCEL_OPTION);
                        if (ok == JOptionPane.OK_OPTION) {
                            log.debug("deleting determination row " + clickedOnDetsRow);
                            ((DeterminationTableModel) jTableDeterminations.getModel())
                                    .deleteRow(clickedOnDetsRow);
                        } else {
                            log.debug("determination row delete canceled by user.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(thisFrame, "Unable to select row to delete.");
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    JOptionPane.showMessageDialog(thisFrame,
                            "Failed to delete a determination row. " + ex.getMessage());
                }
            }
        });
        jPopupDets.add(mntmDeleteRow);

    }
    return jTableDeterminations;
}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

public void setMirthColumnControlEnabled(boolean enabled) {
    if (enabled) {
        if (tableSortAdapter == null) {
            tableSortAdapter = new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isRightMouseButton(e)) {
                        getColumnMenu().show(e.getComponent(), e.getX(), e.getY());
                    }//  w w  w .  j  a v a 2s. c o m
                }
            };

            getTableHeader().addMouseListener(tableSortAdapter);
        }
    } else {
        if (tableSortAdapter != null) {
            getTableHeader().removeMouseListener(tableSortAdapter);
            tableSortAdapter = null;
        }
    }

    setColumnControlVisible(enabled);
}