290 if ("name" == eName || 291 "ancestor" == eName || 292 "Nimbus.Overrides" == eName || 293 "Nimbus.Overrides.InheritDefaults" == eName || 294 "JComponent.sizeVariant" == eName) { 295 296 JComponent c = (JComponent) ev.getSource(); 297 defaults.clearOverridesCache(c); 298 return true; 299 } 300 301 return super.shouldUpdateStyleOnEvent(ev); 302 } 303 304 /** 305 * <p>Registers a third party component with the NimbusLookAndFeel.</p> 306 * 307 * <p>Regions represent Components and areas within Components that act as 308 * independent painting areas. Once registered with the NimbusLookAndFeel, 309 * NimbusStyles for these Regions can be retrieved via the 310 * <code>getStyle</code> method.</p> 311 * 312 * <p>The NimbusLookAndFeel uses a standard naming scheme for entries in the 313 * UIDefaults table. The key for each property, state, painter, and other 314 * default registered in UIDefaults for a specific Region will begin with 315 * the specified <code>prefix</code></p> 316 * 317 * <p>For example, suppose I had a component named JFoo. Suppose I then registered 318 * this component with the NimbusLookAndFeel in this manner:</p> 319 * 320 * <pre><code> 321 * laf.register(NimbusFooUI.FOO_REGION, "Foo"); 322 * </code></pre> 323 * 324 * <p>In this case, I could then register properties for this component with 325 * UIDefaults in the following manner:</p> 326 * 327 * <pre><code> 328 * UIManager.put("Foo.background", new ColorUIResource(Color.BLACK)); 329 * UIManager.put("Foo.Enabled.backgroundPainter", new FooBackgroundPainter()); 330 * </code></pre> 331 * 332 * <p>It is also possible to register a named component with Nimbus. 333 * For example, suppose you wanted to style the background of a JPanel 334 * named "MyPanel" differently from other JPanels. You could accomplish this 335 * by doing the following:</p> 336 * 337 * <pre><code> 338 * laf.register(Region.PANEL, "\"MyPanel\""); 339 * UIManager.put("\"MyPanel\".background", new ColorUIResource(Color.RED)); 340 * </code></pre> 341 * 342 * @param region The Synth Region that is being registered. Such as Button, or 343 * ScrollBarThumb, or NimbusFooUI.FOO_REGION. 344 * @param prefix The UIDefault prefix. For example, could be ComboBox, or if 345 * a named components, "MyComboBox", or even something like 346 * ToolBar."MyComboBox"."ComboBox.arrowButton" 347 */ 348 public void register(Region region, String prefix) { 349 defaults.register(region, prefix); 350 } 512 * example "Button.background" --> "Button[Enabled].backgound" 513 */ 514 private class NimbusProperty implements UIDefaults.ActiveValue, UIResource { 515 private String prefix; 516 private String state = null; 517 private String suffix; 518 private boolean isFont; 519 520 private NimbusProperty(String prefix, String suffix) { 521 this.prefix = prefix; 522 this.suffix = suffix; 523 isFont = "font".equals(suffix); 524 } 525 526 private NimbusProperty(String prefix, String state, String suffix) { 527 this(prefix,suffix); 528 this.state = state; 529 } 530 531 /** 532 * Creates the value retrieved from the <code>UIDefaults</code> table. 533 * The object is created each time it is accessed. 534 * 535 * @param table a <code>UIDefaults</code> table 536 * @return the created <code>Object</code> 537 */ 538 @Override 539 public Object createValue(UIDefaults table) { 540 Object obj = null; 541 // check specified state 542 if (state!=null){ 543 obj = uiDefaults.get(prefix+"["+state+"]."+suffix); 544 } 545 // check enabled state 546 if (obj==null){ 547 obj = uiDefaults.get(prefix+"[Enabled]."+suffix); 548 } 549 // check for defaults 550 if (obj==null){ 551 if (isFont) { 552 obj = uiDefaults.get("defaultFont"); 553 } else { 554 obj = uiDefaults.get(suffix); 555 } 556 } | 290 if ("name" == eName || 291 "ancestor" == eName || 292 "Nimbus.Overrides" == eName || 293 "Nimbus.Overrides.InheritDefaults" == eName || 294 "JComponent.sizeVariant" == eName) { 295 296 JComponent c = (JComponent) ev.getSource(); 297 defaults.clearOverridesCache(c); 298 return true; 299 } 300 301 return super.shouldUpdateStyleOnEvent(ev); 302 } 303 304 /** 305 * <p>Registers a third party component with the NimbusLookAndFeel.</p> 306 * 307 * <p>Regions represent Components and areas within Components that act as 308 * independent painting areas. Once registered with the NimbusLookAndFeel, 309 * NimbusStyles for these Regions can be retrieved via the 310 * {@code getStyle} method.</p> 311 * 312 * <p>The NimbusLookAndFeel uses a standard naming scheme for entries in the 313 * UIDefaults table. The key for each property, state, painter, and other 314 * default registered in UIDefaults for a specific Region will begin with 315 * the specified {@code prefix}</p> 316 * 317 * <p>For example, suppose I had a component named JFoo. Suppose I then registered 318 * this component with the NimbusLookAndFeel in this manner:</p> 319 * 320 * <pre>{@code 321 * laf.register(NimbusFooUI.FOO_REGION, "Foo"); 322 * }</pre> 323 * 324 * <p>In this case, I could then register properties for this component with 325 * UIDefaults in the following manner:</p> 326 * 327 * <pre>{@code 328 * UIManager.put("Foo.background", new ColorUIResource(Color.BLACK)); 329 * UIManager.put("Foo.Enabled.backgroundPainter", new FooBackgroundPainter()); 330 * }</pre> 331 * 332 * <p>It is also possible to register a named component with Nimbus. 333 * For example, suppose you wanted to style the background of a JPanel 334 * named "MyPanel" differently from other JPanels. You could accomplish this 335 * by doing the following:</p> 336 * 337 * <pre><code> 338 * laf.register(Region.PANEL, "\"MyPanel\""); 339 * UIManager.put("\"MyPanel\".background", new ColorUIResource(Color.RED)); 340 * </code></pre> 341 * 342 * @param region The Synth Region that is being registered. Such as Button, or 343 * ScrollBarThumb, or NimbusFooUI.FOO_REGION. 344 * @param prefix The UIDefault prefix. For example, could be ComboBox, or if 345 * a named components, "MyComboBox", or even something like 346 * ToolBar."MyComboBox"."ComboBox.arrowButton" 347 */ 348 public void register(Region region, String prefix) { 349 defaults.register(region, prefix); 350 } 512 * example "Button.background" --> "Button[Enabled].backgound" 513 */ 514 private class NimbusProperty implements UIDefaults.ActiveValue, UIResource { 515 private String prefix; 516 private String state = null; 517 private String suffix; 518 private boolean isFont; 519 520 private NimbusProperty(String prefix, String suffix) { 521 this.prefix = prefix; 522 this.suffix = suffix; 523 isFont = "font".equals(suffix); 524 } 525 526 private NimbusProperty(String prefix, String state, String suffix) { 527 this(prefix,suffix); 528 this.state = state; 529 } 530 531 /** 532 * Creates the value retrieved from the {@code UIDefaults} table. 533 * The object is created each time it is accessed. 534 * 535 * @param table a {@code UIDefaults} table 536 * @return the created {@code Object} 537 */ 538 @Override 539 public Object createValue(UIDefaults table) { 540 Object obj = null; 541 // check specified state 542 if (state!=null){ 543 obj = uiDefaults.get(prefix+"["+state+"]."+suffix); 544 } 545 // check enabled state 546 if (obj==null){ 547 obj = uiDefaults.get(prefix+"[Enabled]."+suffix); 548 } 549 // check for defaults 550 if (obj==null){ 551 if (isFont) { 552 obj = uiDefaults.get("defaultFont"); 553 } else { 554 obj = uiDefaults.get(suffix); 555 } 556 } |