Examples of CanvasObject


Examples of com.cburch.draw.model.CanvasObject

    int n = sel.getSelected().size();
    List<CanvasObject> select = new ArrayList<CanvasObject>(n);
    List<CanvasObject> clones = new ArrayList<CanvasObject>(n);
    for (CanvasObject o : sel.getSelected()) {
      if (o.canRemove()) {
        CanvasObject copy = o.clone();
        copy.translate(10, 10);
        clones.add(copy);
        select.add(copy);
      } else {
        select.add(o);
      }
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

  @Override
  public String getTitle() {
    Selection sel = canvas.getSelection();
    Class<? extends CanvasObject> commonClass = null;
    int commonCount = 0;
    CanvasObject firstObject = null;
    int totalCount = 0;
    for (CanvasObject obj : sel.getSelected()) {
      if (firstObject == null) {
        firstObject = obj;
        commonClass = obj.getClass();
        commonCount = 1;
      } else if (obj.getClass() == commonClass) {
        commonCount++;
      } else {
        commonClass = null;
      }
      totalCount++;
    }
   
    if (firstObject == null) {
      return null;
    } else if (commonClass == null) {
      return Strings.get("selectionVarious", "" + totalCount);
    } else if (commonCount == 1) {
      return Strings.get("selectionOne", firstObject.getDisplayName());
    } else {
      return Strings.get("selectionMultiple", firstObject.getDisplayName(),
          "" + commonCount);
    }
  }
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

public class Main {
  public static void main(String[] args) {
    DrawingAttributeSet attrs = new DrawingAttributeSet();
    Drawing model = new Drawing();
    CanvasObject rect = attrs.applyTo(new Rectangle(25, 25, 50, 50));
    model.addObjects(0, Collections.singleton(rect));

    showFrame(model, "Drawing 1");
    showFrame(model, "Drawing 2");
  }
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

        if (active) {
            Bounds oldBounds = currentBounds;
            Bounds bds = computeBounds(canvas, e.getX(), e.getY(), e.getModifiersEx());
            currentBounds = Bounds.EMPTY_BOUNDS;
            active = false;
            CanvasObject add = null;
            if (bds.getWidth() != 0 && bds.getHeight() != 0) {
                CanvasModel model = canvas.getModel();
                add = createShape(bds.getX(), bds.getY(),
                        bds.getWidth(), bds.getHeight());
                canvas.doAction(new ModelAddAction(model, add));
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

    }

    private void handlePopupTrigger(MouseEvent e) {
        Location loc = Location.create(e.getX(), e.getY());
        List<CanvasObject> objects = canvas.getModel().getObjectsFromTop();
        CanvasObject clicked = null;
        for (CanvasObject o : objects) {
            if (o.contains(loc, false)) {
                clicked = o;
                break;
            }
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

        Selection selection = canvas.getSelection();
        selection.setHandleSelected(null);

        // see whether user is pressing within an existing handle
        int halfSize = getHandleSize(canvas) / 2;
        CanvasObject clicked = null;
        for (CanvasObject shape : selection.getSelected()) {
            List<Handle> handles = shape.getHandles(null);
            for (Handle han : handles) {
                int dx = han.getX() - mx;
                int dy = han.getY() - my;
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

        int action = curAction;
        curAction = IDLE;

        if (!dragEffective) {
            Location loc = dragEnd;
            CanvasObject o = getObjectAt(model, loc.getX(), loc.getY(), false);
            if (o != null) {
                Handle han = o.canDeleteHandle(loc);
                if (han != null) {
                    selection.setHandleSelected(han);
                } else {
                    han = o.canInsertHandle(loc);
                    if (han != null) {
                        selection.setHandleSelected(han);
                    }
                }
            }
        }

        Location start = dragStart;
        int x1 = e.getX();
        int y1 = e.getY();
        switch (action) {
        case MOVE_ALL:
            Location moveDelta = selection.getMovingDelta();
            if (dragEffective && !moveDelta.equals(Location.create(0, 0))) {
                canvas.doAction(new ModelTranslateAction(model, selected,
                        moveDelta.getX(), moveDelta.getY()));
            }
            break;
        case MOVE_HANDLE:
            HandleGesture gesture = curGesture;
            curGesture = null;
            if (dragEffective && gesture != null) {
                ModelMoveHandleAction act;
                act = new ModelMoveHandleAction(model, gesture);
                canvas.doAction(act);
                Handle result = act.getNewHandle();
                if (result != null) {
                    Handle h = result.getObject().canDeleteHandle(result.getLocation());
                    selection.setHandleSelected(h);
                }
            }
            break;
        case RECT_SELECT:
            if (dragEffective) {
                Bounds bds = Bounds.create(start).add(x1, y1);
                selection.setSelected(canvas.getModel().getObjectsIn(bds), true);
            } else {
                CanvasObject clicked;
                clicked = getObjectAt(model, start.getX(), start.getY(), true);
                if (clicked != null) {
                    selection.clearSelected();
                    selection.setSelected(clicked, true);
                }
            }
            break;
        case RECT_TOGGLE:
            if (dragEffective) {
                Bounds bds = Bounds.create(start).add(x1, y1);
                selection.toggleSelected(canvas.getModel().getObjectsIn(bds));
            } else {
                CanvasObject clicked;
                clicked = getObjectAt(model, start.getX(), start.getY(), true);
                selection.setSelected(clicked, !selected.contains(clicked));
            }
            break;
        default:
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

            break;
        default:
            drawHandles = true;
        }

        CanvasObject moveHandleObj = null;
        if (gesture != null) moveHandleObj = gesture.getHandle().getObject();
        if (drawHandles) {
            // unscale the coordinate system so that the stroke width isn't scaled
            double zoom = 1.0;
            Graphics gCopy = g.create();
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

        List<CanvasObject> shapes = new ArrayList<CanvasObject>(shapesBase);
        int n = shapes.size();
        int ports = 0;
        // count ports, move anchor to end
        for (int i = n - 1; i >= 0; i--) {
            CanvasObject o = shapes.get(i);
            if (o instanceof AppearanceAnchor) {
                if (i != n - 1) {
                    shapes.remove(i);
                    shapes.add(o);
                }
            } else if (o instanceof AppearancePort) {
                ports++;
            }
        }
        // move ports to top
        for (int i = (n - ports - 1) - 1; i >= 0; i--) {
            CanvasObject o = shapes.get(i);
            if (o instanceof AppearancePort) {
                shapes.remove(i);
                shapes.add(n - ports - 1, o);
                i--;
            }
View Full Code Here

Examples of com.cburch.draw.model.CanvasObject

public class Main {
    public static void main(String[] args) {
        DrawingAttributeSet attrs = new DrawingAttributeSet();
        Drawing model = new Drawing();
        CanvasObject rect = attrs.applyTo(new Rectangle(25, 25, 50, 50));
        model.addObjects(0, Collections.singleton(rect));

        showFrame(model, "Drawing 1");
        showFrame(model, "Drawing 2");
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.