2
|
1 |
/*
|
|
2 |
* Copyright 2002-2006 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package com.sun.java.swing.plaf.gtk;
|
|
26 |
|
|
27 |
import sun.swing.SwingUtilities2;
|
|
28 |
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
|
|
29 |
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
|
|
30 |
|
|
31 |
import javax.swing.plaf.ColorUIResource;
|
|
32 |
import javax.swing.plaf.synth.*;
|
|
33 |
|
|
34 |
import java.awt.*;
|
|
35 |
import java.awt.geom.*;
|
|
36 |
import java.awt.image.*;
|
|
37 |
import java.io.*;
|
|
38 |
import java.net.*;
|
|
39 |
import java.security.*;
|
|
40 |
import java.util.*;
|
|
41 |
|
|
42 |
import javax.swing.*;
|
|
43 |
import javax.swing.border.*;
|
|
44 |
|
|
45 |
import javax.xml.parsers.*;
|
|
46 |
import org.xml.sax.SAXException;
|
|
47 |
import org.w3c.dom.*;
|
|
48 |
|
|
49 |
/**
|
|
50 |
*/
|
|
51 |
class Metacity implements SynthConstants {
|
|
52 |
// Tutorial:
|
|
53 |
// http://developer.gnome.org/doc/tutorials/metacity/metacity-themes.html
|
|
54 |
|
|
55 |
// Themes:
|
|
56 |
// http://art.gnome.org/theme_list.php?category=metacity
|
|
57 |
|
|
58 |
static Metacity INSTANCE;
|
|
59 |
|
|
60 |
private static final String[] themeNames = {
|
|
61 |
getUserTheme(),
|
|
62 |
"blueprint",
|
|
63 |
"Bluecurve",
|
|
64 |
"Crux",
|
|
65 |
"SwingFallbackTheme"
|
|
66 |
};
|
|
67 |
|
|
68 |
static {
|
|
69 |
for (String themeName : themeNames) {
|
|
70 |
if (themeName != null) {
|
|
71 |
try {
|
|
72 |
INSTANCE = new Metacity(themeName);
|
|
73 |
} catch (FileNotFoundException ex) {
|
|
74 |
} catch (IOException ex) {
|
|
75 |
logError(themeName, ex);
|
|
76 |
} catch (ParserConfigurationException ex) {
|
|
77 |
logError(themeName, ex);
|
|
78 |
} catch (SAXException ex) {
|
|
79 |
logError(themeName, ex);
|
|
80 |
}
|
|
81 |
}
|
|
82 |
if (INSTANCE != null) {
|
|
83 |
break;
|
|
84 |
}
|
|
85 |
}
|
|
86 |
if (INSTANCE == null) {
|
|
87 |
throw new Error("Could not find any installed metacity theme, and fallback failed");
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
private static boolean errorLogged = false;
|
|
92 |
private static DocumentBuilder documentBuilder;
|
|
93 |
private static Document xmlDoc;
|
|
94 |
private static String userHome;
|
|
95 |
|
|
96 |
private Node frame_style_set;
|
|
97 |
private Map<String, Object> frameGeometry;
|
|
98 |
private Map<String, Map<String, Object>> frameGeometries;
|
|
99 |
|
|
100 |
private LayoutManager titlePaneLayout = new TitlePaneLayout();
|
|
101 |
|
|
102 |
private ColorizeImageFilter imageFilter = new ColorizeImageFilter();
|
|
103 |
private URL themeDir = null;
|
|
104 |
private SynthContext context;
|
|
105 |
private String themeName;
|
|
106 |
|
|
107 |
private ArithmeticExpressionEvaluator aee = new ArithmeticExpressionEvaluator();
|
|
108 |
private Map<String, Integer> variables;
|
|
109 |
|
|
110 |
// Reusable clip shape object
|
|
111 |
private RoundRectClipShape roundedClipShape;
|
|
112 |
|
|
113 |
protected Metacity(String themeName) throws IOException, ParserConfigurationException, SAXException {
|
|
114 |
this.themeName = themeName;
|
|
115 |
themeDir = getThemeDir(themeName);
|
|
116 |
if (themeDir != null) {
|
|
117 |
URL themeURL = new URL(themeDir, "metacity-theme-1.xml");
|
|
118 |
xmlDoc = getXMLDoc(themeURL);
|
|
119 |
if (xmlDoc == null) {
|
|
120 |
throw new IOException(themeURL.toString());
|
|
121 |
}
|
|
122 |
} else {
|
|
123 |
throw new FileNotFoundException(themeName);
|
|
124 |
}
|
|
125 |
|
|
126 |
// Initialize constants
|
|
127 |
variables = new HashMap();
|
|
128 |
NodeList nodes = xmlDoc.getElementsByTagName("constant");
|
|
129 |
int n = nodes.getLength();
|
|
130 |
for (int i = 0; i < n; i++) {
|
|
131 |
Node node = nodes.item(i);
|
|
132 |
String name = getStringAttr(node, "name");
|
|
133 |
if (name != null) {
|
|
134 |
String value = getStringAttr(node, "value");
|
|
135 |
if (value != null) {
|
|
136 |
try {
|
|
137 |
variables.put(name, Integer.parseInt(value));
|
|
138 |
} catch (NumberFormatException ex) {
|
|
139 |
logError(themeName, ex);
|
|
140 |
// Ignore bad value
|
|
141 |
}
|
|
142 |
}
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
// Cache frame geometries
|
|
147 |
frameGeometries = new HashMap();
|
|
148 |
nodes = xmlDoc.getElementsByTagName("frame_geometry");
|
|
149 |
n = nodes.getLength();
|
|
150 |
for (int i = 0; i < n; i++) {
|
|
151 |
Node node = nodes.item(i);
|
|
152 |
String name = getStringAttr(node, "name");
|
|
153 |
if (name != null) {
|
|
154 |
HashMap<String, Object> gm = new HashMap();
|
|
155 |
frameGeometries.put(name, gm);
|
|
156 |
|
|
157 |
String parentGM = getStringAttr(node, "parent");
|
|
158 |
if (parentGM != null) {
|
|
159 |
gm.putAll(frameGeometries.get(parentGM));
|
|
160 |
}
|
|
161 |
|
|
162 |
gm.put("has_title",
|
|
163 |
Boolean.valueOf(getBooleanAttr(node, "has_title", true)));
|
|
164 |
gm.put("rounded_top_left",
|
|
165 |
Boolean.valueOf(getBooleanAttr(node, "rounded_top_left", false)));
|
|
166 |
gm.put("rounded_top_right",
|
|
167 |
Boolean.valueOf(getBooleanAttr(node, "rounded_top_right", false)));
|
|
168 |
gm.put("rounded_bottom_left",
|
|
169 |
Boolean.valueOf(getBooleanAttr(node, "rounded_bottom_left", false)));
|
|
170 |
gm.put("rounded_bottom_right",
|
|
171 |
Boolean.valueOf(getBooleanAttr(node, "rounded_bottom_right", false)));
|
|
172 |
|
|
173 |
NodeList childNodes = node.getChildNodes();
|
|
174 |
int nc = childNodes.getLength();
|
|
175 |
for (int j = 0; j < nc; j++) {
|
|
176 |
Node child = childNodes.item(j);
|
|
177 |
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
|
178 |
name = child.getNodeName();
|
|
179 |
Object value = null;
|
|
180 |
if ("distance".equals(name)) {
|
|
181 |
value = new Integer(getIntAttr(child, "value", 0));
|
|
182 |
} else if ("border".equals(name)) {
|
|
183 |
value = new Insets(getIntAttr(child, "top", 0),
|
|
184 |
getIntAttr(child, "left", 0),
|
|
185 |
getIntAttr(child, "bottom", 0),
|
|
186 |
getIntAttr(child, "right", 0));
|
|
187 |
} else if ("aspect_ratio".equals(name)) {
|
|
188 |
value = new Float(getFloatAttr(child, "value", 1.0F));
|
|
189 |
} else {
|
|
190 |
logError(themeName, "Unknown Metacity frame geometry value type: "+name);
|
|
191 |
}
|
|
192 |
String childName = getStringAttr(child, "name");
|
|
193 |
if (childName != null && value != null) {
|
|
194 |
gm.put(childName, value);
|
|
195 |
}
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|
|
199 |
}
|
|
200 |
frameGeometry = frameGeometries.get("normal");
|
|
201 |
}
|
|
202 |
|
|
203 |
|
|
204 |
public static LayoutManager getTitlePaneLayout() {
|
|
205 |
return INSTANCE.titlePaneLayout;
|
|
206 |
}
|
|
207 |
|
|
208 |
private Shape getRoundedClipShape(int x, int y, int w, int h,
|
|
209 |
int arcw, int arch, int corners) {
|
|
210 |
if (roundedClipShape == null) {
|
|
211 |
roundedClipShape = new RoundRectClipShape();
|
|
212 |
}
|
|
213 |
roundedClipShape.setRoundedRect(x, y, w, h, arcw, arch, corners);
|
|
214 |
|
|
215 |
return roundedClipShape;
|
|
216 |
}
|
|
217 |
|
|
218 |
void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
|
|
219 |
updateFrameGeometry(context);
|
|
220 |
|
|
221 |
this.context = context;
|
|
222 |
JButton button = (JButton)context.getComponent();
|
|
223 |
String buttonName = button.getName();
|
|
224 |
int buttonState = context.getComponentState();
|
|
225 |
|
|
226 |
JComponent titlePane = (JComponent)button.getParent();
|
|
227 |
Container titlePaneParent = titlePane.getParent();
|
|
228 |
|
|
229 |
JInternalFrame jif;
|
|
230 |
if (titlePaneParent instanceof JInternalFrame) {
|
|
231 |
jif = (JInternalFrame)titlePaneParent;
|
|
232 |
} else if (titlePaneParent instanceof JInternalFrame.JDesktopIcon) {
|
|
233 |
jif = ((JInternalFrame.JDesktopIcon)titlePaneParent).getInternalFrame();
|
|
234 |
} else {
|
|
235 |
return;
|
|
236 |
}
|
|
237 |
|
|
238 |
boolean active = jif.isSelected();
|
|
239 |
button.setOpaque(false);
|
|
240 |
|
|
241 |
String state = "normal";
|
|
242 |
if ((buttonState & PRESSED) != 0) {
|
|
243 |
state = "pressed";
|
|
244 |
} else if ((buttonState & MOUSE_OVER) != 0) {
|
|
245 |
state = "prelight";
|
|
246 |
}
|
|
247 |
|
|
248 |
String function = null;
|
|
249 |
String location = null;
|
|
250 |
boolean left_corner = false;
|
|
251 |
boolean right_corner = false;
|
|
252 |
|
|
253 |
|
|
254 |
if (buttonName == "InternalFrameTitlePane.menuButton") {
|
|
255 |
function = "menu";
|
|
256 |
location = "left_left";
|
|
257 |
left_corner = true;
|
|
258 |
} else if (buttonName == "InternalFrameTitlePane.iconifyButton") {
|
|
259 |
function = "minimize";
|
|
260 |
int nButtons = ((jif.isIconifiable() ? 1 : 0) +
|
|
261 |
(jif.isMaximizable() ? 1 : 0) +
|
|
262 |
(jif.isClosable() ? 1 : 0));
|
|
263 |
right_corner = (nButtons == 1);
|
|
264 |
switch (nButtons) {
|
|
265 |
case 1: location = "right_right"; break;
|
|
266 |
case 2: location = "right_middle"; break;
|
|
267 |
case 3: location = "right_left"; break;
|
|
268 |
}
|
|
269 |
} else if (buttonName == "InternalFrameTitlePane.maximizeButton") {
|
|
270 |
function = "maximize";
|
|
271 |
right_corner = !jif.isClosable();
|
|
272 |
location = jif.isClosable() ? "right_middle" : "right_right";
|
|
273 |
} else if (buttonName == "InternalFrameTitlePane.closeButton") {
|
|
274 |
function = "close";
|
|
275 |
right_corner = true;
|
|
276 |
location = "right_right";
|
|
277 |
}
|
|
278 |
|
|
279 |
Node frame = getNode(frame_style_set, "frame", new String[] {
|
|
280 |
"focus", (active ? "yes" : "no"),
|
|
281 |
"state", (jif.isMaximum() ? "maximized" : "normal")
|
|
282 |
});
|
|
283 |
|
|
284 |
if (function != null && frame != null) {
|
|
285 |
Node frame_style = getNode("frame_style", new String[] {
|
|
286 |
"name", getStringAttr(frame, "style")
|
|
287 |
});
|
|
288 |
if (frame_style != null) {
|
|
289 |
Shape oldClip = g.getClip();
|
|
290 |
if ((right_corner && getBoolean("rounded_top_right", false)) ||
|
|
291 |
(left_corner && getBoolean("rounded_top_left", false))) {
|
|
292 |
|
|
293 |
Point buttonLoc = button.getLocation();
|
|
294 |
if (right_corner) {
|
|
295 |
g.setClip(getRoundedClipShape(0, 0, w, h,
|
|
296 |
12, 12, RoundRectClipShape.TOP_RIGHT));
|
|
297 |
} else {
|
|
298 |
g.setClip(getRoundedClipShape(0, 0, w, h,
|
|
299 |
11, 11, RoundRectClipShape.TOP_LEFT));
|
|
300 |
}
|
|
301 |
|
|
302 |
Rectangle clipBounds = oldClip.getBounds();
|
|
303 |
g.clipRect(clipBounds.x, clipBounds.y,
|
|
304 |
clipBounds.width, clipBounds.height);
|
|
305 |
}
|
|
306 |
drawButton(frame_style, location+"_background", state, g, w, h, jif);
|
|
307 |
drawButton(frame_style, function, state, g, w, h, jif);
|
|
308 |
g.setClip(oldClip);
|
|
309 |
}
|
|
310 |
}
|
|
311 |
}
|
|
312 |
|
|
313 |
protected void drawButton(Node frame_style, String function, String state,
|
|
314 |
Graphics g, int w, int h, JInternalFrame jif) {
|
|
315 |
Node buttonNode = getNode(frame_style, "button",
|
|
316 |
new String[] { "function", function, "state", state });
|
|
317 |
if (buttonNode == null && !state.equals("normal")) {
|
|
318 |
buttonNode = getNode(frame_style, "button",
|
|
319 |
new String[] { "function", function, "state", "normal" });
|
|
320 |
}
|
|
321 |
if (buttonNode != null) {
|
|
322 |
Node draw_ops;
|
|
323 |
String draw_ops_name = getStringAttr(buttonNode, "draw_ops");
|
|
324 |
if (draw_ops_name != null) {
|
|
325 |
draw_ops = getNode("draw_ops", new String[] { "name", draw_ops_name });
|
|
326 |
} else {
|
|
327 |
draw_ops = getNode(buttonNode, "draw_ops", null);
|
|
328 |
}
|
|
329 |
variables.put("width", w);
|
|
330 |
variables.put("height", h);
|
|
331 |
draw(draw_ops, g, jif);
|
|
332 |
}
|
|
333 |
}
|
|
334 |
|
|
335 |
void paintFrameBorder(SynthContext context, Graphics g, int x0, int y0, int width, int height) {
|
|
336 |
updateFrameGeometry(context);
|
|
337 |
|
|
338 |
this.context = context;
|
|
339 |
JComponent comp = context.getComponent();
|
|
340 |
JComponent titlePane = findChild(comp, "InternalFrame.northPane");
|
|
341 |
|
|
342 |
if (titlePane == null) {
|
|
343 |
return;
|
|
344 |
}
|
|
345 |
|
|
346 |
JInternalFrame jif = null;
|
|
347 |
if (comp instanceof JInternalFrame) {
|
|
348 |
jif = (JInternalFrame)comp;
|
|
349 |
} else if (comp instanceof JInternalFrame.JDesktopIcon) {
|
|
350 |
jif = ((JInternalFrame.JDesktopIcon)comp).getInternalFrame();
|
|
351 |
} else {
|
|
352 |
assert false : "component is not JInternalFrame or JInternalFrame.JDesktopIcon";
|
|
353 |
return;
|
|
354 |
}
|
|
355 |
|
|
356 |
boolean active = jif.isSelected();
|
|
357 |
Font oldFont = g.getFont();
|
|
358 |
g.setFont(titlePane.getFont());
|
|
359 |
g.translate(x0, y0);
|
|
360 |
|
|
361 |
Rectangle titleRect = calculateTitleArea(jif);
|
|
362 |
JComponent menuButton = findChild(titlePane, "InternalFrameTitlePane.menuButton");
|
|
363 |
|
|
364 |
Icon frameIcon = jif.getFrameIcon();
|
|
365 |
variables.put("mini_icon_width",
|
|
366 |
(frameIcon != null) ? frameIcon.getIconWidth() : 0);
|
|
367 |
variables.put("mini_icon_height",
|
|
368 |
(frameIcon != null) ? frameIcon.getIconHeight() : 0);
|
|
369 |
variables.put("title_width", calculateTitleTextWidth(g, jif));
|
|
370 |
FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
|
|
371 |
variables.put("title_height", fm.getAscent() + fm.getDescent());
|
|
372 |
|
|
373 |
// These don't seem to apply here, but the Galaxy theme uses them. Not sure why.
|
|
374 |
variables.put("icon_width", 32);
|
|
375 |
variables.put("icon_height", 32);
|
|
376 |
|
|
377 |
if (frame_style_set != null) {
|
|
378 |
Node frame = getNode(frame_style_set, "frame", new String[] {
|
|
379 |
"focus", (active ? "yes" : "no"),
|
|
380 |
"state", (jif.isMaximum() ? "maximized" : "normal")
|
|
381 |
});
|
|
382 |
|
|
383 |
if (frame != null) {
|
|
384 |
Node frame_style = getNode("frame_style", new String[] {
|
|
385 |
"name", getStringAttr(frame, "style")
|
|
386 |
});
|
|
387 |
if (frame_style != null) {
|
|
388 |
Shape oldClip = g.getClip();
|
|
389 |
boolean roundTopLeft = getBoolean("rounded_top_left", false);
|
|
390 |
boolean roundTopRight = getBoolean("rounded_top_right", false);
|
|
391 |
boolean roundBottomLeft = getBoolean("rounded_bottom_left", false);
|
|
392 |
boolean roundBottomRight = getBoolean("rounded_bottom_right", false);
|
|
393 |
|
|
394 |
if (roundTopLeft || roundTopRight || roundBottomLeft || roundBottomRight) {
|
|
395 |
jif.setOpaque(false);
|
|
396 |
|
|
397 |
g.setClip(getRoundedClipShape(0, 0, width, height, 12, 12,
|
|
398 |
(roundTopLeft ? RoundRectClipShape.TOP_LEFT : 0) |
|
|
399 |
(roundTopRight ? RoundRectClipShape.TOP_RIGHT : 0) |
|
|
400 |
(roundBottomLeft ? RoundRectClipShape.BOTTOM_LEFT : 0) |
|
|
401 |
(roundBottomRight ? RoundRectClipShape.BOTTOM_RIGHT : 0)));
|
|
402 |
}
|
|
403 |
|
|
404 |
Rectangle clipBounds = oldClip.getBounds();
|
|
405 |
g.clipRect(clipBounds.x, clipBounds.y,
|
|
406 |
clipBounds.width, clipBounds.height);
|
|
407 |
|
|
408 |
int titleHeight = titlePane.getHeight();
|
|
409 |
|
|
410 |
boolean minimized = jif.isIcon();
|
|
411 |
Insets insets = getBorderInsets(context, null);
|
|
412 |
|
|
413 |
int leftTitlebarEdge = getInt("left_titlebar_edge");
|
|
414 |
int rightTitlebarEdge = getInt("right_titlebar_edge");
|
|
415 |
int topTitlebarEdge = getInt("top_titlebar_edge");
|
|
416 |
int bottomTitlebarEdge = getInt("bottom_titlebar_edge");
|
|
417 |
|
|
418 |
if (!minimized) {
|
|
419 |
drawPiece(frame_style, g, "entire_background",
|
|
420 |
0, 0, width, height, jif);
|
|
421 |
}
|
|
422 |
drawPiece(frame_style, g, "titlebar",
|
|
423 |
0, 0, width, titleHeight, jif);
|
|
424 |
drawPiece(frame_style, g, "titlebar_middle",
|
|
425 |
leftTitlebarEdge, topTitlebarEdge,
|
|
426 |
width - leftTitlebarEdge - rightTitlebarEdge,
|
|
427 |
titleHeight - topTitlebarEdge - bottomTitlebarEdge,
|
|
428 |
jif);
|
|
429 |
drawPiece(frame_style, g, "left_titlebar_edge",
|
|
430 |
0, 0, leftTitlebarEdge, titleHeight, jif);
|
|
431 |
drawPiece(frame_style, g, "right_titlebar_edge",
|
|
432 |
width - rightTitlebarEdge, 0,
|
|
433 |
rightTitlebarEdge, titleHeight, jif);
|
|
434 |
drawPiece(frame_style, g, "top_titlebar_edge",
|
|
435 |
0, 0, width, topTitlebarEdge, jif);
|
|
436 |
drawPiece(frame_style, g, "bottom_titlebar_edge",
|
|
437 |
0, titleHeight - bottomTitlebarEdge,
|
|
438 |
width, bottomTitlebarEdge, jif);
|
|
439 |
drawPiece(frame_style, g, "title",
|
|
440 |
titleRect.x, titleRect.y, titleRect.width, titleRect.height, jif);
|
|
441 |
if (!minimized) {
|
|
442 |
drawPiece(frame_style, g, "left_edge",
|
|
443 |
0, titleHeight, insets.left, height-titleHeight, jif);
|
|
444 |
drawPiece(frame_style, g, "right_edge",
|
|
445 |
width-insets.right, titleHeight, insets.right, height-titleHeight, jif);
|
|
446 |
drawPiece(frame_style, g, "bottom_edge",
|
|
447 |
0, height - insets.bottom, width, insets.bottom, jif);
|
|
448 |
drawPiece(frame_style, g, "overlay",
|
|
449 |
0, 0, width, height, jif);
|
|
450 |
}
|
|
451 |
g.setClip(oldClip);
|
|
452 |
}
|
|
453 |
}
|
|
454 |
}
|
|
455 |
g.translate(-x0, -y0);
|
|
456 |
g.setFont(oldFont);
|
|
457 |
}
|
|
458 |
|
|
459 |
|
|
460 |
|
|
461 |
private static class Privileged implements PrivilegedAction {
|
|
462 |
private static int GET_THEME_DIR = 0;
|
|
463 |
private static int GET_USER_THEME = 1;
|
|
464 |
private static int GET_IMAGE = 2;
|
|
465 |
private int type;
|
|
466 |
private Object arg;
|
|
467 |
|
|
468 |
public Object doPrivileged(int type, Object arg) {
|
|
469 |
this.type = type;
|
|
470 |
this.arg = arg;
|
|
471 |
return AccessController.doPrivileged(this);
|
|
472 |
}
|
|
473 |
|
|
474 |
public Object run() {
|
|
475 |
if (type == GET_THEME_DIR) {
|
|
476 |
String sep = File.separator;
|
|
477 |
String[] dirs = new String[] {
|
|
478 |
userHome + sep + ".themes",
|
|
479 |
System.getProperty("swing.metacitythemedir"),
|
|
480 |
"/usr/share/themes",
|
|
481 |
"/usr/gnome/share/themes", // Debian/Redhat/Solaris
|
|
482 |
"/opt/gnome2/share/themes" // SuSE
|
|
483 |
};
|
|
484 |
|
|
485 |
URL themeDir = null;
|
|
486 |
for (int i = 0; i < dirs.length; i++) {
|
|
487 |
// System property may not be set so skip null directories.
|
|
488 |
if (dirs[i] == null) {
|
|
489 |
continue;
|
|
490 |
}
|
|
491 |
File dir =
|
|
492 |
new File(dirs[i] + sep + arg + sep + "metacity-1");
|
|
493 |
if (new File(dir, "metacity-theme-1.xml").canRead()) {
|
|
494 |
try {
|
|
495 |
themeDir = dir.toURI().toURL();
|
|
496 |
} catch (MalformedURLException ex) {
|
|
497 |
themeDir = null;
|
|
498 |
}
|
|
499 |
break;
|
|
500 |
}
|
|
501 |
}
|
|
502 |
if (themeDir == null) {
|
|
503 |
String filename = "resources/metacity/" + arg +
|
|
504 |
"/metacity-1/metacity-theme-1.xml";
|
|
505 |
URL url = getClass().getResource(filename);
|
|
506 |
if (url != null) {
|
|
507 |
String str = url.toString();
|
|
508 |
try {
|
|
509 |
themeDir = new URL(str.substring(0, str.lastIndexOf('/'))+"/");
|
|
510 |
} catch (MalformedURLException ex) {
|
|
511 |
themeDir = null;
|
|
512 |
}
|
|
513 |
}
|
|
514 |
}
|
|
515 |
return themeDir;
|
|
516 |
} else if (type == GET_USER_THEME) {
|
|
517 |
try {
|
|
518 |
// Set userHome here because we need the privilege
|
|
519 |
userHome = System.getProperty("user.home");
|
|
520 |
|
|
521 |
String theme = System.getProperty("swing.metacitythemename");
|
|
522 |
if (theme != null) {
|
|
523 |
return theme;
|
|
524 |
}
|
|
525 |
// Note: this is a small file (< 1024 bytes) so it's not worth
|
|
526 |
// starting an XML parser or even to use a buffered reader.
|
|
527 |
URL url = new URL(new File(userHome).toURI().toURL(),
|
|
528 |
".gconf/apps/metacity/general/%25gconf.xml");
|
|
529 |
// Pending: verify character encoding spec for gconf
|
|
530 |
Reader reader = new InputStreamReader(url.openStream(), "ISO-8859-1");
|
|
531 |
char[] buf = new char[1024];
|
|
532 |
StringBuffer strBuf = new StringBuffer();
|
|
533 |
int n;
|
|
534 |
while ((n = reader.read(buf)) >= 0) {
|
|
535 |
strBuf.append(buf, 0, n);
|
|
536 |
}
|
|
537 |
reader.close();
|
|
538 |
String str = strBuf.toString();
|
|
539 |
if (str != null) {
|
|
540 |
String strLowerCase = str.toLowerCase();
|
|
541 |
int i = strLowerCase.indexOf("<entry name=\"theme\"");
|
|
542 |
if (i >= 0) {
|
|
543 |
i = strLowerCase.indexOf("<stringvalue>", i);
|
|
544 |
if (i > 0) {
|
|
545 |
i += "<stringvalue>".length();
|
|
546 |
int i2 = str.indexOf("<", i);
|
|
547 |
return str.substring(i, i2);
|
|
548 |
}
|
|
549 |
}
|
|
550 |
}
|
|
551 |
} catch (MalformedURLException ex) {
|
|
552 |
// OK to just ignore. We'll use a fallback theme.
|
|
553 |
} catch (IOException ex) {
|
|
554 |
// OK to just ignore. We'll use a fallback theme.
|
|
555 |
}
|
|
556 |
return null;
|
|
557 |
} else if (type == GET_IMAGE) {
|
|
558 |
return new ImageIcon((URL)arg).getImage();
|
|
559 |
} else {
|
|
560 |
return null;
|
|
561 |
}
|
|
562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
private static URL getThemeDir(String themeName) {
|
|
566 |
return (URL)new Privileged().doPrivileged(Privileged.GET_THEME_DIR, themeName);
|
|
567 |
}
|
|
568 |
|
|
569 |
private static String getUserTheme() {
|
|
570 |
return (String)new Privileged().doPrivileged(Privileged.GET_USER_THEME, null);
|
|
571 |
}
|
|
572 |
|
|
573 |
protected void tileImage(Graphics g, Image image, int x0, int y0, int w, int h, float[] alphas) {
|
|
574 |
Graphics2D g2 = (Graphics2D)g;
|
|
575 |
Composite oldComp = g2.getComposite();
|
|
576 |
|
|
577 |
int sw = image.getWidth(null);
|
|
578 |
int sh = image.getHeight(null);
|
|
579 |
int y = y0;
|
|
580 |
while (y < y0 + h) {
|
|
581 |
sh = Math.min(sh, y0 + h - y);
|
|
582 |
int x = x0;
|
|
583 |
while (x < x0 + w) {
|
|
584 |
float f = (alphas.length - 1.0F) * x / (x0 + w);
|
|
585 |
int i = (int)f;
|
|
586 |
f -= (int)f;
|
|
587 |
float alpha = (1-f) * alphas[i];
|
|
588 |
if (i+1 < alphas.length) {
|
|
589 |
alpha += f * alphas[i+1];
|
|
590 |
}
|
|
591 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
|
|
592 |
int swm = Math.min(sw, x0 + w - x);
|
|
593 |
g.drawImage(image, x, y, x+swm, y+sh, 0, 0, swm, sh, null);
|
|
594 |
x += swm;
|
|
595 |
}
|
|
596 |
y += sh;
|
|
597 |
}
|
|
598 |
g2.setComposite(oldComp);
|
|
599 |
}
|
|
600 |
|
|
601 |
private HashMap<String, Image> images = new HashMap();
|
|
602 |
|
|
603 |
protected Image getImage(String key, Color c) {
|
|
604 |
Image image = images.get(key+"-"+c.getRGB());
|
|
605 |
if (image == null) {
|
|
606 |
image = imageFilter.colorize(getImage(key), c);
|
|
607 |
if (image != null) {
|
|
608 |
images.put(key+"-"+c.getRGB(), image);
|
|
609 |
}
|
|
610 |
}
|
|
611 |
return image;
|
|
612 |
}
|
|
613 |
|
|
614 |
protected Image getImage(String key) {
|
|
615 |
Image image = images.get(key);
|
|
616 |
if (image == null) {
|
|
617 |
if (themeDir != null) {
|
|
618 |
try {
|
|
619 |
URL url = new URL(themeDir, key);
|
|
620 |
image = (Image)new Privileged().doPrivileged(Privileged.GET_IMAGE, url);
|
|
621 |
} catch (MalformedURLException ex) {
|
|
622 |
//log("Bad image url: "+ themeDir + "/" + key);
|
|
623 |
}
|
|
624 |
}
|
|
625 |
if (image != null) {
|
|
626 |
images.put(key, image);
|
|
627 |
}
|
|
628 |
}
|
|
629 |
return image;
|
|
630 |
}
|
|
631 |
|
|
632 |
private class ColorizeImageFilter extends RGBImageFilter {
|
|
633 |
double cr, cg, cb;
|
|
634 |
|
|
635 |
public ColorizeImageFilter() {
|
|
636 |
canFilterIndexColorModel = true;
|
|
637 |
}
|
|
638 |
|
|
639 |
public void setColor(Color color) {
|
|
640 |
cr = color.getRed() / 255.0;
|
|
641 |
cg = color.getGreen() / 255.0;
|
|
642 |
cb = color.getBlue() / 255.0;
|
|
643 |
}
|
|
644 |
|
|
645 |
public Image colorize(Image fromImage, Color c) {
|
|
646 |
setColor(c);
|
|
647 |
ImageProducer producer = new FilteredImageSource(fromImage.getSource(), this);
|
|
648 |
return new ImageIcon(context.getComponent().createImage(producer)).getImage();
|
|
649 |
}
|
|
650 |
|
|
651 |
public int filterRGB(int x, int y, int rgb) {
|
|
652 |
// Assume all rgb values are shades of gray
|
|
653 |
double grayLevel = 2 * (rgb & 0xff) / 255.0;
|
|
654 |
double r, g, b;
|
|
655 |
|
|
656 |
if (grayLevel <= 1.0) {
|
|
657 |
r = cr * grayLevel;
|
|
658 |
g = cg * grayLevel;
|
|
659 |
b = cb * grayLevel;
|
|
660 |
} else {
|
|
661 |
grayLevel -= 1.0;
|
|
662 |
r = cr + (1.0 - cr) * grayLevel;
|
|
663 |
g = cg + (1.0 - cg) * grayLevel;
|
|
664 |
b = cb + (1.0 - cb) * grayLevel;
|
|
665 |
}
|
|
666 |
|
|
667 |
return ((rgb & 0xff000000) +
|
|
668 |
(((int)(r * 255)) << 16) +
|
|
669 |
(((int)(g * 255)) << 8) +
|
|
670 |
(int)(b * 255));
|
|
671 |
}
|
|
672 |
}
|
|
673 |
|
|
674 |
protected static JComponent findChild(JComponent parent, String name) {
|
|
675 |
int n = parent.getComponentCount();
|
|
676 |
for (int i = 0; i < n; i++) {
|
|
677 |
JComponent c = (JComponent)parent.getComponent(i);
|
|
678 |
if (name.equals(c.getName())) {
|
|
679 |
return c;
|
|
680 |
}
|
|
681 |
}
|
|
682 |
return null;
|
|
683 |
}
|
|
684 |
|
|
685 |
|
|
686 |
protected class TitlePaneLayout implements LayoutManager {
|
|
687 |
public void addLayoutComponent(String name, Component c) {}
|
|
688 |
public void removeLayoutComponent(Component c) {}
|
|
689 |
public Dimension preferredLayoutSize(Container c) {
|
|
690 |
return minimumLayoutSize(c);
|
|
691 |
}
|
|
692 |
|
|
693 |
public Dimension minimumLayoutSize(Container c) {
|
|
694 |
JComponent titlePane = (JComponent)c;
|
|
695 |
Container titlePaneParent = titlePane.getParent();
|
|
696 |
JInternalFrame frame;
|
|
697 |
if (titlePaneParent instanceof JInternalFrame) {
|
|
698 |
frame = (JInternalFrame)titlePaneParent;
|
|
699 |
} else if (titlePaneParent instanceof JInternalFrame.JDesktopIcon) {
|
|
700 |
frame = ((JInternalFrame.JDesktopIcon)titlePaneParent).getInternalFrame();
|
|
701 |
} else {
|
|
702 |
return null;
|
|
703 |
}
|
|
704 |
|
|
705 |
Dimension buttonDim = calculateButtonSize(titlePane);
|
|
706 |
Insets title_border = (Insets)getFrameGeometry().get("title_border");
|
|
707 |
Insets button_border = (Insets)getFrameGeometry().get("button_border");
|
|
708 |
|
|
709 |
// Calculate width.
|
|
710 |
int width = getInt("left_titlebar_edge") + buttonDim.width + getInt("right_titlebar_edge");
|
|
711 |
if (title_border != null) {
|
|
712 |
width += title_border.left + title_border.right;
|
|
713 |
}
|
|
714 |
if (frame.isClosable()) {
|
|
715 |
width += buttonDim.width;
|
|
716 |
}
|
|
717 |
if (frame.isMaximizable()) {
|
|
718 |
width += buttonDim.width;
|
|
719 |
}
|
|
720 |
if (frame.isIconifiable()) {
|
|
721 |
width += buttonDim.width;
|
|
722 |
}
|
|
723 |
FontMetrics fm = frame.getFontMetrics(titlePane.getFont());
|
|
724 |
String frameTitle = frame.getTitle();
|
|
725 |
int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
|
|
726 |
frame, fm, frameTitle) : 0;
|
|
727 |
int title_length = frameTitle != null ? frameTitle.length() : 0;
|
|
728 |
|
|
729 |
// Leave room for three characters in the title.
|
|
730 |
if (title_length > 3) {
|
|
731 |
int subtitle_w = SwingUtilities2.stringWidth(
|
|
732 |
frame, fm, frameTitle.substring(0, 3) + "...");
|
|
733 |
width += (title_w < subtitle_w) ? title_w : subtitle_w;
|
|
734 |
} else {
|
|
735 |
width += title_w;
|
|
736 |
}
|
|
737 |
|
|
738 |
// Calculate height.
|
|
739 |
int titleHeight = fm.getHeight() + getInt("title_vertical_pad");
|
|
740 |
if (title_border != null) {
|
|
741 |
titleHeight += title_border.top + title_border.bottom;
|
|
742 |
}
|
|
743 |
int buttonHeight = buttonDim.height;
|
|
744 |
if (button_border != null) {
|
|
745 |
buttonHeight += button_border.top + button_border.bottom;
|
|
746 |
}
|
|
747 |
int height = Math.max(buttonHeight, titleHeight);
|
|
748 |
|
|
749 |
return new Dimension(width, height);
|
|
750 |
}
|
|
751 |
|
|
752 |
public void layoutContainer(Container c) {
|
|
753 |
JComponent titlePane = (JComponent)c;
|
|
754 |
Container titlePaneParent = titlePane.getParent();
|
|
755 |
JInternalFrame frame;
|
|
756 |
if (titlePaneParent instanceof JInternalFrame) {
|
|
757 |
frame = (JInternalFrame)titlePaneParent;
|
|
758 |
} else if (titlePaneParent instanceof JInternalFrame.JDesktopIcon) {
|
|
759 |
frame = ((JInternalFrame.JDesktopIcon)titlePaneParent).getInternalFrame();
|
|
760 |
} else {
|
|
761 |
return;
|
|
762 |
}
|
|
763 |
Map gm = getFrameGeometry();
|
|
764 |
|
|
765 |
int w = titlePane.getWidth();
|
|
766 |
int h = titlePane.getHeight();
|
|
767 |
|
|
768 |
JComponent menuButton = findChild(titlePane, "InternalFrameTitlePane.menuButton");
|
|
769 |
JComponent minimizeButton = findChild(titlePane, "InternalFrameTitlePane.iconifyButton");
|
|
770 |
JComponent maximizeButton = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");
|
|
771 |
JComponent closeButton = findChild(titlePane, "InternalFrameTitlePane.closeButton");
|
|
772 |
|
|
773 |
int buttonGap = 0;
|
|
774 |
|
|
775 |
Insets button_border = (Insets)gm.get("button_border");
|
|
776 |
Dimension buttonDim = calculateButtonSize(titlePane);
|
|
777 |
|
|
778 |
int x = getInt("left_titlebar_edge");
|
|
779 |
int y = (button_border != null) ? button_border.top : 0;
|
|
780 |
|
|
781 |
menuButton.setBounds(x, y, buttonDim.width, buttonDim.height);
|
|
782 |
|
|
783 |
x = w - buttonDim.width - getInt("right_titlebar_edge");
|
|
784 |
if (button_border != null) {
|
|
785 |
x -= button_border.right;
|
|
786 |
}
|
|
787 |
|
|
788 |
if (frame.isClosable()) {
|
|
789 |
closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
|
|
790 |
x -= (buttonDim.width + buttonGap);
|
|
791 |
}
|
|
792 |
|
|
793 |
if (frame.isMaximizable()) {
|
|
794 |
maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
|
|
795 |
x -= (buttonDim.width + buttonGap);
|
|
796 |
}
|
|
797 |
|
|
798 |
if (frame.isIconifiable()) {
|
|
799 |
minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
|
|
800 |
}
|
|
801 |
}
|
|
802 |
} // end TitlePaneLayout
|
|
803 |
|
|
804 |
protected Map getFrameGeometry() {
|
|
805 |
return frameGeometry;
|
|
806 |
}
|
|
807 |
|
|
808 |
protected void setFrameGeometry(JComponent titlePane, Map gm) {
|
|
809 |
this.frameGeometry = gm;
|
|
810 |
if (getInt("top_height") == 0 && titlePane != null) {
|
|
811 |
gm.put("top_height", new Integer(titlePane.getHeight()));
|
|
812 |
}
|
|
813 |
}
|
|
814 |
|
|
815 |
protected int getInt(String key) {
|
|
816 |
Integer i = (Integer)frameGeometry.get(key);
|
|
817 |
if (i == null) {
|
|
818 |
i = variables.get(key);
|
|
819 |
}
|
|
820 |
return (i != null) ? i.intValue() : 0;
|
|
821 |
}
|
|
822 |
|
|
823 |
protected boolean getBoolean(String key, boolean fallback) {
|
|
824 |
Boolean b = (Boolean)frameGeometry.get(key);
|
|
825 |
return (b != null) ? b.booleanValue() : fallback;
|
|
826 |
}
|
|
827 |
|
|
828 |
|
|
829 |
protected void drawArc(Node node, Graphics g) {
|
|
830 |
NamedNodeMap attrs = node.getAttributes();
|
|
831 |
Color color = parseColor(getStringAttr(attrs, "color"));
|
|
832 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
833 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
834 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
835 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
836 |
int start_angle = aee.evaluate(getStringAttr(attrs, "start_angle"));
|
|
837 |
int extent_angle = aee.evaluate(getStringAttr(attrs, "extent_angle"));
|
|
838 |
boolean filled = getBooleanAttr(node, "filled", false);
|
|
839 |
if (getInt("width") == -1) {
|
|
840 |
x -= w;
|
|
841 |
}
|
|
842 |
if (getInt("height") == -1) {
|
|
843 |
y -= h;
|
|
844 |
}
|
|
845 |
g.setColor(color);
|
|
846 |
if (filled) {
|
|
847 |
g.fillArc(x, y, w, h, start_angle, extent_angle);
|
|
848 |
} else {
|
|
849 |
g.drawArc(x, y, w, h, start_angle, extent_angle);
|
|
850 |
}
|
|
851 |
}
|
|
852 |
|
|
853 |
protected void drawLine(Node node, Graphics g) {
|
|
854 |
NamedNodeMap attrs = node.getAttributes();
|
|
855 |
Color color = parseColor(getStringAttr(attrs, "color"));
|
|
856 |
int x1 = aee.evaluate(getStringAttr(attrs, "x1"));
|
|
857 |
int y1 = aee.evaluate(getStringAttr(attrs, "y1"));
|
|
858 |
int x2 = aee.evaluate(getStringAttr(attrs, "x2"));
|
|
859 |
int y2 = aee.evaluate(getStringAttr(attrs, "y2"));
|
|
860 |
int lineWidth = aee.evaluate(getStringAttr(attrs, "width"), 1);
|
|
861 |
g.setColor(color);
|
|
862 |
if (lineWidth != 1) {
|
|
863 |
Graphics2D g2d = (Graphics2D)g;
|
|
864 |
Stroke stroke = g2d.getStroke();
|
|
865 |
g2d.setStroke(new BasicStroke((float)lineWidth));
|
|
866 |
g2d.drawLine(x1, y1, x2, y2);
|
|
867 |
g2d.setStroke(stroke);
|
|
868 |
} else {
|
|
869 |
g.drawLine(x1, y1, x2, y2);
|
|
870 |
}
|
|
871 |
}
|
|
872 |
|
|
873 |
protected void drawRectangle(Node node, Graphics g) {
|
|
874 |
NamedNodeMap attrs = node.getAttributes();
|
|
875 |
Color color = parseColor(getStringAttr(attrs, "color"));
|
|
876 |
boolean filled = getBooleanAttr(node, "filled", false);
|
|
877 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
878 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
879 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
880 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
881 |
g.setColor(color);
|
|
882 |
if (getInt("width") == -1) {
|
|
883 |
x -= w;
|
|
884 |
}
|
|
885 |
if (getInt("height") == -1) {
|
|
886 |
y -= h;
|
|
887 |
}
|
|
888 |
if (filled) {
|
|
889 |
g.fillRect(x, y, w, h);
|
|
890 |
} else {
|
|
891 |
g.drawRect(x, y, w, h);
|
|
892 |
}
|
|
893 |
}
|
|
894 |
|
|
895 |
protected void drawTile(Node node, Graphics g, JInternalFrame jif) {
|
|
896 |
NamedNodeMap attrs = node.getAttributes();
|
|
897 |
int x0 = aee.evaluate(getStringAttr(attrs, "x"));
|
|
898 |
int y0 = aee.evaluate(getStringAttr(attrs, "y"));
|
|
899 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
900 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
901 |
int tw = aee.evaluate(getStringAttr(attrs, "tile_width"));
|
|
902 |
int th = aee.evaluate(getStringAttr(attrs, "tile_height"));
|
|
903 |
int width = getInt("width");
|
|
904 |
int height = getInt("height");
|
|
905 |
if (width == -1) {
|
|
906 |
x0 -= w;
|
|
907 |
}
|
|
908 |
if (height == -1) {
|
|
909 |
y0 -= h;
|
|
910 |
}
|
|
911 |
Shape oldClip = g.getClip();
|
|
912 |
if (g instanceof Graphics2D) {
|
|
913 |
((Graphics2D)g).clip(new Rectangle(x0, y0, w, h));
|
|
914 |
}
|
|
915 |
variables.put("width", tw);
|
|
916 |
variables.put("height", th);
|
|
917 |
|
|
918 |
Node draw_ops = getNode("draw_ops", new String[] { "name", getStringAttr(node, "name") });
|
|
919 |
|
|
920 |
int y = y0;
|
|
921 |
while (y < y0 + h) {
|
|
922 |
int x = x0;
|
|
923 |
while (x < x0 + w) {
|
|
924 |
g.translate(x, y);
|
|
925 |
draw(draw_ops, g, jif);
|
|
926 |
g.translate(-x, -y);
|
|
927 |
x += tw;
|
|
928 |
}
|
|
929 |
y += th;
|
|
930 |
}
|
|
931 |
|
|
932 |
variables.put("width", width);
|
|
933 |
variables.put("height", height);
|
|
934 |
g.setClip(oldClip);
|
|
935 |
}
|
|
936 |
|
|
937 |
protected void drawTint(Node node, Graphics g) {
|
|
938 |
NamedNodeMap attrs = node.getAttributes();
|
|
939 |
Color color = parseColor(getStringAttr(attrs, "color"));
|
|
940 |
float alpha = Float.parseFloat(getStringAttr(attrs, "alpha"));
|
|
941 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
942 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
943 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
944 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
945 |
if (getInt("width") == -1) {
|
|
946 |
x -= w;
|
|
947 |
}
|
|
948 |
if (getInt("height") == -1) {
|
|
949 |
y -= h;
|
|
950 |
}
|
|
951 |
if (g instanceof Graphics2D) {
|
|
952 |
Graphics2D g2 = (Graphics2D)g;
|
|
953 |
Composite oldComp = g2.getComposite();
|
|
954 |
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
|
|
955 |
g2.setComposite(ac);
|
|
956 |
g2.setColor(color);
|
|
957 |
g2.fillRect(x, y, w, h);
|
|
958 |
g2.setComposite(oldComp);
|
|
959 |
}
|
|
960 |
}
|
|
961 |
|
|
962 |
protected void drawTitle(Node node, Graphics g, JInternalFrame jif) {
|
|
963 |
NamedNodeMap attrs = node.getAttributes();
|
|
964 |
String colorStr = getStringAttr(attrs, "color");
|
|
965 |
int i = colorStr.indexOf("gtk:fg[");
|
|
966 |
if (i > 0) {
|
|
967 |
colorStr = colorStr.substring(0, i) + "gtk:text[" + colorStr.substring(i+7);
|
|
968 |
}
|
|
969 |
Color color = parseColor(colorStr);
|
|
970 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
971 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
972 |
|
|
973 |
String title = jif.getTitle();
|
|
974 |
if (title != null) {
|
|
975 |
FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
|
|
976 |
if (jif.getComponentOrientation().isLeftToRight()) {
|
|
977 |
title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,
|
|
978 |
calculateTitleTextWidth(g, jif));
|
|
979 |
}
|
|
980 |
g.setColor(color);
|
|
981 |
SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent());
|
|
982 |
}
|
|
983 |
}
|
|
984 |
|
|
985 |
protected Dimension calculateButtonSize(JComponent titlePane) {
|
|
986 |
int buttonHeight = getInt("button_height");
|
|
987 |
if (buttonHeight == 0) {
|
|
988 |
buttonHeight = titlePane.getHeight();
|
|
989 |
if (buttonHeight == 0) {
|
|
990 |
buttonHeight = 13;
|
|
991 |
} else {
|
|
992 |
Insets button_border = (Insets)frameGeometry.get("button_border");
|
|
993 |
if (button_border != null) {
|
|
994 |
buttonHeight -= (button_border.top + button_border.bottom);
|
|
995 |
}
|
|
996 |
}
|
|
997 |
}
|
|
998 |
int buttonWidth = getInt("button_width");
|
|
999 |
if (buttonWidth == 0) {
|
|
1000 |
buttonWidth = buttonHeight;
|
|
1001 |
Float aspect_ratio = (Float)frameGeometry.get("aspect_ratio");
|
|
1002 |
if (aspect_ratio != null) {
|
|
1003 |
buttonWidth = (int)(buttonHeight / aspect_ratio.floatValue());
|
|
1004 |
}
|
|
1005 |
}
|
|
1006 |
return new Dimension(buttonWidth, buttonHeight);
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
protected Rectangle calculateTitleArea(JInternalFrame jif) {
|
|
1010 |
JComponent titlePane = findChild(jif, "InternalFrame.northPane");
|
|
1011 |
Dimension buttonDim = calculateButtonSize(titlePane);
|
|
1012 |
Insets title_border = (Insets)frameGeometry.get("title_border");
|
|
1013 |
Rectangle r = new Rectangle();
|
|
1014 |
|
|
1015 |
r.x = getInt("left_titlebar_edge") + buttonDim.width;
|
|
1016 |
r.y = 0;
|
|
1017 |
r.height = titlePane.getHeight();
|
|
1018 |
if (title_border != null) {
|
|
1019 |
r.x += title_border.left;
|
|
1020 |
r.y += title_border.top;
|
|
1021 |
r.height -= (title_border.top + title_border.bottom);
|
|
1022 |
}
|
|
1023 |
|
|
1024 |
r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge");
|
|
1025 |
if (jif.isClosable()) {
|
|
1026 |
r.width -= buttonDim.width;
|
|
1027 |
}
|
|
1028 |
if (jif.isMaximizable()) {
|
|
1029 |
r.width -= buttonDim.width;
|
|
1030 |
}
|
|
1031 |
if (jif.isIconifiable()) {
|
|
1032 |
r.width -= buttonDim.width;
|
|
1033 |
}
|
|
1034 |
if (title_border != null) {
|
|
1035 |
r.width -= title_border.right;
|
|
1036 |
}
|
|
1037 |
return r;
|
|
1038 |
}
|
|
1039 |
|
|
1040 |
|
|
1041 |
protected int calculateTitleTextWidth(Graphics g, JInternalFrame jif) {
|
|
1042 |
String title = jif.getTitle();
|
|
1043 |
if (title != null) {
|
|
1044 |
Rectangle r = calculateTitleArea(jif);
|
|
1045 |
return Math.min(SwingUtilities2.stringWidth(jif,
|
|
1046 |
SwingUtilities2.getFontMetrics(jif, g), title), r.width);
|
|
1047 |
}
|
|
1048 |
return 0;
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
protected void setClip(Node node, Graphics g) {
|
|
1052 |
NamedNodeMap attrs = node.getAttributes();
|
|
1053 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1054 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
1055 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
1056 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
1057 |
if (getInt("width") == -1) {
|
|
1058 |
x -= w;
|
|
1059 |
}
|
|
1060 |
if (getInt("height") == -1) {
|
|
1061 |
y -= h;
|
|
1062 |
}
|
|
1063 |
if (g instanceof Graphics2D) {
|
|
1064 |
((Graphics2D)g).clip(new Rectangle(x, y, w, h));
|
|
1065 |
}
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
protected void drawGTKArrow(Node node, Graphics g) {
|
|
1069 |
NamedNodeMap attrs = node.getAttributes();
|
|
1070 |
String arrow = getStringAttr(attrs, "arrow");
|
|
1071 |
String shadow = getStringAttr(attrs, "shadow");
|
|
1072 |
String stateStr = getStringAttr(attrs, "state").toUpperCase();
|
|
1073 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1074 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
1075 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
1076 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
1077 |
|
|
1078 |
int state = -1;
|
|
1079 |
if ("NORMAL".equals(stateStr)) {
|
|
1080 |
state = ENABLED;
|
|
1081 |
} else if ("SELECTED".equals(stateStr)) {
|
|
1082 |
state = SELECTED;
|
|
1083 |
} else if ("INSENSITIVE".equals(stateStr)) {
|
|
1084 |
state = DISABLED;
|
|
1085 |
} else if ("PRELIGHT".equals(stateStr)) {
|
|
1086 |
state = MOUSE_OVER;
|
|
1087 |
}
|
|
1088 |
|
|
1089 |
ShadowType shadowType = null;
|
|
1090 |
if ("in".equals(shadow)) {
|
|
1091 |
shadowType = ShadowType.IN;
|
|
1092 |
} else if ("out".equals(shadow)) {
|
|
1093 |
shadowType = ShadowType.OUT;
|
|
1094 |
} else if ("etched_in".equals(shadow)) {
|
|
1095 |
shadowType = ShadowType.ETCHED_IN;
|
|
1096 |
} else if ("etched_out".equals(shadow)) {
|
|
1097 |
shadowType = ShadowType.ETCHED_OUT;
|
|
1098 |
} else if ("none".equals(shadow)) {
|
|
1099 |
shadowType = ShadowType.NONE;
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
ArrowType direction = null;
|
|
1103 |
if ("up".equals(arrow)) {
|
|
1104 |
direction = ArrowType.UP;
|
|
1105 |
} else if ("down".equals(arrow)) {
|
|
1106 |
direction = ArrowType.DOWN;
|
|
1107 |
} else if ("left".equals(arrow)) {
|
|
1108 |
direction = ArrowType.LEFT;
|
|
1109 |
} else if ("right".equals(arrow)) {
|
|
1110 |
direction = ArrowType.RIGHT;
|
|
1111 |
}
|
|
1112 |
|
|
1113 |
GTKPainter.INSTANCE.paintMetacityElement(context, g, state,
|
|
1114 |
"metacity-arrow", x, y, w, h, shadowType, direction);
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
protected void drawGTKBox(Node node, Graphics g) {
|
|
1118 |
NamedNodeMap attrs = node.getAttributes();
|
|
1119 |
String shadow = getStringAttr(attrs, "shadow");
|
|
1120 |
String stateStr = getStringAttr(attrs, "state").toUpperCase();
|
|
1121 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1122 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
1123 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
1124 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
1125 |
|
|
1126 |
int state = -1;
|
|
1127 |
if ("NORMAL".equals(stateStr)) {
|
|
1128 |
state = ENABLED;
|
|
1129 |
} else if ("SELECTED".equals(stateStr)) {
|
|
1130 |
state = SELECTED;
|
|
1131 |
} else if ("INSENSITIVE".equals(stateStr)) {
|
|
1132 |
state = DISABLED;
|
|
1133 |
} else if ("PRELIGHT".equals(stateStr)) {
|
|
1134 |
state = MOUSE_OVER;
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
ShadowType shadowType = null;
|
|
1138 |
if ("in".equals(shadow)) {
|
|
1139 |
shadowType = ShadowType.IN;
|
|
1140 |
} else if ("out".equals(shadow)) {
|
|
1141 |
shadowType = ShadowType.OUT;
|
|
1142 |
} else if ("etched_in".equals(shadow)) {
|
|
1143 |
shadowType = ShadowType.ETCHED_IN;
|
|
1144 |
} else if ("etched_out".equals(shadow)) {
|
|
1145 |
shadowType = ShadowType.ETCHED_OUT;
|
|
1146 |
} else if ("none".equals(shadow)) {
|
|
1147 |
shadowType = ShadowType.NONE;
|
|
1148 |
}
|
|
1149 |
GTKPainter.INSTANCE.paintMetacityElement(context, g, state,
|
|
1150 |
"metacity-box", x, y, w, h, shadowType, null);
|
|
1151 |
}
|
|
1152 |
|
|
1153 |
protected void drawGTKVLine(Node node, Graphics g) {
|
|
1154 |
NamedNodeMap attrs = node.getAttributes();
|
|
1155 |
String stateStr = getStringAttr(attrs, "state").toUpperCase();
|
|
1156 |
|
|
1157 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1158 |
int y1 = aee.evaluate(getStringAttr(attrs, "y1"));
|
|
1159 |
int y2 = aee.evaluate(getStringAttr(attrs, "y2"));
|
|
1160 |
|
|
1161 |
int state = -1;
|
|
1162 |
if ("NORMAL".equals(stateStr)) {
|
|
1163 |
state = ENABLED;
|
|
1164 |
} else if ("SELECTED".equals(stateStr)) {
|
|
1165 |
state = SELECTED;
|
|
1166 |
} else if ("INSENSITIVE".equals(stateStr)) {
|
|
1167 |
state = DISABLED;
|
|
1168 |
} else if ("PRELIGHT".equals(stateStr)) {
|
|
1169 |
state = MOUSE_OVER;
|
|
1170 |
}
|
|
1171 |
|
|
1172 |
GTKPainter.INSTANCE.paintMetacityElement(context, g, state,
|
|
1173 |
"metacity-vline", x, y1, 1, y2 - y1, null, null);
|
|
1174 |
}
|
|
1175 |
|
|
1176 |
protected void drawGradient(Node node, Graphics g) {
|
|
1177 |
NamedNodeMap attrs = node.getAttributes();
|
|
1178 |
String type = getStringAttr(attrs, "type");
|
|
1179 |
float alpha = getFloatAttr(node, "alpha", -1F);
|
|
1180 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1181 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
1182 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
1183 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
1184 |
if (getInt("width") == -1) {
|
|
1185 |
x -= w;
|
|
1186 |
}
|
|
1187 |
if (getInt("height") == -1) {
|
|
1188 |
y -= h;
|
|
1189 |
}
|
|
1190 |
|
|
1191 |
// Get colors from child nodes
|
|
1192 |
Node[] colorNodes = getNodesByName(node, "color");
|
|
1193 |
Color[] colors = new Color[colorNodes.length];
|
|
1194 |
for (int i = 0; i < colorNodes.length; i++) {
|
|
1195 |
colors[i] = parseColor(getStringAttr(colorNodes[i], "value"));
|
|
1196 |
}
|
|
1197 |
|
|
1198 |
boolean horizontal = ("diagonal".equals(type) || "horizontal".equals(type));
|
|
1199 |
boolean vertical = ("diagonal".equals(type) || "vertical".equals(type));
|
|
1200 |
|
|
1201 |
if (g instanceof Graphics2D) {
|
|
1202 |
Graphics2D g2 = (Graphics2D)g;
|
|
1203 |
Composite oldComp = g2.getComposite();
|
|
1204 |
if (alpha >= 0F) {
|
|
1205 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
|
|
1206 |
}
|
|
1207 |
int n = colors.length - 1;
|
|
1208 |
for (int i = 0; i < n; i++) {
|
|
1209 |
g2.setPaint(new GradientPaint(x + (horizontal ? (i*w/n) : 0),
|
|
1210 |
y + (vertical ? (i*h/n) : 0),
|
|
1211 |
colors[i],
|
|
1212 |
x + (horizontal ? ((i+1)*w/n) : 0),
|
|
1213 |
y + (vertical ? ((i+1)*h/n) : 0),
|
|
1214 |
colors[i+1]));
|
|
1215 |
g2.fillRect(x + (horizontal ? (i*w/n) : 0),
|
|
1216 |
y + (vertical ? (i*h/n) : 0),
|
|
1217 |
(horizontal ? (w/n) : w),
|
|
1218 |
(vertical ? (h/n) : h));
|
|
1219 |
}
|
|
1220 |
g2.setComposite(oldComp);
|
|
1221 |
}
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
protected void drawImage(Node node, Graphics g) {
|
|
1225 |
NamedNodeMap attrs = node.getAttributes();
|
|
1226 |
String filename = getStringAttr(attrs, "filename");
|
|
1227 |
String colorizeStr = getStringAttr(attrs, "colorize");
|
|
1228 |
Color colorize = (colorizeStr != null) ? parseColor(colorizeStr) : null;
|
|
1229 |
String alpha = getStringAttr(attrs, "alpha");
|
|
1230 |
Image object = (colorize != null) ? getImage(filename, colorize) : getImage(filename);
|
|
1231 |
variables.put("object_width", object.getWidth(null));
|
|
1232 |
variables.put("object_height", object.getHeight(null));
|
|
1233 |
String fill_type = getStringAttr(attrs, "fill_type");
|
|
1234 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1235 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
1236 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
1237 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
1238 |
if (getInt("width") == -1) {
|
|
1239 |
x -= w;
|
|
1240 |
}
|
|
1241 |
if (getInt("height") == -1) {
|
|
1242 |
y -= h;
|
|
1243 |
}
|
|
1244 |
|
|
1245 |
if (alpha != null) {
|
|
1246 |
if ("tile".equals(fill_type)) {
|
|
1247 |
StringTokenizer tokenizer = new StringTokenizer(alpha, ":");
|
|
1248 |
float[] alphas = new float[tokenizer.countTokens()];
|
|
1249 |
for (int i = 0; i < alphas.length; i++) {
|
|
1250 |
alphas[i] = Float.parseFloat(tokenizer.nextToken());
|
|
1251 |
}
|
|
1252 |
tileImage(g, object, x, y, w, h, alphas);
|
|
1253 |
} else {
|
|
1254 |
float a = Float.parseFloat(alpha);
|
|
1255 |
if (g instanceof Graphics2D) {
|
|
1256 |
Graphics2D g2 = (Graphics2D)g;
|
|
1257 |
Composite oldComp = g2.getComposite();
|
|
1258 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a));
|
|
1259 |
g2.drawImage(object, x, y, w, h, null);
|
|
1260 |
g2.setComposite(oldComp);
|
|
1261 |
}
|
|
1262 |
}
|
|
1263 |
} else {
|
|
1264 |
g.drawImage(object, x, y, w, h, null);
|
|
1265 |
}
|
|
1266 |
}
|
|
1267 |
|
|
1268 |
protected void drawIcon(Node node, Graphics g, JInternalFrame jif) {
|
|
1269 |
Icon icon = jif.getFrameIcon();
|
|
1270 |
if (icon == null) {
|
|
1271 |
return;
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
NamedNodeMap attrs = node.getAttributes();
|
|
1275 |
String alpha = getStringAttr(attrs, "alpha");
|
|
1276 |
int x = aee.evaluate(getStringAttr(attrs, "x"));
|
|
1277 |
int y = aee.evaluate(getStringAttr(attrs, "y"));
|
|
1278 |
int w = aee.evaluate(getStringAttr(attrs, "width"));
|
|
1279 |
int h = aee.evaluate(getStringAttr(attrs, "height"));
|
|
1280 |
if (getInt("width") == -1) {
|
|
1281 |
x -= w;
|
|
1282 |
}
|
|
1283 |
if (getInt("height") == -1) {
|
|
1284 |
y -= h;
|
|
1285 |
}
|
|
1286 |
|
|
1287 |
if (alpha != null) {
|
|
1288 |
float a = Float.parseFloat(alpha);
|
|
1289 |
if (g instanceof Graphics2D) {
|
|
1290 |
Graphics2D g2 = (Graphics2D)g;
|
|
1291 |
Composite oldComp = g2.getComposite();
|
|
1292 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a));
|
|
1293 |
icon.paintIcon(jif, g, x, y);
|
|
1294 |
g2.setComposite(oldComp);
|
|
1295 |
}
|
|
1296 |
} else {
|
|
1297 |
icon.paintIcon(jif, g, x, y);
|
|
1298 |
}
|
|
1299 |
}
|
|
1300 |
|
|
1301 |
protected void drawInclude(Node node, Graphics g, JInternalFrame jif) {
|
|
1302 |
int oldWidth = getInt("width");
|
|
1303 |
int oldHeight = getInt("height");
|
|
1304 |
|
|
1305 |
NamedNodeMap attrs = node.getAttributes();
|
|
1306 |
int x = aee.evaluate(getStringAttr(attrs, "x"), 0);
|
|
1307 |
int y = aee.evaluate(getStringAttr(attrs, "y"), 0);
|
|
1308 |
int w = aee.evaluate(getStringAttr(attrs, "width"), -1);
|
|
1309 |
int h = aee.evaluate(getStringAttr(attrs, "height"), -1);
|
|
1310 |
|
|
1311 |
if (w != -1) {
|
|
1312 |
variables.put("width", w);
|
|
1313 |
}
|
|
1314 |
if (h != -1) {
|
|
1315 |
variables.put("height", h);
|
|
1316 |
}
|
|
1317 |
|
|
1318 |
Node draw_ops = getNode("draw_ops", new String[] {
|
|
1319 |
"name", getStringAttr(node, "name")
|
|
1320 |
});
|
|
1321 |
g.translate(x, y);
|
|
1322 |
draw(draw_ops, g, jif);
|
|
1323 |
g.translate(-x, -y);
|
|
1324 |
|
|
1325 |
if (w != -1) {
|
|
1326 |
variables.put("width", oldWidth);
|
|
1327 |
}
|
|
1328 |
if (h != -1) {
|
|
1329 |
variables.put("height", oldHeight);
|
|
1330 |
}
|
|
1331 |
}
|
|
1332 |
|
|
1333 |
protected void draw(Node draw_ops, Graphics g, JInternalFrame jif) {
|
|
1334 |
if (draw_ops != null) {
|
|
1335 |
NodeList nodes = draw_ops.getChildNodes();
|
|
1336 |
if (nodes != null) {
|
|
1337 |
Shape oldClip = g.getClip();
|
|
1338 |
for (int i = 0; i < nodes.getLength(); i++) {
|
|
1339 |
Node child = nodes.item(i);
|
|
1340 |
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
|
1341 |
try {
|
|
1342 |
String name = child.getNodeName();
|
|
1343 |
if ("include".equals(name)) {
|
|
1344 |
drawInclude(child, g, jif);
|
|
1345 |
} else if ("arc".equals(name)) {
|
|
1346 |
drawArc(child, g);
|
|
1347 |
} else if ("clip".equals(name)) {
|
|
1348 |
setClip(child, g);
|
|
1349 |
} else if ("gradient".equals(name)) {
|
|
1350 |
drawGradient(child, g);
|
|
1351 |
} else if ("gtk_arrow".equals(name)) {
|
|
1352 |
drawGTKArrow(child, g);
|
|
1353 |
} else if ("gtk_box".equals(name)) {
|
|
1354 |
drawGTKBox(child, g);
|
|
1355 |
} else if ("gtk_vline".equals(name)) {
|
|
1356 |
drawGTKVLine(child, g);
|
|
1357 |
} else if ("image".equals(name)) {
|
|
1358 |
drawImage(child, g);
|
|
1359 |
} else if ("icon".equals(name)) {
|
|
1360 |
drawIcon(child, g, jif);
|
|
1361 |
} else if ("line".equals(name)) {
|
|
1362 |
drawLine(child, g);
|
|
1363 |
} else if ("rectangle".equals(name)) {
|
|
1364 |
drawRectangle(child, g);
|
|
1365 |
} else if ("tint".equals(name)) {
|
|
1366 |
drawTint(child, g);
|
|
1367 |
} else if ("tile".equals(name)) {
|
|
1368 |
drawTile(child, g, jif);
|
|
1369 |
} else if ("title".equals(name)) {
|
|
1370 |
drawTitle(child, g, jif);
|
|
1371 |
} else {
|
|
1372 |
System.err.println("Unknown Metacity drawing op: "+child);
|
|
1373 |
}
|
|
1374 |
} catch (NumberFormatException ex) {
|
|
1375 |
logError(themeName, ex);
|
|
1376 |
}
|
|
1377 |
}
|
|
1378 |
}
|
|
1379 |
g.setClip(oldClip);
|
|
1380 |
}
|
|
1381 |
}
|
|
1382 |
}
|
|
1383 |
|
|
1384 |
protected void drawPiece(Node frame_style, Graphics g, String position, int x, int y,
|
|
1385 |
int width, int height, JInternalFrame jif) {
|
|
1386 |
Node piece = getNode(frame_style, "piece", new String[] { "position", position });
|
|
1387 |
if (piece != null) {
|
|
1388 |
Node draw_ops;
|
|
1389 |
String draw_ops_name = getStringAttr(piece, "draw_ops");
|
|
1390 |
if (draw_ops_name != null) {
|
|
1391 |
draw_ops = getNode("draw_ops", new String[] { "name", draw_ops_name });
|
|
1392 |
} else {
|
|
1393 |
draw_ops = getNode(piece, "draw_ops", null);
|
|
1394 |
}
|
|
1395 |
variables.put("width", width);
|
|
1396 |
variables.put("height", height);
|
|
1397 |
g.translate(x, y);
|
|
1398 |
draw(draw_ops, g, jif);
|
|
1399 |
g.translate(-x, -y);
|
|
1400 |
}
|
|
1401 |
}
|
|
1402 |
|
|
1403 |
|
|
1404 |
Insets getBorderInsets(SynthContext context, Insets insets) {
|
|
1405 |
updateFrameGeometry(context);
|
|
1406 |
|
|
1407 |
if (insets == null) {
|
|
1408 |
insets = new Insets(0, 0, 0, 0);
|
|
1409 |
}
|
|
1410 |
insets.top = ((Insets)frameGeometry.get("title_border")).top;
|
|
1411 |
insets.bottom = getInt("bottom_height");
|
|
1412 |
insets.left = getInt("left_width");
|
|
1413 |
insets.right = getInt("right_width");
|
|
1414 |
return insets;
|
|
1415 |
}
|
|
1416 |
|
|
1417 |
|
|
1418 |
private void updateFrameGeometry(SynthContext context) {
|
|
1419 |
this.context = context;
|
|
1420 |
JComponent comp = context.getComponent();
|
|
1421 |
JComponent titlePane = findChild(comp, "InternalFrame.northPane");
|
|
1422 |
|
|
1423 |
JInternalFrame jif = null;
|
|
1424 |
if (comp instanceof JInternalFrame) {
|
|
1425 |
jif = (JInternalFrame)comp;
|
|
1426 |
} else if (comp instanceof JInternalFrame.JDesktopIcon) {
|
|
1427 |
jif = ((JInternalFrame.JDesktopIcon)comp).getInternalFrame();
|
|
1428 |
} else {
|
|
1429 |
assert false : "component is not JInternalFrame or JInternalFrame.JDesktopIcon";
|
|
1430 |
return;
|
|
1431 |
}
|
|
1432 |
|
|
1433 |
if (frame_style_set == null) {
|
|
1434 |
Node window = getNode("window", new String[]{"type", "normal"});
|
|
1435 |
|
|
1436 |
if (window != null) {
|
|
1437 |
frame_style_set = getNode("frame_style_set",
|
|
1438 |
new String[] {"name", getStringAttr(window, "style_set")});
|
|
1439 |
}
|
|
1440 |
|
|
1441 |
if (frame_style_set == null) {
|
|
1442 |
frame_style_set = getNode("frame_style_set", new String[] {"name", "normal"});
|
|
1443 |
}
|
|
1444 |
}
|
|
1445 |
|
|
1446 |
if (frame_style_set != null) {
|
|
1447 |
Node frame = getNode(frame_style_set, "frame", new String[] {
|
|
1448 |
"focus", (jif.isSelected() ? "yes" : "no"),
|
|
1449 |
"state", (jif.isMaximum() ? "maximized" : "normal")
|
|
1450 |
});
|
|
1451 |
|
|
1452 |
if (frame != null) {
|
|
1453 |
Node frame_style = getNode("frame_style", new String[] {
|
|
1454 |
"name", getStringAttr(frame, "style")
|
|
1455 |
});
|
|
1456 |
if (frame_style != null) {
|
|
1457 |
Map gm = frameGeometries.get(getStringAttr(frame_style, "geometry"));
|
|
1458 |
|
|
1459 |
setFrameGeometry(titlePane, gm);
|
|
1460 |
}
|
|
1461 |
}
|
|
1462 |
}
|
|
1463 |
}
|
|
1464 |
|
|
1465 |
|
|
1466 |
protected static void logError(String themeName, Exception ex) {
|
|
1467 |
logError(themeName, ex.toString());
|
|
1468 |
}
|
|
1469 |
|
|
1470 |
protected static void logError(String themeName, String msg) {
|
|
1471 |
if (!errorLogged) {
|
|
1472 |
System.err.println("Exception in Metacity for theme \""+themeName+"\": "+msg);
|
|
1473 |
errorLogged = true;
|
|
1474 |
}
|
|
1475 |
}
|
|
1476 |
|
|
1477 |
|
|
1478 |
// XML Parsing
|
|
1479 |
|
|
1480 |
|
|
1481 |
protected static Document getXMLDoc(final URL xmlFile)
|
|
1482 |
throws IOException,
|
|
1483 |
ParserConfigurationException,
|
|
1484 |
SAXException {
|
|
1485 |
if (documentBuilder == null) {
|
|
1486 |
documentBuilder =
|
|
1487 |
DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
1488 |
}
|
|
1489 |
InputStream inputStream =
|
|
1490 |
(InputStream)AccessController.doPrivileged(new PrivilegedAction() {
|
|
1491 |
public Object run() {
|
|
1492 |
try {
|
|
1493 |
return new BufferedInputStream(xmlFile.openStream());
|
|
1494 |
} catch (IOException ex) {
|
|
1495 |
return null;
|
|
1496 |
}
|
|
1497 |
}
|
|
1498 |
});
|
|
1499 |
|
|
1500 |
Document doc = null;
|
|
1501 |
if (inputStream != null) {
|
|
1502 |
doc = documentBuilder.parse(inputStream);
|
|
1503 |
}
|
|
1504 |
return doc;
|
|
1505 |
}
|
|
1506 |
|
|
1507 |
|
|
1508 |
protected Node[] getNodesByName(Node parent, String name) {
|
|
1509 |
NodeList nodes = parent.getChildNodes(); // ElementNode
|
|
1510 |
int n = nodes.getLength();
|
|
1511 |
ArrayList<Node> list = new ArrayList();
|
|
1512 |
for (int i=0; i < n; i++) {
|
|
1513 |
Node node = nodes.item(i);
|
|
1514 |
if (name.equals(node.getNodeName())) {
|
|
1515 |
list.add(node);
|
|
1516 |
}
|
|
1517 |
}
|
|
1518 |
return list.toArray(new Node[list.size()]);
|
|
1519 |
}
|
|
1520 |
|
|
1521 |
|
|
1522 |
|
|
1523 |
protected Node getNode(String tagName, String[] attrs) {
|
|
1524 |
NodeList nodes = xmlDoc.getElementsByTagName(tagName);
|
|
1525 |
return (nodes != null) ? getNode(nodes, tagName, attrs) : null;
|
|
1526 |
}
|
|
1527 |
|
|
1528 |
protected Node getNode(Node parent, String name, String[] attrs) {
|
|
1529 |
Node node = null;
|
|
1530 |
NodeList nodes = parent.getChildNodes();
|
|
1531 |
if (nodes != null) {
|
|
1532 |
node = getNode(nodes, name, attrs);
|
|
1533 |
}
|
|
1534 |
if (node == null) {
|
|
1535 |
String inheritFrom = getStringAttr(parent, "parent");
|
|
1536 |
if (inheritFrom != null) {
|
|
1537 |
Node inheritFromNode = getNode(parent.getParentNode(),
|
|
1538 |
parent.getNodeName(),
|
|
1539 |
new String[] { "name", inheritFrom });
|
|
1540 |
if (inheritFromNode != null) {
|
|
1541 |
node = getNode(inheritFromNode, name, attrs);
|
|
1542 |
}
|
|
1543 |
}
|
|
1544 |
}
|
|
1545 |
return node;
|
|
1546 |
}
|
|
1547 |
|
|
1548 |
protected Node getNode(NodeList nodes, String name, String[] attrs) {
|
|
1549 |
int n = nodes.getLength();
|
|
1550 |
for (int i=0; i < n; i++) {
|
|
1551 |
Node node = nodes.item(i);
|
|
1552 |
if (name.equals(node.getNodeName())) {
|
|
1553 |
if (attrs != null) {
|
|
1554 |
NamedNodeMap nodeAttrs = node.getAttributes();
|
|
1555 |
if (nodeAttrs != null) {
|
|
1556 |
boolean matches = true;
|
|
1557 |
int nAttrs = attrs.length / 2;
|
|
1558 |
for (int a = 0; a < nAttrs; a++) {
|
|
1559 |
String aName = attrs[a * 2];
|
|
1560 |
String aValue = attrs[a * 2 + 1];
|
|
1561 |
Node attr = nodeAttrs.getNamedItem(aName);
|
|
1562 |
if (attr == null ||
|
|
1563 |
aValue != null && !aValue.equals((String)attr.getNodeValue())) {
|
|
1564 |
matches = false;
|
|
1565 |
break;
|
|
1566 |
}
|
|
1567 |
}
|
|
1568 |
if (matches) {
|
|
1569 |
return node;
|
|
1570 |
}
|
|
1571 |
}
|
|
1572 |
} else {
|
|
1573 |
return node;
|
|
1574 |
}
|
|
1575 |
}
|
|
1576 |
}
|
|
1577 |
return null;
|
|
1578 |
}
|
|
1579 |
|
|
1580 |
protected String getStringAttr(Node node, String name) {
|
|
1581 |
String value = null;
|
|
1582 |
NamedNodeMap attrs = node.getAttributes();
|
|
1583 |
if (attrs != null) {
|
|
1584 |
value = getStringAttr(attrs, name);
|
|
1585 |
if (value == null) {
|
|
1586 |
String inheritFrom = getStringAttr(attrs, "parent");
|
|
1587 |
if (inheritFrom != null) {
|
|
1588 |
Node inheritFromNode = getNode(node.getParentNode(),
|
|
1589 |
node.getNodeName(),
|
|
1590 |
new String[] { "name", inheritFrom });
|
|
1591 |
if (inheritFromNode != null) {
|
|
1592 |
value = getStringAttr(inheritFromNode, name);
|
|
1593 |
}
|
|
1594 |
}
|
|
1595 |
}
|
|
1596 |
}
|
|
1597 |
return value;
|
|
1598 |
}
|
|
1599 |
|
|
1600 |
protected String getStringAttr(NamedNodeMap attrs, String name) {
|
|
1601 |
Node item = attrs.getNamedItem(name);
|
|
1602 |
return (item != null) ? (String)item.getNodeValue() : null;
|
|
1603 |
}
|
|
1604 |
|
|
1605 |
protected boolean getBooleanAttr(Node node, String name, boolean fallback) {
|
|
1606 |
String str = getStringAttr(node, name);
|
|
1607 |
if (str != null) {
|
|
1608 |
return Boolean.valueOf(str).booleanValue();
|
|
1609 |
}
|
|
1610 |
return fallback;
|
|
1611 |
}
|
|
1612 |
|
|
1613 |
protected int getIntAttr(Node node, String name, int fallback) {
|
|
1614 |
String str = getStringAttr(node, name);
|
|
1615 |
int value = fallback;
|
|
1616 |
if (str != null) {
|
|
1617 |
try {
|
|
1618 |
value = Integer.parseInt(str);
|
|
1619 |
} catch (NumberFormatException ex) {
|
|
1620 |
logError(themeName, ex);
|
|
1621 |
}
|
|
1622 |
}
|
|
1623 |
return value;
|
|
1624 |
}
|
|
1625 |
|
|
1626 |
protected float getFloatAttr(Node node, String name, float fallback) {
|
|
1627 |
String str = getStringAttr(node, name);
|
|
1628 |
float value = fallback;
|
|
1629 |
if (str != null) {
|
|
1630 |
try {
|
|
1631 |
value = Float.parseFloat(str);
|
|
1632 |
} catch (NumberFormatException ex) {
|
|
1633 |
logError(themeName, ex);
|
|
1634 |
}
|
|
1635 |
}
|
|
1636 |
return value;
|
|
1637 |
}
|
|
1638 |
|
|
1639 |
|
|
1640 |
|
|
1641 |
protected Color parseColor(String str) {
|
|
1642 |
StringTokenizer tokenizer = new StringTokenizer(str, "/");
|
|
1643 |
int n = tokenizer.countTokens();
|
|
1644 |
if (n > 1) {
|
|
1645 |
String function = tokenizer.nextToken();
|
|
1646 |
if ("shade".equals(function)) {
|
|
1647 |
assert (n == 3);
|
|
1648 |
Color c = parseColor2(tokenizer.nextToken());
|
|
1649 |
float alpha = Float.parseFloat(tokenizer.nextToken());
|
|
1650 |
return GTKColorType.adjustColor(c, 1.0F, alpha, alpha);
|
|
1651 |
} else if ("blend".equals(function)) {
|
|
1652 |
assert (n == 4);
|
|
1653 |
Color bg = parseColor2(tokenizer.nextToken());
|
|
1654 |
Color fg = parseColor2(tokenizer.nextToken());
|
|
1655 |
float alpha = Float.parseFloat(tokenizer.nextToken());
|
|
1656 |
if (alpha > 1.0f) {
|
|
1657 |
alpha = 1.0f / alpha;
|
|
1658 |
}
|
|
1659 |
|
|
1660 |
return new Color((int)(bg.getRed() + ((fg.getRed() - bg.getRed()) * alpha)),
|
|
1661 |
(int)(bg.getRed() + ((fg.getRed() - bg.getRed()) * alpha)),
|
|
1662 |
(int)(bg.getRed() + ((fg.getRed() - bg.getRed()) * alpha)));
|
|
1663 |
} else {
|
|
1664 |
System.err.println("Unknown Metacity color function="+str);
|
|
1665 |
return null;
|
|
1666 |
}
|
|
1667 |
} else {
|
|
1668 |
return parseColor2(str);
|
|
1669 |
}
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
protected Color parseColor2(String str) {
|
|
1673 |
Color c = null;
|
|
1674 |
if (str.startsWith("gtk:")) {
|
|
1675 |
int i1 = str.indexOf('[');
|
|
1676 |
if (i1 > 3) {
|
|
1677 |
String typeStr = str.substring(4, i1).toLowerCase();
|
|
1678 |
int i2 = str.indexOf(']');
|
|
1679 |
if (i2 > i1+1) {
|
|
1680 |
String stateStr = str.substring(i1+1, i2).toUpperCase();
|
|
1681 |
int state = -1;
|
|
1682 |
if ("ACTIVE".equals(stateStr)) {
|
|
1683 |
state = PRESSED;
|
|
1684 |
} else if ("INSENSITIVE".equals(stateStr)) {
|
|
1685 |
state = DISABLED;
|
|
1686 |
} else if ("NORMAL".equals(stateStr)) {
|
|
1687 |
state = ENABLED;
|
|
1688 |
} else if ("PRELIGHT".equals(stateStr)) {
|
|
1689 |
state = MOUSE_OVER;
|
|
1690 |
} else if ("SELECTED".equals(stateStr)) {
|
|
1691 |
state = SELECTED;
|
|
1692 |
}
|
|
1693 |
ColorType type = null;
|
|
1694 |
if ("fg".equals(typeStr)) {
|
|
1695 |
type = GTKColorType.FOREGROUND;
|
|
1696 |
} else if ("bg".equals(typeStr)) {
|
|
1697 |
type = GTKColorType.BACKGROUND;
|
|
1698 |
} else if ("base".equals(typeStr)) {
|
|
1699 |
type = GTKColorType.TEXT_BACKGROUND;
|
|
1700 |
} else if ("text".equals(typeStr)) {
|
|
1701 |
type = GTKColorType.TEXT_FOREGROUND;
|
|
1702 |
} else if ("dark".equals(typeStr)) {
|
|
1703 |
type = GTKColorType.DARK;
|
|
1704 |
} else if ("light".equals(typeStr)) {
|
|
1705 |
type = GTKColorType.LIGHT;
|
|
1706 |
}
|
|
1707 |
if (state >= 0 && type != null) {
|
|
1708 |
c = ((GTKStyle)context.getStyle()).getGTKColor(context, state, type);
|
|
1709 |
}
|
|
1710 |
}
|
|
1711 |
}
|
|
1712 |
}
|
|
1713 |
if (c == null) {
|
|
1714 |
c = parseColorString(str);
|
|
1715 |
}
|
|
1716 |
return c;
|
|
1717 |
}
|
|
1718 |
|
|
1719 |
private static Color parseColorString(String str) {
|
|
1720 |
if (str.charAt(0) == '#') {
|
|
1721 |
str = str.substring(1);
|
|
1722 |
|
|
1723 |
int i = str.length();
|
|
1724 |
|
|
1725 |
if (i < 3 || i > 12 || (i % 3) != 0) {
|
|
1726 |
return null;
|
|
1727 |
}
|
|
1728 |
|
|
1729 |
i /= 3;
|
|
1730 |
|
|
1731 |
int r;
|
|
1732 |
int g;
|
|
1733 |
int b;
|
|
1734 |
|
|
1735 |
try {
|
|
1736 |
r = Integer.parseInt(str.substring(0, i), 16);
|
|
1737 |
g = Integer.parseInt(str.substring(i, i * 2), 16);
|
|
1738 |
b = Integer.parseInt(str.substring(i * 2, i * 3), 16);
|
|
1739 |
} catch (NumberFormatException nfe) {
|
|
1740 |
return null;
|
|
1741 |
}
|
|
1742 |
|
|
1743 |
if (i == 4) {
|
|
1744 |
return new ColorUIResource(r / 65535.0f, g / 65535.0f, b / 65535.0f);
|
|
1745 |
} else if (i == 1) {
|
|
1746 |
return new ColorUIResource(r / 15.0f, g / 15.0f, b / 15.0f);
|
|
1747 |
} else if (i == 2) {
|
|
1748 |
return new ColorUIResource(r, g, b);
|
|
1749 |
} else {
|
|
1750 |
return new ColorUIResource(r / 4095.0f, g / 4095.0f, b / 4095.0f);
|
|
1751 |
}
|
|
1752 |
} else {
|
|
1753 |
return XColors.lookupColor(str);
|
|
1754 |
}
|
|
1755 |
}
|
|
1756 |
|
|
1757 |
class ArithmeticExpressionEvaluator {
|
|
1758 |
private PeekableStringTokenizer tokenizer;
|
|
1759 |
|
|
1760 |
int evaluate(String expr) {
|
|
1761 |
tokenizer = new PeekableStringTokenizer(expr, " \t+-*/%()", true);
|
|
1762 |
return Math.round(expression());
|
|
1763 |
}
|
|
1764 |
|
|
1765 |
int evaluate(String expr, int fallback) {
|
|
1766 |
return (expr != null) ? evaluate(expr) : fallback;
|
|
1767 |
}
|
|
1768 |
|
|
1769 |
public float expression() {
|
|
1770 |
float value = getTermValue();
|
|
1771 |
boolean done = false;
|
|
1772 |
while (!done && tokenizer.hasMoreTokens()) {
|
|
1773 |
String next = tokenizer.peek();
|
|
1774 |
if ("+".equals(next) ||
|
|
1775 |
"-".equals(next) ||
|
|
1776 |
"`max`".equals(next) ||
|
|
1777 |
"`min`".equals(next)) {
|
|
1778 |
tokenizer.nextToken();
|
|
1779 |
float value2 = getTermValue();
|
|
1780 |
if ("+".equals(next)) {
|
|
1781 |
value += value2;
|
|
1782 |
} else if ("-".equals(next)) {
|
|
1783 |
value -= value2;
|
|
1784 |
} else if ("`max`".equals(next)) {
|
|
1785 |
value = Math.max(value, value2);
|
|
1786 |
} else if ("`min`".equals(next)) {
|
|
1787 |
value = Math.min(value, value2);
|
|
1788 |
}
|
|
1789 |
} else {
|
|
1790 |
done = true;
|
|
1791 |
}
|
|
1792 |
}
|
|
1793 |
return value;
|
|
1794 |
}
|
|
1795 |
|
|
1796 |
public float getTermValue() {
|
|
1797 |
float value = getFactorValue();
|
|
1798 |
boolean done = false;
|
|
1799 |
while (!done && tokenizer.hasMoreTokens()) {
|
|
1800 |
String next = tokenizer.peek();
|
|
1801 |
if ("*".equals(next) || "/".equals(next) || "%".equals(next)) {
|
|
1802 |
tokenizer.nextToken();
|
|
1803 |
float value2 = getFactorValue();
|
|
1804 |
if ("*".equals(next)) {
|
|
1805 |
value *= value2;
|
|
1806 |
} else if ("/".equals(next)) {
|
|
1807 |
value /= value2;
|
|
1808 |
} else {
|
|
1809 |
value %= value2;
|
|
1810 |
}
|
|
1811 |
} else {
|
|
1812 |
done = true;
|
|
1813 |
}
|
|
1814 |
}
|
|
1815 |
return value;
|
|
1816 |
}
|
|
1817 |
|
|
1818 |
public float getFactorValue() {
|
|
1819 |
float value;
|
|
1820 |
if ("(".equals(tokenizer.peek())) {
|
|
1821 |
tokenizer.nextToken();
|
|
1822 |
value = expression();
|
|
1823 |
tokenizer.nextToken(); // skip right paren
|
|
1824 |
} else {
|
|
1825 |
String token = tokenizer.nextToken();
|
|
1826 |
if (Character.isDigit(token.charAt(0))) {
|
|
1827 |
value = Float.parseFloat(token);
|
|
1828 |
} else {
|
|
1829 |
Integer i = variables.get(token);
|
|
1830 |
if (i == null) {
|
|
1831 |
i = (Integer)getFrameGeometry().get(token);
|
|
1832 |
}
|
|
1833 |
if (i == null) {
|
|
1834 |
logError(themeName, "Variable \"" + token + "\" not defined");
|
|
1835 |
return 0;
|
|
1836 |
}
|
|
1837 |
value = (i != null) ? i.intValue() : 0F;
|
|
1838 |
}
|
|
1839 |
}
|
|
1840 |
return value;
|
|
1841 |
}
|
|
1842 |
|
|
1843 |
|
|
1844 |
}
|
|
1845 |
|
|
1846 |
static class PeekableStringTokenizer extends StringTokenizer {
|
|
1847 |
String token = null;
|
|
1848 |
|
|
1849 |
public PeekableStringTokenizer(String str, String delim,
|
|
1850 |
boolean returnDelims) {
|
|
1851 |
super(str, delim, returnDelims);
|
|
1852 |
peek();
|
|
1853 |
}
|
|
1854 |
|
|
1855 |
public String peek() {
|
|
1856 |
if (token == null) {
|
|
1857 |
token = nextToken();
|
|
1858 |
}
|
|
1859 |
return token;
|
|
1860 |
}
|
|
1861 |
|
|
1862 |
public boolean hasMoreTokens() {
|
|
1863 |
return (token != null || super.hasMoreTokens());
|
|
1864 |
}
|
|
1865 |
|
|
1866 |
public String nextToken() {
|
|
1867 |
if (token != null) {
|
|
1868 |
String t = token;
|
|
1869 |
token = null;
|
|
1870 |
if (hasMoreTokens()) {
|
|
1871 |
peek();
|
|
1872 |
}
|
|
1873 |
return t;
|
|
1874 |
} else {
|
|
1875 |
String token = super.nextToken();
|
|
1876 |
while ((token.equals(" ") || token.equals("\t"))
|
|
1877 |
&& hasMoreTokens()) {
|
|
1878 |
token = super.nextToken();
|
|
1879 |
}
|
|
1880 |
return token;
|
|
1881 |
}
|
|
1882 |
}
|
|
1883 |
}
|
|
1884 |
|
|
1885 |
|
|
1886 |
static class RoundRectClipShape extends RectangularShape {
|
|
1887 |
static final int TOP_LEFT = 1;
|
|
1888 |
static final int TOP_RIGHT = 2;
|
|
1889 |
static final int BOTTOM_LEFT = 4;
|
|
1890 |
static final int BOTTOM_RIGHT = 8;
|
|
1891 |
|
|
1892 |
int x;
|
|
1893 |
int y;
|
|
1894 |
int width;
|
|
1895 |
int height;
|
|
1896 |
int arcwidth;
|
|
1897 |
int archeight;
|
|
1898 |
int corners;
|
|
1899 |
|
|
1900 |
public RoundRectClipShape() {
|
|
1901 |
}
|
|
1902 |
|
|
1903 |
public RoundRectClipShape(int x, int y, int w, int h,
|
|
1904 |
int arcw, int arch, int corners) {
|
|
1905 |
setRoundedRect(x, y, w, h, arcw, arch, corners);
|
|
1906 |
}
|
|
1907 |
|
|
1908 |
public void setRoundedRect(int x, int y, int w, int h,
|
|
1909 |
int arcw, int arch, int corners) {
|
|
1910 |
this.corners = corners;
|
|
1911 |
this.x = x;
|
|
1912 |
this.y = y;
|
|
1913 |
this.width = w;
|
|
1914 |
this.height = h;
|
|
1915 |
this.arcwidth = arcw;
|
|
1916 |
this.archeight = arch;
|
|
1917 |
}
|
|
1918 |
|
|
1919 |
public double getX() {
|
|
1920 |
return (double)x;
|
|
1921 |
}
|
|
1922 |
|
|
1923 |
public double getY() {
|
|
1924 |
return (double)y;
|
|
1925 |
}
|
|
1926 |
|
|
1927 |
public double getWidth() {
|
|
1928 |
return (double)width;
|
|
1929 |
}
|
|
1930 |
|
|
1931 |
public double getHeight() {
|
|
1932 |
return (double)height;
|
|
1933 |
}
|
|
1934 |
|
|
1935 |
public double getArcWidth() {
|
|
1936 |
return (double)arcwidth;
|
|
1937 |
}
|
|
1938 |
|
|
1939 |
public double getArcHeight() {
|
|
1940 |
return (double)archeight;
|
|
1941 |
}
|
|
1942 |
|
|
1943 |
public boolean isEmpty() {
|
|
1944 |
return false; // Not called
|
|
1945 |
}
|
|
1946 |
|
|
1947 |
public Rectangle2D getBounds2D() {
|
|
1948 |
return null; // Not called
|
|
1949 |
}
|
|
1950 |
|
|
1951 |
public int getCornerFlags() {
|
|
1952 |
return corners;
|
|
1953 |
}
|
|
1954 |
|
|
1955 |
public void setFrame(double x, double y, double w, double h) {
|
|
1956 |
// Not called
|
|
1957 |
}
|
|
1958 |
|
|
1959 |
public boolean contains(double x, double y) {
|
|
1960 |
return false; // Not called
|
|
1961 |
}
|
|
1962 |
|
|
1963 |
private int classify(double coord, double left, double right, double arcsize) {
|
|
1964 |
return 0; // Not called
|
|
1965 |
}
|
|
1966 |
|
|
1967 |
public boolean intersects(double x, double y, double w, double h) {
|
|
1968 |
return false; // Not called
|
|
1969 |
}
|
|
1970 |
|
|
1971 |
public boolean contains(double x, double y, double w, double h) {
|
|
1972 |
return false; // Not called
|
|
1973 |
}
|
|
1974 |
|
|
1975 |
public PathIterator getPathIterator(AffineTransform at) {
|
|
1976 |
return new RoundishRectIterator(this, at);
|
|
1977 |
}
|
|
1978 |
|
|
1979 |
|
|
1980 |
static class RoundishRectIterator implements PathIterator {
|
|
1981 |
double x, y, w, h, aw, ah;
|
|
1982 |
AffineTransform affine;
|
|
1983 |
int index;
|
|
1984 |
|
|
1985 |
double ctrlpts[][];
|
|
1986 |
int types[];
|
|
1987 |
|
|
1988 |
private static final double angle = Math.PI / 4.0;
|
|
1989 |
private static final double a = 1.0 - Math.cos(angle);
|
|
1990 |
private static final double b = Math.tan(angle);
|
|
1991 |
private static final double c = Math.sqrt(1.0 + b * b) - 1 + a;
|
|
1992 |
private static final double cv = 4.0 / 3.0 * a * b / c;
|
|
1993 |
private static final double acv = (1.0 - cv) / 2.0;
|
|
1994 |
|
|
1995 |
// For each array:
|
|
1996 |
// 4 values for each point {v0, v1, v2, v3}:
|
|
1997 |
// point = (x + v0 * w + v1 * arcWidth,
|
|
1998 |
// y + v2 * h + v3 * arcHeight);
|
|
1999 |
private static final double CtrlPtTemplate[][] = {
|
|
2000 |
{ 0.0, 0.0, 1.0, 0.0 }, /* BOTTOM LEFT corner */
|
|
2001 |
{ 0.0, 0.0, 1.0, -0.5 }, /* BOTTOM LEFT arc start */
|
|
2002 |
{ 0.0, 0.0, 1.0, -acv, /* BOTTOM LEFT arc curve */
|
|
2003 |
0.0, acv, 1.0, 0.0,
|
|
2004 |
0.0, 0.5, 1.0, 0.0 },
|
|
2005 |
{ 1.0, 0.0, 1.0, 0.0 }, /* BOTTOM RIGHT corner */
|
|
2006 |
{ 1.0, -0.5, 1.0, 0.0 }, /* BOTTOM RIGHT arc start */
|
|
2007 |
{ 1.0, -acv, 1.0, 0.0, /* BOTTOM RIGHT arc curve */
|
|
2008 |
1.0, 0.0, 1.0, -acv,
|
|
2009 |
1.0, 0.0, 1.0, -0.5 },
|
|
2010 |
{ 1.0, 0.0, 0.0, 0.0 }, /* TOP RIGHT corner */
|
|
2011 |
{ 1.0, 0.0, 0.0, 0.5 }, /* TOP RIGHT arc start */
|
|
2012 |
{ 1.0, 0.0, 0.0, acv, /* TOP RIGHT arc curve */
|
|
2013 |
1.0, -acv, 0.0, 0.0,
|
|
2014 |
1.0, -0.5, 0.0, 0.0 },
|
|
2015 |
{ 0.0, 0.0, 0.0, 0.0 }, /* TOP LEFT corner */
|
|
2016 |
{ 0.0, 0.5, 0.0, 0.0 }, /* TOP LEFT arc start */
|
|
2017 |
{ 0.0, acv, 0.0, 0.0, /* TOP LEFT arc curve */
|
|
2018 |
0.0, 0.0, 0.0, acv,
|
|
2019 |
0.0, 0.0, 0.0, 0.5 },
|
|
2020 |
{}, /* Closing path element */
|
|
2021 |
};
|
|
2022 |
private static final int CornerFlags[] = {
|
|
2023 |
RoundRectClipShape.BOTTOM_LEFT,
|
|
2024 |
RoundRectClipShape.BOTTOM_RIGHT,
|
|
2025 |
RoundRectClipShape.TOP_RIGHT,
|
|
2026 |
RoundRectClipShape.TOP_LEFT,
|
|
2027 |
};
|
|
2028 |
|
|
2029 |
RoundishRectIterator(RoundRectClipShape rr, AffineTransform at) {
|
|
2030 |
this.x = rr.getX();
|
|
2031 |
this.y = rr.getY();
|
|
2032 |
this.w = rr.getWidth();
|
|
2033 |
this.h = rr.getHeight();
|
|
2034 |
this.aw = Math.min(w, Math.abs(rr.getArcWidth()));
|
|
2035 |
this.ah = Math.min(h, Math.abs(rr.getArcHeight()));
|
|
2036 |
this.affine = at;
|
|
2037 |
if (w < 0 || h < 0) {
|
|
2038 |
// Don't draw anything...
|
|
2039 |
ctrlpts = new double[0][];
|
|
2040 |
types = new int[0];
|
|
2041 |
} else {
|
|
2042 |
int corners = rr.getCornerFlags();
|
|
2043 |
int numedges = 5; // 4xCORNER_POINT, CLOSE
|
|
2044 |
for (int i = 1; i < 0x10; i <<= 1) {
|
|
2045 |
// Add one for each corner that has a curve
|
|
2046 |
if ((corners & i) != 0) numedges++;
|
|
2047 |
}
|
|
2048 |
ctrlpts = new double[numedges][];
|
|
2049 |
types = new int[numedges];
|
|
2050 |
int j = 0;
|
|
2051 |
for (int i = 0; i < 4; i++) {
|
|
2052 |
types[j] = SEG_LINETO;
|
|
2053 |
if ((corners & CornerFlags[i]) == 0) {
|
|
2054 |
ctrlpts[j++] = CtrlPtTemplate[i*3+0];
|
|
2055 |
} else {
|
|
2056 |
ctrlpts[j++] = CtrlPtTemplate[i*3+1];
|
|
2057 |
types[j] = SEG_CUBICTO;
|
|
2058 |
ctrlpts[j++] = CtrlPtTemplate[i*3+2];
|
|
2059 |
}
|
|
2060 |
}
|
|
2061 |
types[j] = SEG_CLOSE;
|
|
2062 |
ctrlpts[j++] = CtrlPtTemplate[12];
|
|
2063 |
types[0] = SEG_MOVETO;
|
|
2064 |
}
|
|
2065 |
}
|
|
2066 |
|
|
2067 |
public int getWindingRule() {
|
|
2068 |
return WIND_NON_ZERO;
|
|
2069 |
}
|
|
2070 |
|
|
2071 |
public boolean isDone() {
|
|
2072 |
return index >= ctrlpts.length;
|
|
2073 |
}
|
|
2074 |
|
|
2075 |
public void next() {
|
|
2076 |
index++;
|
|
2077 |
}
|
|
2078 |
|
|
2079 |
public int currentSegment(float[] coords) {
|
|
2080 |
if (isDone()) {
|
|
2081 |
throw new NoSuchElementException("roundrect iterator out of bounds");
|
|
2082 |
}
|
|
2083 |
double ctrls[] = ctrlpts[index];
|
|
2084 |
int nc = 0;
|
|
2085 |
for (int i = 0; i < ctrls.length; i += 4) {
|
|
2086 |
coords[nc++] = (float) (x + ctrls[i + 0] * w + ctrls[i + 1] * aw);
|
|
2087 |
coords[nc++] = (float) (y + ctrls[i + 2] * h + ctrls[i + 3] * ah);
|
|
2088 |
}
|
|
2089 |
if (affine != null) {
|
|
2090 |
affine.transform(coords, 0, coords, 0, nc / 2);
|
|
2091 |
}
|
|
2092 |
return types[index];
|
|
2093 |
}
|
|
2094 |
|
|
2095 |
public int currentSegment(double[] coords) {
|
|
2096 |
if (isDone()) {
|
|
2097 |
throw new NoSuchElementException("roundrect iterator out of bounds");
|
|
2098 |
}
|
|
2099 |
double ctrls[] = ctrlpts[index];
|
|
2100 |
int nc = 0;
|
|
2101 |
for (int i = 0; i < ctrls.length; i += 4) {
|
|
2102 |
coords[nc++] = x + ctrls[i + 0] * w + ctrls[i + 1] * aw;
|
|
2103 |
coords[nc++] = y + ctrls[i + 2] * h + ctrls[i + 3] * ah;
|
|
2104 |
}
|
|
2105 |
if (affine != null) {
|
|
2106 |
affine.transform(coords, 0, coords, 0, nc / 2);
|
|
2107 |
}
|
|
2108 |
return types[index];
|
|
2109 |
}
|
|
2110 |
}
|
|
2111 |
}
|
|
2112 |
}
|