mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
checks for file modifications
This commit is contained in:
+26
-34
@@ -74,16 +74,41 @@ public interface IPlugInPort {
|
||||
*/
|
||||
void loadProject(Project project, boolean freshStart);
|
||||
|
||||
/**
|
||||
* Creates a new project.
|
||||
*/
|
||||
void createNewProject();
|
||||
|
||||
/**
|
||||
* Loads a project from the specified file.
|
||||
*
|
||||
* @param fileName
|
||||
*/
|
||||
void loadProjectFromFile(String fileName);
|
||||
|
||||
/**
|
||||
* Saves the current project into the specified file.
|
||||
*
|
||||
* @param fileName
|
||||
*/
|
||||
void saveProjectToFile(String fileName);
|
||||
|
||||
/**
|
||||
* @return the current file name.
|
||||
*/
|
||||
String getCurrentFileName();
|
||||
|
||||
/**
|
||||
* @return true if the current project is modified.
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
@@ -247,47 +272,14 @@ public interface IPlugInPort {
|
||||
* Adds a list of components to the project.
|
||||
*
|
||||
* @param components
|
||||
* @param preferredPoint
|
||||
*/
|
||||
void addComponents(List<IDIYComponent<?>> components, Point preferredPoint);
|
||||
void addComponents(List<IDIYComponent<?>> components);
|
||||
|
||||
/**
|
||||
* Deletes all the selected components from the project.
|
||||
*/
|
||||
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
|
||||
* component types.
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public class Project implements Serializable {
|
||||
public static String DEFAULT_TITLE = "New Project";
|
||||
public static Size DEFAULT_WIDTH = new Size(29d, 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 author;
|
||||
|
||||
+10
-3
@@ -195,6 +195,13 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
editor.setVisible(true);
|
||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||
plugInPort.applyPropertiesToProject(properties);
|
||||
// Save default values.
|
||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||
if (property.getValue() != null) {
|
||||
plugInPort.setDefaultPropertyValue(property.getName(),
|
||||
property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||
@@ -207,12 +214,12 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Save default values.
|
||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||
if (property.getValue() != null) {
|
||||
plugInPort.setDefaultPropertyValue(property.getName(), property
|
||||
.getValue());
|
||||
plugInPort.setDefaultPropertyValue(property.getName(),
|
||||
property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -175,7 +175,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
||||
try {
|
||||
List<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
||||
.getData(ComponentSelection.listFlavor);
|
||||
plugInPort.addComponents(cloner.deepClone(components), null);
|
||||
plugInPort.addComponents(cloner.deepClone(components));
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Coule not paste.", ex);
|
||||
}
|
||||
|
||||
+26
-53
@@ -129,7 +129,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
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);
|
||||
plugIn.connect(this);
|
||||
messageDispatcher.registerListener(plugIn);
|
||||
@@ -150,7 +150,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public void setZoomLevel(double zoomLevel) {
|
||||
LOG.debug(String.format("setZoomLevel(%s)", zoomLevel));
|
||||
LOG.info(String.format("setZoomLevel(%s)", zoomLevel));
|
||||
this.zoomLevel = zoomLevel;
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
@@ -192,7 +192,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
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;
|
||||
selectedComponents.clear();
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
|
||||
@@ -211,6 +211,8 @@ public class Presenter implements IPlugInPort {
|
||||
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",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,11 +228,13 @@ public class Presenter implements IPlugInPort {
|
||||
this.modified = false;
|
||||
fireFileStatusChanged();
|
||||
} catch (FileNotFoundException ex) {
|
||||
// TODO Auto-generated catch block
|
||||
ex.printStackTrace();
|
||||
LOG.error("Could not load file", ex);
|
||||
view.showMessage("Could not open file, " + fileName + " does not exist.", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} catch (IOException ex) {
|
||||
// TODO Auto-generated catch block
|
||||
ex.printStackTrace();
|
||||
LOG.error("Could not load file", ex);
|
||||
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.modified = false;
|
||||
fireFileStatusChanged();
|
||||
} catch (FileNotFoundException ex) {
|
||||
// TODO Auto-generated catch block
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
// TODO Auto-generated catch block
|
||||
ex.printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Could not save file", ex);
|
||||
view.showMessage("Could not save file " + fileName + ". Check the log for details.",
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,7 +631,6 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
// Expand control points to include all stuck components.
|
||||
includeStuckComponents(controlPointMap);
|
||||
LOG.debug(controlPointMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,8 +796,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addComponents(List<IDIYComponent<?>> components, Point preferredPoint) {
|
||||
LOG.debug(String.format("addComponents(%s)", components));
|
||||
public void addComponents(List<IDIYComponent<?>> components) {
|
||||
LOG.info(String.format("addComponents(%s)", components));
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
for (IDIYComponent<?> component : components) {
|
||||
addComponent(component, componentTypeMap.get(component.getClass().getName()));
|
||||
@@ -810,7 +811,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public void deleteSelectedComponents() {
|
||||
LOG.debug("deleteSelectedComponents()");
|
||||
LOG.info("deleteSelectedComponents()");
|
||||
if (selectedComponents.isEmpty()) {
|
||||
LOG.debug("Nothing to delete");
|
||||
return;
|
||||
@@ -826,36 +827,10 @@ public class Presenter implements IPlugInPort {
|
||||
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")
|
||||
@Override
|
||||
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) {
|
||||
String className = component.getClass().getName();
|
||||
LOG.debug("Default property value set for " + className + ":" + propertyName);
|
||||
@@ -873,7 +848,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public void groupSelectedComponents() {
|
||||
LOG.debug("groupSelectedComponents()");
|
||||
LOG.info("groupSelectedComponents()");
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
// First remove the selected components from other groups.
|
||||
ungroupComponents(selectedComponents);
|
||||
@@ -891,7 +866,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public void ungroupSelectedComponents() {
|
||||
LOG.debug("ungroupSelectedComponents()");
|
||||
LOG.info("ungroupSelectedComponents()");
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
ungroupComponents(selectedComponents);
|
||||
// Notify the listeners.
|
||||
@@ -1129,6 +1104,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
} catch (Exception 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 {
|
||||
// Notify the listeners.
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
@@ -1168,6 +1145,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
} catch (Exception 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 {
|
||||
// Notify the listeners.
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
@@ -1183,7 +1162,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
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()));
|
||||
this.componentSlot = componentType;
|
||||
selectedComponents.clear();
|
||||
@@ -1221,11 +1200,5 @@ public class Presenter implements IPlugInPort {
|
||||
return false;
|
||||
}
|
||||
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