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.qspin.qtaste.ui.TestCaseTree.java

@Override
public String getToolTipText(MouseEvent e) {
    if (getRowForLocation(e.getX(), e.getY()) == -1)
        return null;
    else {/* ww w  . ja va  2 s .  c  o  m*/
        TreePath tp = this.getPathForLocation(e.getX(), e.getY());
        TreeNode node = this.getTreeNode(tp);
        if (node != null) {
            TCTreeNode tcTreeNode = (TCTreeNode) node;
            if ((tcTreeNode.getUserObject() != null) && (tcTreeNode.getUserObject() instanceof FileNode)) {
                FileNode fNode = (FileNode) tcTreeNode.getUserObject();
                //node
                if (fNode.isTestcaseDir()) {
                    if (fNode.isTestcaseCheckOk()) {
                        // compute the number of test cases (based on test data)
                        String text = fNode.getTestcaseCount() + " testcase(s) defined.";
                        String testcaseHeader = fNode.getTestcaseHeader();
                        if (!testcaseHeader.isEmpty()) {
                            text += "\n\nDescription:\n" + testcaseHeader;
                        }
                        return text;
                    } else {
                        return "no TestData file found or file is empty.";
                    }
                }
            }
        }
        return null;
    }
}

From source file:au.org.ala.delta.editor.ui.CharacterTree.java

/**
 * This is a done to initiate a cell edit from a single click with drag and drop enabled.
 *///from w w w  .  j  a v a 2 s .c  o m
protected void processMouseEvent(MouseEvent e) {

    super.processMouseEvent(e);
    _doubleProcessingMouseEvent = false;
    TreePath selectedPath = getSelectionPath();
    if (selectedPath != null) {
        Object lastComponent = selectedPath.getLastPathComponent();
        if (lastComponent instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;

            if (node.isLeaf()) {
                int row = getRowForPath(selectedPath);
                Rectangle bounds = getRowBounds(row);
                int pos = e.getX() - bounds.x;
                if (pos >= 0 && pos < 20) {
                    _doubleProcessingMouseEvent = true;
                    super.processMouseEvent(e);
                }
            }
        }
    }
}

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

/**
 * Process general right-click events on the table. Show the table context menu at
 * the position where the user right-clicked.
 * @param e The mouse event defining the popup trigger.
 * @param row The row where the event occured.
 *//*from   w  w w  .  j  a v  a 2  s.  c o  m*/
private void processPopupTrigger(MouseEvent e, int row) {
    int selRow = table.getSelectedRow();
    if ((selRow == -1) || // (getSelectedRowCount() == 0))
            !table.isRowSelected(table.rowAtPoint(e.getPoint()))) {
        table.setRowSelectionInterval(row, row);
        //panel.updateViewToSelected();
    }
    RightClickMenu rightClickMenu = new RightClickMenu(panel, panel.metaData());
    rightClickMenu.show(table, 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 a 2 s. co m
    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:com.mycompany.zad1.MainWindow.java

private void imageMoiffayLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imageMoiffayLabelMouseClicked
    if (regionGrowing) {
        int treschold = Integer.parseInt(JOptionPane.showInputDialog("Treschold value"));
        RegionGrowing growing = new RegionGrowing();
        ArrayList<int[]> mask = growing.findRegion(imageBuff, evt.getX(), evt.getY(), treschold);

        ImageUtlis utlis = new ImageUtlis();
        utlis.repaintImage(imageBuff, colors[currentColor], mask);

        SupportFrame frame = new SupportFrame();

        frame.initRegionMask(imageOrginal.getWidth(), imageOrginal.getHeight(), mask);
        frame.setVisible(true);//  w  w w  .ja  v a  2  s .  c o  m
        imageMoiffayLabel.setIcon(new ImageIcon(imageBuff.getImage()));

        currentColor++;

        if (currentColor == colors.length) {
            regionGrowingButton.setEnabled(false);
            regionGrowing = false;
            currentColor = 0;
        }
    }
}

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);
    }/*from  ww  w .  j a v a2s  .  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:org.gumtree.vis.awt.time.TimePlotPanel.java

@Override
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();//  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:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void mouseDragged(MouseEvent event) {
    try {//  w w  w  . j  a  v  a  2s .  c  om
        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  .  ja v  a 2  s .com*/
    }
    return null;
}

From source file:io.gameover.utilities.pixeleditor.Pixelizer.java

public JProgressBar getToleranceBar() {
    if (toleranceBar == null) {
        toleranceBar = new JProgressBar();
        toleranceBar.setPreferredSize(new Dimension(200, 25));
        toleranceBar.setValue(10);//from  w w w.  j a  va 2 s  .  c o  m
        toleranceBar.setMaximum(100);
        toleranceBar.setStringPainted(true);
        toleranceBar.addMouseListener(new MouseAdapter() {
            public boolean mouseEntered = false;

            @Override
            public void mouseReleased(MouseEvent e) {
                if (mouseEntered) {
                    JProgressBar pb = (JProgressBar) e.getComponent();
                    pb.setValue((int) ((((double) e.getX()) / pb.getSize().getWidth()) * 100d));
                    pb.updateUI();
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                this.mouseEntered = true;
            }

            @Override
            public void mouseExited(MouseEvent e) {
                this.mouseEntered = false;
            }
        });
    }
    return toleranceBar;
}