Example usage for java.awt.event MouseEvent getButton

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

Introduction

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

Prototype

public int getButton() 

Source Link

Document

Returns which, if any, of the mouse buttons has changed state.

Usage

From source file:ru.goodfil.catalog.ui.forms.CarsPanel.java

private void allFiltersTableMouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        if (allFilters.size() > 0) {
            listsPopupMenu.show(allFiltersTable, e.getX(), e.getY());
        }/*from ww  w.j av  a2s  .  c  o  m*/
    }
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

public void mouseClicked(final MouseEvent e) {
    Point prePos = e.getPoint();//w  w w . ja va 2 s.  c o m
    float sp[] = { 0.0f, 0.0f };
    this.convertMousePointToSceneSpace(prePos, scenePos);

    switch (e.getButton()) {
    case MouseEvent.BUTTON1:
        if (e.getClickCount() > 1) { // doubleclick zoom in/out
            Point mousePos = e.getPoint();

            float[] cp = { 0.0f, 0.0f };
            float[] sc = { 0.0f, 0.0f };

            canvasLock.lock();

            convertMousePointToSceneSpace(mousePos, cp);

            sc[0] = SceneGraph.getSceneCenterX();
            sc[1] = SceneGraph.getSceneCenterY();

            // alt down for zoom out?!
            float base;
            if (e.isAltDown()) { // zoom out
                base = 1.05f;
            } else { // zoom out
                base = 0.95f;
            }

            float scale = (float) Math.pow(base, 3);

            SceneGraph.scaleScene(scale);

            float ncp[] = { 0.0f, 0.0f };

            this.convertMousePointToSceneSpace(mousePos, ncp);
            ncp[0] = ncp[0] - cp[0];
            ncp[1] = ncp[1] - cp[1];

            SceneGraph.panScene(-ncp[0], -ncp[1]);
            canvasLock.unlock();

            CorelyzerApp.getApp().updateGLWindows();
            return;
        }

        // measuring mode
        if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) {
            int nPoint = SceneGraph.addMeasurePoint(scenePos[0], scenePos[1]);
            this.convertScenePointToAbsolute(scenePos, sp);
            if (nPoint == 1) {
                CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 1);
            } else if (nPoint == 2) {
                CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 2);
            }

            PAN_MODE = 0;
            return;
        }

        if (selectedFreeDraw > -1) {
            CorelyzerApp.getApp().getPluginManager().broadcastEventToPlugin(
                    SceneGraph.getFreeDrawPluginID(selectedFreeDraw), CorelyzerPluginEvent.FREE_DRAW_SELECTED,
                    "" + selectedFreeDraw);
            return;
        }

        selectedMarker = SceneGraph.accessPickedMarker();

        if (selectedMarker < 0) {
            if (canvasMode == CorelyzerApp.APP_MARKER_MODE) {
                SceneGraph.setCoreSectionMarkerFocus(false);
                CorelyzerApp.getApp().updateGLWindows();
            }
            return;
        } else {
            if (canvasMode == CorelyzerApp.APP_NORMAL_MODE) {
                AnnotationUtils.openAnnotation(getCanvas(), selectedTrack, selectedTrackSection,
                        selectedMarker);
            } else { // marker mode
                // TODO do something if want to allow user adjust the
                // selected
                // TODO block, like sync to ClastInfo hash...
                if (selectedMarker != SceneGraph.focusedMarker
                        || selectedTrackSection != SceneGraph.focusedTrackSection
                        || selectedTrack != SceneGraph.focusedTrack) {
                    SceneGraph.setCoreSectionMarkerFocus(false);

                    SceneGraph.focusedTrack = selectedTrack;
                    SceneGraph.focusedTrackSection = selectedTrackSection;
                    SceneGraph.focusedMarker = selectedMarker;
                    SceneGraph.setCoreSectionMarkerFocus(true);
                }
            }
        }

        break;

    case MouseEvent.BUTTON2:
        /*
         * System.out.println("---- Middle button clicked at: " +
         * prePos.x + ", " + prePos.y);
         * System.out.println("Converted to Scene Space: " + scenePos[0]
         * + ", " + scenePos[1]);
         */
        break;

    case MouseEvent.BUTTON3:
        /*
         * System.out.println("---- Right button clicked at: " +
         * prePos.x + ", " + prePos.y);
         * System.out.println("Converted to Scene Space: " + scenePos[0]
         * + ", " + scenePos[1]);
         */
        this.handleRightMouseClick(e);
        break;
    default:
        if (e.isPopupTrigger()) {
            this.handleRightMouseClick(e);
        }
    }
}

From source file:net.sf.firemox.clickable.target.card.MCard.java

@Override
public void mouseClicked(MouseEvent e) {
    if (!(getParent() instanceof MZone) && !(getParent() instanceof MCard)) {
        return;/* w w w. jav  a  2  s.  c o m*/
    }
    StackManager.noReplayToken.take();
    MZone container = getContainer();
    try {
        TargetFactory.triggerTargetable = this;
        if (ConnectionManager.isConnected() && e.getButton() == MouseEvent.BUTTON1) {
            // only if left button is pressed
            if (!StackManager.actionManager.clickOn(this)) {
                // this card is activated and you control it
                if (!(StackManager.actionManager.currentAction instanceof WaitingAbility)) {
                    // we are not waiting ability
                    if (container instanceof ExpandableZone) {
                        ((ExpandableZone) container).toggle();
                    }
                    return;
                }
                final List<Ability> abilities = ((WaitingAbility) StackManager.actionManager.currentAction)
                        .abilitiesOf(this);
                final List<Ability> advAbilities = ((WaitingAbility) StackManager.actionManager.currentAction)
                        .advancedAbilitiesOf(this);

                // is there any playable ability with this card ?
                if ((abilities == null || abilities.isEmpty())
                        && (advAbilities == null || advAbilities.isEmpty())) {
                    // no playable ability, and this card is not wait for -> toggle
                    if (container instanceof ExpandableZone) {
                        ((ExpandableZone) container).toggle();
                    }
                    return;
                }

                // a choice has to be made
                if (advAbilities != null && !advAbilities.isEmpty()
                        || abilities != null && abilities.size() > 1) {
                    /*
                     * several abilities for this card, we fill the popup ability menu
                     */
                    TargetFactory.abilitiesMenu.removeAll();
                    if (abilities != null) {
                        for (Ability ability : abilities) {
                            final JMenuItem item = new JMenuItem(
                                    "<html>" + ability.toHtmlString(null) + "</html>");
                            item.addActionListener(this);
                            TargetFactory.abilitiesMenu.add(item);
                        }
                    }
                    if (advAbilities != null && !advAbilities.isEmpty()) {
                        TargetFactory.abilitiesMenu.add(new JSeparator());
                        for (Ability ability : advAbilities) {
                            final JMenuItem item = new JMenuItem(
                                    "<html>" + ability.toHtmlString(null) + "</html>", WARNING_PICTURE);
                            item.addActionListener(this);
                            TargetFactory.abilitiesMenu.add(item);
                        }
                    }
                    // show the option popup menu
                    TargetFactory.abilitiesMenu.show(e.getComponent(), e.getX(), e.getY());
                    return;
                } else if (abilities != null && abilities.size() == 1
                        && (advAbilities == null || advAbilities.isEmpty())) {
                    // only one playable ability, we select it automatically
                    ((UserAbility) abilities.get(0)).mouseClicked(0);
                }
            } else if (StackManager.idHandedPlayer != 0) {
                if (container instanceof ExpandableZone) {
                    ((ExpandableZone) container).toggle();
                }
            } else {
                // Since this click has been handled, the opponent will be informed on
                sendClickToOpponent();
                StackManager.actionManager.succeedClickOn(this);
            }
        } else if (ConnectionManager.isConnected()) {
            // only if not left button is pressed
            CardFactory.contextMenu.removeAll();
            TargetFactory.triggerTargetable = this;

            // add counter item
            CardFactory.countItem.setText(LanguageManager.getString("countcard", container.toString(),
                    String.valueOf(container.getCardCount())));
            CardFactory.contextMenu.add(CardFactory.countItem);

            // add refresh picture item
            CardFactory.contextMenu.add(CardFactory.reloadPictureItem);

            // add expand/gather item
            if (container instanceof ExpandableZone) {
                if (container == ZoneManager.expandedZone) {
                    CardFactory.contextMenu.add(CardFactory.gatherItem);
                } else {
                    CardFactory.contextMenu.add(CardFactory.expandItem);
                }
            }
            CardFactory.contextMenu.add(new JSeparator());

            // add the "database" item --> activate the tabbed panel
            CardFactory.contextMenu.add(CardFactory.databaseCardInfoItem);

            // TODO add "java properties" item --> show an inspect popup.
            // CardFactory.contextMenu.add(CardFactory.javaDebugItem);

            // TODO add "show id" option

            // show the option popup menu
            CardFactory.contextMenu.show(e.getComponent(), e.getX(), e.getY());
        }
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        StackManager.noReplayToken.release();
    }
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private void definePopup() {
    // These key bindings are just to have the shortcuts displayed
    // in the popup menu. The actual keystroke processing is in
    // BasePanel (entryTable.addKeyListener(...)).
    groupsContextMenu.add(editGroupPopupAction);
    groupsContextMenu.add(addGroupPopupAction);
    groupsContextMenu.add(addSubgroupPopupAction);
    groupsContextMenu.addSeparator();//from  w  w  w  . j a  v a2s  .  c  o m
    groupsContextMenu.add(removeGroupAndSubgroupsPopupAction);
    groupsContextMenu.add(removeGroupKeepSubgroupsPopupAction);
    groupsContextMenu.add(removeSubgroupsPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(expandSubtreePopupAction);
    groupsContextMenu.add(collapseSubtreePopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(moveSubmenu);
    sortSubmenu.add(sortDirectSubgroupsPopupAction);
    sortSubmenu.add(sortAllSubgroupsPopupAction);
    groupsContextMenu.add(sortSubmenu);
    moveSubmenu.add(moveNodeUpPopupAction);
    moveSubmenu.add(moveNodeDownPopupAction);
    moveSubmenu.add(moveNodeLeftPopupAction);
    moveSubmenu.add(moveNodeRightPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(addToGroup);
    groupsContextMenu.add(moveToGroup);
    groupsContextMenu.add(removeFromGroup);
    groupsTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

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

        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (path == null) {
                return;
            }
            GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent();
            // the root node is "AllEntries" and cannot be edited
            if (node.getNode().isRoot()) {
                return;
            }
            if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { // edit
                editGroupAction.actionPerformed(null); // dummy event
            } else if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
                annotationEvent(node);
            }
        }
    });
    // be sure to remove a possible border highlight when the popup menu
    // disappears
    groupsContextMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            // nothing to do
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }
    });
}

From source file:org.martin.ftp.gui.GUIClient.java

private void tblFilesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFilesMouseReleased

    if (evt.getButton() == 3) {

    }/*from   w  w  w .  j  a va2s . c  o  m*/

    if (evt.getClickCount() == 2)
        try {
            setWorkingDirectory();
        } catch (IOException ex) {
            Logger.getLogger(GUIClient.class.getName()).log(Level.SEVERE, null, ex);
        }

}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

public void mousePressed(final MouseEvent e) {
    prePos = e.getPoint();//  ww w.j  a v a  2s .  c o  m
    float sp[] = { 0.0f, 0.0f };
    this.convertMousePointToSceneSpace(prePos, scenePos);

    PAN_MODE = 0;
    ZOOM_MODE = 0;
    MANIPULATE_MODE = 0;

    // For mouse right-click or Ctrl-Left-Click
    if (e.isPopupTrigger()) {
        this.handleRightMouseClick(e);

        return;
    }

    switch (e.getButton()) {
    case MouseEvent.BUTTON1:

        if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) {
            return;
        } else if (canvasMode == CorelyzerApp.APP_MARKER_MODE) {

            // the first check up: focused marker manipulation
            if (SceneGraph.focusedMarker > -1) {
                if (SceneGraph.hitMarker(canvasId, scenePos[0], scenePos[1])) {
                    MANIPULATE_MODE = 1;

                    /*
                     * System.out.println(
                     * "---- Left button pressed down at: " + prePos.x +
                     * ", " + prePos.y); System.out.println(
                     * "Converted to Scene Space: " + scenePos[0] + ", "
                     * + sp[1]);
                     * System.out.println("Marker manipulator hit!");
                     */

                    prescenePos[0] = scenePos[0];
                    prescenePos[1] = scenePos[1];

                    return;
                }
            }
        } else if (canvasMode == CorelyzerApp.APP_CLAST_MODE || canvasMode == CorelyzerApp.APP_CUT_MODE)

        {
            determineSelectedSceneComponents(scenePos, e);

            if (selectedTrackSection != -1) {
                if (!SceneGraph.getDepthOrientation()) {
                    float t = scenePos[0];
                    scenePos[0] = scenePos[1];
                    scenePos[1] = -t;
                }

                SceneGraph.addClastPoint1(scenePos[0], scenePos[1]);
                this.convertScenePointToAbsolute(scenePos, sp);

                CorelyzerApp.getApp().getToolFrame().setClastUpperLeft(sp);
            }

            PAN_MODE = 0;
            return;
        }

        PAN_MODE = 1;

        // System.out.println("---- Left button pressed down at: " +
        // prePos.x + ", " + prePos.y);
        // System.out.println("Converted to Scene Space: " +
        // scenePos[0] + ", " + sp[1]);

        determineSelectedSceneComponents(scenePos, e);

        break;
    case MouseEvent.BUTTON2:
        // System.out.println("MOUSE BUTTON 2!!!???");
        break;
    case MouseEvent.BUTTON3:
        // System.out.println("---- Right button clicked at: " +
        // prePos.x + ", " + prePos.y);
        // System.out.println("Converted to Scene Space: " +
        // scenePos[0] + ", " + sp[1]);
        this.handleRightMouseClick(e);
        break;
    default:
        // more reliable than BUTTON3 (ctrl-click)
        if (e.isPopupTrigger()) {
            this.handleRightMouseClick(e);
        }
    }
}

From source file:org.pmedv.blackboard.components.BoardEditor.java

private void handleMousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
        handleContextClick(e);//w  w  w .  ja v a  2 s .  c om
    }
    if (e.isControlDown()) {
        ctrlPressed = true;
    } else {
        ctrlPressed = false;
    }
    if (e.getButton() == 1) {
        if (!button1Pressed) {
            button1Pressed = true;
            if (editorMode.equals(EditorMode.SELECT)) {
                handleClickSelectionEvent(e);
            } else if (editorMode.equals(EditorMode.MOVE)) {
                dragStartX = e.getX();
                dragStartY = e.getY();
                dragStopX = e.getX();
                dragStopY = e.getY();
            } else if (editorMode.equals(EditorMode.DRAW_LINE) || editorMode.equals(EditorMode.DRAW_MEASURE)
                    || editorMode.equals(EditorMode.DRAW_RECTANGLE)
                    || editorMode.equals(EditorMode.DRAW_ELLIPSE)) {
                if (!model.getCurrentLayer().getName().equalsIgnoreCase("Board")) {
                    if (!drawing) {
                        handleClickDrawEvent(e);
                    } else {
                        handleReleaseDrawEvent(e);
                    }
                }
            } else if (editorMode.equals(EditorMode.CHECK_CONNECTIONS)) {
                handleCheckConnectionEvent(e);
            }
        }

    } else if (e.getButton() == 2) {
        button2Pressed = true;
    } else if (e.getButton() == 3) {
        button3Pressed = true;
    }
    if (e.getClickCount() == 2 && e.isShiftDown()) {
        if (selectedItem != null || getSelectedItems().size() > 0) {
            AppContext.getContext().getBean(EditPropertiesCommand.class).execute(null);
        }
    }
    refresh();
}

From source file:net.sf.jabref.groups.GroupSelector.java

private void definePopup() {
    // These key bindings are just to have the shortcuts displayed
    // in the popup menu. The actual keystroke processing is in
    // BasePanel (entryTable.addKeyListener(...)).
    groupsContextMenu.add(editGroupPopupAction);
    groupsContextMenu.add(addGroupPopupAction);
    groupsContextMenu.add(addSubgroupPopupAction);
    groupsContextMenu.addSeparator();//from   www  .  jav a 2 s  .co  m
    groupsContextMenu.add(removeGroupAndSubgroupsPopupAction);
    groupsContextMenu.add(removeGroupKeepSubgroupsPopupAction);
    groupsContextMenu.add(removeSubgroupsPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(expandSubtreePopupAction);
    groupsContextMenu.add(collapseSubtreePopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(moveSubmenu);
    sortSubmenu.add(sortDirectSubgroupsPopupAction);
    sortSubmenu.add(sortAllSubgroupsPopupAction);
    groupsContextMenu.add(sortSubmenu);
    moveSubmenu.add(moveNodeUpPopupAction);
    moveSubmenu.add(moveNodeDownPopupAction);
    moveSubmenu.add(moveNodeLeftPopupAction);
    moveSubmenu.add(moveNodeRightPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(addToGroup);
    groupsContextMenu.add(moveToGroup);
    groupsContextMenu.add(removeFromGroup);
    groupsTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

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

        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (path == null) {
                return;
            }
            GroupTreeNode node = (GroupTreeNode) path.getLastPathComponent();
            // the root node is "AllEntries" and cannot be edited
            if (node.isRoot()) {
                return;
            }
            if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { // edit
                editGroupAction.actionPerformed(null); // dummy event
            } else if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
                annotationEvent(node);
            }
        }
    });
    // be sure to remove a possible border highlight when the popup menu
    // disappears
    groupsContextMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            // nothing to do
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }
    });
}

From source file:neembuu.uploader.NeembuuUploader.java

/**
 * Opens up the Popup Menu// www.java  2 s .  com
 *
 * @param evt
 */
private void openPopup(MouseEvent evt) {
    //The above three mouse events call this method.
    //So check which one will trigger Rightclick menu depending on os and use it.
    if (evt.isPopupTrigger()) {
        //Check if it is right click.
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            NULogger.getLogger().info("RightClick event");
            //if already 2 or more rows selected, leave it.
            //EDIT: After some days I forgot what this code does,.. This is copied from a stackoverflow post actually..
            //But it's an unchangeable code and will just work forever, so I'm not gonna mess with it.
            if (neembuuUploaderTable.getSelectedRowCount() < 2) {
                int r = neembuuUploaderTable.rowAtPoint(evt.getPoint());
                if (r >= 0 && r < neembuuUploaderTable.getRowCount()) {
                    neembuuUploaderTable.setRowSelectionInterval(r, r);
                } else {
                    neembuuUploaderTable.clearSelection();
                }

                int rowindex = neembuuUploaderTable.getSelectedRow();
                if (rowindex < 0) {
                    return;
                }
            }
            //Display the popup menu on the exact point of right click.
            PopupBuilder.getInstance().show(evt.getComponent(), evt.getX(), evt.getY());
        }
    }
}

From source file:org.gtdfree.GTDFree.java

protected TrayIcon getTrayIcon() {
    if (trayIcon == null) {
        if (ApplicationHelper.isGTKLaF()) {
            trayIcon = new TrayIcon(ApplicationHelper.loadImage(ApplicationHelper.icon_name_large_tray_splash));
        } else {//from  ww  w. jav  a 2s  . co  m
            trayIcon = new TrayIcon(ApplicationHelper.loadImage(ApplicationHelper.icon_name_small_tray_splash));
        }

        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    trayIconPopup.setVisible(false);
                    if (getJFrame().isVisible()) {
                        getJFrame().setVisible(false);
                    } else {
                        pushVisible();
                    }
                } else {
                    if (trayIconPopup.isVisible()) {
                        trayIconPopup.setVisible(false);
                    } else {
                        Point p = new Point(e.getPoint());
                        /*
                         * Disabled, because we are anyway doing things like rollover,
                         * which are probably done by Frame.
                        if (getJFrame().isShowing()) {
                           SwingUtilities.convertPointFromScreen(p, getJFrame());
                           trayIconPopup.show(getJFrame(), p.x, p.y);
                        } else {
                        }*/
                        trayIconPopup.show(null, p.x, p.y);
                    }
                }
            }
        });
        trayIcon.setToolTip("GTD-Free - " + Messages.getString("GTDFree.Tray.desc")); //$NON-NLS-1$ //$NON-NLS-2$

        /*
         * Necessary only when popup is showing with null window. Hides popup.
         */
        MouseListener hideMe = new MouseAdapter() {
            @Override
            public void mouseExited(MouseEvent e) {
                if (e.getComponent() instanceof JMenuItem) {
                    JMenuItem jm = (JMenuItem) e.getComponent();
                    jm.getModel().setRollover(false);
                    jm.getModel().setArmed(false);
                    jm.repaint();
                }

                Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), trayIconPopup);
                //System.out.println(p.x+" "+p.y+" "+trayIconPopup.getWidth()+" "+trayIconPopup.getHeight());
                if (p.x < 0 || p.x >= trayIconPopup.getWidth() || p.y < 0 || p.y >= trayIconPopup.getHeight()) {
                    trayIconPopup.setVisible(false);
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                if (e.getComponent() instanceof JMenuItem) {
                    JMenuItem jm = (JMenuItem) e.getComponent();
                    jm.getModel().setRollover(true);
                    jm.getModel().setArmed(true);
                    jm.repaint();
                }
            }
        };

        trayIconPopup = new JPopupMenu();
        trayIconPopup.addMouseListener(hideMe);

        JMenuItem mi = new JMenuItem(Messages.getString("GTDFree.Tray.Drop")); //$NON-NLS-1$
        mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_small_collecting));
        mi.setToolTipText(Messages.getString("GTDFree.Tray.Drop.desc")); //$NON-NLS-1$
        mi.addMouseListener(hideMe);

        /*
         * Workaround for tray, if JFrame is showing, then mouse click is not fired
         */
        mi.addMouseListener(new MouseAdapter() {
            private boolean click = false;

            @Override
            public void mousePressed(MouseEvent e) {
                click = true;
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (click) {
                    click = false;
                    doMouseClicked(e);
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                click = false;
            }

            private void doMouseClicked(MouseEvent e) {
                trayIconPopup.setVisible(false);
                Clipboard c = null;
                if (e.getButton() == MouseEvent.BUTTON1) {
                    c = Toolkit.getDefaultToolkit().getSystemClipboard();
                } else if (e.getButton() == MouseEvent.BUTTON2) {
                    c = Toolkit.getDefaultToolkit().getSystemSelection();
                } else {
                    return;
                }
                try {
                    Object o = c.getData(DataFlavor.stringFlavor);
                    if (o != null) {
                        getEngine().getGTDModel().collectAction(o.toString());
                    }
                    flashMessage(Messages.getString("GTDFree.Tray.Collect.ok"), e.getLocationOnScreen()); //$NON-NLS-1$
                } catch (Exception e1) {
                    Logger.getLogger(this.getClass()).debug("Internal error.", e1); //$NON-NLS-1$
                    flashMessage(Messages.getString("GTDFree.Tray.Collect.fail") + e1.getMessage(), //$NON-NLS-1$
                            e.getLocationOnScreen());
                }
            }
        });

        TransferHandler th = new TransferHandler() {
            private static final long serialVersionUID = 1L;

            @Override
            public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
                return DataFlavor.selectBestTextFlavor(transferFlavors) != null;
            }

            @Override
            public boolean importData(JComponent comp, Transferable t) {
                try {
                    DataFlavor f = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
                    Object o = t.getTransferData(f);
                    if (o != null) {
                        getEngine().getGTDModel().collectAction(o.toString());
                    }
                    return true;
                } catch (UnsupportedFlavorException e) {
                    Logger.getLogger(this.getClass()).debug("Internal error.", e); //$NON-NLS-1$
                } catch (IOException e) {
                    Logger.getLogger(this.getClass()).debug("Internal error.", e); //$NON-NLS-1$
                }
                return false;
            }

        };
        mi.setTransferHandler(th);

        trayIconPopup.add(mi);

        mi = new JMenuItem();
        mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_delete));
        mi.setText(Messages.getString("GTDFree.Tray.Hide")); //$NON-NLS-1$
        mi.setToolTipText(Messages.getString("GTDFree.Tray.Hide.desc")); //$NON-NLS-1$
        mi.addMouseListener(hideMe);
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                trayIconPopup.setVisible(false);
                if (getJFrame().isVisible()) {
                    getJFrame().setVisible(false);
                }
            }
        });
        trayIconPopup.add(mi);

        mi = new JMenuItem();
        mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_small_splash));
        mi.setText(Messages.getString("GTDFree.Tray.Show")); //$NON-NLS-1$
        mi.setToolTipText(Messages.getString("GTDFree.Tray.Show.desc")); //$NON-NLS-1$
        mi.addMouseListener(hideMe);
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                trayIconPopup.setVisible(false);
                pushVisible();
            }
        });
        trayIconPopup.add(mi);

        mi = new JMenuItem();
        mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_exit));
        mi.setText(Messages.getString("GTDFree.Tray.Exit")); //$NON-NLS-1$
        mi.addMouseListener(hideMe);
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                trayIconPopup.setVisible(false);
                close(false);
            }
        });
        trayIconPopup.add(mi);

    }
    return trayIcon;
}