Skip to content

Commit 73d081a

Browse files
author
Paulsen
committed
v1.1.5 UI
- Changed Standard-Colors - Colors for all Elements can be set with setStandardColor(..) - StandardColors can be overwritten by the local color-Array over setColor(..) - Rounded-Corners Design
1 parent 2577ed6 commit 73d081a

File tree

7 files changed

+115
-122
lines changed

7 files changed

+115
-122
lines changed

src/ooo/paulsen/demo/Demo.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static void main(String[] args) {
3535

3636
PSerialConnection usb;
3737

38+
private boolean isDarkmode = true;
39+
private Color[] otherMode = {Color.white, Color.BLACK, Color.darkGray, Color.lightGray};
40+
3841
public Demo() {
3942

4043
try {
@@ -104,17 +107,28 @@ public void paint(Graphics2D g, int x, int y, int w, int h) {
104107
setMatrixElements(false);
105108

106109

107-
darkModeButton = new PUIText(f, "LIGHT", 2);
110+
darkModeButton = new PUIText(f, "DARK", 2);
108111
darkModeButton.addActionListener(new PUIAction() {
109112
@Override
110113
public void run(PUIElement that) {
111-
PUIElement.darkUIMode = !PUIElement.darkUIMode;
112-
if (PUIElement.darkUIMode) {
113-
darkModeButton.setText("DARK");
114-
sp.setEnabled(false); // set any Element as disabled -> No more Interaction and no Visuals with this Element
115-
} else {
114+
if (isDarkmode) {
115+
116+
//swapping colors
117+
Color temp[] = otherMode;
118+
otherMode = PUIElement.default_colors;
119+
PUIElement.default_colors = temp;
120+
121+
isDarkmode = false;
116122
darkModeButton.setText("LIGHT");
117-
sp.setEnabled(true);
123+
} else {
124+
125+
//swapping colors
126+
Color temp[] = otherMode;
127+
otherMode = PUIElement.default_colors;
128+
PUIElement.default_colors = temp;
129+
130+
isDarkmode = true;
131+
darkModeButton.setText("DARK");
118132
}
119133
}
120134
});
@@ -214,7 +228,7 @@ public void update(int w, int h) {
214228
// Set Position of other non-relative Elements
215229
darkModeButton.setBounds(50, 50, 300, 100);
216230
slider.setBounds(50, 200, 300, 50);
217-
slider2.setBounds(50, 250, 300, 50);
231+
slider2.setBounds(50, 251, 300, 50);
218232

219233
f.updateElements();
220234

src/ooo/paulsen/io/serial/PSerialConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static String[] getSerialPorts() {
3030
// Private Constructor
3131
public PSerialConnection(SerialPort port) {
3232
if (port == null)
33-
throw new SerialPortInvalidPortException("Port can not be null!");
33+
throw new SerialPortInvalidPortException("Port can not be null!", null);
3434
initSerial(port);
3535
}
3636

src/ooo/paulsen/ui/PUICheckBox.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ public void draw(Graphics2D g) {
3737
if (!activated)
3838
return;
3939

40-
if (darkUIMode)
41-
g.setColor(darkSelected);
42-
else
43-
g.setColor(Color.green);
44-
g.fillOval(x + w / 10, y + h / 10, w - w / 5, h - h / 5);
40+
g.setColor(getTextColor());
41+
g.fillRoundRect(x + w / 10, y + h / 10, w - w / 5, h - h / 5, arcWidth, arcHeight);
4542
}
4643

4744
}

src/ooo/paulsen/ui/PUIElement.java

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@
99
import java.awt.event.MouseMotionListener;
1010
import java.awt.event.MouseWheelListener;
1111
import java.util.ArrayList;
12+
import java.util.Arrays;
1213
import java.util.concurrent.CopyOnWriteArrayList;
1314

1415
public class PUIElement extends PUICanvas { // PaulsenUserInterfaceIntegratedElement
1516

1617
// Static
1718
public static volatile boolean useGBC = false; // signals PUICore to use System.gbc()
1819
public static volatile CopyOnWriteArrayList<PUIElement> registeredElements = new CopyOnWriteArrayList<PUIElement>();
19-
public static boolean darkUIMode = false;
20-
public static Color darkBG_1 = new Color(47, 47, 47), darkBG_2 = new Color(57, 57, 57),
21-
darkOutline = new Color(81, 81, 81), darkText = new Color(235, 235, 235),
22-
darkSelected = new Color(196, 196, 196);
20+
public static volatile Color[] default_colors = new Color[]{
21+
new Color(47, 47, 47), // BG
22+
new Color(196, 196, 196), // Text
23+
new Color(57, 57, 57), // BG_accent
24+
new Color(81, 81, 81) // Text_accent
25+
};
2326

2427
public enum ElementAlignment {
2528
HORIZONTAL, VERTICAL
2629
}
2730

28-
protected int x = 0, y = 0, w = 0, h = 0;
29-
protected Color backgroundColor = Color.LIGHT_GRAY;
31+
protected int x = 0, y = 0, w = 0, h = 0, arcWidth = 15, arcHeight = 15;
32+
protected volatile Color colors[] = new Color[0];
3033
protected PUIPaintable hoverOverlay, pressOverlay;
3134
protected PUIFrame frame;
3235
protected PUICore core;
@@ -63,15 +66,13 @@ private void init() {
6366
mouseMotionListeners.add(new MouseMotionListener() {
6467
@Override
6568
public void mouseMoved(MouseEvent e) {
66-
if (!enabled)
67-
return;
69+
if (!enabled) return;
6870
hovered = contains(e.getPoint());
6971
}
7072

7173
@Override
7274
public void mouseDragged(MouseEvent e) {
73-
if (!enabled)
74-
return;
75+
if (!enabled) return;
7576
Point p = e.getPoint();
7677
hovered = contains(e.getPoint());
7778

@@ -80,16 +81,14 @@ public void mouseDragged(MouseEvent e) {
8081
mouseListeners.add(new MouseListener() {
8182
@Override
8283
public void mouseReleased(MouseEvent e) {
83-
if (enabled)
84-
hovered = contains(e.getPoint());
84+
if (enabled) hovered = contains(e.getPoint());
8585
pressed = false;
8686
isCurrentlyPressing = false;
8787
}
8888

8989
@Override
9090
public void mousePressed(MouseEvent e) {
91-
if (!enabled)
92-
return;
91+
if (!enabled) return;
9392
if (!pressed && hovered) {
9493
Point p = e.getPoint();
9594
if (p != null && getBounds().contains(p)) {
@@ -116,31 +115,25 @@ public void mouseClicked(MouseEvent e) {
116115
paint = new PUIPaintable() {
117116
@Override
118117
public void paint(Graphics2D g, int x, int y, int w, int h) {
119-
if (darkUIMode && backgroundColor == Color.LIGHT_GRAY) {
120-
g.setColor(darkBG_1);
121-
g.fillRect(x, y, w, h);
122-
g.setColor(darkOutline);
123-
g.drawRect(x, y, w, h);
124-
} else {
125-
g.setColor(backgroundColor);
126-
g.fillRect(x, y, w, h);
127-
g.setColor(new Color(50, 50, 50));
128-
g.drawRect(x, y, w, h);
129-
}
118+
g.setColor(getBackgroundColor());
119+
g.fillRoundRect(x, y, w, h, arcWidth, arcHeight);
120+
121+
g.setColor(color(2));
122+
g.drawRoundRect(x, y, w, h, arcWidth, arcHeight);
130123
}
131124
};
132125
hoverOverlay = new PUIPaintable() {
133126
@Override
134127
public void paint(Graphics2D g, int x, int y, int w, int h) {
135128
g.setColor(new Color(100, 100, 100, 100));
136-
g.fillRect(x, y, w, h);
129+
g.fillRoundRect(x, y, w, h, arcWidth, arcHeight);
137130
}
138131
};
139132
pressOverlay = new PUIPaintable() {
140133
@Override
141134
public void paint(Graphics2D g, int x, int y, int w, int h) {
142135
g.setColor(new Color(100, 100, 100, 200));
143-
g.fillRect(x, y, w, h);
136+
g.fillRoundRect(x, y, w, h, arcWidth, arcHeight);
144137
}
145138
};
146139
}
@@ -169,19 +162,16 @@ private void initCore() {
169162

170163
@Override
171164
public synchronized void draw(Graphics2D g) {
172-
if (g == null || !isEnabled())
173-
return;
165+
if (g == null || !isEnabled()) return;
174166

175167
if (paint != null) {
176168
paint.paint(g, x, y, w, h);
177169
}
178170
if (hovered) {
179171
if (hovered && !pressed && paintOverOnHover) {
180-
if (hoverOverlay != null)
181-
hoverOverlay.paint(g, x, y, w, h);
172+
if (hoverOverlay != null) hoverOverlay.paint(g, x, y, w, h);
182173
} else if (pressed && paintOverOnPress) {
183-
if (pressOverlay != null)
184-
pressOverlay.paint(g, x, y, w, h);
174+
if (pressOverlay != null) pressOverlay.paint(g, x, y, w, h);
185175
}
186176
}
187177
}
@@ -205,10 +195,8 @@ public ArrayList<PUIAction> getActionListeners() {
205195

206196
public void runAllActions() {
207197

208-
if (actions != null)
209-
for (PUIAction r : actions)
210-
if (r != null)
211-
r.run(this);
198+
if (actions != null) for (PUIAction r : actions)
199+
if (r != null) r.run(this);
212200

213201
if (repaintFrameOnEvent && frame != null) {
214202
frame.repaint();
@@ -359,10 +347,8 @@ public void setInteractionLayer(int interactionLayer) {
359347
public void setLayer(int l) {
360348
drawLayer = l;
361349
interactionLayer = l;
362-
if (core != null)
363-
core.rearrangeElements();
364-
if (frame != null)
365-
frame.rearrangeElements();
350+
if (core != null) core.rearrangeElements();
351+
if (frame != null) frame.rearrangeElements();
366352
}
367353

368354
public ArrayList<MouseMotionListener> getMouseMotionListeners() {
@@ -378,11 +364,56 @@ public ArrayList<MouseListener> getMouseListeners() {
378364
}
379365

380366
public Color getBackgroundColor() {
381-
return backgroundColor;
367+
return color(0);
368+
}
369+
370+
public Color getTextColor() {
371+
return color(1);
382372
}
383373

384374
public void setBackgroundColor(Color backgroundColor) {
385-
this.backgroundColor = backgroundColor;
375+
setColor(0, backgroundColor);
376+
}
377+
378+
public Color color(int index) {
379+
if (colors.length > index) {
380+
return colors[index];
381+
}
382+
if (default_colors.length > index) {
383+
return default_colors[index];
384+
}
385+
return null;
386+
}
387+
388+
public void setColor(int index, Color color) {
389+
if (colors.length > index) {
390+
colors[index] = color;
391+
} else {
392+
colors = Arrays.copyOf(colors, index + 1);
393+
colors[index] = color;
394+
}
395+
}
396+
397+
/**
398+
* @return Default-Color of the library - Null if the Could does not exist
399+
*/
400+
public static Color getDefaultColor(int index) {
401+
if (default_colors.length > index) {
402+
return default_colors[index];
403+
}
404+
return null;
405+
}
406+
407+
/*
408+
Sets Default-Color of the library
409+
*/
410+
public static void setDefaultColor(int index, Color color) {
411+
if (default_colors.length > index) {
412+
default_colors[index] = color;
413+
} else {
414+
default_colors = Arrays.copyOf(default_colors, index + 1);
415+
default_colors[index] = color;
416+
}
386417
}
387418

388419
public Object getMetadata() {

src/ooo/paulsen/ui/PUIRotaryControl.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public class PUIRotaryControl extends PUIElement {
2020
protected float mouseMultiplicator = 0.005f;
2121
private CopyOnWriteArrayList<PUIAction> valueUpdateAction = new CopyOnWriteArrayList<>();
2222
private float value = .5f;
23-
private Color valueColor = Color.GRAY;
24-
private Color backgroundColor = Color.LIGHT_GRAY;
2523
private ElementAlignment alignment = ElementAlignment.VERTICAL;
2624
private boolean useMouseWheel = true;
2725

@@ -50,34 +48,22 @@ public void paint(Graphics2D g, int x, int y, int w, int h) {
5048
h = -h;
5149

5250
// BG
53-
if (darkUIMode && backgroundColor == Color.LIGHT_GRAY)
54-
g.setColor(darkBG_1);
55-
else
56-
g.setColor(backgroundColor);
51+
g.setColor(getBackgroundColor());
5752
g.fillOval(x, y, w, h);
5853

5954
// value-visual
60-
if (darkUIMode && valueColor == Color.GRAY)
61-
g.setColor(darkSelected);
62-
else
63-
g.setColor(valueColor);
55+
g.setColor(getTextColor());
6456

6557
// Value-Visual
6658
g.fillArc(x, y, w, h, (int) (360 - ((rotationArea * value + (360 - rotationArea) / 2 + 90) + valueThickness / 2)), (int) valueThickness);
6759

6860
// Overpaint part of ^ , to visualize valueLength
69-
if (darkUIMode && backgroundColor == Color.LIGHT_GRAY)
70-
g.setColor(darkBG_1);
71-
else
72-
g.setColor(backgroundColor);
61+
g.setColor(getBackgroundColor());
7362

7463
g.fillOval((int) (x + (1.0f - valueLength) * (w / 2)), (int) (y + (1.0f - valueLength) * (h / 2)), (int) (w * (valueLength)), (int) (h * (valueLength)));
7564

7665
// Outline
77-
if (darkUIMode)
78-
g.setColor(darkOutline);
79-
else
80-
g.setColor(Color.black);
66+
g.setColor(getBackgroundColor());
8167
g.drawOval(x, y, w, h);
8268

8369
}
@@ -196,14 +182,6 @@ public void setValueThickness(float valueThickness) {
196182
this.valueThickness = valueThickness;
197183
}
198184

199-
public Color getValueColor() {
200-
return valueColor;
201-
}
202-
203-
public void setValueColor(Color valueColor) {
204-
this.valueColor = valueColor;
205-
}
206-
207185
public boolean isMouseWheelUsed() {
208186
return useMouseWheel;
209187
}
@@ -212,14 +190,6 @@ public void setUseMouseWheel(boolean useMouseWheel) {
212190
this.useMouseWheel = useMouseWheel;
213191
}
214192

215-
public Color getBackgroundColor() {
216-
return backgroundColor;
217-
}
218-
219-
public void setBackgroundColor(Color backgroundColor) {
220-
this.backgroundColor = backgroundColor;
221-
}
222-
223193
public float getMouseMultiplicator() {
224194
return mouseMultiplicator;
225195
}

0 commit comments

Comments
 (0)