Example #1
0
 /**
  * Paint component
  *
  * @param g Graphics object
  */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   g2 = (Graphics2D) g;
   if (font_antialiasing) {
     g2.setRenderingHints(qualityHints);
   } else {
     g2.setRenderingHints(normalHints);
   }
   if (first_draw) { // store initial width and height
     initial_width = this.getWidth();
     initial_heigth = this.getHeight();
     first_draw = false;
   }
 }
Example #2
0
 protected void setupAntialiasing(Graphics graphics) {
   if (graphics instanceof Graphics2D) {
     Graphics2D myGfx = (Graphics2D) graphics;
     final Object mode =
         mySettingsProvider.useAntialiasing()
             ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
             : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
     final RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, mode);
     myGfx.setRenderingHints(hints);
   }
 }
Example #3
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (nodes.get(0) == null) {
      return;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.blue);
    int x = 0;
    int y = 0;
    double xs = (double) (this.getWidth() - b - (nodes.get(0).r * nodeScaling));
    double ys = (double) (this.getHeight() - b - (nodes.get(0).r * nodeScaling) - noticeBorder);
    g2.setColor(Color.black);
    g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    g2.setColor(Color.blue);
    drawNode s;
    drawNode d;
    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);
    g2.setColor(Color.white);
    if (!ignoreLinks) {
      for (drawLink L : links.values()) {
        g2.setColor(L.color);
        s = nodes.get(L.sid);
        d = nodes.get(L.eid);
        if (s != null && d != null) {
          g2.drawLine(
              (int) ((s.x * xs) + (s.r * nodeScaling) / 2d),
              (int) ((s.y * ys) + (s.r * nodeScaling) / 2d),
              (int) ((d.x * xs) + (d.r * nodeScaling) / 2d),
              (int) ((d.y * ys) + (d.r * nodeScaling) / 2d));
        }
      }
    }
    for (drawNode N : nodes.values()) {
      g2.setColor(N.color);
      g2.fill(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
      g2.setColor(Color.black);
      g2.draw(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
    }
    if (showInfoForNode != -1 && nodeInfo.containsKey(showInfoForNode)) {
      drawNode N = nodes.get(showInfoForNode);

      x = (int) (N.x * xs + N.r * nodeScaling) + 3;
      y = (int) (N.y * ys);
      CTB.flipShift = (int) (N.r * nodeScaling) + 5;
      CTB.draw(g2, x, y, this.getWidth(), this.getHeight(), nodeInfo.get(showInfoForNode));
    }
    g2.setColor(Color.white);
    g2.setFont(new Font("Arial", Font.PLAIN, 10));
    g2.drawString("Ruud van de Bovenkamp - NAS", b, this.getHeight() - b);
    doneDrawing = true;
  }
  @Override
  public void draw(Graphics2D g) {
    double opacity = get(OPACITY);
    opacity = Math.min(Math.max(0d, opacity), 1d);
    if (opacity != 0d) {
      if (opacity != 1d) {
        Rectangle2D.Double drawingArea = getDrawingArea();

        Rectangle2D clipBounds = g.getClipBounds();
        if (clipBounds != null) {
          Rectangle2D.intersect(drawingArea, clipBounds, drawingArea);
        }

        if (!drawingArea.isEmpty()) {

          BufferedImage buf =
              new BufferedImage(
                  (int) ((2 + drawingArea.width) * g.getTransform().getScaleX()),
                  (int) ((2 + drawingArea.height) * g.getTransform().getScaleY()),
                  BufferedImage.TYPE_INT_ARGB);
          Graphics2D gr = buf.createGraphics();
          gr.scale(g.getTransform().getScaleX(), g.getTransform().getScaleY());
          gr.translate((int) -drawingArea.x, (int) -drawingArea.y);
          gr.setRenderingHints(g.getRenderingHints());
          drawFigure(gr);
          gr.dispose();
          Composite savedComposite = g.getComposite();
          g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) opacity));
          g.drawImage(
              buf,
              (int) drawingArea.x,
              (int) drawingArea.y,
              2 + (int) drawingArea.width,
              2 + (int) drawingArea.height,
              null);
          g.setComposite(savedComposite);
        }
      } else {
        drawFigure(g);
      }
    }
  }
Example #5
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   this.setBackground(Color.WHITE);
   Graphics2D g2d = (Graphics2D) g;
   RenderingHints rh =
       new RenderingHints(
           RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   g2d.setRenderingHints(rh);
   for (int i = 0; i < strokes.size(); i++) {
     Stroke currentStroke = strokes.get(i);
     g2d.setPaint(currentStroke.getColor());
     g2d.setStroke(new BasicStroke(currentStroke.getThickness()));
     ArrayList<Point2D> currentStrokePoints = currentStroke.getPoints();
     for (int j = 1; j < currentStrokePoints.size(); j++) {
       g2d.drawLine(
           (int) (currentStrokePoints.get(j - 1).getX() * this.getSize().getWidth()),
           (int) (currentStrokePoints.get(j - 1).getY() * this.getSize().getHeight()),
           (int) (currentStrokePoints.get(j).getX() * this.getSize().getWidth()),
           (int) (currentStrokePoints.get(j).getY() * this.getSize().getHeight()));
     }
   }
 }
Example #6
0
  protected void paintComponent(Graphics graphics) {
    super.paintComponent(graphics);

    Graphics2D g = (Graphics2D) graphics;

    // If we are disabled, we don't draw our arrow, focus, and unstick
    // decorations:
    if (!isEnabled()) {
      return;
    }
    Color oldColor = g.getColor();
    RenderingHints oldHints = g.getRenderingHints();
    g.setColor(Color.black);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (isStuck()) {
      paintHorizontalLine(g);
    }
    g.setRenderingHints(oldHints);
    g.setColor(oldColor);

    knobPainter.paint(g);
  }
Example #7
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    // Background.
    D = this.getSize();
    g.setColor(backgroundColor);
    g.fillRect(0, 0, D.width, D.height);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(lineStroke);

    // Axes, bounding box.
    g.setColor(Color.gray);
    g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset);
    g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset);
    g.drawLine(inset, inset, inset, D.height - inset);
    g.drawLine(inset, inset, D.width - inset, inset);

    double xDelta = (maxX - minX) / numIntervals;

    // X-ticks and labels.
    for (int i = 1; i <= numIntervals; i++) {
      double xTickd = i * xDelta;
      int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5);
      double x = minX + i * xDelta;
      g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20);
    }

    // Y-ticks
    double yDelta = (maxY - minY) / numIntervals;
    for (int i = 0; i < numIntervals; i++) {
      int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals);
      g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset);
      double y = minY + (i + 1) * yDelta;
      g.drawString(df.format(y), 1, D.height - yTick - inset);
    }

    // Zoom+move
    Font savedFont = g.getFont();
    g.setFont(plusFont);
    g.drawString("+", D.width - 25, 20);
    g.setFont(minusFont);
    g.drawString("-", D.width - 25, 50);
    drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up
    drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down
    drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right
    drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left
    g.setFont(savedFont);

    // See if standard axes are in the middle.
    g.setColor(Color.gray);
    if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) {
      // Draw y-axis
      int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + x, D.height - inset, inset + x, inset);
    }
    if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) {
      // Draw x-axis
      int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
      g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset);
    }

    // Draw the objects.
    drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines);
    if (animationMode) {
      drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines);
      // No images in animation mode.
    }

    drawScribbles(g);
  }
Example #8
0
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
  public void paintComponent(Graphics g) {
    // clear(g);
    Graphics2D g2d = (Graphics2D) g;

    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.setRenderingHints(rh);

    g.setColor(new Color(0, 0, 0));
    g.fillRect(0, 0, getWidth(), getHeight());

    // draw the connectors
    for (int i = 1; i < connections.length; i++) {

      NetworkButton b1 = this.nodeList.get(connections[i][0]);
      NetworkButton b2 = this.nodeList.get(connections[i][1]);

      g2d.setStroke(new BasicStroke(2));

      // grey line
      g2d.setPaint(new Color(50, 50, 50));
      g2d.drawLine(
          b1.x + b1.width / 2, b1.y + b1.height / 2, b2.x + b2.width / 2, b2.y + b2.height / 2);

      g2d.setStroke(new BasicStroke(1));

      // b1 line
      g2d.setPaint(b1.baseColor);
      g2d.drawLine(
          b1.x + b1.width / 2 - 2,
          b1.y - 2 + b1.height / 2,
          b2.x - 2 + b2.width / 2,
          b2.y - 2 + b2.height / 2);
      // b2 line
      g2d.setPaint(b2.baseColor);
      g2d.drawLine(
          b1.x + 2 + b1.width / 2,
          b1.y + 2 + b1.height / 2,
          b2.x + 2 + b2.width / 2,
          b2.y + 2 + b2.height / 2);

      // draw crosshairs around current

      String currentNode = mapPanel.networkPanel.getName();

      NetworkButton current = this.nodeList.get(currentNode);
      int x = current.x;
      int y = current.y;
      int height = current.height;
      int width = current.width;
      int l = (int) (height * 0.2);
      g2d.setStroke(new BasicStroke(6));
      g2d.setPaint(new Color(200, 200, 200));
      g2d.drawLine((int) (x + width * 0.5), y, (int) (x + width * 0.5), y - l);
      g2d.drawLine(x, (int) (y + height * 0.5), x - l, (int) (y + height * 0.5));
      g2d.drawLine((int) (x + width * 0.5), y + height, (int) (x + width * 0.5), y + height + l);
      g2d.drawLine(x + width, (int) (y + height * 0.5), x + width + l, (int) (y + height * 0.5));

      g2d.setStroke(new BasicStroke(4));
      g2d.setPaint(current.baseColor);
      g2d.drawLine((int) (x + width * 0.5), y, (int) (x + width * 0.5), y - l);
      g2d.drawLine(x, (int) (y + height * 0.5), x - l, (int) (y + height * 0.5));
      g2d.drawLine((int) (x + width * 0.5), y + height, (int) (x + width * 0.5), y + height + l);
      g2d.drawLine(x + width, (int) (y + height * 0.5), x + width + l, (int) (y + height * 0.5));
    }
  }