Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Bounds


  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    RegisterData state = (RegisterData) painter.getData();
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();

    // determine text to draw in label
    String a;
    String b = null;
    if (painter.getShowState()) {
      int val = state == null ? 0 : state.value;
      String str = StringUtil.toHexString(width, val);
      if (str.length() <= 4) {
        a = str;
      } else {
        int split = str.length() - 4;
        a = str.substring(0, split);
        b = str.substring(split);
      }
    } else {
      a = Strings.get("registerLabel");
      b = Strings.get("registerWidthLabel", "" + widthVal.getWidth());
    }

    // draw boundary, label
    painter.drawBounds();
    painter.drawLabel();

    // draw input and output ports
    if (b == null) {
      painter.drawPort(IN,  "D", Direction.EAST);
      painter.drawPort(OUT, "Q", Direction.WEST);
    } else {
      painter.drawPort(IN);
      painter.drawPort(OUT);
    }
    g.setColor(Color.GRAY);
    painter.drawPort(CLR, "0", Direction.SOUTH);
    painter.drawPort(EN, Strings.get("memEnableLabel"), Direction.EAST);
    g.setColor(Color.BLACK);
    painter.drawClock(CK, Direction.NORTH);

    // draw contents
    if (b == null) {
      GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 4,
          GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    } else {
      GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 3,
          GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
      GraphicsUtil.drawText(g, b, bds.getX() + 15, bds.getY() + 15,
          GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    }
  }
View Full Code Here


      if (changed) state.getInstance().fireInvalidated();
    }
   
    public void draw(InstancePainter painter) {
      KeyboardData data = getKeyboardState(painter);
      Bounds bds = painter.getInstance().getBounds();
      Graphics g = painter.getGraphics();
      FontMetrics fm = g.getFontMetrics(DEFAULT_FONT);

      String str;
      int cursor;
      int dispStart;
      synchronized(data) {
        str = data.toString();
        cursor = data.getCursorPosition();
        if (!data.isDisplayValid()) data.updateDisplay(fm);
        dispStart = data.getDisplayStart();
      }

      int asc = fm.getAscent();
      int x = bds.getX() + 8;
      if (dispStart > 0) {
        x += fm.stringWidth(str.charAt(0) + "m");
        x += fm.stringWidth(str.substring(dispStart, cursor));
      } else if (cursor >= str.length()) {
        x += fm.stringWidth(str);
      } else {
        x += fm.stringWidth(str.substring(0, cursor));
      }
      int y = bds.getY() + (bds.getHeight() + asc) / 2;
      g.drawLine(x, y - asc, x, y);
    }
View Full Code Here

  }
 
  @Override
  public void paintGhost(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    GraphicsUtil.switchToWidth(g, 2);
    g.drawOval(bds.getX() + 1, bds.getY() + 1,
        bds.getWidth() - 2, bds.getHeight() - 2);
  }
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
    Value val = data == null ? Value.FALSE : (Value) data.getValue();
    Bounds bds = painter.getBounds().expand(-1);

    Graphics g = painter.getGraphics();
    if (painter.getShowState()) {
      Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
      Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
      Boolean activ = painter.getAttributeValue(Io.ATTR_ACTIVE);
      Object desired = activ.booleanValue() ? Value.TRUE : Value.FALSE;
      g.setColor(val == desired ? onColor : offColor);
      g.fillOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    }
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, 2);
    g.drawOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    GraphicsUtil.switchToWidth(g, 1);
    g.setColor(painter.getAttributeValue(Io.ATTR_LABEL_COLOR));
    painter.drawLabel();
    painter.drawPorts();
  }
View Full Code Here

      return data.getBounds(-1, painter.getBounds());
    }
 
    @Override
    public void paint(InstancePainter painter) {
      Bounds bds = getBounds(painter);
      Graphics g = painter.getGraphics();
      g.setColor(Color.RED);
      g.drawRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
      g.setColor(Color.BLACK);
    }
View Full Code Here

  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int inputs = 1 << select.getWidth();
   
    // draw stubs for select/enable inputs that aren't on instance boundary
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing != Direction.NORTH && facing != Direction.SOUTH;
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int dx = vertical ? 0 : -selMult;
    int dy = vertical ? selMult : 0;
    if (inputs == 2) { // draw select wire
      Location pt = painter.getInstance().getPortLocation(inputs);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(inputs).getColor());
      }
      g.drawLine(pt.getX() - 2 * dx, pt.getY() - 2 * dy,
          pt.getX(), pt.getY());
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(inputs + 1);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(inputs + 1).getColor());
      }
      int len = inputs == 2 ? 6 : 4;
      g.drawLine(en.getX() - len * dx, en.getY() - len * dy,
          en.getX(), en.getY());
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(inputs));
   
    // draw a 0 indicating where the numbering starts for inputs
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = bds.getX() + bds.getWidth() - 3;
      y0 = bds.getY() + 15;
      halign = GraphicsUtil.H_RIGHT;
    } else if (facing == Direction.NORTH) {
      x0 = bds.getX() + 10;
      y0 = bds.getY() + bds.getHeight() - 2;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = bds.getX() + 10;
      y0 = bds.getY() + 12;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getX() + 3;
      y0 = bds.getY() + 15;
      halign = GraphicsUtil.H_LEFT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", x0, y0, halign, GraphicsUtil.V_BASELINE);
   
    // draw the trapezoid, "MUX" string, the individual ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing, select.getWidth() == 1 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "MUX",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
  }
View Full Code Here

    } else {
      mid = Strings.get("bitFinderLowLabel");
      bot = "1";
    }
   
    Bounds bds = painter.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y0 = bds.getY();
    GraphicsUtil.drawCenteredText(g, top, x, y0 + 8);
    GraphicsUtil.drawCenteredText(g, mid, x, y0 + 20);
    GraphicsUtil.drawCenteredText(g, bot, x, y0 + 32);
  }
View Full Code Here

        }
      }
      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));
View Full Code Here

  }
 
  static void configureLabel(Instance instance, boolean isRectangular,
      Location control) {
    Object facing = instance.getAttributeValue(StdAttr.FACING);
    Bounds bds = instance.getBounds();
    int x;
    int y;
    int halign;
    if (facing == Direction.NORTH || facing == Direction.SOUTH) {
      x = bds.getX() + bds.getWidth() / 2 + 2;
      y = bds.getY() - 2;
      halign = TextField.H_LEFT;
    } else { // west or east
      y = isRectangular ? bds.getY() - 2 : bds.getY();
      if (control != null && control.getY() == bds.getY()) {
        // the control line will get in the way
        x = control.getX() + 2;
        halign = TextField.H_LEFT;
      } else {
        x = bds.getX() + bds.getWidth() / 2;
        halign = TextField.H_CENTER;
      }
    }
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y,
        halign, TextField.V_BASELINE);
View Full Code Here

  }
 
  @Override
  public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    Bounds base = Bounds.create(-30, -15, 30, 30);
    return base.rotate(Direction.EAST, facing, 0, 0);
  }
View Full Code Here

TOP

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

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.