mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
better error handling when drawing
This commit is contained in:
+8
-2
@@ -72,6 +72,12 @@ public enum EventType {
|
||||
* current cursor location (not taking zoom into account).
|
||||
*/
|
||||
MOUSE_MOVED,
|
||||
LAYER_STATE_CHANGED;
|
||||
;
|
||||
/**
|
||||
* Called when a layer status is changed. The first parameter is a set of indices of locked layers. All layers not included are considered unlocked.
|
||||
*/
|
||||
LAYER_STATE_CHANGED,
|
||||
/**
|
||||
* Called to update the status message. New status message is passed as a first parameter.
|
||||
*/
|
||||
STATUS_MESSAGE_CHANGED;
|
||||
}
|
||||
|
||||
+42
-7
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.GridType;
|
||||
@@ -38,6 +39,8 @@ import com.diyfever.gui.simplemq.MessageDispatcher;
|
||||
*/
|
||||
public class DrawingManager {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DrawingManager.class);
|
||||
|
||||
public static int CONTROL_POINT_SIZE = 7;
|
||||
|
||||
public static final String ANTIALIASING_KEY = "anti-aliasing";
|
||||
@@ -56,6 +59,7 @@ public class DrawingManager {
|
||||
|
||||
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||
private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>();
|
||||
|
||||
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
|
||||
// 1d);
|
||||
@@ -69,12 +73,31 @@ public class DrawingManager {
|
||||
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
|
||||
}
|
||||
|
||||
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
||||
IComponentFiler filter, Rectangle selectionRect, List<IDIYComponent<?>> selectedComponents,
|
||||
Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents,
|
||||
List<Point> controlPointSlot, IDIYComponent<?> componentSlot, boolean dragInProgress) {
|
||||
/**
|
||||
* Paints the project onto the canvas and returns the list of components
|
||||
* that failed to draw.
|
||||
*
|
||||
* @param g2d
|
||||
* @param project
|
||||
* @param drawOptions
|
||||
* @param filter
|
||||
* @param selectionRect
|
||||
* @param selectedComponents
|
||||
* @param lockedComponents
|
||||
* @param groupedComponents
|
||||
* @param controlPointSlot
|
||||
* @param componentSlot
|
||||
* @param dragInProgress
|
||||
* @return
|
||||
*/
|
||||
public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project,
|
||||
Set<DrawOption> drawOptions, IComponentFiler filter, Rectangle selectionRect,
|
||||
List<IDIYComponent<?>> selectedComponents, Set<IDIYComponent<?>> lockedComponents,
|
||||
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||
IDIYComponent<?> componentSlot, boolean dragInProgress) {
|
||||
failedComponents.clear();
|
||||
if (project == null) {
|
||||
return;
|
||||
return failedComponents;
|
||||
}
|
||||
G2DWrapper g2dWrapper = new G2DWrapper(g2d);
|
||||
|
||||
@@ -158,7 +181,12 @@ public class DrawingManager {
|
||||
g2d.setComposite(lockedComposite);
|
||||
}
|
||||
// Draw the component through the g2dWrapper.
|
||||
component.draw(g2dWrapper, state, project, g2dWrapper);
|
||||
try {
|
||||
component.draw(g2dWrapper, state, project, g2dWrapper);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error drawing " + component.getName(), e);
|
||||
failedComponents.add(component);
|
||||
}
|
||||
Area area = g2dWrapper.finishedDrawingComponent();
|
||||
if (trackArea) {
|
||||
componentAreaMap.put(component, area);
|
||||
@@ -214,7 +242,12 @@ public class DrawingManager {
|
||||
if (componentSlot != null) {
|
||||
g2dWrapper.startedDrawingComponent();
|
||||
g2dWrapper.setComposite(slotComposite);
|
||||
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, project, g2dWrapper);
|
||||
try {
|
||||
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, project, g2dWrapper);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error drawing " + componentSlot.getName(), e);
|
||||
failedComponents.add(componentSlot);
|
||||
}
|
||||
g2dWrapper.finishedDrawingComponent();
|
||||
}
|
||||
|
||||
@@ -258,6 +291,8 @@ public class DrawingManager {
|
||||
g2d.draw(area);
|
||||
}
|
||||
}
|
||||
|
||||
return failedComponents;
|
||||
}
|
||||
|
||||
public double getZoomLevel() {
|
||||
|
||||
+19
-5
@@ -299,7 +299,8 @@ public class Presenter implements IPlugInPort {
|
||||
groupedComponents.add(component);
|
||||
}
|
||||
}
|
||||
// Don't draw the component in the slot if both control points match.
|
||||
// Don't draw the component in the slot if both control points
|
||||
// match.
|
||||
IDIYComponent<?> componentSlotToDraw;
|
||||
if (instantiationManager.getFirstControlPoint() != null
|
||||
&& instantiationManager.getPotentialControlPoint() != null
|
||||
@@ -309,10 +310,23 @@ public class Presenter implements IPlugInPort {
|
||||
} else {
|
||||
componentSlotToDraw = instantiationManager.getComponentSlot();
|
||||
}
|
||||
drawingManager.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
|
||||
selectedComponents, getLockedComponents(), groupedComponents, Arrays.asList(
|
||||
instantiationManager.getFirstControlPoint(), instantiationManager
|
||||
.getPotentialControlPoint()), componentSlotToDraw, dragInProgress);
|
||||
List<IDIYComponent<?>> failedComponents = drawingManager.drawProject(g2d, currentProject,
|
||||
drawOptions, filter, selectionRect, selectedComponents, getLockedComponents(),
|
||||
groupedComponents, Arrays.asList(instantiationManager.getFirstControlPoint(),
|
||||
instantiationManager.getPotentialControlPoint()), componentSlotToDraw,
|
||||
dragInProgress);
|
||||
List<String> failedComponentNames = new ArrayList<String>();
|
||||
for (IDIYComponent<?> component : failedComponents) {
|
||||
failedComponentNames.add(component.getName());
|
||||
}
|
||||
Collections.sort(failedComponentNames);
|
||||
if (!failedComponentNames.isEmpty()) {
|
||||
messageDispatcher.dispatchMessage(EventType.STATUS_MESSAGE_CHANGED,
|
||||
"<html><font color='red'>Failed to draw components: "
|
||||
+ Utils.toCommaString(failedComponentNames) + "</font></html>");
|
||||
} else {
|
||||
messageDispatcher.dispatchMessage(EventType.STATUS_MESSAGE_CHANGED, "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-4
@@ -66,6 +66,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
private List<String> componentNamesUnderCursor;
|
||||
private List<String> selectedComponentNames;
|
||||
private List<String> stuckComponentNames;
|
||||
private String statusMessage;
|
||||
|
||||
public StatusBar(ISwingUI swingUI) {
|
||||
super();
|
||||
@@ -196,7 +197,8 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.ZOOM_CHANGED, EventType.SLOT_CHANGED,
|
||||
EventType.AVAILABLE_CTRL_POINTS_CHANGED, EventType.SELECTION_CHANGED);
|
||||
EventType.AVAILABLE_CTRL_POINTS_CHANGED, EventType.SELECTION_CHANGED,
|
||||
EventType.STATUS_MESSAGE_CHANGED);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -247,11 +249,13 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
Collections.sort(componentNamesUnderCursor);
|
||||
refreshStatusText();
|
||||
break;
|
||||
case STATUS_MESSAGE_CHANGED:
|
||||
statusMessage = (String) params[0];
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshStatusText() {
|
||||
String statusText = "";
|
||||
String statusText = this.statusMessage;
|
||||
if (componentSlot == null) {
|
||||
if (componentNamesUnderCursor != null && !componentNamesUnderCursor.isEmpty()) {
|
||||
String formattedNames = Utils.toCommaString(componentNamesUnderCursor);
|
||||
@@ -265,8 +269,6 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
builder.append(")");
|
||||
}
|
||||
statusText = "<html>Selection: " + builder.toString() + "</html>";
|
||||
} else {
|
||||
statusText = "";
|
||||
}
|
||||
} else {
|
||||
switch (componentSlot.getCreationMethod()) {
|
||||
|
||||
Reference in New Issue
Block a user