Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.scene.shape;
027
028import javafx.beans.property.DoubleProperty;
029import javafx.beans.property.DoublePropertyBase;
030
031import com.sun.javafx.geom.Path2D;
032import com.sun.javafx.sg.PGPath;
033
034
035/**
036 * Creates an addition to the path by moving to the specified
037 * coordinates.
038 *
039 * <p>For more information on path elements see the {@link Path} and
040 * {@link PathElement} classes.
041 *
042 * <p>Example:
043 *
044<PRE>
045import javafx.scene.shape.*;
046
047Path path = new Path();
048path.getElements().add(new MoveTo(0.0f, 0.0f));
049path.getElements().add(new LineTo(100.0f, 100.0f));
050</PRE>
051 */
052public class MoveTo extends PathElement {
053
054    /**
055     * Creates an empty instance of MoveTo.
056     */
057    public MoveTo() {
058    }
059
060    /**
061     * Creates a new instance of MoveTo.
062     * @param x the horizontal coordinate to move to
063     * @param y the vertical coordinate to move to
064     */
065    public MoveTo(double x, double y) {
066        setX(x);
067        setY(y);
068    }
069
070    /**
071     * Defines the specified X coordinate.
072     *
073     * @defaultValue 0.0
074     */
075    private DoubleProperty x;
076
077    public final void setX(double value) {
078        if (x != null || value != 0.0) {
079            xProperty().set(value);
080        }
081    }
082
083    public final double getX() {
084        return x == null ? 0.0 : x.get();
085    }
086
087    public final DoubleProperty xProperty() {
088        if (x == null) {
089            x = new DoublePropertyBase() {
090
091                @Override
092                public void invalidated() {
093                    u();
094                }
095
096                @Override
097                public Object getBean() {
098                    return MoveTo.this;
099                }
100
101                @Override
102                public String getName() {
103                    return "x";
104                }
105            };
106        }
107        return x;
108    }
109
110    /**
111     * Defines the specified Y coordinate.
112     *
113     * @defaultValue 0.0
114     */
115    private DoubleProperty y;
116
117    public final void setY(double value) {
118        if (y != null || value != 0.0) {
119            yProperty().set(value);
120        }
121    }
122
123    public final double getY() {
124        return y == null ? 0.0 : y.get();
125    }
126
127    public final DoubleProperty yProperty() {
128        if (y == null) {
129            y = new DoublePropertyBase() {
130
131                @Override
132                public void invalidated() {
133                    u();
134                }
135
136                @Override
137                public Object getBean() {
138                    return MoveTo.this;
139                }
140
141                @Override
142                public String getName() {
143                    return "y";
144                }
145            };
146        }
147        return y;
148    }
149
150    @Override
151    void addTo(PGPath pgPath) {
152        if (isAbsolute()) {
153            pgPath.addMoveTo((float)getX(), (float)getY());
154        } else {
155            pgPath.addMoveTo((float)(pgPath.getCurrentX() + getX()),
156                             (float)(pgPath.getCurrentY() + getY()));
157        }
158    }
159
160    /**
161     * @treatAsPrivate implementation detail
162     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
163     */
164    @Deprecated
165    @Override
166    public void impl_addTo(Path2D path) {
167        if (isAbsolute()) {
168            path.moveTo((float)getX(), (float)getY());
169        } else {
170            path.moveTo((float)(path.getCurrentX() + getX()),
171                        (float)(path.getCurrentY() + getY()));
172        }
173    }
174
175    /**
176     * Returns a string representation of this {@code MoveTo} object.
177     * @return a string representation of this {@code MoveTo} object.
178     */
179    @Override
180    public String toString() {
181        final StringBuilder sb = new StringBuilder("MoveTo[");
182        sb.append("x=").append(getX());
183        sb.append(", y=").append(getY());
184        return sb.append("]").toString();
185    }
186}
187