Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Location


    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 ? 2 : 1)];
    if (outputs == 2) {
      Location end0;
      Location end1;
      if (facing == Direction.NORTH || facing == Direction.SOUTH) {
        int y = facing == Direction.NORTH ? -10 : 10;
        if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
          end0 = Location.create(-30, y);
          end1 = Location.create(-10, y);
        } else {
          end0 = Location.create(10, y);
          end1 = Location.create(30, y);
        }
      } else {
        int x = facing == Direction.WEST ? -10 : 10;
        if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
          end0 = Location.create(x, 10);
          end1 = Location.create(x, 30);
        } else {
          end0 = Location.create(x, -30);
          end1 = Location.create(x, -10);
        }
      }
      ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, 1);
      ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, 1);
    } else {
      int dx;
      int ddx;
      int dy;
      int ddy;
      if (facing == Direction.NORTH || facing == Direction.SOUTH) {
        dy = facing == Direction.NORTH ? -20 : 20;
        ddy = 0;
        dx = selectLoc == Plexers.SELECT_TOP_RIGHT ? -10 * outputs : 0;
        ddx = 10;
      } else {
        dx = facing == Direction.WEST ? -20 : 20;
        ddx = 0;
        dy = selectLoc == Plexers.SELECT_TOP_RIGHT ? 0 : -10 * outputs;
        ddy = 10;
      }
      for (int i = 0; i < outputs; i++) {
        ps[i] = new Port(dx, dy, Port.OUTPUT, 1);
        dx += ddx;
        dy += ddy;
      }
    }
    Location en = Location.create(0, 0).translate(facing, -10);
    ps[outputs] = new Port(0, 0, Port.INPUT, select.getWidth());
    if (enable) {
      ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    for (int i = 0; i < outputs; i++) {
      ps[i].setToolTip(Strings.getter("decoderOutTip", "" + i));
    }
    ps[outputs].setToolTip(Strings.getter("decoderSelectTip"));
View Full Code Here


    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      Location pt = painter.getInstance().getPortLocation(outputs);
      g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      int len = outputs == 2 ? 6 : 4;
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      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

        depress = 0;
      }
     
      Object facing = painter.getAttributeValue(StdAttr.FACING);
      if (facing == Direction.NORTH || facing == Direction.WEST) {
        Location p = painter.getLocation();
        int px = p.getX();
        int py = p.getY();
        GraphicsUtil.switchToWidth(g, Wire.WIDTH);
        g.setColor(Value.TRUE_COLOR);
        if (facing == Direction.NORTH) g.drawLine(px, py, px, py + 10);
        else                          g.drawLine(px, py, px + 10, py);
        GraphicsUtil.switchToWidth(g, 1);
View Full Code Here

        if (Math.abs(delt) > 5) {
          return true;
        } else {
          int inputs = attrs.inputs;
          for (int i = 1; i <= inputs; i++) {
            Location offs = getInputOffset(attrs, i);
            if (loc.manhattanDistanceTo(offs) <= 5) return true;
          }
          return false;
        }
      }
View Full Code Here

    Direction facing = attrs.facing;
    int inputs = attrs.inputs;
    int negated = attrs.negated;

    Object shape = painter.getGateShape();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int width = bds.getWidth();
    int height = bds.getHeight();
    if (facing == Direction.NORTH || facing == Direction.SOUTH) {
      int t = width; width = height; height = t;
    }
    if (negated != 0) {
      width -= 10;
    }

    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
      PainterShaped.paintInputLines(painter, this);
    } else if (negated != 0) {
      for (int i = 0; i < inputs; i++) {
        int negatedBit = (negated >> i) & 1;
        if (negatedBit == 1) {
          Location in = getInputOffset(attrs, i);
          Location cen = in.translate(facing, 5);
          painter.drawDongle(loc.getX() + cen.getX(),
              loc.getY() + cen.getY());
        }
      }
    }
   
    g.setColor(baseColor);
View Full Code Here

    Curve ret = null;
    switch (state) {
    case ENDPOINT_DRAG:
      if (mouseDown) {
        if (shiftDown) {
          Location p = LineUtil.snapTo8Cardinals(end0, mx, my);
          mx = p.getX();
          my = p.getY();
        }
        if (ctrlDown) {
          mx = canvas.snapX(mx);
          my = canvas.snapY(my);
        }
View Full Code Here

    // caret will be null at this point

    // Otherwise search for a new caret.
    int x = e.getX();
    int y = e.getY();
    Location loc = Location.create(x, y);
    ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);

    // First search in selection.
    for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
      TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
      if (editable != null) {
        caret = editable.getTextCaret(event);
        if (caret != null) {
          proj.getFrame().viewComponentAttributes(circ, comp);
          caretComponent = comp;
          caretCreatingText = false;
          break;
        }
      }
    }

    // Then search in circuit
    if (caret == null) {
      for (Component comp : circ.getAllContaining(loc, g)) {
        TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
        if (editable != null) {
          caret = editable.getTextCaret(event);
          if (caret != null) {
            proj.getFrame().viewComponentAttributes(circ, comp);
            caretComponent = comp;
            caretCreatingText = false;
            break;
          }
        }
      }
    }

    // if nothing found, create a new label
    if (caret == null) {
      if (loc.getX() < 0 || loc.getY() < 0) return;
      AttributeSet copy = (AttributeSet) attrs.clone();
      caretComponent = Text.FACTORY.createComponent(loc, copy);
      caretCreatingText = true;
      TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
      if (editable != null) {
View Full Code Here

        for (Wire w : mergeSet) {
          locs.add(w.getEnd0());
          locs.add(w.getEnd1());
        }
        Collections.sort(locs);
        Location e0 = locs.get(0);
        Location e1 = locs.get(locs.size() - 1);
        Wire wnew = Wire.create(e0, e1);
        Collection<Wire> wset = Collections.singleton(wnew);

        for (Wire w : mergeSet) {
          if (!w.equals(wset)) {
View Full Code Here

   
    ArrayList<Wire> mergeResult = new ArrayList<Wire>();
    if (mids.size() == 2) {
      mergeResult.add(whole);
    } else {
      Location e0 = mids.first();
      for (Location e1 : mids) {
        mergeResult.add(Wire.create(e0, e1));
        e0 = e1;
      }
    }
View Full Code Here

 
  private void doSplits(CircuitMutator mutator) {
    Set<Location> splitLocs = circuit.wires.points.getSplitLocations();
    ReplacementMap repl = new ReplacementMap();
    for (Wire w : circuit.getWires()) {
      Location w0 = w.getEnd0();
      Location w1 = w.getEnd1();
      ArrayList<Location> splits = null;
      for (Location loc : splitLocs) {
        if (w.contains(loc) && !loc.equals(w0) && !loc.equals(w1)) {
          if (splits == null) splits = new ArrayList<Location>();
          splits.add(loc);
        }
      }
      if (splits != null) {
        splits.add(w1);
        Collections.sort(splits);
        Location e0 = w0;
        ArrayList<Wire> subs = new ArrayList<Wire>(splits.size());
        for (Location e1 : splits) {
          subs.add(Wire.create(e0, e1));
          e0 = e1;
        }
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.