mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
refactored file management out of presenter
This commit is contained in:
+3
-17
@@ -113,7 +113,7 @@ public class Presenter implements IPlugInPort {
|
||||
currentProject = new Project();
|
||||
cloner = new Cloner();
|
||||
projectPainter = new ProjectPainter();
|
||||
projectFileManager = new ProjectFileManager();
|
||||
projectFileManager = new ProjectFileManager(messageDispatcher);
|
||||
|
||||
// lockedLayers = EnumSet.noneOf(ComponentLayer.class);
|
||||
// visibleLayers = EnumSet.allOf(ComponentLayer.class);
|
||||
@@ -196,7 +196,7 @@ public class Presenter implements IPlugInPort {
|
||||
Project project = new Project();
|
||||
setDefaultProperties(project);
|
||||
loadProject(project, true);
|
||||
fireFileStatusChanged();
|
||||
projectFileManager.fireFileStatusChanged();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not create new file", e);
|
||||
view.showMessage("Could not create a new file. Check the log for details.", "Error",
|
||||
@@ -210,7 +210,7 @@ public class Presenter implements IPlugInPort {
|
||||
try {
|
||||
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName);
|
||||
loadProject(project, true);
|
||||
fireFileStatusChanged();
|
||||
projectFileManager.fireFileStatusChanged();
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Could not load file", ex);
|
||||
view.showMessage("Could not open file " + fileName + ". Check the log for details.",
|
||||
@@ -234,7 +234,6 @@ public class Presenter implements IPlugInPort {
|
||||
LOG.info(String.format("saveProjectToFile(%s)", fileName));
|
||||
try {
|
||||
projectFileManager.serializeProjectToFile(currentProject, fileName);
|
||||
fireFileStatusChanged();
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Could not save file", ex);
|
||||
view.showMessage("Could not save file " + fileName + ". Check the log for details.",
|
||||
@@ -728,7 +727,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, preDragProject, cloner
|
||||
.deepClone(currentProject), "Drag");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
fireSelectionChanged();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
@@ -753,7 +751,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Add");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
fireSelectionChanged();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
@@ -773,7 +770,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Delete");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
fireSelectionChanged();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
@@ -818,7 +814,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Group");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,7 +828,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Group");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,11 +847,6 @@ public class Presenter implements IPlugInPort {
|
||||
calculateSelectionDimension());
|
||||
}
|
||||
|
||||
private void fireFileStatusChanged() {
|
||||
messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(),
|
||||
isProjectModified());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the groups that contain at least one of the specified
|
||||
* components.
|
||||
@@ -1004,7 +993,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Add " + componentType.getName());
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
|
||||
fireSelectionChanged();
|
||||
@@ -1075,7 +1063,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Edit Selection");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
||||
@@ -1117,7 +1104,6 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Edit Project");
|
||||
projectFileManager.notifyFileChange();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
|
||||
+16
-1
@@ -12,6 +12,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.boards.AbstractBoard;
|
||||
import org.diylc.components.boards.BlankBoard;
|
||||
@@ -36,6 +37,7 @@ import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.diyfever.gui.simplemq.MessageDispatcher;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
|
||||
@@ -51,6 +53,13 @@ public class ProjectFileManager {
|
||||
private String currentFileName = null;
|
||||
private boolean modified = false;
|
||||
|
||||
private MessageDispatcher<EventType> messageDispatcher;
|
||||
|
||||
public ProjectFileManager(MessageDispatcher<EventType> messageDispatcher) {
|
||||
super();
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
}
|
||||
|
||||
public void serializeProjectToFile(Project project, String fileName) throws IOException {
|
||||
LOG.info(String.format("saveProjectToFile(%s)", fileName));
|
||||
FileOutputStream fos;
|
||||
@@ -59,7 +68,7 @@ public class ProjectFileManager {
|
||||
fos.close();
|
||||
this.currentFileName = fileName;
|
||||
this.modified = false;
|
||||
// fireFileStatusChanged();
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
|
||||
public Project deserializeProjectFromFile(String fileName) throws SAXException, IOException,
|
||||
@@ -96,6 +105,7 @@ public class ProjectFileManager {
|
||||
|
||||
public void notifyFileChange() {
|
||||
this.modified = true;
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
|
||||
public String getCurrentFileName() {
|
||||
@@ -106,6 +116,11 @@ public class ProjectFileManager {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void fireFileStatusChanged() {
|
||||
messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(),
|
||||
isModified());
|
||||
}
|
||||
|
||||
private Project parseV1File(Element root) {
|
||||
Project project = new Project();
|
||||
project.setTitle(root.getAttribute("Project"));
|
||||
|
||||
Reference in New Issue
Block a user