~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/internal/contrib/randelshofer/quaqua/QuaquaIconFactory.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * @(#)QuaquaIconFactory.java  3.2 2007-01-05
 
3
 *
 
4
 * Copyright (c) 2005-2006 Werner Randelshofer
 
5
 * Staldenmattweg 2, Immensee, CH-6405, Switzerland.
 
6
 * All rights reserved.
 
7
 *
 
8
 * This software is the confidential and proprietary information of
 
9
 * Werner Randelshofer. ("Confidential Information").  You shall not
 
10
 * disclose such Confidential Information and shall use it only in
 
11
 * accordance with the terms of the license agreement you entered into
 
12
 * with Werner Randelshofer.
 
13
 */
 
14
 
 
15
package org.pushingpixels.substance.internal.contrib.randelshofer.quaqua;
 
16
 
 
17
import java.net.*;
 
18
import java.awt.*;
 
19
import java.awt.image.*;
 
20
import javax.swing.*;
 
21
import javax.swing.plaf.*;
 
22
 
 
23
import org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.util.*;
 
24
 
 
25
//import javax.imageio.*;
 
26
//import javax.imageio.stream.*;
 
27
import java.io.*;
 
28
import java.util.*;
 
29
 
 
30
/**
 
31
 * QuaquaIconFactory.
 
32
 *
 
33
 * @author  Werner Randelshofer, Christopher Atlan
 
34
 * @version 3.2 2007-01-05 Issue #1: Changed LazyOptionPaneIcon to load image
 
35
 * asynchronously before paintIcon is invoked.
 
36
 * <br>3.1 2006-12-24 by Karl von Randow: Use Images class to create artwork.
 
37
 * <br>3.0.2 2006-11-01 Use Graphics2D.drawImage() to scale application
 
38
 * image icon instead of using Image.getScaledInstance(). 
 
39
 * <br>3.0.1 2006-05-14 Application icon was unnecessarily created multiple
 
40
 * times. 
 
41
 * <br>3.0 2006-05-12 Added support for file icon images. Renamed some
 
42
 * methods.
 
43
 * <br>2.1 2006-02-14 Added method createFrameButtonStateIcon.
 
44
 * <br>2.0 2006-02-12 Added methods createApplicationIcon, compose,
 
45
 * createOptionPaneIcon. These methods were contributed by Christopher Atlan.
 
46
 * <br>1.0 December 4, 2005 Created.
 
47
 */
 
48
public class QuaquaIconFactory {
 
49
    private static BufferedImage applicationImage;
 
50
    
 
51
    
 
52
    /**
 
53
     * Prevent instance creation.
 
54
     */
 
55
    private QuaquaIconFactory() {
 
56
    }
 
57
    
 
58
    public static URL getResource(String location) {
 
59
        URL url = QuaquaIconFactory.class.getResource(location);
 
60
        if (url == null) {
 
61
            throw new InternalError("image resource missing: "+location);
 
62
        }
 
63
        return url;
 
64
    }
 
65
    
 
66
    public static Image createImage(String location) {
 
67
        return createImage(QuaquaIconFactory.class, location);
 
68
    }
 
69
    public static Image createImage(Class baseClass, String location) {
 
70
        return Images.createImage(baseClass.getResource(location));
 
71
    }
 
72
    public static Image createBufferedImage(String location) {
 
73
        return Images.toBufferedImage(createImage(location));
 
74
    }
 
75
    
 
76
    public static Icon[] createIcons(String location, int count, boolean horizontal) {
 
77
        Icon[] icons = new Icon[count];
 
78
        
 
79
        BufferedImage[] images = Images.split(
 
80
                (Image) createImage(location),
 
81
                count, horizontal
 
82
                );
 
83
        
 
84
        for (int i=0; i < count; i++) {
 
85
            icons[i] = new IconUIResource(new ImageIcon(images[i]));
 
86
        }
 
87
        return icons;
 
88
    }
 
89
    
 
90
    public static Icon createIcon(String location, int count, boolean horizontal, int index) {
 
91
        return createIcons(location, count, horizontal)[index];
 
92
    }
 
93
    
 
94
    
 
95
    public static Icon createButtonStateIcon(String location, int states) {
 
96
        return new ButtonStateIcon(
 
97
                (Image) createImage(location),
 
98
                states, true
 
99
                );
 
100
    }
 
101
    public static Icon createButtonStateIcon(String location, int states, Point shift) {
 
102
        return new ShiftedIcon(
 
103
                new ButtonStateIcon(
 
104
                (Image) createImage(location),
 
105
                states, true
 
106
                ),
 
107
                shift
 
108
                );
 
109
    }
 
110
    public static Icon createButtonStateIcon(String location, int states, Rectangle shift) {
 
111
        return new ShiftedIcon(
 
112
                new ButtonStateIcon(
 
113
                (Image) createImage(location),
 
114
                states, true
 
115
                ),
 
116
                shift
 
117
                );
 
118
    }
 
119
    
 
120
    public static Icon createIcon(Class baseClass, String location) {
 
121
        return new ImageIcon(createImage(baseClass, location));
 
122
    }
 
123
    public static Icon createIcon(Class baseClass, String location, Point shift) {
 
124
        return new ShiftedIcon(
 
125
                new ImageIcon(createImage(baseClass, location)),
 
126
                shift
 
127
                );
 
128
    }
 
129
    public static Icon createIcon(Class baseClass, String location, Rectangle shiftAndSize) {
 
130
        return new ShiftedIcon(
 
131
                new ImageIcon(createImage(baseClass, location)),
 
132
                shiftAndSize
 
133
                );
 
134
    }
 
135
    
 
136
}