Skip to content

Commit bda2ae3

Browse files
author
Paulsen
authored
V1.0.0
Added Features: - CustomProtocols - Managing of Files/Folders - DataStorage-System for storing/reading variable-values in files - Element-UI-System based on Java.awt.Component: + Frame (based on JFrame) + Element/Button + Checkbox + Textbutton + Slider + Scrollpanel + Rotarycontrol - Demo
1 parent 82ca074 commit bda2ae3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2470
-0
lines changed

bin/com/paulsen/demo/Main$1$1.class

1.18 KB
Binary file not shown.

bin/com/paulsen/demo/Main$1$2.class

811 Bytes
Binary file not shown.

bin/com/paulsen/demo/Main$1$3.class

897 Bytes
Binary file not shown.

bin/com/paulsen/demo/Main$1.class

2.73 KB
Binary file not shown.

bin/com/paulsen/demo/Main$2.class

1.19 KB
Binary file not shown.

bin/com/paulsen/demo/Main$3.class

1.15 KB
Binary file not shown.

bin/com/paulsen/demo/Main.class

1.2 KB
Binary file not shown.
3.06 KB
Binary file not shown.
1.25 KB
Binary file not shown.
Binary file not shown.

bin/com/paulsen/io/PDataStorage.class

6.59 KB
Binary file not shown.

bin/com/paulsen/io/PFile.class

6.25 KB
Binary file not shown.

bin/com/paulsen/io/PFolder$1.class

688 Bytes
Binary file not shown.

bin/com/paulsen/io/PFolder.class

3.64 KB
Binary file not shown.

bin/com/paulsen/ui/PUIAction.class

161 Bytes
Binary file not shown.
814 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUICheckBox.class

1.1 KB
Binary file not shown.

bin/com/paulsen/ui/PUIElement$1.class

1.45 KB
Binary file not shown.

bin/com/paulsen/ui/PUIElement$2.class

1.62 KB
Binary file not shown.

bin/com/paulsen/ui/PUIElement$3.class

1.17 KB
Binary file not shown.

bin/com/paulsen/ui/PUIElement$4.class

894 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUIElement$5.class

895 Bytes
Binary file not shown.
Binary file not shown.

bin/com/paulsen/ui/PUIElement.class

8.16 KB
Binary file not shown.

bin/com/paulsen/ui/PUIFrame$1.class

1.71 KB
Binary file not shown.

bin/com/paulsen/ui/PUIFrame$2.class

863 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUIFrame$3.class

986 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUIFrame.class

6.54 KB
Binary file not shown.
171 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUIPaintable.class

165 Bytes
Binary file not shown.
1.83 KB
Binary file not shown.
930 Bytes
Binary file not shown.
931 Bytes
Binary file not shown.
1.81 KB
Binary file not shown.
6.38 KB
Binary file not shown.
1.42 KB
Binary file not shown.
704 Bytes
Binary file not shown.
7.64 KB
Binary file not shown.

bin/com/paulsen/ui/PUISlider$1.class

1.12 KB
Binary file not shown.

bin/com/paulsen/ui/PUISlider$2.class

994 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUISlider$3.class

997 Bytes
Binary file not shown.

bin/com/paulsen/ui/PUISlider.class

5.15 KB
Binary file not shown.

bin/com/paulsen/ui/PUIText$1.class

1.8 KB
Binary file not shown.

bin/com/paulsen/ui/PUIText$2.class

1.2 KB
Binary file not shown.

bin/com/paulsen/ui/PUIText.class

7.38 KB
Binary file not shown.

bin/com/paulsen/ui/PUIUpdatable.class

145 Bytes
Binary file not shown.

src/com/paulsen/demo/Main.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.paulsen.demo;
2+
3+
import java.awt.Component;
4+
import java.awt.Graphics;
5+
6+
import com.paulsen.ui.*;
7+
import com.paulsen.ui.PUIElement.ElementAlignment;
8+
9+
public class Main {
10+
11+
public static void main(String[] args) {
12+
new Main();
13+
}
14+
15+
PUIFrame f;
16+
17+
PUIText darkmodeButton;
18+
PUICheckBox cb;
19+
PUIRotaryControl rc;
20+
PUISlider slider;
21+
PUIScrollPanel sp;
22+
23+
public Main() {
24+
// initialize variables before using them in update/paint
25+
f = new PUIFrame("Project-Library Demo", 600, 600, new PUIInitializable() {
26+
@Override
27+
public void initUI(Component c) {
28+
29+
darkmodeButton = new PUIText(c, "LIGHT");
30+
darkmodeButton.addActionListener(new PUIAction() {
31+
@Override
32+
public void run(PUIElement that) {
33+
PUIElement.darkUIMode = !PUIElement.darkUIMode;
34+
if (PUIElement.darkUIMode) {
35+
darkmodeButton.setText("DARK");
36+
} else {
37+
darkmodeButton.setText("LIGHT");
38+
}
39+
f.updateElements();
40+
}
41+
});
42+
43+
Runnable update = new Runnable() {
44+
@Override
45+
public void run() {
46+
f.updateElements();
47+
}
48+
};
49+
50+
cb = new PUICheckBox(c);
51+
cb.addActionListener(new PUIAction() {
52+
@Override
53+
public void run(PUIElement that) {
54+
f.updateElements();
55+
}
56+
});
57+
58+
rc = new PUIRotaryControl(c);
59+
rc.addValueUpdateAction(update);
60+
61+
slider = new PUISlider(c);
62+
slider.addValueUpdateAction(update);
63+
slider.setAlignment(ElementAlignment.HORIZONTAL);
64+
65+
sp = new PUIScrollPanel(c);
66+
sp.addValueUpdateAction(update);
67+
68+
// add test-Buttons for scrollpanel
69+
for (int i = 1; i <= 10; i++)
70+
sp.addElement(new PUIText(c, "" + i));
71+
72+
// prevent different colors when hovering/pressing
73+
for (PUIElement e : PUIElement.registeredElements) {
74+
e.doPaintOverOnHover(false);
75+
e.doPaintOverOnPress(false);
76+
}
77+
}
78+
});
79+
f.setDraw(new PUIPaintable() { // graphics display on Frame
80+
@Override
81+
public void paint(Graphics g, int x, int y, int w, int h) {
82+
darkmodeButton.draw(g);
83+
cb.draw(g);
84+
rc.draw(g);
85+
slider.draw(g);
86+
sp.draw(g);
87+
}
88+
});
89+
f.setUpdateElements(new PUIUpdatable() { // initialize updateMethod
90+
@Override
91+
public void update(int w, int h) {
92+
93+
/*
94+
* Element-Positions can also be defined relative by using width & height
95+
* variables
96+
*/
97+
98+
darkmodeButton.setBounds(50, 50, 300, 100);
99+
cb.setBounds(w - 150, 50, 100, 100);// relative
100+
rc.setBounds(w - 150, 200, 100, 100);// relative
101+
slider.setBounds(50, 200, 300, 100);
102+
sp.setBounds(50, h - 200, 300, 150); // relative
103+
}
104+
});
105+
f.updateElements();
106+
}
107+
108+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.paulsen.io;
2+
3+
public class CustomProtocol {
4+
5+
private String IDENTIFIER = "CP";
6+
7+
private char BLOCK_START = '[', BLOCK_END = ']';
8+
/**
9+
* Replacement if start- or end-character is included in data (1)=> store data
10+
* with replaced characters (2)=> read data with replacements back replaced to
11+
* start or end
12+
*/
13+
private String START_REPLACEMENT = "^<<^", END_REPLACEMENT = "^>>^";
14+
15+
public CustomProtocol() {
16+
}
17+
18+
public CustomProtocol(String identifier, char blockStart, char blockEnd, String startReplacement,
19+
String endRemplacement) {
20+
IDENTIFIER = identifier;
21+
BLOCK_START = blockStart;
22+
BLOCK_END = blockEnd;
23+
START_REPLACEMENT = startReplacement;
24+
END_REPLACEMENT = endRemplacement;
25+
}
26+
27+
public boolean isPartOfProtocol(String s) {
28+
s = trimEnd(trimStart(s));
29+
// Message must start immediatley with IDENTIFIER and BLOCK_START
30+
if (s.startsWith(IDENTIFIER + BLOCK_START) && s.endsWith(String.valueOf(BLOCK_END))) {
31+
String message = removeStart(s, IDENTIFIER.length());
32+
// Message can only contain BLOCK_START && BLOCK_END once
33+
if (count(message, BLOCK_START) != 1 || count(message, BLOCK_END) != 1) {
34+
return false;
35+
}
36+
return true;
37+
}
38+
return false;
39+
}
40+
41+
/**
42+
* @param Protocol-Output
43+
* @return Message
44+
*/
45+
public String getMessage(String input) {
46+
if (isPartOfProtocol(input)) {
47+
String message = removeStart(trimEnd(trimStart(input)), IDENTIFIER.length());
48+
49+
// remove block-character and fill replcements
50+
String mN = "";
51+
for (int i = 1; i < message.length() - 1; i++)
52+
mN += message.charAt(i);
53+
message = mN.replace(START_REPLACEMENT, String.valueOf(BLOCK_START)).replace(END_REPLACEMENT,
54+
String.valueOf(BLOCK_END));
55+
56+
return message;
57+
}
58+
return null;
59+
}
60+
61+
/**
62+
* @param Message that gets convertet into the protocol-format
63+
* @return Protocol-Output
64+
*/
65+
public String getProtocolOutput(String message) {
66+
return IDENTIFIER + BLOCK_START + message.replace(String.valueOf(BLOCK_START), START_REPLACEMENT)
67+
.replace(String.valueOf(BLOCK_END), END_REPLACEMENT) + BLOCK_END;
68+
}
69+
70+
private static String trimStart(String sIn) {
71+
String s = "";
72+
boolean hasBeenStart = false;
73+
for (int i = 0; i < sIn.length(); i++) {
74+
if (sIn.charAt(i) != ' ')
75+
hasBeenStart = true;
76+
if (hasBeenStart)
77+
s += sIn.charAt(i);
78+
}
79+
return s;
80+
}
81+
82+
private static String removeStart(String in, int length) {
83+
String s = "";
84+
for (int i = length; i < in.length(); i++)
85+
s += in.charAt(i);
86+
return s;
87+
}
88+
89+
private static String trimEnd(String sIn) {
90+
String s = "";
91+
boolean hasBeenEnd = false;
92+
for (int i = sIn.length() - 1; i >= 0; i--) {
93+
if (sIn.charAt(i) != ' ')
94+
hasBeenEnd = true;
95+
if (hasBeenEnd)
96+
s = sIn.charAt(i) + s;
97+
}
98+
return s;
99+
}
100+
101+
private static int count(String s, char c) {
102+
int count = 0;
103+
for (int i = 0; i < s.length(); i++) {
104+
if (s.charAt(i) == c)
105+
count++;
106+
}
107+
return count;
108+
}
109+
}

0 commit comments

Comments
 (0)