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 package javax.swing.plaf.metal;
27
28 import javax.swing.*;
29 import javax.swing.plaf.UIResource;
30 import java.awt.*;
31 import java.awt.image.BufferedImage;
32 import java.io.Serializable;
33 import java.util.Enumeration;
34 import java.util.Vector;
35 import sun.swing.CachedPainter;
36
37 /**
38 * Factory object that vends <code>Icon</code>s for
39 * the Java™ look and feel (Metal).
40 * These icons are used extensively in Metal via the defaults mechanism.
41 * While other look and feels often use GIFs for icons, creating icons
42 * in code facilitates switching to other themes.
43 *
44 * <p>
45 * Each method in this class returns
46 * either an <code>Icon</code> or <code>null</code>,
47 * where <code>null</code> implies that there is no default icon.
48 *
49 * <p>
50 * <strong>Warning:</strong>
51 * Serialized objects of this class will not be compatible with
52 * future Swing releases. The current serialization support is
53 * appropriate for short term storage or RMI between applications running
54 * the same version of Swing. As of 1.4, support for long term storage
55 * of all JavaBeans™
56 * has been added to the <code>java.beans</code> package.
57 * Please see {@link java.beans.XMLEncoder}.
58 *
59 * @author Michael C. Albers
60 */
61 @SuppressWarnings("serial") // Same-version serialization only
62 public class MetalIconFactory implements Serializable {
63
64 // List of code-drawn Icons
65 private static Icon fileChooserDetailViewIcon;
66 private static Icon fileChooserHomeFolderIcon;
67 private static Icon fileChooserListViewIcon;
68 private static Icon fileChooserNewFolderIcon;
69 private static Icon fileChooserUpFolderIcon;
70 private static Icon internalFrameAltMaximizeIcon;
71 private static Icon internalFrameCloseIcon;
72 private static Icon internalFrameDefaultMenuIcon;
73 private static Icon internalFrameMaximizeIcon;
74 private static Icon internalFrameMinimizeIcon;
75 private static Icon radioButtonIcon;
76 private static Icon treeComputerIcon;
298 * @param isCollapsed if {@code true} the icon is collapsed
299 * @return a new instance of {@code TreeControlIcon}
300 */
301 public static Icon getTreeControlIcon( boolean isCollapsed ) {
302 return new TreeControlIcon( isCollapsed );
303 }
304
305 /**
306 * Returns an icon to be used by {@code JMenu}.
307 *
308 * @return an icon to be used by {@code JMenu}
309 */
310 public static Icon getMenuArrowIcon() {
311 if (menuArrowIcon == null) {
312 menuArrowIcon = new MenuArrowIcon();
313 }
314 return menuArrowIcon;
315 }
316
317 /**
318 * Returns an icon to be used by <code>JCheckBoxMenuItem</code>.
319 *
320 * @return the default icon for check box menu items,
321 * or <code>null</code> if no default exists
322 */
323 public static Icon getMenuItemCheckIcon() {
324 return null;
325 }
326
327 /**
328 * Returns an icon to be used by {@code JMenuItem}.
329 *
330 * @return an icon to be used by {@code JMenuItem}
331 */
332 public static Icon getMenuItemArrowIcon() {
333 if (menuItemArrowIcon == null) {
334 menuItemArrowIcon = new MenuItemArrowIcon();
335 }
336 return menuItemArrowIcon;
337 }
338
339 /**
340 * Returns an icon to be used by {@code JCheckBoxMenuItem}.
341 *
1666 }
1667 return currentImageGcPair.image;
1668 }
1669
1670 void cacheImage(Image image, GraphicsConfiguration gc) {
1671 ImageGcPair imgGcPair = new ImageGcPair(image, gc);
1672 images.addElement(imgGcPair);
1673 currentImageGcPair = imgGcPair;
1674 }
1675
1676 }
1677
1678 /**
1679 * <p>
1680 * <strong>Warning:</strong>
1681 * Serialized objects of this class will not be compatible with
1682 * future Swing releases. The current serialization support is
1683 * appropriate for short term storage or RMI between applications running
1684 * the same version of Swing. As of 1.4, support for long term storage
1685 * of all JavaBeans™
1686 * has been added to the <code>java.beans</code> package.
1687 * Please see {@link java.beans.XMLEncoder}.
1688 */
1689 @SuppressWarnings("serial") // Same-version serialization only
1690 public static class FolderIcon16 implements Icon, Serializable {
1691
1692 ImageCacher imageCacher;
1693
1694 public void paintIcon(Component c, Graphics g, int x, int y) {
1695 GraphicsConfiguration gc = c.getGraphicsConfiguration();
1696 if (imageCacher == null) {
1697 imageCacher = new ImageCacher();
1698 }
1699 Image image = imageCacher.getImage(gc);
1700 if (image == null) {
1701 if (gc != null) {
1702 image = gc.createCompatibleImage(getIconWidth(),
1703 getIconHeight(),
1704 Transparency.BITMASK);
1705 } else {
1706 image = new BufferedImage(getIconWidth(),
1760 /**
1761 * Returns an additional height of the icon.
1762 *
1763 * @return an additional height of the icon
1764 */
1765 public int getAdditionalHeight() { return 0; }
1766
1767 public int getIconWidth() { return folderIcon16Size.width; }
1768 public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); }
1769 }
1770
1771
1772 /**
1773 * <p>
1774 * <strong>Warning:</strong>
1775 * Serialized objects of this class will not be compatible with
1776 * future Swing releases. The current serialization support is
1777 * appropriate for short term storage or RMI between applications running
1778 * the same version of Swing. As of 1.4, support for long term storage
1779 * of all JavaBeans™
1780 * has been added to the <code>java.beans</code> package.
1781 * Please see {@link java.beans.XMLEncoder}.
1782 */
1783 @SuppressWarnings("serial") // Same-version serialization only
1784 public static class TreeFolderIcon extends FolderIcon16 {
1785 public int getShift() { return -1; }
1786 public int getAdditionalHeight() { return 2; }
1787 }
1788
1789
1790 private static final Dimension fileIcon16Size = new Dimension( 16, 16 );
1791
1792 /**
1793 * <p>
1794 * <strong>Warning:</strong>
1795 * Serialized objects of this class will not be compatible with
1796 * future Swing releases. The current serialization support is
1797 * appropriate for short term storage or RMI between applications running
1798 * the same version of Swing. As of 1.4, support for long term storage
1799 * of all JavaBeans™
1800 * has been added to the <code>java.beans</code> package.
1801 * Please see {@link java.beans.XMLEncoder}.
1802 */
1803 @SuppressWarnings("serial") // Same-version serialization only
1804 public static class FileIcon16 implements Icon, Serializable {
1805
1806 ImageCacher imageCacher;
1807
1808 public void paintIcon(Component c, Graphics g, int x, int y) {
1809 GraphicsConfiguration gc = c.getGraphicsConfiguration();
1810 if (imageCacher == null) {
1811 imageCacher = new ImageCacher();
1812 }
1813 Image image = imageCacher.getImage(gc);
1814 if (image == null) {
1815 if (gc != null) {
1816 image = gc.createCompatibleImage(getIconWidth(),
1817 getIconHeight(),
1818 Transparency.BITMASK);
1819 } else {
1820 image = new BufferedImage(getIconWidth(),
1880
1881 /**
1882 * The class represents a tree leaf icon.
1883 */
1884 public static class TreeLeafIcon extends FileIcon16 {
1885 public int getShift() { return 2; }
1886 public int getAdditionalHeight() { return 4; }
1887 }
1888
1889
1890 private static final Dimension treeControlSize = new Dimension( 18, 18 );
1891
1892 /**
1893 * <p>
1894 * <strong>Warning:</strong>
1895 * Serialized objects of this class will not be compatible with
1896 * future Swing releases. The current serialization support is
1897 * appropriate for short term storage or RMI between applications running
1898 * the same version of Swing. As of 1.4, support for long term storage
1899 * of all JavaBeans™
1900 * has been added to the <code>java.beans</code> package.
1901 * Please see {@link java.beans.XMLEncoder}.
1902 */
1903 @SuppressWarnings("serial") // Same-version serialization only
1904 public static class TreeControlIcon implements Icon, Serializable {
1905
1906 /**
1907 * if {@code true} the icon is collapsed.
1908 * NOTE: This data member should not have been exposed. It's called
1909 * {@code isLight}, but now it really means {@code isCollapsed}.
1910 * Since we can't change any APIs... that's life.
1911 */
1912 protected boolean isLight;
1913
1914 /**
1915 * Constructs an instance of {@code TreeControlIcon}.
1916 *
1917 * @param isCollapsed if {@code true} the icon is collapsed
1918 */
1919 public TreeControlIcon( boolean isCollapsed ) {
1920 isLight = isCollapsed;
|
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 package javax.swing.plaf.metal;
27
28 import javax.swing.*;
29 import javax.swing.plaf.UIResource;
30 import java.awt.*;
31 import java.awt.image.BufferedImage;
32 import java.io.Serializable;
33 import java.util.Enumeration;
34 import java.util.Vector;
35 import sun.swing.CachedPainter;
36
37 /**
38 * Factory object that vends {@code Icon}s for
39 * the Java™ look and feel (Metal).
40 * These icons are used extensively in Metal via the defaults mechanism.
41 * While other look and feels often use GIFs for icons, creating icons
42 * in code facilitates switching to other themes.
43 *
44 * <p>
45 * Each method in this class returns
46 * either an {@code Icon} or {@code null},
47 * where {@code null} implies that there is no default icon.
48 *
49 * <p>
50 * <strong>Warning:</strong>
51 * Serialized objects of this class will not be compatible with
52 * future Swing releases. The current serialization support is
53 * appropriate for short term storage or RMI between applications running
54 * the same version of Swing. As of 1.4, support for long term storage
55 * of all JavaBeans™
56 * has been added to the {@code java.beans} package.
57 * Please see {@link java.beans.XMLEncoder}.
58 *
59 * @author Michael C. Albers
60 */
61 @SuppressWarnings("serial") // Same-version serialization only
62 public class MetalIconFactory implements Serializable {
63
64 // List of code-drawn Icons
65 private static Icon fileChooserDetailViewIcon;
66 private static Icon fileChooserHomeFolderIcon;
67 private static Icon fileChooserListViewIcon;
68 private static Icon fileChooserNewFolderIcon;
69 private static Icon fileChooserUpFolderIcon;
70 private static Icon internalFrameAltMaximizeIcon;
71 private static Icon internalFrameCloseIcon;
72 private static Icon internalFrameDefaultMenuIcon;
73 private static Icon internalFrameMaximizeIcon;
74 private static Icon internalFrameMinimizeIcon;
75 private static Icon radioButtonIcon;
76 private static Icon treeComputerIcon;
298 * @param isCollapsed if {@code true} the icon is collapsed
299 * @return a new instance of {@code TreeControlIcon}
300 */
301 public static Icon getTreeControlIcon( boolean isCollapsed ) {
302 return new TreeControlIcon( isCollapsed );
303 }
304
305 /**
306 * Returns an icon to be used by {@code JMenu}.
307 *
308 * @return an icon to be used by {@code JMenu}
309 */
310 public static Icon getMenuArrowIcon() {
311 if (menuArrowIcon == null) {
312 menuArrowIcon = new MenuArrowIcon();
313 }
314 return menuArrowIcon;
315 }
316
317 /**
318 * Returns an icon to be used by {@code JCheckBoxMenuItem}.
319 *
320 * @return the default icon for check box menu items,
321 * or {@code null} if no default exists
322 */
323 public static Icon getMenuItemCheckIcon() {
324 return null;
325 }
326
327 /**
328 * Returns an icon to be used by {@code JMenuItem}.
329 *
330 * @return an icon to be used by {@code JMenuItem}
331 */
332 public static Icon getMenuItemArrowIcon() {
333 if (menuItemArrowIcon == null) {
334 menuItemArrowIcon = new MenuItemArrowIcon();
335 }
336 return menuItemArrowIcon;
337 }
338
339 /**
340 * Returns an icon to be used by {@code JCheckBoxMenuItem}.
341 *
1666 }
1667 return currentImageGcPair.image;
1668 }
1669
1670 void cacheImage(Image image, GraphicsConfiguration gc) {
1671 ImageGcPair imgGcPair = new ImageGcPair(image, gc);
1672 images.addElement(imgGcPair);
1673 currentImageGcPair = imgGcPair;
1674 }
1675
1676 }
1677
1678 /**
1679 * <p>
1680 * <strong>Warning:</strong>
1681 * Serialized objects of this class will not be compatible with
1682 * future Swing releases. The current serialization support is
1683 * appropriate for short term storage or RMI between applications running
1684 * the same version of Swing. As of 1.4, support for long term storage
1685 * of all JavaBeans™
1686 * has been added to the {@code java.beans} package.
1687 * Please see {@link java.beans.XMLEncoder}.
1688 */
1689 @SuppressWarnings("serial") // Same-version serialization only
1690 public static class FolderIcon16 implements Icon, Serializable {
1691
1692 ImageCacher imageCacher;
1693
1694 public void paintIcon(Component c, Graphics g, int x, int y) {
1695 GraphicsConfiguration gc = c.getGraphicsConfiguration();
1696 if (imageCacher == null) {
1697 imageCacher = new ImageCacher();
1698 }
1699 Image image = imageCacher.getImage(gc);
1700 if (image == null) {
1701 if (gc != null) {
1702 image = gc.createCompatibleImage(getIconWidth(),
1703 getIconHeight(),
1704 Transparency.BITMASK);
1705 } else {
1706 image = new BufferedImage(getIconWidth(),
1760 /**
1761 * Returns an additional height of the icon.
1762 *
1763 * @return an additional height of the icon
1764 */
1765 public int getAdditionalHeight() { return 0; }
1766
1767 public int getIconWidth() { return folderIcon16Size.width; }
1768 public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); }
1769 }
1770
1771
1772 /**
1773 * <p>
1774 * <strong>Warning:</strong>
1775 * Serialized objects of this class will not be compatible with
1776 * future Swing releases. The current serialization support is
1777 * appropriate for short term storage or RMI between applications running
1778 * the same version of Swing. As of 1.4, support for long term storage
1779 * of all JavaBeans™
1780 * has been added to the {@code java.beans} package.
1781 * Please see {@link java.beans.XMLEncoder}.
1782 */
1783 @SuppressWarnings("serial") // Same-version serialization only
1784 public static class TreeFolderIcon extends FolderIcon16 {
1785 public int getShift() { return -1; }
1786 public int getAdditionalHeight() { return 2; }
1787 }
1788
1789
1790 private static final Dimension fileIcon16Size = new Dimension( 16, 16 );
1791
1792 /**
1793 * <p>
1794 * <strong>Warning:</strong>
1795 * Serialized objects of this class will not be compatible with
1796 * future Swing releases. The current serialization support is
1797 * appropriate for short term storage or RMI between applications running
1798 * the same version of Swing. As of 1.4, support for long term storage
1799 * of all JavaBeans™
1800 * has been added to the {@code java.beans} package.
1801 * Please see {@link java.beans.XMLEncoder}.
1802 */
1803 @SuppressWarnings("serial") // Same-version serialization only
1804 public static class FileIcon16 implements Icon, Serializable {
1805
1806 ImageCacher imageCacher;
1807
1808 public void paintIcon(Component c, Graphics g, int x, int y) {
1809 GraphicsConfiguration gc = c.getGraphicsConfiguration();
1810 if (imageCacher == null) {
1811 imageCacher = new ImageCacher();
1812 }
1813 Image image = imageCacher.getImage(gc);
1814 if (image == null) {
1815 if (gc != null) {
1816 image = gc.createCompatibleImage(getIconWidth(),
1817 getIconHeight(),
1818 Transparency.BITMASK);
1819 } else {
1820 image = new BufferedImage(getIconWidth(),
1880
1881 /**
1882 * The class represents a tree leaf icon.
1883 */
1884 public static class TreeLeafIcon extends FileIcon16 {
1885 public int getShift() { return 2; }
1886 public int getAdditionalHeight() { return 4; }
1887 }
1888
1889
1890 private static final Dimension treeControlSize = new Dimension( 18, 18 );
1891
1892 /**
1893 * <p>
1894 * <strong>Warning:</strong>
1895 * Serialized objects of this class will not be compatible with
1896 * future Swing releases. The current serialization support is
1897 * appropriate for short term storage or RMI between applications running
1898 * the same version of Swing. As of 1.4, support for long term storage
1899 * of all JavaBeans™
1900 * has been added to the {@code java.beans} package.
1901 * Please see {@link java.beans.XMLEncoder}.
1902 */
1903 @SuppressWarnings("serial") // Same-version serialization only
1904 public static class TreeControlIcon implements Icon, Serializable {
1905
1906 /**
1907 * if {@code true} the icon is collapsed.
1908 * NOTE: This data member should not have been exposed. It's called
1909 * {@code isLight}, but now it really means {@code isCollapsed}.
1910 * Since we can't change any APIs... that's life.
1911 */
1912 protected boolean isLight;
1913
1914 /**
1915 * Constructs an instance of {@code TreeControlIcon}.
1916 *
1917 * @param isCollapsed if {@code true} the icon is collapsed
1918 */
1919 public TreeControlIcon( boolean isCollapsed ) {
1920 isLight = isCollapsed;
|