1
2 package hoplugins.trainingExperience.ui.bar;
3
4 import hoplugins.Commons;
5
6 import hoplugins.commons.utils.PluginProperty;
7
8 import java.awt.Color;
9 import java.awt.Dimension;
10 import java.awt.Graphics;
11
12 import javax.swing.JComponent;
13
14
15 /***
16 * Statusbalken für Trefferpunkte, Ausdauer und Erfahrung The bar is composed of 3 different bars
17 * one over the other, each one of 3 different colors
18 *
19 * @author Volker Fischer
20 * @version 0.1a 12.02.01
21 */
22 public class StateBar extends JComponent {
23
24
25 private ColorModus bkgcolor = new ColorModus(Color.DARK_GRAY);
26 private ColorModus color1;
27 private ColorModus color2;
28 private int breite = 100;
29 private int hoehe = 24;
30 private int level1;
31 private int level2;
32
33
34
35 /***
36 * Creates a new StateBar object, with the right levels
37 *
38 * @param lvl1
39 * @param lvl2
40 * @param c1
41 * @param c2
42 */
43 public StateBar(int lvl1, int lvl2, Color c1, Color c2) {
44 color1 = new ColorModus(c1);
45 color2 = new ColorModus(c2);
46 change(lvl1, lvl2);
47 setPreferredSize(new Dimension(breite, hoehe));
48 setOpaque(false);
49 }
50
51
52
53 /***
54 * Update the bar, with the new levels
55 *
56 * @param lvl1
57 * @param lvl2
58 */
59 public void change(int lvl1, int lvl2) {
60 level1 = lvl1;
61 level2 = lvl2;
62
63 String desc = "";
64
65 if (lvl1 > 0) {
66 desc = desc + Commons.getModel().getResource().getProperty("Aktuell") + lvl1 + "% ";
67 }
68
69 if (lvl2 > 0) {
70 desc = desc + PluginProperty.getString("Final") + lvl2 + "% ";
71 }
72
73 setToolTipText(desc);
74
75 paintImmediately(getBounds());
76 }
77
78 /***
79 * paint method
80 *
81 * @param g
82 */
83 public void paint(Graphics g) {
84 java.awt.Graphics2D g2d = (java.awt.Graphics2D) g;
85
86
87 g2d.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,
88 java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
89
90 int width = getWidth() - 10;
91 int height = getHeight();
92
93
94 g2d.setColor(bkgcolor.dunkel);
95 g2d.fillRect(5, (int) (height / 3), width, (int) (height / 3));
96 g2d.setColor(bkgcolor.mittel);
97 g2d.fillRect(6, (int) (height / 2.6f), width - 2, (int) (height / 5));
98 g2d.setColor(bkgcolor.hell);
99 g2d.fillRect(7, (int) (height / 2.3f), width - 3, (int) (height / 8));
100
101
102 setLevelBar(g2d, level2, color2);
103 setLevelBar(g2d, level1, color1);
104 }
105
106 /***
107 * Paint each single bar that compose the main object
108 *
109 * @param g2d graphic
110 * @param level length of the bar
111 * @param cm Color of the bar
112 */
113 private void setLevelBar(java.awt.Graphics2D g2d, int level, ColorModus cm) {
114 int height = getHeight();
115 int width = getWidth() - 10;
116 int laenge = (int) ((float) width * ((float) level / 100f));
117
118 g2d.setColor(cm.dunkel);
119 g2d.fillRect(5, (int) (height / 3), laenge, (int) (height / 3));
120 g2d.setColor(cm.mittel);
121 g2d.fillRect(6, (int) (height / 2.6f), laenge - 2, (int) (height / 5));
122 g2d.setColor(cm.hell);
123 g2d.fillRect(7, (int) (height / 2.3f), laenge - 3, (int) (height / 8));
124 }
125 }