Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EmptyIcon |
|
| 2.1666666666666665;2.167 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy.gui; | |
11 | ||
12 | import java.awt.Component; | |
13 | import java.awt.Graphics; | |
14 | import java.io.Serializable; | |
15 | ||
16 | import javax.swing.Icon; | |
17 | ||
18 | /** | |
19 | * An icon that does not have any content. | |
20 | * <p>Use icons of this type if you need an icon that has a specific size | |
21 | * but does not render any content.</p> | |
22 | * @since 0.1.0 | |
23 | */ | |
24 | public final class EmptyIcon | |
25 | implements Icon, Serializable | |
26 | { | |
27 | ||
28 | //---- Static | |
29 | ||
30 | /** | |
31 | * @since 0.1.0 | |
32 | */ | |
33 | private static final long serialVersionUID = -5944654665535461825L; | |
34 | ||
35 | /** | |
36 | * Returns an empty icon of the specified size. | |
37 | * @param size the dimensions of the icons as string in form '[width]x[height]', | |
38 | * for example {@code 22x22}. | |
39 | * @return the icon requested. | |
40 | * @throws IllegalArgumentException if the icon size specified cannot be parsed. | |
41 | * @since 0.1.0 | |
42 | */ | |
43 | public static final Icon getIcon (String size) throws IllegalArgumentException { | |
44 | 0 | if (size == null) { |
45 | 0 | throw new IllegalArgumentException("Size of icon is [null]."); |
46 | } | |
47 | 0 | final String[] dimension = size.split("x"); |
48 | 0 | if (dimension.length != 2) { |
49 | 0 | throw new IllegalArgumentException( |
50 | "Size of icon cannot be determined from [" + size + "]." | |
51 | ); | |
52 | } | |
53 | try { | |
54 | 0 | final int width = Integer.parseInt(dimension[0]); |
55 | 0 | final int height = Integer.parseInt(dimension[1]); |
56 | 0 | return getIcon(width, height); |
57 | 0 | } catch (NumberFormatException e) { |
58 | 0 | throw new IllegalArgumentException( |
59 | "Size of icon cannot be determined from [" + size + "]." | |
60 | ); | |
61 | } | |
62 | } | |
63 | ||
64 | /** | |
65 | * Returns an empty icon of the specified size. | |
66 | * @param width the width of the icon. | |
67 | * @param height the height of the icon. | |
68 | * @return the icon requested. | |
69 | * @since 0.1.0 | |
70 | */ | |
71 | public static final Icon getIcon (int width, int height) { | |
72 | 0 | return new EmptyIcon(width, height); |
73 | } | |
74 | ||
75 | //---- State | |
76 | ||
77 | /** | |
78 | * The width of this icon. | |
79 | * @since 0.1.0 | |
80 | */ | |
81 | private final int width; | |
82 | ||
83 | /** | |
84 | * The height of this icon. | |
85 | * @since 0.1.0 | |
86 | */ | |
87 | private final int height; | |
88 | ||
89 | //---- Constructors | |
90 | ||
91 | /** | |
92 | * Creates an empty icon of the specified dimensions. | |
93 | * @param width the width of the icon. | |
94 | * @param height the height of the icon. | |
95 | * @since 0.1.0 | |
96 | */ | |
97 | 0 | private EmptyIcon (int width, int height) { |
98 | 0 | this.width = width; |
99 | 0 | this.height = height; |
100 | 0 | } |
101 | ||
102 | //---- Icons | |
103 | ||
104 | /** | |
105 | * @since 0.1.0 | |
106 | */ | |
107 | public int getIconHeight () { | |
108 | 0 | return this.height; |
109 | } | |
110 | ||
111 | /** | |
112 | * @since 0.1.0 | |
113 | */ | |
114 | public int getIconWidth () { | |
115 | 0 | return this.width; |
116 | } | |
117 | ||
118 | /** | |
119 | * @since 0.1.0 | |
120 | */ | |
121 | public void paintIcon ( | |
122 | final Component component, | |
123 | final Graphics graphics, | |
124 | final int xCoord, | |
125 | final int yCoord | |
126 | ) { | |
127 | // Nop. | |
128 | 0 | } |
129 | ||
130 | } |