implement json configuration
This commit is contained in:
parent
41ebc47800
commit
184a75752f
5 changed files with 77 additions and 6 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -37,4 +37,7 @@ build/
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
# mptv
|
||||||
|
config.json
|
||||||
10
pom.xml
10
pom.xml
|
|
@ -20,6 +20,16 @@
|
||||||
<version>5.10.2</version>
|
<version>5.10.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.17.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-cli</groupId>
|
||||||
|
<artifactId>commons-cli</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
22
src/main/java/com/mykola2312/mptv/Config.java
Normal file
22
src/main/java/com/mykola2312/mptv/Config.java
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.mykola2312.mptv;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
public class Frame {
|
||||||
|
public short width;
|
||||||
|
public short height;
|
||||||
|
public boolean fullscreen;
|
||||||
|
|
||||||
|
}
|
||||||
|
public Frame frame;
|
||||||
|
|
||||||
|
public static Config loadConfig(String path) throws IOException {
|
||||||
|
return new ObjectMapper().readerFor(Config.class).readValue(new File(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,39 @@
|
||||||
package com.mykola2312.mptv;
|
package com.mykola2312.mptv;
|
||||||
|
|
||||||
import com.mykola2312.mptv.ui.MainFrame;
|
import com.mykola2312.mptv.ui.MainFrame;
|
||||||
|
import org.apache.commons.cli.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
final Options options = new Options();
|
||||||
|
options.addOption(Option
|
||||||
|
.builder("c")
|
||||||
|
.longOpt("config")
|
||||||
|
.required(false)
|
||||||
|
.hasArg()
|
||||||
|
.build());
|
||||||
|
CommandLine cmd;
|
||||||
|
try {
|
||||||
|
cmd = new DefaultParser().parse(options, args);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
System.err.println(e.toString());
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String configPath = cmd.hasOption('c') ? cmd.getOptionValue('c') : "config.json";
|
||||||
|
Config config;
|
||||||
|
try {
|
||||||
|
config = Config.loadConfig(configPath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.printf("failed to read config: %s\n", e.toString());
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MainFrame frame = new MainFrame();
|
MainFrame frame = new MainFrame();
|
||||||
frame.create();
|
frame.create(config.frame.width, config.frame.height, config.frame.fullscreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,23 @@ package com.mykola2312.mptv.ui;
|
||||||
import com.mykola2312.mptv.I18n;
|
import com.mykola2312.mptv.I18n;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class MainFrame {
|
public class MainFrame {
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
|
|
||||||
public void create() {
|
public void create(short width, short height, boolean fullscreen) {
|
||||||
this.frame = new JFrame(I18n.get("MainFrame_Title"));
|
this.frame = new JFrame(I18n.get("MainFrame_Title"));
|
||||||
|
|
||||||
frame.setUndecorated(true);
|
if (fullscreen) {
|
||||||
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
|
frame.setUndecorated(true);
|
||||||
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
|
||||||
|
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||||
|
} else {
|
||||||
|
Dimension size = new Dimension(width, height);
|
||||||
|
frame.setPreferredSize(size);
|
||||||
|
frame.setSize(size);
|
||||||
|
}
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue