setup sticky and visibility policy for each point inidividually

This commit is contained in:
bancika
2011-01-17 19:46:42 +00:00
parent 7ad87076d3
commit f37e0dfc95
25 changed files with 198 additions and 57 deletions
@@ -62,7 +62,6 @@ public class ComponentProcessor {
Icon icon;
double zOrder;
boolean stretchable;
boolean sticky;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
name = annotation.name();
@@ -73,7 +72,6 @@ public class ComponentProcessor {
author = annotation.author();
zOrder = annotation.zOrder();
stretchable = annotation.stretchable();
sticky = annotation.sticky();
} else {
name = clazz.getSimpleName();
description = "";
@@ -83,7 +81,6 @@ public class ComponentProcessor {
author = "Unknown";
zOrder = IDIYComponent.COMPONENT;
stretchable = true;
sticky = false;
}
icon = null;
// Draw component icon.
@@ -92,7 +89,9 @@ public class ComponentProcessor {
Image image = new BufferedImage(Presenter.ICON_SIZE, Presenter.ICON_SIZE,
java.awt.image.BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
componentInstance.drawIcon(g2d, Presenter.ICON_SIZE, Presenter.ICON_SIZE);
icon = new ImageIcon(image);
} catch (InstantiationException e) {
@@ -101,7 +100,7 @@ public class ComponentProcessor {
e.printStackTrace();
}
ComponentType componentType = new ComponentType(name, description, creationMethod,
category, namePrefix, author, icon, clazz, zOrder, stretchable, sticky);
category, namePrefix, author, icon, clazz, zOrder, stretchable);
return componentType;
}
@@ -306,14 +306,15 @@ public class Presenter implements IPlugInPort {
if (currentProject == null) {
return;
}
Set<IDIYComponent<?>> drawControlPoints = new HashSet<IDIYComponent<?>>();
Set<IDIYComponent<?>> groupedComponents = new HashSet<IDIYComponent<?>>();
for (IDIYComponent<?> component : currentProject.getComponents()) {
if (shouldShowControlPointsFor(component)) {
drawControlPoints.add(component);
// Only try to draw control points of ungrouped
if (findAllGroupedComponents(component).size() > 1) {
groupedComponents.add(component);
}
}
projectPainter.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
selectedComponents, drawControlPoints, Arrays.asList(controlPointSlot,
selectedComponents, groupedComponents, Arrays.asList(controlPointSlot,
potentialControlPoint), dragInProgress, zoomLevel);
}
@@ -569,13 +570,14 @@ public class Presenter implements IPlugInPort {
for (IDIYComponent<?> component : currentProject.getComponents()) {
// Do not process a component if it's already in the map.
ComponentType componentType = componentTypeMap.get(component.getClass().getName());
if (!controlPointMap.containsKey(component) && componentType.isSticky()) {
// Check if there's a control point in the current selection
// that matches with one of its control points.
for (int i = 0; i < component.getControlPointCount(); i++) {
if (controlPointMap.containsKey(component)) {
break;
}
// Check if there's a control point in the current selection
// that matches with one of its control points.
for (int i = 0; i < component.getControlPointCount(); i++) {
if (controlPointMap.containsKey(component)) {
break;
}
if (!controlPointMap.containsKey(component) && component.isControlPointSticky(i)) {
boolean componentMatches = false;
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap
.entrySet()) {
@@ -1154,11 +1156,6 @@ public class Presenter implements IPlugInPort {
* component.
*/
private boolean shouldShowControlPointsFor(IDIYComponent<?> component) {
ComponentType componentType = componentTypeMap.get(component.getClass().getName());
// Do not show control points for non-stretchable components.
if (!componentType.isStretchable()) {
return false;
}
if (findAllGroupedComponents(component).size() > 1) {
return false;
}
@@ -22,6 +22,7 @@ import org.diylc.common.IComponentFiler;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.utils.Constants;
/**
@@ -50,7 +51,7 @@ public class ProjectPainter {
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents,
Set<IDIYComponent<?>> drawControlPoints, List<Point> controlPointSlot,
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
boolean dragInProgress, double zoomLevel) {
if (project == null) {
return;
@@ -137,10 +138,17 @@ public class ProjectPainter {
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
// Draw unselected points first to make sure they are below.
for (IDIYComponent<?> component : project.getComponents()) {
if (drawControlPoints.contains(component)
&& !selectedComponents.contains(component)) {
g2dWrapper.setColor(Constants.CONTROL_POINT_COLOR);
for (int i = 0; i < component.getControlPointCount(); i++) {
for (int i = 0; i < component.getControlPointCount(); i++) {
VisibilityPolicy visibilityPolicy = component
.getControlPointVisibilityPolicy(i);
if ((groupedComponents.contains(component)
&& (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents
.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
.contains(component)
&& !selectedComponents.contains(component) && component
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
g2dWrapper.setColor(Constants.CONTROL_POINT_COLOR);
Point controlPoint = component.getControlPoint(i);
int pointSize = CONTROL_POINT_SIZE - 2;
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
@@ -150,9 +158,12 @@ public class ProjectPainter {
}
// Then draw the selected ones.
for (IDIYComponent<?> component : selectedComponents) {
if (drawControlPoints.contains(component)) {
g2dWrapper.setColor(Constants.SELECTED_CONTROL_POINT_COLOR);
for (int i = 0; i < component.getControlPointCount(); i++) {
for (int i = 0; i < component.getControlPointCount(); i++) {
if (!groupedComponents.contains(component)
&& (component.getControlPointVisibilityPolicy(i) == VisibilityPolicy.WHEN_SELECTED || component
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS)) {
g2dWrapper.setColor(Constants.SELECTED_CONTROL_POINT_COLOR);
Point controlPoint = component.getControlPoint(i);
int pointSize = CONTROL_POINT_SIZE;
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y