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:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

public void showTabPopup(MouseEvent e) {
    JComponent tabHeaderComponent = (JComponent) e.getComponent();
    int tabIndex = getTabIndex(tabHeaderComponent);
    JComponent tabContent = (JComponent) tabsPane.getComponentAt(tabIndex);
    WindowBreadCrumbs windowBreadCrumbs = tabs.get(tabContent);

    Window window = windowBreadCrumbs.getCurrentWindow();

    JPopupMenu popupMenu = createWindowPopupMenu(window);
    if (popupMenu.getComponentCount() > 0) {
        popupMenu.show(tabHeaderComponent, e.getX(), e.getY());
    }//from   w  ww .  j a v a2s  .co  m
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void rootRightClickAction(final MouseEvent evt) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem refreshItem = new JMenuItem("Refresh Templates");
    JMenuItem resetConnectionItem = new JMenuItem("Reset Connection");
    menu.add(refreshItem);//from   www .  j a  v a  2s .  c  o m
    menu.add(resetConnectionItem);

    refreshItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            // simulate close and open to refresh the tree
            componentClosed();
            componentOpened();
        }
    });

    resetConnectionItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent evt) {
            ServerDetailsView serverDetails = getRefreshServerDetails();
            // set previous preferences
            Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class);
            serverDetails.setDetails(prefs.get("scheme", "http"), prefs.get("host", "localhost"),
                    prefs.get("port", "8080"), prefs.get("username", StringUtils.EMPTY),
                    prefs.get("password", StringUtils.EMPTY));
            // reset connection preferences
            prefs.remove("scheme");
            prefs.remove("host");
            prefs.remove("port");
            prefs.remove("username");
            prefs.remove("password");
            serverDetails.setVisible(true);
        }
    });
    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java

public Catalog() {
    menuTree = new org.orbisgis.core.ui.pluginSystem.menu.MenuTree();
    lstSources = new OGList();
    lstSources.addMouseListener(new MouseAdapter() {

        @Override/*from   ww w  . j a v a2  s  .  co m*/
        public void mousePressed(MouseEvent e) {
            showPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showPopup(e);
        }

        private void showPopup(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                int path = -1;
                for (int i = 0; i < listModel.getSize(); i++) {
                    if (lstSources.getCellBounds(i, i).contains(e.getPoint())) {
                        path = i;
                        break;
                    }
                }
                int[] selectionPaths = lstSources.getSelectedIndices();
                if ((selectionPaths != null) && (path != -1)) {
                    if (!CollectionUtils.contains(selectionPaths, path)) {
                        if (e.isControlDown()) {
                            lstSources.addSelectionInterval(path, path);
                        } else {
                            lstSources.setSelectionInterval(path, path);
                        }
                    }
                } else if (path == -1) {
                    lstSources.clearSelection();
                } else {
                }
            }
            if (e.isPopupTrigger()) {
                JPopupMenu popup = getPopup();
                if (popup != null) {
                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });
    listModel = new SourceListModel();
    lstSources.setModel(listModel);

    this.setLayout(new BorderLayout());
    this.add(new JScrollPane(lstSources), BorderLayout.CENTER);
    this.add(getNorthPanel(), BorderLayout.NORTH);
    SourceListRenderer cellRenderer = new SourceListRenderer(this);
    cellRenderer.setRenderers(new SourceRenderer[0]);
    lstSources.setCellRenderer(cellRenderer);

    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(lstSources, DnDConstants.ACTION_COPY_OR_MOVE, this);
    editingSources = new HashMap<String, EditableSource>();

    //Init the file drop system
    FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() {

        @Override
        public void filesDropped(java.io.File[] files) {
            DataManager dm = (DataManager) Services.getService(DataManager.class);
            SourceManager sourceManager = dm.getSourceManager();
            for (File file : files) {
                // For each file, we ensure that we have a driver
                // that can be used to read it. If we don't, we don't
                // open the file.
                if (OrbisConfiguration.isFileEligible(file)) {
                    try {
                        String name = sourceManager
                                .getUniqueName(FilenameUtils.removeExtension(file.getName()));
                        sourceManager.register(name, file);
                    } catch (SourceAlreadyExistsException e) {
                        ErrorMessages.error(ErrorMessages.SourceAlreadyRegistered + ": ", e);
                    }
                }
            }

        }
    });

}

From source file:com.mirth.connect.client.ui.DashboardPanel.java

/**
 * Shows the popup menu when the trigger button (right-click) has been pushed. Deselects the
 * rows if no row was selected.//from ww w . jav  a2  s.  c  o m
 */
private void checkSelectionAndPopupMenu(MouseEvent event) {
    TreePath path = dashboardTable.getPathForLocation(event.getX(), event.getY());

    /*
     * On mouse events we don't need to update the dashboard panel plugins. They will already
     * have been updated because of the ListSelectionEvent, and multiple mouse events will enter
     * here (as many as three, one pressed and two released) so we would basically be doing four
     * times the work.
     */
    if (path == null) {
        deselectRows(false);
    } else {
        updatePopupMenu(false);
    }

    if (event.isPopupTrigger()) {
        TreeSelectionModel selectionModel = dashboardTable.getTreeSelectionModel();

        if (!selectionModel.isPathSelected(path)) {
            deselectRows(false);
            selectionModel.addSelectionPath(path);
        }

        parent.dashboardPopupMenu.show(event.getComponent(), event.getX(), event.getY());
    }
}

From source file:Clavis.Windows.WShedule.java

public synchronized void refreshTable(int val) {
    DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
    if (modelo.getRowCount() > 0) {
        int tam = modelo.getRowCount();
        for (int h = 0; h < tam; h++) {
            modelo.removeRow(0);/*from  w w  w.j a va 2s . c o  m*/
        }
    }

    java.util.List<Keys.Request> requisicoes = new java.util.ArrayList<>();
    if (DataBase.DataBase.testConnection(url)) {
        DataBase.DataBase db = new DataBase.DataBase(url);
        requisicoes = Clavis.RequestList
                .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim));
        db.close();
    }
    lista = new java.util.ArrayList<>();
    andamento = 0;
    switch (val) {
    case 0:
        estado = lingua.translate("Todos");
        for (Keys.Request req : requisicoes) {
            String[] multipla = req.getActivity().split(":::");
            String saux;
            if (multipla.length > 1) {
                saux = multipla[0];
                Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                pop.create();
                jTable1.addMouseListener(new MouseAdapter() {
                    int x = andamento;
                    int y = 3;

                    @Override
                    public void mousePressed(MouseEvent e) {
                        if (e.getButton() == MouseEvent.BUTTON1) {
                            int row = jTable1.rowAtPoint(e.getPoint());
                            int col = jTable1.columnAtPoint(e.getPoint());
                            if ((row == x) && (col == y)) {
                                pop.show(e.getComponent(), e.getX(), e.getY());
                            }
                        }
                    }

                    @Override
                    public void mouseReleased(MouseEvent e) {
                        if (e.getButton() == MouseEvent.BUTTON1) {
                            if (pop.isShowing()) {
                                pop.setVisible(false);
                            }
                        }
                    }
                });
            } else {
                saux = req.getActivity();
            }
            if (saux.equals("")) {
                saux = lingua.translate("Sem descrio");
            }
            if (mat.getMaterialTypeID() == 1) {
                Object[] ob = { req.getPerson().getName(),
                        req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                        req.getBeginDate().toString(), saux, req.getSubject().getName() };
                modelo.addRow(ob);
            } else {
                Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                        req.getEndDate().toString(), saux };
                modelo.addRow(ob);
            }
            lista.add(req);
            andamento++;
        }
        break;
    case 1:
        estado = lingua.translate("terminado");
        for (Keys.Request req : requisicoes) {
            if (req.isTerminated()) {
                String[] multipla = req.getActivity().split(":::");
                String saux;
                if (multipla.length > 1) {
                    saux = multipla[0];
                    Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                    pop.create();
                    jTable1.addMouseListener(new MouseAdapter() {
                        int x = andamento;
                        int y = 3;

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                int row = jTable1.rowAtPoint(e.getPoint());
                                int col = jTable1.columnAtPoint(e.getPoint());
                                if ((row == x) && (col == y)) {
                                    pop.show(e.getComponent(), e.getX(), e.getY());
                                }
                            }
                        }

                        @Override
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                if (pop.isShowing()) {
                                    pop.setVisible(false);
                                }
                            }
                        }
                    });
                } else {
                    saux = req.getActivity();
                }
                if (saux.equals("")) {
                    saux = lingua.translate("Sem descrio");
                }
                if (mat.getMaterialTypeID() == 1) {
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), saux, req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), saux };
                    modelo.addRow(ob);
                }
                lista.add(req);
                andamento++;
            }
        }
        break;
    case 2:
        estado = lingua.translate("no realizado");
        for (Keys.Request req : requisicoes) {
            if ((!req.isActive()) && ((req.getEndDate().isBigger(new TimeDate.Date()) > 0)
                    || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0)
                            && (req.getTimeEnd().compareTime(new TimeDate.Time()) > 0)))) {
                String[] multipla = req.getActivity().split(":::");
                String saux;
                if (multipla.length > 1) {
                    saux = multipla[0];
                    Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                    pop.create();
                    jTable1.addMouseListener(new MouseAdapter() {
                        int x = andamento;
                        int y = 3;

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                int row = jTable1.rowAtPoint(e.getPoint());
                                int col = jTable1.columnAtPoint(e.getPoint());
                                if ((row == x) && (col == y)) {
                                    pop.show(e.getComponent(), e.getX(), e.getY());
                                }
                            }
                        }

                        @Override
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                if (pop.isShowing()) {
                                    pop.setVisible(false);
                                }
                            }
                        }
                    });
                } else {
                    saux = req.getActivity();
                }
                if (saux.equals("")) {
                    saux = lingua.translate("Sem descrio");
                }
                if (mat.getMaterialTypeID() == 1) {
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), saux, req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), saux };
                    modelo.addRow(ob);
                }
                lista.add(req);
                andamento++;
            }
        }
        break;
    case 3:
        estado = lingua.translate("por realizar");
        for (Keys.Request req : requisicoes) {
            if ((!req.isActive()) && (!req.isTerminated())
                    && ((req.getEndDate().isBigger(new TimeDate.Date()) < 0)
                            || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0)
                                    && (req.getTimeEnd().compareTime(new TimeDate.Time()) < 0)))) {
                String[] multipla = req.getActivity().split(":::");
                String saux;
                if (multipla.length > 1) {
                    saux = multipla[0];
                    Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                    pop.create();
                    jTable1.addMouseListener(new MouseAdapter() {
                        int x = andamento;
                        int y = 3;

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                int row = jTable1.rowAtPoint(e.getPoint());
                                int col = jTable1.columnAtPoint(e.getPoint());
                                if ((row == x) && (col == y)) {
                                    pop.show(e.getComponent(), e.getX(), e.getY());
                                }
                            }
                        }

                        @Override
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                if (pop.isShowing()) {
                                    pop.setVisible(false);
                                }
                            }
                        }
                    });
                } else {
                    saux = req.getActivity();
                }
                if (saux.equals("")) {
                    saux = lingua.translate("Sem descrio");
                }
                if (mat.getMaterialTypeID() == 1) {
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), saux, req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), saux };
                    modelo.addRow(ob);
                }
                lista.add(req);
                andamento++;
            }
        }
        break;
    }
    valores = new String[lista.size()][4];
    for (int i = 0; i < lista.size(); i++) {
        String[] multipla = lista.get(i).getActivity().split(":::");
        String saux = multipla[0];
        if (saux.equals("")) {
            saux = lingua.translate("Sem descrio");
        }
        if (mat.getMaterialTypeID() == 1) {
            valores[i][0] = lista.get(i).getPerson().getName();
            valores[i][1] = lista.get(i).getTimeBegin().toString(0) + " - "
                    + lista.get(i).getTimeEnd().toString(0);
            valores[i][2] = lista.get(i).getBeginDate().toString();
            valores[i][3] = saux + " - " + lista.get(i).getSubject().getName();
        } else {
            valores[i][0] = lista.get(i).getPerson().getName();
            valores[i][1] = lista.get(i).getBeginDate().toString();
            valores[i][2] = lista.get(i).getEndDate().toString();
            valores[i][3] = saux;
        }
    }
}

From source file:op.care.prescription.DlgRegular.java

private void tblDosisMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDosisMousePressed
    if (!SwingUtilities.isRightMouseButton(evt)) {
        return;/*from www  . j a va 2 s.  co  m*/
    }

    final TMDose tm = (TMDose) tblDosis.getModel();
    if (tm.getRowCount() == 0) {
        return;
    }
    Point p = evt.getPoint();
    Point p2 = evt.getPoint();
    // Convert a coordinate relative to a component's bounds to screen coordinates
    SwingUtilities.convertPointToScreen(p2, tblDosis);

    //        final Point screenposition = p2;
    final int row = tblDosis.rowAtPoint(p);

    ListSelectionModel lsm = tblDosis.getSelectionModel();
    lsm.setSelectionInterval(row, row);

    // Meneintrge
    SYSTools.unregisterListeners(menu);
    menu = new JPopupMenu();

    //-----------------------------------------
    JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.msg.delete"), SYSConst.icon22delete);
    itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PrescriptionSchedule schedule = prescription.getPrescriptionSchedule().get(row);
            prescription.getPrescriptionSchedule().remove(schedule);
            schedules2delete.add(schedule);
            reloadTable();
        }
    });
    menu.add(itemPopupDelete);
    menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());

}

From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java

private void sedsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sedsTableMousePressed
    if (evt.isPopupTrigger()) {
        JTable source = (JTable) evt.getSource();
        int row = source.rowAtPoint(evt.getPoint());
        int column = source.columnAtPoint(evt.getPoint());

        if (!source.isRowSelected(row))
            source.changeSelection(row, column, false, false);

        sedsTable.changeSelection(row, column, false, false);

        jPopupMenu2.show(evt.getComponent(), evt.getX(), evt.getY());
    }/* ww  w. j  a  v a  2s  .  co  m*/
}

From source file:com.hp.alm.ali.idea.content.taskboard.TaskBoardPanel.java

public TaskBoardPanel(final Project project) {
    super(new BorderLayout());

    this.project = project;

    status = new EntityStatusPanel(project);
    queue = new QueryQueue(project, status, false);

    entityService = project.getComponent(EntityService.class);
    entityService.addEntityListener(this);
    sprintService = project.getComponent(SprintService.class);
    sprintService.addListener(this);

    loadTasks();/* w w w.j  a va 2  s .c o m*/

    header = new Header();
    columnHeader = new ColumnHeader();

    content = new Content();
    add(content, BorderLayout.NORTH);

    header.assignedTo.reload();

    // force mouse-over task as visible (otherwise events are captured by the overlay and repaint quirks)
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing() && event.getID() == MouseEvent.MOUSE_MOVED) {
                MouseEvent m = (MouseEvent) event;
                TaskPanel currentPanel = locateContainer(m, TaskPanel.class);
                if (currentPanel != null) {
                    if (forcedTaskPanel == currentPanel) {
                        return;
                    } else if (forcedTaskPanel != null) {
                        forcedTaskPanel.removeForcedMatch(this);
                    }
                    forcedTaskPanel = currentPanel;
                    forcedTaskPanel.addForcedMatch(this);
                } else if (forcedTaskPanel != null) {
                    forcedTaskPanel.removeForcedMatch(this);
                    forcedTaskPanel = null;
                }
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing()) {
                MouseEvent m = (MouseEvent) event;
                switch (event.getID()) {
                case MouseEvent.MOUSE_PRESSED:
                case MouseEvent.MOUSE_RELEASED:
                    // implement backlog item popup
                    if (m.isPopupTrigger()) {
                        final BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            ActionPopupMenu popupMenu = ActionUtil.createEntityActionPopup("taskboard");
                            Point p = SwingUtilities.convertPoint(m.getComponent(), m.getPoint(), itemPanel);
                            popupMenu.getComponent().show(itemPanel, p.x, p.y);
                        }
                    }
                    break;

                case MouseEvent.MOUSE_CLICKED:
                    // implement backlog item double click
                    if (m.getClickCount() > 1) {
                        BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            Entity backlogItem = itemPanel.getItem();
                            Entity workItem = new Entity(backlogItem.getPropertyValue("entity-type"),
                                    Integer.valueOf(backlogItem.getPropertyValue("entity-id")));
                            AliContentFactory.loadDetail(project, workItem, true, true);
                        }
                    }
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java

private void pdsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pdsTableMousePressed
    if (evt.isPopupTrigger()) {
        copyMenuItem.setEnabled(!pdsTable.getSelectionModel().isSelectionEmpty());
        Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
        pasteMenuItem.setEnabled(contents.isDataFlavorSupported(DataFlavor.stringFlavor));
        tablePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//w  ww  .  j  a va2s  .  c om
}

From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java

private void pdsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pdsTableMouseReleased
    if (evt.isPopupTrigger()) {
        copyMenuItem.setEnabled(!pdsTable.getSelectionModel().isSelectionEmpty());
        Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
        pasteMenuItem.setEnabled(contents.isDataFlavorSupported(DataFlavor.stringFlavor));
        tablePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }/*from w  w w .  jav a  2 s.  co m*/
}