Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Location


    double rotate = 0.0;
    if (facing != defaultFacing && g instanceof Graphics2D) {
      rotate = defaultFacing.toRadians() - facing.toRadians();
      ((Graphics2D) g).rotate(rotate);
    }
    Location offset = findAnchorLocation();
    g.translate(-offset.getX(), -offset.getY());
    for (CanvasObject shape : getObjectsFromBottom()) {
      if (!(shape instanceof AppearanceElement)) {
        Graphics dup = g.create();
        shape.paint(dup, null);
        dup.dispose();
      }
    }
    g.translate(offset.getX(), offset.getY());
    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
  }
View Full Code Here


    return getBounds(false);
  }
 
  private Bounds getBounds(boolean relativeToAnchor) {
    Bounds ret = null;
    Location offset = null;
    for (CanvasObject o : getObjectsFromBottom()) {
      if (o instanceof AppearanceElement) {
        Location loc = ((AppearanceElement) o).getLocation();
        if (o instanceof AppearanceAnchor) {
          offset = loc;
        }
        if (ret == null) {
          ret = Bounds.create(loc);
View Full Code Here

      return ret;
    }
  }
 
  public SortedMap<Location, Instance> getPortOffsets(Direction facing) {
    Location anchor = null;
    Direction defaultFacing = Direction.EAST;
    List<AppearancePort> ports = new ArrayList<AppearancePort>();
    for (CanvasObject shape : getObjectsFromBottom()) {
      if (shape instanceof AppearancePort) {
        ports.add((AppearancePort) shape);
      } else if (shape instanceof AppearanceAnchor) {
        AppearanceAnchor o = (AppearanceAnchor) shape;
        anchor = o.getLocation();
        defaultFacing = o.getFacing();
      }
    }

    SortedMap<Location, Instance> ret = new TreeMap<Location, Instance>();
    for (AppearancePort port : ports) {
      Location loc = port.getLocation();
      if (anchor != null) {
        loc = loc.translate(-anchor.getX(), -anchor.getY());
      }
      if (facing != defaultFacing) {
        loc = loc.rotate(defaultFacing, facing, 0, 0);
      }
      ret.put(loc, port.getPin());
    }
    return ret;
  }
View Full Code Here

    }
  }
 
  private void configureLabel(Instance instance) {
    TextAttributes attrs = (TextAttributes) instance.getAttributeSet();
    Location loc = instance.getLocation();
    instance.setTextField(ATTR_TEXT, ATTR_FONT, loc.getX(), loc.getY(),
        attrs.getHorizontalAlign(), attrs.getVerticalAlign());
  }     
View Full Code Here

          x1 += x0;
          y1 += y0;
          x2 += x0;
          y2 += y0;
        }
        Location e0 = Location.create(x0, y0);
        Location e1 = Location.create(x2, y2);
        Location ct = Location.create(x1, y1);
        return new Curve(e0, e1, ct);
      } else {
        throw new NumberFormatException("Unexpected format for curve");
      }
    } else {
View Full Code Here

    int mods = e.getModifiersEx();
    if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
      x = canvas.snapX(x);
      y = canvas.snapY(y);
    }
    Location loc = Location.create(x, y);
    mouseStart = loc;
    mouseEnd = loc;
    lastMouseX = loc.getX();
    lastMouseY = loc.getY();
    active = canvas.getModel() != null;
    repaintArea(canvas);
  }
View Full Code Here

 
  @Override
  public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
      updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
      Location start = mouseStart;
      Location end = mouseEnd;
      CanvasObject add = null;
      if (!start.equals(end)) {
        active = false;
        CanvasModel model = canvas.getModel();
        Location[] ends = { start, end };
View Full Code Here

  }
 
  private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    if (active) {
      boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
      Location newEnd;
      if (shift) {
        newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
      } else {
        newEnd = Location.create(mx, my);
      }
     
      if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        int x = newEnd.getX();
        int y = newEnd.getY();
        x = canvas.snapX(x);
        y = canvas.snapY(y);
        newEnd = Location.create(x, y);
      }
     
      if (!newEnd.equals(mouseEnd)) {
        mouseEnd = newEnd;
        repaintArea(canvas);
      }
    }
    lastMouseX = mx;
View Full Code Here

  }
 
  @Override
  public void draw(Canvas canvas, Graphics g) {
    if (active) {
      Location start = mouseStart;
      Location end = mouseEnd;
      g.setColor(Color.GRAY);
      g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
    }
  }
View Full Code Here

      int gy = g.getY() + gesture.getDeltaY();
      Handle[] ret = { new Handle(this, p0), new Handle(this, p1),
          new Handle(this, p2) };
      if (g.isAt(p0)) {
        if (gesture.isShiftDown()) {
          Location p = LineUtil.snapTo8Cardinals(p2, gx, gy);
          ret[0] = new Handle(this, p);
        } else {
          ret[0] = new Handle(this, gx, gy);
        }
      } else if (g.isAt(p2)) {
        if (gesture.isShiftDown()) {
          Location p = LineUtil.snapTo8Cardinals(p0, gx, gy);
          ret[2] = new Handle(this, p);
        } else {
          ret[2] = new Handle(this, gx, gy);
        }
      } else if (g.isAt(p1)) {
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Location

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.