1 /* 2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * <p>These classes are designed to be used while the 28 * corresponding <code>LookAndFeel</code> class has been installed 29 * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>). 30 * Using them while a different <code>LookAndFeel</code> is installed 31 * may produce unexpected results, including exceptions. 32 * Additionally, changing the <code>LookAndFeel</code> 33 * maintained by the <code>UIManager</code> without updating the 34 * corresponding <code>ComponentUI</code> of any 35 * <code>JComponent</code>s may also produce unexpected results, 36 * such as the wrong colors showing up, and is generally not 37 * encouraged. 38 * 39 */ 40 41 package com.sun.java.swing.plaf.windows; 42 43 import java.awt.*; 44 import java.awt.image.*; 45 import java.security.AccessController; 46 import java.util.*; 47 import java.util.concurrent.atomic.AtomicBoolean; 48 49 import javax.swing.*; 50 import javax.swing.border.*; 51 import javax.swing.plaf.*; 52 import javax.swing.text.JTextComponent; 53 54 import sun.awt.image.SunWritableRaster; 55 import sun.awt.windows.ThemeReader; 56 import sun.awt.windows.WToolkit; 57 import sun.security.action.GetPropertyAction; 58 import sun.swing.CachedPainter; 59 60 import static com.sun.java.swing.plaf.windows.TMSchema.*; 61 62 63 /** 64 * Implements Windows XP Styles for the Windows Look and Feel. 65 * 66 * @author Leif Samuelsson 67 */ 68 class XPStyle { 69 // Singleton instance of this class 70 private static XPStyle xp; 71 72 // Singleton instance of SkinPainter 73 private static SkinPainter skinPainter = new SkinPainter(); 74 75 private static Boolean themeActive = null; 76 77 private static final AtomicBoolean xpstyleEnabled = WToolkit.getWToolkit().getXPStyleEnabled(); 78 79 private HashMap<String, Border> borderMap; 80 private HashMap<String, Color> colorMap; 81 82 private boolean flatMenus; 83 84 static { 85 invalidateStyle(); 86 } 87 88 /** Static method for clearing the hashmap and loading the 89 * current XP style and theme 90 */ 91 static synchronized void invalidateStyle() { 92 xp = null; 93 themeActive = null; 94 skinPainter.flush(); 95 } 96 97 /** Get the singleton instance of this class 98 * 99 * @return the singleton instance of this class or null if XP styles 100 * are not active or if this is not Windows XP 101 */ 102 static synchronized XPStyle getXP() { 103 if (themeActive != null && themeActive.booleanValue() != xpstyleEnabled.get()) { 104 // JDK-8039383: theme changed, schedule updateAllUIs() 105 DesktopProperty.scheduleUpdateUI(); 106 } 107 if (themeActive == null) { 108 themeActive = Boolean.valueOf(xpstyleEnabled.get()); 109 if (themeActive.booleanValue()) { 110 GetPropertyAction propertyAction = 111 new GetPropertyAction("swing.noxp"); 112 if (AccessController.doPrivileged(propertyAction) == null && 113 ThemeReader.isThemed() && 114 !(UIManager.getLookAndFeel() 115 instanceof WindowsClassicLookAndFeel)) { 116 117 xp = new XPStyle(); 118 } 119 } 120 } 121 return xp; 122 } 123 124 static boolean isVista() { 125 XPStyle xp = XPStyle.getXP(); 126 return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT)); 127 } 128 129 /** Get a named <code>String</code> value from the current style 130 * 131 * @param part a <code>Part</code> 132 * @param state a <code>String</code> 133 * @param attributeKey a <code>String</code> 134 * @return a <code>String</code> or null if key is not found 135 * in the current style 136 * 137 * This is currently only used by WindowsInternalFrameTitlePane for painting 138 * title foregound and can be removed when no longer needed 139 */ 140 String getString(Component c, Part part, State state, Prop prop) { 141 return getTypeEnumName(c, part, state, prop); 142 } 143 144 TypeEnum getTypeEnum(Component c, Part part, State state, Prop prop) { 145 int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(), 146 State.getValue(part, state), 147 prop.getValue()); 148 return TypeEnum.getTypeEnum(prop, enumValue); 149 } 150 151 private static String getTypeEnumName(Component c, Part part, State state, Prop prop) { 152 int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(), 153 State.getValue(part, state), 154 prop.getValue()); 155 if (enumValue == -1) { 156 return null; 157 } 158 return TypeEnum.getTypeEnum(prop, enumValue).getName(); 159 } 160 161 162 163 164 /** Get a named <code>int</code> value from the current style 165 * 166 * @param part a <code>Part</code> 167 * @return an <code>int</code> or null if key is not found 168 * in the current style 169 */ 170 int getInt(Component c, Part part, State state, Prop prop, int fallback) { 171 return ThemeReader.getInt(part.getControlName(c), part.getValue(), 172 State.getValue(part, state), 173 prop.getValue()); 174 } 175 176 /** Get a named <code>Dimension</code> value from the current style 177 * 178 * @param key a <code>String</code> 179 * @return a <code>Dimension</code> or null if key is not found 180 * in the current style 181 * 182 * This is currently only used by WindowsProgressBarUI and the value 183 * should probably be cached there instead of here. 184 */ 185 Dimension getDimension(Component c, Part part, State state, Prop prop) { 186 Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(), 187 State.getValue(part, state), 188 prop.getValue()); 189 return (d != null) ? d : new Dimension(); 190 } 191 192 /** Get a named <code>Point</code> (e.g. a location or an offset) value 193 * from the current style 194 * 195 * @param key a <code>String</code> 196 * @return a <code>Point</code> or null if key is not found 197 * in the current style 198 * 199 * This is currently only used by WindowsInternalFrameTitlePane for painting 200 * title foregound and can be removed when no longer needed 201 */ 202 Point getPoint(Component c, Part part, State state, Prop prop) { 203 Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(), 204 State.getValue(part, state), 205 prop.getValue()); 206 return (d != null) ? new Point(d.width, d.height) : new Point(); 207 } 208 209 /** Get a named <code>Insets</code> value from the current style 210 * 211 * @param key a <code>String</code> 212 * @return an <code>Insets</code> object or null if key is not found 213 * in the current style 214 * 215 * This is currently only used to create borders and by 216 * WindowsInternalFrameTitlePane for painting title foregound. 217 * The return value is already cached in those places. 218 */ 219 Insets getMargin(Component c, Part part, State state, Prop prop) { 220 Insets insets = ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(), 221 State.getValue(part, state), 222 prop.getValue()); 223 return (insets != null) ? insets : new Insets(0, 0, 0, 0); 224 } 225 226 227 /** Get a named <code>Color</code> value from the current style 228 * 229 * @param part a <code>Part</code> 230 * @return a <code>Color</code> or null if key is not found 231 * in the current style 232 */ 233 synchronized Color getColor(Skin skin, Prop prop, Color fallback) { 234 String key = skin.toString() + "." + prop.name(); 235 Part part = skin.part; 236 Color color = colorMap.get(key); 237 if (color == null) { 238 color = ThemeReader.getColor(part.getControlName(null), part.getValue(), 239 State.getValue(part, skin.state), 240 prop.getValue()); 241 if (color != null) { 242 color = new ColorUIResource(color); 243 colorMap.put(key, color); 244 } 245 } 246 return (color != null) ? color : fallback; 247 } 248 249 Color getColor(Component c, Part part, State state, Prop prop, Color fallback) { 250 return getColor(new Skin(c, part, state), prop, fallback); 251 } 252 253 254 255 /** Get a named <code>Border</code> value from the current style 256 * 257 * @param part a <code>Part</code> 258 * @return a <code>Border</code> or null if key is not found 259 * in the current style or if the style for the particular 260 * part is not defined as "borderfill". 261 */ 262 synchronized Border getBorder(Component c, Part part) { 263 if (part == Part.MENU) { 264 // Special case because XP has no skin for menus 265 if (flatMenus) { 266 // TODO: The classic border uses this color, but we should 267 // create a new UI property called "PopupMenu.borderColor" 268 // instead. 269 return new XPFillBorder(UIManager.getColor("InternalFrame.borderShadow"), 270 1); 271 } else { 272 return null; // Will cause L&F to use classic border 273 } 274 } 275 Skin skin = new Skin(c, part, null); 276 Border border = borderMap.get(skin.string); 277 if (border == null) { 278 String bgType = getTypeEnumName(c, part, null, Prop.BGTYPE); 279 if ("borderfill".equalsIgnoreCase(bgType)) { 280 int thickness = getInt(c, part, null, Prop.BORDERSIZE, 1); 281 Color color = getColor(skin, Prop.BORDERCOLOR, Color.black); 282 border = new XPFillBorder(color, thickness); 283 if (part == Part.CP_COMBOBOX) { 284 border = new XPStatefulFillBorder(color, thickness, part, Prop.BORDERCOLOR); 285 } 286 } else if ("imagefile".equalsIgnoreCase(bgType)) { 287 Insets m = getMargin(c, part, null, Prop.SIZINGMARGINS); 288 if (m != null) { 289 if (getBoolean(c, part, null, Prop.BORDERONLY)) { 290 border = new XPImageBorder(c, part); 291 } else if (part == Part.CP_COMBOBOX) { 292 border = new EmptyBorder(1, 1, 1, 1); 293 } else { 294 if(part == Part.TP_BUTTON) { 295 border = new XPEmptyBorder(new Insets(3,3,3,3)); 296 } else { 297 border = new XPEmptyBorder(m); 298 } 299 } 300 } 301 } 302 if (border != null) { 303 borderMap.put(skin.string, border); 304 } 305 } 306 return border; 307 } 308 309 @SuppressWarnings("serial") // Superclass is not serializable across versions 310 private class XPFillBorder extends LineBorder implements UIResource { 311 XPFillBorder(Color color, int thickness) { 312 super(color, thickness); 313 } 314 315 public Insets getBorderInsets(Component c, Insets insets) { 316 Insets margin = null; 317 // 318 // Ideally we'd have an interface defined for classes which 319 // support margins (to avoid this hackery), but we've 320 // decided against it for simplicity 321 // 322 if (c instanceof AbstractButton) { 323 margin = ((AbstractButton)c).getMargin(); 324 } else if (c instanceof JToolBar) { 325 margin = ((JToolBar)c).getMargin(); 326 } else if (c instanceof JTextComponent) { 327 margin = ((JTextComponent)c).getMargin(); 328 } 329 insets.top = (margin != null? margin.top : 0) + thickness; 330 insets.left = (margin != null? margin.left : 0) + thickness; 331 insets.bottom = (margin != null? margin.bottom : 0) + thickness; 332 insets.right = (margin != null? margin.right : 0) + thickness; 333 334 return insets; 335 } 336 } 337 338 @SuppressWarnings("serial") // Superclass is not serializable across versions 339 private class XPStatefulFillBorder extends XPFillBorder { 340 private final Part part; 341 private final Prop prop; 342 XPStatefulFillBorder(Color color, int thickness, Part part, Prop prop) { 343 super(color, thickness); 344 this.part = part; 345 this.prop = prop; 346 } 347 348 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 349 State state = State.NORMAL; 350 // special casing for comboboxes. 351 // there may be more special cases in the future 352 if(c instanceof JComboBox) { 353 JComboBox cb = (JComboBox)c; 354 // note. in the future this should be replaced with a call 355 // to BasicLookAndFeel.getUIOfType() 356 if(cb.getUI() instanceof WindowsComboBoxUI) { 357 WindowsComboBoxUI wcb = (WindowsComboBoxUI)cb.getUI(); 358 state = wcb.getXPComboBoxState(cb); 359 } 360 } 361 lineColor = getColor(c, part, state, prop, Color.black); 362 super.paintBorder(c, g, x, y, width, height); 363 } 364 } 365 366 @SuppressWarnings("serial") // Superclass is not serializable across versions 367 private class XPImageBorder extends AbstractBorder implements UIResource { 368 Skin skin; 369 370 XPImageBorder(Component c, Part part) { 371 this.skin = getSkin(c, part); 372 } 373 374 public void paintBorder(Component c, Graphics g, 375 int x, int y, int width, int height) { 376 skin.paintSkin(g, x, y, width, height, null); 377 } 378 379 public Insets getBorderInsets(Component c, Insets insets) { 380 Insets margin = null; 381 Insets borderInsets = skin.getContentMargin(); 382 if(borderInsets == null) { 383 borderInsets = new Insets(0, 0, 0, 0); 384 } 385 // 386 // Ideally we'd have an interface defined for classes which 387 // support margins (to avoid this hackery), but we've 388 // decided against it for simplicity 389 // 390 if (c instanceof AbstractButton) { 391 margin = ((AbstractButton)c).getMargin(); 392 } else if (c instanceof JToolBar) { 393 margin = ((JToolBar)c).getMargin(); 394 } else if (c instanceof JTextComponent) { 395 margin = ((JTextComponent)c).getMargin(); 396 } 397 insets.top = (margin != null? margin.top : 0) + borderInsets.top; 398 insets.left = (margin != null? margin.left : 0) + borderInsets.left; 399 insets.bottom = (margin != null? margin.bottom : 0) + borderInsets.bottom; 400 insets.right = (margin != null? margin.right : 0) + borderInsets.right; 401 402 return insets; 403 } 404 } 405 406 @SuppressWarnings("serial") // Superclass is not serializable across versions 407 private class XPEmptyBorder extends EmptyBorder implements UIResource { 408 XPEmptyBorder(Insets m) { 409 super(m.top+2, m.left+2, m.bottom+2, m.right+2); 410 } 411 412 public Insets getBorderInsets(Component c, Insets insets) { 413 insets = super.getBorderInsets(c, insets); 414 415 Insets margin = null; 416 if (c instanceof AbstractButton) { 417 Insets m = ((AbstractButton)c).getMargin(); 418 // if this is a toolbar button then ignore getMargin() 419 // and subtract the padding added by the constructor 420 if(c.getParent() instanceof JToolBar 421 && ! (c instanceof JRadioButton) 422 && ! (c instanceof JCheckBox) 423 && m instanceof InsetsUIResource) { 424 insets.top -= 2; 425 insets.left -= 2; 426 insets.bottom -= 2; 427 insets.right -= 2; 428 } else { 429 margin = m; 430 } 431 } else if (c instanceof JToolBar) { 432 margin = ((JToolBar)c).getMargin(); 433 } else if (c instanceof JTextComponent) { 434 margin = ((JTextComponent)c).getMargin(); 435 } 436 if (margin != null) { 437 insets.top = margin.top + 2; 438 insets.left = margin.left + 2; 439 insets.bottom = margin.bottom + 2; 440 insets.right = margin.right + 2; 441 } 442 return insets; 443 } 444 } 445 boolean isSkinDefined(Component c, Part part) { 446 return (part.getValue() == 0) 447 || ThemeReader.isThemePartDefined( 448 part.getControlName(c), part.getValue(), 0); 449 } 450 451 452 /** Get a <code>Skin</code> object from the current style 453 * for a named part (component type) 454 * 455 * @param part a <code>Part</code> 456 * @return a <code>Skin</code> object 457 */ 458 synchronized Skin getSkin(Component c, Part part) { 459 assert isSkinDefined(c, part) : "part " + part + " is not defined"; 460 return new Skin(c, part, null); 461 } 462 463 464 long getThemeTransitionDuration(Component c, Part part, State stateFrom, 465 State stateTo, Prop prop) { 466 return ThemeReader.getThemeTransitionDuration(part.getControlName(c), 467 part.getValue(), 468 State.getValue(part, stateFrom), 469 State.getValue(part, stateTo), 470 (prop != null) ? prop.getValue() : 0); 471 } 472 473 474 /** A class which encapsulates attributes for a given part 475 * (component type) and which provides methods for painting backgrounds 476 * and glyphs 477 */ 478 static class Skin { 479 final Component component; 480 final Part part; 481 final State state; 482 483 private final String string; 484 private Dimension size = null; 485 486 Skin(Component component, Part part) { 487 this(component, part, null); 488 } 489 490 Skin(Part part, State state) { 491 this(null, part, state); 492 } 493 494 Skin(Component component, Part part, State state) { 495 this.component = component; 496 this.part = part; 497 this.state = state; 498 499 String str = part.getControlName(component) +"." + part.name(); 500 if (state != null) { 501 str += "("+state.name()+")"; 502 } 503 string = str; 504 } 505 506 Insets getContentMargin() { 507 /* idk: it seems margins are the same for all 'big enough' 508 * bounding rectangles. 509 */ 510 int boundingWidth = 100; 511 int boundingHeight = 100; 512 513 Insets insets = ThemeReader.getThemeBackgroundContentMargins( 514 part.getControlName(null), part.getValue(), 515 0, boundingWidth, boundingHeight); 516 return (insets != null) ? insets : new Insets(0, 0, 0, 0); 517 } 518 519 private int getWidth(State state) { 520 if (size == null) { 521 size = getPartSize(part, state); 522 } 523 return (size != null) ? size.width : 0; 524 } 525 526 int getWidth() { 527 return getWidth((state != null) ? state : State.NORMAL); 528 } 529 530 private int getHeight(State state) { 531 if (size == null) { 532 size = getPartSize(part, state); 533 } 534 return (size != null) ? size.height : 0; 535 } 536 537 int getHeight() { 538 return getHeight((state != null) ? state : State.NORMAL); 539 } 540 541 public String toString() { 542 return string; 543 } 544 545 public boolean equals(Object obj) { 546 return (obj instanceof Skin && ((Skin)obj).string.equals(string)); 547 } 548 549 public int hashCode() { 550 return string.hashCode(); 551 } 552 553 /** Paint a skin at x, y. 554 * 555 * @param g the graphics context to use for painting 556 * @param dx the destination <i>x</i> coordinate 557 * @param dy the destination <i>y</i> coordinate 558 * @param state which state to paint 559 */ 560 void paintSkin(Graphics g, int dx, int dy, State state) { 561 if (state == null) { 562 state = this.state; 563 } 564 paintSkin(g, dx, dy, getWidth(state), getHeight(state), state); 565 } 566 567 /** Paint a skin in an area defined by a rectangle. 568 * 569 * @param g the graphics context to use for painting 570 * @param r a <code>Rectangle</code> defining the area to fill, 571 * may cause the image to be stretched or tiled 572 * @param state which state to paint 573 */ 574 void paintSkin(Graphics g, Rectangle r, State state) { 575 paintSkin(g, r.x, r.y, r.width, r.height, state); 576 } 577 578 /** Paint a skin at a defined position and size 579 * This method supports animation. 580 * 581 * @param g the graphics context to use for painting 582 * @param dx the destination <i>x</i> coordinate 583 * @param dy the destination <i>y</i> coordinate 584 * @param dw the width of the area to fill, may cause 585 * the image to be stretched or tiled 586 * @param dh the height of the area to fill, may cause 587 * the image to be stretched or tiled 588 * @param state which state to paint 589 */ 590 void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) { 591 if (ThemeReader.isGetThemeTransitionDurationDefined() 592 && component instanceof JComponent 593 && SwingUtilities.getAncestorOfClass(CellRendererPane.class, 594 component) == null) { 595 AnimationController.paintSkin((JComponent) component, this, 596 g, dx, dy, dw, dh, state); 597 } else { 598 paintSkinRaw(g, dx, dy, dw, dh, state); 599 } 600 } 601 602 /** Paint a skin at a defined position and size. This method 603 * does not trigger animation. It is needed for the animation 604 * support. 605 * 606 * @param g the graphics context to use for painting 607 * @param dx the destination <i>x</i> coordinate. 608 * @param dy the destination <i>y</i> coordinate. 609 * @param dw the width of the area to fill, may cause 610 * the image to be stretched or tiled 611 * @param dh the height of the area to fill, may cause 612 * the image to be stretched or tiled 613 * @param state which state to paint 614 */ 615 void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) { 616 skinPainter.paint(null, g, dx, dy, dw, dh, this, state); 617 } 618 619 /** Paint a skin at a defined position and size 620 * 621 * @param g the graphics context to use for painting 622 * @param dx the destination <i>x</i> coordinate 623 * @param dy the destination <i>y</i> coordinate 624 * @param dw the width of the area to fill, may cause 625 * the image to be stretched or tiled 626 * @param dh the height of the area to fill, may cause 627 * the image to be stretched or tiled 628 * @param state which state to paint 629 * @param borderFill should test if the component uses a border fill 630 and skip painting if it is 631 */ 632 void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state, 633 boolean borderFill) { 634 if(borderFill && "borderfill".equals(getTypeEnumName(component, part, 635 state, Prop.BGTYPE))) { 636 return; 637 } 638 skinPainter.paint(null, g, dx, dy, dw, dh, this, state); 639 } 640 } 641 642 private static class SkinPainter extends CachedPainter { 643 SkinPainter() { 644 super(30); 645 flush(); 646 } 647 648 public void flush() { 649 super.flush(); 650 } 651 652 protected void paintToImage(Component c, Image image, Graphics g, 653 int w, int h, Object[] args) { 654 boolean accEnabled = false; 655 Skin skin = (Skin)args[0]; 656 Part part = skin.part; 657 State state = (State)args[1]; 658 if (state == null) { 659 state = skin.state; 660 } 661 if (c == null) { 662 c = skin.component; 663 } 664 BufferedImage bi = (BufferedImage)image; 665 666 WritableRaster raster = bi.getRaster(); 667 DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer(); 668 // Note that stealData() requires a markDirty() afterwards 669 // since we modify the data in it. 670 ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0), 671 part.getControlName(c), part.getValue(), 672 State.getValue(part, state), 673 0, 0, w, h, w); 674 SunWritableRaster.markDirty(dbi); 675 } 676 677 protected Image createImage(Component c, int w, int h, 678 GraphicsConfiguration config, Object[] args) { 679 return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 680 } 681 } 682 683 @SuppressWarnings("serial") // Superclass is not serializable across versions 684 static class GlyphButton extends JButton { 685 private Skin skin; 686 687 public GlyphButton(Component parent, Part part) { 688 XPStyle xp = getXP(); 689 skin = xp.getSkin(parent, part); 690 setBorder(null); 691 setContentAreaFilled(false); 692 setMinimumSize(new Dimension(5, 5)); 693 setPreferredSize(new Dimension(16, 16)); 694 setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 695 } 696 697 public boolean isFocusTraversable() { 698 return false; 699 } 700 701 protected State getState() { 702 State state = State.NORMAL; 703 if (!isEnabled()) { 704 state = State.DISABLED; 705 } else if (getModel().isPressed()) { 706 state = State.PRESSED; 707 } else if (getModel().isRollover()) { 708 state = State.HOT; 709 } 710 return state; 711 } 712 713 public void paintComponent(Graphics g) { 714 Dimension d = getSize(); 715 skin.paintSkin(g, 0, 0, d.width, d.height, getState()); 716 } 717 718 public void setPart(Component parent, Part part) { 719 XPStyle xp = getXP(); 720 skin = xp.getSkin(parent, part); 721 revalidate(); 722 repaint(); 723 } 724 725 protected void paintBorder(Graphics g) { 726 } 727 728 729 } 730 731 // Private constructor 732 private XPStyle() { 733 flatMenus = getSysBoolean(Prop.FLATMENUS); 734 735 colorMap = new HashMap<String, Color>(); 736 borderMap = new HashMap<String, Border>(); 737 // Note: All further access to the maps must be synchronized 738 } 739 740 741 private boolean getBoolean(Component c, Part part, State state, Prop prop) { 742 return ThemeReader.getBoolean(part.getControlName(c), part.getValue(), 743 State.getValue(part, state), 744 prop.getValue()); 745 } 746 747 748 749 static Dimension getPartSize(Part part, State state) { 750 return ThemeReader.getPartSize(part.getControlName(null), part.getValue(), 751 State.getValue(part, state)); 752 } 753 754 private static boolean getSysBoolean(Prop prop) { 755 // We can use any widget name here, I guess. 756 return ThemeReader.getSysBoolean("window", prop.getValue()); 757 } 758 }