Example usage for java.awt.event MouseEvent isControlDown

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

Introduction

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

Prototype

public boolean isControlDown() 

Source Link

Document

Returns whether or not the Control modifier is down on this event.

Usage

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

/**
 * Reacts to mouse pressed and mouse release event.
 * /*from   ww w.j a  v  a2 s .  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.treeviewer.browser.BrowserUI.java

/** 
 * Helper method to create the trees hosting the display. 
 * //from w  w  w.  j  a v  a2  s. co m
 * @param exp The logged in experimenter.
 */
private void createTrees(ExperimenterData exp) {
    treeDisplay = new DnDTree(model.getUserID(), TreeViewerAgent.isAdministrator());
    treeDisplay.addPropertyChangeListener(this);
    String key = "meta pressed A";
    if (UIUtilities.isWindowsOS())
        key = "ctrl pressed A";
    KeyStroke ks = KeyStroke.getKeyStroke(key);
    treeDisplay.getInputMap().put(ks, "none");
    treeDisplay.setVisible(true);
    treeDisplay.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(treeDisplay);
    treeDisplay.setCellRenderer(new TreeCellRenderer(model.getUserID()));
    treeDisplay.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    treeDisplay.setModel(new DefaultTreeModel(root));
    if (model.getBrowserType() != Browser.ADMIN_EXPLORER) {
        TreeImageDisplay node = buildTreeNodes(exp);
        if (node != null)
            treeDisplay.collapsePath(new TreePath(node.getPath()));
    }
    //Add Listeners
    //treeDisplay.requestFocus();
    treeDisplay.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            mousePressedTime = e.getWhen();
            rightClickPad = UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(e) && e.isControlDown();
            rightClickButton = SwingUtilities.isRightMouseButton(e);
            ctrl = e.isControlDown();
            if (UIUtilities.isMacOS())
                ctrl = e.isMetaDown();
            leftMouseButton = SwingUtilities.isLeftMouseButton(e);
            if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS())
                onClick(e, false);
        }

        public void mouseReleased(MouseEvent e) {
            leftMouseButton = SwingUtilities.isLeftMouseButton(e);
            if (UIUtilities.isWindowsOS())
                onClick(e, true);
        }

        // public void mouseMoved(MouseEvent e) { rollOver(e); }
    });
    treeDisplay.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseMoved(MouseEvent e) {
            rollOver(e);
        }
    });
    treeDisplay.addTreeExpansionListener(listener);
    selectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            event = e;
            eventHandledTime = System.currentTimeMillis();

            if (delayedHandlingTreeSelection)
                /* mouse click delayed handling until this event occurred */
                handleTreeSelection();

            switch (keyEvent) {
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_UP:
                TreePath[] paths = treeDisplay.getSelectionPaths();
                if (paths != null)
                    controller.onClick(Arrays.asList(paths));
                else
                    controller.onClick(new ArrayList<TreePath>());
                break;
            }
        }
    };
    treeDisplay.addTreeSelectionListener(selectionListener);
    //remove standard behaviour
    treeDisplay.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            ctrl = false;
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                ViewCmd cmd = new ViewCmd(model.getParentModel(), true);
                cmd.execute();
                break;
            case KeyEvent.VK_DELETE:
                switch (model.getState()) {
                case Browser.LOADING_DATA:
                case Browser.LOADING_LEAVES:
                    //case Browser.COUNTING_ITEMS:  
                    break;
                default:
                    model.delete();
                }
                break;
            case KeyEvent.VK_CONTROL:
                if (!UIUtilities.isMacOS())
                    ctrl = true;
                break;
            case KeyEvent.VK_META:
                if (UIUtilities.isMacOS())
                    ctrl = true;
                break;
            case KeyEvent.VK_A:
                if (UIUtilities.isWindowsOS() && e.isControlDown()
                        || !UIUtilities.isWindowsOS() && e.isMetaDown()) {
                    handleMultiSelection();
                }
                break;
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_UP:
            case KeyEvent.VK_RIGHT:
                keyEvent = e.getKeyCode();
                break;
            case KeyEvent.VK_LEFT:
                TreePath[] paths = treeDisplay.getSelectionPaths();
                TreeImageDisplay node;
                Object o;
                for (int i = 0; i < paths.length; i++) {
                    o = paths[i].getLastPathComponent();
                    if (o instanceof TreeImageDisplay) {
                        node = (TreeImageDisplay) o;
                        if (node.isExpanded())
                            node.setExpanded(false);
                    }
                }
            }
        }

        public void keyReleased(KeyEvent e) {
            ctrl = false;
            keyEvent = -1;
        }

    });
}

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

/**
 * Selects the channel or displays the pop up menu.
 *
 * @param e The mouse event to handle.// w w  w . j  a va 2  s  .c  om
 */
private void onClick(MouseEvent e) {
    boolean mask = (e.isControlDown() || e.isMetaDown());
    if (e.getButton() == MouseEvent.BUTTON1 && !(mask))
        setChannelSelected();
    else if ((e.getButton() == MouseEvent.BUTTON2 || mask))
        onReleased(e);
}

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. jav  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 www.j  av  a 2s  .  c  o  m
 * @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  a v a2  s.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.photovault.swingui.PhotoCollectionThumbView.java

/**
 * On mouse click select the photo clicked.
 *
 * @param mouseEvent a <code>MouseEvent</code> value
 *//*from   ww w. j  a v a 2  s.  co  m*/
public void mouseClicked(MouseEvent mouseEvent) {
    log.debug("mouseClicked (" + mouseEvent.getX() + ", " + mouseEvent.getY());

    if (dragJustEnded) {
        // Selection was already handled by drag handler so do nothing
        dragJustEnded = false;
        return;
    }

    PhotoInfo clickedPhoto = getPhotoAtLocation(mouseEvent.getX(), mouseEvent.getY());
    if (clickedPhoto != null) {
        if (mouseEvent.isControlDown()) {
            photoClickedCtrlDown(clickedPhoto);
        } else {
            photoClickedNoModifiers(clickedPhoto);
        }
        // If this was a doublke click open the selected photo(s)
        if (mouseEvent.getClickCount() == 2) {
            showSelectedPhotoAction.actionPerformed(new ActionEvent(this, 0, null));
        }
    } else {
        // The click was between photos. Clear the selection
        if (!mouseEvent.isControlDown()) {
            Object[] oldSelection = selection.toArray();
            selection.clear();
            fireSelectionChangeEvent();
            for (int n = 0; n < oldSelection.length; n++) {
                PhotoInfo photo = (PhotoInfo) oldSelection[n];
                repaintPhoto(photo);
            }

        }
    }
    repaintPhoto(clickedPhoto);
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

/**
 * Describe <code>mousePressed</code> method here.
 *
 * @param mouseEvent a <code>MouseEvent</code> value
 *///www  . j  av a  2 s .co  m
public void mousePressed(MouseEvent mouseEvent) {
    // save the mouse press event so that we can later decide whether this gesture
    // is intended as a drag
    firstMouseEvent = mouseEvent;

    PhotoInfo photo = getPhotoAtLocation(mouseEvent.getX(), mouseEvent.getY());
    if (photo == null) {
        dragType = DRAG_TYPE_SELECT;
        // If ctrl is not down clear the selection
        if (!mouseEvent.isControlDown()) {
            Object[] oldSelection = selection.toArray();
            selection.clear();
            fireSelectionChangeEvent();
            for (int n = 0; n < oldSelection.length; n++) {
                PhotoInfo p = (PhotoInfo) oldSelection[n];
                repaintPhoto(p);
            }

        }
        dragSelectionRect = new Rectangle(mouseEvent.getX(), mouseEvent.getY(), 0, 0);
    } else {
        dragType = DRAG_TYPE_DND;
    }
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

protected void handleDnDDragEvent(MouseEvent e) {
    //Don't bother to drag if no photo is selected
    if (selection.isEmpty()) {
        return;/*  w w  w .  ja v a 2s . co  m*/
    }

    if (firstMouseEvent != null) {
        log.debug("considering drag");
        e.consume();

        //If they are holding down the control key, COPY rather than MOVE
        int ctrlMask = InputEvent.CTRL_DOWN_MASK;
        int action = e.isControlDown() ? TransferHandler.COPY : TransferHandler.MOVE;

        int dx = Math.abs(e.getX() - firstMouseEvent.getX());
        int dy = Math.abs(e.getY() - firstMouseEvent.getY());
        //Arbitrarily define a 5-pixel shift as the
        //official beginning of a drag.
        if (dx > 5 || dy > 5) {
            log.debug("Start a drag");
            //This is a drag, not a click.
            JComponent c = (JComponent) e.getSource();
            //Tell the transfer handler to initiate the drag.
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, firstMouseEvent, action);
            firstMouseEvent = null;
        }
    }
}

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

private void handleMousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
        handleContextClick(e);/*w  w  w.  jav  a  2 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();
}