/**
   * Draws the edge.
   *
   * @param graphics the graphics context
   */
  public void draw(Graphics2D graphics) {
    updateContactPoints();

    Color oldColor = graphics.getColor();
    Stroke oldStroke = graphics.getStroke();

    graphics.setColor(getBorderColor());
    graphics.setStroke(getLineStyle());
    graphics.draw(getPath());
    graphics.setStroke(oldStroke);
    graphics.setColor(oldColor);
  }
Esempio n. 2
0
 /**
  * Draws this without refreshing steps.
  *
  * @param panel the drawing panel requesting the drawing
  * @param _g the graphics context on which to draw
  */
 public void drawMe(DrawingPanel panel, Graphics _g) {
   // position and show inspector if requested during loading
   if (inspectorX != Integer.MIN_VALUE
       && trackerPanel != null
       && trackerPanel.getTFrame() != null) {
     positionInspector();
     Runnable runner =
         new Runnable() {
           public void run() {
             showInspector = false;
             inspector.setVisible(true);
           }
         };
     if (showInspector) SwingUtilities.invokeLater(runner);
   }
   if (isVisible() && isTraceVisible()) {
     // draw trace only if fixed coords & (non-worldview or no ref frame)
     TrackerPanel tPanel = (TrackerPanel) panel;
     ImageCoordSystem coords = tPanel.getCoords(); // get active coords
     boolean isRefFrame = coords instanceof ReferenceFrame;
     if (isRefFrame) {
       coords = ((ReferenceFrame) coords).getCoords();
     }
     boolean fixed = coords.isFixedAngle() && coords.isFixedOrigin() && coords.isFixedScale();
     if (fixed && (!(tPanel instanceof WorldTView) || !isRefFrame)) {
       trace.reset();
       for (int i = 0; i < traceX.length; i++) {
         if (Double.isNaN(traceX[i])) continue;
         tracePt.setLocation(traceX[i], traceY[i]);
         java.awt.Point p = tracePt.getScreenPosition(tPanel);
         if (trace.getCurrentPoint() == null) trace.moveTo((float) p.getX(), (float) p.getY());
         else trace.lineTo((float) p.getX(), (float) p.getY());
       }
       Graphics2D g2 = (Graphics2D) _g;
       Color color = g2.getColor();
       Stroke stroke = g2.getStroke();
       g2.setColor(getFootprint().getColor());
       g2.setStroke(traceStroke);
       g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
       g2.draw(trace);
       // restore original color and stroke
       g2.setColor(color);
       g2.setStroke(stroke);
     }
   }
   super.draw(panel, _g);
 }
Esempio n. 3
0
  void draw(Graphics2D g) {

    int endX, endY;
    Block from = null;
    if (fromId > -1) from = diag.blocks.get(new Integer(fromId));
    Block to = null;
    if (!endsAtLine && toId > -1) to = diag.blocks.get(new Integer(toId));

    if (toX == -1) endX = diag.xa;
    else endX = toX;

    if (toY == -1) endY = diag.ya;
    else endY = toY;

    g.setColor(Color.GRAY);

    Stroke stroke = g.getStroke();
    ZigzagStroke zzstroke = new ZigzagStroke(stroke, 2, 4);

    if (toX == -1) {
      g.drawRect(fromX - 3, fromY - 3, 6, 6);
      return;
    }

    if (from != null) {
      if (fromSide == Side.TOP) fromY = from.cy - from.height / 2;
      else if (fromSide == Side.BOTTOM) fromY = from.cy + from.height / 2;
      else if (fromSide == Side.LEFT) fromX = from.cx - from.width / 2;
      else if (fromSide == Side.RIGHT) fromX = from.cx + from.width / 2;
    }

    if (to != null) {
      if (toSide == Side.TOP) toY = to.cy - to.height / 2;
      else if (toSide == Side.BOTTOM) toY = to.cy + to.height / 2;
      else if (toSide == Side.LEFT) toX = to.cx - to.width / 2;
      else if (toSide == Side.RIGHT) toX = to.cx + to.width / 2;
    }

    if (driver.selArrowP == this) g.setColor(Color.BLUE);
    else if ((from instanceof ComponentBlock
            || from instanceof ExtPortBlock
            || from instanceof Enclosure)
        && (to instanceof ComponentBlock
            || to instanceof ExtPortBlock
            || to instanceof Enclosure
            || endsAtLine))
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
    else if (from instanceof LegendBlock || to instanceof LegendBlock) g.setColor(Color.GRAY);

    int fx, fy, tx, ty;
    fx = fromX;
    fy = fromY;
    // tx = toX;
    // ty = toY;
    // int autoX = -1, autoY = -1;  // only used for automatic ports
    if (bends != null) {
      for (Bend bend : bends) {
        tx = bend.x;
        ty = bend.y;
        if (!dropOldest) g.drawLine(fx, fy, tx, ty);
        else {
          Shape shape = new Line2D.Double(fx, fy, tx, ty);
          shape = zzstroke.createStrokedShape(shape);
          g.draw(shape);
          // g.setStroke(stroke);
        }

        if (bend.marked) {
          Color col = g.getColor();
          g.setColor(Color.RED);
          g.drawOval(tx - 5, ty - 5, 10, 10);
          g.setColor(col);
        }
        calcLimits(fx, tx, fy, ty);
        fx = tx;
        fy = ty;
      }
    }
    tx = endX;
    ty = endY;

    int x = endX;
    if (to != null && endsAtBlock && to.multiplex) {
      String s = to.mpxfactor;
      if (s == null) s = " ";
      int i = s.length() * driver.fontWidth + 10;
      x -= i;
    }

    if (headMarked) {
      Color col = g.getColor();
      g.setColor(Color.RED);
      g.drawOval(x - 5, toY - 5, 10, 10);
      g.setColor(col);
    }

    if (!dropOldest) g.drawLine(fx, fy, tx, ty);
    else {
      Shape shape = new Line2D.Double(fx, fy, tx, ty);
      shape = zzstroke.createStrokedShape(shape);
      g.draw(shape);
      // g.setStroke(stroke);
    }

    if (tailMarked) {
      Color col = g.getColor();
      g.setColor(Color.RED);
      g.drawOval(fromX - 5, fromY - 5, 10, 10);
      g.setColor(col);
    }

    calcLimits(fx, x, fy, toY);

    if (!endsAtBlock && !endsAtLine) {
      g.drawRect(fromX - 3, fromY - 3, 6, 6);
      g.drawRect(x - 3, toY - 3, 6, 6);
    } else if (endsAtBlock) {
      if ((from instanceof ComponentBlock
              || from instanceof ExtPortBlock
              || from instanceof Enclosure)
          && (to instanceof ComponentBlock
              || to instanceof ExtPortBlock
              || to instanceof Enclosure)) {
        Arrowhead ah = new Arrowhead(fx, fy, toX, toY);
        ah.draw(g);
      }

    } else if (endsAtLine) {
      drawCircleTo(g, fx, fy, x, toY, Color.BLACK, 4);
      // g.drawOval(toX - 2, toY - 2, 4, 4);
      // g.fillOval(toX - 2, toY - 2, 4, 4);
    }

    if (toX != -1 && (endsAtBlock || endsAtLine)) {
      if (upStreamPort != null && (from instanceof ComponentBlock || from instanceof Enclosure)) {
        if (upStreamPort.equals("*")) {
          drawCircleFrom(g, fromX, fromY, endX, endY, Color.BLUE, 8);
          // g.setColor(Color.BLUE);
          // g.drawOval(fromX, fromY - 4, 8, 8);
          // g.fillOval(fromX, fromY - 4, 8, 8);
        } else if (from.visible) {
          g.setColor(Color.BLUE);
          int y = fromY + driver.fontHeight;
          int x2 = fromX + driver.fontWidth;
          g.drawString(upStreamPort, x2, y);
        }
        g.setColor(Color.BLACK);
      }
      if (downStreamPort != null
          && !endsAtLine
          && to != null
          && (to instanceof ComponentBlock || to instanceof Enclosure)) {
        if (downStreamPort.equals("*")) {
          drawCircleTo(g, fx, fy, toX, toY, Color.BLUE, 8);
          // g.setColor(Color.BLUE);
          // g.drawOval(x - 8, toY - 4, 8, 8);
          // g.fillOval(x - 8, toY - 4, 8, 8);
        } else if (to.visible) {
          g.setColor(Color.BLUE);
          int y = toY - driver.fontHeight / 2;
          x = toX - driver.fontWidth * (downStreamPort.length() + 1);
          if (!endsAtLine && to != null && to.multiplex) x -= 20;
          g.drawString(downStreamPort, x, y);
        }
        g.setColor(Color.BLACK);
      }
    }
    if (extraArrowhead != null) extraArrowhead.draw(g);
  }
Esempio n. 4
0
  boolean eventHandeler(Graphics2D g2d) {

    if (keyboard.keyDownOnce(KeyEvent.VK_Q)) {
      window.setState(Frame.ICONIFIED);
      paused = true;
    }

    if (firstStartup) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));

      g2d.setFont(new Font("Courier New", Font.PLAIN, 20));
      g2d.setColor(Color.black);
      switch (startupPage) {
        case 1:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 2;

          g2d.drawString("The goal of this game is to kill as", 100, 170);
          g2d.drawString("many *zombies* as possible. You are", 100, 200);
          g2d.drawString("given weapons and power-ups to help", 100, 230);
          g2d.drawString("you succeed. Good luck.", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("Ø O O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Story", 265, 110);
          break;
        case 2:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 3;

          g2d.drawString("Use A,S,D,W to stear", 100, 170);
          g2d.drawString("Use 1,2,3,4 to change weapon", 100, 200);
          g2d.drawString("Use the MOUSE to aim", 100, 230);
          g2d.drawString("Use the LEFT MOUSE BUTTON to fire", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("O Ø O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Controlls", 230, 110);
          break;
        case 3:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) firstStartup = false;

          g2d.setColor(Color.black);
          g2d.draw(new Ellipse2D.Double(100, 170 - 15, 20, 20));
          g2d.setColor(Color.red);
          g2d.draw(new Ellipse2D.Double(100, 200 - 15, 20, 20));
          g2d.setColor(Color.blue);
          g2d.draw(new Ellipse2D.Double(100, 230 - 15, 20, 20));
          g2d.setColor(Color.green);
          g2d.draw(new Ellipse2D.Double(100, 260 - 15, 20, 20));

          g2d.setColor(Color.black);
          g2d.drawString("Is you", 130, 170);
          g2d.drawString("Heals you", 130, 200);
          g2d.drawString("Unlocks / upgrades a weapon", 130, 230);
          g2d.drawString("Causes an explosion around you", 130, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to start", 150, 330);
          g2d.drawString("O O Ø", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Power-ups", 230, 110);
          break;
      }
      return true;
    }

    if (player.isDead) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_R)) restart();

      if (newHighscore) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 320, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("New Highscore"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record was " + oldHighScore + " kills", 210, 260);
      } else if (cheated) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 270, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("You cheated"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Highscore not saved", 210, 260);
      } else {
        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record is " + oldHighScore + " kills", 210, 260);
      }

      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));

      if (player.score == 1) g2d.drawString(String.format(player.score + " kill"), 200, 230);
      else g2d.drawString(String.format(player.score + " kills"), 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press R to restart"), 150, 330);
      return true;
    }

    if (window.isFocused() == false) paused = true;

    if (paused) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = false;
      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));
      g2d.drawString("Paused", 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press ESC to resume"), 150, 330);
      return true;
    }

    return false;
  }
Esempio n. 5
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }
  public void paintRegion(Graphics2D g, int x1, int y1, int w, int h) {
    int h2 = h / 2;
    int rad = 3;
    int diam = rad * 2;

    Color lg = Color.cyan;
    Color dg = Color.orange;

    lg = new Color(lg.getRed(), lg.getGreen(), lg.getBlue(), 75);
    dg = new Color(dg.getRed(), dg.getGreen(), dg.getBlue(), 75);

    /*
     * Draw the Baseline
     */
    g.setColor(Color.black);
    g.drawLine(x1, y1 + h, x1 + w, y1 + h);

    Stroke oldStroke = g.getStroke();
    g.setStroke(new BasicStroke((float) 2.0));

    /*
     * Draw the datapoints
     */
    for (ExprPoint ep : points) {
      if (ep.strand == '+') {
        g.setColor(lg);
      } else {
        g.setColor(dg);
      }

      g.drawOval(x1 + ep.x - rad, y1 + ep.y - rad, diam, diam);
    }

    g.setStroke(oldStroke);

    /*
     * Paint the hash marks...
     */
    if (!displayOppositeChannel) {
      g.setColor(Color.black);
      boolean flipper = true;
      for (int value = 100;
          value <= scale.getMax();
          value *= (flipper ? 5 : 2), flipper = !flipper) {
        int yoff = getYOffset((double) value);
        String line = String.format("%d", value);
        int uy = y1 + h2 - yoff, ly = y1 + h2 + yoff;

        g.drawLine(x1, uy, x1 + 10, uy);
        g.drawString(line, x1 + 12, uy + 5);

        g.drawLine(x1, ly, x1 + 10, ly);
        g.drawString(line, x1 + 12, ly + 5);
      }
    }

    /*
     * Draw any selections.
     */

    g.setColor(Color.black);
    for (Point p : selections.keySet()) {
      ExprPoint ep = selections.get(p);
      g.drawLine(p.x, p.y, ep.x, ep.y);
      g.drawString(ep.getLabel(), p.x, p.y);
    }

    /*
     * Draw the label in the upper-right hand corner.
     */
    g.setColor(Color.black);
    Font oldFont = g.getFont();
    Font newFont = new Font("Arial", Font.BOLD, 24);
    g.setFont(newFont);
    FontMetrics fm = g.getFontMetrics();
    int lblHeight = fm.getAscent() + fm.getDescent();
    int lblWidth = fm.charsWidth(label.toCharArray(), 0, label.length());

    int padding = 5;
    int lblx = x1 + w - lblWidth - padding;
    int lbly = y1 + lblHeight + padding;

    g.drawString(label, lblx, lbly);

    g.setFont(oldFont);
  }