Package com.cburch.draw.canvas

Examples of com.cburch.draw.canvas.Selection


    canvas.doAction(new ModelInsertHandleAction(canvas.getModel(), handle));
  }
 
  @Override
  public void removeControlPoint() {
    Selection sel = canvas.getSelection();
    Handle handle = sel.getSelectedHandle();
    canvas.doAction(new ModelDeleteHandleAction(canvas.getModel(), handle));
  }
View Full Code Here


    return displayName.get();
  }
 
  @Override
  public void doIt(Project proj) {
    Selection sel = canvas.getSelection();
    sel.clearSelected();
    if (toRemove != null) canvasModel.removeObjects(toRemove.keySet());
    int dest = AppearanceCanvas.getMaxIndex(canvasModel) + 1;
    if (toAdd != null) canvasModel.addObjects(dest, toAdd);

    AppearanceAnchor anchor = findAnchor(canvasModel);
    if (anchor != null && anchorNewLocation != null) {
      anchorOldLocation = anchor.getLocation();
      anchor.translate(anchorNewLocation.getX() - anchorOldLocation.getX(),
          anchorNewLocation.getY() - anchorOldLocation.getY());
    }
    if (anchor != null && anchorNewFacing != null) {
      anchorOldFacing = anchor.getFacing();
      anchor.setValue(AppearanceAnchor.FACING, anchorNewFacing);
    }
    sel.setSelected(newSelection, true);
    canvas.repaint();
  }
View Full Code Here

          anchorOldLocation.getY() - anchorNewLocation.getY());
    }
    if (anchor != null && anchorOldFacing != null) {
      anchor.setValue(AppearanceAnchor.FACING, anchorOldFacing);
    }
    Selection sel = canvas.getSelection();
    sel.clearSelected();
    if (toAdd != null) canvasModel.removeObjects(toAdd);
    if (toRemove != null) canvasModel.addObjects(toRemove);
    sel.setSelected(oldSelection, true);
    canvas.repaint();
  }
View Full Code Here

 
  @Override
  public void computeEnabled() {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    Selection sel = canvas.getSelection();
    boolean selEmpty = sel.isEmpty();
    boolean canChange = proj.getLogisimFile().contains(circ);
    boolean clipExists = !Clipboard.isEmpty();
    boolean selHasRemovable = false;
    for (CanvasObject o : sel.getSelected()) {
      if (!(o instanceof AppearanceElement)) {
        selHasRemovable = true;
      }
    }
    boolean canRaise;
    boolean canLower;
    if (!selEmpty && canChange) {
      Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(),
          canvas.getModel());
      int zmin = Integer.MAX_VALUE;
      int zmax = Integer.MIN_VALUE;
      int count = 0;
      for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
        if (!(entry.getKey() instanceof AppearanceElement)) {
          count++;
          int z = entry.getValue().intValue();
          if (z < zmin) zmin = z;
          if (z > zmax) zmax = z;
        }
      }
      int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
      if (count > 0 && count <= maxPoss) {
        canRaise = zmin <= maxPoss - count;
        canLower = zmax >= count;
      } else {
        canRaise = false;
        canLower = false;
      }
    } else {
      canRaise = false;
      canLower = false;
    }
    boolean canAddCtrl = false;
    boolean canRemCtrl = false;
    Handle handle = sel.getSelectedHandle();
    if (handle != null && canChange) {
      CanvasObject o = handle.getObject();
      canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
      canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
    }
View Full Code Here

        dragStart = Location.create(mx, my);
        dragEffective = false;
        dragEnd = dragStart;
        lastMouseX = mx;
        lastMouseY = my;
        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;
                if (dx >= -halfSize && dx <= halfSize
                        && dy >= -halfSize && dy <= halfSize) {
                    if (shape.canMoveHandle(han)) {
                        curAction = MOVE_HANDLE;
                        curGesture = new HandleGesture(han, 0, 0,
                                e.getModifiersEx());
                        repaintArea(canvas);
                        return;
                    } else if (clicked == null) {
                        clicked = shape;
                    }
                }
            }
        }

        // see whether the user is clicking within a shape
        if (clicked == null) {
            clicked = getObjectAt(canvas.getModel(), e.getX(), e.getY(), false);
        }
        if (clicked != null) {
            if (shift && selection.isSelected(clicked)) {
                selection.setSelected(clicked, false);
                curAction = IDLE;
            } else {
                if (!shift && !selection.isSelected(clicked)) {
                    selection.clearSelected();
                }
                selection.setSelected(clicked, true);
                selection.setMovingShapes(selection.getSelected(), 0, 0);
                curAction = MOVE_ALL;
            }
            repaintArea(canvas);
            return;
        }

        clicked = getObjectAt(canvas.getModel(), e.getX(), e.getY(), true);
        if (clicked != null && selection.isSelected(clicked)) {
            if (shift) {
                selection.setSelected(clicked, false);
                curAction = IDLE;
            } else {
                selection.setMovingShapes(selection.getSelected(), 0, 0);
                curAction = MOVE_ALL;
            }
            repaintArea(canvas);
            return;
        }

        if (shift) {
            curAction = RECT_TOGGLE;
        } else {
            selection.clearSelected();
            curAction = RECT_SELECT;
        }
        repaintArea(canvas);
    }
View Full Code Here

        Handle handle = beforePressHandle;
        beforePressSelection = null;
        beforePressHandle = null;
        if (before != null) {
            curAction = IDLE;
            Selection sel = canvas.getSelection();
            sel.clearDrawsSuppressed();
            sel.setMovingShapes(Collections.<CanvasObject>emptySet(), 0, 0);
            sel.clearSelected();
            sel.setSelected(before, true);
            sel.setHandleSelected(handle);
            repaintArea(canvas);
        }
    }
View Full Code Here

        beforePressSelection = null;
        beforePressHandle = null;
        setMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());

        CanvasModel model = canvas.getModel();
        Selection selection = canvas.getSelection();
        Set<CanvasObject> selected = selection.getSelected();
        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:
          break;
        }
        selection.clearDrawsSuppressed();
        repaintArea(canvas);
    }
View Full Code Here

    }

    @Override
    public void keyTyped(Canvas canvas, KeyEvent e) {
        char ch = e.getKeyChar();
        Selection selected = canvas.getSelection();
        if ((ch == '\u0008' || ch == '\u007F') && !selected.isEmpty()) {
            ArrayList<CanvasObject> toRemove = new ArrayList<CanvasObject>();
            for (CanvasObject shape : selected.getSelected()) {
                if (shape.canRemove()) {
                    toRemove.add(shape);
                }
            }
            if (!toRemove.isEmpty()) {
                e.consume();
                CanvasModel model = canvas.getModel();
                canvas.doAction(new ModelRemoveAction(model, toRemove));
                selected.clearSelected();
                repaintArea(canvas);
            }
        } else if (ch == '\u001b' && !selected.isEmpty()) {
            selected.clearSelected();
            repaintArea(canvas);
        }
    }
View Full Code Here

        canvas.repaint();
    }

    @Override
    public void draw(Canvas canvas, Graphics g) {
        Selection selection = canvas.getSelection();
        int action = curAction;

        Location start = dragStart;
        Location end = dragEnd;
        HandleGesture gesture = null;
        boolean drawHandles;
        switch (action) {
        case MOVE_ALL:
            drawHandles = !dragEffective;
            break;
        case MOVE_HANDLE:
            drawHandles = !dragEffective;
            if (dragEffective) gesture = curGesture;
            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();
            if (gCopy instanceof Graphics2D) {
                zoom = canvas.getZoomFactor();
                if (zoom != 1.0) {
                    ((Graphics2D) gCopy).scale(1.0 / zoom, 1.0 / zoom);
                }
            }
            GraphicsUtil.switchToWidth(gCopy, 1);

            int size = (int) Math.ceil(HANDLE_SIZE * Math.sqrt(zoom));
            int offs = size / 2;
            for (CanvasObject obj : selection.getSelected()) {
                List<Handle> handles;
                if (action == MOVE_HANDLE && obj == moveHandleObj) {
                    handles = obj.getHandles(gesture);
                } else {
                    handles = obj.getHandles(null);
                }
                for (Handle han : handles) {
                    int x = han.getX();
                    int y = han.getY();
                    if (action == MOVE_ALL && dragEffective) {
                        Location delta = selection.getMovingDelta();
                        x += delta.getX();
                        y += delta.getY();
                    }
                    x = (int) Math.round(zoom * x);
                    y = (int) Math.round(zoom * y);
                    gCopy.clearRect(x - offs, y - offs, size, size);
                    gCopy.drawRect(x - offs, y - offs, size, size);
                }
            }
            Handle selHandle = selection.getSelectedHandle();
            if (selHandle != null) {
                int x = selHandle.getX();
                int y = selHandle.getY();
                if (action == MOVE_ALL && dragEffective) {
                    Location delta = selection.getMovingDelta();
                    x += delta.getX();
                    y += delta.getY();
                }
                x = (int) Math.round(zoom * x);
                y = (int) Math.round(zoom * y);
 
View Full Code Here

        canvas.getSelection().addSelectionListener(this);
    }

    @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) {
View Full Code Here

TOP

Related Classes of com.cburch.draw.canvas.Selection

Copyright © 2018 www.massapicom. 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.