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 javax.swing.*;
21 import javax.swing.plaf.metal.MetalLookAndFeel;
22 import java.awt.*;
23 import java.net.URL;
24 import java.util.HashMap;
25 import java.util.Map;
26
27
28
29 public class LevelIconFactory {
30 private static final LevelIconFactory instance = new LevelIconFactory();
31 private final Map<String, javax.swing.Icon> iconMap = new HashMap<>();
32
33 private LevelIconFactory() {
34
35 String[] iconFileNames =
36 new String[]{"Warn.gif", "Inform.gif", "Error.gif", "Error.gif"};
37 String[] iconLabels = new String[]{"WARN", "INFO", "ERROR", "FATAL"};
38
39 for (int i = 0; i < iconLabels.length; i++) {
40 URL resourceURL = UIManager.getLookAndFeel().getClass().getResource(
41 "icons/" + iconFileNames[i]);
42 if (resourceURL == null) {
43 resourceURL = MetalLookAndFeel.class.getResource(
44 "icons/" + iconFileNames[i]);
45 }
46 if (resourceURL == null) {
47 iconMap.put(iconLabels[i], ChainsawIcons.ICON_DEBUG);
48 } else {
49
50 final ImageIcon icon =
51 new ImageIcon(resourceURL);
52 double scalex = .5;
53 double scaley = .5;
54 final int newWidth = (int) (scalex * icon.getIconWidth());
55 final int newHeight = (int) (scaley * icon.getIconHeight());
56 Image iconImage =
57 icon.getImage().getScaledInstance(
58 newWidth, newHeight, Image.SCALE_SMOOTH);
59 iconMap.put(iconLabels[i], new ImageIcon(iconImage));
60 }
61 }
62
63 iconMap.put("TRACE", ChainsawIcons.ICON_DEBUG);
64 iconMap.put("DEBUG", ChainsawIcons.ICON_DEBUG);
65 }
66
67 public static final LevelIconFactory getInstance() {
68 return instance;
69 }
70
71 public Map<String, javax.swing.Icon> getLevelToIconMap() {
72 return iconMap;
73 }
74 }