added ram alloc error jframe back
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
package com.vaporvee.loadsupport;
|
package com.vaporvee.loadsupport;
|
||||||
|
|
||||||
|
import com.vaporvee.loadsupport.platform.Services;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class Allocated {
|
public class Allocated {
|
||||||
public static float memoryInGB;
|
public static float memoryInGB;
|
||||||
public static void init(){
|
public static void init(){
|
||||||
@@ -9,4 +14,43 @@ public class Allocated {
|
|||||||
public static void printAllocated() {
|
public static void printAllocated() {
|
||||||
Constants.LOG.info(String.format("Allocated Memory: %.1f GB", memoryInGB));
|
Constants.LOG.info(String.format("Allocated Memory: %.1f GB", memoryInGB));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] getWarningMessage(){
|
||||||
|
Config config = Services.CONFIG.getConfig();
|
||||||
|
return new String[]{config.errorTitle, config.errorDescription
|
||||||
|
.replace("{minMemory}", String.valueOf(config.minMemory))
|
||||||
|
.replace("{currentMemory}", String.valueOf(memoryInGB))};
|
||||||
|
};
|
||||||
|
|
||||||
|
static boolean errorWindowOpen = false;
|
||||||
|
private static JFrame errorWindow;
|
||||||
|
|
||||||
|
public static void createErrorWindow() {
|
||||||
|
try {
|
||||||
|
if (!errorWindowOpen) {
|
||||||
|
errorWindowOpen = true;
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
errorWindow = new JFrame(getWarningMessage()[0]);
|
||||||
|
errorWindow.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
errorWindow.setSize(400, 200);
|
||||||
|
errorWindow.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
JLabel message = new JLabel("<html><p style=\"width:200px\">"+ getWarningMessage()[1]+"</p></html>", JLabel.CENTER);
|
||||||
|
JButton exitButton = new JButton("OK");
|
||||||
|
|
||||||
|
exitButton.addActionListener(e -> {
|
||||||
|
errorWindow.dispose();
|
||||||
|
//minecraftClient.stop(); // how to get client crossplatform?
|
||||||
|
});
|
||||||
|
|
||||||
|
errorWindow.setLayout(new BorderLayout());
|
||||||
|
errorWindow.add(message, BorderLayout.CENTER);
|
||||||
|
errorWindow.add(exitButton, BorderLayout.SOUTH);
|
||||||
|
errorWindow.setVisible(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Constants.LOG.error(String.valueOf(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,17 +13,17 @@ public class CommonClass {
|
|||||||
Allocated.printAllocated();
|
Allocated.printAllocated();
|
||||||
Services.CONFIG.InitConfig();
|
Services.CONFIG.InitConfig();
|
||||||
}
|
}
|
||||||
public static void checkConfig(LSConfig config) {
|
public static void checkConfig(Config config) {
|
||||||
Constants.LOG.info("Load config test!");
|
Constants.LOG.info("Config loaded!");
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
if(config.minMemory > Allocated.memoryInGB){
|
if(config.minMemory > Allocated.memoryInGB){
|
||||||
System.setProperty("java.awt.headless", "false");
|
System.setProperty("java.awt.headless", "false");
|
||||||
Constants.LOG.info("Not enough memory! Allocated memory in GB is {} but set in config is {}",
|
Constants.LOG.error("Not enough memory! Allocated memory in GB is {} but set in config is {}",
|
||||||
Allocated.memoryInGB, config.minMemory);
|
Allocated.memoryInGB, config.minMemory);
|
||||||
//create jframe window
|
Allocated.createErrorWindow();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Constants.LOG.info("Load config is null!");
|
Constants.LOG.warn("Load config is null!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,10 +1,9 @@
|
|||||||
package com.vaporvee.loadsupport;
|
package com.vaporvee.loadsupport;
|
||||||
|
|
||||||
import me.shedaniel.autoconfig.ConfigData;
|
import me.shedaniel.autoconfig.ConfigData;
|
||||||
import me.shedaniel.autoconfig.annotation.Config;
|
|
||||||
|
|
||||||
@Config(name = Constants.MOD_ID)
|
@me.shedaniel.autoconfig.annotation.Config(name = Constants.MOD_ID)
|
||||||
public class LSConfig implements ConfigData {
|
public class Config implements ConfigData {
|
||||||
boolean startSound = true;
|
boolean startSound = true;
|
||||||
float minMemory = 4.0f;
|
float minMemory = 4.0f;
|
||||||
String errorTitle = "Error: Not enough Java memory!";
|
String errorTitle = "Error: Not enough Java memory!";
|
@@ -1,10 +1,16 @@
|
|||||||
package com.vaporvee.loadsupport.platform.services;
|
package com.vaporvee.loadsupport.platform.services;
|
||||||
|
|
||||||
import com.vaporvee.loadsupport.LSConfig;
|
import com.vaporvee.loadsupport.Config;
|
||||||
|
|
||||||
public interface IConfig {
|
public interface IConfig {
|
||||||
/**
|
/**
|
||||||
* Initializes config on available platforms
|
* Initializes config on available platforms
|
||||||
*/
|
*/
|
||||||
void InitConfig();
|
void InitConfig();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the populated config class with local config data when loaded correctly
|
||||||
|
* @return pupulated Config object
|
||||||
|
*/
|
||||||
|
Config getConfig();
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,21 @@
|
|||||||
package com.vaporvee.loadsupport.platform;
|
package com.vaporvee.loadsupport.platform;
|
||||||
|
|
||||||
import com.vaporvee.loadsupport.CommonClass;
|
import com.vaporvee.loadsupport.CommonClass;
|
||||||
import com.vaporvee.loadsupport.Constants;
|
import com.vaporvee.loadsupport.Config;
|
||||||
import com.vaporvee.loadsupport.LSConfig;
|
|
||||||
import com.vaporvee.loadsupport.platform.services.IConfig;
|
import com.vaporvee.loadsupport.platform.services.IConfig;
|
||||||
import me.shedaniel.autoconfig.AutoConfig;
|
import me.shedaniel.autoconfig.AutoConfig;
|
||||||
import me.shedaniel.autoconfig.annotation.Config;
|
|
||||||
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
||||||
|
|
||||||
@Config(name = Constants.MOD_ID)
|
|
||||||
public class LSConfigFabric implements IConfig {
|
public class LSConfigFabric implements IConfig {
|
||||||
public static LSConfig config;
|
public static Config config;
|
||||||
@Override
|
@Override
|
||||||
public void InitConfig() {
|
public void InitConfig() {
|
||||||
AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new);
|
AutoConfig.register(Config.class, Toml4jConfigSerializer::new);
|
||||||
config = AutoConfig.getConfigHolder(LSConfig.class).getConfig();
|
config = AutoConfig.getConfigHolder(Config.class).getConfig();
|
||||||
CommonClass.checkConfig(config);
|
CommonClass.checkConfig(config);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Config getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,21 @@
|
|||||||
package com.vaporvee.loadsupport.platform;
|
package com.vaporvee.loadsupport.platform;
|
||||||
|
|
||||||
import com.vaporvee.loadsupport.CommonClass;
|
import com.vaporvee.loadsupport.CommonClass;
|
||||||
import com.vaporvee.loadsupport.Constants;
|
import com.vaporvee.loadsupport.Config;
|
||||||
import com.vaporvee.loadsupport.LSConfig;
|
|
||||||
import com.vaporvee.loadsupport.platform.services.IConfig;
|
import com.vaporvee.loadsupport.platform.services.IConfig;
|
||||||
import me.shedaniel.autoconfig.AutoConfig;
|
import me.shedaniel.autoconfig.AutoConfig;
|
||||||
import me.shedaniel.autoconfig.annotation.Config;
|
|
||||||
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
||||||
|
|
||||||
@Config(name = Constants.MOD_ID)
|
|
||||||
public class LSConfigNeoForge implements IConfig {
|
public class LSConfigNeoForge implements IConfig {
|
||||||
public static LSConfig config;
|
public static Config config;
|
||||||
@Override
|
@Override
|
||||||
public void InitConfig() {
|
public void InitConfig() {
|
||||||
AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new);
|
AutoConfig.register(Config.class, Toml4jConfigSerializer::new);
|
||||||
config = AutoConfig.getConfigHolder(LSConfig.class).getConfig();
|
config = AutoConfig.getConfigHolder(Config.class).getConfig();
|
||||||
CommonClass.checkConfig(config);
|
CommonClass.checkConfig(config);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Config getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user