1
2
3
4
5 package hoplugins.trainingExperience.ui;
6
7 import hoplugins.Commons;
8
9 import hoplugins.commons.utils.PluginProperty;
10
11 import hoplugins.trainingExperience.constants.Skills;
12
13 import java.awt.Color;
14 import java.awt.GridLayout;
15 import java.awt.Image;
16 import java.awt.Toolkit;
17 import java.awt.image.FilteredImageSource;
18 import java.awt.image.RGBImageFilter;
19
20 import javax.swing.BorderFactory;
21 import javax.swing.Icon;
22 import javax.swing.ImageIcon;
23 import javax.swing.JLabel;
24 import javax.swing.JPanel;
25
26
27 /***
28 * DOCUMENT ME!
29 *
30 * @author <a href="mailto:kenmooda@users.sourceforge.net">Tommi Rautava </a>
31 */
32 public class TrainingLegendPanel extends JPanel {
33
34
35 /*** TODO Missing Parameter Documentation */
36 static final Color GREEN = new Color(0, 140, 0);
37
38 /*** TODO Missing Parameter Documentation */
39 static final Color LIGHT_GREEN = new Color(40, 155, 40);
40
41
42
43 /***
44 * Default constructor.
45 */
46 public TrainingLegendPanel() {
47 this.setLayout(new GridLayout(2, 5));
48
49 JLabel title = new JLabel(PluginProperty.getString("Legenda"), JLabel.LEFT);
50
51 title.setForeground(Color.BLACK);
52 this.add(title);
53
54 for (int i = 0; i < 4; i++) {
55 int skill = Skills.getSkillAtPosition(i);
56 this.add(getSkillupLabel(Skills.getSkillDescription(skill), skill));
57 }
58
59 this.add(new JLabel(""));
60
61 for (int i = 4; i < 8; i++) {
62 int skill = Skills.getSkillAtPosition(i);
63 this.add(getSkillupLabel(Skills.getSkillDescription(skill), skill));
64 }
65
66 this.setBorder(BorderFactory.createEtchedBorder(0));
67 }
68
69
70
71 /***
72 * Create a position colored label.
73 *
74 * @param title text of the label
75 * @param skill color of the text
76 *
77 * @return a label
78 */
79 public static final JLabel getSkillupLabel(String title, int skill) {
80 Icon icon = getSkillupTypeIcon(skill);
81
82 return new JLabel(title, icon, JLabel.LEFT);
83 }
84
85 /***
86 * DOCUMENT ME!
87 *
88 * @param skill
89 *
90 * @return icon
91 */
92 public static final Icon getSkillupTypeIcon(int skill) {
93 Color color = Skills.getSkillColor(skill);
94 Color lcolor = new Color(Math.min(color.getRed() + 20, 255),
95 Math.min(color.getGreen() + 20, 255),
96 Math.min(color.getBlue() + 20, 255), 224);
97
98 ImageIcon icon = Commons.getModel().getHelper().getImageIcon4Veraenderung(1);
99 Image image = ReplaceImageColor(icon.getImage(), GREEN, color);
100
101 image = ReplaceImageColor(image, LIGHT_GREEN, lcolor);
102
103 return new ImageIcon(image);
104 }
105
106 /***
107 * DOCUMENT ME!
108 *
109 * @param image
110 * @param oldColor
111 * @param newColor
112 *
113 * @return Image
114 */
115 public static Image ReplaceImageColor(Image image, Color oldColor, Color newColor) {
116 FilteredImageSource filteredimagesource = new FilteredImageSource(image.getSource(),
117 ((java.awt.image.ImageFilter) (new ColorReplaceFilter(oldColor,
118 newColor,
119 Color.WHITE))));
120
121 return Toolkit.getDefaultToolkit().createImage(((java.awt.image.ImageProducer) (filteredimagesource)));
122 }
123
124
125
126 /***
127 * Color replacement filter class
128 */
129 public static final class ColorReplaceFilter extends RGBImageFilter {
130
131
132 /*** TODO Missing Parameter Documentation */
133 boolean transparency = false;
134
135 /*** TODO Missing Parameter Documentation */
136 int newColor = 0;
137
138 /*** TODO Missing Parameter Documentation */
139 int oldColor = 0;
140
141 /*** TODO Missing Parameter Documentation */
142 int transparentColor = 0;
143
144
145
146 /***
147 * Creates a new ColorReplaceFilter object.
148 *
149 * @param oldColor TODO Missing Constructuor Parameter Documentation
150 * @param newColor TODO Missing Constructuor Parameter Documentation
151 * @param transparentColor TODO Missing Constructuor Parameter Documentation
152 */
153 ColorReplaceFilter(Color oldColor, Color newColor, Color transparentColor) {
154 this.oldColor = oldColor.getRGB();
155 this.newColor = newColor.getRGB();
156
157 if (transparentColor != null) {
158 transparency = true;
159 this.transparentColor = transparentColor.getRGB() | 0xff000000;
160 }
161 }
162
163
164
165 /***
166 * TODO Missing Method Documentation
167 *
168 * @param x TODO Missing Method Parameter Documentation
169 * @param y TODO Missing Method Parameter Documentation
170 * @param rgb TODO Missing Method Parameter Documentation
171 *
172 * @return TODO Missing Return Method Documentation
173 */
174 public int filterRGB(int x, int y, int rgb) {
175 if (transparency && ((rgb | 0xff000000) == transparentColor)) {
176 return 0;
177 } else if (rgb == oldColor) {
178 return newColor;
179 } else {
180 return rgb;
181 }
182 }
183 }
184 }