Example usage for java.awt.geom Point2D getX

List of usage examples for java.awt.geom Point2D getX

Introduction

In this page you can find the example usage for java.awt.geom Point2D getX.

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mousePressed(MouseEvent e) {
    if (selectedTextWrapper != null && getCursor() == Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)) {
        Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
        if (screenRect.contains(e.getX(), e.getY())) {

            double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(),
                    getChart());// ww  w.  j  a  v  a2s. c o m
            double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(),
                    0);
            //         Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            Point2D point = new Point2D.Double(screenX, screenY);
            if (point != null) {
                this.textMovePoint = point;
            }
        } else {
            this.textMovePoint = null;
        }
    } else {
        super.mousePressed(e);
    }
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Translates a Java2D point on the chart to a screen location.
 * /*from   w ww  .  j  a va2  s .  c om*/
 * @param java2DPoint
 *            the Java2D point.
 * @return The screen location.
 */
public Point translateJava2DToScreen(Point2D java2DPoint) {
    Insets insets = getInsets();
    int x = (int) (java2DPoint.getX() * this.scaleX + insets.left);
    int y = (int) (java2DPoint.getY() * this.scaleY + insets.top);
    return new Point(x, y);
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mouseMoved(MouseEvent e) {
    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (selectedTextWrapper == null && isMaskingEnabled()) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else {// ww w. j  a v a2s .  c o m
        Cursor newCursor = defaultCursor;
        if (selectedTextWrapper != null) {
            Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                    new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                    getScreenDataArea(), getChart());
            Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                    selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
            if (screenRect.contains(e.getX(), e.getY())) {
                newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
            }
        }
        if (newCursor != getCursor()) {
            setCursor(newCursor);
        }
    }
    Line2D oldSelection = selectedMarker;
    findSelectedMarker(e.getPoint());
    if (selectedMarker != oldSelection) {
        repaint();
    }
}

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

/**
 * Finds the chart entity at the given co-ordinates. If the co-ordinates are
 * not within a given entity scrolls down(vertical plot) or left(plot
 * horizontal) until it is within the entity or outside the plot area.
 * /*w  w  w .j a  va2s . co m*/
 * @param x
 * @param y
 * @return The entity at the co-ordinates. Returns null if no entity found
 */
private ChartEntity getEntityForLocation(double x, double y) {
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            ChartEntity entity = null;
            Rectangle rect = getScreenDataArea();

            int count = 0;
            // //logger.debug(rect.x + "," + rect.y +"," + rect.width + ","
            // + rect.height);

            Point2D javaPoint = translateScreenToJava2D(new Point(rect.x, rect.y));
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                while (entity == null && x > javaPoint.getX()) {
                    entity = entities.getEntity(x, y);

                    // if(entity!=null)
                    // //logger.debug("found in " + count + " attempts");

                    x--;
                    count++;
                }
            } else {
                while (entity == null && y < (javaPoint.getY() + (rect.height * scaleY))) {
                    entity = entities.getEntity(x, y);

                    // if(entity!=null)
                    // //logger.debug("found in " + count + " attempts");

                    y++;
                    count++;
                }
            }
            return entity;
        }
    }
    return null;
}

From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java

private static Point2D llis(Point2D l1p1, Point2D l1p2, Point2D l2p1, Point2D l2p2) {
    double l1x1 = l1p1.getX();
    double l1x2 = l1p2.getX();
    if (l1x2 < l1x1) {
        l1x1 = l1x2;//from   www . j  av a 2  s .  c o  m
        l1x2 = l1p1.getX();
    }
    double l1y1 = l1p1.getY();
    double l1y2 = l1p2.getY();
    if (l1y2 < l1y1) {
        l1y1 = l1y2;
        l1y2 = l1p1.getY();
    }
    double l2x1 = l2p1.getX();
    double l2x2 = l2p2.getX();
    if (l2x2 < l2x1) {
        l2x1 = l2x2;
        l2x2 = l2p1.getX();
    }
    double l2y1 = l2p1.getY();
    double l2y2 = l2p2.getY();
    if (l2y2 < l2y1) {
        l2y1 = l2y2;
        l2y2 = l2p1.getY();
    }
    Point2D ip = llip(l1p1, l1p2, l2p1, l2p2);
    double ipx = ip.getX();
    double ipy = ip.getY();
    double tol = 1e-6;
    if (Math.abs(l1x1 - l1x2) < tol) {
        ipx = l1x1;
    } else if (Math.abs(l2x1 - l2x2) < tol) {
        ipx = l2x1;
    }
    if (Math.abs(l1y1 - l1y2) < tol) {
        ipy = l1y1;
    } else if (Math.abs(l2y1 - l2y2) < tol) {
        ipy = l2y1;
    }
    if (ipx >= l1x1 && ipx <= l1x2 && ipx >= l2x1 && ipx <= l2x2 && ipy >= l1y1 && ipy <= l1y2 && ipy >= l2y1
            && ipy <= l2y2) {
        return ip;
    } else {
        return null;
    }
}

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

@Override
public void mouseDragged(MouseEvent e) {
    Insets insets = getInsets();//  w ww.  ja  v a 2s.c om
    int x = (int) ((e.getX() - insets.left) / getScaleX());
    int y = (int) ((e.getY() - insets.top) / getScaleY());

    ChartEntity entity = null;
    EntityCollection entities = null;
    if (getChartRenderingInfo() != null) {
        entities = getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
            //                boolean isDirty = false;
            int seriesIndex = -1;
            if (selectedSeriesIndex >= 0) {
                //                   double xInChart = ChartMaskingUtilities.translateScreenX(x, 
                //                         getScreenDataArea(), getChart());
                //                   XYDataset dataset = getChart().getXYPlot().getDataset();
                //                   PatternDataset patternDataset = (PatternDataset) dataset;
                //                   int itemIndex = patternDataset.getItemFromX(selectedSeriesIndex, xInChart);
                //                   if (itemIndex < patternDataset.getItemCount(selectedSeriesIndex)) {
                //                      chartX = patternDataset.getXValue(selectedSeriesIndex, itemIndex);
                //                      chartY = patternDataset.getYValue(selectedSeriesIndex, itemIndex);
                //                      Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(
                //                            new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                      horizontalTraceLocation = (int) axisTrace.getX();
                //                      verticalTraceLocation = (int) axisTrace.getY();
                //                      seriesIndex = selectedSeriesIndex;
                //                      isDirty = true;
                //                   }
                seriesIndex = followDomainTrace(selectedSeriesIndex, x);
            } else if (getChart().getXYPlot().getSeriesCount() == 1) {
                //                   int seriesIndex0 = 0;
                //                   double xInChart = ChartMaskingUtilities.translateScreenX(x, 
                //                         getScreenDataArea(), getChart());
                //                   XYDataset dataset = getChart().getXYPlot().getDataset();
                //                   PatternDataset patternDataset = (PatternDataset) dataset;
                //                   int itemIndex = patternDataset.getItemFromX(seriesIndex0, xInChart);
                //                   if (itemIndex < patternDataset.getItemCount(seriesIndex0)) {
                //                      chartX = patternDataset.getXValue(seriesIndex0, itemIndex);
                //                      chartY = patternDataset.getYValue(seriesIndex0, itemIndex);
                //                      Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(
                //                            new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                      horizontalTraceLocation = (int) axisTrace.getX();
                //                      verticalTraceLocation = (int) axisTrace.getY();
                //                      seriesIndex = seriesIndex0;
                //                      isDirty = true;
                //                   }
                seriesIndex = followDomainTrace(0, x);
            } else if (entity instanceof XYItemEntity) {
                XYItemEntity xyEntity = (XYItemEntity) entity;
                XYDataset dataset = xyEntity.getDataset();
                int item = ((XYItemEntity) entity).getItem();
                seriesIndex = xyEntity.getSeriesIndex();
                double chartX = dataset.getXValue(seriesIndex, item);
                double chartY = dataset.getYValue(seriesIndex, item);
                Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                        new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                setChartX(chartX);
                setChartY(chartY);
                setSeriesIndex(seriesIndex);
                setItemIndex(item);
                if (dataset instanceof IXYErrorDataset) {
                    setChartError(((IXYErrorDataset) dataset).getYError(seriesIndex, item));

                }
                if (getHorizontalAxisTrace()) {
                    setHorizontalTraceLocation((int) screenPoint.getX());
                }
                if (getVerticalAxisTrace()) {
                    setVerticalTraceLocation((int) screenPoint.getY());
                }
                //                   isDirty = true;
            }
            if (seriesIndex >= 0) {
                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);
                    }
                }
            }

        }
    }

    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) == 0) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else if (getCursor() != defaultCursor) {
        setCursor(defaultCursor);
    }

    if (isInternalLegendEnabled && isInternalLegendSelected
            && findCursorOnSelectedItem(e.getX(), e.getY()) != Cursor.DEFAULT_CURSOR
            && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        changeInternalLegend(e);
    } else if (getMaskDragIndicator() != Cursor.DEFAULT_CURSOR && this.getSelectedMask() != null
            && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        changeSelectedMask(e);
    } else if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
        // Do masking service
        // if no initial masking point was set, ignore dragging...
        makeNewMask(e);
    } else {
        super.mouseDragged(e);
    }
}

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

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

    ChartEntity entity = null;
    if (getChartRenderingInfo() != null) {
        EntityCollection entities = getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
            //                   boolean isDirty = false;
            int seriesIndex = -1;
            if (selectedSeriesIndex >= 0) {
                //                      double xInChart = ChartMaskingUtilities.translateScreenX(x, 
                //                            getScreenDataArea(), getChart());
                //                      XYDataset dataset = getChart().getXYPlot().getDataset();
                //                      PatternDataset patternDataset = (PatternDataset) dataset;
                //                      int itemIndex = patternDataset.getItemFromX(selectedSeriesIndex, xInChart);
                //                      if (itemIndex < patternDataset.getItemCount(selectedSeriesIndex)) {
                //                         chartX = patternDataset.getXValue(selectedSeriesIndex, itemIndex);
                //                         chartY = patternDataset.getYValue(selectedSeriesIndex, itemIndex);
                //                         Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(
                //                               new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                         horizontalTraceLocation = (int) axisTrace.getX();
                //                         verticalTraceLocation = (int) axisTrace.getY();
                //                         if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) {
                //                            repaint();
                //                         }
                //                         seriesIndex = selectedSeriesIndex;
                //                         isDirty = true;
                //                      }
                seriesIndex = followDomainTrace(selectedSeriesIndex, x);
                if (seriesIndex >= 0
                        && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) {
                    repaint();
                }
            } else if (getChart().getXYPlot().getSeriesCount() == 1) {
                //                      int seriesIndex0 = 0;
                //                      double xInChart = ChartMaskingUtilities.translateScreenX(x, 
                //                            getScreenDataArea(), getChart());
                //                      XYDataset dataset = getChart().getXYPlot().getDataset();
                //                      PatternDataset patternDataset = (PatternDataset) dataset;
                //                      int itemIndex = patternDataset.getItemFromX(seriesIndex0, xInChart);
                //                      if (itemIndex < patternDataset.getItemCount(seriesIndex0)) {
                //                         chartX = patternDataset.getXValue(seriesIndex0, itemIndex);
                //                         chartY = patternDataset.getYValue(seriesIndex0, itemIndex);
                //                         Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(
                //                               new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                ////                         if (getScreenDataArea().contains(axisTrace)) {
                //                         horizontalTraceLocation = (int) axisTrace.getX();
                //                         verticalTraceLocation = (int) axisTrace.getY();
                //                         if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) {
                //                            repaint();
                //                         }
                //                         seriesIndex = seriesIndex0;
                //                         isDirty = true;
                ////                         }
                //                      }
                seriesIndex = followDomainTrace(0, x);
                if (seriesIndex >= 0
                        && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) {
                    repaint();
                }
            } else if (entity instanceof XYItemEntity) {
                XYItemEntity xyEntity = (XYItemEntity) entity;
                XYDataset dataset = xyEntity.getDataset();
                int item = ((XYItemEntity) entity).getItem();
                seriesIndex = xyEntity.getSeriesIndex();
                double chartX = dataset.getXValue(seriesIndex, item);
                double chartY = dataset.getYValue(seriesIndex, item);
                Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                        new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                setChartX(chartX);
                setChartY(chartY);
                setSeriesIndex(seriesIndex);
                setItemIndex(item);
                if (dataset instanceof IXYErrorDataset) {
                    setChartError(((IXYErrorDataset) dataset).getYError(seriesIndex, item));

                }
                if (getHorizontalAxisTrace()) {
                    setHorizontalTraceLocation((int) screenPoint.getX());
                }
                if (getVerticalAxisTrace()) {
                    setVerticalTraceLocation((int) screenPoint.getY());
                }
                if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled()) {
                    repaint();
                }
                //                      isDirty = true;
            }
            if (seriesIndex >= 0) {
                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);
                    }
                }
            }

        }
        //              getChart().handleClick(x, y, getChartRenderingInfo());
    }

    if (isInternalLegendEnabled && isInternalLegendSelected) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else if (getCursor() != defaultCursor) {
        setCursor(defaultCursor);
    }

    super.mouseMoved(e);
    // we can only generate events if the panel's chart is not null
    // (see bug report 1556951)
}

From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java

private static Point2D llip(Point2D l1p1, Point2D l1p2, Point2D l2p1, Point2D l2p2) {
    // Line between l1p1 and l1p2
    double a1 = l1p2.getY() - l1p1.getY();
    double b1 = l1p1.getX() - l1p2.getX();
    double c1 = a1 * l1p1.getX() + b1 * l1p1.getY();

    // Line between l2p1 and l2p2
    double a2 = l2p2.getY() - l2p1.getY();
    double b2 = l2p1.getX() - l2p2.getX();
    double c2 = a2 * l2p1.getX() + b2 * l2p1.getY();

    // Intersection point
    double det = a1 * b2 - a2 * b1;
    double x = (b2 * c1 - b1 * c2) / det;
    double y = (a1 * c2 - a2 * c1) / det;

    return new Point2D.Double(x, y);
}

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

public void mouseDown(MouseEvent event) {

    Point2D javaPoint = translateScreenToJava2D(new Point(event.x, event.y));
    Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
    if (scaledDataArea == null)
        return;// w  w  w .  jav  a 2s .  c  o  m

    // new entity code
    ChartEntity entity = getEntityForLocation(javaPoint.getX(), javaPoint.getY());
    if (entity != null)
        logger.debug("Entity Bounds:" + entity.getArea().getBounds());

    // logger.debug("----------END------------");

    if (event.button == 1) {
        // Init zoom point only if CTRL key is down.
        if ((event.stateMask & SWT.CONTROL) != 0) {
            this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        } else {
            clearSelection(false, false);
            this.selectionPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        }
    }

    this.anchor = javaPoint;
    this.chart.setNotify(true); // force a redraw
    this.canvas.redraw();

    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    // pass mouse down event if some ChartMouseListener are listening
    java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    if ((e.getModifiers() & InputEvent.ALT_MASK) != 0) {
        double xNew = ChartMaskingUtilities.translateScreenX(e.getX(), getScreenDataArea(), getChart());
        double yNew = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(), 0);
        addMarker(xNew, yNew, null);//ww w  .j  a va  2 s .  com
    } else if (isTextInputEnabled) {
        if (!textInputFlag) {
            boolean newTextEnabled = selectedTextWrapper == null;
            if (selectedTextWrapper != null) {
                Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                        new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                        getScreenDataArea(), getChart());
                Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                        selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
                if (screenRect.contains(e.getX(), e.getY())) {
                    Point2D point = e.getPoint();
                    String inputText = textContentMap.get(selectedTextWrapper);
                    if (inputText == null) {
                        inputText = "";
                    }
                    String[] lines = inputText.split("\n", 100);
                    int cursorX = 0;
                    int charCount = 0;
                    int maxWidth = 0;
                    int pickX = -1;
                    FontMetrics fm = getGraphics().getFontMetrics();
                    for (int i = 0; i < lines.length; i++) {
                        int lineWidth = fm.stringWidth(lines[i]);
                        if (lineWidth > maxWidth) {
                            maxWidth = lineWidth;
                        }
                    }
                    if (maxWidth < 100) {
                        maxWidth = 100;
                    }
                    Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                            new Point2D.Double(selectedTextWrapper.getX(), selectedTextWrapper.getY()),
                            getScreenDataArea(), getChart());
                    if (point.getX() <= screenPoint.getX() + 11 + maxWidth
                            && point.getY() <= screenPoint.getY() + lines.length * 15 - 15) {
                        textInputPoint = screenPoint;
                        textInputContent = inputText;
                        textInputFlag = true;
                        textContentMap.remove(selectedTextWrapper);
                        selectedTextWrapper = null;
                        textInputCursorIndex = 0;
                        for (int i = 0; i < lines.length; i++) {
                            if (point.getY() > screenPoint.getY() + i * 15 - 15
                                    && point.getY() <= screenPoint.getY() + i * 15) {
                                cursorX = fm.stringWidth(lines[i]);
                                if (point.getX() >= screenPoint.getX()
                                        && point.getX() <= screenPoint.getX() + 3 + cursorX) {
                                    if (point.getX() >= screenPoint.getX()
                                            && point.getX() < screenPoint.getX() + 3) {
                                        pickX = 0;
                                    }
                                    double lastEnd = screenPoint.getX() + 3;
                                    for (int j = 0; j < lines[i].length(); j++) {
                                        int size = fm.stringWidth(lines[i].substring(0, j + 1));
                                        double newEnd = screenPoint.getX() + 3 + size;
                                        if (point.getX() >= lastEnd
                                                && point.getX() < lastEnd + (newEnd - lastEnd) / 2) {
                                            pickX = j;
                                        } else if (point.getX() >= lastEnd + (newEnd - lastEnd) / 2
                                                && point.getX() < newEnd) {
                                            pickX = j + 1;
                                        }
                                        lastEnd = newEnd;
                                    }
                                    if (pickX >= 0) {
                                        textInputCursorIndex = charCount + pickX;
                                    }
                                } else {
                                    textInputCursorIndex = charCount + lines[i].length();
                                }
                                break;
                            }
                            charCount += lines[i].length() + 1;
                        }
                    }
                }
            }
            selectText(e.getX(), e.getY());
            if (selectedTextWrapper == null && !textInputFlag && newTextEnabled
                    && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                textInputFlag = true;
                textInputPoint = e.getPoint();
            }
        } else {
            Point2D point = e.getPoint();
            boolean finishInput = false;
            //            if (point.getX() < textInputPoint.getX() || point.getY() < textInputPoint.getY() - 15) {
            //               finishInput = true;
            //            } else {
            String inputText = textInputContent;
            if (inputText == null) {
                inputText = "";
            }
            String[] lines = inputText.split("\n", 100);
            int cursorX = 0;
            int charCount = 0;
            int maxWidth = 0;
            int pickX = -1;
            FontMetrics fm = getGraphics().getFontMetrics();
            for (int i = 0; i < lines.length; i++) {
                int lineWidth = fm.stringWidth(lines[i]);
                if (lineWidth > maxWidth) {
                    maxWidth = lineWidth;
                }
            }
            if (maxWidth < 100) {
                maxWidth = 100;
            }
            if (point.getX() > textInputPoint.getX() + 11 + maxWidth
                    || point.getY() > textInputPoint.getY() + lines.length * 15 - 15
                    || point.getX() < textInputPoint.getX() || point.getY() < textInputPoint.getY() - 15) {
                finishInput = true;
            } else {
                for (int i = 0; i < lines.length; i++) {
                    if (point.getY() > textInputPoint.getY() + i * 15 - 15
                            && point.getY() <= textInputPoint.getY() + i * 15) {
                        cursorX = fm.stringWidth(lines[i]);
                        if (point.getX() >= textInputPoint.getX()
                                && point.getX() <= textInputPoint.getX() + 3 + cursorX) {
                            if (point.getX() >= textInputPoint.getX()
                                    && point.getX() < textInputPoint.getX() + 3) {
                                pickX = 0;
                            }
                            double lastEnd = textInputPoint.getX() + 3;
                            for (int j = 0; j < lines[i].length(); j++) {
                                int size = fm.stringWidth(lines[i].substring(0, j + 1));
                                double newEnd = textInputPoint.getX() + 3 + size;
                                if (point.getX() >= lastEnd
                                        && point.getX() < lastEnd + (newEnd - lastEnd) / 2) {
                                    pickX = j;
                                } else if (point.getX() >= lastEnd + (newEnd - lastEnd) / 2
                                        && point.getX() < newEnd) {
                                    pickX = j + 1;
                                }
                                lastEnd = newEnd;
                            }
                            if (pickX >= 0) {
                                textInputCursorIndex = charCount + pickX;
                            }
                        } else {
                            textInputCursorIndex = charCount + lines[i].length();
                        }
                        break;
                    }
                    charCount += lines[i].length() + 1;
                }
            }
            //            }

            if (finishInput) {
                if (textInputContent != null && textInputContent.length() > 0) {
                    double xNew = ChartMaskingUtilities.translateScreenX(textInputPoint.getX(),
                            getScreenDataArea(), getChart());
                    double yNew = ChartMaskingUtilities.translateScreenY(textInputPoint.getY(),
                            getScreenDataArea(), getChart(), 0);
                    textContentMap.put(new Rectangle2D.Double(xNew, yNew, maxWidth, lines.length * 15),
                            textInputContent);
                }
                textInputContent = null;
                textInputCursorIndex = 0;
                textInputFlag = false;
            }
        }
    }
}