Example usage for java.awt.event MouseEvent isPopupTrigger

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

Introduction

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

Prototype

public boolean isPopupTrigger() 

Source Link

Document

Returns whether or not this mouse event is the popup menu trigger event for the platform.

Usage

From source file:Main.java

public static void addPopup(Component component, final JPopupMenu popup) {
    component.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);//from ww w.j  av a 2 s.  co m
            }
        }

        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

        private void showMenu(MouseEvent e) {
            popup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
}

From source file:Main.java

/**
 * Gives a component a popup menu//from w  ww .j a v  a  2  s .com
 *
 * @param component
 *            The target component
 * @param popup
 *            The popup menu
 */

public static void setPopupMenu(final JComponent component, final JPopupMenu popup) {
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.show(component, e.getX(), e.getY());
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.show(component, e.getX(), e.getY());
            }
        }
    });
}

From source file:Main.java

/**
 * Gives a tray icon a popup menu./* w  w  w.  java2s .  co  m*/
 *
 * @param trayIcon
 *            The tray icon
 * @param popup
 *            The popup menu
 */

public static void setPopupMenu(final TrayIcon trayIcon, final JPopupMenu popup) {
    trayIcon.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.setLocation(e.getX(), e.getY());
                popup.setInvoker(popup);
                popup.setVisible(true);
            }
        }

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

From source file:Main.java

public static MouseEvent newMouseEvent(Component comp, int id, MouseEvent e) {
    return new MouseEvent(comp, id, e.getWhen(), e.getModifiers() | e.getModifiersEx(), e.getX(), e.getY(),
            e.getClickCount(), e.isPopupTrigger());
}

From source file:Main.java

public static MouseEvent convertMouseEvent(MouseEvent e, Component newSource, Point newPoint) {
    return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiersEx(), newPoint.x, newPoint.y,
            e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

From source file:Main.java

public static MouseEvent adaptEventToDescendent(MouseEvent e, JComponent descendentTarget) {
    Point trans = new Point();
    Component source = e.getComponent();

    Component current = descendentTarget;
    while (current != source) {
        Rectangle b = current.getBounds();
        trans.x += b.x;/*from  www  .  j av a2s.  co  m*/
        trans.y += b.y;
        current = current.getParent();
    }
    Point point = e.getPoint();

    return new MouseEvent(descendentTarget, e.getID(), e.getWhen(), e.getModifiers(), point.x + trans.x,
            point.y + trans.y, e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

From source file:de.ailis.xadrian.utils.SwingUtils.java

/**
 * Gives a component a popup menu//  w ww  .  j ava 2 s  .co m
 * 
 * @param component
 *            The target component
 * @param popup
 *            The popup menu
 */
public static void setPopupMenu(final JComponent component, final JPopupMenu popup) {
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            // Ignore mouse buttons outside of the normal range. This
            // fixes problems with trackpad scrolling.
            if (e.getButton() > MouseEvent.BUTTON3)
                return;

            if (e.isPopupTrigger()) {
                popup.show(component, e.getX(), e.getY());
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            // Ignore mouse buttons outside of the normal range. This
            // fixes problems with trackpad scrolling.
            if (e.getButton() > MouseEvent.BUTTON3)
                return;

            if (e.isPopupTrigger()) {
                popup.show(component, e.getX(), e.getY());
            }
        }
    });
}

From source file:com.intuit.tank.tools.debugger.PanelBuilder.java

/**
 * @param debuggerActions//from  ww  w .  jav  a 2s  . com
 * @return
 */
static Component createContentPanel(final AgentDebuggerFrame frame) {
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    final RSyntaxTextArea scriptEditorTA = new RSyntaxTextArea();
    frame.setScriptEditorTA(scriptEditorTA);
    scriptEditorTA.setSelectionColor(scriptEditorTA.getCurrentLineHighlightColor());
    scriptEditorTA.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    scriptEditorTA.setHyperlinksEnabled(false);
    scriptEditorTA.setEditable(false);
    scriptEditorTA.setEnabled(false);
    scriptEditorTA.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            scriptEditorTA.grabFocus();
            try {
                int offs = scriptEditorTA.viewToModel(e.getPoint());
                if (offs > -1) {
                    int line = scriptEditorTA.getLineOfOffset(offs);
                    if (frame.getSteps().size() > line) {

                        frame.fireStepChanged(line);
                        if (e.getClickCount() == 2 && !e.isPopupTrigger()) {
                            // show step xml
                            try {
                                DebugStep debugStep = frame.getSteps().get(line);
                                String text = JaxbUtil.marshall(debugStep.getStepRun());
                                StepDialog dlg = new StepDialog(frame, text, SyntaxConstants.SYNTAX_STYLE_XML);
                                dlg.setVisible(true);
                            } catch (JAXBException e1) {
                                frame.showError("Error showing step xml: " + e);
                            }
                        }
                    }
                }
            } catch (BadLocationException ble) {
                ble.printStackTrace(); // Never happens
            }
        }
    });
    RTextScrollPane scriptEditorScrollPane = new RTextScrollPane(scriptEditorTA);
    frame.setScriptEditorScrollPane(scriptEditorScrollPane);
    scriptEditorScrollPane.setIconRowHeaderEnabled(true);
    scriptEditorScrollPane.getGutter()
            .setBookmarkIcon(ActionProducer.getIcon("bullet_blue.png", IconSize.SMALL));
    scriptEditorScrollPane.getGutter()
            .setCurrentLineIcon(ActionProducer.getIcon("current_line.png", IconSize.SMALL));
    scriptEditorScrollPane.getGutter().setBookmarkingEnabled(true);
    pane.setLeftComponent(scriptEditorScrollPane);

    pane.setRightComponent(createRightPanel(frame));
    pane.setDividerLocation(300);
    pane.setResizeWeight(0.4D);
    return pane;
}

From source file:Main.java

public Main() {
    setLayout(null);/*ww  w.  j a v a2s.c  om*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.isPopupTrigger());
        }
    });
}

From source file:Main.java

public void mousePressed(MouseEvent e) {
    if (e.isPopupTrigger())
        myPopupEvent(e);
}