示例#1
0
  @Override
  public Bounds getOffsetBounds(AttributeSet attrsBase) {
    GateAttributes attrs = (GateAttributes) attrsBase;
    Direction facing = attrs.facing;
    int size = ((Integer) attrs.size.getValue()).intValue();
    int inputs = attrs.inputs;
    if (inputs % 2 == 0) {
      inputs++;
    }
    int negated = attrs.negated;

    int width = size + bonusWidth + (negateOutput ? 10 : 0);
    if (negated != 0) {
      width += 10;
    }
    int height = Math.max(10 * inputs, size);
    if (facing == Direction.SOUTH) {
      return Bounds.create(-height / 2, -width, height, width);
    } else if (facing == Direction.NORTH) {
      return Bounds.create(-height / 2, 0, height, width);
    } else if (facing == Direction.WEST) {
      return Bounds.create(0, -height / 2, width, height);
    } else {
      return Bounds.create(-width, -height / 2, width, height);
    }
  }
 private void computeSize(boolean immediate) {
   hidePopup();
   Bounds bounds;
   CircuitState circState = circuitState;
   if (circState == null) {
     bounds = Bounds.create(0, 0, 50, 50);
   } else {
     bounds = circState.getCircuit().getAppearance().getAbsoluteBounds();
   }
   int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
   int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
   Size dim;
   if (canvasPane == null) {
     dim = new Size(width, height);
   } else {
     dim = canvasPane.supportPreferredSize(width, height);
   }
   if (!immediate) {
     Bounds old = oldPreferredSize;
     if (old != null
         && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE
         && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
       return;
     }
   }
   oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
   setPreferredSize(dim);
   revalidate();
 }
示例#3
0
 @Override
 public Bounds getOffsetBounds(AttributeSet attrs) {
   Direction facing = attrs.getValue(StdAttr.FACING);
   if (facing == Direction.EAST) {
     return Bounds.create(-42, -6, 42, 12);
   } else if (facing == Direction.WEST) {
     return Bounds.create(0, -6, 42, 12);
   } else if (facing == Direction.NORTH) {
     return Bounds.create(-6, 0, 12, 42);
   } else {
     return Bounds.create(-6, -42, 12, 42);
   }
 }
示例#4
0
 public Bounds getBounds(long addr, Bounds bds) {
   int addrBits = getAddrBits();
   int boxX = bds.getX() + (addrBits <= 12 ? ENTRY_XOFFS12 : ENTRY_XOFFS32);
   int boxW = addrBits <= 12 ? TABLE_WIDTH12 : TABLE_WIDTH32;
   if (addr < 0) {
     int addrLen = (contents.getWidth() + 3) / 4;
     int width = ADDR_WIDTH_PER_CHAR * addrLen;
     return Bounds.create(boxX - width, bds.getY() + ENTRY_YOFFS, width, ENTRY_HEIGHT);
   } else {
     int bdsX = addrToX(bds, addr);
     int bdsY = addrToY(bds, addr);
     return Bounds.create(bdsX, bdsY, boxW / columns, ENTRY_HEIGHT);
   }
 }
示例#5
0
 @Override
 public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
   Project proj = canvas.getProject();
   if (state == MOVING) {
     setState(proj, IDLE);
     computeDxDy(proj, e, g);
     int dx = curDx;
     int dy = curDy;
     if (dx != 0 || dy != 0) {
       if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
         canvas.setErrorMessage(Strings.getter("cannotModifyError"));
       } else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
         canvas.setErrorMessage(Strings.getter("exclusiveError"));
       } else {
         boolean connect = shouldConnect(canvas, e.getModifiersEx());
         drawConnections = false;
         ReplacementMap repl;
         if (connect) {
           MoveGesture gesture = moveGesture;
           if (gesture == null) {
             gesture =
                 new MoveGesture(
                     new MoveRequestHandler(canvas),
                     canvas.getCircuit(),
                     canvas.getSelection().getAnchoredComponents());
           }
           canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
           MoveResult result = gesture.forceRequest(dx, dy);
           clearCanvasMessage(canvas, dx, dy);
           repl = result.getReplacementMap();
         } else {
           repl = null;
         }
         Selection sel = proj.getSelection();
         proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
       }
     }
     moveGesture = null;
     proj.repaintCanvas();
   } else if (state == RECT_SELECT) {
     Bounds bds = Bounds.create(start).add(start.getX() + curDx, start.getY() + curDy);
     Circuit circuit = canvas.getCircuit();
     Selection sel = proj.getSelection();
     Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
     for (Component comp : circuit.getAllWithin(bds, g)) {
       if (!in_sel.contains(comp)) sel.add(comp);
     }
     Action act = SelectionActions.drop(sel, in_sel);
     if (act != null) {
       proj.doAction(act);
     }
     setState(proj, IDLE);
     proj.repaintCanvas();
   }
 }
示例#6
0
 public BitExtender() {
   super("Bit Extender", Strings.getter("extenderComponent"));
   setIconName("extender.gif");
   setAttributes(
       new Attribute[] {ATTR_IN_WIDTH, ATTR_OUT_WIDTH, ATTR_TYPE},
       new Object[] {BitWidth.create(8), BitWidth.create(16), ATTR_TYPE.parse("sign")});
   setFacingAttribute(StdAttr.FACING);
   setKeyConfigurator(
       JoinedConfigurator.create(
           new BitWidthConfigurator(ATTR_OUT_WIDTH),
           new BitWidthConfigurator(ATTR_IN_WIDTH, 1, Value.MAX_WIDTH, 0)));
   setOffsetBounds(Bounds.create(-40, -20, 40, 40));
 }
示例#7
0
  public Negator() {
    super("Negator", __("negatorComponent"));
    setAttributes(new Attribute[] {StdAttr.WIDTH}, new Object[] {BitWidth.create(8)});
    setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH));
    setOffsetBounds(Bounds.create(-40, -20, 40, 40));
    setIconName("negator.svg");

    Port[] ps = new Port[2];
    ps[IN] = new Port(-40, 0, Port.INPUT, StdAttr.WIDTH);
    ps[OUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    ps[IN].setToolTip(__("negatorInputTip"));
    ps[OUT].setToolTip(__("negatorOutputTip"));
    setPorts(ps);
  }
示例#8
0
 @Override
 public Bounds getOffsetBounds(AttributeSet attrs) {
   Object value = attrs.getValue(ATTR_SIZE);
   if (value == SIZE_NARROW) {
     Direction facing = attrs.getValue(StdAttr.FACING);
     if (facing == Direction.SOUTH) return Bounds.create(-9, -20, 18, 20);
     if (facing == Direction.NORTH) return Bounds.create(-9, 0, 18, 20);
     if (facing == Direction.WEST) return Bounds.create(0, -9, 20, 18);
     return Bounds.create(-20, -9, 20, 18);
   } else {
     Direction facing = attrs.getValue(StdAttr.FACING);
     if (facing == Direction.SOUTH) return Bounds.create(-9, -30, 18, 30);
     if (facing == Direction.NORTH) return Bounds.create(-9, 0, 18, 30);
     if (facing == Direction.WEST) return Bounds.create(0, -9, 30, 18);
     return Bounds.create(-30, -9, 30, 18);
   }
 }
示例#9
0
 public Bounds getOffsetBounds(AttributeSet attrs) {
   return Bounds.create(-30, -50, 60, 100);
 }
示例#10
0
 @Override
 public Bounds getOffsetBounds(AttributeSet attrs) {
   return Bounds.create(0, -8, 14, 16)
       .rotate(Direction.EAST, attrs.getValue(StdAttr.FACING), 0, 0);
 }
示例#11
0
 @Override
 public Bounds getOffsetBounds(AttributeSet attrs) {
   Direction facing = attrs.getValue(StdAttr.FACING);
   return Bounds.create(0, -20, 40, 40).rotate(Direction.WEST, facing, 0, 0);
 }
示例#12
0
  @Override
  public void draw(Canvas canvas, ComponentDrawContext context) {
    Project proj = canvas.getProject();
    int dx = curDx;
    int dy = curDy;
    if (state == MOVING) {
      proj.getSelection().drawGhostsShifted(context, dx, dy);

      MoveGesture gesture = moveGesture;
      if (gesture != null && drawConnections && (dx != 0 || dy != 0)) {
        MoveResult result = gesture.findResult(dx, dy);
        if (result != null) {
          Collection<Wire> wiresToAdd = result.getWiresToAdd();
          Graphics g = context.getGraphics();
          GraphicsUtil.switchToWidth(g, 3);
          g.setColor(Color.GRAY);
          for (Wire w : wiresToAdd) {
            Location loc0 = w.getEnd0();
            Location loc1 = w.getEnd1();
            g.drawLine(loc0.getX(), loc0.getY(), loc1.getX(), loc1.getY());
          }
          GraphicsUtil.switchToWidth(g, 1);
          g.setColor(COLOR_UNMATCHED);
          for (Location conn : result.getUnconnectedLocations()) {
            int connX = conn.getX();
            int connY = conn.getY();
            g.fillOval(connX - 3, connY - 3, 6, 6);
            g.fillOval(connX + dx - 3, connY + dy - 3, 6, 6);
          }
        }
      }
    } else if (state == RECT_SELECT) {
      int left = start.getX();
      int right = left + dx;
      if (left > right) {
        int i = left;
        left = right;
        right = i;
      }
      int top = start.getY();
      int bot = top + dy;
      if (top > bot) {
        int i = top;
        top = bot;
        bot = i;
      }

      Graphics gBase = context.getGraphics();
      int w = right - left - 1;
      int h = bot - top - 1;
      if (w > 2 && h > 2) {
        gBase.setColor(BACKGROUND_RECT_SELECT);
        gBase.fillRect(left + 1, top + 1, w - 1, h - 1);
      }

      Circuit circ = canvas.getCircuit();
      Bounds bds = Bounds.create(left, top, right - left, bot - top);
      for (Component c : circ.getAllWithin(bds)) {
        Location cloc = c.getLocation();
        Graphics gDup = gBase.create();
        context.setGraphics(gDup);
        c.getFactory()
            .drawGhost(context, COLOR_RECT_SELECT, cloc.getX(), cloc.getY(), c.getAttributeSet());
        gDup.dispose();
      }

      gBase.setColor(COLOR_RECT_SELECT);
      GraphicsUtil.switchToWidth(gBase, 2);
      if (w < 0) w = 0;
      if (h < 0) h = 0;
      gBase.drawRect(left, top, w, h);
    }
  }
示例#13
0
 public Bounds getBounds() {
   int x0 = e0.getX();
   int y0 = e0.getY();
   return Bounds.create(x0 - 2, y0 - 2, e1.getX() - x0 + 5, e1.getY() - y0 + 5);
 }