This commit is contained in:
bancika
2011-01-03 10:31:44 +00:00
parent 65650edad6
commit 2f87896523
4 changed files with 29 additions and 19 deletions
@@ -20,12 +20,12 @@
</entry> </entry>
</map> </map>
</entry> </entry>
<entry>
<string>metric</string>
<boolean>true</boolean>
</entry>
<entry> <entry>
<string>lastPath</string> <string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string> <string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry> </entry>
<entry>
<string>metric</string>
<boolean>true</boolean>
</entry>
</map> </map>
@@ -110,6 +110,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
createBufferImage(); createBufferImage();
} }
do { do {
try {
if (bufferImage.contentsLost()) { if (bufferImage.contentsLost()) {
createBufferImage(); createBufferImage();
} }
@@ -118,7 +119,10 @@ class CanvasPanel extends JComponent implements Autoscroll {
createBufferImage(); createBufferImage();
} }
g.drawImage(bufferImage, 0, 0, this); g.drawImage(bufferImage, 0, 0, this);
} while (bufferImage.contentsLost()); } catch (NullPointerException e) {
// Do nothing, it will be recreated in the next pass.
}
} while (bufferImage == null || bufferImage.contentsLost());
} }
@Override @Override
@@ -6,6 +6,8 @@ import java.util.EnumSet;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import org.apache.log4j.Logger;
import com.diyfever.diylc.common.BadPositionException; import com.diyfever.diylc.common.BadPositionException;
import com.diyfever.diylc.common.EventType; import com.diyfever.diylc.common.EventType;
import com.diyfever.diylc.common.IPlugIn; import com.diyfever.diylc.common.IPlugIn;
@@ -17,7 +19,7 @@ import com.diyfever.gui.ruler.RulerScrollPane;
public class CanvasPlugin implements IPlugIn { public class CanvasPlugin implements IPlugIn {
// private static final Logger LOG = Logger.getLogger(CanvasPlugin.class); private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
private static final String METRIC_KEY = "metric"; private static final String METRIC_KEY = "metric";
@@ -35,7 +37,7 @@ public class CanvasPlugin implements IPlugIn {
try { try {
plugInPort.injectGUIComponent(getScrollPane(), SwingConstants.CENTER); plugInPort.injectGUIComponent(getScrollPane(), SwingConstants.CENTER);
} catch (BadPositionException e) { } catch (BadPositionException e) {
e.printStackTrace(); LOG.error("Could not install canvas plugin", e);
} }
} }
@@ -453,7 +453,7 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} else { } else {
// If there are components selected translate their control points. // If there are components selected translate their control points.
translateSelection(point); translateSelection(dragStartPoint, point);
dragStartPoint = point; dragStartPoint = point;
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
@@ -490,7 +490,7 @@ public class Presenter implements IPlugInPort {
Project oldProject = cloner.deepClone(currentProject); Project oldProject = cloner.deepClone(currentProject);
// If there are components selected translate their control points. // If there are components selected translate their control points.
translateSelection(point); translateSelection(dragStartPoint, point);
if (!oldProject.equals(currentProject)) { if (!oldProject.equals(currentProject)) {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
.deepClone(currentProject), "Move"); .deepClone(currentProject), "Move");
@@ -500,9 +500,13 @@ public class Presenter implements IPlugInPort {
dragInProgress = false; dragInProgress = false;
} }
private void translateSelection(Point toPoint) { private void translateSelection(Point fromPoint, Point toPoint) {
int dx = (int) ((toPoint.x - dragStartPoint.x) / zoomLevel); if (toPoint == null) {
int dy = (int) ((toPoint.y - dragStartPoint.y) / zoomLevel); LOG.debug("Drag ended outside the drawing area.");
return;
}
int dx = (int) ((toPoint.x - fromPoint.x) / zoomLevel);
int dy = (int) ((toPoint.y - fromPoint.y) / zoomLevel);
for (IComponentInstance component : selectedComponents) { for (IComponentInstance component : selectedComponents) {
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance() List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
.extractControlPoints(component.getClass()); .extractControlPoints(component.getClass());