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.paint; 027 028import com.sun.javafx.beans.event.AbstractNotifyListener; 029import com.sun.javafx.tk.Toolkit; 030 031/** 032 * Base class for a color or gradients used to fill shapes and backgrounds when 033 * rendering the scene graph. 034 */ 035public abstract class Paint { 036 /** 037 * @treatAsPrivate implementation detail 038 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 039 */ 040 static { 041 Toolkit.setPaintAccessor(new Toolkit.PaintAccessor() { 042 043 @Override 044 public boolean isMutable(Paint paint) { 045 return paint.acc_isMutable(); 046 } 047 048 @Override 049 public Object getPlatformPaint(Paint paint) { 050 return paint.acc_getPlatformPaint(); 051 } 052 053 @Override 054 public void addListener(Paint paint, AbstractNotifyListener platformChangeListener) { 055 paint.acc_addListener(platformChangeListener); 056 } 057 058 @Override 059 public void removeListener(Paint paint, AbstractNotifyListener platformChangeListener) { 060 paint.acc_removeListener(platformChangeListener); 061 } 062 063 064 }); 065 } 066 067 boolean acc_isMutable() { 068 return false; 069 } 070 071 abstract Object acc_getPlatformPaint(); 072 073 void acc_addListener(AbstractNotifyListener platformChangeListener) { 074 throw new UnsupportedOperationException("Not Supported."); 075 } 076 077 void acc_removeListener(AbstractNotifyListener platformChangeListener) { 078 throw new UnsupportedOperationException("Not Supported."); 079 } 080 081 /** 082 * Gets whether this Paint is completely opaque. An opaque paint is one that 083 * has no alpha component in any of its colors. It may be possible for a Paint 084 * to be opaque and yet return false, if it cannot be easily determined 085 * whether the paint is actually opaque. For example, the ImagePattern may not 086 * be able to cheaply determine its opacity. 087 * 088 * @return true if the Paint is opaque, false if it is not opaque or if 089 * it cannot be determined. 090 */ 091 public abstract boolean isOpaque(); 092 093 /** 094 * Creates a paint value from a string representation. Recognizes strings 095 * representing {@code Color}, {@code RadialGradient} or {@code LinearGradient}. 096 * String specifying LinearGradient must begin with linear-gradient keyword 097 * and string specifying RadialGradient must begin with radial-gradient. 098 * 099 * @param value the string to convert 100 * @throws NullPointerException if {@code value} is {@code null} 101 * @throws IllegalArgumentException if {@code value} cannot be parsed 102 * @return a {@code Color}, {@code RadialGradient} or {@code LinearGradient} 103 * object holding the value represented by the string argument. 104 * 105 * @see Color#valueOf(String) 106 * @see LinearGradient#valueOf(String) 107 * @see RadialGradient#valueOf(String) 108 */ 109 public static Paint valueOf(String value) { 110 if (value == null) { 111 throw new NullPointerException("paint must be specified"); 112 } 113 114 if (value.startsWith("linear-gradient(")) { 115 return LinearGradient.valueOf(value); 116 } else if (value.startsWith("radial-gradient(")) { 117 return RadialGradient.valueOf(value); 118 } else { 119 return Color.valueOf(value); 120 } 121 } 122}