472 } 473 } 474 } // end WindowsTitlePaneLayout 475 476 public class WindowsPropertyChangeHandler extends PropertyChangeHandler { 477 public void propertyChange(PropertyChangeEvent evt) { 478 String prop = evt.getPropertyName(); 479 480 // Update the internal frame icon for the system menu. 481 if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) && 482 systemLabel != null) { 483 systemLabel.setIcon(frame.getFrameIcon()); 484 } 485 486 super.propertyChange(evt); 487 } 488 } 489 490 /** 491 * A versatile Icon implementation which can take an array of Icon 492 * instances (typically <code>ImageIcon</code>s) and choose one that gives the best 493 * quality for a given Graphics2D scale factor when painting. 494 * <p> 495 * The class is public so it can be instantiated by UIDefaults.ProxyLazyValue. 496 * <p> 497 * Note: We assume here that icons are square. 498 */ 499 public static class ScalableIconUIResource implements Icon, UIResource { 500 // We can use an arbitrary size here because we scale to it in paintIcon() 501 private static final int SIZE = 16; 502 503 private Icon[] icons; 504 505 /** 506 * @param objects an array of Icon or UIDefaults.LazyValue 507 * <p> 508 * The constructor is public so it can be called by UIDefaults.ProxyLazyValue. 509 */ 510 public ScalableIconUIResource(Object[] objects) { 511 this.icons = new Icon[objects.length]; 512 513 for (int i = 0; i < objects.length; i++) { 514 if (objects[i] instanceof UIDefaults.LazyValue) { 515 icons[i] = (Icon)((UIDefaults.LazyValue)objects[i]).createValue(null); 516 } else { 517 icons[i] = (Icon)objects[i]; 518 } 519 } 520 } 521 522 /** 523 * @return the <code>Icon</code> closest to the requested size 524 */ 525 protected Icon getBestIcon(int size) { 526 if (icons != null && icons.length > 0) { 527 int bestIndex = 0; 528 int minDiff = Integer.MAX_VALUE; 529 for (int i=0; i < icons.length; i++) { 530 Icon icon = icons[i]; 531 int iconSize; 532 if (icon != null && (iconSize = icon.getIconWidth()) > 0) { 533 int diff = Math.abs(iconSize - size); 534 if (diff < minDiff) { 535 minDiff = diff; 536 bestIndex = i; 537 } 538 } 539 } 540 return icons[bestIndex]; 541 } else { 542 return null; 543 } | 472 } 473 } 474 } // end WindowsTitlePaneLayout 475 476 public class WindowsPropertyChangeHandler extends PropertyChangeHandler { 477 public void propertyChange(PropertyChangeEvent evt) { 478 String prop = evt.getPropertyName(); 479 480 // Update the internal frame icon for the system menu. 481 if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) && 482 systemLabel != null) { 483 systemLabel.setIcon(frame.getFrameIcon()); 484 } 485 486 super.propertyChange(evt); 487 } 488 } 489 490 /** 491 * A versatile Icon implementation which can take an array of Icon 492 * instances (typically {@code ImageIcon}s) and choose one that gives the best 493 * quality for a given Graphics2D scale factor when painting. 494 * <p> 495 * The class is public so it can be instantiated by UIDefaults.ProxyLazyValue. 496 * <p> 497 * Note: We assume here that icons are square. 498 */ 499 public static class ScalableIconUIResource implements Icon, UIResource { 500 // We can use an arbitrary size here because we scale to it in paintIcon() 501 private static final int SIZE = 16; 502 503 private Icon[] icons; 504 505 /** 506 * @param objects an array of Icon or UIDefaults.LazyValue 507 * <p> 508 * The constructor is public so it can be called by UIDefaults.ProxyLazyValue. 509 */ 510 public ScalableIconUIResource(Object[] objects) { 511 this.icons = new Icon[objects.length]; 512 513 for (int i = 0; i < objects.length; i++) { 514 if (objects[i] instanceof UIDefaults.LazyValue) { 515 icons[i] = (Icon)((UIDefaults.LazyValue)objects[i]).createValue(null); 516 } else { 517 icons[i] = (Icon)objects[i]; 518 } 519 } 520 } 521 522 /** 523 * @return the {@code Icon} closest to the requested size 524 */ 525 protected Icon getBestIcon(int size) { 526 if (icons != null && icons.length > 0) { 527 int bestIndex = 0; 528 int minDiff = Integer.MAX_VALUE; 529 for (int i=0; i < icons.length; i++) { 530 Icon icon = icons[i]; 531 int iconSize; 532 if (icon != null && (iconSize = icon.getIconWidth()) > 0) { 533 int diff = Math.abs(iconSize - size); 534 if (diff < minDiff) { 535 minDiff = diff; 536 bestIndex = i; 537 } 538 } 539 } 540 return icons[bestIndex]; 541 } else { 542 return null; 543 } |