Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/generatenimbus/UIState.java
32287 views
/*1* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.generatenimbus;2627import java.util.Arrays;28import java.util.Collections;29import java.util.Iterator;30import java.util.List;3132import javax.xml.bind.annotation.XmlAttribute;33import javax.xml.bind.annotation.XmlElement;3435class UIState {36@XmlAttribute private String stateKeys;37public String getStateKeys() { return stateKeys; }3839/** Indicates whether to invert the meaning of the 9-square stretching insets */40@XmlAttribute private boolean inverted;4142/** A cached string representing the list of stateKeys deliminated with "+" */43private String cachedName = null;4445@XmlElement private Canvas canvas;46public Canvas getCanvas() { return canvas; }4748@XmlElement private UIStyle style;49public UIStyle getStyle() { return style; }5051public boolean hasCanvas() {52return ! canvas.isBlank();53}5455public static List<String> stringToKeys(String keysString) {56return Arrays.asList(keysString.split("\\+"));57}5859public String getName() {60if (cachedName == null) {61StringBuilder buf = new StringBuilder();62List<String> keys = stringToKeys(stateKeys);63Collections.sort(keys);64for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {65buf.append(iter.next());66if (iter.hasNext()) {67buf.append('+');68}69}70cachedName = buf.toString();71}72return cachedName;73}7475public void write(StringBuilder sb, String prefix, String pkg, String fileNamePrefix, String painterPrefix) {76String statePrefix = prefix + "[" + getName() + "]";77// write state style78sb.append(style.write(statePrefix + '.'));79// write painter80if (hasCanvas()) {81writeLazyPainter(sb, statePrefix, pkg, fileNamePrefix, painterPrefix);82}83}8485private void writeLazyPainter(StringBuilder sb, String statePrefix, String packageNamePrefix, String fileNamePrefix, String painterPrefix) {86String cacheModeString = "AbstractRegionPainter.PaintContext.CacheMode." + style.getCacheMode();87String stateConstant = Utils.statesToConstantName(painterPrefix + "_" + stateKeys);88sb.append(String.format(89" d.put(\"%s.%sPainter\", new LazyPainter(\"%s.%s\", %s.%s, %s, %s, %b, %s, %s, %s));\n",90statePrefix, painterPrefix, packageNamePrefix, fileNamePrefix,91fileNamePrefix, stateConstant, canvas.getStretchingInsets().write(false),92canvas.getSize().write(false), inverted, cacheModeString,93Utils.formatDouble(style.getMaxHozCachedImgScaling()),94Utils.formatDouble(style.getMaxVertCachedImgScaling())));95}96}979899