Ejemplo n.º 1
0
 /** Overrides <code>Graphics.copyArea</code>. */
 public void copyArea(int x, int y, int width, int height, int destX, int destY) {
   if (debugLog()) {
     info()
         .log(
             toShortString()
                 + " Copying area from: "
                 + new Rectangle(x, y, width, height)
                 + " to: "
                 + new Point(destX, destY));
   }
   graphics.copyArea(x, y, width, height, destX, destY);
 }
Ejemplo n.º 2
0
  public void paintcomponent(Graphics g) {
    if (image == null) return;

    int imageWidth = image.getWidth(this);
    int imageHeight = image.getHeight(this);

    g.drawImage(image, 0, 0, null);

    for (int i = 0; i * imageWidth <= getWidth(); i++)
      for (int j = 0; j * imageHeight <= getHeight(); j++)
        if (i + j > 0) g.copyArea(0, 0, imageWidth, imageHeight, i * imageWidth, j * imageHeight);
  }
Ejemplo n.º 3
0
 public void update(double slowdown, double arrival) {
   freeway.update(slowdown, arrival);
   if (buffer == null) {
     xsize = size().width;
     ysize = size().height;
     buffer = createImage(xsize, ysize);
   }
   Graphics bg = buffer.getGraphics();
   freeway.paint(bg, row, XDOTDIST, DOTSIZE);
   if (row < ysize - 2 * DOTSIZE + 1) row += DOTSIZE;
   else {
     bg.copyArea(0, DOTSIZE, xsize, ysize - DOTSIZE, 0, -DOTSIZE);
     bg.clearRect(0, ysize - DOTSIZE, xsize, DOTSIZE);
   }
   bg.dispose();
   repaint();
 }
  private static void shearY(Graphics g, int w1, int h1, Color color) {

    int period = random.nextInt(40) + 10; // 50;

    boolean borderGap = true;
    int frames = 20;
    int phase = 7;
    for (int i = 0; i < w1; i++) {
      double d =
          (double) (period >> 1)
              * Math.sin(
                  (double) i / (double) period
                      + (6.2831853071795862D * (double) phase) / (double) frames);
      g.copyArea(i, 0, 1, h1, 0, (int) d);
      if (borderGap) {
        g.setColor(color);
        g.drawLine(i, (int) d, i, 0);
        g.drawLine(i, (int) d + h1, i, h1);
      }
    }
  }
  private static void shearX(Graphics g, int w1, int h1, Color color) {

    int period = random.nextInt(2);

    boolean borderGap = true;
    int frames = 1;
    int phase = random.nextInt(2);

    for (int i = 0; i < h1; i++) {
      double d =
          (double) (period >> 1)
              * Math.sin(
                  (double) i / (double) period
                      + (6.2831853071795862D * (double) phase) / (double) frames);
      g.copyArea(0, i, w1, 1, (int) d, 0);
      if (borderGap) {
        g.setColor(color);
        g.drawLine((int) d, i, 0, i);
        g.drawLine((int) d + w1, i, w1, i);
      }
    }
  }
  /**
   * Update the plot
   *
   * @param dataPoint contains y values to plot
   */
  protected void updateChart(double[] dataPoint) {
    if (m_previousY[0] == -1) {
      int iw = m_plotPanel.getWidth();
      int ih = m_plotPanel.getHeight();
      m_osi = m_plotPanel.createImage(iw, ih);
      Graphics m = m_osi.getGraphics();
      m.fillRect(0, 0, iw, ih);
      m_previousY[0] = convertToPanelY(0);
      m_iheight = ih;
      m_iwidth = iw;
    }

    if (dataPoint.length - 1 != m_previousY.length) {
      m_previousY = new double[dataPoint.length - 1];
      //      m_plotCount = 0;
      for (int i = 0; i < dataPoint.length - 1; i++) {
        m_previousY[i] = convertToPanelY(0);
      }
    }

    Graphics osg = m_osi.getGraphics();
    Graphics g = m_plotPanel.getGraphics();

    osg.copyArea(m_refreshWidth, 0, m_iwidth - m_refreshWidth, m_iheight, -m_refreshWidth, 0);
    osg.setColor(Color.black);
    osg.fillRect(m_iwidth - m_refreshWidth, 0, m_iwidth, m_iheight);

    // paint the old scale onto the plot if a scale update has occured
    if (m_yScaleUpdate) {
      String maxVal = numToString(m_oldMax);
      String minVal = numToString(m_oldMin);
      String midVal = numToString((m_oldMax - m_oldMin) / 2.0);
      if (m_labelMetrics == null) {
        m_labelMetrics = g.getFontMetrics(m_labelFont);
      }
      osg.setFont(m_labelFont);
      int wmx = m_labelMetrics.stringWidth(maxVal);
      int wmn = m_labelMetrics.stringWidth(minVal);
      int wmd = m_labelMetrics.stringWidth(midVal);

      int hf = m_labelMetrics.getAscent();
      osg.setColor(m_colorList[m_colorList.length - 1]);
      osg.drawString(maxVal, m_iwidth - wmx, hf - 2);
      osg.drawString(midVal, m_iwidth - wmd, (m_iheight / 2) + (hf / 2));
      osg.drawString(minVal, m_iwidth - wmn, m_iheight - 1);
      m_yScaleUpdate = false;
    }

    double pos;
    for (int i = 0; i < dataPoint.length - 1; i++) {
      osg.setColor(m_colorList[(i % m_colorList.length)]);
      pos = convertToPanelY(dataPoint[i]);
      osg.drawLine(m_iwidth - m_refreshWidth, (int) m_previousY[i], m_iwidth - 1, (int) pos);
      m_previousY[i] = pos;
      if (dataPoint[dataPoint.length - 1] % m_xValFreq == 0) {
        // draw the actual y value onto the plot for this curve
        String val = numToString(dataPoint[i]);
        if (m_labelMetrics == null) {
          m_labelMetrics = g.getFontMetrics(m_labelFont);
        }
        int hf = m_labelMetrics.getAscent();
        if (pos - hf < 0) {
          pos += hf;
        }
        int w = m_labelMetrics.stringWidth(val);
        osg.setFont(m_labelFont);
        osg.drawString(val, m_iwidth - w, (int) pos);
      }
    }

    // last element in the data point array contains the data point number
    if (dataPoint[dataPoint.length - 1] % m_xValFreq == 0) {

      String xVal = "" + (int) dataPoint[dataPoint.length - 1];
      osg.setColor(m_colorList[m_colorList.length - 1]);
      int w = m_labelMetrics.stringWidth(xVal);
      osg.setFont(m_labelFont);
      osg.drawString(xVal, m_iwidth - w, m_iheight - 1);
    }
    g.drawImage(m_osi, 0, 0, m_plotPanel);
    //    System.err.println("Finished");
    //    m_plotCount++;
  }