fix for drawing area and optimization

This commit is contained in:
bancika
2011-03-02 18:13:34 +00:00
parent 085732fb2c
commit d89a500a5f
3 changed files with 15 additions and 10 deletions
@@ -102,6 +102,9 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
@EditableProperty(name = "Point Count") @EditableProperty(name = "Point Count")
public PointCount getPointCount() { public PointCount getPointCount() {
if (pointCount == null) {
pointCount = PointCount.FOUR;
}
return pointCount; return pointCount;
} }
@@ -115,7 +118,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
@Override @Override
public int getControlPointCount() { public int getControlPointCount() {
switch (pointCount) { switch (getPointCount()) {
case TWO: case TWO:
return 2; return 2;
case THREE: case THREE:
@@ -139,7 +142,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
@Override @Override
public boolean canControlPointOverlap(int index) { public boolean canControlPointOverlap(int index) {
// Only shape control points may overlap. // Only shape control points may overlap.
switch (pointCount) { switch (getPointCount()) {
case TWO: case TWO:
return false; return false;
case THREE: case THREE:
@@ -155,7 +158,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
if (index == 0) { if (index == 0) {
return controlPoints[0]; return controlPoints[0];
} }
switch (pointCount) { switch (getPointCount()) {
case TWO: case TWO:
switch (index) { switch (index) {
case 1: case 1:
@@ -186,7 +189,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
if (index == 0) { if (index == 0) {
controlPoints[0].setLocation(point); controlPoints[0].setLocation(point);
} else { } else {
switch (pointCount) { switch (getPointCount()) {
case TWO: case TWO:
switch (index) { switch (index) {
case 1: case 1:
@@ -66,9 +66,6 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
Shape shape = getBodyShape(); Shape shape = getBodyShape();
// If there's no body, just draw the line connecting the ending points. // If there's no body, just draw the line connecting the ending points.
if (shape == null) { if (shape == null) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
drawLead(g2d, componentState); drawLead(g2d, componentState);
} else if (supportsStandingMode() } else if (supportsStandingMode()
&& length.convertToPixels() > points[0].distance(points[1])) { && length.convertToPixels() > points[0].distance(points[1])) {
@@ -47,7 +47,7 @@ public class DrawingManager {
public static final String ZOOM_KEY = "zoom"; public static final String ZOOM_KEY = "zoom";
public static final String THEME_KEY = "theme"; public static final String THEME_KEY = "theme";
public static boolean DEBUG_COMPONENT_AREAS = false; public static String DEBUG_COMPONENT_AREAS = "org.diylc.debugComponentAreas";
public static Color GRID_COLOR = new Color(240, 240, 240); public static Color GRID_COLOR = new Color(240, 240, 240);
public static Color CONTROL_POINT_COLOR = Color.black; public static Color CONTROL_POINT_COLOR = Color.black;
@@ -70,11 +70,16 @@ public class DrawingManager {
private MessageDispatcher<EventType> messageDispatcher; private MessageDispatcher<EventType> messageDispatcher;
private boolean debugComponentAreas;
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) { public DrawingManager(MessageDispatcher<EventType> messageDispatcher) {
super(); super();
this.messageDispatcher = messageDispatcher; this.messageDispatcher = messageDispatcher;
componentAreaMap = new HashMap<IDIYComponent<?>, Area>(); componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>(); lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS);
debugComponentAreas = debugComponentAreasStr != null
&& debugComponentAreasStr.equalsIgnoreCase("true");
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(THEME_KEY, null); Theme theme = (Theme) ConfigurationManager.getInstance().readObject(THEME_KEY, null);
if (theme != null) { if (theme != null) {
this.theme = theme; this.theme = theme;
@@ -221,7 +226,7 @@ public class DrawingManager {
failedComponents.add(component); failedComponents.add(component);
} }
Area area = g2dWrapper.finishedDrawingComponent(); Area area = g2dWrapper.finishedDrawingComponent();
if (trackArea) { if (trackArea && area != null && !area.isEmpty()) {
componentAreaMap.put(component, area); componentAreaMap.put(component, area);
lastDrawnStateMap.put(component, state); lastDrawnStateMap.put(component, state);
} }
@@ -319,7 +324,7 @@ public class DrawingManager {
} }
// Draw component area for test // Draw component area for test
if (DEBUG_COMPONENT_AREAS) { if (debugComponentAreas) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(Color.red); g2d.setColor(Color.red);
for (Area area : componentAreaMap.values()) { for (Area area : componentAreaMap.values()) {