Example #1
0
  public void draw(Graphics2D g2d, Point offset, int width) {
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setColor(new Color(255, 255, 212));
    g2d.fillRect(
        offset.x, offset.y + this.heightOffset + 1, width, this.typeHeight - this.heightOffset - 1);
    g2d.setColor(new Color(196, 196, 196));
    g2d.drawLine(
        offset.x, offset.y + this.typeHeight, offset.x + width, offset.y + this.typeHeight);

    g2d.setColor(portTypeFontColor);
    g2d.setFont(portTypeFont);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.drawString(
        this.typeName, offset.x + this.portTypeTextOffset.x, offset.y + this.portTypeTextOffset.y);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    Iterator<PortEntry> iter = this.portEntryMap.values().iterator();
    while (iter.hasNext()) {
      // Enumeration<PortEntry> pe = this.portEntryMap.elements();
      // while (pe.hasMoreElements()) {
      // PortEntry p = pe.nextElement();
      PortEntry p = iter.next();
      if (p.isConnected()) {
        g2d.setColor(new Color(128, 255, 128));
      } else {
        g2d.setColor(new Color(255, 128, 128));
      }

      g2d.fillOval(
          offset.x + p.getCircleOffset().x,
          offset.y + p.getCircleOffset().y,
          portCircleSize,
          portCircleSize);
      g2d.setColor(new Color(64, 64, 64));
      g2d.drawOval(
          offset.x + p.getCircleOffset().x,
          offset.y + p.getCircleOffset().y,
          portCircleSize,
          portCircleSize);

      g2d.setColor(portNameFontColor);
      g2d.setFont(portNameFont);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.drawString(p.getText(), offset.x + p.getTextOffset().x, offset.y + p.getTextOffset().y);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
      g2d.setColor(new Color(196, 196, 196));
      g2d.drawLine(offset.x, offset.y + p.getHeight(), offset.x + width, offset.y + p.getHeight());
      /*
      g2d.setColor(new Color(255, 0, 0));
      g2d.drawLine(offset.x + p.getConnectionPoint().x - 1, offset.y + p.getConnectionPoint().y, offset.x + p.getConnectionPoint().x + 1, offset.y + p.getConnectionPoint().y);
      g2d.drawLine(offset.x + p.getConnectionPoint().x, offset.y + p.getConnectionPoint().y + 1, offset.x + p.getConnectionPoint().x, offset.y + p.getConnectionPoint().y - 1);
      */
    }
  }
Example #2
0
  public PortEntry positionWithinPort(Point offset, Point pos) {
    Iterator<PortEntry> iter = this.portEntryMap.values().iterator();
    while (iter.hasNext()) {
      // Enumeration<PortEntry> pe = this.portEntryMap.elements();
      // while (pe.hasMoreElements()) {
      // PortEntry p = pe.nextElement();
      PortEntry p = iter.next();
      if (pos.x >= offset.x + p.getCircleOffset().x
          && pos.y >= offset.y + p.getCircleOffset().y
          && pos.x <= offset.x + p.getCircleOffset().x + portCircleSize
          && pos.y <= offset.y + p.getCircleOffset().y + portCircleSize) {
        return p;
      }
    }

    return null;
  }