1package de.ur.mi.oop.utils;
3import de.ur.mi.oop.colors.Color;
4import de.ur.mi.oop.graphics.Label;
5import de.ur.mi.oop.graphics.Rectangle;
7import java.util.LinkedHashMap;
52 private static final int X_POSITION = 5;
53 private static final int Y_POSITION = 5;
54 private static final int MIN_WIDTH = 1;
55 private static final int MIN_HEIGHT = 1;
56 private static final int PADDING = 10;
57 private static final Color BACKGROUND_COLOR =
new Color(250, 250, 250, 150);
58 private static final Color BORDER_COLOR =
new Color(200, 200, 200, 150);
59 private static final float BORDER_WEIGHT = 1;
60 private static final String FONT_NAME =
"Monospaced";
61 private static final Color FONT_COLOR =
new Color(30, 30, 30);
62 private static final int FONT_SIZE = 10;
63 private static final String TITLE =
"### Debug Info ###";
68 private final LinkedHashMap<String, Label> values;
69 private boolean isVisible;
72 background =
new Rectangle(X_POSITION, Y_POSITION, MIN_WIDTH, MIN_HEIGHT, BACKGROUND_COLOR);
73 background.
setBorder(BORDER_COLOR, BORDER_WEIGHT);
74 values =
new LinkedHashMap<>();
76 updateOrAddLabel(TITLE,
"");
81 if (instance ==
null) {
87 private void updateOrAddLabel(String name, String value) {
88 Label label = values.get(name);
90 label = createLabel(name, value);
91 values.put(name, label);
93 label.
setText(name +
": " + value);
97 private Label createLabel(String name, String value) {
98 Label label =
new Label(0, 0, name +
": " + value, FONT_COLOR);
99 if (name.equals(TITLE)) {
107 private void pack() {
110 float x = background.
getXPos() + PADDING;
111 float y = background.
getYPos() + PADDING;
112 for (
Label label : values.values()) {
113 label.setPosition(x, y);
114 y += FONT_SIZE + PADDING;
115 minHeight += FONT_SIZE + PADDING;
116 if (minWidth < label.getWidthEstimate()) {
117 minWidth = label.getWidthEstimate();
120 background.
setWidth(minWidth + 2 * PADDING);
121 background.
setHeight(minHeight - FONT_SIZE);
124 private void setValue(String name, String value) {
125 updateOrAddLabel(name, value);
129 private void removeValue(String name) {
134 private void showInfo() {
147 for (
Label label : values.values()) {
152 public static void set(String name, String value) {
153 getInstance().setValue(name, value);
156 public static void set(String name,
boolean value) {
157 set(name, String.valueOf(value));
160 public static void set(String name,
short value) {
161 set(name, String.valueOf(value));
164 public static void set(String name,
int value) {
165 set(name, String.valueOf(value));
168 public static void set(String name,
float value) {
169 set(name, String.valueOf(value));
172 public static void set(String name,
double value) {
173 set(name, String.valueOf(value));
176 public static void set(String name,
char value) {
177 set(name, String.valueOf(value));
180 public static void remove(String name) {
181 getInstance().removeValue(name);
185 getInstance().showInfo();
void setWidth(float width)
void setHeight(float height)
void setBorder(Color color, float weight)
void setFontSize(int fontSize)
void setText(String text)
void setFont(String font)