mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 16:34:47 -04:00
added settings
This commit is contained in:
parent
cc6d4830b1
commit
9c0a2923a1
@ -2,6 +2,8 @@ package de.neemann.digital.core.element;
|
||||
|
||||
import de.neemann.digital.core.memory.DataField;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Collection of key constants
|
||||
*
|
||||
@ -191,4 +193,10 @@ public final class Keys {
|
||||
*/
|
||||
public static final Key<String> NETNAME
|
||||
= new Key<>("NetName", "");
|
||||
|
||||
/**
|
||||
* shape setting
|
||||
*/
|
||||
public static final Key<Boolean> SETTINGS_IEEE_SHAPES
|
||||
= new Key<>("IEEEShapes", !Locale.getDefault().getCountry().equals("DE"));
|
||||
}
|
||||
|
@ -43,8 +43,14 @@ public class Circuit {
|
||||
private transient boolean dotsPresent = false;
|
||||
private transient boolean modified = false;
|
||||
|
||||
private static XStream getxStream() {
|
||||
/**
|
||||
* Creates a proper configurated XStream instance
|
||||
*
|
||||
* @return the XStream instance
|
||||
*/
|
||||
public static XStream getxStream() {
|
||||
XStream xStream = new XStream(new StaxDriver());
|
||||
xStream.alias("attributes", ElementAttributes.class);
|
||||
xStream.alias("visualElement", VisualElement.class);
|
||||
xStream.alias("wire", Wire.class);
|
||||
xStream.alias("circuit", Circuit.class);
|
||||
|
@ -131,7 +131,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
||||
this.savedListener = savedListener;
|
||||
|
||||
library = new ElementLibrary();
|
||||
shapeFactory = new ShapeFactory(library);
|
||||
shapeFactory = new ShapeFactory(library, Settings.getInstance().getAttributes().get(Keys.SETTINGS_IEEE_SHAPES));
|
||||
|
||||
final boolean normalMode = savedListener == null;
|
||||
|
||||
@ -326,11 +326,20 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_editAttributes_tt"));
|
||||
|
||||
ToolTipAction editSettings = new ToolTipAction(Lang.get("menu_editSettings")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (new AttributeDialog(Main.this, Settings.SETTINGS_KEYS, Settings.getInstance().getAttributes()).showDialog())
|
||||
JOptionPane.showMessageDialog(Main.this,Lang.get("msg_restartNeeded"));;
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_editSettings_tt"));
|
||||
|
||||
edit.add(elementStateAction.createJMenuItem());
|
||||
edit.add(orderInputs.createJMenuItem());
|
||||
edit.add(orderOutputs.createJMenuItem());
|
||||
edit.add(orderMeasurements.createJMenuItem());
|
||||
edit.add(editAttributes.createJMenuItem());
|
||||
edit.add(editSettings.createJMenuItem());
|
||||
}
|
||||
|
||||
/**
|
||||
|
84
src/main/java/de/neemann/digital/gui/Settings.java
Normal file
84
src/main/java/de/neemann/digital/gui/Settings.java
Normal file
@ -0,0 +1,84 @@
|
||||
package de.neemann.digital.gui;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
||||
import de.neemann.digital.core.element.AttributeListener;
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The Settings of Digital
|
||||
* <p/>
|
||||
* Created by Helmut.Neemann on 11.05.2016.
|
||||
*/
|
||||
public class Settings implements AttributeListener {
|
||||
|
||||
/**
|
||||
* The list of supported attributes.
|
||||
*/
|
||||
public static final ArrayList<Key> SETTINGS_KEYS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SETTINGS_KEYS.add(Keys.SETTINGS_IEEE_SHAPES);
|
||||
}
|
||||
|
||||
private static SettingsHolder settingsHolder = new SettingsHolder();
|
||||
|
||||
private static class SettingsHolder {
|
||||
Settings INSTANCE = new Settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the settings instance
|
||||
*
|
||||
* @return the Settings
|
||||
*/
|
||||
public static Settings getInstance() {
|
||||
return settingsHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private ElementAttributes attributes;
|
||||
private final File filename;
|
||||
|
||||
private Settings() {
|
||||
filename = new File(new File(System.getProperty("user.home")), ".digital.cfg");
|
||||
|
||||
XStream xStream = Circuit.getxStream();
|
||||
try (InputStream in = new FileInputStream(filename)) {
|
||||
attributes = (ElementAttributes) xStream.fromXML(in);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (attributes == null) {
|
||||
System.out.println("Use default settings!");
|
||||
attributes = new ElementAttributes();
|
||||
}
|
||||
|
||||
attributes.addListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the settings
|
||||
*/
|
||||
public ElementAttributes getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeChanged(Key key) {
|
||||
XStream xStream = Circuit.getxStream();
|
||||
try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), "utf-8")) {
|
||||
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
xStream.marshal(attributes, new PrettyPrintWriter(out));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ key_isHighZ=Eingang kann hochohmig sein
|
||||
key_Description=Beschreibung
|
||||
key_NetName=Netzname
|
||||
key_NetName_tt=Alle Netze mit identischem Namen werden verbunden.
|
||||
key_IEEEShapes=Verwende IEEE 91-1984 Symbole
|
||||
key_IEEEShapes_tt=Verwende IEEE 91-1984 Symbole anstelle der rechteckige Symbole
|
||||
|
||||
elem_And=Und
|
||||
elem_NAnd=Nicht Und
|
||||
@ -193,6 +195,7 @@ msg_frequency_N=Die maximale Frequenz ber\u00E4gt {0}Hz.
|
||||
msg_annalyseErr=Fehler bei der Analyse der Schaltung
|
||||
msg_errorDuringCalculation=Fehler w\u00E4hrend der Vereinfachung.
|
||||
msg_N_nodes={0} aktive Elemente
|
||||
msg_restartNeeded=Die \u00C4nderung erfordert einen Neustart!
|
||||
|
||||
|
||||
stat_clocks={0} Halbzyklen
|
||||
@ -273,6 +276,8 @@ menu_table_createNAnd=Model erzeugen mit NAnd
|
||||
menu_table_createNAnd_tt=Erzeugt ein Model, welches der Wahrheitstabelle entspricht nur mit NAnd-Gattern.
|
||||
menu_table_createNOr=Model erzeugen mit NOr
|
||||
menu_table_createNOr_tt=Erzeugt ein Model, welches der Wahrheitstabelle entspricht nur mit NOr-Gattern.
|
||||
menu_editSettings=Einstellungen
|
||||
menu_editSettings_tt=Bearbeitet die globalen Einstellungen
|
||||
|
||||
menu_about=\u00DCber Digital
|
||||
|
||||
|
@ -43,6 +43,8 @@ key_runRealTime=Start real time clock
|
||||
key_Description=Description
|
||||
key_NetName=Netname
|
||||
key_NetName_tt=All nets with identical name are connected together.
|
||||
key_IEEEShapes=Use IEEE 91-1984 shapes
|
||||
key_IEEEShapes_tt=Use IEEE 91-1984 shapes instead of rectangular shapes
|
||||
|
||||
elem_And=And
|
||||
elem_NAnd=NAnd
|
||||
@ -174,6 +176,7 @@ msg_clockError=Error during a clock state change
|
||||
msg_frequency_N=The maximum frequency is {0}Hz
|
||||
msg_errorDuringCalculation=Error during simplification
|
||||
msg_N_nodes={0} nodes
|
||||
msg_restartNeeded=Change needs a restart to take effect!
|
||||
|
||||
stat_clocks={0} half cycles
|
||||
|
||||
@ -253,6 +256,8 @@ menu_table_createNAnd=create with NAnd
|
||||
menu_table_createNAnd_tt=Creates a circuit which reproduces the truth table only with NAnd gates.
|
||||
menu_table_createNOr=create with NOr
|
||||
menu_table_createNOr_tt=Creates a circuit which reproduces the truth table only with NOr gates.
|
||||
menu_editSettings=Settings
|
||||
menu_editSettings_tt=Edits Digitals Preferences
|
||||
|
||||
win_saveChanges=Save Changes?
|
||||
win_confirmExit=Confirm Exit!
|
||||
|
Loading…
x
Reference in New Issue
Block a user