001: /*
002: * @(#)QuaquaIconFactory.java 3.2 2007-01-05
003: *
004: * Copyright (c) 2005-2006 Werner Randelshofer
005: * Staldenmattweg 2, Immensee, CH-6405, Switzerland.
006: * All rights reserved.
007: *
008: * This software is the confidential and proprietary information of
009: * Werner Randelshofer. ("Confidential Information"). You shall not
010: * disclose such Confidential Information and shall use it only in
011: * accordance with the terms of the license agreement you entered into
012: * with Werner Randelshofer.
013: */
014:
015: package contrib.ch.randelshofer.quaqua;
016:
017: import java.net.*;
018: import java.awt.*;
019: import java.awt.image.*;
020: import javax.swing.*;
021: import javax.swing.plaf.*;
022:
023: import contrib.ch.randelshofer.quaqua.util.*; //import javax.imageio.*;
024: //import javax.imageio.stream.*;
025: import java.io.*;
026: import java.util.*;
027:
028: /**
029: * QuaquaIconFactory.
030: *
031: * @author Werner Randelshofer, Christopher Atlan
032: * @version 3.2 2007-01-05 Issue #1: Changed LazyOptionPaneIcon to load image
033: * asynchronously before paintIcon is invoked.
034: * <br>3.1 2006-12-24 by Karl von Randow: Use Images class to create artwork.
035: * <br>3.0.2 2006-11-01 Use Graphics2D.drawImage() to scale application
036: * image icon instead of using Image.getScaledInstance().
037: * <br>3.0.1 2006-05-14 Application icon was unnecessarily created multiple
038: * times.
039: * <br>3.0 2006-05-12 Added support for file icon images. Renamed some
040: * methods.
041: * <br>2.1 2006-02-14 Added method createFrameButtonStateIcon.
042: * <br>2.0 2006-02-12 Added methods createApplicationIcon, compose,
043: * createOptionPaneIcon. These methods were contributed by Christopher Atlan.
044: * <br>1.0 December 4, 2005 Created.
045: */
046: public class QuaquaIconFactory {
047: private static BufferedImage applicationImage;
048:
049: /**
050: * Prevent instance creation.
051: */
052: private QuaquaIconFactory() {
053: }
054:
055: public static URL getResource(String location) {
056: URL url = QuaquaIconFactory.class.getResource(location);
057: if (url == null) {
058: throw new InternalError("image resource missing: "
059: + location);
060: }
061: return url;
062: }
063:
064: public static Image createImage(String location) {
065: return createImage(QuaquaIconFactory.class, location);
066: }
067:
068: public static Image createImage(Class baseClass, String location) {
069: return Images.createImage(baseClass.getResource(location));
070: }
071:
072: public static Image createBufferedImage(String location) {
073: return Images.toBufferedImage(createImage(location));
074: }
075:
076: public static Icon[] createIcons(String location, int count,
077: boolean horizontal) {
078: Icon[] icons = new Icon[count];
079:
080: BufferedImage[] images = Images.split(
081: (Image) createImage(location), count, horizontal);
082:
083: for (int i = 0; i < count; i++) {
084: icons[i] = new IconUIResource(new ImageIcon(images[i]));
085: }
086: return icons;
087: }
088:
089: public static Icon createIcon(String location, int count,
090: boolean horizontal, int index) {
091: return createIcons(location, count, horizontal)[index];
092: }
093:
094: public static Icon createButtonStateIcon(String location, int states) {
095: return new ButtonStateIcon((Image) createImage(location),
096: states, true);
097: }
098:
099: public static Icon createButtonStateIcon(String location,
100: int states, Point shift) {
101: return new ShiftedIcon(new ButtonStateIcon(
102: (Image) createImage(location), states, true), shift);
103: }
104:
105: public static Icon createButtonStateIcon(String location,
106: int states, Rectangle shift) {
107: return new ShiftedIcon(new ButtonStateIcon(
108: (Image) createImage(location), states, true), shift);
109: }
110:
111: public static Icon createIcon(Class baseClass, String location) {
112: return new ImageIcon(createImage(baseClass, location));
113: }
114:
115: public static Icon createIcon(Class baseClass, String location,
116: Point shift) {
117: return new ShiftedIcon(new ImageIcon(createImage(baseClass,
118: location)), shift);
119: }
120:
121: public static Icon createIcon(Class baseClass, String location,
122: Rectangle shiftAndSize) {
123: return new ShiftedIcon(new ImageIcon(createImage(baseClass,
124: location)), shiftAndSize);
125: }
126:
127: }
|