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.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/*from  ww w  . j  av a 2s.c om*/
 */
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:org.openmicroscopy.shoola.agents.metadata.editor.DocComponent.java

/** Initializes the components composing the display. */
private void initComponents() {
    isModulo = model.isModulo(data);/* ww  w .  j a va2s . co m*/
    imageToLoad = -1;
    initButtons();
    label = new JLabel();
    label.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    if (data == null) {
        label.setText(AnnotationUI.DEFAULT_TEXT);
    } else {
        if (data instanceof FileAnnotationData) {
            FileAnnotationData f = (FileAnnotationData) data;
            String fileName = f.getFileName();
            String s = fileName;
            if (FileAnnotationData.MEASUREMENT_NS.equals(f.getNameSpace())) {
                String desc = f.getDescription();
                if (desc != null && desc.trim().length() > 0)
                    label.setText(desc);
                else {
                    label.setText(UIUtilities.formatPartialName(EditorUtil.getPartialName(fileName)));
                }
                s = label.getText();
            } else {
                label.setText(UIUtilities.formatPartialName(EditorUtil.getPartialName(fileName)));
            }

            label.setToolTipText(formatToolTip(f, s));
            Iterator<CustomizedFileFilter> i = FILTERS.iterator();
            CustomizedFileFilter filter;
            long id = f.getId();
            while (i.hasNext()) {
                filter = i.next();
                if (filter.accept(fileName)) {
                    if (id > 0)
                        imageToLoad = LOAD_FROM_SERVER;
                    else
                        imageToLoad = LOAD_FROM_LOCAL;
                    break;
                }
            }
            if (id < 0)
                label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
            switch (imageToLoad) {
            case LOAD_FROM_LOCAL:
                if (thumbnail == null)
                    setThumbnail(f.getFilePath());
                break;
            /*
            case LOAD_FROM_SERVER:
            if (thumbnail == null) {
             model.loadFile((FileAnnotationData) data, this);
            }
            */
            }
        } else if (data instanceof File) {
            File f = (File) data;
            label.setText(EditorUtil.getPartialName(f.getName()));
            label.setForeground(Color.BLUE);
        } else if (data instanceof TagAnnotationData) {
            TagAnnotationData tag = (TagAnnotationData) data;
            label.setText(tag.getTagValue());
            label.setToolTipText(formatToolTip(tag, null));
            if (tag.getId() < 0)
                label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
        } else if (data instanceof XMLAnnotationData) {
            XMLAnnotationData tag = (XMLAnnotationData) data;
            label.setText(EditorUtil.truncate(tag.getText(), TEXT_LENGTH, false));
            label.setToolTipText(formatToolTip(tag, null));
            if (tag.getId() < 0)
                label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
        } else if (data instanceof TermAnnotationData) {
            TermAnnotationData tag = (TermAnnotationData) data;
            label.setText(tag.getTerm());
            label.setToolTipText(formatToolTip(tag, null));
            if (tag.getId() < 0)
                label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
        } else if (data instanceof LongAnnotationData) {
            LongAnnotationData tag = (LongAnnotationData) data;
            label.setText(tag.getContentAsString());
            label.setToolTipText(formatToolTip(tag, null));
            if (tag.getId() < 0)
                label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
        } else if (data instanceof DoubleAnnotationData) {
            DoubleAnnotationData tag = (DoubleAnnotationData) data;
            label.setText(tag.getContentAsString());
            label.setToolTipText(formatToolTip(tag, null));
            if (tag.getId() < 0)
                label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
        }
    }

    label.addMouseListener(new MouseAdapter() {

        /** 
         * Posts an event to edit the file.
         * @see MouseAdapter#mouseReleased(MouseEvent)
         */
        public void mouseReleased(MouseEvent e) {
            if (e.getClickCount() == 1) {
                if (e.isPopupTrigger())
                    showMenu(label, e.getPoint());
            } else if (e.getClickCount() == 2)
                postFileClicked();
        }

        /** 
         * Shows menu
         * @see MouseAdapter#mouseReleased(MouseEvent)
         */
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger())
                showMenu(label, e.getPoint());
        }
    });
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Reacts to mouse pressed and mouse release event.
 * //from  w  ww .ja  v a 2s.c o  m
 * @param me        The event to handle.
 * @param released  Pass <code>true</code> if the method is invoked when
 *                  the mouse is released, <code>false</code> otherwise.
 */
private void onClick(MouseEvent me, boolean released) {
    Point p = me.getPoint();
    int row = treeDisplay.getRowForLocation(p.x, p.y);
    if (row != -1) {
        if (me.getClickCount() == 1) {
            model.setClickPoint(p);
            if (mousePressedTime > eventHandledTime)
                /* have not yet seen the tree selection event */
                delayedHandlingTreeSelection = true;
            else
                handleTreeSelection();
            //if (released) {
            if ((me.isPopupTrigger() && !released)
                    || (me.isPopupTrigger() && released && !UIUtilities.isMacOS())
                    || (UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(me) && me.isControlDown())) {
                if (rightClickButton && !model.isMultiSelection()) { //(!(me.isShiftDown() || ctrl))

                    TreePath path = treeDisplay.getPathForLocation(p.x, p.y);
                    //treeDisplay.removeTreeSelectionListener(
                    //      selectionListener);
                    if (path != null)
                        treeDisplay.setSelectionPath(path);
                    //treeDisplay.addTreeSelectionListener(selectionListener);
                    if (path != null && path.getLastPathComponent() instanceof TreeImageDisplay)
                        controller.onRightClick((TreeImageDisplay) path.getLastPathComponent());
                }
                if (model.getBrowserType() == Browser.ADMIN_EXPLORER)
                    controller.showPopupMenu(TreeViewer.ADMIN_MENU);
                else
                    controller.showPopupMenu(TreeViewer.FULL_POP_UP_MENU);
            }
        } else if (me.getClickCount() == 2 && !(me.isMetaDown() || me.isControlDown() || me.isShiftDown())) {
            //controller.cancel();
            //model.viewDataObject();
            TreeImageDisplay d = model.getLastSelectedDisplay();
            if (d == null)
                return;
            Object o = d.getUserObject();
            if (o instanceof ImageData) {
                model.browse(d);
            } else if (o instanceof PlateData) {
                if (!d.hasChildrenDisplay() || d.getChildrenDisplay().size() == 1)
                    model.browse(d);
            } else if (o instanceof PlateAcquisitionData) {
                model.browse(d);
            }
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ChannelButton.java

/**
 * Handles the mouse released event because pop-up menus are triggered
 * differently depending on the platform.
 *
 * @param e The The mouse event to handle.
 *//*from w  w  w  .j a v a2s.co  m*/
private void onReleased(MouseEvent e) {
    if (e.isPopupTrigger() && rightClickSupported) {
        if (popupMenu == null)
            popupMenu = new ChannelButtonPopupMenu(this);
        popupMenu.show(this, e.getX(), e.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//  w  w w  .ja v a2  s  .c o  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:org.orbisgis.sif.components.fstree.FileTree.java

/**
 * Event on Tree, called by listener/*from  ww  w  .  j  av a  2s  .  c  om*/
 * @param evt 
 */
public void onMouseEvent(MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        //Update selection
        TreePath path = getPathForLocation(evt.getX(), evt.getY());
        TreePath[] selectionPaths = getSelectionPaths();
        if ((selectionPaths != null) && (path != null)) {
            if (!contains(selectionPaths, path)) {
                if (evt.isControlDown()) {
                    addSelectionPath(path);
                } else {
                    setSelectionPath(path);
                }
            }
        } else {
            setSelectionPath(path);
        }
        //Show popup
        makePopupMenu().show(evt.getComponent(), evt.getX(), evt.getY());
    }
}

From source file:org.orbisgis.view.geocatalog.Catalog.java

/**
 * The user click on the source list control
 *
 * @param e The mouse event fired by the LI
 *//*from w w w  .  j  av  a2s.  co m*/
public void onMouseActionOnSourceList(MouseEvent e) {
    //Manage selection of items before popping up the menu
    if (e.isPopupTrigger()) { //Right mouse button under linux and windows
        int itemUnderMouse = -1; //Item under the position of the mouse event
        //Find the Item under the position of the mouse cursor
        for (int i = 0; i < sourceListContent.getSize(); i++) {
            //If the coordinate of the cursor cover the cell bouding box
            if (sourceList.getCellBounds(i, i).contains(e.getPoint())) {
                itemUnderMouse = i;
                break;
            }
        }
        //Retrieve all selected items index
        int[] selectedItems = sourceList.getSelectedIndices();
        //If there are a list item under the mouse
        if ((selectedItems != null) && (itemUnderMouse != -1)) {
            //If the item under the mouse was not previously selected
            if (!CollectionUtils.contains(selectedItems, itemUnderMouse)) {
                //Control must be pushed to add the list item to the selection
                if (e.isControlDown()) {
                    sourceList.addSelectionInterval(itemUnderMouse, itemUnderMouse);
                } else {
                    //Unselect the other items and select only the item under the mouse
                    sourceList.setSelectionInterval(itemUnderMouse, itemUnderMouse);
                }
            }
        } else if (itemUnderMouse == -1) {
            //Unselect all items
            sourceList.clearSelection();
        }
        //Selection are ready, now create the popup menu
        JPopupMenu popup = new JPopupMenu();
        popupActions.copyEnabledActions(popup);
        if (popup.getComponentCount() > 0) {
            popup.show(e.getComponent(), e.getX(), e.getY());
        }

    }
}

From source file:org.parosproxy.paros.view.OutputPanel.java

/**
 * This method initializes txtOutput   /*from  w w w.  j  a  v  a 2 s.  c  o  m*/
 *    
 * @return org.zaproxy.zap.utils.ZapTextArea   
 */
private ZapTextArea getTxtOutput() {
    if (txtOutput == null) {
        txtOutput = new ZapTextArea();
        txtOutput.setEditable(false);
        txtOutput.setLineWrap(true);
        txtOutput.setName("");
        txtOutput.addMouseListener(new java.awt.event.MouseAdapter() {

            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger()) {
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }

        });
    }
    return txtOutput;
}

From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java

/**
 * adds the listener that showes the popup
 *//*ww w .j a v a  2  s . c o m*/
private void addPopupShower() {
    //show popup
    thumbnailList.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

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

        private void showMenu(MouseEvent e) {
            int[] selection = thumbnailList.getSelectedIndices();
            if (!(selection != null && selection.length > 1)) {
                thumbnailList.setSelectedIndex(thumbnailList.locationToIndex(e.getPoint()));
                selection = thumbnailList.getSelectedIndices();
            }
            menuItemPreview.setEnabled(selection != null && selection.length == 1);
            popupMenu.show(thumbnailList, e.getX(), e.getY());
        }
    });
}

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

private void handleMousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
        handleContextClick(e);/*from w  w  w  .  ja  v  a2 s .  c  o m*/
    }
    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();
}