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
028
029import javafx.beans.property.DoubleProperty;
030import javafx.beans.property.DoublePropertyBase;
031
032import com.sun.javafx.geom.QuadCurve2D;
033import com.sun.javafx.scene.DirtyBits;
034import com.sun.javafx.sg.PGNode;
035import com.sun.javafx.sg.PGQuadCurve;
036import com.sun.javafx.tk.Toolkit;
037import javafx.scene.paint.Paint;
038
039
040/**
041 * The {@code Quadcurve} class defines a quadratic Bézier parametric curve
042 * segment in (x,y) coordinate space. Drawing a curve that intersects both the
043 * specified coordinates {@code (startX, startY)} and {@code (endX, enfY)},
044 * using the specified point {@code (controlX, controlY)}
045 * as Bézier control point.
046 *
047<PRE>
048import javafx.scene.shape.*;
049
050QuadCurve quad = new QuadCurve();
051quad.setStartX(0.0f);
052quad.setStartY(50.0f);
053quad.setEndX(50.0f);
054quad.setEndY(50.0f);
055quad.setControlX(25.0f);
056quad.setControlY(0.0f);
057</PRE>
058 */
059public  class QuadCurve extends Shape {
060
061    private final QuadCurve2D shape = new QuadCurve2D();
062
063    /**
064     * Creates an empty instance of QuadCurve.
065     */
066    public QuadCurve() {
067    }
068
069    /**
070     * Creates a new instance of QuadCurve.
071     * @param startX the X coordinate of the start point
072     * @param startY the Y coordinate of the start point
073     * @param controlX the X coordinate of the control point
074     * @param controlY the Y coordinate of the control point
075     * @param endX the X coordinate of the end point
076     * @param endY the Y coordinate of the end point
077     */
078    public QuadCurve(double startX, double startY, double controlX, double controlY, double endX, double endY) {
079        setStartX(startX);
080        setStartY(startY);
081        setControlX(controlX);
082        setControlY(controlY);
083        setEndX(endX);
084        setEndY(endY);
085    }
086
087    /**
088     * Defines the X coordinate of the start point
089     * of the quadratic curve segment.
090     *
091     * @defaultValue 0.0
092     */
093    private DoubleProperty startX;
094
095    public final void setStartX(double value) {
096        if (startX != null || value != 0.0) {
097            startXProperty().set(value);
098        }
099    }
100
101    public final double getStartX() {
102        return startX == null ? 0.0 : startX.get();
103    }
104
105    public final DoubleProperty startXProperty() {
106        if (startX == null) {
107            startX = new DoublePropertyBase() {
108
109                @Override
110                public void invalidated() {
111                    impl_markDirty(DirtyBits.NODE_GEOMETRY);
112                    impl_geomChanged();
113                }
114
115                @Override
116                public Object getBean() {
117                    return QuadCurve.this;
118                }
119
120                @Override
121                public String getName() {
122                    return "startX";
123                }
124            };
125        }
126        return startX;
127    }
128
129    /**
130     * Defines the Y coordinate of the start point
131     * of the quadratic curve segment.
132     *
133     * @defaultValue 0.0
134     */
135    private DoubleProperty startY;
136
137    public final void setStartY(double value) {
138        if (startY != null || value != 0.0) {
139            startYProperty().set(value);
140        }
141    }
142
143    public final double getStartY() {
144        return startY == null ? 0.0 : startY.get();
145    }
146
147    public final DoubleProperty startYProperty() {
148        if (startY == null) {
149            startY = new DoublePropertyBase() {
150
151                @Override
152                public void invalidated() {
153                    impl_markDirty(DirtyBits.NODE_GEOMETRY);
154                    impl_geomChanged();
155                }
156
157                @Override
158                public Object getBean() {
159                    return QuadCurve.this;
160                }
161
162                @Override
163                public String getName() {
164                    return "startY";
165                }
166            };
167        }
168        return startY;
169    }
170
171    /**
172     * Defines the X coordinate of the control point
173     * of the quadratic curve segment.
174     *
175     * @defaultValue 0.0
176     */
177    private DoubleProperty controlX = new DoublePropertyBase() {
178
179        @Override
180        public void invalidated() {
181            impl_markDirty(DirtyBits.NODE_GEOMETRY);
182            impl_geomChanged();
183        }
184
185        @Override
186        public Object getBean() {
187            return QuadCurve.this;
188        }
189
190        @Override
191        public String getName() {
192            return "controlX";
193        }
194    };
195
196    public final void setControlX(double value) {
197        controlX.set(value);
198    }
199
200    public final double getControlX() {
201        return controlX.get();
202    }
203
204    public final DoubleProperty controlXProperty() {
205        return controlX;
206    }
207
208    /**
209     * Defines the Y coordinate of the control point
210     * of the quadratic curve segment.
211     *
212     * @defaultValue 0.0
213     */
214    private DoubleProperty controlY = new DoublePropertyBase() {
215
216        @Override
217        public void invalidated() {
218            impl_markDirty(DirtyBits.NODE_GEOMETRY);
219            impl_geomChanged();
220        }
221
222        @Override
223        public Object getBean() {
224            return QuadCurve.this;
225        }
226
227        @Override
228        public String getName() {
229            return "controlY";
230        }
231    };
232
233
234    public final void setControlY(double value) {
235        controlY.set(value);
236    }
237
238    public final double getControlY() {
239        return controlY.get();
240    }
241
242    public final DoubleProperty controlYProperty() {
243        return controlY;
244    }
245
246    /**
247     * Defines the X coordinate of the end point
248     * of the quadratic curve segment.
249     *
250     * @defaultValue 0.0
251     */
252    private DoubleProperty endX;
253
254
255    public final void setEndX(double value) {
256        if (endX != null || value != 0.0) {
257            endXProperty().set(value);
258        }
259    }
260
261    public final double getEndX() {
262        return endX == null ? 0.0 : endX.get();
263    }
264
265    public final DoubleProperty endXProperty() {
266        if (endX == null) {
267            endX = new DoublePropertyBase() {
268
269        @Override
270        public void invalidated() {
271            impl_markDirty(DirtyBits.NODE_GEOMETRY);
272            impl_geomChanged();
273        }
274
275        @Override
276        public Object getBean() {
277            return QuadCurve.this;
278        }
279
280        @Override
281        public String getName() {
282            return "endX";
283        }
284    };
285    }
286        return endX;
287    }
288
289    /**
290     * Defines the Y coordinate of the end point
291     * of the quadratic curve segment.
292     *
293     * @defaultValue 0.0
294     */
295    private DoubleProperty endY;
296
297    public final void setEndY(double value) {
298        if (endY != null || value != 0.0) {
299            endYProperty().set(value);
300        }
301    }
302
303    public final double getEndY() {
304        return endY == null ? 0.0 : endY.get();
305    }
306
307    public final DoubleProperty endYProperty() {
308        if (endY == null) {
309            endY = new DoublePropertyBase() {
310
311        @Override
312        public void invalidated() {
313            impl_markDirty(DirtyBits.NODE_GEOMETRY);
314            impl_geomChanged();
315        }
316
317        @Override
318        public Object getBean() {
319            return QuadCurve.this;
320        }
321
322        @Override
323        public String getName() {
324            return "endY";
325        }
326    };
327    }
328        return endY;
329    }
330
331    /**
332     * @treatAsPrivate implementation detail
333     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
334     */
335    @Deprecated
336    @Override
337    protected PGNode impl_createPGNode() {
338        return Toolkit.getToolkit().createPGQuadCurve();
339    }
340
341    PGQuadCurve getPGQuadCurve() {
342        return (PGQuadCurve)impl_getPGNode();
343    }
344
345    /**
346     * @treatAsPrivate implementation detail
347     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
348     */
349    @Deprecated
350    @Override
351        public QuadCurve2D impl_configShape() {
352        shape.x1 = (float)getStartX();
353        shape.y1 = (float)getStartY();
354        shape.ctrlx = (float)getControlX();
355        shape.ctrly = (float)getControlY();
356        shape.x2 = (float)getEndX();
357        shape.y2 = (float)getEndY();
358        return shape;
359    }
360
361    /**
362     * @treatAsPrivate implementation detail
363     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
364     */
365    @Deprecated
366    @Override
367    public void impl_updatePG() {
368        super.impl_updatePG();
369
370        if (impl_isDirty(DirtyBits.NODE_GEOMETRY)) {
371            PGQuadCurve peer = getPGQuadCurve();
372            peer.updateQuadCurve((float)getStartX(),
373                (float)getStartY(),
374                (float)getEndX(),
375                (float)getEndY(),
376                (float)getControlX(),
377                (float)getControlY());
378        }
379    }
380
381    /**
382     * Returns a string representation of this {@code QuadCurve} object.
383     * @return a string representation of this {@code QuadCurve} object.
384     */
385    @Override
386    public String toString() {
387        final StringBuilder sb = new StringBuilder("QuadCurve[");
388
389        String id = getId();
390        if (id != null) {
391            sb.append("id=").append(id).append(", ");
392        }
393
394        sb.append("startX=").append(getStartX());
395        sb.append(", startY=").append(getStartY());
396        sb.append(", controlX=").append(getControlX());
397        sb.append(", controlY=").append(getControlY());
398        sb.append(", endX=").append(getEndX());
399        sb.append(", endY=").append(getEndY());
400
401        sb.append(", fill=").append(getFill());
402
403        Paint stroke = getStroke();
404        if (stroke != null) {
405            sb.append(", stroke=").append(stroke);
406            sb.append(", strokeWidth=").append(getStrokeWidth());
407        }
408
409        return sb.append("]").toString();
410    }
411}
412