mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
auto-gc
This commit is contained in:
Binary file not shown.
+3
@@ -126,6 +126,9 @@ public class ResistorInstance implements IComponentInstance {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState) {
|
||||
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
|
||||
g2d.setStroke(new BasicStroke(2));
|
||||
if (componentState == ComponentState.DRAGGING) {
|
||||
g2d.setStroke(new BasicStroke(1));
|
||||
}
|
||||
g2d.drawLine(leftTopCorner.x, leftTopCorner.y, otherCorner.x, otherCorner.y);
|
||||
g2d.fillRect((leftTopCorner.x + otherCorner.x) / 2 - 10,
|
||||
(leftTopCorner.y + otherCorner.y) / 2 - 10, 20, 20);
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ package com.diyfever.diylc.model;
|
||||
*/
|
||||
public enum ComponentState {
|
||||
|
||||
NORMAL, SELECTED, LOCKED
|
||||
NORMAL, SELECTED, LOCKED, DRAGGING
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
|
||||
private MemoryBar getMemoryPanel() {
|
||||
if (memoryPanel == null) {
|
||||
memoryPanel = new MemoryBar();
|
||||
memoryPanel = new MemoryBar(true);
|
||||
}
|
||||
return memoryPanel;
|
||||
}
|
||||
|
||||
-210
@@ -85,399 +85,258 @@ class G2DWrapper extends Graphics2D {
|
||||
currentArea.add(new Area(s));
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void addRenderingHints(Map<?, ?> hints) {
|
||||
canvasGraphics.addRenderingHints(hints);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void clip(Shape s) {
|
||||
canvasGraphics.clip(s);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void draw(Shape s) {
|
||||
canvasGraphics.draw(s);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawGlyphVector(GlyphVector g, float x, float y) {
|
||||
canvasGraphics.drawGlyphVector(g, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
|
||||
// FIXME: process map
|
||||
return canvasGraphics.drawImage(img, xform, obs);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
|
||||
canvasGraphics.drawImage(img, op, x, y);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
|
||||
canvasGraphics.drawRenderableImage(img, xform);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
|
||||
canvasGraphics.drawRenderedImage(img, xform);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawString(String str, int x, int y) {
|
||||
canvasGraphics.drawString(str, x, y);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawString(String str, float x, float y) {
|
||||
canvasGraphics.drawString(str, x, y);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawString(AttributedCharacterIterator iterator, int x, int y) {
|
||||
canvasGraphics.drawString(iterator, x, y);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
|
||||
canvasGraphics.drawString(iterator, x, y);
|
||||
// FIXME: process map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void fill(Shape s) {
|
||||
canvasGraphics.fill(s);
|
||||
appendShape(s);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Color getBackground() {
|
||||
return canvasGraphics.getBackground();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Composite getComposite() {
|
||||
return canvasGraphics.getComposite();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public GraphicsConfiguration getDeviceConfiguration() {
|
||||
return canvasGraphics.getDeviceConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public FontRenderContext getFontRenderContext() {
|
||||
return canvasGraphics.getFontRenderContext();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Paint getPaint() {
|
||||
return canvasGraphics.getPaint();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Object getRenderingHint(Key hintKey) {
|
||||
return canvasGraphics.getRenderingHint(hintKey);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public RenderingHints getRenderingHints() {
|
||||
return canvasGraphics.getRenderingHints();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Stroke getStroke() {
|
||||
return canvasGraphics.getStroke();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public AffineTransform getTransform() {
|
||||
return canvasGraphics.getTransform();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
|
||||
return canvasGraphics.hit(rect, s, onStroke);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void rotate(double theta) {
|
||||
canvasGraphics.rotate(theta);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void rotate(double theta, double x, double y) {
|
||||
canvasGraphics.rotate(theta, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void scale(double sx, double sy) {
|
||||
canvasGraphics.scale(sx, sy);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setBackground(Color color) {
|
||||
canvasGraphics.setBackground(color);
|
||||
// FIXME: fix map
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setComposite(Composite comp) {
|
||||
canvasGraphics.setComposite(comp);
|
||||
// FIXME: check this.
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setPaint(Paint paint) {
|
||||
canvasGraphics.setPaint(paint);
|
||||
// FIXME: check this
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setRenderingHint(Key hintKey, Object hintValue) {
|
||||
canvasGraphics.setRenderingHint(hintKey, hintValue);
|
||||
// FIXME: check this
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setRenderingHints(Map<?, ?> hints) {
|
||||
canvasGraphics.setRenderingHints(hints);
|
||||
// FIXME: check this
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setStroke(Stroke s) {
|
||||
canvasGraphics.setStroke(s);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setTransform(AffineTransform Tx) {
|
||||
canvasGraphics.setTransform(Tx);
|
||||
currentTx = Tx;
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void shear(double shx, double shy) {
|
||||
canvasGraphics.shear(shx, shy);
|
||||
currentTx.shear(shx, shy);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void transform(AffineTransform Tx) {
|
||||
canvasGraphics.transform(Tx);
|
||||
currentTx.concatenate(Tx);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void translate(int x, int y) {
|
||||
canvasGraphics.translate(x, y);
|
||||
currentTx.translate(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void translate(double tx, double ty) {
|
||||
canvasGraphics.translate(tx, ty);
|
||||
currentTx.translate(tx, ty);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void clearRect(int x, int y, int width, int height) {
|
||||
canvasGraphics.clearRect(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void clipRect(int x, int y, int width, int height) {
|
||||
canvasGraphics.clipRect(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
|
||||
canvasGraphics.copyArea(x, y, width, height, dx, dy);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Graphics create() {
|
||||
return canvasGraphics.create();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void dispose() {
|
||||
canvasGraphics.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
|
||||
canvasGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
|
||||
// FIXME: map
|
||||
return canvasGraphics.drawImage(img, x, y, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
|
||||
// FIXME: map
|
||||
return canvasGraphics.drawImage(img, x, y, bgcolor, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
|
||||
// FIXME: map
|
||||
return canvasGraphics.drawImage(img, x, y, width, height, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor,
|
||||
ImageObserver observer) {
|
||||
@@ -485,9 +344,6 @@ class G2DWrapper extends Graphics2D {
|
||||
return canvasGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
|
||||
int sx2, int sy2, ImageObserver observer) {
|
||||
@@ -495,9 +351,6 @@ class G2DWrapper extends Graphics2D {
|
||||
return canvasGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
|
||||
int sx2, int sy2, Color bgcolor, ImageObserver observer) {
|
||||
@@ -505,174 +358,111 @@ class G2DWrapper extends Graphics2D {
|
||||
return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawLine(int x1, int y1, int x2, int y2) {
|
||||
canvasGraphics.drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawOval(int x, int y, int width, int height) {
|
||||
canvasGraphics.drawOval(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawPolygon(int[] points, int[] points2, int points3) {
|
||||
canvasGraphics.drawPolygon(points, points2, points3);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawPolyline(int[] points, int[] points2, int points3) {
|
||||
canvasGraphics.drawPolyline(points, points2, points3);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
|
||||
canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
|
||||
canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
|
||||
appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE));
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void fillOval(int x, int y, int width, int height) {
|
||||
canvasGraphics.fillOval(x, y, width, height);
|
||||
appendShape(new Ellipse2D.Double(x, y, width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void fillPolygon(int[] points, int[] points2, int points3) {
|
||||
canvasGraphics.fillPolygon(points, points2, points3);
|
||||
appendShape(new Polygon(points, points2, points3));
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void fillRect(int x, int y, int width, int height) {
|
||||
canvasGraphics.fillRect(x, y, width, height);
|
||||
appendShape(new Rectangle(x, y, width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
|
||||
canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
|
||||
appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Shape getClip() {
|
||||
return canvasGraphics.getClip();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Rectangle getClipBounds() {
|
||||
return canvasGraphics.getClipBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return canvasGraphics.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public Font getFont() {
|
||||
return canvasGraphics.getFont();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public FontMetrics getFontMetrics(Font f) {
|
||||
return canvasGraphics.getFontMetrics(f);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setClip(Shape clip) {
|
||||
canvasGraphics.setClip(clip);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setClip(int x, int y, int width, int height) {
|
||||
canvasGraphics.setClip(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setColor(Color c) {
|
||||
canvasGraphics.setColor(c);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setFont(Font font) {
|
||||
canvasGraphics.setFont(font);
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setPaintMode() {
|
||||
canvasGraphics.setPaintMode();
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
**/
|
||||
@Override
|
||||
public void setXORMode(Color c1) {
|
||||
canvasGraphics.setXORMode(c1);
|
||||
|
||||
+57
-20
@@ -1,7 +1,9 @@
|
||||
package com.diyfever.diylc.presenter;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -233,6 +235,9 @@ public class Presenter implements IPlugInPort {
|
||||
g2dWrapper.scale(zoomLevel, zoomLevel);
|
||||
}
|
||||
|
||||
Composite mainComposite = g2d.getComposite();
|
||||
Composite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
|
||||
|
||||
g2dWrapper.resetTx();
|
||||
|
||||
List<IComponentInstance> components = getCurrentProject().getComponents();
|
||||
@@ -240,10 +245,26 @@ public class Presenter implements IPlugInPort {
|
||||
if (components != null) {
|
||||
for (IComponentInstance component : components) {
|
||||
g2dWrapper.startedDrawingComponent();
|
||||
ComponentState state = (selectedComponents.contains(component) && drawOptions
|
||||
.contains(DrawOption.SELECTION)) ? ComponentState.SELECTED
|
||||
: ComponentState.NORMAL;
|
||||
ComponentState state = ComponentState.NORMAL;
|
||||
if (drawOptions.contains(DrawOption.SELECTION)
|
||||
&& selectedComponents.contains(component)) {
|
||||
if (dragInProgress) {
|
||||
state = ComponentState.DRAGGING;
|
||||
} else {
|
||||
state = ComponentState.SELECTED;
|
||||
}
|
||||
}
|
||||
// If the component is being dragged, draw it in a separate
|
||||
// composite.
|
||||
if (state == ComponentState.DRAGGING) {
|
||||
g2dWrapper.setComposite(alphaComposite);
|
||||
}
|
||||
// Draw the component through the g2dWrapper.
|
||||
component.draw(g2dWrapper, state);
|
||||
// Restore the composite if needed.
|
||||
if (state == ComponentState.DRAGGING) {
|
||||
g2dWrapper.setComposite(mainComposite);
|
||||
}
|
||||
componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent());
|
||||
|
||||
// Draw control points
|
||||
@@ -404,12 +425,15 @@ public class Presenter implements IPlugInPort {
|
||||
dragStartPoint = point;
|
||||
Point scaledPoint = scalePoint(point);
|
||||
List<IComponentInstance> components = findComponentsAt(scaledPoint);
|
||||
// If no components are under the cursor, reset selection.
|
||||
if (components.isEmpty()) {
|
||||
selectedComponents.clear();
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
} else {
|
||||
IComponentInstance component = components.get(0);
|
||||
// If the component under the cursor is not already selected, make
|
||||
// it into the only selected component.
|
||||
if (!selectedComponents.contains(component)) {
|
||||
selectedComponents.clear();
|
||||
selectedComponents.add(component);
|
||||
@@ -421,10 +445,17 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public boolean dragOver(Point point) {
|
||||
// If there's no selection, the only thing to do is update the selection
|
||||
// rectangle and refresh.
|
||||
if (selectedComponents.isEmpty()) {
|
||||
this.selectionRect = Utils.createRectangle(point, dragStartPoint);
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED, selectionRect);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
} else {
|
||||
// If there are components selected translate their control points.
|
||||
translateSelection(point);
|
||||
dragStartPoint = point;
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -454,26 +485,12 @@ public class Presenter implements IPlugInPort {
|
||||
selectionRect = null;
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||
} else {
|
||||
// There is selection, so we need to finalize the drag&drop
|
||||
// operation.
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
|
||||
// If there are components selected translate their control points.
|
||||
int dx = (int) ((point.x - dragStartPoint.x) / zoomLevel);
|
||||
int dy = (int) ((point.y - dragStartPoint.y) / zoomLevel);
|
||||
for (IComponentInstance component : selectedComponents) {
|
||||
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||
.extractControlPoints(component.getClass());
|
||||
for (ControlPointWrapper controlPoint : controlPoints) {
|
||||
try {
|
||||
controlPoint.readFrom(component);
|
||||
if (controlPoint.isEditable()) {
|
||||
controlPoint.getValue().translate(dx, dy);
|
||||
}
|
||||
controlPoint.writeTo(component);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not translate control points: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
translateSelection(point);
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Move");
|
||||
@@ -483,6 +500,26 @@ 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);
|
||||
for (IComponentInstance component : selectedComponents) {
|
||||
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||
.extractControlPoints(component.getClass());
|
||||
for (ControlPointWrapper controlPoint : controlPoints) {
|
||||
try {
|
||||
controlPoint.readFrom(component);
|
||||
if (controlPoint.isEditable()) {
|
||||
controlPoint.getValue().translate(dx, dy);
|
||||
}
|
||||
controlPoint.writeTo(component);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not translate control points: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addComponents(List<IComponentInstance> components, Point preferredPoint) {
|
||||
LOG.debug(String.format("addComponents(%s)", components));
|
||||
|
||||
Reference in New Issue
Block a user