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 a horizontal line path element from the current point to x. 037 * 038 * <p>For more information on path elements see the {@link Path} and 039 * {@link PathElement} classes. 040 * 041 * <p>Example: 042 * 043<PRE> 044import javafx.scene.shape.*; 045 046Path path = new Path(); 047path.getElements().add(new MoveTo(0.0f, 0.0f)); 048path.getElements().add(new HLineTo(80.0f)); 049</PRE> 050 */ 051public class HLineTo extends PathElement { 052 053 /** 054 * Creates an empty instance of HLineTo. 055 */ 056 public HLineTo() { 057 } 058 059 /** 060 * Creates an instance of HLineTo. 061 * @param x the horizontal coordinate to line to 062 */ 063 public HLineTo(double x) { 064 setX(x); 065 } 066 067 /** 068 * Defines the X coordinate. 069 * 070 * @defaultValue 0.0 071 */ 072 private DoubleProperty x = new DoublePropertyBase() { 073 074 @Override 075 public void invalidated() { 076 u(); 077 } 078 079 @Override 080 public Object getBean() { 081 return HLineTo.this; 082 } 083 084 @Override 085 public String getName() { 086 return "x"; 087 } 088 }; 089 090 091 public final void setX(double value) { 092 x.set(value); 093 } 094 095 public final double getX() { 096 return x.get(); 097 } 098 099 public final DoubleProperty xProperty() { 100 return x; 101 } 102 103 @Override 104 void addTo(PGPath pgPath) { 105 if (isAbsolute()) { 106 pgPath.addLineTo((float)getX(), pgPath.getCurrentY()); 107 } else { 108 pgPath.addLineTo((float)(pgPath.getCurrentX() + getX()), pgPath.getCurrentY()); 109 } 110 } 111 112 /** 113 * @treatAsPrivate implementation detail 114 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 115 */ 116 @Deprecated 117 @Override 118 public void impl_addTo(Path2D path) { 119 if (isAbsolute()) { 120 path.lineTo((float)getX(), path.getCurrentY()); 121 } else { 122 path.lineTo((float)(path.getCurrentX() + getX()), path.getCurrentY()); 123 } 124 } 125 126 /** 127 * Returns a string representation of this {@code HLineTo} object. 128 * @return a string representation of this {@code HLineTo} object. 129 */ 130 @Override 131 public String toString() { 132 final StringBuilder sb = new StringBuilder("HLineTo["); 133 sb.append("x=").append(getX()); 134 return sb.append("]").toString(); 135 } 136} 137