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.jcraft.weirdx.DDXWindowImpSwing.java

public void mouseEntered(MouseEvent e) {

    if (window != null && window.getFrame() != null) {
        java.awt.Window frame = window.getFrame();
        if ((frame instanceof java.awt.Frame) && frame == e.getSource()) {
            try {
                if (window.isRealized()) {
                    XWindow.setInputFocus(window.client, window.id, 1, (int) System.currentTimeMillis(), false);
                }//from   w w w.  j  a  va2  s .c  o m
            } catch (Exception ee) {
                LOG.error(ee);
            }
            return;
        }
    }

    String str = CopyPaste.getString();
    if (!CopyPaste.isOwner() && str != null) {
        synchronized (window.screen.root) {
            Property p = window.screen.root.getProperty();
            while (p != null) {
                if (p.propertyName == 9)
                    break;
                p = p.next;
            }
            if (p != null) {
                p.data = str.getBytes();
                p.size = p.data.length;
            }
        }

        Selection sel = Selection.getSelection(1); // PRIMARY
        if (sel != null && sel.client != null) {
            int time = (int) System.currentTimeMillis();
            Event event = new Event();
            event.mkSelectionClear(time, sel.wid, sel.selection);
            try {
                sel.client.sendEvent(event, 1, Event.NoEventMask, Event.NoEventMask, null);
            } catch (Exception ee) {
                //System.out.println(ee);
            }
            ;
            sel.window = window.screen.root;
            sel.wid = window.screen.root.id;
            sel.lastTimeChanged = time;
            sel.client = null;
        }
        CopyPaste.setString(str);
    }

    if (window.id == window.screen.rootId) {
        return;
    }

    if (window.isMapped()) {
        requestFocus();
        XWindow.focus.win = window.id;
    }

    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;
    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    Client client = window.client;
    if (client == null || client == serverClient)
        return;

    event.mkEnterNotify(0, // Ancestor
            window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 0, // Normal
            0x1 | 0x02 // focus|same-screen
    );
    try {
        XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void mouseEntered(MouseEvent e) {
    if (window == null)
        return;/*  www .j a v a 2  s .c om*/
    if (window.getFrame() != null) {
        java.awt.Window frame = window.getFrame();
        if ((frame instanceof java.awt.Frame) && frame == e.getSource()) {
            try {
                if (window.isRealized()) {
                    XWindow.setInputFocus(window.client, window.id, 1, (int) System.currentTimeMillis(), false);
                }
            } catch (Exception ee) {
                LOG.error(ee);
            }
            return;
        }
    }

    String str = CopyPaste.getString();
    if (!CopyPaste.isOwner() && str != null) {
        synchronized (window.screen.root) {
            Property p = window.screen.root.getProperty();
            while (p != null) {
                if (p.propertyName == 9)
                    break;
                p = p.next;
            }
            if (p != null) {
                p.data = str.getBytes();
                p.size = p.data.length;
            }
        }

        Selection sel = Selection.getSelection(1); // PRIMARY
        if (sel != null && sel.client != null) {
            int time = (int) System.currentTimeMillis();
            Event event = new Event();
            event.mkSelectionClear(time, sel.wid, sel.selection);
            try {
                sel.client.sendEvent(event, 1, Event.NoEventMask, Event.NoEventMask, null);
            } catch (Exception ee) {
                //System.out.println(ee);
            }
            ;
            sel.window = window.screen.root;
            sel.wid = window.screen.root.id;
            sel.lastTimeChanged = time;
            sel.client = null;
        }
        CopyPaste.setString(str);
    }

    if (window.id == window.screen.rootId) {
        return;
    }

    if (window.isMapped()) {
        requestFocus();
        XWindow.focus.win = window.id;
    }

    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;
    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    Client client = window.client;
    if (client == null || client == serverClient)
        return;

    event.mkEnterNotify(0, // Ancestor
            window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 0, // Normal
            0x1 | 0x02 // focus|same-screen
    );
    try {
        XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_// w  w  w  .j a v a2s.  co  m
 *
 * @return _more_
 */
public JComponent doMakeDashboardPanel() {
    dashboardImage = GuiUtils.getImage("/auxdata/ui/icons/cockpit.gif", getClass(), false);
    pipPanel = new PipPanel(viewManager);
    pipPanel.getNavigatedPanel().setBorder(null);
    pipPanel.setPreferredSize(new Dimension(100, 100));
    pipPanel.doLayout();
    pipPanel.validate();
    pipFrame = new JFrame("Show remain invisible");
    pipFrame.setContentPane(pipPanel);
    pipFrame.pack();

    dashboardLbl = new JLabel(new ImageIcon(dashboardImage)) {
        public void paint(Graphics g) {
            //                readPts();
            paintDashboardBackground(g, dashboardLbl);
            super.paint(g);
            paintDashboardAfter(g, dashboardLbl);
        }
    };
    dashboardLbl.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            pipPanel.keyPressedInMap(e);
            updateDashboard();
        }
    });

    dashboardLbl.setVerticalAlignment(SwingConstants.BOTTOM);
    MouseAdapter mouseAdapter = new MouseAdapter() {
        Point mouseStart = new Point(0, 0);
        Point originalOffset = new Point(0, 0);

        public void mouseClicked(MouseEvent me) {
            if (pipRect == null) {
                return;
            }
            if (goToClick && pipRect.contains(new Point(me.getX(), me.getY()))) {
                try {
                    int x = me.getX() - pipRect.x;
                    int y = me.getY() - pipRect.y;
                    //                        System.err.println ("x:" + x +" y:" + y);
                    LatLonPoint llp = pipPanel.screenToLatLon(x, y);
                    location = makePoint(llp.getLatitude(), llp.getLongitude(), 0);
                    doDrive(false, heading);
                } catch (Exception exc) {
                    logException("Driving", exc);
                }
            }
        }

        public void mousePressed(MouseEvent me) {
            dashboardLbl.requestFocus();
            originalOffset = new Point(dashboardImageOffset);
            mouseStart.x = me.getX();
            mouseStart.y = me.getY();
            Rectangle b = dashboardLbl.getBounds();
            int w = dashboardImage.getWidth(null);
            int h = dashboardImage.getHeight(null);
            Point ul = new Point(b.width / 2 - w / 2, b.height - h);
            //                System.out.println("{" + (me.getX()-ul.x) +",  " + (me.getY()-ul.y)+"}");
        }

        public void mouseDragged(MouseEvent me) {
            dashboardImageOffset.x = originalOffset.x + me.getX() - mouseStart.x;
            dashboardImageOffset.y = originalOffset.y + me.getY() - mouseStart.y;
            updateDashboard();
        }
    };

    dashboardLbl.addMouseListener(mouseAdapter);
    dashboardLbl.addMouseMotionListener(mouseAdapter);

    //Create ome charts to force classloading (which takes some time) in a thread
    //So the gui shows quicker
    Misc.run(new Runnable() {
        public void run() {
            try {
                MeterPlot plot = new MeterPlot(new DefaultValueDataset(new Double(1)));
                createChart(new XYSeriesCollection());
            } catch (Exception ignore) {
            }
        }
    });

    return dashboardLbl;
}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Handles a 'mouse dragged' event./*  w  w w .  java  2  s  . c o  m*/
 *
 * @param e  the mouse event.
 */
public void mouseDragged(MouseEvent e) {

    // if the popup menu has already been triggered, then ignore dragging...
    if (this.popup != null && this.popup.isShowing()) {
        return;
    }
    // if no initial zoom point was set, ignore dragging...
    if (this.zoomPoint == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // Erase the previous zoom rectangle (if any)...
    drawZoomRectangle(g2);

    boolean hZoom = false;
    boolean vZoom = false;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        hZoom = this.rangeZoomable;
        vZoom = this.domainZoomable;
    } else {
        hZoom = this.domainZoomable;
        vZoom = this.rangeZoomable;
    }
    Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(),
                xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(),
                xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(),
                scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
    }

    // Draw the new zoom rectangle...
    drawZoomRectangle(g2);

    g2.dispose();

}

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

/**
 * Process popup trigger events occurring on an icon cell in the table. Show
 * a menu where the user can choose which external resource to open for the
 * entry. If no relevant external resources exist, let the normal popup trigger
 * handler do its thing instead./*from w  w w. ja v  a 2s . c  om*/
 * @param e The mouse event defining this popup trigger.
 * @param row The row where the event occurred.
 * @param iconType A string array containing the resource fields associated with
 *  this table cell.
 */
private void showIconRightClickMenu(MouseEvent e, int row, String[] iconType) {
    BibtexEntry entry = tableRows.get(row);
    JPopupMenu menu = new JPopupMenu();
    boolean showDefaultPopup = true;

    // See if this is a simple file link field, or if it is a file-list
    // field that can specify a list of links:
    if (iconType[0].equals(Globals.FILE_FIELD)) {
        // We use a FileListTableModel to parse the field content:
        Object o = entry.getField(iconType[0]);
        FileListTableModel fileList = new FileListTableModel();
        fileList.setContent((String) o);
        // If there are one or more links, open the first one:
        for (int i = 0; i < fileList.getRowCount(); i++) {
            FileListEntry flEntry = fileList.getEntry(i);

            //If file types are specified, ignore files of other types.
            if (iconType.length > 1) {
                boolean correctType = false;
                for (int j = 1; j < iconType.length; j++) {
                    if (flEntry.getType().toString().equals(iconType[j])) {
                        correctType = true;
                    }
                }
                if (!correctType) {
                    continue;
                }
            }

            String description = flEntry.getDescription();
            if ((description == null) || (description.trim().isEmpty())) {
                description = flEntry.getLink();
            }
            menu.add(new ExternalFileMenuItem(panel.frame(), entry, description, flEntry.getLink(),
                    flEntry.getType().getIcon(), panel.metaData(), flEntry.getType()));
            showDefaultPopup = false;
        }
    } else {
        SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]);
        if (field != null) {
            //                for (SpecialFieldValue val: field.getValues()) {
            //                   menu.add(val.getMenuAction(panel.frame()));
            //                }
            // full pop should be shown as left click already shows short popup
            showDefaultPopup = true;
        } else {
            for (String anIconType : iconType) {
                Object o = entry.getField(anIconType);
                if (o != null) {
                    menu.add(new ExternalFileMenuItem(panel.frame(), entry, (String) o, (String) o,
                            GUIGlobals.getTableIcon(anIconType).getIcon(), panel.metaData(), anIconType));
                    showDefaultPopup = false;
                }
            }
        }
    }
    if (showDefaultPopup) {
        processPopupTrigger(e, row);
    } else {
        menu.show(table, e.getX(), e.getY());
    }
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void makeNewMask(MouseEvent e, EntityCollection entities) {
    if (this.maskPoint == null) {
        return;//from  www  . j av a2s .  c  o  m
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any).  We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!isDoubleBuffered()) {
        //          drawZoomRectangle(g2, true);
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }

    //       boolean hZoom = false;
    //       boolean vZoom = false;
    //       if (this.orientation == PlotOrientation.HORIZONTAL) {
    //          hZoom = this.rangeZoomable;
    //          vZoom = this.domainZoomable;
    //       }
    //       else {
    //          hZoom = this.domainZoomable;
    //          vZoom = this.rangeZoomable;
    //       }
    Rectangle2D scaledDataArea = getScreenDataArea((int) this.maskPoint.getX(), (int) this.maskPoint.getY());
    // Working on the current mask. Only create one new mask per drag-drawing.
    if (currentMaskRectangle == null) {
        boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0;
        boolean isEllipse = (e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0;
        if (isEllipse) {
            currentMaskRectangle = new EllipseMask(isInclusive);
        } else {
            currentMaskRectangle = new RectangleMask(isInclusive);
        }
        //           currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive));
        //           getMasks().add(currentMaskRectangle);
        addMask(currentMaskRectangle);
    }
    // selected rectangle shouldn't extend outside the data area...
    double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
    double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
    // Update the current mask.
    ChartEntity startEntity = null;
    ChartEntity endEntity = null;
    boolean isMaskUpdated = false;
    if (entities != null) {
        //            EntityCollection entities = this.info.getEntityCollection();
        //            if (entities != null) {
        Insets insets = getInsets();
        double screenX = (maskPoint.getX() - insets.left) / getScaleX();
        double screenY = (maskPoint.getY() - insets.top) / getScaleY();
        startEntity = entities.getEntity(screenX, screenY);

        screenX = (xmax - insets.left) / getScaleX();
        screenY = (ymax - insets.top) / getScaleY();
        if (screenX >= scaledDataArea.getMaxX()) {
            screenX = scaledDataArea.getMaxX() - 0.001;
        }
        if (screenY >= scaledDataArea.getMaxY()) {
            screenY = scaledDataArea.getMaxY() - 0.001;
        }
        endEntity = entities.getEntity(screenX, screenY);
        //           System.out.println("Try to update mask");
        if (startEntity instanceof XYItemEntity && endEntity instanceof XYItemEntity) {
            isMaskUpdated = updateCurrentMaskRectangle((XYItemEntity) startEntity, (XYItemEntity) endEntity);
        }
        //            }
    }
    if (!isMaskUpdated) {
        currentMaskRectangle.setRectangleFrame(new Rectangle2D.Double(maskPoint.getX(), this.maskPoint.getY(),
                xmax - this.maskPoint.getX(), ymax - this.maskPoint.getY()));
    }
    // Draw the new zoom rectangle...
    if (isDoubleBuffered()) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }
    g2.dispose();
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Handles a 'mouse released' event. On Windows, we need to check if this is a popup trigger,
 * but only if we haven't already been tracking a zoom rectangle.
 * //from   w  w w . j a v  a2s. c  om
 * @param e
 *            information about the event.
 */

@Override
public void mouseReleased(MouseEvent e) {
    // if we've been panning, we need to reset now that the mouse is
    // released...
    if (this.panLast != null) {
        this.panLast = null;
        setCursor(Cursor.getDefaultCursor());
    } else if (this.selectionRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if (hZoom && e.getX() < this.zoomPoint.getX() || vZoom && e.getY() < this.zoomPoint.getY()) {
                restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.selectionRectangle.getWidth(), maxX - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.selectionRectangle.getHeight(), maxY - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.selectionRectangle.getWidth(), maxX - this.zoomPoint.getX());
                    h = Math.min(this.selectionRectangle.getHeight(), maxY - this.zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                selectRectangle(zoomArea, e);
            }
            this.zoomPoint = null;
            this.selectionRectangle = null;
        } else {
            this.zoomPoint = null;
            this.selectionRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }

}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void makeNewMask(MouseEvent e) {
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    if (Double.isNaN(maskPoint) || Math.abs(screenPoint.getX() - maskPoint) < minMaskWidth) {
        return;//from   ww w . j av  a 2  s. c o m
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any).  We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!isDoubleBuffered()) {
        //          drawZoomRectangle(g2, true);
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }

    //       boolean hZoom = false;
    //       boolean vZoom = false;
    //       if (this.orientation == PlotOrientation.HORIZONTAL) {
    //          hZoom = this.rangeZoomable;
    //          vZoom = this.domainZoomable;
    //       }
    //       else {
    //          hZoom = this.domainZoomable;
    //          vZoom = this.rangeZoomable;
    //       }
    Rectangle2D scaledDataArea = getScreenDataArea();
    //             (int) this.maskPoint.getX(), (int) this.maskPoint.getY());
    // Working on the current mask. Only create one new mask per drag-drawing.
    if (currentMaskRectangle == null) {
        boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0;
        currentMaskRectangle = new RangeMask(isInclusive);
        //           currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive));
        //           getMasks().add(currentMaskRectangle);
        addMask(currentMaskRectangle);
    }
    // selected rectangle shouldn't extend outside the data area...
    double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
    // Update the current mask.
    Insets insets = getInsets();
    double startX = ChartMaskingUtilities.translateScreenX((maskPoint - insets.left) / getScaleX(),
            getScreenDataArea(), getChart());
    double endX = ChartMaskingUtilities.translateScreenX((xmax - insets.left) / getScaleX(),
            getScreenDataArea(), getChart());
    updateCurrentDomainMask(startX, endX);
    // Draw the new zoom rectangle...
    if (isDoubleBuffered()) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }
    g2.dispose();
}

From source file:neembuu.uploader.NeembuuUploader.java

/**
 * Opens up the Popup Menu//from   w w w.  j  a v a  2  s . c  om
 *
 * @param evt
 */
private void openPopup(MouseEvent evt) {
    //The above three mouse events call this method.
    //So check which one will trigger Rightclick menu depending on os and use it.
    if (evt.isPopupTrigger()) {
        //Check if it is right click.
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            NULogger.getLogger().info("RightClick event");
            //if already 2 or more rows selected, leave it.
            //EDIT: After some days I forgot what this code does,.. This is copied from a stackoverflow post actually..
            //But it's an unchangeable code and will just work forever, so I'm not gonna mess with it.
            if (neembuuUploaderTable.getSelectedRowCount() < 2) {
                int r = neembuuUploaderTable.rowAtPoint(evt.getPoint());
                if (r >= 0 && r < neembuuUploaderTable.getRowCount()) {
                    neembuuUploaderTable.setRowSelectionInterval(r, r);
                } else {
                    neembuuUploaderTable.clearSelection();
                }

                int rowindex = neembuuUploaderTable.getSelectedRow();
                if (rowindex < 0) {
                    return;
                }
            }
            //Display the popup menu on the exact point of right click.
            PopupBuilder.getInstance().show(evt.getComponent(), evt.getX(), evt.getY());
        }
    }
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_layer.java

@Override
public void doPopup(MouseEvent e, int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());//from w  w  w.j  a va2  s .c o  m
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!isTableEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                if (networkElementType == NetworkElementType.LAYER
                        && callback.getDesign().getNumberOfLayers() == 1) {

                } else {
                    JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                    removeItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            NetPlan netPlan = callback.getDesign();

                            try {
                                netPlan.removeNetworkLayer(netPlan.getNetworkLayerFromId((long) itemId));

                                final VisualizationState vs = callback.getVisualizationState();
                                Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs
                                        .suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(
                                                new HashSet<>(callback.getDesign().getNetworkLayers()));
                                vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(),
                                        res.getSecond());
                                callback.updateVisualizationAfterChanges(
                                        Sets.newHashSet(NetworkElementType.LAYER));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                            } catch (Throwable ex) {
                                ErrorHandling.addErrorOrException(ex, getClass());
                                ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                            }
                        }
                    });

                    popup.add(removeItem);
                }

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

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