Matte.java revision 8845:4be14673b9bf
1/* 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package build.tools.generatenimbus; 27 28import javax.xml.bind.annotation.XmlAttribute; 29 30class Matte extends Paint { 31 @XmlAttribute private int red; 32 @XmlAttribute private int green; 33 @XmlAttribute private int blue; 34 @XmlAttribute private int alpha; 35 36 @XmlAttribute private String uiDefaultParentName = null; 37 @XmlAttribute private float hueOffset = 0; 38 @XmlAttribute private float saturationOffset = 0; 39 @XmlAttribute private float brightnessOffset = 0; 40 @XmlAttribute private int alphaOffset = 0; 41 42 @XmlAttribute private String componentPropertyName = null; 43 public String getComponentPropertyName() { return componentPropertyName; } 44 45 @XmlAttribute private boolean uiResource = true; 46 47 public boolean isAbsolute() { 48 return uiDefaultParentName == null; 49 } 50 51 public String getDeclaration() { 52 if (isAbsolute()) { 53 return String.format("new Color(%d, %d, %d, %d)", 54 red, green, blue, alpha); 55 } else { 56 return String.format("decodeColor(\"%s\", %sf, %sf, %sf, %d)", 57 uiDefaultParentName, String.valueOf(hueOffset), 58 String.valueOf(saturationOffset), 59 String.valueOf(brightnessOffset), alphaOffset); 60 } 61 } 62 63 public String write() { 64 if (isAbsolute()) { 65 return String.format("%s, %s, %s, %s", red, green, blue, alpha); 66 } else { 67 String s = String.format("\"%s\", %sf, %sf, %sf, %d", 68 uiDefaultParentName, String.valueOf(hueOffset), 69 String.valueOf(saturationOffset), 70 String.valueOf(brightnessOffset), alphaOffset); 71 if (! uiResource) { 72 s += ", false"; 73 } 74 return s; 75 } 76 } 77 78 public ComponentColor createComponentColor(String variableName) { 79 return new ComponentColor(componentPropertyName, variableName, 80 saturationOffset, brightnessOffset, alphaOffset); 81 } 82} 83