1 package org.opentrafficsim.editor;
2
3 import java.awt.Color;
4
5 import javax.swing.JLabel;
6
7 import org.opentrafficsim.draw.ColorInterpolator;
8 import org.opentrafficsim.swing.gui.AppearanceControl;
9
10
11
12
13
14
15
16
17
18
19
20 public class StatusLabel extends JLabel implements AppearanceControl
21 {
22
23
24 private static final long serialVersionUID = 20231017L;
25
26
27 private Color appearanceBackgroundColor;
28
29
30 private Color appearanceForegroundColor;
31
32
33
34
35 public StatusLabel()
36 {
37
38 }
39
40
41 @Override
42 public boolean isBackground()
43 {
44 return true;
45 }
46
47
48 @Override
49 public boolean isForeground()
50 {
51 return true;
52 }
53
54
55 @Override
56 public boolean isFont()
57 {
58 return true;
59 }
60
61
62 @Override
63 public void setBackground(final Color bg)
64 {
65 this.appearanceBackgroundColor = bg;
66 super.setBackground(bg);
67 updateForgroundColor();
68 }
69
70
71 @Override
72 public void setForeground(final Color fg)
73 {
74 this.appearanceForegroundColor = fg;
75 super.setForeground(fg);
76 updateForgroundColor();
77 }
78
79
80
81
82 private void updateForgroundColor()
83 {
84 if (this.appearanceForegroundColor != null && this.appearanceBackgroundColor != null)
85 {
86 super.setForeground(
87 ColorInterpolator.interpolateColor(this.appearanceForegroundColor, this.appearanceBackgroundColor, 0.7));
88 }
89 }
90
91 }