mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
checks for file modifications
This commit is contained in:
+32
-40
@@ -73,17 +73,42 @@ public interface IPlugInPort {
|
|||||||
* @param freshStart
|
* @param freshStart
|
||||||
*/
|
*/
|
||||||
void loadProject(Project project, boolean freshStart);
|
void loadProject(Project project, boolean freshStart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new project.
|
||||||
|
*/
|
||||||
void createNewProject();
|
void createNewProject();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a project from the specified file.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
*/
|
||||||
void loadProjectFromFile(String fileName);
|
void loadProjectFromFile(String fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the current project into the specified file.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
*/
|
||||||
void saveProjectToFile(String fileName);
|
void saveProjectToFile(String fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the current file name.
|
||||||
|
*/
|
||||||
String getCurrentFileName();
|
String getCurrentFileName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the current project is modified.
|
||||||
|
*/
|
||||||
boolean isProjectModified();
|
boolean isProjectModified();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a user dialog if there are changes to confirm that it's safe to
|
||||||
|
* proceed.
|
||||||
|
*
|
||||||
|
* @return true, if file actions (new, open, close) can be taken
|
||||||
|
*/
|
||||||
boolean allowFileAction();
|
boolean allowFileAction();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -247,47 +272,14 @@ public interface IPlugInPort {
|
|||||||
* Adds a list of components to the project.
|
* Adds a list of components to the project.
|
||||||
*
|
*
|
||||||
* @param components
|
* @param components
|
||||||
* @param preferredPoint
|
|
||||||
*/
|
*/
|
||||||
void addComponents(List<IDIYComponent<?>> components, Point preferredPoint);
|
void addComponents(List<IDIYComponent<?>> components);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all the selected components from the project.
|
* Deletes all the selected components from the project.
|
||||||
*/
|
*/
|
||||||
void deleteSelectedComponents();
|
void deleteSelectedComponents();
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Checks if a certain layer is locked for editing.
|
|
||||||
// *
|
|
||||||
// * @param layer
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// boolean isLayerLocked(ComponentLayer layer);
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Changes layer's locked state.
|
|
||||||
// *
|
|
||||||
// * @param layer
|
|
||||||
// * @param locked
|
|
||||||
// */
|
|
||||||
// void setLayerLocked(ComponentLayer layer, boolean locked);
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Checks if a certain layer is visible.
|
|
||||||
// *
|
|
||||||
// * @param layer
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// boolean isLayerVisible(ComponentLayer layer);
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Changes layer visibility.
|
|
||||||
// *
|
|
||||||
// * @param layer
|
|
||||||
// * @param visible
|
|
||||||
// */
|
|
||||||
// void setLayerVisible(ComponentLayer layer, boolean visible);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets default value for the specified property name for currently selected
|
* Sets default value for the specified property name for currently selected
|
||||||
* component types.
|
* component types.
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ public class Project implements Serializable {
|
|||||||
public static String DEFAULT_TITLE = "New Project";
|
public static String DEFAULT_TITLE = "New Project";
|
||||||
public static Size DEFAULT_WIDTH = new Size(29d, SizeUnit.cm);
|
public static Size DEFAULT_WIDTH = new Size(29d, SizeUnit.cm);
|
||||||
public static Size DEFAULT_HEIGHT = new Size(21d, SizeUnit.cm);
|
public static Size DEFAULT_HEIGHT = new Size(21d, SizeUnit.cm);
|
||||||
public static Size DEFAULT_GRID_SPACING = new Size(0.2d, SizeUnit.in);
|
public static Size DEFAULT_GRID_SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private String author;
|
private String author;
|
||||||
|
|||||||
+13
-6
@@ -195,6 +195,13 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
editor.setVisible(true);
|
editor.setVisible(true);
|
||||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
plugInPort.applyPropertiesToProject(properties);
|
plugInPort.applyPropertiesToProject(properties);
|
||||||
|
// Save default values.
|
||||||
|
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||||
|
if (property.getValue() != null) {
|
||||||
|
plugInPort.setDefaultPropertyValue(property.getName(),
|
||||||
|
property.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PropertyEditorDialog editor = DialogFactory.getInstance()
|
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||||
@@ -207,12 +214,12 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
// Save default values.
|
||||||
// Save default values.
|
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
if (property.getValue() != null) {
|
||||||
if (property.getValue() != null) {
|
plugInPort.setDefaultPropertyValue(property.getName(),
|
||||||
plugInPort.setDefaultPropertyValue(property.getName(), property
|
property.getValue());
|
||||||
.getValue());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
try {
|
try {
|
||||||
List<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
List<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
||||||
.getData(ComponentSelection.listFlavor);
|
.getData(ComponentSelection.listFlavor);
|
||||||
plugInPort.addComponents(cloner.deepClone(components), null);
|
plugInPort.addComponents(cloner.deepClone(components));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Coule not paste.", ex);
|
LOG.error("Coule not paste.", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-53
@@ -129,7 +129,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void installPlugin(IPlugIn plugIn) {
|
public void installPlugin(IPlugIn plugIn) {
|
||||||
LOG.debug(String.format("installPlugin(%s)", plugIn.getClass().getSimpleName()));
|
LOG.info(String.format("installPlugin(%s)", plugIn.getClass().getSimpleName()));
|
||||||
plugIns.add(plugIn);
|
plugIns.add(plugIn);
|
||||||
plugIn.connect(this);
|
plugIn.connect(this);
|
||||||
messageDispatcher.registerListener(plugIn);
|
messageDispatcher.registerListener(plugIn);
|
||||||
@@ -150,7 +150,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setZoomLevel(double zoomLevel) {
|
public void setZoomLevel(double zoomLevel) {
|
||||||
LOG.debug(String.format("setZoomLevel(%s)", zoomLevel));
|
LOG.info(String.format("setZoomLevel(%s)", zoomLevel));
|
||||||
this.zoomLevel = zoomLevel;
|
this.zoomLevel = zoomLevel;
|
||||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
@@ -192,7 +192,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadProject(Project project, boolean freshStart) {
|
public void loadProject(Project project, boolean freshStart) {
|
||||||
LOG.info("Loading project: " + project.getTitle());
|
LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart));
|
||||||
this.currentProject = project;
|
this.currentProject = project;
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
|
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
|
||||||
@@ -211,6 +211,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
fireFileStatusChanged();
|
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",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,11 +228,13 @@ public class Presenter implements IPlugInPort {
|
|||||||
this.modified = false;
|
this.modified = false;
|
||||||
fireFileStatusChanged();
|
fireFileStatusChanged();
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
// TODO Auto-generated catch block
|
LOG.error("Could not load file", ex);
|
||||||
ex.printStackTrace();
|
view.showMessage("Could not open file, " + fileName + " does not exist.", "Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
// TODO Auto-generated catch block
|
LOG.error("Could not load file", ex);
|
||||||
ex.printStackTrace();
|
view.showMessage("Could not open file " + fileName + ". Check the log for details.",
|
||||||
|
"Error", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,12 +260,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
this.currentFileName = fileName;
|
this.currentFileName = fileName;
|
||||||
this.modified = false;
|
this.modified = false;
|
||||||
fireFileStatusChanged();
|
fireFileStatusChanged();
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (Exception ex) {
|
||||||
// TODO Auto-generated catch block
|
LOG.error("Could not save file", ex);
|
||||||
ex.printStackTrace();
|
view.showMessage("Could not save file " + fileName + ". Check the log for details.",
|
||||||
} catch (IOException ex) {
|
"Error", JOptionPane.ERROR_MESSAGE);
|
||||||
// TODO Auto-generated catch block
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +631,6 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
// Expand control points to include all stuck components.
|
// Expand control points to include all stuck components.
|
||||||
includeStuckComponents(controlPointMap);
|
includeStuckComponents(controlPointMap);
|
||||||
LOG.debug(controlPointMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -795,8 +796,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addComponents(List<IDIYComponent<?>> components, Point preferredPoint) {
|
public void addComponents(List<IDIYComponent<?>> components) {
|
||||||
LOG.debug(String.format("addComponents(%s)", components));
|
LOG.info(String.format("addComponents(%s)", components));
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
for (IDIYComponent<?> component : components) {
|
for (IDIYComponent<?> component : components) {
|
||||||
addComponent(component, componentTypeMap.get(component.getClass().getName()));
|
addComponent(component, componentTypeMap.get(component.getClass().getName()));
|
||||||
@@ -810,7 +811,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteSelectedComponents() {
|
public void deleteSelectedComponents() {
|
||||||
LOG.debug("deleteSelectedComponents()");
|
LOG.info("deleteSelectedComponents()");
|
||||||
if (selectedComponents.isEmpty()) {
|
if (selectedComponents.isEmpty()) {
|
||||||
LOG.debug("Nothing to delete");
|
LOG.debug("Nothing to delete");
|
||||||
return;
|
return;
|
||||||
@@ -826,36 +827,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public boolean isLayerLocked(ComponentLayer layer) {
|
|
||||||
// return lockedLayers.contains(layer);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setLayerLocked(ComponentLayer layer, boolean locked) {
|
|
||||||
// LOG.debug(String.format("setLayerLocked(%s, %s)", layer, locked));
|
|
||||||
// if (locked) {
|
|
||||||
// lockedLayers.add(layer);
|
|
||||||
// } else {
|
|
||||||
// lockedLayers.remove(layer);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public boolean isLayerVisible(ComponentLayer layer) {
|
|
||||||
// return visibleLayers.contains(layer);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setLayerVisible(ComponentLayer layer, boolean visible) {
|
|
||||||
// LOG.debug(String.format("setLayerVisible(%s, %s)", layer, visible));
|
|
||||||
// if (visible) {
|
|
||||||
// visibleLayers.add(layer);
|
|
||||||
// } else {
|
|
||||||
// visibleLayers.remove(layer);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultPropertyValue(String propertyName, Object value) {
|
public void setDefaultPropertyValue(String propertyName, Object value) {
|
||||||
LOG.debug(String.format("setDefaultPropertyValue(%s, %s)", propertyName, value));
|
LOG.info(String.format("setDefaultPropertyValue(%s, %s)", propertyName, value));
|
||||||
for (IDIYComponent component : selectedComponents) {
|
for (IDIYComponent component : selectedComponents) {
|
||||||
String className = component.getClass().getName();
|
String className = component.getClass().getName();
|
||||||
LOG.debug("Default property value set for " + className + ":" + propertyName);
|
LOG.debug("Default property value set for " + className + ":" + propertyName);
|
||||||
@@ -873,7 +848,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void groupSelectedComponents() {
|
public void groupSelectedComponents() {
|
||||||
LOG.debug("groupSelectedComponents()");
|
LOG.info("groupSelectedComponents()");
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
// First remove the selected components from other groups.
|
// First remove the selected components from other groups.
|
||||||
ungroupComponents(selectedComponents);
|
ungroupComponents(selectedComponents);
|
||||||
@@ -891,7 +866,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ungroupSelectedComponents() {
|
public void ungroupSelectedComponents() {
|
||||||
LOG.debug("ungroupSelectedComponents()");
|
LOG.info("ungroupSelectedComponents()");
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
ungroupComponents(selectedComponents);
|
ungroupComponents(selectedComponents);
|
||||||
// Notify the listeners.
|
// Notify the listeners.
|
||||||
@@ -1129,6 +1104,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not apply selection properties", e);
|
LOG.error("Could not apply selection properties", e);
|
||||||
|
view.showMessage("Could not apply changes to the selection. Check the log for details.",
|
||||||
|
"Error", JOptionPane.ERROR_MESSAGE);
|
||||||
} finally {
|
} finally {
|
||||||
// Notify the listeners.
|
// Notify the listeners.
|
||||||
if (!oldProject.equals(currentProject)) {
|
if (!oldProject.equals(currentProject)) {
|
||||||
@@ -1168,6 +1145,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not apply project properties", e);
|
LOG.error("Could not apply project properties", e);
|
||||||
|
view.showMessage("Could not apply changes to the project. Check the log for details.",
|
||||||
|
"Error", JOptionPane.ERROR_MESSAGE);
|
||||||
} finally {
|
} finally {
|
||||||
// Notify the listeners.
|
// Notify the listeners.
|
||||||
if (!oldProject.equals(currentProject)) {
|
if (!oldProject.equals(currentProject)) {
|
||||||
@@ -1183,7 +1162,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNewComponentSlot(ComponentType componentType) {
|
public void setNewComponentSlot(ComponentType componentType) {
|
||||||
LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
LOG.info(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
||||||
: componentType.getName()));
|
: componentType.getName()));
|
||||||
this.componentSlot = componentType;
|
this.componentSlot = componentType;
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
@@ -1221,11 +1200,5 @@ public class Presenter implements IPlugInPort {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return selectedComponents.contains(component);
|
return selectedComponents.contains(component);
|
||||||
// return
|
|
||||||
// controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.ALWAYS)
|
|
||||||
// ||
|
|
||||||
// ((controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.WHEN_SELECTED))
|
|
||||||
// && (getSelectedComponents()
|
|
||||||
// .contains(component)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user