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