Exemplo n.º 1
0
 /** [Internal] */
 private void paintBackground(Graphics2D g2, Color theBackground) {
   Color color1 = g2.getColor();
   if (theBackground == null) theBackground = Color.white;
   g2.setColor(theBackground);
   g2.fillRect(0, 0, 30000, 30000);
   g2.setColor(color1);
 }
  /**
   * Paints the progress string.
   *
   * @param g Graphics used for drawing.
   * @param x x location of bounding box
   * @param y y location of bounding box
   * @param width width of bounding box
   * @param height height of bounding box
   * @param fillStart start location, in x or y depending on orientation, of the filled portion of
   *     the progress bar.
   * @param amountFull size of the fill region, either width or height depending upon orientation.
   * @param b Insets of the progress bar.
   */
  private void paintString(
      Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      g2.setColor(getSelectionBackground());
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(fillStart, y, amountFull, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
      g2.setColor(getSelectionBackground());
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      g2.setFont(progressBar.getFont().deriveFont(rotate));
      renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(x, fillStart, width, amountFull);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
  }
Exemplo n.º 3
0
  public void drawFunctionToGraphic(Graphics2D g, int x, int y, int UNITYX, int UNITYY) {
    int _x, _y;

    g.setColor(Color.red);
    g.drawString("f(x) = " + F.toString(), 15, 20);

    g.setColor(Color.blue);
    for (double i = 0; ; i += EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }

    for (double i = 0; ; i -= EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }
  }
Exemplo n.º 4
0
  public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setStroke(new BasicStroke(1.0f));

    if (isOpaque()) {
      g2d.setColor(getBackground());
      g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    g2d.setColor(Color.black);
    g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2);
    g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight);

    for (int i = unityX; i < frameWidth / 2; i += unityX) {
      g2d.drawLine(
          frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3);
      g2d.drawLine(
          frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3);
    }

    for (int i = unityY; i < frameHeight / 2; i += unityY) {
      g2d.drawLine(
          frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i);
      g2d.drawLine(
          frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i);
    }

    g2d.setColor(Color.blue);
    function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY);

    paintCurrentMethodState(g2d);

    g2d.dispose();
  }
Exemplo n.º 5
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
Exemplo n.º 6
0
  public void setPenColour(int colour) {

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      if (colour == 0) {
        gRef.setColor(Preferences.penColor);
      }
      if (colour == 1) {
        gRef.setColor(Preferences.highlightColor);
      }
    }
  }
  /**
   * All purpose paint method that should do the right thing for all linear bouncing-box progress
   * bars. Override this if you are making another kind of progress bar.
   *
   * @see #paintDeterminate
   * @since 1.4
   */
  protected void paintIndeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);

    if (barRectWidth <= 0 || barRectHeight <= 0) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g;

    // Paint the bouncing box.
    boxRect = getBox(boxRect);
    if (boxRect != null) {
      g2.setColor(progressBar.getForeground());
      g2.fillRect(boxRect.x, boxRect.y, boxRect.width, boxRect.height);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.x, boxRect.width, b);
      } else {
        paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.y, boxRect.height, b);
      }
    }
  }
Exemplo n.º 8
0
  private void paintCurrentMethodState(Graphics2D g2d) {
    switch (type) {
      case 0: // bisectiei
        if (Cn.size() > 0) {
          g2d.setColor(Color.green);
          for (int pnt = 0; pnt < An.size(); pnt++) drawPoint(An.elementAt(pnt), g2d);
          g2d.setColor(Color.orange);
          for (int pnt = 0; pnt < Bn.size(); pnt++) drawPoint(Bn.elementAt(pnt), g2d);

          g2d.setColor(Color.red);
          drawPoint(Cn.lastElement(), g2d);

          g2d.setColor(Color.blue);
          g2d.drawString("Pasul " + Cn.size(), 15, 35);
          g2d.drawString(
              "[An, Bn] = [" + An.lastElement().x + ", " + Bn.lastElement().x + "]", 15, 50);
          g2d.drawString("Cn = " + Cn.lastElement().x, 15, 65);

          if (complete) {
            g2d.setColor(Color.red);
            g2d.drawString("Algoritm terminat in " + Cn.size() + " pasi.", 15, 80);
            g2d.drawString(
                "Rezultatule este " + Cn.lastElement().x + ", cu eroarea de +-" + err + ".",
                15,
                95);
          }
        }
        break;
      case 3: // newton
      case 2: // secantei
      case 1: // coardei
        g2d.setColor(Color.green);
        for (int pnt = 0; pnt < An.size() - 1; pnt++) drawPoint(An.elementAt(pnt), g2d);
        g2d.setColor(Color.red);
        drawPoint(An.lastElement(), g2d);

        g2d.setColor(Color.blue);
        g2d.drawString("Pasul " + An.size(), 15, 35);
        if (type != 3)
          g2d.drawString(
              "[x0, x1] = [" + An.elementAt(0).x + ", " + An.elementAt(1).x + "]", 15, 50);
        else g2d.drawString("x0 = " + An.elementAt(0).x, 15, 50);
        g2d.drawString("xn = " + An.lastElement().x, 15, 65);
        if (complete) {
          g2d.setColor(Color.red);
          g2d.drawString("Algoritm terminat in " + An.size() + " pasi.", 15, 80);
          g2d.drawString(
              "Rezultatule este " + An.lastElement().x + ", cu eroarea de +-" + err + ".", 15, 95);
        }
        break;
    }
  }
Exemplo n.º 9
0
    /**
     * Paint a background for all groups and a round blue border and background when a cell is
     * selected.
     *
     * @param g the <tt>Graphics</tt> object
     */
    private void internalPaintComponent(Graphics g) {
      AntialiasingManager.activateAntialiasing(g);

      Graphics2D g2 = (Graphics2D) g;

      if (isSelected) {
        g2.setColor(selectedColor);
        g2.fillRect(0, 0, this.getWidth(), this.getHeight());
      }
    }
Exemplo n.º 10
0
  public void generarFondo(Component componente) {
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    tmp = gc.createCompatibleImage(areaDibujo.width, areaDibujo.height, BufferedImage.TRANSLUCENT);
    Graphics2D g2d = (Graphics2D) tmp.getGraphics();
    g2d.setColor(new Color(55, 55, 255, 165));
    g2d.fillRect(0, 0, areaDibujo.width, areaDibujo.height);
    fondo = tmp;
  }
Exemplo n.º 11
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
Exemplo n.º 12
0
  private void buildAccumulator(int r) {
    accImage = new BufferedImage(width, height, greyScale.getType());
    Graphics2D g = accImage.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();
    int max = 0;

    double[] a = new double[1];
    for (int y = 0; y < height; ++y)
      for (int x = 0; x < width; ++x) {
        a[0] = acc[y * width + x][r - rmin] & 0xFF;
        accImage.getRaster().setPixel(x, y, a);
      }
    ImageIcon icon2 = new ImageIcon(accImage);
    lbl2.setIcon(icon2);
  }
Exemplo n.º 13
0
  /**
   * Draws the passed-in text using syntax highlighting for the current language. It is assumed that
   * the entire line is either not in a selected region, or painting with a selection-foreground
   * color is turned off.
   *
   * @param painter The painter to render the tokens.
   * @param token The list of tokens to draw.
   * @param g The graphics context in which to draw.
   * @param x The x-coordinate at which to draw.
   * @param y The y-coordinate at which to draw.
   * @return The x-coordinate representing the end of the painted text.
   */
  private float drawLine(
      TokenPainter painter, Token token, Graphics2D g, float x, float y, int line) {

    float nextX = x; // The x-value at the end of our text.
    boolean paintBG = host.getPaintTokenBackgrounds(line, y);

    while (token != null && token.isPaintable() && nextX < clipEnd) {
      nextX = painter.paint(token, g, nextX, y, host, this, clipStart, paintBG);
      token = token.getNextToken();
    }

    // NOTE: We should re-use code from Token (paintBackground()) here,
    // but don't because I'm just too lazy.
    if (host.getEOLMarkersVisible()) {
      g.setColor(host.getForegroundForTokenType(Token.WHITESPACE));
      g.setFont(host.getFontForTokenType(Token.WHITESPACE));
      g.drawString("\u00B6", nextX, y);
    }

    // Return the x-coordinate at the end of the painted text.
    return nextX;
  }
Exemplo n.º 14
0
  public void sobel() {
    sobel = new BufferedImage(width, height, filtered.getType());
    Graphics2D g = sobel.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();

    int[] tmp = new int[1];
    sX = new double[height][width];
    sY = new double[height][width];
    double maxX = 0;
    double maxY = 0;
    for (int y = 1; y < height - 1; ++y)
      for (int x = 1; x < width - 1; ++x) {
        double Xvalue = 0;
        double Yvalue = 0;
        for (int j = -1; j <= 1; ++j)
          for (int i = -1; i <= 1; ++i) {

            Xvalue += GX[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0];
            Yvalue += GY[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0];
          }
        if (Xvalue > maxX) maxX = Xvalue;
        if (Yvalue > maxY) maxY = Yvalue;
        sX[y][x] = Xvalue;
        sY[y][x] = Yvalue;
      }

    for (int y = 1; y < height - 1; ++y)
      for (int x = 1; x < width - 1; ++x) {
        double[] a = {(Math.abs((sX[y][x] / maxX * 255)) + Math.abs((sY[y][x] / maxY) * 255))};
        // if (a[0] > 0) binary[y][x] = 1;
        // if (a[0] <= 0) binary[y][x] = 0;

        sobel.getRaster().setPixel(x, y, a);
      }
    ImageIcon icon2 = new ImageIcon(sobel);
    lbl2.setIcon(icon2);
  }
    public void paint(Graphics g) {
      path = findOptimizedPath(srcID, dstID, type);

      /// Create the drawing board
      Dimension d = getSize();
      g.setColor(Color.white);
      g.fillRect(1, 1, d.width - 2, d.height - 2);

      g.setColor(Color.black);
      g.drawRect(1, 1, d.width - 2, d.height - 2);
      g.setFont(serifFont);

      /// Draw the whole network, including all routers with
      ///     delay and flow level, sources and destinations.
      int numR = 1;
      int w = 95;
      int h = d.height / 5;
      int pos = -1;

      for (int i = 0; i < 3; i++) {
        g.drawOval(w, h + 100 * i, 40, 40);
        g.drawString("S" + String.valueOf(i + 1), w + 13, h + 100 * i - 5);
      }

      for (int i = 0; i < 3; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 110, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 123, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 125,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 125, h + 100 * i + 35);
      }

      h = d.height / 11;
      for (int i = 0; i < 4; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 210, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 223, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 225,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 225, h + 100 * i + 35);
      }

      h = 20;
      for (int i = 0; i < 6; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 310, h + 80 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 320, h + 80 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 325,
            h + 80 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 325, h + 80 * i + 35);
      }

      for (int i = 0; i < 4; i++) {
        g.drawOval(w + 410, d.height / 11 + 100 * i, 40, 40);
        g.drawString("D" + String.valueOf(i + 1), w + 423, d.height / 11 + 100 * i - 5);
      }

      g.setColor(Color.black);
      int[][] connection = statMux.getConnections();

      /// Check buffer for connections at each step and draw links at layer1
      for (int i = 0; i < connection[path[0] - 1].length; i++) {
        int temp = connection[path[0] - 1][i] - 3;
        g.drawLine(w + 40, (path[0]) * d.height / 5 + 20, w + 110, temp * d.height / 5 + 20);
      }

      /// Check buffer for connections at each step and draw links at layer2
      for (int i = 0; i < connection[path[1] - 1].length; i++) {
        int temp = connection[path[1] - 1][i] - 7;
        g.drawLine(
            w + 150, (path[1] - 3) * d.height / 5 + 20, w + 210, (d.height / 11) + 100 * temp + 20);
      }

      /// Check buffer for connections at each step and draw links at layer3
      for (int i = 0; i < connection[path[2] - 1].length; i++) {
        int temp = connection[path[2] - 1][i] - 11;
        g.drawLine(w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * temp + 40);
      }

      /// Draw optimized path for packets traveling between source
      /// and destination
      h = d.height / 5;
      Graphics2D g2 = (Graphics2D) g;
      g2.setStroke(new BasicStroke(2));
      g2.setColor(Color.red);

      g2.drawLine(w + 40, h * (path[0]) + 20, w + 110, h * (path[1] - 3) + 20);
      g2.drawLine(
          w + 150, h * (path[1] - 3) + 20, w + 210, (d.height / 11) + 100 * (path[2] - 7) + 20);
      g2.drawLine(
          w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * (path[3] - 11) + 40);
      g2.drawLine(
          w + 350, 80 * (path[3] - 11) + 40, w + 410, (d.height / 11) + 100 * (path[4] - 17) + 20);

      /// Calculate and display loss, delay, and throughput
      delayTime = getDelay(path, type);
      throughPut = getThroughput(path);

      int numPackLost = getLossRate(numTransfer);

      lossRate = numPackLost / 100000.0 + 0.0005 * delayTime;
      delayVal.setText(String.format("%.2f", delayTime));
      throuVal.setText(String.valueOf(throughPut));
      lossVal.setText(String.format("%.4f", lossRate));
    }
Exemplo n.º 16
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);
   }
 }
  /**
   * All purpose paint method that should do the right thing for almost all linear, determinate
   * progress bars. By setting a few values in the defaults table, things should work just fine to
   * paint your progress bar. Naturally, override this if you are making a circular or semi-circular
   * progress bar.
   *
   * @see #paintIndeterminate
   * @since 1.4
   */
  protected void paintDeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);

    if (barRectWidth <= 0 || barRectHeight <= 0) {
      return;
    }

    int cellLength = getCellLength();
    int cellSpacing = getCellSpacing();
    // amount of progress to draw
    int amountFull = getAmountFull(b, barRectWidth, barRectHeight);

    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(progressBar.getForeground());

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      // draw the cells
      if (cellSpacing == 0 && amountFull > 0) {
        // draw one big Rect because there is no space between cells
        g2.setStroke(
            new BasicStroke((float) barRectHeight, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
      } else {
        // draw each individual cell
        g2.setStroke(
            new BasicStroke(
                (float) barRectHeight,
                BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL,
                0.f,
                new float[] {cellLength, cellSpacing},
                0.f));
      }

      if (BasicGraphicsUtils.isLeftToRight(c)) {
        g2.drawLine(
            b.left, (barRectHeight / 2) + b.top, amountFull + b.left, (barRectHeight / 2) + b.top);
      } else {
        g2.drawLine(
            (barRectWidth + b.left),
            (barRectHeight / 2) + b.top,
            barRectWidth + b.left - amountFull,
            (barRectHeight / 2) + b.top);
      }

    } else { // VERTICAL
      // draw the cells
      if (cellSpacing == 0 && amountFull > 0) {
        // draw one big Rect because there is no space between cells
        g2.setStroke(
            new BasicStroke((float) barRectWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
      } else {
        // draw each individual cell
        g2.setStroke(
            new BasicStroke(
                (float) barRectWidth,
                BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL,
                0f,
                new float[] {cellLength, cellSpacing},
                0f));
      }

      g2.drawLine(
          barRectWidth / 2 + b.left,
          b.top + barRectHeight,
          barRectWidth / 2 + b.left,
          b.top + barRectHeight - amountFull);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b);
    }
  }
Exemplo n.º 18
0
  private void process() {
    int width = Integer.parseInt(xres.getText());
    int height = Integer.parseInt(yres.getText());
    boolean preserveAspect = aspect.isSelected();
    Color bg = new Color(red.getValue(), green.getValue(), blue.getValue());

    String outDir = output.getText();
    String suffix = ((String) format.getSelectedItem()).toLowerCase();
    String preText = prepend.getText();
    String appText = append.getText();

    int scaleType = -1;
    String alg = (String) algorithm.getSelectedItem();
    if (alg.equals("Smooth")) scaleType = Image.SCALE_SMOOTH;
    else if (alg.equals("Standard")) scaleType = Image.SCALE_DEFAULT;
    else if (alg.equals("Fast")) scaleType = Image.SCALE_FAST;
    else if (alg.equals("Replicate")) scaleType = Image.SCALE_REPLICATE;
    else if (alg.equals("Area averaging")) {
      scaleType = Image.SCALE_AREA_AVERAGING;
    }

    DefaultListModel model = (DefaultListModel) list.getModel();
    int size = model.size();
    progress.setValue(0);
    progress.setMaximum(4 * size);

    for (int i = 0; i < size; i++) {
      ThumbFile tf = (ThumbFile) model.elementAt(i);
      list.setSelectedValue(tf, true);
      String tail = " (" + (i + 1) + " of " + size + ")";

      progress.setValue(4 * i);
      progress.setString("Reading" + tail);

      // construct input and output filenames
      String inFile = tf.getPath();
      String outFile = outDir + SLASH + tf.getName();
      int ndx = outFile.lastIndexOf(SLASH);
      String s1 = outFile.substring(0, ndx + SLASH.length());
      String s2 = outFile.substring(ndx + SLASH.length());
      int dot_ndx = s2.lastIndexOf(".");
      if (dot_ndx >= 0) s2 = s2.substring(0, dot_ndx);

      // make the thumbnail file name
      outFile = s1 + preText + s2 + appText + "." + suffix;

      // read in the file to an image
      BufferedImage image = null;
      try {
        image = ImageIO.read(new File(inFile));
      } catch (IOException exc) {
        exc.printStackTrace();
      }

      progress.setValue(4 * i + 1);
      progress.setString("Resizing" + tail);

      // resize image
      int w, h;
      if (preserveAspect) {
        int ow = image.getWidth();
        int oh = image.getHeight();
        double oasp = (double) ow / oh;
        double tasp = (double) width / height;
        if (oasp > tasp) {
          w = width;
          h = (int) (w / oasp);
        } else {
          h = height;
          w = (int) (oasp * h);
        }
      } else {
        w = width;
        h = height;
      }
      Image resized = image.getScaledInstance(w, h, scaleType);

      progress.setValue(4 * i + 2);
      progress.setString("Painting" + tail);

      // create thumbnail
      BufferedImage thumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2d = thumb.createGraphics();
      g2d.setColor(bg);
      g2d.fillRect(0, 0, width, height);
      g2d.drawImage(resized, (width - w) / 2, (height - h) / 2, this);
      g2d.dispose();

      progress.setValue(4 * i + 3);
      progress.setString("Writing" + tail);

      // save thumbnail to disk
      File out = new File(outFile);
      File parent = out.getParentFile();
      if (parent != null && !parent.exists()) parent.mkdirs();
      try {
        ImageIO.write(thumb, suffix, out);
      } catch (IOException exc) {
        exc.printStackTrace();
      }
    }

    list.setSelectedIndices(new int[0]);
    progress.setValue(4 * size);
    progress.setString("Complete");
  }
Exemplo n.º 19
0
  /**
   * Draws the passed-in text using syntax highlighting for the current language. Tokens are checked
   * for being in a selected region, and are rendered appropriately if they are.
   *
   * @param painter The painter to render the tokens.
   * @param token The list of tokens to draw.
   * @param g The graphics context in which to draw.
   * @param x The x-coordinate at which to draw.
   * @param y The y-coordinate at which to draw.
   * @param selStart The start of the selection.
   * @param selEnd The end of the selection.
   * @return The x-coordinate representing the end of the painted text.
   */
  private float drawLineWithSelection(
      TokenPainter painter, Token token, Graphics2D g, float x, float y, int selStart, int selEnd) {

    float nextX = x; // The x-value at the end of our text.
    boolean useSTC = host.getUseSelectedTextColor();

    while (token != null && token.isPaintable() && nextX < clipEnd) {

      // Selection starts in this token
      if (token.containsPosition(selStart)) {

        if (selStart > token.getOffset()) {
          tempToken.copyFrom(token);
          tempToken.textCount = selStart - tempToken.getOffset();
          nextX = painter.paint(tempToken, g, nextX, y, host, this, clipStart);
          tempToken.textCount = token.length();
          tempToken.makeStartAt(selStart);
          // Clone required since token and tempToken must be
          // different tokens for else statement below
          token = new TokenImpl(tempToken);
        }

        int tokenLen = token.length();
        int selCount = Math.min(tokenLen, selEnd - token.getOffset());
        if (selCount == tokenLen) {
          nextX = painter.paintSelected(token, g, nextX, y, host, this, clipStart, useSTC);
        } else {
          tempToken.copyFrom(token);
          tempToken.textCount = selCount;
          nextX = painter.paintSelected(tempToken, g, nextX, y, host, this, clipStart, useSTC);
          tempToken.textCount = token.length();
          tempToken.makeStartAt(token.getOffset() + selCount);
          token = tempToken;
          nextX = painter.paint(token, g, nextX, y, host, this, clipStart);
        }

      }

      // Selection ends in this token
      else if (token.containsPosition(selEnd)) {
        tempToken.copyFrom(token);
        tempToken.textCount = selEnd - tempToken.getOffset();
        nextX = painter.paintSelected(tempToken, g, nextX, y, host, this, clipStart, useSTC);
        tempToken.textCount = token.length();
        tempToken.makeStartAt(selEnd);
        token = tempToken;
        nextX = painter.paint(token, g, nextX, y, host, this, clipStart);
      }

      // This token is entirely selected
      else if (token.getOffset() >= selStart && token.getEndOffset() <= selEnd) {
        nextX = painter.paintSelected(token, g, nextX, y, host, this, clipStart, useSTC);
      }

      // This token is entirely unselected
      else {
        nextX = painter.paint(token, g, nextX, y, host, this, clipStart);
      }

      token = token.getNextToken();
    }

    // NOTE: We should re-use code from Token (paintBackground()) here,
    // but don't because I'm just too lazy.
    if (host.getEOLMarkersVisible()) {
      g.setColor(host.getForegroundForTokenType(Token.WHITESPACE));
      g.setFont(host.getFontForTokenType(Token.WHITESPACE));
      g.drawString("\u00B6", nextX, y);
    }

    // Return the x-coordinate at the end of the painted text.
    return nextX;
  }
Exemplo n.º 20
0
 private void clearArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
   penColor = gRef.getColor();
   gRef.setColor(Preferences.backgroundColor);
   gRef.fillArc(x, y, width, height, startAngle, arcAngle);
   gRef.setColor(penColor);
 }
Exemplo n.º 21
0
  /**
   * Draws a single view (i.e., a line of text for a wrapped view), wrapping the text onto multiple
   * lines if necessary.
   *
   * @param painter The painter to use to render tokens.
   * @param g The graphics context in which to paint.
   * @param r The rectangle in which to paint.
   * @param view The <code>View</code> to paint.
   * @param fontHeight The height of the font being used.
   * @param y The y-coordinate at which to begin painting.
   */
  protected void drawView(
      TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y) {

    float x = r.x;

    LayeredHighlighter h = (LayeredHighlighter) host.getHighlighter();

    RSyntaxDocument document = (RSyntaxDocument) getDocument();
    Element map = getElement();

    int p0 = view.getStartOffset();
    int lineNumber = map.getElementIndex(p0);
    int p1 = view.getEndOffset(); // - 1;

    setSegment(p0, p1 - 1, document, drawSeg);
    // System.err.println("drawSeg=='" + drawSeg + "' (p0/p1==" + p0 + "/" + p1 + ")");
    int start = p0 - drawSeg.offset;
    Token token = document.getTokenListForLine(lineNumber);

    // If this line is an empty line, then the token list is simply a
    // null token.  In this case, the line highlight will be skipped in
    // the loop below, so unfortunately we must manually do it here.
    if (token != null && token.getType() == Token.NULL) {
      h.paintLayeredHighlights(g, p0, p1, r, host, this);
      return;
    }

    // Loop through all tokens in this view and paint them!
    while (token != null && token.isPaintable()) {

      int p = calculateBreakPosition(p0, token, x);
      x = r.x;

      h.paintLayeredHighlights(g, p0, p, r, host, this);

      while (token != null && token.isPaintable() && token.getEndOffset() - 1 < p) { // <=p) {
        x = painter.paint(token, g, x, y, host, this);
        token = token.getNextToken();
      }

      if (token != null && token.isPaintable() && token.getOffset() < p) {
        int tokenOffset = token.getOffset();
        tempToken.set(
            drawSeg.array, tokenOffset - start, p - 1 - start, tokenOffset, token.getType());
        painter.paint(tempToken, g, x, y, host, this);
        tempToken.copyFrom(token);
        tempToken.makeStartAt(p);
        token = new TokenImpl(tempToken);
      }

      p0 = (p == p0) ? p1 : p;
      y += fontHeight;
    } // End of while (token!=null && token.isPaintable()).

    // NOTE: We should re-use code from Token (paintBackground()) here,
    // but don't because I'm just too lazy.
    if (host.getEOLMarkersVisible()) {
      g.setColor(host.getForegroundForTokenType(Token.WHITESPACE));
      g.setFont(host.getFontForTokenType(Token.WHITESPACE));
      g.drawString("\u00B6", x, y - fontHeight);
    }
  }
Exemplo n.º 22
0
 private void drawCircle(int pix, int xCenter, int yCenter, int r) {
   Graphics2D g = res.createGraphics();
   g.setColor(Color.RED);
   g.drawOval(xCenter - r, yCenter - r, r * 2, r * 2);
   g.dispose();
 }
Exemplo n.º 23
0
  public void nonMax() {
    nonMax = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g = nonMax.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();

    magnitude = new int[height * width];
    for (int y = 1; y < height - 1; y++) {
      for (int x = 1; x < width - 1; x++) {

        double xGrad = sX[y][x];
        double yGrad = sY[y][x];
        double gradMag = Math.hypot(xGrad, yGrad);

        // perform non-maximal supression
        double nMag = Math.hypot(sX[y - 1][x], sY[y - 1][x]);
        double sMag = Math.hypot(sX[y + 1][x], sY[y + 1][x]);
        double wMag = Math.hypot(sX[y][x - 1], sY[y][x - 1]);
        double eMag = Math.hypot(sX[y][x + 1], sY[y][x + 1]);
        double neMag = Math.hypot(sX[y - 1][x + 1], sY[y - 1][x + 1]);
        double seMag = Math.hypot(sX[y + 1][x + 1], sY[y + 1][x + 1]);
        double swMag = Math.hypot(sX[y + 1][x - 1], sY[y + 1][x - 1]);
        double nwMag = Math.hypot(sX[y - 1][x - 1], sY[y - 1][x - 1]);
        double tmp;
        /*
         * An explanation of what's happening here, for those who want
         * to understand the source: This performs the "non-maximal
         * supression" phase of the Canny edge detection in which we
         * need to compare the gradient magnitude to that in the
         * direction of the gradient; only if the value is a local
         * maximum do we consider the point as an edge candidate.
         *
         * We need to break the comparison into a number of different
         * cases depending on the gradient direction so that the
         * appropriate values can be used. To avoid computing the
         * gradient direction, we use two simple comparisons: first we
         * check that the partial derivatives have the same sign (1)
         * and then we check which is larger (2). As a consequence, we
         * have reduced the problem to one of four identical cases that
         * each test the central gradient magnitude against the values at
         * two points with 'identical support'; what this means is that
         * the geometry required to accurately interpolate the magnitude
         * of gradient function at those points has an identical
         * geometry (upto right-angled-rotation/reflection).
         *
         * When comparing the central gradient to the two interpolated
         * values, we avoid performing any divisions by multiplying both
         * sides of each inequality by the greater of the two partial
         * derivatives. The common comparand is stored in a temporary
         * variable (3) and reused in the mirror case (4).
         *
         */
        if (xGrad * yGrad <= (float) 0 /*(1)*/
            ? Math.abs(xGrad) >= Math.abs(yGrad) /*(2)*/
                ? (tmp = Math.abs(xGrad * gradMag))
                        >= Math.abs(yGrad * neMag - (xGrad + yGrad) * eMag) /*(3)*/
                    && tmp > Math.abs(yGrad * swMag - (xGrad + yGrad) * wMag) /*(4)*/
                : (tmp = Math.abs(yGrad * gradMag))
                        >= Math.abs(xGrad * neMag - (yGrad + xGrad) * nMag) /*(3)*/
                    && tmp > Math.abs(xGrad * swMag - (yGrad + xGrad) * sMag) /*(4)*/
            : Math.abs(xGrad) >= Math.abs(yGrad) /*(2)*/
                ? (tmp = Math.abs(xGrad * gradMag))
                        >= Math.abs(yGrad * seMag + (xGrad - yGrad) * eMag) /*(3)*/
                    && tmp > Math.abs(yGrad * nwMag + (xGrad - yGrad) * wMag) /*(4)*/
                : (tmp = Math.abs(yGrad * gradMag))
                        >= Math.abs(xGrad * seMag + (yGrad - xGrad) * sMag) /*(3)*/
                    && tmp > Math.abs(xGrad * nwMag + (yGrad - xGrad) * nMag) /*(4)*/) {
          magnitude[y * width + x] =
              gradMag >= MAGNITUDE_LIMIT ? MAGNITUDE_MAX : (int) (MAGNITUDE_SCALE * gradMag);
          // NOTE: The orientation of the edge is not employed by this
          // implementation. It is a simple matter to compute it at
          // this point as: Math.atan2(yGrad, xGrad);
        } else {
          magnitude[y * width + x] = 0;
        }
      }
    }

    ImageIcon icon2 = new ImageIcon(nonMax);
    lbl2.setIcon(icon2);
  }
Exemplo n.º 24
0
 private void setFillColor(int symbolType) {
   penColor = gRef.getColor();
   switch (symbolType) {
     case FTAConstants.SYMB_BASIC:
       gRef.setColor(Preferences.basicInitiatingEventColor);
       break;
     case FTAConstants.SYMB_UNDEV:
       gRef.setColor(Preferences.undevelopedEventColor);
       break;
     case FTAConstants.SYMB_EXTERN:
       gRef.setColor(Preferences.externalEventColor);
       break;
     case FTAConstants.SYMB_INTERMEDIATE:
       gRef.setColor(Preferences.intermediateEventColor);
       break;
     case FTAConstants.SYMB_AND:
       gRef.setColor(Preferences.andGateColor);
       break;
     case FTAConstants.SYMB_OR:
       gRef.setColor(Preferences.orGateColor);
       break;
     case FTAConstants.SYMB_PRIORITY_AND:
       gRef.setColor(Preferences.priorityAndGateColor);
       break;
     case FTAConstants.SYMB_EXCL_OR:
       gRef.setColor(Preferences.exclusiveOrGateColor);
       break;
     case FTAConstants.SYMB_INHIBIT:
       gRef.setColor(Preferences.inhibitGateColor);
       break;
     case FTAConstants.SYMB_CONDITION:
       gRef.setColor(Preferences.conditioningEventColor);
       break;
     case FTAConstants.SYMB_TRANS_IN:
       gRef.setColor(Preferences.transferInColor);
       break;
     case FTAConstants.SYMB_TRANS_OUT:
       gRef.setColor(Preferences.transferOutColor);
       break;
     default:
       gRef.setColor(Preferences.backgroundColor);
       break;
   }
 }
Exemplo n.º 25
0
 private void restoreColor() {
   gRef.setColor(penColor);
 }
Exemplo n.º 26
0
  /**
   * Draws a single view (i.e., a line of text for a wrapped view), wrapping the text onto multiple
   * lines if necessary. Any selected text is rendered with the editor's "selected text" color.
   *
   * @param painter The painter to use to render tokens.
   * @param g The graphics context in which to paint.
   * @param r The rectangle in which to paint.
   * @param view The <code>View</code> to paint.
   * @param fontHeight The height of the font being used.
   * @param y The y-coordinate at which to begin painting.
   * @param selStart The start of the selection.
   * @param selEnd The end of the selection.
   */
  protected void drawViewWithSelection(
      TokenPainter painter,
      Graphics2D g,
      Rectangle r,
      View view,
      int fontHeight,
      int y,
      int selStart,
      int selEnd) {

    float x = r.x;

    LayeredHighlighter h = (LayeredHighlighter) host.getHighlighter();

    RSyntaxDocument document = (RSyntaxDocument) getDocument();
    Element map = getElement();

    int p0 = view.getStartOffset();
    int lineNumber = map.getElementIndex(p0);
    int p1 = view.getEndOffset(); // - 1;

    setSegment(p0, p1 - 1, document, drawSeg);
    // System.err.println("drawSeg=='" + drawSeg + "' (p0/p1==" + p0 + "/" + p1 + ")");
    int start = p0 - drawSeg.offset;
    Token token = document.getTokenListForLine(lineNumber);

    // If this line is an empty line, then the token list is simply a
    // null token.  In this case, the line highlight will be skipped in
    // the loop below, so unfortunately we must manually do it here.
    if (token != null && token.getType() == Token.NULL) {
      h.paintLayeredHighlights(g, p0, p1, r, host, this);
      return;
    }

    // Loop through all tokens in this view and paint them!
    while (token != null && token.isPaintable()) {

      int p = calculateBreakPosition(p0, token, x);
      x = r.x;

      h.paintLayeredHighlights(g, p0, p, r, host, this);

      while (token != null && token.isPaintable() && token.getEndOffset() - 1 < p) { // <=p) {

        // Selection starts in this token
        if (token.containsPosition(selStart)) {

          if (selStart > token.getOffset()) {
            tempToken.copyFrom(token);
            tempToken.textCount = selStart - tempToken.getOffset();
            x = painter.paint(tempToken, g, x, y, host, this);
            tempToken.textCount = token.length();
            tempToken.makeStartAt(selStart);
            // Clone required since token and tempToken must be
            // different tokens for else statement below
            token = new TokenImpl(tempToken);
          }

          int selCount = Math.min(token.length(), selEnd - token.getOffset());
          if (selCount == token.length()) {
            x = painter.paintSelected(token, g, x, y, host, this);
          } else {
            tempToken.copyFrom(token);
            tempToken.textCount = selCount;
            x = painter.paintSelected(tempToken, g, x, y, host, this);
            tempToken.textCount = token.length();
            tempToken.makeStartAt(token.getOffset() + selCount);
            token = tempToken;
            x = painter.paint(token, g, x, y, host, this);
          }

        }

        // Selection ends in this token
        else if (token.containsPosition(selEnd)) {
          tempToken.copyFrom(token);
          tempToken.textCount = selEnd - tempToken.getOffset();
          x = painter.paintSelected(tempToken, g, x, y, host, this);
          tempToken.textCount = token.length();
          tempToken.makeStartAt(selEnd);
          token = tempToken;
          x = painter.paint(token, g, x, y, host, this);
        }

        // This token is entirely selected
        else if (token.getOffset() >= selStart && token.getEndOffset() <= selEnd) {
          x = painter.paintSelected(token, g, x, y, host, this);
        }

        // This token is entirely unselected
        else {
          x = painter.paint(token, g, x, y, host, this);
        }

        token = token.getNextToken();
      }

      // If there's a token that's going to be split onto the next line
      if (token != null && token.isPaintable() && token.getOffset() < p) {

        int tokenOffset = token.getOffset();
        Token orig = token;
        token =
            new TokenImpl(
                drawSeg, tokenOffset - start, p - 1 - start, tokenOffset, token.getType());

        // Selection starts in this token
        if (token.containsPosition(selStart)) {

          if (selStart > token.getOffset()) {
            tempToken.copyFrom(token);
            tempToken.textCount = selStart - tempToken.getOffset();
            x = painter.paint(tempToken, g, x, y, host, this);
            tempToken.textCount = token.length();
            tempToken.makeStartAt(selStart);
            // Clone required since token and tempToken must be
            // different tokens for else statement below
            token = new TokenImpl(tempToken);
          }

          int selCount = Math.min(token.length(), selEnd - token.getOffset());
          if (selCount == token.length()) {
            x = painter.paintSelected(token, g, x, y, host, this);
          } else {
            tempToken.copyFrom(token);
            tempToken.textCount = selCount;
            x = painter.paintSelected(tempToken, g, x, y, host, this);
            tempToken.textCount = token.length();
            tempToken.makeStartAt(token.getOffset() + selCount);
            token = tempToken;
            x = painter.paint(token, g, x, y, host, this);
          }

        }

        // Selection ends in this token
        else if (token.containsPosition(selEnd)) {
          tempToken.copyFrom(token);
          tempToken.textCount = selEnd - tempToken.getOffset();
          x = painter.paintSelected(tempToken, g, x, y, host, this);
          tempToken.textCount = token.length();
          tempToken.makeStartAt(selEnd);
          token = tempToken;
          x = painter.paint(token, g, x, y, host, this);
        }

        // This token is entirely selected
        else if (token.getOffset() >= selStart && token.getEndOffset() <= selEnd) {
          x = painter.paintSelected(token, g, x, y, host, this);
        }

        // This token is entirely unselected
        else {
          x = painter.paint(token, g, x, y, host, this);
        }

        token = new TokenImpl(orig);
        ((TokenImpl) token).makeStartAt(p);
      }

      p0 = (p == p0) ? p1 : p;
      y += fontHeight;
    } // End of while (token!=null && token.isPaintable()).

    // NOTE: We should re-use code from Token (paintBackground()) here,
    // but don't because I'm just too lazy.
    if (host.getEOLMarkersVisible()) {
      g.setColor(host.getForegroundForTokenType(Token.WHITESPACE));
      g.setFont(host.getFontForTokenType(Token.WHITESPACE));
      g.drawString("\u00B6", x, y - fontHeight);
    }
  }
Exemplo n.º 27
0
  public void run() {
    Thread me = Thread.currentThread();
    while (getSize().width <= 0) {
      try {
        anim.sleep(500);
      } catch (InterruptedException e) {
        return;
      }
    }

    Graphics2D g2d = null;
    Graphics2D BufferG2D = null;
    Graphics2D ScreenG2D = null;
    BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f);
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    int rule = AlphaComposite.SRC_OVER;
    AlphaComposite opaque = AlphaComposite.SrcOver;
    AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f);
    AlphaComposite set = AlphaComposite.Src;
    int frame = 0;
    int frametmp = 0;
    Dimension oldSize = getSize();
    Shape clippath = null;
    while (anim == me) {
      Dimension size = getSize();
      if (size.width != oldSize.width || size.height != oldSize.height) {
        img = null;
        clippath = null;
        if (BufferG2D != null) {
          BufferG2D.dispose();
          BufferG2D = null;
        }
        if (ScreenG2D != null) {
          ScreenG2D.dispose();
          ScreenG2D = null;
        }
      }
      oldSize = size;

      if (img == null) {
        img = (BufferedImage) createImage(size.width, size.height);
      }

      if (BufferG2D == null) {
        BufferG2D = img.createGraphics();
        BufferG2D.setRenderingHint(
            RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
        BufferG2D.setClip(clippath);
      }
      g2d = BufferG2D;

      float[] ctrlpts;
      for (int i = 0; i < animpts.length; i += 2) {
        animate(animpts, deltas, i + 0, size.width);
        animate(animpts, deltas, i + 1, size.height);
      }
      ctrlpts = animpts;
      int len = ctrlpts.length;
      gp.reset();
      int dir = 0;
      float prevx = ctrlpts[len - 2];
      float prevy = ctrlpts[len - 1];
      float curx = ctrlpts[0];
      float cury = ctrlpts[1];
      float midx = (curx + prevx) / 2.0f;
      float midy = (cury + prevy) / 2.0f;
      gp.moveTo(midx, midy);
      for (int i = 2; i <= ctrlpts.length; i += 2) {
        float x1 = (midx + curx) / 2.0f;
        float y1 = (midy + cury) / 2.0f;
        prevx = curx;
        prevy = cury;
        if (i < ctrlpts.length) {
          curx = ctrlpts[i + 0];
          cury = ctrlpts[i + 1];
        } else {
          curx = ctrlpts[0];
          cury = ctrlpts[1];
        }
        midx = (curx + prevx) / 2.0f;
        midy = (cury + prevy) / 2.0f;
        float x2 = (prevx + midx) / 2.0f;
        float y2 = (prevy + midy) / 2.0f;
        gp.curveTo(x1, y1, x2, y2, midx, midy);
      }
      gp.closePath();

      g2d.setComposite(set);
      g2d.setBackground(backgroundColor);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

      if (bgChanged || bounds == null) {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height
      // + 5);
      g2d.clearRect(0, 0, getWidth(), getHeight());

      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setColor(outerColor);
      g2d.setComposite(opaque);
      g2d.setStroke(solid);
      g2d.draw(gp);
      g2d.setPaint(gradient);

      if (!bgChanged) {
        bounds = gp.getBounds();
      } else {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      gradient =
          new GradientPaint(
              bounds.x,
              bounds.y,
              gradientColorA,
              bounds.x + bounds.width,
              bounds.y + bounds.height,
              gradientColorB,
              true);
      g2d.setComposite(blend);
      g2d.fill(gp);

      if (g2d == BufferG2D) {
        repaint();
      }
      ++frame;
      Thread.yield();
    }
    if (g2d != null) {
      g2d.dispose();
    }
  }