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
@@ -110,15 +110,19 @@ class CanvasPanel extends JComponent implements Autoscroll {
createBufferImage();
}
do {
if (bufferImage.contentsLost()) {
createBufferImage();
try {
if (bufferImage.contentsLost()) {
createBufferImage();
}
int validation = bufferImage.validate(screenGraphicsConfiguration);
if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
createBufferImage();
}
g.drawImage(bufferImage, 0, 0, this);
} catch (NullPointerException e) {
// Do nothing, it will be recreated in the next pass.
}
int validation = bufferImage.validate(screenGraphicsConfiguration);
if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
createBufferImage();
}
g.drawImage(bufferImage, 0, 0, this);
} while (bufferImage.contentsLost());
} while (bufferImage == null || bufferImage.contentsLost());
}
@Override
@@ -6,6 +6,8 @@ import java.util.EnumSet;
import javax.swing.SwingConstants;
import org.apache.log4j.Logger;
import com.diyfever.diylc.common.BadPositionException;
import com.diyfever.diylc.common.EventType;
import com.diyfever.diylc.common.IPlugIn;
@@ -17,7 +19,7 @@ import com.diyfever.gui.ruler.RulerScrollPane;
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";
@@ -35,7 +37,7 @@ public class CanvasPlugin implements IPlugIn {
try {
plugInPort.injectGUIComponent(getScrollPane(), SwingConstants.CENTER);
} 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);
} else {
// If there are components selected translate their control points.
translateSelection(point);
translateSelection(dragStartPoint, point);
dragStartPoint = point;
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
@@ -490,7 +490,7 @@ public class Presenter implements IPlugInPort {
Project oldProject = cloner.deepClone(currentProject);
// If there are components selected translate their control points.
translateSelection(point);
translateSelection(dragStartPoint, point);
if (!oldProject.equals(currentProject)) {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
.deepClone(currentProject), "Move");
@@ -500,9 +500,13 @@ public class Presenter implements IPlugInPort {
dragInProgress = false;
}
private void translateSelection(Point toPoint) {
int dx = (int) ((toPoint.x - dragStartPoint.x) / zoomLevel);
int dy = (int) ((toPoint.y - dragStartPoint.y) / zoomLevel);
private void translateSelection(Point fromPoint, Point toPoint) {
if (toPoint == null) {
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) {
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
.extractControlPoints(component.getClass());