move config classes to its own module, make font configurable

This commit is contained in:
mykola2312 2024-04-12 19:37:37 +03:00
parent c0369e6015
commit 3747ef33a4
6 changed files with 32 additions and 18 deletions

View file

@ -2,6 +2,8 @@
"frame": {
"width": 1366,
"height": 1024,
"fullscreen": false
"fullscreen": false,
"fontName": "Arial",
"fontSize": 64
}
}

View file

@ -1,5 +1,6 @@
package com.mykola2312.mptv;
import com.mykola2312.mptv.config.Config;
import com.mykola2312.mptv.ui.MainFrame;
import org.apache.commons.cli.*;
@ -34,6 +35,6 @@ public class Main {
}
MainFrame frame = new MainFrame();
frame.create(config.frame.width, config.frame.height, config.frame.fullscreen);
frame.create(config.frame);
}
}

View file

@ -1,20 +1,12 @@
package com.mykola2312.mptv;
package com.mykola2312.mptv.config;
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 FrameConfig frame;
public static Config loadConfig(String path) throws IOException {
return new ObjectMapper().readerFor(Config.class).readValue(new File(path));

View file

@ -0,0 +1,10 @@
package com.mykola2312.mptv.config;
public class FrameConfig {
public short width;
public short height;
public boolean fullscreen;
public String fontName;
public short fontSize;
}

View file

@ -1,6 +1,7 @@
package com.mykola2312.mptv.ui;
import com.mykola2312.mptv.I18n;
import com.mykola2312.mptv.config.FrameConfig;
import javax.swing.*;
import java.awt.*;
@ -9,20 +10,20 @@ public class MainFrame {
private JFrame frame;
private MenuPanel menu;
private void spawn(short width, short height, boolean fullscreen) {
Font font = new Font("Arial", Font.PLAIN, 48);
private void spawn(FrameConfig config) {
Font font = new Font(config.fontName, Font.PLAIN, config.fontSize);
frame = new JFrame(I18n.get("MainFrame_Title"));
menu = new MenuPanel(font);
frame.add(menu, BorderLayout.CENTER);
if (fullscreen) {
if (config.fullscreen) {
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
} else {
Dimension size = new Dimension(width, height);
Dimension size = new Dimension(config.width, config.height);
frame.setPreferredSize(size);
frame.setSize(size);
}
@ -30,9 +31,9 @@ public class MainFrame {
frame.setVisible(true);
}
public void create(short width, short height, boolean fullscreen) {
public void create(FrameConfig config) {
SwingUtilities.invokeLater(() -> {
spawn(width, height, fullscreen);
spawn(config);
});
}
}

View file

@ -84,10 +84,16 @@ public class MenuPanel extends JPanel {
switch (menuPosition) {
case MENU_CATEGORIES -> {
categoryList.setEnabled(true);
channelList.setEnabled(false);
categoryList.setSelectedIndex(categoryIndex);
categoryList.ensureIndexIsVisible(categoryIndex);
}
case MENU_CHANNELS -> {
categoryList.setEnabled(false);
channelList.setEnabled(true);
channelList.setSelectedIndex(channelIndex);
channelList.ensureIndexIsVisible(channelIndex);
}
@ -144,5 +150,7 @@ public class MenuPanel extends JPanel {
getActionMap().put("D", new KeyboardMenuAction(this, MenuAction.ACTION_RIGHT));
menuPosition = MenuPosition.MENU_CATEGORIES;
categoryList.setEnabled(true);
channelList.setEnabled(false);
}
}