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:ja.lingo.application.gui.main.describer.DescriberGui.java

public void mouseClickedOnEditorPane(MouseEvent e) {
    if (!articlePanel.hasArticle()) {
        return;/*  w  w  w.j  a  v  a 2 s .  c  o m*/
    }

    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
        if (getSelectedTextTrimmed().length() > 0) {
            Rectangle rectangle;
            try {
                rectangle = articlePanel.getEditorPane()
                        .modelToView(articlePanel.getEditorPane().getSelectionStart());
            } catch (BadLocationException e1) {
                throw new RuntimeException(e1);
            }

            showMenuOnSelect(e.getX(), (int) (rectangle.getY() + rectangle.getHeight()));
        }
        return;
    }

    if (SwingUtilities.isRightMouseButton(e)) {
        if (getSelectedTextTrimmed().length() > 0) {
            showMenuOnSelect(e.getX(), e.getY());
        } else {
            menu.show(articlePanel, e.getX(), e.getY());
        }
    }
}

From source file:org.gumtree.vis.awt.time.TimePlotPanel.java

@Override
public void mouseMoved(MouseEvent e) {
    Insets insets = getInsets();//from w  w  w .  j av a2 s  . c om
    int x = (int) ((e.getX() - insets.left) / getScaleX());
    int y = (int) ((e.getY() - insets.top) / getScaleY());

    EntityCollection entities = getChartRenderingInfo().getEntityCollection();
    if (entities != null) {
        ChartEntity entity = entities.getEntity(x, y);
        Object[] listeners = getListeners(ChartMouseListener.class);
        if (getChart() != null) {
            XYChartMouseEvent event = new XYChartMouseEvent(getChart(), e, entity);
            event.setXY(getChartX(), getChartY());
            //              event.setSeriesIndex(seriesIndex);
            for (int i = listeners.length - 1; i >= 0; i -= 1) {
                ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
            }
        }
    }
    super.mouseMoved(e);
}

From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java

/**
 * creates the layered pane if it does not already exists
 * //from ww w .  j  a  v  a 2s  . 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 readers
        createReaders(controller.getReaderIds());

        // add context menu
        jLayeredPane.add(getContextMenu());

        // 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);
                    setActiveContextMenu(contextMenu);
                } else {
                    contextMenu.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:com.net2plan.gui.tools.GUINetworkDesign.java

@Override
public void configure(JPanel contentPane) {
    this.currentNetPlan = new NetPlan();

    BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>();
    Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>();
    for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) {
        mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size());
        layerVisibilityMap.put(layer, true);
    }//  ww  w .j a  v  a  2  s. c o  m
    this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap,
            MAXSIZEUNDOLISTPICK);

    topologyPanel = new TopologyPanel(this, JUNGCanvas.class);

    JPanel leftPane = new JPanel(new BorderLayout());
    JPanel logSection = configureLeftBottomPanel();
    if (logSection == null) {
        leftPane.add(topologyPanel, BorderLayout.CENTER);
    } else {
        JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPaneTopology.setTopComponent(topologyPanel);
        splitPaneTopology.setBottomComponent(logSection);
        splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener());
        splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground()));
        splitPaneTopology.setOneTouchExpandable(true);
        splitPaneTopology.setDividerSize(7);
        leftPane.add(splitPaneTopology, BorderLayout.CENTER);
    }
    contentPane.add(leftPane, "grow");

    viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout());

    reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT);

    setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan);
    Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState
            .generateCanvasDefaultVisualizationLayerInfo(getDesign());
    vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond());

    /* Initialize the undo/redo manager, and set its initial design */
    this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES);
    this.undoRedoManager.addNetPlanChange();

    onlineSimulationPane = new OnlineSimulationPane(this);
    executionPane = new OfflineExecutionPanel(this);
    whatIfAnalysisPane = new WhatIfAnalysisPane(this);

    // Closing windows
    WindowUtils.clearFloatingWindows();

    final JTabbedPane tabPane = new JTabbedPane();
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network),
            viewEditTopTables);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online),
            onlineSimulationPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif),
            whatIfAnalysisPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane);

    // Installing customized mouse listener
    MouseListener[] ml = tabPane.getListeners(MouseListener.class);

    for (int i = 0; i < ml.length; i++) {
        tabPane.removeMouseListener(ml[i]);
    }

    // Left click works as usual, right click brings up a pop-up menu.
    tabPane.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JTabbedPane tabPane = (JTabbedPane) e.getSource();

            int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY());

            if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
                if (tabIndex == tabPane.getSelectedIndex()) {
                    if (tabPane.isRequestFocusEnabled()) {
                        tabPane.requestFocus();

                        tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex));
                    }
                } else {
                    tabPane.setSelectedIndex(tabIndex);
                }

                if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) {
                    final JPopupMenu popupMenu = new JPopupMenu();

                    final JMenuItem popWindow = new JMenuItem("Pop window out");
                    popWindow.addActionListener(e1 -> {
                        final int selectedIndex = tabPane.getSelectedIndex();
                        final String tabName = tabPane.getTitleAt(selectedIndex);
                        final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent();

                        // Pops up the selected tab.
                        final WindowController.WindowToTab windowToTab = WindowController.WindowToTab
                                .parseString(tabName);

                        if (windowToTab != null) {
                            switch (windowToTab) {
                            case offline:
                                WindowController.buildOfflineWindow(selectedComponent);
                                WindowController.showOfflineWindow(true);
                                break;
                            case online:
                                WindowController.buildOnlineWindow(selectedComponent);
                                WindowController.showOnlineWindow(true);
                                break;
                            case whatif:
                                WindowController.buildWhatifWindow(selectedComponent);
                                WindowController.showWhatifWindow(true);
                                break;
                            case report:
                                WindowController.buildReportWindow(selectedComponent);
                                WindowController.showReportWindow(true);
                                break;
                            default:
                                return;
                            }
                        }

                        tabPane.setSelectedIndex(0);
                    });

                    // Disabling the pop up button for the network state tab.
                    if (WindowController.WindowToTab.parseString(tabPane
                            .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) {
                        popWindow.setEnabled(false);
                    }

                    popupMenu.add(popWindow);

                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    // Building windows
    WindowController.buildTableControlWindow(tabPane);
    WindowController.showTablesWindow(false);

    addAllKeyCombinationActions();
    updateVisualizationAfterNewTopology();
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void mouseDragged(MouseEvent event) {
    try {/*www.  j  av  a  2s  .  com*/
        if (this.panStartPoint != null) {
            Rectangle2D scaledDataArea = this.chartPanel.getScaledDataArea();

            this.panStartPoint = RefineryUtilities.getPointInRectangle(this.panStartPoint.getX(),
                    this.panStartPoint.getY(), scaledDataArea);
            Point2D panEndPoint = RefineryUtilities.getPointInRectangle(event.getX(), event.getY(),
                    scaledDataArea);

            // horizontal pan

            Plot plot = this.chartPanel.getChart().getPlot();
            if (plot instanceof XYPlot) {
                XYPlot hvp = (XYPlot) plot;
                ValueAxis xAxis = hvp.getDomainAxis();

                if (xAxis != null) {
                    double translatedStartPoint = xAxis.java2DToValue((float) panStartPoint.getX(),
                            scaledDataArea, hvp.getDomainAxisEdge());
                    double translatedEndPoint = xAxis.java2DToValue((float) panEndPoint.getX(), scaledDataArea,
                            hvp.getDomainAxisEdge());
                    double dX = translatedStartPoint - translatedEndPoint;

                    double oldMin = xAxis.getLowerBound();
                    double newMin = oldMin + dX;

                    double oldMax = xAxis.getUpperBound();
                    double newMax = oldMax + dX;

                    // do not pan out of range
                    if (newMin >= hvp.getDataRange(xAxis).getLowerBound()
                            && newMax <= hvp.getDataRange(xAxis).getUpperBound()) {
                        xAxis.setLowerBound(newMin);
                        xAxis.setUpperBound(newMax);
                    }
                }
            }

            // vertical pan (1. Y-Axis)

            if (plot instanceof XYPlot) {
                XYPlot vvp = (XYPlot) plot;
                ValueAxis yAxis = vvp.getRangeAxis();

                if (yAxis != null) {
                    double translatedStartPoint = yAxis.java2DToValue((float) panStartPoint.getY(),
                            scaledDataArea, vvp.getRangeAxisEdge());
                    double translatedEndPoint = yAxis.java2DToValue((float) panEndPoint.getY(), scaledDataArea,
                            vvp.getRangeAxisEdge());
                    double dY = translatedStartPoint - translatedEndPoint;

                    double oldMin = yAxis.getLowerBound();
                    double newMin = oldMin + dY;

                    double oldMax = yAxis.getUpperBound();
                    double newMax = oldMax + dY;

                    // do not pan out of range
                    if (newMin >= yMin && newMax <= yMax) {
                        yAxis.setLowerBound(newMin);
                        yAxis.setUpperBound(newMax);
                    }
                }
            }

            // for the next time
            this.panStartPoint = panEndPoint;
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:de.codesourcery.planning.swing.PlanningCanvas.java

@Override
public String getToolTipText(MouseEvent event) {
    IRegionOfInterest region = getRegionOfInterest(event.getX(), event.getY());
    if (region != null) {
        if (toolTipProvider != null) {
            return toolTipProvider.getToolTipText(region);
        }/*from  w  w  w  .j a  v  a2 s. co m*/
    }
    return null;
}

From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java

/**
 * creates the layered pane if it does not already exists
 * /*from  w  w w .  ja  v  a2  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;
        try {
            antennaIds = controller.getReadPointNames();
        } catch (HardwareException ignored) {
        }
        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:org.gumtree.vis.awt.time.TimePlotPanel.java

@Override
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();/*from w  w w .  ja v  a 2 s  . c  o m*/
    int x = (int) ((event.getX() - insets.left) / getScaleX());
    int y = (int) ((event.getY() - insets.top) / getScaleY());

    setAnchor(new Point2D.Double(x, y));
    if (getChart() == null) {
        return;
    }
    //        getChart().setNotify(true);  // force a redraw
    // new entity code...
    //        if (listeners.length == 0) {
    //            return;
    //        }

    ChartEntity entity = null;
    if (getChartRenderingInfo() != null) {
        EntityCollection entities = getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
            if (entity instanceof XYItemEntity) {
                XYItemEntity xyEntity = (XYItemEntity) entity;
                //                   XYDataset dataset = xyEntity.getDataset();
                //                   int item = ((XYItemEntity) entity).getItem();
                //                   chartX = dataset.getXValue(xyEntity.getSeriesIndex(), item);
                //                   chartY = dataset.getYValue(xyEntity.getSeriesIndex(), item);
                //                   Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                //                         new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                   if (getHorizontalAxisTrace()) {
                //                      horizontalTraceLocation = (int) screenPoint.getX();
                //                   }
                //                   if (getVerticalAxisTrace()) {
                //                      verticalTraceLocation = (int) screenPoint.getY();
                //                   }
                if ((event.getModifiers() & seriesSelectionEventMask) != 0
                        && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                    XYDataset dataset = xyEntity.getDataset();
                    if (dataset instanceof IDataset) {
                        selectSeries((IDataset) xyEntity.getDataset(), xyEntity.getSeriesIndex());
                    }
                } else if ((event.getModifiers() & maskingSelectionMask) == 0
                        && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                    if (selectedSeriesIndex != xyEntity.getSeriesIndex()) {
                        selectSeries(null, -1);
                    }
                }
            } else {
                if (selectedSeriesIndex >= 0) {
                    if ((event.getModifiers() & seriesSelectionEventMask) != 0
                            && (event.getModifiers() & maskingSelectionMask) == 0
                            && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                        selectSeries(null, -1);
                    }
                }
            }
        }
    }

    if ((event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        double chartX = ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart());
        int selectedDatasetIndex = 0;
        if (selectedDataset != null) {
            selectedDatasetIndex = getXYPlot().indexOf(selectedDataset);
        }
        double chartY = ChartMaskingUtilities.translateScreenY(y, getScreenDataArea(), getChart(),
                selectedDatasetIndex);
        setHorizontalTraceLocation(x);
        setVerticalTraceLocation(y);
        setChartX(chartX);
        setChartY(chartY);
        repaint();
    }

    XYChartMouseEvent chartEvent = new XYChartMouseEvent(getChart(), event, entity);
    chartEvent.setXY(getChartX(), getChartY());
    Object[] listeners = getListeners(ChartMouseListener.class);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
    System.out.println("chartX = " + getChartX() + ", chartY = " + getChartY());
}

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();/*from w w w .j  av  a 2  s  .com*/
    downY = evt.getY();
}

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  a v a2s .c om
        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();
}