Search in sources :

Example 31 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class Tile method pointPosition.

/**
 * Returns the x, y point of the given coordinate relative to this tile
 * @param point a coordinate to translate to x, y
 * @return a Point object relative to this tile
 */
public Point pointPosition(Coord point) {
    int x = position(dimension.getWidth(), point.getLongitude(), bbox.getSouthWest().getLongitude(), bbox.getNorthEast().getLongitude());
    int y = position(dimension.getHeight(), point.getLatitude(), bbox.getSouthWest().getLatitude(), bbox.getNorthEast().getLatitude());
    // 
    return new Point(x, dimension.getHeight() - y);
}
Also used : Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 32 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class PointsLayer method removePoint.

/**
 * Removes a point from the PointsLayer
 *
 * @param point to remove from the PointsLayer
 */
public void removePoint(PointLayer point) {
    if (!point.isProjected()) {
        Coord c = getProjection().fromWGS84(point);
        point.setLatitude(c.getLatitude());
        point.setLongitude(c.getLongitude());
        point.setProjected(true);
    }
    points.removeElement(point);
}
Also used : Coord(com.codename1.maps.Coord)

Example 33 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class Dialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param c the context component which is used to position the dialog and can also be pointed at
 * @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
 */
public Command showPopupDialog(Component c) {
    Rectangle componentPos = c.getSelectedRect();
    componentPos.setX(componentPos.getX() - c.getScrollX());
    componentPos.setY(componentPos.getY() - c.getScrollY());
    return showPopupDialog(componentPos);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 34 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class ResetableTextWatcher method showTextEditorAgain.

/**
 * Shows the native text field again after it has been hidden in async edit mode.
 */
private void showTextEditorAgain() {
    if (!mIsEditing || !isTextEditorHidden()) {
        return;
    }
    textEditorHidden = false;
    final TextArea ta = mEditText.mTextArea;
    // changed since the native aread was hidden.
    synchronized (this) {
        inputBuffer = new ArrayList<TextChange>();
    }
    // We are probably not on the EDT.  We need to be on the EDT to
    // safely get text from the textarea for synchronization.
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            // and the editing text area hasn't changed since we issued this call.
            if (mIsEditing && mEditText != null && mEditText.mTextArea == ta) {
                final String text = ta.getText();
                final int cursorPos = ta.getCursorPosition();
                // Now that we have our text from the CN1 text area, we need to be on the
                // Android UI thread in order to set the text of the native text editor.
                impl.getActivity().runOnUiThread(new Runnable() {

                    public void run() {
                        // and the editing text area hasn't changed since we issued this call.
                        if (mIsEditing && mEditText != null && mEditText.mTextArea == ta) {
                            // so that we don't find it in an inconsistent state.
                            synchronized (InPlaceEditView.this) {
                                // Let's record the cursor positions of the native
                                // text editor in case we need to use them after synchronizing
                                // with the CN1 textarea.
                                int start = cursorPos;
                                int end = cursorPos;
                                /*
                                    if (!inputBuffer.isEmpty()) {
                                        // If the input buffer isn't empty, then our start
                                        // and end positions will be "wonky"
                                        start = end = inputBuffer.get(0).atPos;

                                        // If the first change was a delete, then the atPos
                                        // will point to the beginning of the deleted section
                                        // so we need to adjust the end point to be *after*
                                        // the deleted section to begin.
                                        if (inputBuffer.get(0).deleteLength > 0) {
                                            end = start = end + inputBuffer.get(0).deleteLength;
                                        }
                                    }
                                    */
                                StringBuilder buf = new StringBuilder();
                                buf.append(text);
                                // Loop through any pending changes in the input buffer
                                // (I.e. key strokes that have occurred since we initiated
                                // this async callback hell!!)
                                List<TextChange> tinput = inputBuffer;
                                if (tinput != null) {
                                    for (TextChange change : tinput) {
                                        // end.
                                        if (change.textToAppend != null) {
                                            if (end >= 0 && end <= buf.length()) {
                                                buf.insert(end, change.textToAppend);
                                                end += change.textToAppend.length();
                                                start = end;
                                            } else {
                                                buf.append(change.textToAppend);
                                                end = buf.length();
                                                start = end;
                                            }
                                        } else // The change is "deleted" text.
                                        if (change.deleteLength > 0) {
                                            if (end >= change.deleteLength && end <= buf.length()) {
                                                buf.delete(end - change.deleteLength, end);
                                                end -= change.deleteLength;
                                                start = end;
                                            } else if (end > 0 && end < change.deleteLength) {
                                                buf.delete(0, end);
                                                end = 0;
                                                start = end;
                                            }
                                        }
                                    }
                                }
                                // Important:  Clear the input buffer so that the TextWatcher
                                // knows to stop filling it up.  We only need the inputBuffer
                                // to keep input between the original showTextEditorAgain() call
                                // and here.
                                inputBuffer = null;
                                mEditText.setText(buf.toString());
                                if (start < 0 || start > mEditText.getText().length()) {
                                    start = mEditText.getText().length();
                                }
                                if (end < 0 || end > mEditText.getText().length()) {
                                    end = mEditText.getText().length();
                                }
                                // Update the caret in the edit text field so we can continue.
                                mEditText.setSelection(start, end);
                            }
                        }
                    }
                });
            }
        }
    });
    reLayoutEdit(true);
    repaintTextEditor(true);
}
Also used : TextArea(com.codename1.ui.TextArea) Paint(android.graphics.Paint)

Example 35 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class ChartComponent method pointerDragged.

@Override
public void pointerDragged(int[] x, int[] y) {
    if (x.length > 1) {
        if (!zoomEnabled) {
            super.pointerDragged(x, y);
            return;
        }
        // Pinch zoom
        if (chart instanceof XYChart) {
            XYChart xyChart = (XYChart) chart;
            double[] panLimits = xyChart.getRenderer().getPanLimits();
            if (zoomStart == null) {
                zoomStart = new Point((x[0] + x[1]) / 2, (y[0] + y[1]) / 2);
                zoomDistStartX = Math.abs(x[0] - x[1]);
                zoomDistStartY = Math.abs(y[0] - y[1]);
                zoomStartBBox = getBBox();
                if (initialZoomBBox == null) {
                    initialZoomBBox = zoomStartBBox.translateScreenCoords(0, 0);
                }
            } else {
                int dx = Math.abs(x[0] - x[1]);
                int dy = Math.abs(y[0] - y[1]);
                if (dx == 0)
                    dx = 1;
                if (dy == 0)
                    dy = 1;
                double zoomX = zoomDistStartX / dx;
                double zoomY = zoomDistStartY / dy;
                BBox newBounds = zoomStartBBox.scaleScreenCoords((float) zoomX, (float) zoomY);
                double minX = newBounds.minX;
                double minY = newBounds.minY;
                double maxX = newBounds.maxX;
                double maxY = newBounds.maxY;
                if (panLimits != null) {
                    // Make sure that this zoom doesn't exceed the maxZoomIn value
                    if (minX < panLimits[0]) {
                        maxX = maxX + panLimits[0] - minX;
                        minX = panLimits[0];
                    }
                    if (minY < panLimits[2]) {
                        maxY = maxY + panLimits[2] - minY;
                        minY = panLimits[2];
                    }
                    if (maxX > panLimits[1]) {
                        minX = minX + panLimits[1] - maxX;
                        maxX = panLimits[1];
                    }
                    if (maxY > panLimits[3]) {
                        minY = minY + panLimits[3] - maxY;
                        maxY = panLimits[3];
                    }
                }
                double[] zoomLimits = xyChart.getRenderer().getZoomLimits();
                if (zoomLimits != null && zoomLimits[0] != 0) {
                    if (maxX - minX < zoomLimits[0]) {
                        maxX = xyChart.getRenderer().getXAxisMax();
                        minX = xyChart.getRenderer().getXAxisMin();
                    }
                }
                if (zoomLimits != null && zoomLimits[1] != 0) {
                    if (maxX - minX > zoomLimits[1]) {
                        maxX = xyChart.getRenderer().getXAxisMax();
                        minX = xyChart.getRenderer().getXAxisMin();
                    }
                }
                if (zoomLimits != null && zoomLimits[2] != 0) {
                    if (maxY - minY < zoomLimits[2]) {
                        maxY = xyChart.getRenderer().getYAxisMax();
                        minY = xyChart.getRenderer().getYAxisMin();
                    }
                }
                if (zoomLimits != null && zoomLimits[3] != 0) {
                    if (maxY - minY > zoomLimits[3]) {
                        maxY = xyChart.getRenderer().getYAxisMax();
                        minY = xyChart.getRenderer().getYAxisMin();
                    }
                }
                if (!xyChart.getRenderer().isZoomXEnabled()) {
                    minX = xyChart.getRenderer().getXAxisMin();
                    maxX = xyChart.getRenderer().getXAxisMax();
                }
                if (!xyChart.getRenderer().isZoomYEnabled()) {
                    minY = xyChart.getRenderer().getYAxisMin();
                    maxY = xyChart.getRenderer().getYAxisMax();
                }
                xyChart.getRenderer().setRange(new double[] { minX, maxX, minY, maxY });
                chartBoundsChanged();
                this.repaint();
            }
        } else {
            if (zoomStart == null) {
                zoomStart = new Point((x[0] + x[1]) / 2, (y[0] + y[1]) / 2);
                zoomTransformStart = Transform.makeIdentity();
                if (transform != null) {
                    zoomTransformStart.concatenate(transform);
                }
                int dx = Math.abs(x[0] - x[1]) / 2;
                int dy = Math.abs(y[0] - y[1]) / 2;
                zoomDistStart = Math.sqrt(dx * dx + dy * dy);
            } else {
                int dx = Math.abs(x[0] - x[1]) / 2;
                int dy = Math.abs(y[0] - y[1]) / 2;
                double zoomDist = Math.sqrt(dx * dx + dy * dy);
                if (zoomDist == 0) {
                    zoomDist = 1;
                }
                transform = Transform.makeIdentity();
                transform.translate(zoomStart.getX(), zoomStart.getY());
                transform.scale((float) (zoomDist / zoomDistStart), (float) (zoomDist / zoomDistStart));
                transform.translate(-zoomStart.getX(), -zoomStart.getY());
                transform.concatenate(zoomTransformStart);
                this.repaint();
            }
        }
    } else {
        if (!isPanEnabled()) {
            super.pointerDragged(x, y);
            return;
        }
        if (chart instanceof XYChart) {
            XYChart xyChart = (XYChart) chart;
            double[] panLimits = xyChart.getRenderer().getPanLimits();
            if (dragStartBBox == null) {
                dragStart = new Point(x[0], y[0]);
                dragStartBBox = getBBox();
            } else {
                float tx = x[0] - dragStart.getX();
                float ty = y[0] - dragStart.getY();
                BBox newBounds = dragStartBBox.translateScreenCoords(-tx, ty);
                double minX = newBounds.minX;
                double minY = newBounds.minY;
                double maxX = newBounds.maxX;
                double maxY = newBounds.maxY;
                if (panLimits != null) {
                    if (minX < panLimits[0]) {
                        maxX = maxX + panLimits[0] - minX;
                        minX = panLimits[0];
                    }
                    if (minY < panLimits[2]) {
                        maxY = maxY + panLimits[2] - minY;
                        minY = panLimits[2];
                    }
                    if (maxX > panLimits[1]) {
                        minX = minX + panLimits[1] - maxX;
                        maxX = panLimits[1];
                    }
                    if (maxY > panLimits[3]) {
                        minY = minY + panLimits[3] - maxY;
                        maxY = panLimits[3];
                    }
                }
                if (!xyChart.getRenderer().isPanXEnabled()) {
                    minX = xyChart.getRenderer().getXAxisMin();
                    maxX = xyChart.getRenderer().getXAxisMax();
                }
                if (!xyChart.getRenderer().isPanYEnabled()) {
                    minY = xyChart.getRenderer().getYAxisMin();
                    maxY = xyChart.getRenderer().getYAxisMax();
                }
                xyChart.getRenderer().setRange(new double[] { minX, maxX, minY, maxY });
                chartBoundsChanged();
            }
        } else {
            if (dragStart == null) {
                dragStart = new Point(x[0], y[0]);
                dragTransformStart = Transform.makeIdentity();
                if (transform != null) {
                    dragTransformStart.concatenate(transform);
                }
            } else {
                transform = Transform.makeIdentity();
                transform.translate(x[0] - dragStart.getX(), y[0] - dragStart.getY());
                transform.concatenate(dragTransformStart);
                this.repaint();
            }
        }
    }
    // To change body of generated methods, choose Tools | Templates.
    super.pointerDragged(x, y);
}
Also used : XYChart(com.codename1.charts.views.XYChart) Point(com.codename1.charts.models.Point) Point(com.codename1.charts.models.Point)

Aggregations

Point (com.codename1.ui.geom.Point)11 Point (com.codename1.charts.models.Point)10 Coord (com.codename1.maps.Coord)9 Paint (com.codename1.charts.compat.Paint)7 Component (com.codename1.ui.Component)5 TextArea (com.codename1.ui.TextArea)3 Dimension (com.codename1.ui.geom.Dimension)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Rectangle (com.codename1.ui.geom.Rectangle)3 Border (com.codename1.ui.plaf.Border)3 ArrayList (java.util.ArrayList)3 SeriesSelection (com.codename1.charts.models.SeriesSelection)2 Container (com.codename1.ui.Container)2 EncodedImage (com.codename1.ui.EncodedImage)2 Form (com.codename1.ui.Form)2 Image (com.codename1.ui.Image)2 Label (com.codename1.ui.Label)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 Style (com.codename1.ui.plaf.Style)2