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.yosanai.java.aws.console.panel.InstancesPanel.java

public void showPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
        tblPopup.show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:ec.ui.view.StabilityView.java

public StabilityView() {
    super();/* www . j  a  va2s . com*/
    setLayout(new BorderLayout());

    this.graphs_ = new LinkedHashMap<>();

    meanRenderer = new XYLineAndShapeRenderer(true, false);
    meanRenderer.setAutoPopulateSeriesPaint(false);
    meanRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.RED));

    pointsRenderer = new XYLineAndShapeRenderer(false, true);
    pointsRenderer.setAutoPopulateSeriesPaint(false);
    pointsRenderer.setAutoPopulateSeriesShape(false);
    pointsRenderer.setBaseShape(new Ellipse2D.Double(-2, -2, 4, 4));
    pointsRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.BLUE));
    pointsRenderer.setBaseShapesFilled(false);

    smoothRenderer = new XYLineAndShapeRenderer(true, false);
    smoothRenderer.setAutoPopulateSeriesPaint(false);
    smoothRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.GREEN));

    mainChart = createChart();
    detailChart = createChart();

    panel = new JChartPanel(null);

    errorPanel = new JPanel(new BorderLayout());
    errorLabel = new JLabel();
    errorLabel.setHorizontalAlignment(SwingConstants.CENTER);
    errorLabel.setFont(errorLabel.getFont().deriveFont(errorLabel.getFont().getSize2D() * 3 / 2));
    errorPanel.add(errorLabel, BorderLayout.CENTER);

    panel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            indexSelected = -1;
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                double x = panel.getChartX(e.getX());
                Graphs g = null;
                for (Bornes b : graphs_.keySet()) {
                    indexSelected++;
                    if (x >= b.min_ && x <= b.max_) {
                        g = graphs_.get(b);
                        break;
                    }
                }
                if (g == null) {
                    return;
                }

                showDetail(g);
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                showMain();
                indexSelected = -1;
            }
        }
    });

    StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator() {
        final DecimalFormat format = new DecimalFormat("0.0000");

        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            try {
                StabilityViewItem i = items.get(indexSelected == -1 ? series : indexSelected);
                int cpt = 0;
                for (Map.Entry<TsDomain, Double> e : i.data.entrySet()) {
                    if (cpt == item) {
                        TsDomain dom = e.getKey();
                        return "(" + dom.getStart().toString() + ", " + dom.getEnd().toString() + ") : "
                                + format.format(e.getValue());
                    }
                    cpt++;
                }
            } catch (IndexOutOfBoundsException e) {
            }
            return null;
        }
    };
    pointsRenderer.setBaseToolTipGenerator(generator);
    cards = new JPanel(new CardLayout());

    cards.add(MAIN_PANEL, panel);

    cards.add(ERROR_PANEL, errorPanel);

    add(cards, BorderLayout.CENTER);

    onColorSchemeChange();
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

public void mouseClicked(MouseEvent e) {
    if (e.getSource() instanceof ChartPanel && ((e.getButton() == MouseEvent.BUTTON2)
            || (e.getButton() == MouseEvent.BUTTON1) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))) {
        CenterZoomNumberAxis czna = (CenterZoomNumberAxis) _cp.getChart().getXYPlot().getDomainAxis();
        NumberAxis range = (NumberAxis) _cp.getChart().getXYPlot().getRangeAxis();
        Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY());
        double y1 = czna.getLowerBound();
        double y2 = czna.getUpperBound();
        double x1 = screenDataArea.getX();
        double x2 = x1 + screenDataArea.getWidth();
        double transformedx = (((y2 - y1) / (x2 - x1)) * (e.getX() - x1)) + y1;
        MRMDialog mrmd = (MRMDialog) MRMAncestor();
        PeaksTableModel model = (PeaksTableModel) mrmd.peaksTable.getModel();
        MRMTransition mrt = mrmd.transitionOnPlot;
        mrt.setCalcXatMaxYAllDaughters(transformedx);
        mrt.setCalcMaxYAllDaughters(/*  w ww  .j av a 2  s  . c om*/
                range.getLowerBound() + 0.95 * (range.getUpperBound() - range.getLowerBound()));
        model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), mrt.getTableRow(),
                MRMDialog.peaksData.MidTime.colno);
        for (MRMDaughter d : mrt.getDaughters().values()) {
            model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), d.getElutionDataTableRow(),
                    MRMDialog.peaksData.MidTime.colno);
        }
        mrmd.updateChartsAndFields(false);
    }
    if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
        _cp.mouseClicked(e);
    } else {
        _cp.mouseClicked(e);
    }
}

From source file:AsymptoticFreedom.AppletAF.java

private void theViewPanelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_theViewPanelMousePressed
    // TODO add your handling code here:
    //System.out.printf("pressed >> x : %d, y : %d\n",evt.getX(), evt.getY());
    for (int i = 0; i < theViewPanel.getQuarkSize(); i++) {
        if (theViewPanel.quark_list.get(i).pos.distance(new Point(evt.getX(), evt.getY())) < 25) {
            //System.out.printf("Selected %d quark!\n",i);                
            pre_x_pos = evt.getX();/*from   w ww  .ja  v  a2  s.c  o m*/
            pre_y_pos = evt.getY();

            //theViewPanel.repaint();
        }
    }
    theViewPanel.repaint();
}

From source file:AsymptoticFreedom.AppletAF.java

private void theViewPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_theViewPanelMouseDragged
    // TODO add your handling code here:
    //System.out.printf("Draggred>> x : %d, y : %d\n",evt.getX(), evt.getY());
    for (int i = 0; i < theViewPanel.getQuarkSize(); i++) {
        if (theViewPanel.quark_list.get(i).pos.distance(new Point(evt.getX(), evt.getY())) < 25) {
            //System.out.printf("Selected %d quark!\n",i);
            theViewPanel.quark_list.get(i).translate(evt.getX() - pre_x_pos, evt.getY() - pre_y_pos);
            //System.out.format("%d %d\n",evt.getX()-pre_x_pos,evt.getY()-pre_y_pos);
            pre_x_pos = evt.getX();//from  w  ww  . j a v  a 2s  .c o  m
            pre_y_pos = evt.getY();

        }
    }
    theViewPanel.repaint();
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

public void mouseReleased(MouseEvent e) {
    if (isReadOnly())
        return;/* w ww.  ja  va 2s .co m*/
    if (!SwingUtilities.isLeftMouseButton(e))
        return;
    if (selected == null || state == NOTHING_SELECTED)
        return;
    if (isRepaintOnRelease())
        getGraph().repaint();

    double x1 = e.getX();
    double y1 = e.getY();
    executeAction(x1, y1);
    reset();
    findState(x1, y1);
}

From source file:JavaXWin.java

public void mousePressed(MouseEvent e) {
    //toFront();/*from   w  ww.j av a 2 s.c  om*/
    m_rightX = m_resizeComponent.getX() + m_resizeComponent.getWidth();
    m_dragging = true;
    m_dragX = e.getX();
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

public void mouseDragged(MouseEvent e) {
    if (isReadOnly())
        return;/*  w  w w.ja  va2 s. c  o  m*/
    if (!SwingUtilities.isLeftMouseButton(e))
        return;
    if (selected instanceof GraphicNode) {
        GraphicNode node = (GraphicNode) selected;
        boolean sw = switchOnLinkCreation(e.getX(), e.getY());
        if (state != LINK_CREATION && sw) {
            drawBarShadow(lastShadowX, lastLinkShadowY, true);
            beforeLinkState = state;
            state = LINK_CREATION;
            selectCursor();

            sourceNode = (GraphicNode) selected;
            drawLinkSelectionBarShadow(sourceNode);

            setLinkOrigin();
        } else if (state == LINK_CREATION && !sw && allowLinkSelectionToMove()) {
            drawLinkShadow(lastLinkShadowX, lastLinkShadowY, true);
            drawBarShadow(lastShadowX, lastLinkShadowY, true);
            state = beforeLinkState;
            selectCursor();

            sourceNode = null;

        }
    }
    if (state == LINK_CREATION) {
        GraphZone zone = ui.getNodeAt(e.getX(), e.getY());
        GraphicNode newDestinationNode = zone == null ? null : (GraphicNode) zone.getObject();
        drawLinkSelectionBarShadow(destinationNode);
        drawLinkShadow(lastLinkShadowX, lastLinkShadowY, true);
        scrollToVisible(e.getX(), e.getY());
        drawLinkShadow(e.getX(), e.getY(), true);
        if (newDestinationNode != null && newDestinationNode.isLinkable() && sourceNode != newDestinationNode) {
            destinationNode = newDestinationNode;
            drawLinkSelectionBarShadow(destinationNode);
        } else
            destinationNode = null;
    } else if (isMove()) {
        drawBarShadow(lastShadowX, lastShadowY, true);
        scrollToVisible(e.getX(), e.getY());
        drawBarShadow(e.getX(), e.getY(), true);
    }
}

From source file:ScribbleDragAndDrop.java

/**
 * This method implements the DragGestureListener interface. It will be
 * invoked when the DragGestureRecognizer thinks that the user has initiated
 * a drag. If we're not in drawing mode, then this method will try to figure
 * out which Scribble object is being dragged, and will initiate a drag on
 * that object.//w  ww  .j a v a2 s  . c  om
 */
public void dragGestureRecognized(DragGestureEvent e) {
    // Don't drag if we're not in drag mode
    if (!dragMode)
        return;

    // Figure out where the drag started
    MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent();
    int x = inputEvent.getX();
    int y = inputEvent.getY();

    // Figure out which scribble was clicked on, if any by creating a
    // small rectangle around the point and testing for intersection.
    Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2);
    int numScribbles = scribbles.size();
    for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles
        Scribble s = (Scribble) scribbles.get(i);
        if (s.intersects(r)) {
            // The user started the drag on top of this scribble, so
            // start to drag it.

            // First, remember which scribble is being dragged, so we can
            // delete it later (if this is a move rather than a copy)
            beingDragged = s;

            // Next, create a copy that will be the one dragged
            Scribble dragScribble = (Scribble) s.clone();
            // Adjust the origin to the point the user clicked on.
            dragScribble.translate(-x, -y);

            // Choose a cursor based on the type of drag the user initiated
            Cursor cursor;
            switch (e.getDragAction()) {
            case DnDConstants.ACTION_COPY:
                cursor = DragSource.DefaultCopyDrop;
                break;
            case DnDConstants.ACTION_MOVE:
                cursor = DragSource.DefaultMoveDrop;
                break;
            default:
                return; // We only support move and copys
            }

            // Some systems allow us to drag an image along with the
            // cursor. If so, create an image of the scribble to drag
            if (dragSource.isDragImageSupported()) {
                Rectangle scribbleBox = dragScribble.getBounds();
                Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height);
                Graphics2D g = (Graphics2D) dragImage.getGraphics();
                g.setColor(new Color(0, 0, 0, 0)); // transparent background
                g.fillRect(0, 0, scribbleBox.width, scribbleBox.height);
                g.setColor(Color.black);
                g.setStroke(linestyle);
                g.translate(-scribbleBox.x, -scribbleBox.y);
                g.draw(dragScribble);
                Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y);

                // Now start dragging, using the image.
                e.startDrag(cursor, dragImage, hotspot, dragScribble, this);
            } else {
                // Or start the drag without an image
                e.startDrag(cursor, dragScribble, this);
            }
            // After we've started dragging one scribble, stop looking
            return;
        }
    }
}

From source file:biz.wolschon.finance.jgnucash.accountProperties.AccountProperties.java

/**
 * @return a panel to edit the settings of this section
 *///from w  w  w . ja  v a  2  s.c  o  m
private JPanel getMySettingsPanel() {
    if (mySettingsPanel == null) {
        mySettingsPanel = new JPanel();

        mySettingsPanel.setLayout(new BorderLayout());
        myPropertySheet = new PropertySheetPanel();
        myPropertySheet.setToolBarVisible(true);
        myPropertySheet.setSorting(false);
        myPropertySheet.setMode(PropertySheetPanel.VIEW_AS_CATEGORIES);
        myPropertySheet.setDescriptionVisible(true);

        myPropertySheet.addPropertySheetChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent aEvt) {
                Object property = aEvt.getSource();
                if (property instanceof DefaultProperty) {
                    DefaultProperty prop = (DefaultProperty) property;
                    try {
                        myAccount.setUserDefinedAttribute(prop.getName(), prop.getValue().toString());
                    } catch (Exception e) {
                        LOGGER.error("error in writing userDefinedAttribute", e);
                    }
                }
            }

        });
        myPropertySheet.getTable().addMouseListener(new MouseAdapter() {

            /** show popup if mouseReleased is a popupTrigger on this platform.
             * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
             */
            @Override
            public void mouseReleased(final MouseEvent aE) {
                if (aE.isPopupTrigger()) {
                    JPopupMenu menu = getPropertyPopup();
                    menu.show(myPropertySheet, aE.getX(), aE.getY());
                }
                super.mouseClicked(aE);
            }

            /** show popup if mousePressed is a popupTrigger on this platform.
             * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
             */
            @Override
            public void mousePressed(final MouseEvent aE) {
                if (aE.isPopupTrigger()) {
                    JPopupMenu menu = getPropertyPopup();
                    menu.show(myPropertySheet, aE.getX(), aE.getY());
                }
                super.mouseClicked(aE);
            }

        });
        //
        updateCustomAttributesPanel();
        //        for (ConfigurationSetting setting : getConfigSection().getSettings()) {
        //            MyProperty myProperty = new MyProperty(setting);
        //            myProperty.addPropertyChangeListener(savingPropertyChangeListener);
        //            propertySheet.addProperty(myProperty);
        //        }
        mySettingsPanel.add(new JLabel("custom attributes:"), BorderLayout.NORTH);
        mySettingsPanel.add(myPropertySheet, BorderLayout.CENTER);
        mySettingsPanel.add(getAddCustomAttrPanel(), BorderLayout.SOUTH);

        //        MyPropertyEditorFactory propertyEditorFactory = new MyPropertyEditorFactory();
        //        propertySheet.setEditorFactory(propertyEditorFactory);
        //        propertySheet.setRendererFactory(propertyEditorFactory);

    }
    return mySettingsPanel;
}