Skip to content

Commit 11cf4a9

Browse files
author
Vadim Kimlaychuk
committed
prepare runtime
1 parent 174284b commit 11cf4a9

File tree

6 files changed

+45
-28
lines changed

6 files changed

+45
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
out/
33
target/
4+
*.iml

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ Main features:
55
- generates empty matrix for creating fonts from 5x8 to 16x16 pixel size
66
- can draw font, provided as hex string from 5x8 to 16x16 pixel size by using "Draw" button
77

8+
# Dependencies
9+
- Java 13
10+
- OpenJFX
11+
12+
# Running
13+
```shell script
14+
./mvnw javafx:run
15+
```
816
# Example sreenshots
917
![](https://github.com/vadimkim/dotmatrix/raw/master/images/single_segment.png "single segment")
1018
![](https://github.com/vadimkim/dotmatrix/raw/master/images/multi_segment.png "multi segment")

pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>ant.ee</groupId>
55
<artifactId>dot-matrix</artifactId>
6-
<version>1.0-SNAPSHOT</version>
6+
<version>1.1.0</version>
77
<properties>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
99
<maven.compiler.source>13</maven.compiler.source>
@@ -35,10 +35,17 @@
3535
<groupId>org.openjfx</groupId>
3636
<artifactId>javafx-maven-plugin</artifactId>
3737
<version>0.0.3</version>
38-
<configuration>
38+
<configuration>
39+
<stripDebug>true</stripDebug>
40+
<compress>2</compress>
41+
<noHeaderFiles>true</noHeaderFiles>
42+
<noManPages>true</noManPages>
43+
<launcher>dotmatrix</launcher>
44+
<jlinkImageName>dotmatrix</jlinkImageName>
45+
<jlinkZipName>dotmatrix.zip</jlinkZipName>
3946
<mainClass>ee.ant.dotmatrix.App</mainClass>
4047
</configuration>
4148
</plugin>
4249
</plugins>
4350
</build>
44-
</project>
51+
</project>

run.sh

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/sh
2-
java -jar target/dotmatrix-1.0.0-RELEASE.jar
2+
./mvnw clean package
3+
java -jar target/dot-matrix-1.1.0.jar

src/main/java/ee/ant/dotmatrix/App.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class App extends Application {
2020
@Override
2121
public void start(Stage primaryStage) throws Exception{
2222
services = getHostServices();
23-
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("primary.fxml")));
23+
Parent root = FXMLLoader.load(getClass().getResource("primary.fxml"));
2424
primaryStage.setTitle("Dot matrix font generator");
25-
primaryStage.getIcons().add(new Image("ant.png"));
26-
Scene main = new Scene(root, 800, 500);
27-
main.getStylesheets().add("styles.css");
25+
primaryStage.getIcons().add(new Image("ee/ant/dotmatrix/ant.png"));
26+
var main = new Scene(root, 800, 500);
27+
main.getStylesheets().add("ee/ant/dotmatrix/styles.css");
2828
primaryStage.setScene(main);
2929
primaryStage.show();
3030
}

src/main/java/ee/ant/dotmatrix/PrimaryController.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ee.ant.dotmatrix;
22

3-
import javafx.collections.ObservableList;
43
import javafx.event.ActionEvent;
54
import javafx.fxml.FXML;
65
import javafx.scene.Node;
@@ -12,6 +11,7 @@
1211

1312
import java.util.ArrayList;
1413
import java.util.Arrays;
14+
import java.util.Base64;
1515
import java.util.List;
1616

1717
public class PrimaryController {
@@ -81,12 +81,12 @@ private void initialize() {
8181
* Show promotion
8282
*/
8383
private void showAbout() {
84-
String uri = "www.ant.ee";
85-
Alert alert = new Alert(Alert.AlertType.INFORMATION);
84+
var uri = "www.ant.ee";
85+
var alert = new Alert(Alert.AlertType.INFORMATION);
8686
alert.setTitle("About author");
8787
alert.setHeaderText("");
88-
alert.setGraphic(new ImageView(new Image("ant.png")));
89-
Hyperlink link = new Hyperlink(uri);
88+
alert.setGraphic(new ImageView(new Image("ee/ant/dotmatrix/ant.png")));
89+
var link = new Hyperlink(uri);
9090
link.setOnAction(event -> App.openURL(uri + "/?dotmatrix"));
9191
alert.getDialogPane().contentProperty().set(link);
9292
alert.showAndWait();
@@ -103,11 +103,11 @@ private void createEmptyMatrix(int rows, int columns) {
103103
hexString.clear();
104104
for (int i = 0; i < columns; i++) {
105105
for (int j = 0; j < rows; j++) {
106-
Button btn = new Button();
106+
var btn = new Button();
107107
btn.setMinSize(16.0, 16.0);
108108
btn.setMaxSize(16.0, 16.0);
109109
btn.setOnAction(((ActionEvent click) -> {
110-
ObservableList classes = btn.getStyleClass();
110+
var classes = btn.getStyleClass();
111111
if (classes.size() == 1) {
112112
btn.getStyleClass().add("buttonOn");
113113
} else {
@@ -131,13 +131,13 @@ private void createEmptyMatrix(int rows, int columns) {
131131
private void drawLines(int columns) {
132132
// Draw horizontal line
133133
for (int i = 0; i < columns; i++) {
134-
Button btn = (Button) dotMatrix.getChildren().get(2 * i * 8 + 7);
134+
var btn = (Button) dotMatrix.getChildren().get(2 * i * 8 + 7);
135135
btn.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(0, 0, 1, 0))));
136136
}
137137

138138
// Draw vertical line
139139
for (int i = 0; i < 16; i++) {
140-
Button btn = (Button) dotMatrix.getChildren().get(i + 8 * columns);
140+
var btn = (Button) dotMatrix.getChildren().get(i + 8 * columns);
141141
if (i == 7) { // One button has both bottom and left lines
142142
btn.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(0, 0, 1, 1))));
143143
} else {
@@ -155,13 +155,13 @@ private void parseHexString(String text) {
155155
// Assume that hex string contains words separated by comas like
156156
// 0x00, 0x07, 0x05, 0x07, 0x00
157157
// create corresponding byte[] array
158-
String binaryString = text.replace("{", "")
158+
var binaryString = text.replace("{", "")
159159
.replace("}", "")
160160
.replace("0x", "")
161161
.replace(",", "")
162162
.replace(" ", "");
163-
// byte[] bytes = DatatypeConverter.parseHexBinary(binaryString); TODO refactor
164-
// fillMatrixWithDots(bytes);
163+
var bytes = Base64.getMimeDecoder().decode(binaryString.getBytes());
164+
fillMatrixWithDots(bytes);
165165
}
166166

167167
/**
@@ -171,7 +171,7 @@ private void parseHexString(String text) {
171171
* @param bytes byte array that encodes symbol
172172
*/
173173
private void fillMatrixWithDots(byte[] bytes) {
174-
int colums = bytes.length;
174+
var colums = bytes.length;
175175
if (bytes.length > 8) {
176176
// there are 4 segments
177177
colums = bytes.length / 2;
@@ -213,7 +213,7 @@ private void fillMatrixWithDots(byte[] bytes) {
213213
*/
214214
private void drawSegment(byte[] bytes) {
215215
for (int i = 0; i < bytes.length; i++) {
216-
byte column = bytes[i];
216+
var column = bytes[i];
217217
for (int j = 0; j < 8; j++) {
218218
if ((column & 1) == 1) {
219219
dotMatrix.getChildren().get(i * 8 + j).getStyleClass().add("buttonOn");
@@ -233,7 +233,7 @@ private void drawSegment(byte[] bytes) {
233233
*/
234234
private void drawSegment(int offsetCol, int offsetRaw, byte[] bytes) {
235235
for (int i = 0; i < bytes.length; i++) {
236-
byte column = bytes[i];
236+
var column = bytes[i];
237237
for (int j = offsetCol; j < offsetCol + 8; j++) {
238238
if ((column & 1) == 1) {
239239
dotMatrix.getChildren().get(i * 16 + j + offsetRaw * 16).getStyleClass().add("buttonOn");
@@ -247,7 +247,7 @@ private void drawSegment(int offsetCol, int offsetRaw, byte[] bytes) {
247247
* Create font hex string and display it
248248
*/
249249
private void generateHexString() {
250-
StringBuilder hexOut = new StringBuilder();
250+
var hexOut = new StringBuilder();
251251

252252
if (dotMatrix.getChildren().size() > 64) {
253253
// Multi- segment
@@ -260,7 +260,7 @@ private void generateHexString() {
260260
hexOut.append(getSegmentHex(dotMatrix.getChildren()));
261261
}
262262

263-
String out = hexOut.toString();
263+
var out = hexOut.toString();
264264
hexString.setText("{ " + out.substring(0, out.length() - 1) + " }");
265265
}
266266

@@ -274,7 +274,7 @@ private void generateHexString() {
274274
*/
275275
private char[] readSegment(int offsetCol, int offsetRaw) {
276276

277-
List<Node> segment = new ArrayList<>();
277+
var segment = new ArrayList<Node>();
278278
for (int i=offsetCol; i < offsetCol + dotMatrix.getChildren().size()/32; i++) {
279279
for (int j=offsetRaw; j < offsetRaw + 8; j++) {
280280
segment.add(dotMatrix.getChildren().get(i*16 + j));
@@ -290,11 +290,11 @@ private char[] readSegment(int offsetCol, int offsetRaw) {
290290
* @return hex string
291291
*/
292292
private String getSegmentHex(List<Node> segment) {
293-
StringBuilder hexOut = new StringBuilder();
293+
var hexOut = new StringBuilder();
294294
// Single segment code
295295
byte element = 0; // initial byte
296296
for (int i = 0; i < segment.size(); i++) {
297-
Node button = segment.get(i);
297+
var button = segment.get(i);
298298
// reset element each 8 bits
299299
if (i % 8 == 0) {
300300
element = 0;

0 commit comments

Comments
 (0)