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; 030import javafx.beans.property.ObjectProperty; 031import javafx.beans.property.ObjectPropertyBase; 032 033import com.sun.javafx.geom.Arc2D; 034import com.sun.javafx.scene.DirtyBits; 035import com.sun.javafx.sg.PGArc; 036import com.sun.javafx.sg.PGNode; 037import com.sun.javafx.tk.Toolkit; 038import javafx.scene.paint.Paint; 039 040 041/** 042 * The {@code Arc} class represents a 2D arc object, defined by a center point, 043 * start angle (in degrees), angular extent (length of the arc in degrees), 044 * and an arc type ({@link ArcType#OPEN}, {@link ArcType#CHORD}, 045 * or {@link ArcType#ROUND}). 046 * 047 * <p>Example usage: the following code creates an Arc which is centered around 048 * 50,50, has a radius of 25 and extends from the angle 45 to the angle 315 049 * (270 degrees long), and is round. 050 * 051<PRE> 052import javafx.scene.shape.*; 053 054Arc arc = new Arc(); 055arc.setCenterX(50.0f); 056arc.setCenterY(50.0f); 057arc.setRadiusX(25.0f); 058arc.setRadiusY(25.0f); 059arc.setStartAngle(45.0f); 060arc.setLength(270.0f); 061arc.setType(ArcType.ROUND); 062</PRE> 063 */ 064public class Arc extends Shape { 065 066 private final Arc2D shape = new Arc2D(); 067 068 static com.sun.javafx.sg.PGArc.ArcType toPGArcType(ArcType type) { 069 switch (type) { 070 case OPEN: 071 return PGArc.ArcType.OPEN; 072 case CHORD: 073 return PGArc.ArcType.CHORD; 074 default: 075 return PGArc.ArcType.ROUND; 076 } 077 } 078 079 /** 080 * Creates an empty instance of Arc. 081 */ 082 public Arc() { 083 } 084 085 /** 086 * Creates a new instance of Arc. 087 * @param centerX the X coordinate of the center point of the arc 088 * @param centerY the Y coordinate of the center point of the arc 089 * @param radiusX the overall width (horizontal radius) of the full ellipse 090 * of which this arc is a partial section 091 * @param radiusY the overall height (vertical radius) of the full ellipse 092 * of which this arc is a partial section 093 * @param startAngle the starting angle of the arc in degrees 094 * @param length the angular extent of the arc in degrees 095 */ 096 public Arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length) { 097 setCenterX(centerX); 098 setCenterY(centerY); 099 setRadiusX(radiusX); 100 setRadiusY(radiusY); 101 setStartAngle(startAngle); 102 setLength(length); 103 } 104 105 /** 106 * Defines the X coordinate of the center point of the arc. 107 * 108 * @defaultValue 0.0 109 */ 110 private DoubleProperty centerX; 111 112 public final void setCenterX(double value) { 113 if (centerX != null || value != 0.0) { 114 centerXProperty().set(value); 115 } 116 } 117 118 public final double getCenterX() { 119 return centerX == null ? 0.0 : centerX.get(); 120 } 121 122 public final DoubleProperty centerXProperty() { 123 if (centerX == null) { 124 centerX = new DoublePropertyBase() { 125 126 @Override 127 public void invalidated() { 128 impl_markDirty(DirtyBits.NODE_GEOMETRY); 129 impl_geomChanged(); 130 } 131 132 @Override 133 public Object getBean() { 134 return Arc.this; 135 } 136 137 @Override 138 public String getName() { 139 return "centerX"; 140 } 141 }; 142 } 143 return centerX; 144 } 145 146 /** 147 * Defines the Y coordinate of the center point of the arc. 148 * 149 * @defaultValue 0.0 150 */ 151 private DoubleProperty centerY; 152 153 public final void setCenterY(double value) { 154 if (centerY != null || value != 0.0) { 155 centerYProperty().set(value); 156 } 157 } 158 159 public final double getCenterY() { 160 return centerY == null ? 0.0 : centerY.get(); 161 } 162 163 public final DoubleProperty centerYProperty() { 164 if (centerY == null) { 165 centerY = new DoublePropertyBase() { 166 167 @Override 168 public void invalidated() { 169 impl_markDirty(DirtyBits.NODE_GEOMETRY); 170 impl_geomChanged(); 171 } 172 173 @Override 174 public Object getBean() { 175 return Arc.this; 176 } 177 178 @Override 179 public String getName() { 180 return "centerY"; 181 } 182 }; 183 } 184 return centerY; 185 } 186 187 /** 188 * Defines the overall width (horizontal radius) of the full ellipse 189 * of which this arc is a partial section. 190 * 191 * @defaultValue 0.0 192 */ 193 private DoubleProperty radiusX = new DoublePropertyBase() { 194 195 @Override 196 public void invalidated() { 197 impl_markDirty(DirtyBits.NODE_GEOMETRY); 198 impl_geomChanged(); 199 } 200 201 @Override 202 public Object getBean() { 203 return Arc.this; 204 } 205 206 @Override 207 public String getName() { 208 return "radiusX"; 209 } 210 }; 211 212 public final void setRadiusX(double value) { 213 radiusX.set(value); 214 } 215 216 public final double getRadiusX() { 217 return radiusX.get(); 218 } 219 220 public final DoubleProperty radiusXProperty() { 221 return radiusX; 222 } 223 224 /** 225 * Defines the overall height (vertical radius) of the full ellipse 226 * of which this arc is a partial section. 227 * 228 * @defaultValue 0.0 229 */ 230 private DoubleProperty radiusY = new DoublePropertyBase() { 231 232 @Override 233 public void invalidated() { 234 impl_markDirty(DirtyBits.NODE_GEOMETRY); 235 impl_geomChanged(); 236 } 237 238 @Override 239 public Object getBean() { 240 return Arc.this; 241 } 242 243 @Override 244 public String getName() { 245 return "radiusY"; 246 } 247 }; 248 249 public final void setRadiusY(double value) { 250 radiusY.set(value); 251 } 252 253 public final double getRadiusY() { 254 return radiusY.get(); 255 } 256 257 public final DoubleProperty radiusYProperty() { 258 return radiusY; 259 } 260 261 /** 262 * Defines the starting angle of the arc in degrees. 263 * 264 * @defaultValue 0.0 265 */ 266 private DoubleProperty startAngle; 267 268 public final void setStartAngle(double value) { 269 if (startAngle != null || value != 0.0) { 270 startAngleProperty().set(value); 271 } 272 } 273 274 public final double getStartAngle() { 275 return startAngle == null ? 0.0 : startAngle.get(); 276 } 277 278 public final DoubleProperty startAngleProperty() { 279 if (startAngle == null) { 280 startAngle = new DoublePropertyBase() { 281 282 @Override 283 public void invalidated() { 284 impl_markDirty(DirtyBits.NODE_GEOMETRY); 285 impl_geomChanged(); 286 } 287 288 @Override 289 public Object getBean() { 290 return Arc.this; 291 } 292 293 @Override 294 public String getName() { 295 return "startAngle"; 296 } 297 }; 298 } 299 return startAngle; 300 } 301 302 /** 303 * Defines the angular extent of the arc in degrees. 304 * 305 * @defaultValue 0.0 306 */ 307 private DoubleProperty length = new DoublePropertyBase() { 308 309 @Override 310 public void invalidated() { 311 impl_markDirty(DirtyBits.NODE_GEOMETRY); 312 impl_geomChanged(); 313 } 314 315 @Override 316 public Object getBean() { 317 return Arc.this; 318 } 319 320 @Override 321 public String getName() { 322 return "length"; 323 } 324 }; 325 326 public final void setLength(double value) { 327 length.set(value); 328 } 329 330 public final double getLength() { 331 return length.get(); 332 } 333 334 public final DoubleProperty lengthProperty() { 335 return length; 336 } 337 338 /** 339 * Defines the closure type for the arc: 340 * {@link ArcType#OPEN}, {@link ArcType#CHORD},or {@link ArcType#ROUND}. 341 * 342 * @defaultValue OPEN 343 */ 344 private ObjectProperty<ArcType> type; 345 346 347 348 public final void setType(ArcType value) { 349 if (type != null || value != ArcType.OPEN) { 350 typeProperty().set(value); 351 } 352 } 353 354 public final ArcType getType() { 355 return type == null ? ArcType.OPEN : type.get(); 356 } 357 358 public final ObjectProperty<ArcType> typeProperty() { 359 if (type == null) { 360 type = new ObjectPropertyBase<ArcType>(ArcType.OPEN) { 361 362 @Override 363 public void invalidated() { 364 impl_markDirty(DirtyBits.NODE_GEOMETRY); 365 impl_geomChanged(); 366 } 367 368 @Override 369 public Object getBean() { 370 return Arc.this; 371 } 372 373 @Override 374 public String getName() { 375 return "type"; 376 } 377 }; 378 } 379 return type; 380 } 381 382 /** 383 * @treatAsPrivate implementation detail 384 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 385 */ 386 @Deprecated 387 @Override protected PGNode impl_createPGNode() { 388 return Toolkit.getToolkit().createPGArc(); 389 } 390 391 PGArc getPGArc() { 392 return (PGArc) impl_getPGNode(); 393 } 394 395 /** 396 * @treatAsPrivate implementation detail 397 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 398 */ 399 @Deprecated 400 @Override public Arc2D impl_configShape() { 401 short tmpType; 402 switch (getTypeInternal()) { 403 case OPEN: 404 tmpType = 0; 405 break; 406 case CHORD: 407 tmpType = 1; 408 break; 409 default: 410 tmpType = 2; 411 break; 412 } 413 414 shape.setArc( 415 (float)(getCenterX() - getRadiusX()), // x 416 (float)(getCenterY() - getRadiusY()), // y 417 (float)(getRadiusX() * 2.0), // w 418 (float)(getRadiusY() * 2.0), // h 419 (float)getStartAngle(), 420 (float)getLength(), 421 tmpType); 422 423 return shape; 424 } 425 426 public final ArcType getTypeInternal() { 427 ArcType t = getType(); 428 return t == null ? ArcType.OPEN : t; 429 } 430 431 /** 432 * @treatAsPrivate implementation detail 433 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 434 */ 435 @Deprecated 436 @Override public void impl_updatePG() { 437 super.impl_updatePG(); 438 439 if (impl_isDirty(DirtyBits.NODE_GEOMETRY)) { 440 PGArc peer = getPGArc(); 441 peer.updateArc((float)getCenterX(), 442 (float)getCenterY(), 443 (float)getRadiusX(), 444 (float)getRadiusY(), 445 (float)getStartAngle(), 446 (float)getLength(), 447 toPGArcType(getTypeInternal())); 448 } 449 } 450 451 /** 452 * Returns a string representation of this {@code Arc} object. 453 * @return a string representation of this {@code Arc} object. 454 */ 455 @Override 456 public String toString() { 457 final StringBuilder sb = new StringBuilder("Arc["); 458 459 String id = getId(); 460 if (id != null) { 461 sb.append("id=").append(id).append(", "); 462 } 463 464 sb.append("centerX=").append(getCenterX()); 465 sb.append(", centerY=").append(getCenterY()); 466 sb.append(", radiusX=").append(getRadiusX()); 467 sb.append(", radiusY=").append(getRadiusY()); 468 sb.append(", startAngle=").append(getStartAngle()); 469 sb.append(", length=").append(getLength()); 470 sb.append(", type=").append(getType()); 471 472 sb.append(", fill=").append(getFill()); 473 474 Paint stroke = getStroke(); 475 if (stroke != null) { 476 sb.append(", stroke=").append(stroke); 477 sb.append(", strokeWidth=").append(getStrokeWidth()); 478 } 479 480 return sb.append("]").toString(); 481 } 482}