mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 23:36:27 -04:00
Refactoring of "restart required" detection if settings are modified.
This commit is contained in:
parent
b7a1dccc3d
commit
2227a609e7
@ -27,6 +27,7 @@ public class Key<VALUE> {
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isSecondary;
|
||||
private boolean requiresRestart = false;
|
||||
|
||||
/**
|
||||
* Creates a new Key
|
||||
@ -202,6 +203,23 @@ public class Key<VALUE> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called if this setting needs a restart.
|
||||
*
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public Key<VALUE> setRequiresRestart() {
|
||||
requiresRestart = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if changing this value needs a restart
|
||||
*/
|
||||
public boolean getRequiresRestart() {
|
||||
return requiresRestart;
|
||||
}
|
||||
|
||||
/**
|
||||
* A integer attribute.
|
||||
* Stores additional combo box values
|
||||
|
@ -402,13 +402,13 @@ public final class Keys {
|
||||
* shape setting
|
||||
*/
|
||||
public static final Key<Boolean> SETTINGS_IEEE_SHAPES
|
||||
= new Key<>("IEEEShapes", Locale.getDefault().getLanguage().equals(Locale.US.getLanguage()));
|
||||
= new Key<>("IEEEShapes", Locale.getDefault().getLanguage().equals(Locale.US.getLanguage())).setRequiresRestart();
|
||||
|
||||
/**
|
||||
* The GUI Language
|
||||
*/
|
||||
public static final Key<Language> SETTINGS_LANGUAGE
|
||||
= new Key<>("Language", new Language());
|
||||
= new Key<>("Language", new Language()).setRequiresRestart();
|
||||
|
||||
|
||||
/**
|
||||
@ -439,7 +439,7 @@ public final class Keys {
|
||||
* enables the MAC mouse mode
|
||||
*/
|
||||
public static final Key<Boolean> SETTINGS_MAC_MOUSE
|
||||
= new Key<>("macMouse", Screen.isMac());
|
||||
= new Key<>("macMouse", Screen.isMac()).setRequiresRestart();
|
||||
|
||||
/**
|
||||
* output format for numbers
|
||||
@ -572,7 +572,8 @@ public final class Keys {
|
||||
new Key.KeyInteger("fontSize", Screen.getDefaultFontScaling())
|
||||
.setComboBoxValues(new Integer[]{100, 120, 150, 180, 200, 250, 300})
|
||||
.setMin(50)
|
||||
.setMax(400);
|
||||
.setMax(400)
|
||||
.setRequiresRestart();
|
||||
|
||||
/**
|
||||
* true if a enable input is needed
|
||||
@ -608,7 +609,7 @@ public final class Keys {
|
||||
* A jar containing custom java components
|
||||
*/
|
||||
public static final Key<File> SETTINGS_JAR_PATH
|
||||
= new Key.KeyFile("jarPath", new File("")).setSecondary();
|
||||
= new Key.KeyFile("jarPath", new File("")).setSecondary().setRequiresRestart();
|
||||
|
||||
/**
|
||||
* The manager which contains all the roms data
|
||||
@ -686,7 +687,7 @@ public final class Keys {
|
||||
* Selects the wide shapes as the default
|
||||
*/
|
||||
public static final Key<Boolean> SETTINGS_USE_WIDE_SHAPES
|
||||
= new Key<>("wideShapeAsDefault", false).setSecondary();
|
||||
= new Key<>("wideShapeAsDefault", false).setSecondary().setRequiresRestart();
|
||||
|
||||
|
||||
}
|
||||
|
@ -680,16 +680,14 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
ElementAttributes modified = new AttributeDialog(Main.this, Settings.getInstance().getKeys(), Settings.getInstance().getAttributes()).showDialog();
|
||||
if (modified != null) {
|
||||
FormatToExpression.setDefaultFormat(modified.get(Keys.SETTINGS_EXPRESSION_FORMAT));
|
||||
if (!Settings.getInstance().getAttributes().equalsKey(Keys.SETTINGS_LANGUAGE, modified)
|
||||
|| !Settings.getInstance().getAttributes().equalsKey(Keys.SETTINGS_IEEE_SHAPES, modified)
|
||||
|| !Settings.getInstance().getAttributes().equalsKey(Keys.SETTINGS_FONT_SCALING, modified)
|
||||
|| !Settings.getInstance().getAttributes().equalsKey(Keys.SETTINGS_MAC_MOUSE, modified)
|
||||
|| !Settings.getInstance().getAttributes().equalsKey(Keys.SETTINGS_JAR_PATH, modified)) {
|
||||
|
||||
if (Settings.getInstance().requiresRestart(modified)) {
|
||||
Lang.setLanguage(modified.get(Keys.SETTINGS_LANGUAGE));
|
||||
JOptionPane.showMessageDialog(Main.this, Lang.get("msg_restartNeeded"));
|
||||
}
|
||||
if (!Settings.getInstance().getAttributes().equalsKey(Keys.SETTINGS_GRID, modified))
|
||||
circuitComponent.repaintNeeded();
|
||||
|
||||
Settings.getInstance().getAttributes().getValuesFrom(modified);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -106,7 +107,7 @@ public final class Settings implements AttributeListener {
|
||||
@Override
|
||||
public void attributeChanged() {
|
||||
XStream xStream = Circuit.getxStream();
|
||||
try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), "utf-8")) {
|
||||
try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8)) {
|
||||
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
xStream.marshal(attributes, new PrettyPrintWriter(out));
|
||||
} catch (Exception e) {
|
||||
@ -121,5 +122,19 @@ public final class Settings implements AttributeListener {
|
||||
return settingsKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given modification requires a restart.
|
||||
*
|
||||
* @param modified the modified settings
|
||||
* @return true if the modification requires a restart
|
||||
*/
|
||||
public boolean requiresRestart(ElementAttributes modified) {
|
||||
for (Key<?> key : settingsKeys)
|
||||
if (key.getRequiresRestart() && !attributes.equalsKey(key, modified))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user