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:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

private void checkPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {

        final JPopupMenu popup = new JPopupMenu();
        popup.add(addMenu);//from   ww  w .j a va  2  s.  c  o m

        if (selectedNode != null) {
            final JMenuItem item = new JMenuItem("Delete");
            popup.add(item);
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            item.addActionListener(this);

            final NodeSource[] sources = selectedNode.getNode().getSources();
            if (sources.length > 0) {
                final JMenu removeSourcedMenu = new JMenu("Remove Source");
                for (NodeSource ns : sources) {
                    final JMenuItem nsItem = new JMenuItem(ns.getSourceNodeId());
                    removeSourcedMenu.add(nsItem);
                    nsItem.setHorizontalTextPosition(JMenuItem.RIGHT);
                    nsItem.addActionListener(removeSourceListener);
                }
                popup.add(removeSourcedMenu);
            }
        }

        if (!graphEx.getGraphNodeList().isGraphComplete()) {
            final JMenuItem connectItem = new JMenuItem("Connect Graph", null);
            connectItem.setHorizontalTextPosition(JMenuItem.RIGHT);
            connectItem.addActionListener(connectListener);
            popup.add(connectItem);
        }

        popup.setLabel("Justification");
        popup.setBorder(new BevelBorder(BevelBorder.RAISED));
        popup.addPopupMenuListener(this);
        popup.show(this, e.getX(), e.getY());
        showRightClickHelp = false;
    }
}

From source file:org.executequery.gui.editor.QueryEditorPopupMenu.java

private void maybeShowPopup(MouseEvent e) {

    if (e.isPopupTrigger()) {

        show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:org.kepler.gui.AnnotatedPTreePopupListener.java

/**
 * Description of the Method//from  w  w w  .ja v  a2s.c o  m
 * 
 *@param e
 *            Description of the Parameter
 */
public void mousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
        _trigger = true;
    }
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/**
 * Description of the Method//w w w  .  jav  a 2 s . c  o m
 * 
 *@param e
 *            Description of the Parameter
 */
private void maybeShowPopup(MouseEvent e) {
    if (isDebugging)
        log.debug("maybeShowPopup(" + e.toString() + ")");
    if (e.isPopupTrigger() || _trigger) {
        _trigger = false;
        TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY());
        if (isDebugging)
            log.debug(selPath.toString());
        if ((selPath != null)) {

            if (isDebugging)
                log.debug(selPath.getLastPathComponent().getClass().getName());

            if (_isPathInsideKAR(selPath)) {
                handlePopupInsideKar(selPath, e);
            } else {
                handlePopupOutsideKar(selPath, e);

            }
        }
        // handle double clicks
    } else if (e.getClickCount() == 2) {
        TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY());
        if (isDebugging)
            log.debug(selPath.toString());
        if ((selPath != null)) {

            if (isDebugging)
                log.debug(selPath.getLastPathComponent().getClass().getName());

            if (_isPathInsideKAR(selPath)) {
                handlePopupInsideKar(selPath, e);
            } else {
                handleDoubleClickOutsideKar(selPath, e);
            }
        }
    }
}

From source file:org.kepler.gui.popups.OutlinePopupListener.java

/**
 * Description of the Method//from   w ww  . java 2 s  .com
 * 
 *@param e
 *            Description of the Parameter
 */
private void maybeShowPopup(MouseEvent e) {
    if (isDebugging)
        log.debug("maybeShowPopup(" + e.toString() + ")");
    if (e.isPopupTrigger() || _trigger) {
        _trigger = false;
        TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY());
        if (isDebugging)
            log.debug(selPath.toString());
        if ((selPath != null)) {

            // determine if this object is contained within a KAR
            // by checking all of the parent objects to see
            // if they are a KAREntityLibrary
            // do not check the object itself
            boolean inKAR = false;
            Object ob = null;
            for (int i = (selPath.getPathCount() - 2); i >= 0; i--) {
                ob = selPath.getPathComponent(i);
                if (ob instanceof KAREntityLibrary) {
                    inKAR = true;
                    break;
                }
            }

            ob = selPath.getLastPathComponent();
            if (isDebugging)
                log.debug(ob.getClass().getName());

            if (!inKAR) {
                handlePopupOutsideKar(selPath, e);
            }
        }
    }
}

From source file:org.kontalk.view.UserListView.java

UserListView(final View view, UserList userList) {
    super();//w w  w .jav a  2 s  .c  om

    mView = view;

    mUserList = userList;

    this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //this.setDragEnabled(true);

    // right click popup menu
    mPopupMenu = new UserPopupMenu();

    // actions triggered by mouse events
    this.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                mView.selectThreadByUser(UserListView.this.getSelectedValue());
            }
        }

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

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

        private void check(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int row = UserListView.this.rowAtPoint(e.getPoint());
                UserListView.this.setSelectedItem(row);
                UserListView.this.showPopupMenu(e);
            }
        }
    });

    this.updateOnEDT(null);
}

From source file:org.kontalk.view.Utils.java

static WebTextField createTextField(final String text) {
    final WebTextField field = new WebTextField(text, false);
    field.setEditable(false);//from   ww  w . j  a v a  2s . c o  m
    field.setBackground(null);
    field.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            check(e);
        }

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

        private void check(MouseEvent e) {
            if (e.isPopupTrigger()) {
                WebPopupMenu popupMenu = new WebPopupMenu();
                popupMenu.add(createCopyMenuItem(field.getText(), ""));
                popupMenu.show(field, e.getX(), e.getY());
            }
        }
    });
    return field;
}

From source file:org.kontalk.view.View.java

static WebTextField createTextField(final String text) {
    final WebTextField field = new WebTextField(text, false);
    field.setEditable(false);/* w w w  .  ja va2s  .c om*/
    field.setBackground(null);
    field.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            check(e);
        }

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

        private void check(MouseEvent e) {
            if (e.isPopupTrigger()) {
                WebPopupMenu popupMenu = new WebPopupMenu();
                popupMenu.add(View.createCopyMenuItem(field.getText(), ""));
                popupMenu.show(field, e.getX(), e.getY());
            }
        }
    });
    return field;
}

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private MouseAdapter getMouseAdapter() {
    return new MouseAdapter() {
        private void handlePopupEvent(MouseEvent e) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }//from w w w. j  av a 2s  . co  m
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            TreePath[] paths = tree.getSelectionPaths();
            boolean isSelected = false;
            if (paths != null) {
                for (TreePath selectionPath : paths) {
                    if (selectionPath.equals(path)) {
                        isSelected = true;
                    }
                }
            }
            if (!isSelected) {
                tree.setSelectionPath(path);
            }
            if (node.isLeaf()) {
                JPopupMenu popup = new JPopupMenu();
                JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu"));
                aboutRuleMenuItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
                        Rule rule = node.getRule();
                        Language lang = config.getLanguage();
                        if (lang == null) {
                            lang = Languages.getLanguageForLocale(Locale.getDefault());
                        }
                        Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"),
                                rule.getDescription(), rule, rule.getUrl(), messages,
                                lang.getShortCodeWithCountryAndVariant());
                    }
                });
                popup.add(aboutRuleMenuItem);
                popup.show(tree, e.getX(), e.getY());
            }
        }

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

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

From source file:org.languagetool.gui.LanguageToolSupport.java

private void init() {
    try {/*from w w w . j ava2  s.com*/
        config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null);
    } catch (IOException ex) {
        throw new RuntimeException("Could not load configuration", ex);
    }

    Language defaultLanguage = config.getLanguage();
    if (defaultLanguage == null) {
        defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault());
    }

    /**
     * Warm-up: we have a lot of lazy init in LT, which causes the first check to
     * be very slow (several seconds) for languages with a lot of data and a lot of
     * rules. We just assume that the default language is the language that the user
     * often uses and init the LT object for that now, not just when it's first used.
     * This makes the first check feel much faster:
     */
    reloadLanguageTool(defaultLanguage);

    checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            t.setPriority(Thread.MIN_PRIORITY);
            t.setName(t.getName() + "-lt-background");
            return t;
        }
    });

    check = new AtomicInteger(0);

    this.textComponent.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), false);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), true);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }
    });

    mouseListener = new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent me) {
        }

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

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

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    };
    this.textComponent.addMouseListener(mouseListener);

    actionListener = e -> _actionPerformed(e);

    mustDetectLanguage = config.getAutoDetect();
    if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) {
        checkImmediately(null);
    }
}