1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.chainsaw.icons;
19
20 import java.awt.BasicStroke;
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Graphics;
24 import java.awt.Graphics2D;
25 import java.awt.GraphicsEnvironment;
26 import java.awt.RenderingHints;
27 import java.awt.image.BufferedImage;
28
29 import javax.swing.Icon;
30 import javax.swing.ImageIcon;
31
32 import org.apache.log4j.LogManager;
33 import org.apache.log4j.Logger;
34
35
36
37
38
39
40
41
42
43 public final class LineIconFactory {
44 private static final Logger logger = LogManager.getLogger(LineIconFactory.class);
45
46
47
48 private LineIconFactory() {
49 }
50
51 public static Icon createExpandIcon() {
52 int size = 8;
53 int xOffSet = 0;
54 int yOffSet = 0;
55 try {
56 GraphicsEnvironment environment =
57 GraphicsEnvironment.getLocalGraphicsEnvironment();
58 BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
59 Graphics2D g2D =
60 environment.createGraphics(
61 image);
62 g2D.setBackground(new Color(0,0,0,0));
63 g2D.clearRect(0,0,size,size);
64 g2D.setStroke(new BasicStroke(1.5f));
65 g2D.setRenderingHint(
66 RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
67 g2D.setColor(Color.black);
68 g2D.drawLine(
69 xOffSet, (size / 2) + yOffSet, size - xOffSet,
70 (size / 2) + yOffSet);
71
72 g2D.drawLine(
73 xOffSet + (size/2), yOffSet, xOffSet + (size/2),
74 (size) + yOffSet);
75
76 return new ImageIcon(image);
77 } catch (Exception e) {
78 logger.error("failed to create a Expand icon", e);
79 }
80
81 return null;
82 }
83 public static Icon createCollapseIcon() {
84 int size = 8;
85 int xOffSet = 0;
86 int yOffSet = 0;
87 try {
88 GraphicsEnvironment environment =
89 GraphicsEnvironment.getLocalGraphicsEnvironment();
90 BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
91 Graphics2D g2D =
92 environment.createGraphics(
93 image);
94 g2D.setBackground(new Color(0,0,0,0));
95 g2D.clearRect(0,0,size,size);
96 g2D.setStroke(new BasicStroke(1.5f));
97 g2D.setRenderingHint(
98 RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
99 g2D.setColor(Color.black);
100 g2D.drawLine(
101 xOffSet, (size / 2) + yOffSet, size - xOffSet,
102 (size / 2) + yOffSet);
103
104 return new ImageIcon(image);
105 } catch (Exception e) {
106 logger.error("failed to create a Collapse icon", e);
107 }
108
109 return null;
110 }
111
112 public static Icon createCloseIcon() {
113 return new CloseIcon(8, 0, 0);
114 }
115
116 public static Icon createBlankIcon() {
117 return new BlankIcon(16);
118 }
119
120
121
122
123
124
125
126 private static class BlankIcon implements Icon {
127 int size;
128
129 public BlankIcon(int size) {
130 this.size = size;
131 }
132
133 public int getIconHeight() {
134 return size;
135 }
136
137 public int getIconWidth() {
138 return size;
139 }
140
141 public void paintIcon(Component c, Graphics g, int x, int y) {
142 }
143 }
144
145
146
147
148
149
150
151 private static class CloseIcon implements Icon {
152 int size;
153 int xOffSet;
154 int yOffSet;
155
156 public CloseIcon(int size, int xOffSet, int yOffSet) {
157 this.size = size;
158 this.xOffSet = xOffSet;
159 this.yOffSet = yOffSet;
160 }
161
162 public int getIconHeight() {
163 return size;
164 }
165
166 public int getIconWidth() {
167 return size;
168 }
169
170 public void paintIcon(Component c, Graphics g, int x, int y) {
171 Graphics2D g2D = (Graphics2D) g;
172 g2D.setStroke(new BasicStroke(1.5f));
173 g2D.setRenderingHint(
174 RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
175 g2D.setColor(Color.black);
176 g2D.drawLine(
177 x + xOffSet, y + yOffSet, x + size + xOffSet, y + size + yOffSet);
178 g2D.drawLine(
179 x + xOffSet, y + size + yOffSet, x + size + xOffSet, y + yOffSet);
180 }
181 }
182 }