Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Location


      g.setColor(Color.GRAY);
      int size = locations.size();
      int[] xs = new int[size];
      int[] ys = new int[size];
      for(int i = 0; i < size; i++) {
        Location loc = locations.get(i);
        xs[i] = loc.getX();
        ys[i] = loc.getY();
      }
      g.drawPolyline(xs, ys, size);
      int lastX = xs[xs.length - 1];
      int lastY = ys[ys.length - 1];
      g.fillOval(lastX - 2, lastY - 2, 4, 4);
View Full Code Here


    return elt;
  }
 
  public static Element createLine(Document doc, Line line) {
    Element elt = doc.createElement("line");
    Location v1 = line.getEnd0();
    Location v2 = line.getEnd1();
    elt.setAttribute("x1", "" + v1.getX());
    elt.setAttribute("y1", "" + v1.getY());
    elt.setAttribute("x2", "" + v2.getX());
    elt.setAttribute("y2", "" + v2.getY());
    populateStroke(elt, line);
    return elt;
  }
View Full Code Here

    return elt;
  }
 
  public static Element createCurve(Document doc, Curve curve) {
    Element elt = doc.createElement("path");
    Location e0 = curve.getEnd0();
    Location e1 = curve.getEnd1();
    Location ct = curve.getControl();
    elt.setAttribute("d", "M" + e0.getX() + "," + e0.getY()
        + " Q" + ct.getX() + "," + ct.getY()
        + " " + e1.getX() + "," + e1.getY());
    populateFill(elt, curve);
    return elt;
  }
View Full Code Here

    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Port[] ps = new Port[outputs + (enable ? 3 : 2)];
    Location sel;
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    if (outputs == 2) {
      Location end0;
      Location end1;
      if (facing == Direction.WEST) {
        end0 = Location.create(-30, -10);
        end1 = Location.create(-3010);
        sel = Location.create(-20,  selMult * 20);
      } else if (facing == Direction.NORTH) {
        end0 = Location.create(-10, -30);
        end1 = Location.create( 10, -30);
        sel = Location.create(selMult * -20, -20);
      } else if (facing == Direction.SOUTH) {
        end0 = Location.create(-1030);
        end1 = Location.create( 1030);
        sel = Location.create(selMult * -2020);
      } else {
        end0 = Location.create(30, -10);
        end1 = Location.create(3010);
        sel = Location.create(20,  selMult * 20);
      }
      ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, data.getWidth());
      ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, data.getWidth());
    } else {
      int dx = -(outputs / 2) * 10;
      int ddx = 10;
      int dy = dx;
      int ddy = 10;
      if (facing == Direction.WEST) {
        dx = -40; ddx = 0;
        sel = Location.create(-20, selMult * (dy + 10 * outputs));
      } else if (facing == Direction.NORTH) {
        dy = -40; ddy = 0;
        sel = Location.create(selMult * dx, -20);
      } else if (facing == Direction.SOUTH) {
        dy = 40; ddy = 0;
        sel = Location.create(selMult * dx, 20);
      } else {
        dx = 40; ddx = 0;
        sel = Location.create(20, selMult * (dy + 10 * outputs));
      }
      for (int i = 0; i < outputs; i++) {
        ps[i] = new Port(dx, dy, Port.OUTPUT, data.getWidth());
        dx += ddx;
        dy += ddy;
      }
    }
    Location en = sel.translate(facing, -10);
    ps[outputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
    if (enable) {
      ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    ps[ps.length - 1] = new Port(0, 0, Port.INPUT, data.getWidth());
   
    for (int i = 0; i < outputs; i++) {
      ps[i].setToolTip(Strings.getter("demultiplexerOutTip", "" + i));
View Full Code Here

    return elt;
  }
 
  public static Element createText(Document doc, Text text) {
    Element elt = doc.createElement("text");
    Location loc = text.getLocation();
    Font font = text.getValue(DrawAttr.FONT);
    Color fill = text.getValue(DrawAttr.FILL_COLOR);
    Object halign = text.getValue(DrawAttr.ALIGNMENT);
    elt.setAttribute("x", "" + loc.getX());
    elt.setAttribute("y", "" + loc.getY());
    if (!colorMatches(fill, Color.BLACK)) {
      elt.setAttribute("fill", getColorString(fill));
    }
    if (showOpacity(fill)) {
      elt.setAttribute("fill-opacity", getOpacityString(fill));
View Full Code Here

    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      Location sel = painter.getInstance().getPortLocation(outputs);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      g.drawLine(sel.getX(), sel.getY(), sel.getX() + 2 * dx, sel.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      int len = outputs == 2 ? 6 : 4;
      g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
View Full Code Here

    Graphics g = painter.getGraphics();

    // draw control wire
    GraphicsUtil.switchToWidth(g, 3);
    Location pt0 = painter.getInstance().getPortLocation(2);
    Location pt1;
    if (painter.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
      pt1 = pt0.translate(face, 0, 6);
    } else {
      pt1 = pt0.translate(face, 0, -6);
    }
    if (painter.getShowState()) {
      g.setColor(painter.getPort(2).getColor());
    }
    g.drawLine(pt0.getX(), pt0.getY(), pt1.getX(), pt1.getY());

    // draw triangle
    g.setColor(Color.BLACK);
    paintShape(painter);
View Full Code Here

    painter.drawLabel();
  }
 
  private void paintShape(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    double rotate = 0.0;
    Graphics g = painter.getGraphics();
    g.translate(x, y);
    if (facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
View Full Code Here

  private void configurePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Bounds bds = getOffsetBounds(instance.getAttributeSet());
    int d = Math.max(bds.getWidth(), bds.getHeight()) - 20;
    Location loc0 = Location.create(0, 0);
    Location loc1 = loc0.translate(facing.reverse(), 20 + d);
    Location loc2;
    if (instance.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
      loc2 = loc0.translate(facing.reverse(), 10 + d, 10);
    } else {
      loc2 = loc0.translate(facing.reverse(), 10 + d, -10);
    }

    Port[] ports = new Port[3];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    ports[1] = new Port(loc1.getX(), loc1.getY(), Port.INPUT, StdAttr.WIDTH);
    ports[2] = new Port(loc2.getX(), loc2.getY(), Port.INPUT, 1);
    instance.setPorts(ports);
  }
View Full Code Here

  @Override
  public Object getInstanceFeature(final Instance instance, Object key) {
    if (key == WireRepair.class) {
      return new WireRepair() {
        public boolean shouldRepairWire(WireRepairData data) {
          Location port2 = instance.getPortLocation(2);
          return data.getPoint().equals(port2);
        }
      };
    }
    return super.getInstanceFeature(instance, key);
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.