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