author | apetcher |
Thu, 07 Jun 2018 13:59:53 -0400 | |
branch | JDK-8145252-TLS13-branch |
changeset 56697 | 2dc6efcdeb11 |
parent 47216 | 71c04702a3d5 |
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 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
30 |
import javax.swing.plaf.synth.Region; |
|
31 |
||
32 |
public class Utils { |
|
33 |
||
34 |
public static String escape(String s) { |
|
35 |
return s.replace("\"", "\\\""); |
|
36 |
} |
|
37 |
||
38 |
public static String normalize(String s) { |
|
39 |
char[] src = s.toCharArray(); |
|
40 |
StringBuilder buf = new StringBuilder(); |
|
41 |
List<String> parts = new ArrayList<String>(); |
|
42 |
boolean capitalize = false; |
|
43 |
||
44 |
for (int i = 0; i < src.length; i++) { |
|
45 |
switch (src[i]) { |
|
46 |
case '\\': |
|
47 |
case '"': |
|
48 |
break; |
|
49 |
case '.': |
|
50 |
capitalize = true; |
|
51 |
break; |
|
52 |
case ':': |
|
53 |
parts.add(buf.toString()); |
|
54 |
buf.delete(0, buf.length()); |
|
55 |
capitalize = true; |
|
56 |
break; |
|
57 |
default: |
|
58 |
buf.append(capitalize ? Character.toUpperCase(src[i]) : src[i]); |
|
59 |
capitalize = false; |
|
60 |
break; |
|
61 |
} |
|
62 |
} |
|
63 |
parts.add(buf.toString()); |
|
64 |
||
65 |
// Try to optimize long class names by omitting repeating prefixes, e.g. |
|
66 |
// SliderTrackPainter.java instead of SliderSliderTrackPainter.java |
|
67 |
String result = parts.get(0); |
|
68 |
for (int i = 1; i < parts.size(); i++) { |
|
69 |
String part = parts.get(i); |
|
70 |
if (part.startsWith(result)) { |
|
71 |
result = part; |
|
72 |
} else { |
|
73 |
result += part; |
|
74 |
} |
|
75 |
} |
|
76 |
return result; |
|
77 |
} |
|
78 |
||
79 |
public static String regionNameToCaps(String regionName) { |
|
80 |
if (Region.ARROW_BUTTON.getName().equals(regionName)) { |
|
81 |
return "ARROW_BUTTON"; |
|
82 |
} else if (Region.BUTTON.getName().equals(regionName)) { |
|
83 |
return "BUTTON"; |
|
84 |
} else if (Region.CHECK_BOX.getName().equals(regionName)) { |
|
85 |
return "CHECK_BOX"; |
|
86 |
} else if (Region.CHECK_BOX_MENU_ITEM.getName().equals(regionName)) { |
|
87 |
return "CHECK_BOX_MENU_ITEM"; |
|
88 |
} else if (Region.COLOR_CHOOSER.getName().equals(regionName)) { |
|
89 |
return "COLOR_CHOOSER"; |
|
90 |
} else if (Region.COMBO_BOX.getName().equals(regionName)) { |
|
91 |
return "COMBO_BOX"; |
|
92 |
} else if (Region.DESKTOP_ICON.getName().equals(regionName)) { |
|
93 |
return "DESKTOP_ICON"; |
|
94 |
} else if (Region.DESKTOP_PANE.getName().equals(regionName)) { |
|
95 |
return "DESKTOP_PANE"; |
|
96 |
} else if (Region.EDITOR_PANE.getName().equals(regionName)) { |
|
97 |
return "EDITOR_PANE"; |
|
98 |
} else if (Region.FILE_CHOOSER.getName().equals(regionName)) { |
|
99 |
return "FILE_CHOOSER"; |
|
100 |
} else if (Region.FORMATTED_TEXT_FIELD.getName().equals(regionName)) { |
|
101 |
return "FORMATTED_TEXT_FIELD"; |
|
102 |
} else if (Region.INTERNAL_FRAME.getName().equals(regionName)) { |
|
103 |
return "INTERNAL_FRAME"; |
|
104 |
} else if (Region.INTERNAL_FRAME_TITLE_PANE.getName().equals(regionName)) { |
|
105 |
return "INTERNAL_FRAME_TITLE_PANE"; |
|
106 |
} else if (Region.LABEL.getName().equals(regionName)) { |
|
107 |
return "LABEL"; |
|
108 |
} else if (Region.LIST.getName().equals(regionName)) { |
|
109 |
return "LIST"; |
|
110 |
} else if (Region.MENU.getName().equals(regionName)) { |
|
111 |
return "MENU"; |
|
112 |
} else if (Region.MENU_BAR.getName().equals(regionName)) { |
|
113 |
return "MENU_BAR"; |
|
114 |
} else if (Region.MENU_ITEM.getName().equals(regionName)) { |
|
115 |
return "MENU_ITEM"; |
|
116 |
} else if (Region.MENU_ITEM_ACCELERATOR.getName().equals(regionName)) { |
|
117 |
return "MENU_ITEM_ACCELERATOR"; |
|
118 |
} else if (Region.OPTION_PANE.getName().equals(regionName)) { |
|
119 |
return "OPTION_PANE"; |
|
120 |
} else if (Region.PANEL.getName().equals(regionName)) { |
|
121 |
return "PANEL"; |
|
122 |
} else if (Region.PASSWORD_FIELD.getName().equals(regionName)) { |
|
123 |
return "PASSWORD_FIELD"; |
|
124 |
} else if (Region.POPUP_MENU.getName().equals(regionName)) { |
|
125 |
return "POPUP_MENU"; |
|
126 |
} else if (Region.POPUP_MENU_SEPARATOR.getName().equals(regionName)) { |
|
127 |
return "POPUP_MENU_SEPARATOR"; |
|
128 |
} else if (Region.PROGRESS_BAR.getName().equals(regionName)) { |
|
129 |
return "PROGRESS_BAR"; |
|
130 |
} else if (Region.RADIO_BUTTON.getName().equals(regionName)) { |
|
131 |
return "RADIO_BUTTON"; |
|
132 |
} else if (Region.RADIO_BUTTON_MENU_ITEM.getName().equals(regionName)) { |
|
133 |
return "RADIO_BUTTON_MENU_ITEM"; |
|
134 |
} else if (Region.ROOT_PANE.getName().equals(regionName)) { |
|
135 |
return "ROOT_PANE"; |
|
136 |
} else if (Region.SCROLL_BAR.getName().equals(regionName)) { |
|
137 |
return "SCROLL_BAR"; |
|
138 |
} else if (Region.SCROLL_BAR_THUMB.getName().equals(regionName)) { |
|
139 |
return "SCROLL_BAR_THUMB"; |
|
140 |
} else if (Region.SCROLL_BAR_TRACK.getName().equals(regionName)) { |
|
141 |
return "SCROLL_BAR_TRACK"; |
|
142 |
} else if (Region.SCROLL_PANE.getName().equals(regionName)) { |
|
143 |
return "SCROLL_PANE"; |
|
144 |
} else if (Region.SEPARATOR.getName().equals(regionName)) { |
|
145 |
return "SEPARATOR"; |
|
146 |
} else if (Region.SLIDER.getName().equals(regionName)) { |
|
147 |
return "SLIDER"; |
|
148 |
} else if (Region.SLIDER_THUMB.getName().equals(regionName)) { |
|
149 |
return "SLIDER_THUMB"; |
|
150 |
} else if (Region.SLIDER_TRACK.getName().equals(regionName)) { |
|
151 |
return "SLIDER_TRACK"; |
|
152 |
} else if (Region.SPINNER.getName().equals(regionName)) { |
|
153 |
return "SPINNER"; |
|
154 |
} else if (Region.SPLIT_PANE.getName().equals(regionName)) { |
|
155 |
return "SPLIT_PANE"; |
|
156 |
} else if (Region.SPLIT_PANE_DIVIDER.getName().equals(regionName)) { |
|
157 |
return "SPLIT_PANE_DIVIDER"; |
|
158 |
} else if (Region.TABBED_PANE.getName().equals(regionName)) { |
|
159 |
return "TABBED_PANE"; |
|
160 |
} else if (Region.TABBED_PANE_CONTENT.getName().equals(regionName)) { |
|
161 |
return "TABBED_PANE_CONTENT"; |
|
162 |
} else if (Region.TABBED_PANE_TAB.getName().equals(regionName)) { |
|
163 |
return "TABBED_PANE_TAB"; |
|
164 |
} else if (Region.TABBED_PANE_TAB_AREA.getName().equals(regionName)) { |
|
165 |
return "TABBED_PANE_TAB_AREA"; |
|
166 |
} else if (Region.TABLE.getName().equals(regionName)) { |
|
167 |
return "TABLE"; |
|
168 |
} else if (Region.TABLE_HEADER.getName().equals(regionName)) { |
|
169 |
return "TABLE_HEADER"; |
|
170 |
} else if (Region.TEXT_AREA.getName().equals(regionName)) { |
|
171 |
return "TEXT_AREA"; |
|
172 |
} else if (Region.TEXT_FIELD.getName().equals(regionName)) { |
|
173 |
return "TEXT_FIELD"; |
|
174 |
} else if (Region.TEXT_PANE.getName().equals(regionName)) { |
|
175 |
return "TEXT_PANE"; |
|
176 |
} else if (Region.TOGGLE_BUTTON.getName().equals(regionName)) { |
|
177 |
return "TOGGLE_BUTTON"; |
|
178 |
} else if (Region.TOOL_BAR.getName().equals(regionName)) { |
|
179 |
return "TOOL_BAR"; |
|
180 |
} else if (Region.TOOL_BAR_CONTENT.getName().equals(regionName)) { |
|
181 |
return "TOOL_BAR_CONTENT"; |
|
182 |
} else if (Region.TOOL_BAR_DRAG_WINDOW.getName().equals(regionName)) { |
|
183 |
return "TOOL_BAR_DRAG_WINDOW"; |
|
184 |
} else if (Region.TOOL_BAR_SEPARATOR.getName().equals(regionName)) { |
|
185 |
return "TOOL_BAR_SEPARATOR"; |
|
186 |
} else if (Region.TOOL_TIP.getName().equals(regionName)) { |
|
187 |
return "TOOL_TIP"; |
|
188 |
} else if (Region.TREE.getName().equals(regionName)) { |
|
189 |
return "TREE"; |
|
190 |
} else if (Region.TREE_CELL.getName().equals(regionName)) { |
|
191 |
return "TREE_CELL"; |
|
192 |
} else if (Region.VIEWPORT.getName().equals(regionName)) { |
|
193 |
return "VIEWPORT"; |
|
194 |
} |
|
195 |
throw new RuntimeException("Bad Region name " + regionName); |
|
196 |
} |
|
197 |
||
198 |
public static String statesToConstantName(String states) { |
|
199 |
String s = states.replace(" ", ""); |
|
200 |
s = states.replace("+", "_"); |
|
201 |
return s.toUpperCase(); |
|
202 |
} |
|
203 |
||
204 |
//takes a states string of the form Enabled+Foo+Bar. |
|
205 |
//removes any whitespace. Replaces the + signs with And. |
|
206 |
public static String statesToClassName(String states) { |
|
207 |
String s = states.replace(" ", ""); |
|
208 |
s = states.replace("+", "And"); |
|
209 |
return s; |
|
210 |
} |
|
211 |
||
212 |
public static String formatDouble(String doubleValue) { |
|
213 |
return doubleValue.replace("INF", "Double.POSITIVE_INFINITY"); |
|
214 |
} |
|
215 |
} |