Example usage for java.awt.event MouseEvent isMetaDown

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

Introduction

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

Prototype

public boolean isMetaDown() 

Source Link

Document

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

Usage

From source file:eu.esdihumboldt.hale.ui.views.styledmap.tool.InstanceTool.java

/**
 * @see AbstractMapTool#click(MouseEvent, GeoPosition)
 *//*  w  w w  .ja va  2  s .c  om*/
@Override
public void click(MouseEvent me, GeoPosition pos) {
    if (me.getClickCount() == 2) {
        mapKit.setCenterPosition(pos);
        mapKit.setZoom(mapKit.getMainMap().getZoom() - 1);
    } else if (me.getClickCount() == 1) {
        if (me.isAltDown() && getPositions().size() < 1) {
            // add pos
            addPosition(pos);
        } else if (getPositions().size() == 1) {
            // finish box selection
            // action & reset
            addPosition(pos);

            // action
            try {
                List<Point2D> points = getPoints();
                Rectangle rect = new Rectangle((int) points.get(0).getX(), (int) points.get(0).getY(), 0, 0);
                rect.add(points.get(1));

                updateSelection(rect, me.isControlDown() || me.isMetaDown(), true);
            } catch (IllegalGeoPositionException e) {
                log.error("Error calculating selection box", e); //$NON-NLS-1$
            }

            reset();
        } else {
            // click selection
            reset();

            updateSelection(me.getPoint(), me.isControlDown() || me.isMetaDown(), true);
        }
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Opens the <tt>WritePanelRightButtonMenu</tt> when user clicks with the
 * right mouse button on the editor area.
 *
 * @param e the <tt>MouseEvent</tt> that notified us
 *//*from   www  .  j a v  a2  s .c o  m*/
public void mouseClicked(MouseEvent e) {
    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) {
        Point p = e.getPoint();
        SwingUtilities.convertPointToScreen(p, e.getComponent());

        //SPELLCHECK
        ArrayList<JMenuItem> contributedMenuEntries = new ArrayList<JMenuItem>();

        for (ChatMenuListener listener : this.menuListeners) {
            contributedMenuEntries.addAll(listener.getMenuElements(this.chatPanel, e));
        }

        for (JMenuItem item : contributedMenuEntries) {
            rightButtonMenu.add(item);
        }

        JPopupMenu rightMenu = rightButtonMenu.makeMenu(contributedMenuEntries);
        rightMenu.setInvoker(editorPane);
        rightMenu.setLocation(p.x, p.y);
        rightMenu.setVisible(true);
    }
}

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() == false) && (evt.isMetaDown() == false));
}

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() != false) && (evt.isMetaDown() == false));
}

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() == false) && (evt.isMetaDown() != false));
}

From source file:de.mendelson.comm.as2.client.AS2Gui.java

@Override
public void mouseClicked(MouseEvent evt) {
    if (evt.isPopupTrigger() || evt.isMetaDown()) {
        if (evt.getSource().equals(this.jTableMessageOverview)) {
            this.jPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
        }/*  www.  j  a  v  a  2 s.  co  m*/
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java

/**
 * When a right button click is performed in the editor pane, a popup menu
 * is opened./*w  ww  . ja  v  a  2s . c o  m*/
 * In case of the Scheme being internal, it won't open the Browser but
 * instead it will trigger the forwarded action.
 *
 * @param e The MouseEvent.
 */
public void mouseClicked(MouseEvent e) {
    Point p = e.getPoint();
    SwingUtilities.convertPointToScreen(p, e.getComponent());

    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) {
        openContextMenu(p);
    } else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && currentHref != null
            && currentHref.length() != 0) {
        URI uri;
        try {
            uri = new URI(currentHref);
        } catch (URISyntaxException e1) {
            logger.error(
                    "Failed to open hyperlink in chat window. " + "Error was: Invalid URL - " + currentHref);
            return;
        }
        if ("jitsi".equals(uri.getScheme())) {
            for (ChatLinkClickedListener l : chatLinkClickedListeners) {
                l.chatLinkClicked(uri);
            }
        } else
            GuiActivator.getBrowserLauncher().openURL(currentHref);

        // after opening the link remove the currentHref to avoid
        // clicking on the window to gain focus to open the link again
        this.currentHref = "";
    }
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

private void updateMainFrameListSelection(final int track, final int section, final MouseEvent event) {
    CorelyzerApp app = CorelyzerApp.getApp();
    if (app == null) {
        return;//from   ww  w . j  ava 2  s  .  c  o m
    }

    if (track >= 0) {
        // Now, we need to traverse app's list model
        // to find match of native id
        // index conversion (native to java list)

        CRDefaultListModel sessionModel = app.getSessionListModel();
        int sessionIndex = -1;
        TrackSceneNode trackNode = null;
        for (int i = 0; i < sessionModel.size(); i++) {
            Session session = (Session) sessionModel.elementAt(i);
            trackNode = session.getTrackSceneNodeWithTrackId(track);

            if (trackNode != null) {
                sessionIndex = i;
            }
        }

        if (sessionIndex < 0) {
            return;
        }

        // Set selected session
        app.getSessionList().setSelectedIndex(sessionIndex);

        // Track
        int ssize;
        boolean found = false;
        CRDefaultListModel tmodel = app.getTrackListModel();
        // tsize = tmodel.getSize();
        TrackSceneNode tt;
        CoreSection cs = null;

        for (int i = 0; i < tmodel.size() && !found; i++) {
            tt = (TrackSceneNode) tmodel.elementAt(i);

            if (track == tt.getId()) {
                selectedTrackIndex = i;
                ssize = tt.getNumCores();

                for (int j = 0; j < ssize; j++) {
                    cs = tt.getCoreSection(j);
                    if (section == cs.getId()) {
                        selectedTrackSectionIndex = j;
                        found = true;
                        break;
                    }
                }
            }
        }

        if (!found || cs == null) {
            return;
        }

        // update ui
        CorelyzerApp.getApp().getTrackList().setSelectedIndex(selectedTrackIndex);
        JList secList = CorelyzerApp.getApp().getSectionList();
        boolean selected = secList.isSelectedIndex(selectedTrackSectionIndex);
        List<Integer> indices = new ArrayList<Integer>();
        indices.addAll(Arrays.asList(ArrayUtils.toObject(secList.getSelectedIndices())));
        if (event.isControlDown() || (event.isMetaDown() && CorelyzerApp.MAC_OS_X)) { // toggle selection
            if (indices.contains(selectedTrackSectionIndex))
                indices.remove(new Integer(selectedTrackSectionIndex));
            else
                indices.add(selectedTrackSectionIndex);

            int[] newSelArray = ArrayUtils.toPrimitive(indices.toArray(new Integer[0]));
            secList.setSelectedIndices(newSelArray);
        } else if (event.isShiftDown()) { // select range
            int[] toSel = null;
            if (indices.size() == 0) {
                toSel = makeRangeArray(0, selectedTrackSectionIndex);
            } else {
                final int minSel = Collections.min(indices);
                final int maxSel = Collections.max(indices);
                if (selectedTrackSectionIndex < minSel) {
                    toSel = makeRangeArray(selectedTrackSectionIndex, minSel);
                } else if (selectedTrackSectionIndex > maxSel) {
                    toSel = makeRangeArray(maxSel, selectedTrackSectionIndex);
                }
            }
            secList.setSelectedIndices(toSel);
        } else if (!(event.isAltDown() && selected)) {
            // don't modify selection if Alt is down and section was already
            // selected...user is presumably trying to move it
            secList.setSelectedIndex(selectedTrackSectionIndex);
        }

        CRDefaultListModel lm = CorelyzerApp.getApp().getSectionListModel();
        String secName = null;
        if (lm != null) {
            Object selSec = lm.getElementAt(selectedTrackSectionIndex);
            if (selSec != null) {
                secName = selSec.toString();
            } else {
                System.out.println("no object at index");
            }
        } else {
            System.out.println("no list model");
        }

        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        String trackName = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex)
                .toString();
        title.setText("Track: " + trackName);
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: " + secName);

        // Enable section-based popupMenu options
        this.setEnableSectionBasedPopupMenuOptions(true);

        // 2/5/2012 brg: check Stagger Sections menu item if necessary
        final boolean trackIsStaggered = SceneGraph.trackIsStaggered(selectedTrack);
        AbstractButton ab = (AbstractButton) this.scenePopupMenu.getComponent(14);
        ab.getModel().setSelected(trackIsStaggered);

        // check section and graph lock menu items
        final boolean sectionIsLocked = !SceneGraph.isSectionMovable(selectedTrack, selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(7);
        ab.getModel().setSelected(sectionIsLocked);
        final boolean sectionGraphIsLocked = !SceneGraph.isSectionGraphMovable(selectedTrack,
                selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(8);
        ab.getModel().setSelected(sectionGraphIsLocked);

        CoreSectionImage csImg = cs.getCoreSectionImage();
        if (csImg != null && csImg.getId() != -1) {
            this.propertyMenuItem.setEnabled(true);
            this.splitMenuItem.setEnabled(true);
        } else {
            this.propertyMenuItem.setEnabled(false);
            this.splitMenuItem.setEnabled(false);
        }

        // System.out.println("---> [in Java DS] Picked Track " + track +
        // " and Track Section " + section);
        // String secname = CorelyzerApp.getApp().getSectionListModel().
        // getElementAt(section).toString();
        // System.out.println("---> [INFO] Section " + secname +
        // " is selected");
    } else {
        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        title.setText("Track: N/A");
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: N/A");

        // disable section based items
        this.setEnableSectionBasedPopupMenuOptions(false);
    }
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * /*from  ww  w  .j  a va 2 s  .c o m*/
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

From source file:org.broad.igv.variant.VariantTrack.java

/**
 * Handle a mouse click from the name panel.
 *
 * @param e/* w  w w  . ja  va 2s.  c  om*/
 */
@Override
public void handleNameClick(MouseEvent e) {
    String sampleAtPosition = getSampleAtPosition(e.getY());

    if (e.isPopupTrigger()) {
        return;
    }

    if (e.isMetaDown() || e.isControlDown()) {
        if (sampleAtPosition != null) {
            if (selectedSamples.contains(sampleAtPosition)) {
                //    selectedSamples.remove(sampleAtPosition);
            } else {
                selectedSamples.add(sampleAtPosition);
            }
        }
    } else if (e.isShiftDown() && !selectedSamples.isEmpty()) {
        int idx = getSampleIndex(sampleAtPosition);
        int lastIDX = getSampleIndex(selectedSamples.get(selectedSamples.size() - 1));
        if (idx >= 0 && lastIDX >= 0) {
            selectedSamples.clear();
            for (int i = Math.min(idx, lastIDX); i <= (Math.max(idx, lastIDX)); i++) {
                String s = sampleBounds.get(i).sample;
                selectedSamples.add(s);
            }
        }

    } else {
        if (sampleAtPosition != null) {
            if (selectedSamples.size() == 1 && selectedSamples.contains(sampleAtPosition)) {
                selectedSamples.clear();
                IGV.getInstance().repaint();
                return;
            } else {
                selectedSamples.clear();
            }
            selectedSamples.add(sampleAtPosition);
        }
    }
    IGV.getInstance().repaint();

}