Example usage for java.awt.event MouseEvent getY

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

Introduction

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

Prototype

public int getY() 

Source Link

Document

Returns the vertical y position of the event relative to the source component.

Usage

From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java

private void initPopupMenu() {
    popup = new JPopupMenu();
    popup.add(this.actRunQuery);
    popup.add(this.actCancelQuery);
    popup.addSeparator();/* w w  w  .jav a 2  s  . co  m*/
    popup.add(this.actLoadData);
    popup.add(this.actLoadQuery);
    popup.addSeparator();
    popup.add(this.actNextMajorInstance);
    popup.add(this.actPreviousMajorInstance);
    popup.addSeparator();
    popup.add(this.actNextMinorInstance);
    popup.add(this.actPreviousMinorInstance);
    popupListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            showPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            showPopup(e);
        }

        private void showPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };
    this.mainPanel.addMouseListener(popupListener);
}

From source file:org.fhaes.jsea.JSEAFrame.java

/**
 * Show popup menu// w ww .j a  va  2 s.c om
 * 
 * @param component
 * @param popup
 */
private static void addPopup(Component component, final JPopupMenu popup) {

    component.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {

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

        @Override
        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:org.accada.hal.impl.sim.GraphicSimulator.java

/**
 * creates the layered pane if it does not already exists
 * /*from   w w  w  .ja v a 2 s  .c  o m*/
 * @return layered pane
 */
private JLayeredPane getJLayeredPane() {
    if (jLayeredPane == null) {
        jLayeredPane = new JLayeredPane();
        jLayeredPane.setLayout(null);
        jLayeredPane.setOpaque(true);
        jLayeredPane.setBackground(Color.WHITE);
        jLayeredPane.add(getReader(), new Integer(0));

        // add antennas
        String[] antennaIds = null;
        antennaIds = controller.getReadPointNames();
        for (int i = 0; i < antennaIds.length; i++) {
            createNewAntenna(antennaIds[i]);
        }
        jLayeredPane.add(getContextMenu());
        jLayeredPane.add(getMgmtSimMenu());

        // add mouse listener
        jLayeredPane.addMouseListener(new MouseAdapter() {

            // context menu
            public void mouseReleased(MouseEvent e) {
                hideActiveContextMenuAndSelection();
                if (e.getButton() == MouseEvent.BUTTON3) {
                    Point posOnScreen = getJLayeredPane().getLocationOnScreen();
                    contextMenu.setLocation(posOnScreen.x + e.getX(), posOnScreen.y + e.getY());
                    contextMenu.setVisible(true);
                    mgmtSimMenu.setVisible(false);
                    setActiveContextMenu(contextMenu);
                } else {
                    contextMenu.setVisible(false);
                    mgmtSimMenu.setVisible(false);
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        selection.select(tags);
                    }
                }
            }

            // selection
            public void mousePressed(final MouseEvent e) {
                hideActiveContextMenuAndSelection();
                if (e.getButton() == MouseEvent.BUTTON1) {
                    selection.setBounds(0, 0, getProperty("WindowWidth"), getProperty("WindowHeight"));
                    selection.setStartPoint(e.getPoint());
                    jLayeredPane.add(selection, new Integer(2));
                }
            }
        });

        // add drag listener
        jLayeredPane.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                if (selection.isActive()) {
                    selection.setCurrentPoint(e.getPoint());
                }
            }
        });
    }
    return jLayeredPane;
}

From source file:jmupen.MyListSelectionListener.java

@Override
public void mousePressed(MouseEvent e) {
    list.setSelectedIndex(list.locationToIndex(e.getPoint()));
    int index = list.getSelectedIndex();
    if (SwingUtilities.isRightMouseButton(e)) {
        JPopupMenu menu = new JPopupMenu();
        JMenuItem item = new JMenuItem("Remove");
        item.addActionListener(new ActionListener() {
            @Override/*from   ww  w .j  a v  a2  s .co m*/
            public void actionPerformed(ActionEvent e) {
                if (index != -1) {
                    try {
                        System.out.println("Linea: " + index + " " + model.get(index));
                        model.removeElementAt(index);
                        removeLines(index, JMupenUtils.getRecents().toFile());
                        JMupenUtils.setGames(JMupenUtils.getGamesFromFile(JMupenUtils.getRecents()));
                    } catch (IOException ex) {
                        System.err.println("Error removing recent game. " + ex.getLocalizedMessage());
                    }
                }
            }
        });
        menu.add(item);
        menu.show(list, e.getX(), e.getY());
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void mousePressed(MouseEvent e) {

    if (MouseUtils.isPopupTrigger(e)) {
        // open popup
        current_peak = findPeakAt(e.getPoint());
        enforceSelection(current_peak);//from   w  w w .j  av  a2s . c o m
        createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY());
    } else {
        was_moving = is_moving;
        if ((MouseUtils.isPushTrigger(e) || MouseUtils.isMoveTrigger(e))
                && theChartPanel.getScreenDataArea().contains(e.getPoint())) {
            mouse_start_point = e.getPoint();
            if (MouseUtils.isMoveTrigger(e))
                onActivateMoving();
        }
    }
}

From source file:edu.pdi2.visual.PDI.java

private void djMousePressed(MouseEvent evt) {
    Rectangle crop = td.dt.getCroppedImageBounds();
    if (si != null) {
        if (cm != null) {
            cm.addPoint(evt.getX() + crop.x + upperLeftX, evt.getY() + crop.y + upperLeftY);
            return;
        }//  w  w  w .  j  a  va2s  . c  o m
        onMouseAction(evt, crop, true);
    }
}

From source file:Classes.MainForm.java

public void mainFrameMousePressed(MouseEvent e) {//moving form with mouse
    this.mouseInitX = e.getX();
    this.mouseInitY = e.getY();
}

From source file:net.schweerelos.parrot.ui.GraphViewComponent.java

@SuppressWarnings("serial")
private void setupRenderContext(final VisualizationViewer<NodeWrapper, NodeWrapper> vis) {
    vis.setRenderer(new ParrotGraphRenderer());
    vis.setPickSupport(new ParrotPickSupport(vis));

    RenderContext<NodeWrapper, NodeWrapper> renderContext = vis.getRenderContext();

    final PickedInfo<NodeWrapper> vertexPickInfo = vis.getPickedVertexState();
    final PickedState<NodeWrapper> edgePickInfo = vis.getPickedEdgeState();

    // hide all edge arrows except for those on outgoing edges of picked
    // nodes//from   w  w w. j  av  a 2 s.c  o m
    renderContext.setEdgeArrowPredicate(new Predicate<Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper>>() {
        @Override
        public boolean evaluate(Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper> context) {
            NodeWrapper edge = context.element;
            NodeWrapper source = graph.getSource(edge);
            return vertexPickInfo.isPicked(source);
        }
    });

    // make edges straight lines to collapse parallel edges
    renderContext.setEdgeShapeTransformer(new EdgeShape.Line<NodeWrapper, NodeWrapper>());

    // hide text of all edges except for outgoing edges of picked nodes
    renderContext.setEdgeLabelTransformer(new Transformer<NodeWrapper, String>() {
        @Override
        public String transform(NodeWrapper edge) {
            NodeWrapper source = graph.getSource(edge);
            NodeWrapper destination = graph.getDest(edge);
            if (vertexPickInfo.isPicked(source) && !vertexPickInfo.isPicked(destination)) {
                return edge.toString();
            } else {
                return "";
            }
        }
    });
    renderContext.setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(COLOR_EDGE_LABEL) {
        @Override
        public <E> Component getEdgeLabelRendererComponent(JComponent vv, Object value, Font font,
                boolean isSelected, E edge) {
            Component component = super.getEdgeLabelRendererComponent(vv, value, font, isSelected, edge);
            component.setForeground(COLOR_EDGE_LABEL);
            return component;
        }

    });

    // start from VertexLabelAsShapeDemo

    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<NodeWrapper, NodeWrapper> vlasr = new VertexLabelAsShapeRenderer<NodeWrapper, NodeWrapper>(
            renderContext);
    renderContext.setVertexShapeTransformer(vlasr);

    vis.setForeground(COLOR_NODE_TEXT);

    // customize the render context

    renderContext.setVertexLabelTransformer(new ToStringLabeller<NodeWrapper>());

    renderContext.setVertexLabelRenderer(new DefaultVertexLabelRenderer(COLOR_NODE_PICKED_TEXT) {
        @Override
        public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font,
                boolean isSelected, V vertexToRender) {
            Component component = super.getVertexLabelRendererComponent(vv, value, font, isSelected,
                    vertexToRender);
            if (component instanceof JLabel) {
                JLabel label = (JLabel) component;
                // add a little bit of padding around the text
                Border originalBorder = label.getBorder();
                label.setBorder(BorderFactory.createCompoundBorder(originalBorder,
                        BorderFactory.createEmptyBorder(3, 2, 4, 2)));
            }
            // now set the colour/font too
            if (vertexToRender instanceof NodeWrapper) {
                NodeWrapper vertex = (NodeWrapper) vertexToRender;
                if (vertexPickInfo.isPicked(vertex)) {
                    component.setForeground(COLOR_NODE_PICKED_TEXT);
                } else if (vertex.isHighlighted()) {
                    component.setForeground(COLOR_NODE_HIGHLIGHTED_TEXT);
                    component.setFont(font.deriveFont(Font.BOLD));
                } else if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) {
                    component.setForeground(COLOR_NODE_WITH_PICKED_NEIGHBOUR_TEXT);
                } else if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) {
                    component.setForeground(COLOR_NODE_ADJACENT_EDGE_PICKED_TEXT);
                } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) {
                    component.setForeground(COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_TEXT);
                } else {
                    component.setForeground(COLOR_NODE_TEXT);
                }
            }

            return component;
        }
    });

    // end from VertexLabelAsShapeDemo

    vis.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    vis.setVertexToolTipTransformer(new Transformer<NodeWrapper, String>() {
        @Override
        public String transform(NodeWrapper vertex) {
            return vertex.getToolTipText(model);
        }
    });

    // inspired by PluggableRendererDemo
    Transformer<NodeWrapper, Paint> vertexOutline = new Transformer<NodeWrapper, Paint>() {
        @Override
        public Paint transform(NodeWrapper vertex) {
            if (vertexPickInfo.isPicked(vertex)) {
                return COLOR_NODE_PICKED_BORDER;
            } else if (vertex.isHighlighted()) {
                return COLOR_NODE_HIGHLIGHTED_BORDER;
            } else {
                if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) {
                    return COLOR_NODE_ADJACENT_EDGE_PICKED_BORDER;
                }
                if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) {
                    return COLOR_NODE_WITH_PICKED_NEIGHBOUR_BORDER;
                } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) {
                    return COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_BORDER;
                }
                // will get here only if no neighbour is picked/highlighted
                return COLOR_NODE_BORDER;
            }
        }
    };
    renderContext.setVertexDrawPaintTransformer(vertexOutline);

    Transformer<NodeWrapper, Paint> vertexBackground = new Transformer<NodeWrapper, Paint>() {
        @Override
        public Paint transform(NodeWrapper vertex) {
            if (vertexPickInfo.isPicked(vertex)) {
                return COLOR_NODE_PICKED_BG;
            } else if (vertex.isHighlighted()) {
                return COLOR_NODE_HIGHLIGHTED_BG;
            } else {
                if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) {
                    return COLOR_NODE_ADJACENT_EDGE_PICKED_BG;
                }
                if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) {
                    return COLOR_NODE_WITH_PICKED_NEIGHBOUR_BG;
                } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) {
                    return COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_BG;
                }
                return COLOR_NODE_BG;
            }
        }
    };
    renderContext.setVertexFillPaintTransformer(vertexBackground);

    Transformer<NodeWrapper, Stroke> vertexStroke = new Transformer<NodeWrapper, Stroke>() {
        @Override
        public Stroke transform(NodeWrapper vertex) {
            if (vertexPickInfo.isPicked(vertex)) {
                return STROKE_VERTEX_PICKED;
            } else if (vertex.isHighlighted()) {
                return STROKE_VERTEX_HIGHLIGHTED;
            }

            Collection<NodeWrapper> edges = graph.getInEdges(vertex);
            for (NodeWrapper edge : edges) {
                if (edgePickInfo.isPicked(edge)) {
                    return STROKE_VERTEX_INCOMING_EDGE_PICKED;
                }
            }
            edges = graph.getOutEdges(vertex);
            for (NodeWrapper edge : edges) {
                if (edgePickInfo.isPicked(edge)) {
                    return STROKE_VERTEX_OUTGOING_EDGE_PICKED;
                }
            }

            // we'll only get here if none of the cases above applies
            return STROKE_VERTEX_DEFAULT;
        }
    };
    renderContext.setVertexStrokeTransformer(vertexStroke);

    Transformer<NodeWrapper, Stroke> edgeStroke = new Transformer<NodeWrapper, Stroke>() {
        @Override
        public Stroke transform(NodeWrapper edge) {
            NodeWrapper edgeSource = graph.getSource(edge);
            if (edgePickInfo.isPicked(edge)) {
                return STROKE_EDGE_PICKED;
            } else if (vertexPickInfo.isPicked(edgeSource)) {
                return STROKE_EDGE_ADJACENT_NODE_PICKED;
            } else {
                return STROKE_EDGE_DEFAULT;
            }
        }
    };
    renderContext.setEdgeStrokeTransformer(edgeStroke);

    Transformer<NodeWrapper, Paint> edgeColor = new Transformer<NodeWrapper, Paint>() {
        @Override
        public Paint transform(NodeWrapper edge) {
            if (edgePickInfo.isPicked(edge)) {
                return COLOR_EDGE_PICKED;
            } else if (GraphViewHelper.hasPickedAdjacentVertex(edge, vertexPickInfo, graph)) {
                return COLOR_EDGE_ADJACENT_VERTEX_PICKED;
            } else if (edge.isHighlighted()) {
                return COLOR_EDGE_HIGHLIGHTED;
            } else if (GraphViewHelper.hasHighlightedAdjacentVertex(edge, graph)) {
                return COLOR_EDGE_ADJACENT_VERTEX_HIGHLIGHTED;
            } else {
                return COLOR_EDGE;
            }
        }
    };
    renderContext.setEdgeDrawPaintTransformer(edgeColor);
    // draw arrows in the same colour as edges
    renderContext.setArrowDrawPaintTransformer(edgeColor);
    renderContext.setArrowFillPaintTransformer(edgeColor);

    includePredicate = new IncludePredicate<Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper>>();
    renderContext.setEdgeIncludePredicate(includePredicate);
    renderContext.setVertexIncludePredicate(includePredicate);

    vis.setBackground(COLOR_BACKGROUND);

    mouse = new DoubleClickPickingModalGraphMouse<NodeWrapper, NodeWrapper>();
    mouse.add(new AbstractPopupGraphMousePlugin() {
        @Override
        protected void handlePopup(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                return;
            }
            GraphElementAccessor<NodeWrapper, NodeWrapper> pickSupport = vis.getPickSupport();
            if (pickSupport == null) {
                return;
            }

            NodeWrapper node = pickSupport.getVertex(layout, e.getX(), e.getY());
            if (node == null) {
                node = pickSupport.getEdge(layout, e.getX(), e.getY());
            }
            if (node == null) {
                return;
            }
            popup.setNodeWrapper(node);
            popup.show(vis, e.getX(), e.getY());
        }
    });
    mouse.setDoubleClickPickingPlugin(new DoubleClickPickingPlugin() {
        @Override
        void doubleClickOccurred(MouseEvent e) {
            GraphElementAccessor<NodeWrapper, NodeWrapper> pickSupport = vis.getPickSupport();
            if (pickSupport == null) {
                return;
            }

            NodeWrapper node = pickSupport.getVertex(layout, e.getX(), e.getY());
            if (node == null) {
                return;
            }
            fireNodeSelected(node);
        }
    });
    vis.setGraphMouse(mouse);

}

From source file:edu.pdi2.visual.PDI.java

private void onMouseAction(MouseEvent evt, Rectangle crop, boolean chart) {
    if (chart) {/*from   ww w  .java  2s  .  c  o m*/
        signature = bandsManager
                .getSignature(new Point(evt.getX() + crop.x + upperLeftX, evt.getY() + crop.y + upperLeftY));
        XYSeries signature1 = new XYSeries("Signature");
        for (int i = 0; i < signature.length; i++) {
            signature1.add(i, signature[i]);
        }
        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(signature1);
        XYPlot plot = (XYPlot) signatureG.getPlot();
        plot.setDataset(dataset);
    }
    int x = evt.getX() + crop.x + upperLeftX;
    int y = evt.getY() + crop.y + upperLeftY;
    edu.pdi2.forms.Point point = new Point(x, y);
    double lat = et.getXi_(x, y);
    double lon = et.getYi_(x, y);
    posDialog.setLat(lat);
    posDialog.setLon(lon);
    jLat.setText("Lat: " + ToDegrees(lat / 10000));
    jLong.setText("Long: " + ToDegrees(lon / 10000));

    for (int i = 0; i < mesh.size(); i++) {
        Polygon p = (Polygon) mesh.get(i);
        // Vector gPoints = p.getGPoints();
        if (p.isIn(point)) {
            p.changeColor();

            ElasticTransform etP = p.getET();
            lat = etP.getYi_(x, y);
            lon = etP.getXi_(x, y);
            posDialog.setLat(lat);
            posDialog.setLon(lon);
            jLat.setText("Lat: " + ToDegrees(lat));
            jLong.setText("Long: " + ToDegrees(lon));
            break;
        }

    }

}

From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java

/**
 * Method to handle a single left click on one the special fields (e.g., ranking, quality, ...)
 * Shows either a popup to select/clear a value or simply toggles the functionality to set/unset the special field
 *
 * @param e MouseEvent used to determine the position of the popups
 * @param columnName the name of the specialfield column
 *//*ww  w  . ja  va  2 s .  c  o m*/
private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) {
    if ((e.getClickCount() == 1)) {
        SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(columnName).ifPresent(field -> {
            // special field found
            if (field.isSingleValueField()) {
                // directly execute toggle action instead of showing a menu with one action
                field.getValues().get(0).getAction(panel.frame()).action();
            } else {
                JPopupMenu menu = new JPopupMenu();
                for (SpecialFieldValue val : field.getValues()) {
                    menu.add(val.getMenuAction(panel.frame()));
                }
                menu.show(table, e.getX(), e.getY());
            }
        });
    }
}