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