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 private boolean switchStates = false; 483 484 Skin(Component component, Part part) { 485 this(component, part, null); 486 } 487 488 Skin(Part part, State state) { 489 this(null, part, state); 490 } 491 492 Skin(Component component, Part part, State state) { 493 this.component = component; 494 this.part = part; 495 this.state = state; 496 497 String str = part.getControlName(component) +"." + part.name(); 498 if (state != null) { 499 str += "("+state.name()+")"; 500 } 501 string = str; 502 } 503 504 Insets getContentMargin() { 505 /* idk: it seems margins are the same for all 'big enough' 506 * bounding rectangles. 507 */ 508 int boundingWidth = 100; 509 int boundingHeight = 100; 510 511 Insets insets = ThemeReader.getThemeBackgroundContentMargins( 512 part.getControlName(null), part.getValue(), 513 0, boundingWidth, boundingHeight); 514 return (insets != null) ? insets : new Insets(0, 0, 0, 0); 515 } 516 517 boolean haveToSwitchStates() { 518 return switchStates; 519 } 520 521 void switchStates(boolean b) { 522 switchStates = b; 523 } 524 525 private int getWidth(State state) { 526 if (size == null) { 527 size = getPartSize(part, state); 528 } 529 return (size != null) ? size.width : 0; 530 } 531 532 int getWidth() { 533 return getWidth((state != null) ? state : State.NORMAL); 534 } 535 536 private int getHeight(State state) { 537 if (size == null) { 538 size = getPartSize(part, state); 539 } 540 return (size != null) ? size.height : 0; 541 } 542 543 int getHeight() { 544 return getHeight((state != null) ? state : State.NORMAL); 545 } 546 547 public String toString() { 548 return string; 549 } 550 551 public boolean equals(Object obj) { 552 return (obj instanceof Skin && ((Skin)obj).string.equals(string)); 553 } 554 555 public int hashCode() { 556 return string.hashCode(); 557 } 558 559 /** Paint a skin at x, y. 560 * 561 * @param g the graphics context to use for painting 562 * @param dx the destination <i>x</i> coordinate 563 * @param dy the destination <i>y</i> coordinate 564 * @param state which state to paint 565 */ 566 void paintSkin(Graphics g, int dx, int dy, State state) { 567 if (state == null) { 568 state = this.state; 569 } 570 paintSkin(g, dx, dy, getWidth(state), getHeight(state), state); 571 } 572 573 /** Paint a skin in an area defined by a rectangle. 574 * 575 * @param g the graphics context to use for painting 576 * @param r a <code>Rectangle</code> defining the area to fill, 577 * may cause the image to be stretched or tiled 578 * @param state which state to paint 579 */ 580 void paintSkin(Graphics g, Rectangle r, State state) { 581 paintSkin(g, r.x, r.y, r.width, r.height, state); 582 } 583 584 /** Paint a skin at a defined position and size 585 * This method supports animation. 586 * 587 * @param g the graphics context to use for painting 588 * @param dx the destination <i>x</i> coordinate 589 * @param dy the destination <i>y</i> coordinate 590 * @param dw the width of the area to fill, may cause 591 * the image to be stretched or tiled 592 * @param dh the height of the area to fill, may cause 593 * the image to be stretched or tiled 594 * @param state which state to paint 595 */ 596 void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) { 597 if (XPStyle.getXP() == null) { 598 return; 599 } 600 if (ThemeReader.isGetThemeTransitionDurationDefined() 601 && component instanceof JComponent 602 && SwingUtilities.getAncestorOfClass(CellRendererPane.class, 603 component) == null) { 604 AnimationController.paintSkin((JComponent) component, this, 605 g, dx, dy, dw, dh, state); 606 } else { 607 paintSkinRaw(g, dx, dy, dw, dh, state); 608 } 609 } 610 611 /** Paint a skin at a defined position and size. This method 612 * does not trigger animation. It is needed for the animation 613 * support. 614 * 615 * @param g the graphics context to use for painting 616 * @param dx the destination <i>x</i> coordinate. 617 * @param dy the destination <i>y</i> coordinate. 618 * @param dw the width of the area to fill, may cause 619 * the image to be stretched or tiled 620 * @param dh the height of the area to fill, may cause 621 * the image to be stretched or tiled 622 * @param state which state to paint 623 */ 624 void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) { 625 if (XPStyle.getXP() == null) { 626 return; 627 } 628 skinPainter.paint(null, g, dx, dy, dw, dh, this, state); 629 } 630 631 /** Paint a skin at a defined position and size 632 * 633 * @param g the graphics context to use for painting 634 * @param dx the destination <i>x</i> coordinate 635 * @param dy the destination <i>y</i> coordinate 636 * @param dw the width of the area to fill, may cause 637 * the image to be stretched or tiled 638 * @param dh the height of the area to fill, may cause 639 * the image to be stretched or tiled 640 * @param state which state to paint 641 * @param borderFill should test if the component uses a border fill 642 and skip painting if it is 643 */ 644 void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state, 645 boolean borderFill) { 646 if (XPStyle.getXP() == null) { 647 return; 648 } 649 if(borderFill && "borderfill".equals(getTypeEnumName(component, part, 650 state, Prop.BGTYPE))) { 651 return; 652 } 653 skinPainter.paint(null, g, dx, dy, dw, dh, this, state); 654 } 655 } 656 657 private static class SkinPainter extends CachedPainter { 658 SkinPainter() { 659 super(30); 660 flush(); 661 } 662 663 public void flush() { 664 super.flush(); 665 } 666 667 protected void paintToImage(Component c, Image image, Graphics g, 668 int w, int h, Object[] args) { 669 Skin skin = (Skin)args[0]; 670 Part part = skin.part; 671 State state = (State)args[1]; 672 if (state == null) { 673 state = skin.state; 674 } 675 if (c == null) { 676 c = skin.component; 677 } 678 BufferedImage bi = (BufferedImage)image; 679 w = bi.getWidth(); 680 h = bi.getHeight(); 681 682 WritableRaster raster = bi.getRaster(); 683 DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer(); 684 // Note that stealData() requires a markDirty() afterwards 685 // since we modify the data in it. 686 ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0), 687 part.getControlName(c), part.getValue(), 688 State.getValue(part, state), 689 0, 0, w, h, w); 690 SunWritableRaster.markDirty(dbi); 691 } 692 693 protected Image createImage(Component c, int w, int h, 694 GraphicsConfiguration config, Object[] args) { 695 return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 696 } 697 } 698 699 @SuppressWarnings("serial") // Superclass is not serializable across versions 700 static class GlyphButton extends JButton { 701 protected Skin skin; 702 703 public GlyphButton(Component parent, Part part) { 704 XPStyle xp = getXP(); 705 skin = xp != null ? xp.getSkin(parent, part) : null; 706 setBorder(null); 707 setContentAreaFilled(false); 708 setMinimumSize(new Dimension(5, 5)); 709 setPreferredSize(new Dimension(16, 16)); 710 setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 711 } 712 713 @SuppressWarnings("deprecation") 714 public boolean isFocusTraversable() { 715 return false; 716 } 717 718 protected State getState() { 719 State state = State.NORMAL; 720 if (!isEnabled()) { 721 state = State.DISABLED; 722 } else if (getModel().isPressed()) { 723 state = State.PRESSED; 724 } else if (getModel().isRollover()) { 725 state = State.HOT; 726 } 727 return state; 728 } 729 730 public void paintComponent(Graphics g) { 731 if (XPStyle.getXP() == null || skin == null) { 732 return; 733 } 734 Dimension d = getSize(); 735 skin.paintSkin(g, 0, 0, d.width, d.height, getState()); 736 } 737 738 public void setPart(Component parent, Part part) { 739 XPStyle xp = getXP(); 740 skin = xp != null ? xp.getSkin(parent, part) : null; 741 revalidate(); 742 repaint(); 743 } 744 745 protected void paintBorder(Graphics g) { 746 } 747 748 749 } 750 751 // Private constructor 752 private XPStyle() { 753 flatMenus = getSysBoolean(Prop.FLATMENUS); 754 755 colorMap = new HashMap<String, Color>(); 756 borderMap = new HashMap<String, Border>(); 757 // Note: All further access to the maps must be synchronized 758 } 759 760 761 private boolean getBoolean(Component c, Part part, State state, Prop prop) { 762 return ThemeReader.getBoolean(part.getControlName(c), part.getValue(), 763 State.getValue(part, state), 764 prop.getValue()); 765 } 766 767 768 769 static Dimension getPartSize(Part part, State state) { 770 return ThemeReader.getPartSize(part.getControlName(null), part.getValue(), 771 State.getValue(part, state)); 772 } 773 774 private static boolean getSysBoolean(Prop prop) { 775 // We can use any widget name here, I guess. 776 return ThemeReader.getSysBoolean("window", prop.getValue()); 777 } 778 }