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.CubicCurve2D; 032import com.sun.javafx.scene.DirtyBits; 033import com.sun.javafx.sg.PGCubicCurve; 034import com.sun.javafx.sg.PGNode; 035import com.sun.javafx.tk.Toolkit; 036import javafx.scene.paint.Paint; 037 038 039/** 040 * <p>The {@code CubiCurve} class defines a cubic Bézier parametric curve segment 041 * in (x,y) coordinate space. Drawing a curve that intersects both the specified 042 * coordinates {@code (startX, startY)} and {@code (endX, enfY)}, using the 043 * specified points {@code (controlX1, controlY1)} and {@code (controlX2, controlY2)} 044 * as Bézier control points. 045 * Example:</p> 046 * 047<PRE> 048import javafx.scene.shape.*; 049 050CubicCurve cubic = new CubicCurve(); 051cubic.setStartX(0.0f); 052cubic.setStartY(50.0f); 053cubic.setControlX1(25.0f); 054cubic.setControlY1(0.0f); 055cubic.setControlX2(75.0f); 056cubic.setControlY2(100.0f); 057cubic.setEndX(100.0f); 058cubic.setEndY(50.0f); 059} 060</PRE> 061 */ 062public class CubicCurve extends Shape { 063 064 private final CubicCurve2D shape = new CubicCurve2D(); 065 /** 066 * Defines the X coordinate of the start point of the cubic curve segment. 067 * 068 * @defaultValue 0.0 069 */ 070 private DoubleProperty startX; 071 072 /** 073 * Creates an empty instance of CubicCurve. 074 */ 075 public CubicCurve() { 076 } 077 078 /** 079 * Creates a new instance of CubicCurve. 080 * @param startX the X coordinate of the start point 081 * @param startY the Y coordinate of the start point 082 * @param controlX1 the X coordinate of the first control point 083 * @param controlY1 the Y coordinate of the first control point 084 * @param controlX2 the X coordinate of the second control point 085 * @param controlY2 the Y coordinate of the second control point 086 * @param endX the X coordinate of the end point 087 * @param endY the Y coordinate of the end point 088 */ 089 public CubicCurve(double startX, double startY, double controlX1, 090 double controlY1, double controlX2, double controlY2, 091 double endX, double endY) { 092 setStartX(startX); 093 setStartY(startY); 094 setControlX1(controlX1); 095 setControlY1(controlY1); 096 setControlX2(controlX2); 097 setControlY2(controlY2); 098 setEndX(endX); 099 setEndY(endY); 100 } 101 102 public final void setStartX(double value) { 103 if (startX != null || value != 0.0) { 104 startXProperty().set(value); 105 } 106 } 107 108 public final double getStartX() { 109 return startX == null ? 0.0 : startX.get(); 110 } 111 112 public final DoubleProperty startXProperty() { 113 if (startX == null) { 114 startX = new DoublePropertyBase() { 115 116 @Override 117 public void invalidated() { 118 impl_markDirty(DirtyBits.NODE_GEOMETRY); 119 impl_geomChanged(); 120 } 121 122 @Override 123 public Object getBean() { 124 return CubicCurve.this; 125 } 126 127 @Override 128 public String getName() { 129 return "startX"; 130 } 131 }; 132 } 133 return startX; 134 } 135 136 /** 137 * Defines the Y coordinate of the start point of the cubic curve segment. 138 * 139 * @defaultValue 0.0 140 */ 141 private DoubleProperty startY; 142 143 public final void setStartY(double value) { 144 if (startY != null || value != 0.0) { 145 startYProperty().set(value); 146 } 147 } 148 149 public final double getStartY() { 150 return startY == null ? 0.0 : startY.get(); 151 } 152 153 public final DoubleProperty startYProperty() { 154 if (startY == null) { 155 startY = new DoublePropertyBase() { 156 157 @Override 158 public void invalidated() { 159 impl_markDirty(DirtyBits.NODE_GEOMETRY); 160 impl_geomChanged(); 161 } 162 163 @Override 164 public Object getBean() { 165 return CubicCurve.this; 166 } 167 168 @Override 169 public String getName() { 170 return "startY"; 171 } 172 }; 173 } 174 return startY; 175 } 176 177 /** 178 * Defines the X coordinate of the first control point 179 * of the cubic curve segment. 180 * 181 * @defaultValue 0.0 182 */ 183 private DoubleProperty controlX1; 184 185 public final void setControlX1(double value) { 186 if (controlX1 != null || value != 0.0) { 187 controlX1Property().set(value); 188 } 189 } 190 191 public final double getControlX1() { 192 return controlX1 == null ? 0.0 : controlX1.get(); 193 } 194 195 public final DoubleProperty controlX1Property() { 196 if (controlX1 == null) { 197 controlX1 = new DoublePropertyBase() { 198 199 @Override 200 public void invalidated() { 201 impl_markDirty(DirtyBits.NODE_GEOMETRY); 202 impl_geomChanged(); 203 } 204 205 @Override 206 public Object getBean() { 207 return CubicCurve.this; 208 } 209 210 @Override 211 public String getName() { 212 return "controlX1"; 213 } 214 }; 215 } 216 return controlX1; 217 } 218 219 /** 220 * Defines the Y coordinate of the first control point 221 * of the cubic curve segment. 222 * 223 * @defaultValue 0.0 224 */ 225 private DoubleProperty controlY1; 226 227 public final void setControlY1(double value) { 228 if (controlY1 != null || value != 0.0) { 229 controlY1Property().set(value); 230 } 231 } 232 233 public final double getControlY1() { 234 return controlY1 == null ? 0.0 : controlY1.get(); 235 } 236 237 public final DoubleProperty controlY1Property() { 238 if (controlY1 == null) { 239 controlY1 = new DoublePropertyBase() { 240 241 @Override 242 public void invalidated() { 243 impl_markDirty(DirtyBits.NODE_GEOMETRY); 244 impl_geomChanged(); 245 } 246 247 @Override 248 public Object getBean() { 249 return CubicCurve.this; 250 } 251 252 @Override 253 public String getName() { 254 return "controlY1"; 255 } 256 }; 257 } 258 return controlY1; 259 } 260 261 /** 262 * Defines the X coordinate of the second control point 263 * of the cubic curve segment. 264 * 265 * @defaultValue 0.0 266 */ 267 private DoubleProperty controlX2; 268 269 public final void setControlX2(double value) { 270 if (controlX2 != null || value != 0.0) { 271 controlX2Property().set(value); 272 } 273 } 274 275 public final double getControlX2() { 276 return controlX2 == null ? 0.0 : controlX2.get(); 277 } 278 279 public final DoubleProperty controlX2Property() { 280 if (controlX2 == null) { 281 controlX2 = new DoublePropertyBase() { 282 283 @Override 284 public void invalidated() { 285 impl_markDirty(DirtyBits.NODE_GEOMETRY); 286 impl_geomChanged(); 287 } 288 289 @Override 290 public Object getBean() { 291 return CubicCurve.this; 292 } 293 294 @Override 295 public String getName() { 296 return "controlX2"; 297 } 298 }; 299 } 300 return controlX2; 301 } 302 303 /** 304 * Defines the Y coordinate of the second control point 305 * of the cubic curve segment. 306 * 307 * @defaultValue 0.0 308 */ 309 private DoubleProperty controlY2; 310 311 public final void setControlY2(double value) { 312 if (controlY2 != null || value != 0.0) { 313 controlY2Property().set(value); 314 } 315 } 316 317 public final double getControlY2() { 318 return controlY2 == null ? 0.0 : controlY2.get(); 319 } 320 321 public final DoubleProperty controlY2Property() { 322 if (controlY2 == null) { 323 controlY2 = new DoublePropertyBase() { 324 325 @Override 326 public void invalidated() { 327 impl_markDirty(DirtyBits.NODE_GEOMETRY); 328 impl_geomChanged(); 329 } 330 331 @Override 332 public Object getBean() { 333 return CubicCurve.this; 334 } 335 336 @Override 337 public String getName() { 338 return "controlY2"; 339 } 340 }; 341 } 342 return controlY2; 343 } 344 345 /** 346 * Defines the X coordinate of the end point of the cubic curve segment. 347 * 348 * @defaultValue 0.0 349 */ 350 private DoubleProperty endX; 351 352 public final void setEndX(double value) { 353 if (endX != null || value != 0.0) { 354 endXProperty().set(value); 355 } 356 } 357 358 public final double getEndX() { 359 return endX == null ? 0.0 : endX.get(); 360 } 361 362 public final DoubleProperty endXProperty() { 363 if (endX == null) { 364 endX = new DoublePropertyBase() { 365 366 @Override 367 public void invalidated() { 368 impl_markDirty(DirtyBits.NODE_GEOMETRY); 369 impl_geomChanged(); 370 } 371 372 @Override 373 public Object getBean() { 374 return CubicCurve.this; 375 } 376 377 @Override 378 public String getName() { 379 return "endX"; 380 } 381 }; 382 } 383 return endX; 384 } 385 386 /** 387 * Defines the Y coordinate of the end point of the cubic curve segment. 388 * 389 * @defaultValue 0.0 390 */ 391 private DoubleProperty endY; 392 393 public final void setEndY(double value) { 394 if (endY != null || value != 0.0) { 395 endYProperty().set(value); 396 } 397 } 398 399 public final double getEndY() { 400 return endY == null ? 0.0 : endY.get(); 401 } 402 403 public final DoubleProperty endYProperty() { 404 if (endY == null) { 405 endY = new DoublePropertyBase() { 406 407 @Override 408 public void invalidated() { 409 impl_markDirty(DirtyBits.NODE_GEOMETRY); 410 impl_geomChanged(); 411 } 412 413 @Override 414 public Object getBean() { 415 return CubicCurve.this; 416 } 417 418 @Override 419 public String getName() { 420 return "endY"; 421 } 422 }; 423 } 424 return endY; 425 } 426 427 /** 428 * @treatAsPrivate implementation detail 429 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 430 */ 431 @Deprecated 432 @Override public CubicCurve2D impl_configShape() { 433 shape.x1 = (float)getStartX(); 434 shape.y1 = (float)getStartY(); 435 shape.ctrlx1 = (float)getControlX1(); 436 shape.ctrly1 = (float)getControlY1(); 437 shape.ctrlx2 = (float)getControlX2(); 438 shape.ctrly2 = (float)getControlY2(); 439 shape.x2 = (float)getEndX(); 440 shape.y2 = (float)getEndY(); 441 return shape; 442 } 443 444 /** 445 * @treatAsPrivate implementation detail 446 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 447 */ 448 @Deprecated 449 @Override protected PGNode impl_createPGNode() { 450 return Toolkit.getToolkit().createPGCubicCurve(); 451 } 452 453 PGCubicCurve getPGCubicCurve() { 454 return (PGCubicCurve)impl_getPGNode(); 455 } 456 457 /** 458 * @treatAsPrivate implementation detail 459 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 460 */ 461 @Deprecated 462 @Override public void impl_updatePG() { 463 super.impl_updatePG(); 464 465 if (impl_isDirty(DirtyBits.NODE_GEOMETRY)) { 466 PGCubicCurve peer = getPGCubicCurve(); 467 peer.updateCubicCurve((float)getStartX(), 468 (float)getStartY(), 469 (float)getEndX(), 470 (float)getEndY(), 471 (float)getControlX1(), 472 (float)getControlY1(), 473 (float)getControlX2(), 474 (float)getControlY2()); 475 } 476 } 477 478 /** 479 * Returns a string representation of this {@code CubicCurve} object. 480 * @return a string representation of this {@code CubicCurve} object. 481 */ 482 @Override 483 public String toString() { 484 final StringBuilder sb = new StringBuilder("CubicCurve["); 485 486 String id = getId(); 487 if (id != null) { 488 sb.append("id=").append(id).append(", "); 489 } 490 491 sb.append("startX=").append(getStartX()); 492 sb.append(", startY=").append(getStartY()); 493 sb.append(", controlX1=").append(getControlX1()); 494 sb.append(", controlY1=").append(getControlY1()); 495 sb.append(", controlX2=").append(getControlX2()); 496 sb.append(", controlY2=").append(getControlY2()); 497 sb.append(", endX=").append(getEndX()); 498 sb.append(", endY=").append(getEndY()); 499 500 sb.append(", fill=").append(getFill()); 501 502 Paint stroke = getStroke(); 503 if (stroke != null) { 504 sb.append(", stroke=").append(stroke); 505 sb.append(", strokeWidth=").append(getStrokeWidth()); 506 } 507 508 return sb.append("]").toString(); 509 } 510} 511