-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
164 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.settings/ | ||
target/ | ||
*.class | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>nz.ac.massey.cs</groupId> | ||
<artifactId>nz.ac.massey.cs.flackpad</artifactId> | ||
<version>0.3.4-SNAPSHOT</version> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>16</source> | ||
<target>16</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer> | ||
<mainClass>nz.ac.massey.cs.flackpad.RunApp</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<maven.compiler.target>16</maven.compiler.target> | ||
<javaVersion>16</javaVersion> | ||
<maven.compiler.source>16</maven.compiler.source> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package nz.ac.massey.cs.flackpad; | ||
|
||
import java.awt.Font; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.PrintWriter; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.yaml.snakeyaml.DumperOptions; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
class Config { | ||
|
||
private Window window; | ||
private Map<String, Object> defaults = new LinkedHashMap<String, Object>(); | ||
private Map<String, Object> config = new LinkedHashMap<String, Object>(); | ||
|
||
Config(Window window) { | ||
this.window = window; | ||
|
||
loadDefaults(); | ||
loadConfigFile(); | ||
} | ||
|
||
private void loadDefaults() { | ||
defaults.put("fontFamily", "Consolas"); | ||
defaults.put("fontStyle", Font.PLAIN); | ||
defaults.put("fontSize", 12); | ||
} | ||
|
||
void loadConfigFile() { | ||
// Read config file | ||
Yaml yaml = new Yaml(); | ||
|
||
try { | ||
InputStream inputStream = new FileInputStream("config.yaml"); | ||
config = yaml.load(inputStream); | ||
inputStream.close(); | ||
} catch (FileNotFoundException e) { | ||
Dialogs.error("Configuration file does not exist, using defaults", window); | ||
} catch (IOException e) { | ||
Dialogs.error("Something wen't wrong when loading configuration file", window); | ||
} | ||
|
||
// Set missing values with defaults | ||
for (String key:defaults.keySet()) { | ||
if (!config.containsKey(key)) config.put(key, defaults.get(key)); | ||
} | ||
|
||
// Save config | ||
saveConfigFile(); | ||
} | ||
|
||
void saveConfigFile() { | ||
DumperOptions options = new DumperOptions(); | ||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); | ||
options.setPrettyFlow(true); | ||
Yaml yaml = new Yaml(options); | ||
|
||
try { | ||
PrintWriter writer = new PrintWriter("config.yaml"); | ||
yaml.dump(config, writer); | ||
writer.flush(); | ||
writer.close(); | ||
} catch (IOException e) { | ||
Dialogs.error("Something wen't wrong when saving configuration", window); | ||
} | ||
} | ||
|
||
Font getFont() { | ||
try { | ||
return new Font((String) config.get("fontFamily"), (int) config.get("fontStyle"), (int) config.get("fontSize")); | ||
} catch (Exception e) { | ||
Dialogs.error("Something wen't wrong when loading the configured font, using defaults", window); | ||
} | ||
setFont(new Font((String) defaults.get("fontFamily"), (int) defaults.get("fontStyle"), (int) defaults.get("fontSize"))); | ||
return getFont(); | ||
} | ||
|
||
void setFont(Font font) { | ||
config.put("fontFamily", font.getFamily()); | ||
config.put("fontStyle", font.getStyle()); | ||
config.put("fontSize", font.getSize()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fontFamily: Consolas | ||
fontStyle: 0 | ||
fontSize: 12 |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes