mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added component slot while creating
invalidate components when deleted
This commit is contained in:
@@ -35,6 +35,11 @@
|
|||||||
<exclude name="**/*dll" />
|
<exclude name="**/*dll" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
|
<copy todir="${jar.dir}/library" overwrite="true">
|
||||||
|
<fileset dir="${basedir}/library">
|
||||||
|
<exclude name="**/*dll" />
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
<copy todir="${jar.dir}" overwrite="true">
|
<copy todir="${jar.dir}" overwrite="true">
|
||||||
<fileset dir="${basedir}/lib/" includes="**/*.dll" />
|
<fileset dir="${basedir}/lib/" includes="**/*.dll" />
|
||||||
</copy>
|
</copy>
|
||||||
@@ -43,6 +48,7 @@
|
|||||||
<path id="class.path">
|
<path id="class.path">
|
||||||
<fileset dir="${basedir}">
|
<fileset dir="${basedir}">
|
||||||
<include name="lib/**/*.jar" />
|
<include name="lib/**/*.jar" />
|
||||||
|
<include name="library/**/*.jar" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -200,10 +200,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setControlPoint(Point point, int index) {
|
public void setControlPoint(Point point, int index) {
|
||||||
// Only accept the change if ending points are not the same.
|
points[index].setLocation(point);
|
||||||
if (!point.equals(points[1 - index])) {
|
|
||||||
points[index].setLocation(point);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Color")
|
@EditableProperty(name = "Color")
|
||||||
|
|||||||
+19
-14
@@ -185,20 +185,25 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
List<PropertyWrapper> properties = plugInPort
|
List<PropertyWrapper> properties = plugInPort
|
||||||
.getMutualSelectionProperties();
|
.getMutualSelectionProperties();
|
||||||
if (properties == null || properties.isEmpty()) {
|
if (properties == null || properties.isEmpty()) {
|
||||||
properties = plugInPort.getProjectProperties();
|
// properties = plugInPort.getProjectProperties();
|
||||||
PropertyEditorDialog editor = DialogFactory.getInstance()
|
// PropertyEditorDialog editor =
|
||||||
.createPropertyEditorDialog(properties, "Edit Project");
|
// DialogFactory.getInstance()
|
||||||
editor.setVisible(true);
|
// .createPropertyEditorDialog(properties,
|
||||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
// "Edit Project");
|
||||||
plugInPort.applyPropertiesToProject(properties);
|
// editor.setVisible(true);
|
||||||
// Save default values.
|
// if
|
||||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
// (ButtonDialog.OK.equals(editor.getSelectedButtonCaption()))
|
||||||
if (property.getValue() != null) {
|
// {
|
||||||
plugInPort.setProjectDefaultPropertyValue(property.getName(),
|
// plugInPort.applyPropertiesToProject(properties);
|
||||||
property.getValue());
|
// // Save default values.
|
||||||
}
|
// for (PropertyWrapper property :
|
||||||
}
|
// editor.getDefaultedProperties()) {
|
||||||
}
|
// if (property.getValue() != null) {
|
||||||
|
// plugInPort.setProjectDefaultPropertyValue(property.getName(),
|
||||||
|
// property.getValue());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
PropertyEditorDialog editor = DialogFactory.getInstance()
|
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||||
.createPropertyEditorDialog(properties, "Edit Selection");
|
.createPropertyEditorDialog(properties, "Edit Selection");
|
||||||
|
|||||||
+16
@@ -12,9 +12,12 @@ import javax.swing.AbstractAction;
|
|||||||
import org.diylc.common.EventType;
|
import org.diylc.common.EventType;
|
||||||
import org.diylc.common.IPlugIn;
|
import org.diylc.common.IPlugIn;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.gui.DialogFactory;
|
import org.diylc.gui.DialogFactory;
|
||||||
|
import org.diylc.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
|
|
||||||
|
import com.diyfever.gui.ButtonDialog;
|
||||||
import com.diyfever.gui.IDrawingProvider;
|
import com.diyfever.gui.IDrawingProvider;
|
||||||
import com.diyfever.gui.export.DrawingExporter;
|
import com.diyfever.gui.export.DrawingExporter;
|
||||||
import com.lowagie.text.DocumentException;
|
import com.lowagie.text.DocumentException;
|
||||||
@@ -74,6 +77,19 @@ public class FileMenuPlugin implements IPlugIn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugInPort.createNewProject();
|
plugInPort.createNewProject();
|
||||||
|
List<PropertyWrapper> properties = plugInPort.getProjectProperties();
|
||||||
|
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
|
||||||
|
properties, "Edit Project");
|
||||||
|
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.setProjectDefaultPropertyValue(property.getName(), property.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+139
-73
@@ -98,7 +98,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
private Project preDragProject = null;
|
private Project preDragProject = null;
|
||||||
|
|
||||||
// Component creation
|
// Component creation
|
||||||
private ComponentType componentSlot;
|
private ComponentType componentTypeSlot;
|
||||||
|
private IDIYComponent<?> componentSlot;
|
||||||
private Point controlPointSlot;
|
private Point controlPointSlot;
|
||||||
private Point potentialControlPoint;
|
private Point potentialControlPoint;
|
||||||
|
|
||||||
@@ -159,7 +160,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
@Override
|
@Override
|
||||||
public Cursor getCursorAt(Point point) {
|
public Cursor getCursorAt(Point point) {
|
||||||
// Only change the cursor if we're not making a new component.
|
// Only change the cursor if we're not making a new component.
|
||||||
if (componentSlot == null) {
|
if (componentTypeSlot == null) {
|
||||||
// Scale point to remove zoom factor.
|
// Scale point to remove zoom factor.
|
||||||
Point2D scaledPoint = scalePoint(point);
|
Point2D scaledPoint = scalePoint(point);
|
||||||
if (projectPainter.isCursorOverArea(scaledPoint)) {
|
if (projectPainter.isCursorOverArea(scaledPoint)) {
|
||||||
@@ -288,14 +289,22 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
Set<IDIYComponent<?>> groupedComponents = new HashSet<IDIYComponent<?>>();
|
Set<IDIYComponent<?>> groupedComponents = new HashSet<IDIYComponent<?>>();
|
||||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||||
// Only try to draw control points of ungrouped
|
// Only try to draw control points of ungrouped components.
|
||||||
if (findAllGroupedComponents(component).size() > 1) {
|
if (findAllGroupedComponents(component).size() > 1) {
|
||||||
groupedComponents.add(component);
|
groupedComponents.add(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Don't draw the component in the slot if both control points match.
|
||||||
|
IDIYComponent<?> componentSlotToDraw;
|
||||||
|
if (controlPointSlot != null && potentialControlPoint != null
|
||||||
|
&& potentialControlPoint.equals(controlPointSlot)) {
|
||||||
|
componentSlotToDraw = null;
|
||||||
|
} else {
|
||||||
|
componentSlotToDraw = componentSlot;
|
||||||
|
}
|
||||||
projectPainter.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
|
projectPainter.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
|
||||||
selectedComponents, groupedComponents, Arrays.asList(controlPointSlot,
|
selectedComponents, groupedComponents, Arrays.asList(controlPointSlot,
|
||||||
potentialControlPoint), dragInProgress, zoomLevel);
|
potentialControlPoint), componentSlotToDraw, dragInProgress, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -333,43 +342,74 @@ public class Presenter implements IPlugInPort {
|
|||||||
LOG.debug(String
|
LOG.debug(String
|
||||||
.format("mouseClicked(%s, %s, %s, %s)", point, ctrlDown, shiftDown, altDown));
|
.format("mouseClicked(%s, %s, %s, %s)", point, ctrlDown, shiftDown, altDown));
|
||||||
Point scaledPoint = scalePoint(point);
|
Point scaledPoint = scalePoint(point);
|
||||||
if (componentSlot != null) {
|
if (componentTypeSlot != null) {
|
||||||
switch (componentSlot.getCreationMethod()) {
|
// Keep the reference to component type for later.
|
||||||
|
ComponentType componentType = componentTypeSlot;
|
||||||
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
|
switch (componentTypeSlot.getCreationMethod()) {
|
||||||
case SINGLE_CLICK:
|
case SINGLE_CLICK:
|
||||||
try {
|
try {
|
||||||
instantiateComponent(componentSlot, scaledPoint);
|
IDIYComponent<?> component = instantiateComponent(componentTypeSlot,
|
||||||
|
scaledPoint);
|
||||||
|
addComponent(component, componentTypeSlot);
|
||||||
|
// Select the new component
|
||||||
|
selectedComponents.clear();
|
||||||
|
selectedComponents.add(component);
|
||||||
|
|
||||||
|
fireSelectionChanged();
|
||||||
|
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
||||||
|
// selectedComponents);
|
||||||
|
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
||||||
|
// calculateSelectionDimension());
|
||||||
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error instatiating component of type: "
|
LOG.error("Error instatiating component of type: "
|
||||||
+ componentSlot.getInstanceClass().getName(), e);
|
+ componentTypeSlot.getInstanceClass().getName(), e);
|
||||||
}
|
}
|
||||||
setNewComponentSlot(null);
|
setNewComponentSlot(null);
|
||||||
break;
|
break;
|
||||||
case POINT_BY_POINT:
|
case POINT_BY_POINT:
|
||||||
if (controlPointSlot != null) {
|
// First click is just to set the controlPointSlot and
|
||||||
|
// componentSlot.
|
||||||
|
if (snapToGrid) {
|
||||||
snapPointToGrid(scaledPoint);
|
snapPointToGrid(scaledPoint);
|
||||||
if (scaledPoint.equals(controlPointSlot)) {
|
}
|
||||||
String message = "Cannot create the component because both controls points match. Choose the second control point.";
|
if (controlPointSlot == null) {
|
||||||
LOG.warn(message);
|
|
||||||
view.showMessage(message, "Error", JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
instantiateComponent(componentSlot, controlPointSlot, scaledPoint);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Error instatiating component of type: "
|
|
||||||
+ componentSlot.getInstanceClass().getName(), e);
|
|
||||||
}
|
|
||||||
setNewComponentSlot(null);
|
|
||||||
} else {
|
|
||||||
controlPointSlot = scaledPoint;
|
controlPointSlot = scaledPoint;
|
||||||
snapPointToGrid(controlPointSlot);
|
try {
|
||||||
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentSlot,
|
componentSlot = instantiateComponent(componentTypeSlot, controlPointSlot);
|
||||||
|
} catch (Exception e) {
|
||||||
|
view.showMessage("Could not create component. Check log for details.",
|
||||||
|
"Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
LOG.error("Could not create component", e);
|
||||||
|
}
|
||||||
|
// Set the other control point to the same location, we'll
|
||||||
|
// move it later when mouse moves.
|
||||||
|
componentSlot.setControlPoint(controlPointSlot, 0);
|
||||||
|
componentSlot.setControlPoint(controlPointSlot, 1);
|
||||||
|
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentTypeSlot,
|
||||||
controlPointSlot);
|
controlPointSlot);
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
|
} else {
|
||||||
|
// On the second click, add the component to the project.
|
||||||
|
componentSlot.setControlPoint(scaledPoint, 1);
|
||||||
|
addComponent(componentSlot, componentTypeSlot);
|
||||||
|
// Select the new component
|
||||||
|
selectedComponents.clear();
|
||||||
|
selectedComponents.add(componentSlot);
|
||||||
|
fireSelectionChanged();
|
||||||
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
|
setNewComponentSlot(null);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG.error("Unknown creation method: " + componentSlot.getCreationMethod());
|
LOG.error("Unknown creation method: " + componentTypeSlot.getCreationMethod());
|
||||||
|
}
|
||||||
|
// Notify the listeners.
|
||||||
|
if (!oldProject.equals(currentProject)) {
|
||||||
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
|
.deepClone(currentProject), "Add " + componentType.getName());
|
||||||
|
projectFileManager.notifyFileChange();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<IDIYComponent<?>> components = findComponentsAt(scaledPoint);
|
List<IDIYComponent<?>> components = findComponentsAt(scaledPoint);
|
||||||
@@ -405,9 +445,44 @@ public class Presenter implements IPlugInPort {
|
|||||||
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
||||||
Map<IDIYComponent<?>, Set<Integer>> components = new HashMap<IDIYComponent<?>, Set<Integer>>();
|
Map<IDIYComponent<?>, Set<Integer>> components = new HashMap<IDIYComponent<?>, Set<Integer>>();
|
||||||
Point scaledPoint = scalePoint(point);
|
Point scaledPoint = scalePoint(point);
|
||||||
if (componentSlot != null) {
|
if (componentTypeSlot != null) {
|
||||||
potentialControlPoint = scaledPoint;
|
if (snapToGrid) {
|
||||||
snapPointToGrid(potentialControlPoint);
|
snapPointToGrid(scaledPoint);
|
||||||
|
}
|
||||||
|
switch (componentTypeSlot.getCreationMethod()) {
|
||||||
|
case POINT_BY_POINT:
|
||||||
|
potentialControlPoint = scaledPoint;
|
||||||
|
if (componentSlot != null) {
|
||||||
|
componentSlot.setControlPoint(scaledPoint, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SINGLE_CLICK:
|
||||||
|
if (potentialControlPoint == null) {
|
||||||
|
potentialControlPoint = new Point(0, 0);
|
||||||
|
}
|
||||||
|
int dx = scaledPoint.x - potentialControlPoint.x;
|
||||||
|
int dy = scaledPoint.y - potentialControlPoint.y;
|
||||||
|
if (snapToGrid) {
|
||||||
|
dx = roundToGrid(dx);
|
||||||
|
dy = roundToGrid(dy);
|
||||||
|
}
|
||||||
|
// Only repaint if there's an actual change.
|
||||||
|
if (dx == 0 && dy == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
potentialControlPoint.translate(dx, dy);
|
||||||
|
if (componentSlot == null) {
|
||||||
|
LOG.error("Component slot should not be null!");
|
||||||
|
} else {
|
||||||
|
Point p = new Point();
|
||||||
|
for (int i = 0; i < componentSlot.getControlPointCount(); i++) {
|
||||||
|
p.setLocation(componentSlot.getControlPoint(i));
|
||||||
|
p.translate(dx, dy);
|
||||||
|
componentSlot.setControlPoint(p, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
} else {
|
} else {
|
||||||
// Go backwards so we take the highest z-order components first.
|
// Go backwards so we take the highest z-order components first.
|
||||||
@@ -767,6 +842,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
// Remove selected components from any groups.
|
// Remove selected components from any groups.
|
||||||
ungroupComponents(selectedComponents);
|
ungroupComponents(selectedComponents);
|
||||||
|
// Remove from area map.
|
||||||
|
for (IDIYComponent<?> component : selectedComponents) {
|
||||||
|
projectPainter.invalidateComponent(component);
|
||||||
|
}
|
||||||
currentProject.getComponents().removeAll(selectedComponents);
|
currentProject.getComponents().removeAll(selectedComponents);
|
||||||
this.selectedComponents.clear();
|
this.selectedComponents.clear();
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
@@ -779,7 +858,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
@Override
|
@Override
|
||||||
public void setSelectionDefaultPropertyValue(String propertyName, Object value) {
|
public void setSelectionDefaultPropertyValue(String propertyName, Object value) {
|
||||||
LOG.info(String.format("setSelectionDefaultPropertyValue(%s, %s)", propertyName, value));
|
LOG.info(String.format("setSelectionDefaultPropertyValue(%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);
|
||||||
ConfigurationManager.getInstance().writeValue(
|
ConfigurationManager.getInstance().writeValue(
|
||||||
@@ -936,14 +1015,12 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void instantiateComponent(ComponentType componentType, Point... points)
|
private IDIYComponent<?> instantiateComponent(ComponentType componentType, Point point)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
|
LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
|
||||||
|
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
|
||||||
|
|
||||||
// Instantiate the component.
|
// Instantiate the component.
|
||||||
IDIYComponent component = componentType.getInstanceClass().newInstance();
|
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
||||||
|
|
||||||
// Find the next available componentName for the component.
|
// Find the next available componentName for the component.
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -952,7 +1029,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
i++;
|
i++;
|
||||||
String name = componentType.getNamePrefix() + i;
|
String name = componentType.getNamePrefix() + i;
|
||||||
exists = false;
|
exists = false;
|
||||||
for (IDIYComponent c : currentProject.getComponents()) {
|
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
||||||
if (c.getName().equals(name)) {
|
if (c.getName().equals(name)) {
|
||||||
exists = true;
|
exists = true;
|
||||||
break;
|
break;
|
||||||
@@ -961,48 +1038,19 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
component.setName(componentType.getNamePrefix() + i);
|
component.setName(componentType.getNamePrefix() + i);
|
||||||
|
|
||||||
// Add it to the project taking z-order into account.
|
|
||||||
addComponent(component, componentType);
|
|
||||||
// Select the new component
|
|
||||||
selectedComponents.clear();
|
|
||||||
selectedComponents.add(component);
|
|
||||||
|
|
||||||
// Translate them to the desired location.
|
// Translate them to the desired location.
|
||||||
if (points != null) {
|
if (point != null) {
|
||||||
switch (componentType.getCreationMethod()) {
|
for (int j = 0; j < component.getControlPointCount(); j++) {
|
||||||
case SINGLE_CLICK:
|
Point controlPoint = new Point(component.getControlPoint(j));
|
||||||
for (int j = 0; j < component.getControlPointCount(); j++) {
|
controlPoint.translate(point.x, point.y);
|
||||||
Point controlPoint = new Point(component.getControlPoint(j));
|
snapPointToGrid(controlPoint);
|
||||||
controlPoint.translate(points[0].x, points[0].y);
|
component.setControlPoint(controlPoint, j);
|
||||||
snapPointToGrid(controlPoint);
|
|
||||||
component.setControlPoint(controlPoint, j);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case POINT_BY_POINT:
|
|
||||||
for (int j = 0; j < points.length; j++) {
|
|
||||||
Point point = points[j];
|
|
||||||
snapPointToGrid(point);
|
|
||||||
component.setControlPoint(point, j);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultProperties(component);
|
setDefaultProperties(component);
|
||||||
|
|
||||||
// Notify the listeners.
|
return component;
|
||||||
if (!oldProject.equals(currentProject)) {
|
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
|
||||||
.deepClone(currentProject), "Add " + componentType.getName());
|
|
||||||
projectFileManager.notifyFileChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
fireSelectionChanged();
|
|
||||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
|
||||||
// selectedComponents);
|
|
||||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
|
||||||
// calculateSelectionDimension());
|
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1116,7 +1164,24 @@ public class Presenter implements IPlugInPort {
|
|||||||
public void setNewComponentSlot(ComponentType componentType) {
|
public void setNewComponentSlot(ComponentType componentType) {
|
||||||
LOG.info(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
LOG.info(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
||||||
: componentType.getName()));
|
: componentType.getName()));
|
||||||
this.componentSlot = componentType;
|
this.componentTypeSlot = componentType;
|
||||||
|
if (componentTypeSlot == null) {
|
||||||
|
this.componentSlot = null;
|
||||||
|
} else {
|
||||||
|
switch (componentTypeSlot.getCreationMethod()) {
|
||||||
|
case POINT_BY_POINT:
|
||||||
|
this.componentSlot = null;
|
||||||
|
break;
|
||||||
|
case SINGLE_CLICK:
|
||||||
|
try {
|
||||||
|
this.componentSlot = instantiateComponent(componentTypeSlot, new Point(0, 0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.controlPointSlot = null;
|
this.controlPointSlot = null;
|
||||||
this.potentialControlPoint = null;
|
this.potentialControlPoint = null;
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
@@ -1126,7 +1191,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
// selectedComponents);
|
// selectedComponents);
|
||||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
||||||
// calculateSelectionDimension());
|
// calculateSelectionDimension());
|
||||||
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentSlot, controlPointSlot);
|
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentTypeSlot,
|
||||||
|
controlPointSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+29
-16
@@ -1,7 +1,9 @@
|
|||||||
package org.diylc.presenter;
|
package org.diylc.presenter;
|
||||||
|
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Composite;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -50,6 +52,8 @@ public class ProjectPainter {
|
|||||||
// determine which components are invalidated when they are not in the map.
|
// determine which components are invalidated when they are not in the map.
|
||||||
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
|
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
|
||||||
|
|
||||||
|
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||||
|
|
||||||
public ProjectPainter() {
|
public ProjectPainter() {
|
||||||
super();
|
super();
|
||||||
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
||||||
@@ -59,7 +63,7 @@ public class ProjectPainter {
|
|||||||
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
||||||
IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents,
|
IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents,
|
||||||
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||||
boolean dragInProgress, double zoomLevel) {
|
IDIYComponent<?> componentSlot, boolean dragInProgress, double zoomLevel) {
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,21 +153,6 @@ public class ProjectPainter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw control points of the component in the slot.
|
|
||||||
if (controlPointSlot != null) {
|
|
||||||
for (Point point : controlPointSlot) {
|
|
||||||
if (point != null) {
|
|
||||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
|
|
||||||
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y
|
|
||||||
- CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
|
|
||||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
|
|
||||||
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y
|
|
||||||
- CONTROL_POINT_SIZE / 2 + 1, CONTROL_POINT_SIZE - 2,
|
|
||||||
CONTROL_POINT_SIZE - 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw control points.
|
// Draw control points.
|
||||||
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
||||||
// Draw unselected points first to make sure they are below.
|
// Draw unselected points first to make sure they are below.
|
||||||
@@ -208,6 +197,29 @@ public class ProjectPainter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw component slot in a separate composite.
|
||||||
|
if (componentSlot != null) {
|
||||||
|
g2dWrapper.startedDrawingComponent();
|
||||||
|
g2dWrapper.setComposite(slotComposite);
|
||||||
|
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, project, g2dWrapper);
|
||||||
|
g2dWrapper.finishedDrawingComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw control points of the component in the slot.
|
||||||
|
if (controlPointSlot != null) {
|
||||||
|
for (Point point : controlPointSlot) {
|
||||||
|
if (point != null) {
|
||||||
|
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
|
||||||
|
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y
|
||||||
|
- CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
|
||||||
|
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
|
||||||
|
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y
|
||||||
|
- CONTROL_POINT_SIZE / 2 + 1, CONTROL_POINT_SIZE - 2,
|
||||||
|
CONTROL_POINT_SIZE - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Go back to the original transformation and zoom in to draw the
|
// Go back to the original transformation and zoom in to draw the
|
||||||
// selection rectangle and other similar elements.
|
// selection rectangle and other similar elements.
|
||||||
// g2d.setTransform(initialTx);
|
// g2d.setTransform(initialTx);
|
||||||
@@ -236,6 +248,7 @@ public class ProjectPainter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateComponent(IDIYComponent<?> component) {
|
public void invalidateComponent(IDIYComponent<?> component) {
|
||||||
|
componentAreaMap.remove(component);
|
||||||
lastDrawnStateMap.remove(component);
|
lastDrawnStateMap.remove(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user