Example usage for java.awt.event MouseEvent getX

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

Introduction

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

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

void pnlLinksMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMousePressed
    // Add your handling code here:
    pnlLinks.setCursor(new Cursor(Cursor.MOVE_CURSOR));

    downX = evt.getX();
    downY = evt.getY();//from w  ww . ja  v  a  2 s  .c  o  m
}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceEditorView.java

private void setupASTInspector() {
    astInspector = new JFrame("AST");

    final MouseAdapter treeMouseListener = new MouseAdapter() {
        @Override//www  .  j  ava2 s .c o m
        public void mouseMoved(MouseEvent e) {
            String text = null;
            TreePath path = astTree.getClosestPathForLocation(e.getX(), e.getY());

            if (path != null) {
                ASTNode node = (ASTNode) path.getLastPathComponent();
                if (node instanceof InstructionNode) { // TODO: debug code, remove when done
                    text = null;
                }
                try {
                    text = getCurrentCompilationUnit().getSource(node.getTextRegion());
                } catch (Exception ex) {
                    text = "Node " + node.getClass().getSimpleName() + " has invalid text region "
                            + node.getTextRegion();
                }
                text = "<HTML>" + text.replace("\n", "<BR>") + "</HTML>";
            }
            if (!ObjectUtils.equals(astTree.getToolTipText(), text)) {
                astTree.setToolTipText(text);
            }
        }
    };
    astTree.addMouseMotionListener(treeMouseListener);
    astTree.setCellRenderer(new ASTTreeCellRenderer());

    final JScrollPane pane = new JScrollPane(astTree);
    setColors(pane);
    pane.setPreferredSize(new Dimension(400, 600));

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.REMAINDER);
    cnstrs.weighty = 0.9;
    panel.add(pane, cnstrs);

    // add symbol table 
    symbolTable.setFillsViewportHeight(true);
    MouseAdapter mouseListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                int viewRow = symbolTable.rowAtPoint(e.getPoint());
                if (viewRow != -1) {
                    final int modelRow = symbolTable.convertRowIndexToModel(viewRow);
                    final ISymbol symbol = symbolTableModel.getSymbolForRow(modelRow);
                    final int caretPosition = symbol.getLocation().getStartingOffset();

                    IEditorView editor = null;
                    if (DefaultResourceMatcher.INSTANCE.isSame(symbol.getCompilationUnit().getResource(),
                            getSourceFromMemory())) {
                        editor = SourceEditorView.this;
                    } else if (getViewContainer() instanceof EditorContainer) {
                        final EditorContainer parent = (EditorContainer) getViewContainer();
                        try {
                            editor = parent.openResource(workspace, getCurrentProject(),
                                    symbol.getCompilationUnit().getResource(), caretPosition);
                        } catch (IOException e1) {
                            LOG.error("mouseClicked(): Failed top open "
                                    + symbol.getCompilationUnit().getResource(), e1);
                            return;
                        }
                    }
                    if (editor instanceof SourceCodeView) {
                        ((SourceCodeView) editor).moveCursorTo(caretPosition, true);
                    }
                }
            }
        }
    };
    symbolTable.addMouseListener(mouseListener);

    final JScrollPane tablePane = new JScrollPane(symbolTable);
    setColors(tablePane);
    tablePane.setPreferredSize(new Dimension(400, 200));

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.REMAINDER);
    cnstrs.weighty = 0.1;
    panel.add(pane, cnstrs);

    final JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, tablePane);
    setColors(split);

    // setup content pane
    astInspector.getContentPane().add(split);
    setColors(astInspector.getContentPane());
    astInspector.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    astInspector.pack();
}

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

/**
 * Show popup menu/* w  w  w  .ja v  a  2s  .com*/
 * 
 * @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: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;
        }//from   w w  w  . j a  v  a2s  . c  o  m
        onMouseAction(evt, crop, true);
    }
}

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   w  ww  . jav a  2s.  c om*/
            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 ww w.  java 2  s.c  om
        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:Classes.MainForm.java

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

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

private void onMouseAction(MouseEvent evt, Rectangle crop, boolean chart) {
    if (chart) {//from  w ww . j a v a 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.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//  w  w w  .j  av a2 s.  com
    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: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
 *//*  w ww. ja  v a2 s  .c om*/
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());
            }
        });
    }
}