Skip to content

Commit 85bac6b

Browse files
author
realPaulsen
committed
README-Update
- Updated a detailed README.md - Renamed CustomProtocol to PCustomProtocol
1 parent 84740af commit 85bac6b

File tree

3 files changed

+185
-113
lines changed

3 files changed

+185
-113
lines changed

README.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,74 @@
1-
# Java-Project-Library
2-
A Library for making small Java-Coding-Projects really fast
31

4-
- Releases and JAR-Downloads: https://github.com/realPaulsen/Java-Project-Library/releases
2+
# Java Project Library
3+
4+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/realPaulsen/Java-Project-Library?label=version)
5+
![GitHub Release Date](https://img.shields.io/github/release-date/realPaulsen/Java-Project-Library?label=last%20RELEASE)
6+
![GitHub last commit](https://img.shields.io/github/last-commit/realPaulsen/Java-Project-Library?label=last%20COMMIT)
7+
8+
![GitHub](https://img.shields.io/github/license/realPaulsen/Java-Project-Library)
9+
![GitHub top language](https://img.shields.io/github/languages/top/realPaulsen/Java-Project-Library)
10+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/realPaulsen/Java-Project-Library)
11+
![Lines of code](https://img.shields.io/tokei/lines/github/realPaulsen/Java-Project-Library)
12+
![GitHub all releases](https://img.shields.io/github/downloads/realPaulsen/Java-Project-Library/total)
13+
14+
`Java-Project-Library` is a library for making small ***Coding-Projects*** of any kind really **fast**.
15+
16+
## Downloads
17+
18+
<!-- TODO: Update D-Link after every new Release -->
19+
- [![GitHub release (latest by date) ](https://img.shields.io/github/v/release/realPaulsen/Java-Project-Library) (latest)](https://github.com/realPaulsen/Java-Project-Library/releases/download/v1.1.0/Java-Project-Library.jar)
20+
- [All](https://github.com/realPaulsen/Java-Project-Library/releases)
21+
22+
## Introduction
23+
24+
Features:
25+
- PUI-Engine
26+
- `PUIFrame`(based on JFrame): simplifies creation of Frames and manages all Elements
27+
- Custom UI-Elements (e.g. `RotaryControl`: Digital Knob the user can rotate)
28+
- Automatic scaling
29+
- Gives pixel-control over Window
30+
- IO
31+
- `PFile` & `PFolder`: Advanced controls over Files & Folders
32+
- `PDataStorage`(similar to json): store/read basic attributes from/to files
33+
- `PCustomProtocol`: Manage serial-communication between different programs/devices
34+
35+
## Why should I use this Library?
36+
37+
- ### Graphics:
38+
39+
This library solves the problem for people, who are ***not experienced enough with Graphics*** in Java
40+
or who don't want to ***invest too much time*** in creating a simple window with buttons, dialogues, user-inputs & graphics.
41+
42+
This Library is ***beginner-friendly*** and allows programmers to create a new ***Window*** and add a ***Button***
43+
to it with ***two lines*** and still have the possibility to draw on the frame on a pixel-level
44+
45+
- ### IO-Functionality:
46+
47+
This library solves the problem of writing a lot of code to ***read*** and ***write*** files. It also provides functions
48+
to get the content in a specific format.
49+
50+
You can get a File as a `One big String`,`Array of Lines` or `Array of Words/Paragraphs`
51+
52+
You can also ***store basic attributes*** to files and later read them (similar to json) by using `PDataStorage`.
53+
54+
## How do I use it?
55+
56+
1. **Download** the [latest `.jar` file](#downloads)
57+
2. **Include** the library into your project
58+
- ***IntelliJ:*** `File > Project Structure > Libraries > +`
59+
- ***Eclipse:*** `Right-Click Project > Properties > Java Build Path > Add External JARs`
60+
3. **Start** with your project
61+
62+
(Detailed Tutorial for using the Library comming soon)
63+
64+
## Project status
65+
66+
The Library is ***fully functional*** and ![Maintenance](https://img.shields.io/maintenance/yes/2021)
67+
by [`Paulsen`](https://github.com/realPaulsen)
68+
69+
### Planned Improvements / In Development
70+
71+
- Mouse-Update-Bug: When not moving Mouse after click-event, Elements can not be clicked until the Mouse moves again
72+
- Graph plotter: Plot multiple graphs and analyze them
73+
- Comments/JavaDoc still missing😬
74+
Lines changed: 109 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +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-
}
1+
package com.paulsen.io;
2+
3+
public class PCustomProtocol {
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 PCustomProtocol() {
16+
}
17+
18+
public PCustomProtocol(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+
}

src/com/paulsen/ui/PUICore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public void mouseWheelMoved(MouseWheelEvent e) {
111111
new Timer().scheduleAtFixedRate(new TimerTask() {
112112
@Override
113113
public void run() {
114-
if (PUIElement.useGBC)
114+
if (PUIElement.useGBC) {
115115
System.gc();
116+
PUIElement.useGBC = false;
117+
}
116118
}
117119
}, 0, 10000);
118120
}

0 commit comments

Comments
 (0)