mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
serialize config using the same XStream as for the project
This commit is contained in:
Binary file not shown.
@@ -110,9 +110,9 @@ public class DrawingManager {
|
|||||||
private long statReportFrequencyMs = 1000 * 60;
|
private long statReportFrequencyMs = 1000 * 60;
|
||||||
private Counter totalStats = new Counter();
|
private Counter totalStats = new Counter();
|
||||||
|
|
||||||
private IConfigurationManager configManager;
|
private IConfigurationManager<?> configManager;
|
||||||
|
|
||||||
public DrawingManager(MessageDispatcher<EventType> messageDispatcher, IConfigurationManager configManager) {
|
public DrawingManager(MessageDispatcher<EventType> messageDispatcher, IConfigurationManager<?> configManager) {
|
||||||
super();
|
super();
|
||||||
this.messageDispatcher = messageDispatcher;
|
this.messageDispatcher = messageDispatcher;
|
||||||
this.configManager = configManager;
|
this.configManager = configManager;
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
private Rectangle selectionRect;
|
private Rectangle selectionRect;
|
||||||
|
|
||||||
private final IView view;
|
private final IView view;
|
||||||
private IConfigurationManager configManager;
|
private IConfigurationManager<?> configManager;
|
||||||
|
|
||||||
private MessageDispatcher<EventType> messageDispatcher;
|
private MessageDispatcher<EventType> messageDispatcher;
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
private DIYTest test = null;
|
private DIYTest test = null;
|
||||||
|
|
||||||
public Presenter(IView view, IConfigurationManager configManager) {
|
public Presenter(IView view, IConfigurationManager<?> configManager) {
|
||||||
super();
|
super();
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.configManager = configManager;
|
this.configManager = configManager;
|
||||||
|
|||||||
@@ -3209,5 +3209,25 @@
|
|||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</org.diylc.appframework.update.Version>
|
||||||
|
<org.diylc.appframework.update.Version>
|
||||||
|
<versionNumber>
|
||||||
|
<major>4</major>
|
||||||
|
<minor>10</minor>
|
||||||
|
<build>0</build>
|
||||||
|
</versionNumber>
|
||||||
|
<releaseDate>2020-09-18 00:00:00.000 CET</releaseDate>
|
||||||
|
<name></name>
|
||||||
|
<changes>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Store configuration using the same XML format used for serializing DIY files</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>BUG_FIX</changeType>
|
||||||
|
<description>Favorites on building blocks show up as "null"</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
</changes>
|
||||||
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
|
</org.diylc.appframework.update.Version>
|
||||||
</a>
|
</a>
|
||||||
</java.util.Arrays_-ArrayList>
|
</java.util.Arrays_-ArrayList>
|
||||||
|
|||||||
@@ -126,6 +126,8 @@ public class AreaConverter implements Converter {
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(Class clazz) {
|
public boolean canConvert(Class clazz) {
|
||||||
|
if (clazz == null)
|
||||||
|
return false;
|
||||||
return Area.class.isAssignableFrom(clazz);
|
return Area.class.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public class ColorConverter extends com.thoughtworks.xstream.converters.extended
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(Class clazz) {
|
public boolean canConvert(Class clazz) {
|
||||||
|
if (clazz == null)
|
||||||
|
return false;
|
||||||
return Color.class.isAssignableFrom(clazz);
|
return Color.class.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public class FontConverter extends com.thoughtworks.xstream.converters.extended.
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(Class clazz) {
|
public boolean canConvert(Class clazz) {
|
||||||
|
if (clazz == null)
|
||||||
|
return false;
|
||||||
return Font.class.isAssignableFrom(clazz);
|
return Font.class.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ public class MeasureConverter implements Converter {
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(Class clazz) {
|
public boolean canConvert(Class clazz) {
|
||||||
|
if (clazz == null)
|
||||||
|
return false;
|
||||||
return AbstractMeasure.class.isAssignableFrom(clazz);
|
return AbstractMeasure.class.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,14 +48,28 @@ public class PointConverter implements Converter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||||
double x = Double.parseDouble(reader.getAttribute("x"));
|
double x;
|
||||||
double y = Double.parseDouble(reader.getAttribute("y"));
|
double y;
|
||||||
return new Point2D.Double(x * Constants.PIXELS_PER_INCH, y * Constants.PIXELS_PER_INCH);
|
if (reader.hasMoreChildren()) {
|
||||||
|
reader.moveDown();
|
||||||
|
x = Double.parseDouble(reader.getValue());
|
||||||
|
reader.moveUp();
|
||||||
|
reader.moveDown();
|
||||||
|
y = Double.parseDouble(reader.getValue());
|
||||||
|
reader.moveUp();
|
||||||
|
return new Point2D.Double(x, y);
|
||||||
|
} else {
|
||||||
|
x = Double.parseDouble(reader.getAttribute("x"));
|
||||||
|
y = Double.parseDouble(reader.getAttribute("y"));
|
||||||
|
return new Point2D.Double(x * Constants.PIXELS_PER_INCH, y * Constants.PIXELS_PER_INCH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(Class clazz) {
|
public boolean canConvert(Class clazz) {
|
||||||
|
if (clazz == null)
|
||||||
|
return false;
|
||||||
return Point2D.class.isAssignableFrom(clazz);
|
return Point2D.class.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,10 +96,18 @@ public class ProjectFileManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
configure(xStream);
|
||||||
|
this.xStreamOld = new XStream(new DomDriver());
|
||||||
|
xStreamOld.autodetectAnnotations(true);
|
||||||
|
this.messageDispatcher = messageDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void configure(XStream xStream) {
|
||||||
xStream.autodetectAnnotations(true);
|
xStream.autodetectAnnotations(true);
|
||||||
xStream.alias("point", java.awt.geom.Point2D.class);
|
xStream.alias("point", java.awt.geom.Point2D.class);
|
||||||
xStream.alias("point", java.awt.geom.Point2D.Double.class);
|
xStream.alias("point", java.awt.geom.Point2D.Double.class);
|
||||||
xStream.alias("font", java.awt.Font.class);
|
xStream.alias("font", java.awt.Font.class);
|
||||||
|
// xStream.alias("color", java.awt.Color.class);
|
||||||
xStream.alias("project", Project.class);
|
xStream.alias("project", Project.class);
|
||||||
xStream.aliasPackage("diylc", "org.diylc.components");
|
xStream.aliasPackage("diylc", "org.diylc.components");
|
||||||
xStream.registerConverter(new PointConverter());
|
xStream.registerConverter(new PointConverter());
|
||||||
@@ -117,9 +125,6 @@ public class ProjectFileManager {
|
|||||||
xStream.addImmutableType(org.diylc.core.measures.Power.class);
|
xStream.addImmutableType(org.diylc.core.measures.Power.class);
|
||||||
xStream.addImmutableType(org.diylc.core.measures.Inductance.class);
|
xStream.addImmutableType(org.diylc.core.measures.Inductance.class);
|
||||||
xStream.addImmutableType(org.diylc.core.measures.Size.class);
|
xStream.addImmutableType(org.diylc.core.measures.Size.class);
|
||||||
this.xStreamOld = new XStream(new DomDriver());
|
|
||||||
xStreamOld.autodetectAnnotations(true);
|
|
||||||
this.messageDispatcher = messageDispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startNewFile() {
|
public void startNewFile() {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -42,6 +42,7 @@ import org.diylc.common.IPlugInPort;
|
|||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
import org.diylc.lang.LangUtil;
|
import org.diylc.lang.LangUtil;
|
||||||
import org.diylc.presenter.Presenter;
|
import org.diylc.presenter.Presenter;
|
||||||
|
import org.diylc.serialization.ProjectFileManager;
|
||||||
import org.diylc.swing.gui.MainFrame;
|
import org.diylc.swing.gui.MainFrame;
|
||||||
import org.diylc.swing.gui.TemplateDialog;
|
import org.diylc.swing.gui.TemplateDialog;
|
||||||
import org.diylc.swingframework.FontChooserComboBox;
|
import org.diylc.swingframework.FontChooserComboBox;
|
||||||
@@ -49,6 +50,7 @@ import org.diylc.utils.ResourceLoader;
|
|||||||
|
|
||||||
import com.apple.eawt.AppEvent;
|
import com.apple.eawt.AppEvent;
|
||||||
import com.apple.eawt.Application;
|
import com.apple.eawt.Application;
|
||||||
|
import com.thoughtworks.xstream.XStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class that runs DIYLC.
|
* Main class that runs DIYLC.
|
||||||
@@ -89,7 +91,11 @@ public class DIYLCStarter {
|
|||||||
LOG.error("Could not initialize log4j configuration", e);
|
LOG.error("Could not initialize log4j configuration", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationManager.initialize("diylc");
|
// initialize configuration
|
||||||
|
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
||||||
|
XStream xStream = configurationManager.getSerializer();
|
||||||
|
ProjectFileManager.configure(xStream);
|
||||||
|
configurationManager.initialize("diylc");
|
||||||
|
|
||||||
// disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient
|
// disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient
|
||||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false);
|
ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false);
|
||||||
|
|||||||
@@ -86,9 +86,9 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
|
|
||||||
private HashMap<String, ComponentType> componentTypeCache;
|
private HashMap<String, ComponentType> componentTypeCache;
|
||||||
|
|
||||||
private IConfigurationManager configManager;
|
private IConfigurationManager<?> configManager;
|
||||||
|
|
||||||
public CanvasPanel(IPlugInPort plugInPort, IConfigurationManager configManager) {
|
public CanvasPanel(IPlugInPort plugInPort, IConfigurationManager<?> configManager) {
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
this.configManager = configManager;
|
this.configManager = configManager;
|
||||||
|
|
||||||
|
|||||||
@@ -117,9 +117,9 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
private double zoomLevel = 1;
|
private double zoomLevel = 1;
|
||||||
|
|
||||||
private IConfigurationManager configManager;
|
private IConfigurationManager<?> configManager;
|
||||||
|
|
||||||
public CanvasPlugin(ISwingUI swingUI, IConfigurationManager configManager) {
|
public CanvasPlugin(ISwingUI swingUI, IConfigurationManager<?> configManager) {
|
||||||
this.swingUI = swingUI;
|
this.swingUI = swingUI;
|
||||||
this.configManager = configManager;
|
this.configManager = configManager;
|
||||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class TestBase {
|
|||||||
protected IView view;
|
protected IView view;
|
||||||
|
|
||||||
public TestBase() {
|
public TestBase() {
|
||||||
ConfigurationManager.initialize("diylc-test");
|
ConfigurationManager.getInstance().initialize("diylc-test");
|
||||||
view = new MockView();
|
view = new MockView();
|
||||||
presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
|
presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user