Debian Codegraph @

src/com/bulenkov/iconloader/util/EmptyIcon.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2014 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.bulenkov.iconloader.util;
18
19 import javax.swing.*;
20 import java.awt.*;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 /**
25 * @author Konstantin Bulenkov
26 */
27 public class EmptyIcon implements Icon {
28 private static final Map<Integer, Icon> cache = new HashMap<Integer, Icon>();
29 private final int width;
30 private final int height;
31
32 public static Icon create(int size) {
33 Icon icon = cache.get(size);
34 if (icon == null && size < 129) {
35 cache.put(size, icon = new EmptyIcon(size, size));
36 }
37 return icon == null ? new EmptyIcon(size, size) : icon;
38 }
39
40 public static Icon create(int width, int height) {
41 return width == height ? create(width) : new EmptyIcon(width, height);
42 }
43
44 public static Icon create(Icon base) {
45 return create(base.getIconWidth(), base.getIconHeight());
46 }
47
48 /**
49 * @deprecated use {@linkplain #create(int)} for caching.
50 */
51 public EmptyIcon(int size) {
52 this(size, size);
53 }
54
55 public EmptyIcon(int width, int height) {
56 this.width = width;
57 this.height = height;
58 }
59
60 /**
61 * @deprecated use {@linkplain #create(javax.swing.Icon)} for caching.
62 */
63 public EmptyIcon(Icon base) {
64 this(base.getIconWidth(), base.getIconHeight());
65 }
66
67 public int getIconWidth() {
68 return width;
69 }
70
71 public int getIconHeight() {
72 return height;
73 }
74
75 public void paintIcon(Component component, Graphics g, int i, int j) {
76 }
77
78 public boolean equals(Object o) {
79 if (this == o) return true;
80 if (!(o instanceof EmptyIcon)) return false;
81
82 final EmptyIcon icon = (EmptyIcon) o;
83
84 return height == icon.height && width == icon.width;
85
86 }
87
88 public int hashCode() {
89 int sum = width + height;
90 return sum * (sum + 1) / 2 + width;
91 }
92 }