author | vlivanov |
Thu, 18 Jan 2018 02:25:18 +0300 | |
changeset 48596 | 860326263d1f |
parent 47389 | 18c850407be9 |
permissions | -rw-r--r-- |
3742 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21805
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
3742 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
3742 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3742 | 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 |
* |
|
5506 | 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. |
|
3742 | 24 |
*/ |
25 |
||
26 |
package build.tools.generatenimbus; |
|
27 |
||
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
28 |
import javax.xml.stream.XMLStreamException; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
29 |
import javax.xml.stream.XMLStreamReader; |
3742 | 30 |
import java.util.ArrayList; |
31 |
import java.util.List; |
|
32 |
||
33 |
class UIStyle { |
|
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
34 |
|
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
35 |
public enum CacheMode { |
3742 | 36 |
NO_CACHING, FIXED_SIZES, NINE_SQUARE_SCALE |
37 |
} |
|
38 |
||
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
39 |
private UIColor textForeground = null; |
3742 | 40 |
private boolean textForegroundInherited = true; |
41 |
||
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
42 |
private UIColor textBackground = null; |
3742 | 43 |
private boolean textBackgroundInherited = true; |
44 |
||
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
45 |
private UIColor background = null; |
3742 | 46 |
private boolean backgroundInherited = true; |
47 |
||
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
48 |
private boolean cacheSettingsInherited = true; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
49 |
CacheMode cacheMode = CacheMode.FIXED_SIZES; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
50 |
String maxHozCachedImgScaling = "1.0"; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
51 |
String maxVertCachedImgScaling = "1.0"; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
52 |
|
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
53 |
private List<UIProperty> uiProperties = new ArrayList<>(); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
54 |
|
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
55 |
UIStyle() { |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
56 |
} |
3742 | 57 |
|
47389
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
58 |
UIStyle(XMLStreamReader reader) throws XMLStreamException { |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
59 |
while (reader.hasNext()) { |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
60 |
int eventType = reader.next(); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
61 |
switch (eventType) { |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
62 |
case XMLStreamReader.START_ELEMENT: |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
63 |
switch (reader.getLocalName()) { |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
64 |
case "textForeground": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
65 |
textForeground = new UIColor(reader); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
66 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
67 |
case "textBackground": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
68 |
textBackground = new UIColor(reader); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
69 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
70 |
case "background": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
71 |
background = new UIColor(reader); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
72 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
73 |
case "uiProperty": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
74 |
uiProperties.add(new UIProperty(reader)); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
75 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
76 |
case "inherit-textForeground": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
77 |
textForegroundInherited = Boolean.parseBoolean(reader.getElementText()); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
78 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
79 |
case "inherit-textBackground": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
80 |
textBackgroundInherited = Boolean.parseBoolean(reader.getElementText()); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
81 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
82 |
case "cacheSettingsInherited": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
83 |
cacheSettingsInherited = Boolean.parseBoolean(reader.getElementText()); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
84 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
85 |
case "inherit-background": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
86 |
backgroundInherited = Boolean.parseBoolean(reader.getElementText()); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
87 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
88 |
case "cacheMode": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
89 |
cacheMode = CacheMode.valueOf(reader.getElementText()); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
90 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
91 |
case "maxHozCachedImgScaling": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
92 |
maxHozCachedImgScaling = reader.getElementText(); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
93 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
94 |
case "maxVertCachedImgScaling": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
95 |
maxVertCachedImgScaling = reader.getElementText(); |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
96 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
97 |
} |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
98 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
99 |
case XMLStreamReader.END_ELEMENT: |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
100 |
switch (reader.getLocalName()) { |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
101 |
case "style": |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
102 |
return; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
103 |
} |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
104 |
break; |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
105 |
} |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
106 |
} |
18c850407be9
8187599: Remove dependency of Building Nimbus L&F on JAXB
ssadetsky
parents:
47216
diff
changeset
|
107 |
} |
3742 | 108 |
|
109 |
private UIStyle parentStyle = null; |
|
110 |
public void setParentStyle(UIStyle parentStyle) { |
|
111 |
this.parentStyle = parentStyle; |
|
112 |
} |
|
113 |
||
114 |
public CacheMode getCacheMode() { |
|
115 |
if (cacheSettingsInherited) { |
|
116 |
return (parentStyle == null ? |
|
117 |
CacheMode.FIXED_SIZES : parentStyle.getCacheMode()); |
|
118 |
} else { |
|
119 |
return cacheMode; |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
public String getMaxHozCachedImgScaling() { |
|
124 |
if (cacheSettingsInherited) { |
|
125 |
return (parentStyle == null ? |
|
126 |
"1.0" : parentStyle.getMaxHozCachedImgScaling()); |
|
127 |
} else { |
|
128 |
return maxHozCachedImgScaling; |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
public String getMaxVertCachedImgScaling() { |
|
133 |
if (cacheSettingsInherited) { |
|
134 |
return (parentStyle == null ? |
|
135 |
"1.0" : parentStyle.getMaxVertCachedImgScaling()); |
|
136 |
} else { |
|
137 |
return maxVertCachedImgScaling; |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
public String write(String prefix) { |
|
142 |
StringBuilder sb = new StringBuilder(); |
|
143 |
if (! textForegroundInherited) { |
|
144 |
sb.append(String.format(" addColor(d, \"%s%s\", %s);\n", |
|
145 |
prefix, "textForeground", textForeground.getValue().write())); |
|
146 |
} |
|
147 |
if (! textBackgroundInherited) { |
|
148 |
sb.append(String.format(" addColor(d, \"%s%s\", %s);\n", |
|
149 |
prefix, "textBackground", textBackground.getValue().write())); |
|
150 |
} |
|
151 |
if (! backgroundInherited) { |
|
152 |
sb.append(String.format(" addColor(d, \"%s%s\", %s);\n", |
|
153 |
prefix, "background", background.getValue().write())); |
|
154 |
} |
|
155 |
for (UIProperty property : uiProperties) { |
|
156 |
sb.append(property.write(prefix)); |
|
157 |
} |
|
158 |
return sb.toString(); |
|
159 |
} |
|
160 |
} |