Example #1
0
  /**
   * Draw the vectors at the data points. If this data has been attached to an Axis then scale the
   * data based on the axis maximum/minimum otherwise scale using the data's maximum/minimum
   *
   * @param g Graphics state
   * @param bounds The data window to draw into
   */
  public void draw_data(Graphics g, Rectangle bounds) {
    Color c;

    if (xaxis != null) {
      xmax = xaxis.maximum;
      xmin = xaxis.minimum;
    }

    if (yaxis != null) {
      ymax = yaxis.maximum;
      ymin = yaxis.minimum;
    }

    xrange = xmax - xmin;
    yrange = ymax - ymin;

    /*
     ** draw the legend before we clip the data window
     */
    draw_legend(g, bounds);
    /*
     ** Clip the data window
     */
    if (clipping) g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);

    c = g.getColor();

    if (linecolor != null) g.setColor(linecolor);
    else g.setColor(c);

    drawVectors(g, bounds);

    g.setColor(c);
  }
  /**
   * Paints the View.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  @Override
  public void paint(Graphics g, Shape a) {
    sync();

    Rectangle rect = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();

    Image image = getImage();
    Rectangle clip = g.getClipBounds();

    fBounds.setBounds(rect);
    paintHighlights(g, a);
    paintBorder(g, rect);
    if (clip != null) {
      g.clipRect(
          rect.x + leftInset,
          rect.y + topInset,
          rect.width - leftInset - rightInset,
          rect.height - topInset - bottomInset);
    }
    if (image != null) {
      if (!hasPixels(image)) {
        // No pixels yet, use the default
        Icon icon = (image == null) ? getNoImageIcon() : getLoadingImageIcon();

        if (icon != null) {
          icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset);
        }
      } else {
        // Draw the image
        g.drawImage(image, rect.x + leftInset, rect.y + topInset, width, height, imageObserver);
      }
    } else {
      Icon icon = getNoImageIcon();

      if (icon != null) {
        icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset);
      }
      View view = getAltView();
      // Paint the view representing the alt text, if its non-null
      if (view != null && ((state & WIDTH_FLAG) == 0 || width > DEFAULT_WIDTH)) {
        // Assume layout along the y direction
        Rectangle altRect =
            new Rectangle(
                rect.x + leftInset + DEFAULT_WIDTH,
                rect.y + topInset,
                rect.width - leftInset - rightInset - DEFAULT_WIDTH,
                rect.height - topInset - bottomInset);

        view.paint(g, altRect);
      }
    }
    if (clip != null) {
      // Reset clip.
      g.setClip(clip.x, clip.y, clip.width, clip.height);
    }
  }
Example #3
0
 /** Overrides <code>Graphics.clipRect</code>. */
 public void clipRect(int x, int y, int width, int height) {
   graphics.clipRect(x, y, width, height);
   if (debugLog()) {
     info()
         .log(
             toShortString()
                 + " Setting clipRect: "
                 + (new Rectangle(x, y, width, height))
                 + " New clipRect: "
                 + graphics.getClip());
   }
 }
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    if (Options.getAsBoolean(Options.DRAW_FPS, Options.VALUE_FALSE)) {
      Font.draw(screen, texts.FPS(fps), 10, 10);
    }

    if (player != null && menuStack.size() == 0) {
      if (isMultiplayer) {
        Font.draw(screen, texts.latency(latencyCacheReady() ? "" + avgLatency() : "-"), 10, 20);
      }

      Font.draw(screen, texts.health(player.health, player.maxHealth), 340, screen.h - 16);
      Font.draw(screen, texts.money(player.score), 340, screen.h - 27);
      Font.draw(screen, texts.nextLevel((int) player.getNextLevel()), 340, screen.h - 38);
      Font.draw(screen, texts.playerExp((int) player.pexp), 340, screen.h - 49);
      Font.draw(screen, texts.playerLevel(player.plevel), 340, screen.h - 60);
    }

    if (isMultiplayer && menuStack.isEmpty()) {
      chat.render(screen);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }
  }
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    Font.draw(screen, "FPS: " + fps, 10, 10);
    // for (int p = 0; p < players.length; p++) {
    // if (players[p] != null) {
    // String msg = "P" + (p + 1) + ": " + players[p].getScore();
    // Font.draw(screen, msg, 320, screen.h - 24 + p * 8);
    // }
    // }
    if (player != null && menuStack.size() == 0) {
      Font.draw(screen, player.health + " / 10", 340, screen.h - 19);
      Font.draw(screen, "" + player.score, 340, screen.h - 33);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }

    // String msg = "FPS: " + fps;
    // g.setColor(Color.LIGHT_GRAY);
    // g.drawString(msg, 11, 11);
    // g.setColor(Color.WHITE);
    // g.drawString(msg, 10, 10);

  }
Example #6
0
  /**
   * This method will draw the axes (if axes mode is on) and the line.
   *
   * @param gc the graphics
   * @see #setAxes
   * @see #setLog
   */
  void drawAll(Graphics gc) {
    Dimension osize = getSize();

    gc.setColor(getBackground());
    gc.fillRect(0, 0, osize.width, osize.height);

    gc.clipRect(0, 0, osize.width, osize.height);

    if (doAxes) {
      gc.setColor(axisColour);
      gc = paintAxis(gc);
    }

    gc.setColor(getBackground());
    gc.fillRect(0, 0, osize.width, osize.height); // trust the clip

    if (dataSet != null) {
      gc.setColor(graphColour);
      paintLine(gc);
    }
  }
Example #7
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (painter != null) {
      Shape shape = getShape();

      if (shape != null) {
        Shape clip = g.getClip();
        g.clipRect(
            shapedInsets.left,
            shapedInsets.top,
            getWidth() - shapedInsets.left - shapedInsets.right,
            getHeight() - shapedInsets.top - shapedInsets.bottom);
        ((Graphics2D) g).clip(shape);
        painter.paint(
            this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip);
        g.setClip(clip);
      } else
        painter.paint(
            this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip);
    }
  }
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    boolean drawFPS = Options.get("drawFPS") != null && Options.get("drawFPS").equals("true");
    if (drawFPS) {
      Font.draw(screen, texts.FPS(fps), 10, 10);
    }

    if (player != null && menuStack.size() == 0) {
      Font.draw(screen, texts.health(player.health, player.maxHealth), 340, screen.h - 16);
      Font.draw(screen, texts.money(player.score), 340, screen.h - 27);
      Font.draw(screen, texts.nextLevel((int) player.getNextLevel()), 340, screen.h - 38);
      Font.draw(screen, texts.playerExp((int) player.pexp), 340, screen.h - 49);
      Font.draw(screen, texts.playerLevel(player.plevel), 340, screen.h - 60);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }
  }
Example #9
0
 /**
  * Draws this histogram in the drawing panel.
  *
  * @param drawingPanel
  * @param g
  */
 public synchronized void draw(DrawingPanel drawingPanel, Graphics g) {
   if (bins.size() == 0) {
     return;
   }
   Shape oldClip = g.getClip();
   g.setColor(binFillColor);
   g.clipRect(0, 0, drawingPanel.getWidth(), drawingPanel.getHeight());
   for (Iterator keys = bins.keySet().iterator(); keys.hasNext(); ) {
     Integer binNumber = (Integer) keys.next();
     Double d = (Double) (bins.get(binNumber));
     if (d == null) return;
     double occurences = d.doubleValue();
     if (normalizedToOne) {
       occurences /= sum;
     }
     if (binStyle == DRAW_BIN) {
       drawBin(drawingPanel, g, binNumber.intValue(), occurences);
     } else {
       drawPoint(drawingPanel, g, binNumber.intValue(), occurences);
     }
   }
   g.setClip(oldClip);
 }
  public void paintTabArea(TabbedPanel tp, Graphics g, int x, int y, int width, int height) {
    int heightTemp = height;
    int widthTemp = width;
    int xTemp = x;
    int yTemp = y;
    if (enabled && tp.isTabAreaVisible()) {

      tabData.initialize(tp);

      PanePainter pane = paneHandler.getPainter(tabData.getAreaOrientation());

      initTabLocations(pane);
      Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation());

      if (tp.getTabCount() > 0) {
        // Adjust x, y
        if (tabData.getAreaOrientation() == Direction.DOWN) {
          yTemp += tabData.getTabbedPanelHeight() - heightTemp;
        } else if (tabData.getAreaOrientation() == Direction.RIGHT) {
          xTemp += tabData.getTabbedPanelWidth() - widthTemp;
        }

        widthTemp = xTemp < 0 ? widthTemp + xTemp : widthTemp;
        heightTemp = yTemp < 0 ? heightTemp + yTemp : heightTemp;

        xTemp = Math.max(0, xTemp);
        yTemp = Math.max(0, yTemp);

        if (tabData.isHorizontalLayout())
          pane.setSize(tabData.getTabbedPanelSize().width, getTabbedPanelExtraSize());
        else pane.setSize(getTabbedPanelExtraSize(), tabData.getTabbedPanelHeight());

        if (PAINT_TAB_AREA && !(pane.getTabCount() == 0 && tabData.getTabCount() > 0)) {
          Shape originalClip = g.getClip();

          int tx =
              -xTemp
                  - (tabData.getAreaOrientation() == Direction.RIGHT
                      ? -tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize()
                      : 0);
          int ty =
              -yTemp
                  - (tabData.getAreaOrientation() == Direction.DOWN
                      ? -tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize()
                      : 0);

          Rectangle firstVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(0);
          Rectangle lastVisibleRect =
              (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1);
          Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabCount() - 1);

          if (tabData.isHorizontalLayout()) {
            int extraWidth =
                lastTab.getWidth() == lastVisibleRect.width
                    ? 0
                    : 2 * tabData.getTabbedPanelSize().width - tabData.getTabAreaWidth();
            pane.setSize(pane.getWidth() + extraWidth, pane.getHeight());

            pane.doValidation();

            // Before tabs
            g.clipRect(
                0,
                0,
                aInsets.left + (firstVisibleRect.width > 0 && firstVisibleRect.x == 0 ? 1 : 0),
                heightTemp);
            pane.paint(g, tx, ty);
            g.setClip(originalClip);

            // After tabs
            tx -= extraWidth;

            int clipExtraWidth = extraWidth == 0 ? 1 : 0;
            g.clipRect(
                aInsets.left + tabData.getTabAreaWidth() - clipExtraWidth,
                0,
                widthTemp - aInsets.left - tabData.getTabAreaWidth() + clipExtraWidth,
                heightTemp);
            pane.paint(g, tx, ty);
            g.setClip(originalClip);
          } else {
            int extraHeight =
                lastTab.getHeight() == lastVisibleRect.height
                    ? 0
                    : 2 * tabData.getTabbedPanelSize().height - tabData.getTabAreaHeight();
            pane.setSize(pane.getWidth(), pane.getHeight() + extraHeight);

            pane.doValidation();

            // Before tabs
            g.clipRect(
                0,
                0,
                widthTemp,
                aInsets.top + (firstVisibleRect.height > 0 && firstVisibleRect.y == 0 ? 1 : 0));
            pane.paint(g, tx, ty);
            g.setClip(originalClip);

            // After tabs
            ty -= extraHeight;

            int clipExtraHeight = extraHeight == 0 ? 1 : 0;
            g.clipRect(
                0,
                aInsets.top + tabData.getTabAreaHeight() - clipExtraHeight,
                widthTemp,
                heightTemp - aInsets.top - tabData.getTabAreaHeight() + clipExtraHeight);
            pane.paint(g, tx, ty);
            g.setClip(originalClip);
          }
        }

        // First and last tab
        paintTabs(pane, tabData, g, xTemp, yTemp, widthTemp, heightTemp);

        tabData.reset();

        reset(pane);
      }
    }
  }
Example #11
0
  /*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) {
    final boolean expandToFit = (mWidth < 1);

    if (DEBUG.IMAGE && DEBUG.META)
      out(
          "paintIcon; onto="
              + GUI.name(c)
              + " painter="
              + GUI.name(mPainter)
              + "@"
              + Integer.toHexString((mPainter.hashCode())));

    if (mPainter == null) {
      // note this means repaint updates would stop in a new parent,
      // tho assuming it's loaded by then, regular paints would work fine.
      mPainter = c;
    }

    if (DrawBorder && !expandToFit) {
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
    }

    if (mImage == null) {

      if (!isLoading /*&& mPreviewData != null*/) {
        synchronized (this) {
          if (!isLoading /*&& mPreviewData != null*/)
            VUE.invokeAfterAWT(ResourceIcon.this); // load the preview
        }
      }
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      return;
    }

    int fitWidth, fitHeight;
    final Dimension maxImageSize;

    if (expandToFit) {
      // fill the given component
      fitWidth = c.getWidth();
      fitHeight = c.getHeight();
      maxImageSize = c.getSize();
    } else {
      // paint at our fixed size
      fitWidth = mWidth;
      fitHeight = mHeight;

      if (DrawBorder)
        maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2);
      else maxImageSize = new Dimension(fitWidth, fitHeight);

      if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize));
    }

    double zoomFit;
    if (mImage == NoImage && expandToFit) {
      zoomFit = 1;
    } else {
      Rectangle2D imageBounds;
      if (CropToSquare) {
        // square off image, then fit in icon (todo: better; crop to icon)
        int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth;
        imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis);
      } else {
        // fit entire image in icon
        imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight);
      }
      zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false);
      if (zoomFit > MaxZoom) zoomFit = MaxZoom;
    }

    final int drawW = (int) (mImageWidth * zoomFit + 0.5);
    final int drawH = (int) (mImageHeight * zoomFit + 0.5);

    int xoff = x;
    int yoff = y;

    // center if drawable area is bigger than image
    if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2;
    if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2;

    Shape oldClip = null;
    if (CropToSquare && !expandToFit) {
      oldClip = g.getClip();
      g.clipRect(x, y, mWidth, mHeight);
    }

    if (DEBUG.IMAGE && DEBUG.META)
      out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH);
    g.drawImage(mImage, xoff, yoff, drawW, drawH, null);

    if (DEBUG.BOXES) {
      g.setColor(Color.green);
      ((Graphics2D) g)
          .setComposite(
              java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f));
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver);
    }

    if (CropToSquare && !expandToFit) g.setClip(oldClip);
  }
Example #12
0
 /**
  * Renders using the given rendering surface and area on that surface. The view may need to do
  * layout and create child views to enable itself to render into the given allocation.
  *
  * @param g the rendering surface to use
  * @param a the allocated region to render into
  * @see View#paint
  */
 public void paint(Graphics g, Shape a) {
   Rectangle r = (Rectangle) a;
   g.clipRect(r.x, r.y, r.width, r.height);
   super.paint(g, a);
 }
    @Override
    protected void paintComponent(Graphics g) {
      if (isLoading) {
        return;
      }

      g.translate(-left, -top);

      if (image != null) {
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g2.scale(zoom, zoom);
        g2.drawImage(image, 0, 0, null);
        if (overlay != null && showOverlay) {
          g2.setComposite(overlayAlpha);
          g2.drawImage(overlay, 0, image.getHeight() - overlay.getHeight(), null);
        }
        g2.dispose();
      }

      int width = getWidth();
      int height = getHeight();

      Graphics2D g2 = null;
      if (width != this.width || height != this.height) {
        this.width = width;
        this.height = height;

        grid = new BufferedImage(width + zoom + 1, height + zoom + 1, BufferedImage.TYPE_INT_ARGB);
        clearGrid = true;
        g2 = grid.createGraphics();
      } else if (clearGrid) {
        g2 = grid.createGraphics();
        g2.setComposite(AlphaComposite.Clear);
        g2.fillRect(0, 0, grid.getWidth(), grid.getHeight());
        g2.setComposite(AlphaComposite.SrcOver);
      }

      if (clearGrid) {
        clearGrid = false;

        g2.setColor(lineColor);
        width += zoom;
        height += zoom;

        for (int x = zoom; x <= width; x += zoom) {
          g2.drawLine(x, 0, x, height);
        }

        for (int y = 0; y <= height; y += zoom) {
          g2.drawLine(0, y, width, y);
        }

        g2.dispose();
      }

      if (image != null) {
        g.getClipBounds(clip);
        g.clipRect(0, 0, image.getWidth() * zoom + 1, image.getHeight() * zoom + 1);
        g.drawImage(grid, clip.x - clip.x % zoom, clip.y - clip.y % zoom, null);
      }

      g.translate(left, top);
    }
 public final void paint(final Graphics g) {
   final Rectangle bounds = getBounds();
   if (myAnchor == ToolWindowAnchor.LEFT) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, myOffset - bounds.width, 0, null);
     } else {
       g.setClip(null);
       g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, -myOffset, 0, null);
     }
     myTopImage.flush();
   } else if (myAnchor == ToolWindowAnchor.RIGHT) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(0, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, bounds.width - myOffset, 0, null);
     } else {
       g.setClip(null);
       g.clipRect(0, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, myOffset, 0, null);
     }
   } else if (myAnchor == ToolWindowAnchor.TOP) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, myOffset);
       UIUtil.drawImage(g, myTopImage, 0, -bounds.height + myOffset, null);
     } else {
       g.setClip(null);
       g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myTopImage, 0, -myOffset, null);
     }
   } else if (myAnchor == ToolWindowAnchor.BOTTOM) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset);
       UIUtil.drawImage(g, myTopImage, 0, bounds.height - myOffset, null);
     } else {
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myTopImage, 0, myOffset, null);
     }
   }
 }
  private void paintTabs(
      PanePainter pane, TabData tabData, Graphics g, int x, int y, int width, int height) {
    if (enabled && PAINT_TAB) {
      Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabList().size() - 1);
      Rectangle lastVisibleRect =
          (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1);

      // Fix post/pre tabs
      initPaintableTabLocations(pane);

      Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation());

      Point l = getLocationInTabbedPanel(lastTab, tabData.getTabbedPanel());

      if (tabData.isHorizontalLayout()) {
        int w =
            aInsets.left
                + aInsets.right
                + Math.max(0, tabData.getTabAreaWidth() - l.x - lastVisibleRect.width)
                + EXTRA_SIZE;

        for (int i = 0; i < tabData.getTabList().size(); i++)
          w += ((Tab) tabData.getTabList().get(i)).getWidth();

        pane.setSize(w, getTabbedPanelExtraSize());
      } else {
        int h =
            aInsets.top
                + aInsets.bottom
                + Math.max(0, tabData.getTabAreaHeight() - l.y - lastVisibleRect.height)
                + EXTRA_SIZE;

        for (int i = 0; i < tabData.getTabList().size(); i++)
          h += ((Tab) tabData.getTabList().get(i)).getHeight();

        pane.setSize(getTabbedPanelExtraSize(), h);
      }

      pane.doValidation();

      int index = tabData.getPreTab() == null ? 0 : tabData.getTabCount() > 1 ? 1 : 0;

      Shape originalClip = g.getClip();

      int tx =
          -x
              - (tabData.getAreaOrientation() == Direction.RIGHT
                  ? -tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize()
                  : 0);
      int ty =
          -y
              - (tabData.getAreaOrientation() == Direction.DOWN
                  ? -tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize()
                  : 0);

      Rectangle visibleRect = (Rectangle) tabData.getVisibleTabRects().get(index);
      Tab tab = (Tab) tabData.getTabList().get(index);

      if (tabData.isHorizontalLayout()) {
        tx -=
            (tabData.getPreTab() != null
                ? tab.getX() - tabData.getPreTab().getX() + visibleRect.x
                : visibleRect.x);
        g.clipRect(aInsets.left, 0, tabData.getTabAreaWidth(), height);
      } else {
        ty -=
            (tabData.getPreTab() != null
                ? tab.getY() - tabData.getPreTab().getY() + visibleRect.y
                : visibleRect.y);
        g.clipRect(0, aInsets.top, width, tabData.getTabAreaHeight());
      }

      applyFocusAndHover(pane, true);
      pane.paint(g, tx, ty);
      applyFocusAndHover(pane, false);

      g.setClip(originalClip);
    }
  }
Example #16
0
  public void print(Graphics g) {
    TextField txt = (TextField) target;
    Dimension d = txt.size();
    int w = d.width - (2 * BORDER);
    int h = d.height - (2 * BORDER);
    Color bg = txt.getBackground();
    Color fg = txt.getForeground();
    Color highlight = bg.brighter();
    String text = txt.getText();
    int moved = 0;
    int selStart = 0;
    int selEnd = 0;

    g.setFont(txt.getFont());
    g.setColor(txt.isEditable() ? highlight : bg);
    g.fillRect(BORDER, BORDER, w, h);

    g.setColor(bg);
    // g.drawRect(0, 0, d.width-1, d.height-1);
    draw3DRect(g, bg, 1, 1, d.width - 3, d.height - 3, false);

    if (text != null) {
      g.clipRect(BORDER, MARGIN, w, d.height - (2 * MARGIN));
      FontMetrics fm = g.getFontMetrics();

      w = d.width - BORDER;
      h = d.height - (2 * MARGIN);
      int xs = pos2x(selStart) - moved;
      int xe = pos2x(selEnd) - moved;

      if ((xs < MARGIN) && (xe > w)) {
        g.setColor(highlight);
        g.fillRect(BORDER, MARGIN, w - BORDER, h);
      } else {
        g.setColor(bg);
        // g.fillRect(BORDER, MARGIN, w - BORDER, h);

        if ((xs >= MARGIN) && (xs <= w)) {
          g.setColor(highlight); // selected text

          if (xe > w) {
            g.fillRect(xs, MARGIN, w - xs, h);
          } else if (xs == xe) {
            // g.fillRect(xs, MARGIN, 1, h);
          } else {
            g.fillRect(xs, MARGIN, xe - xs, h);
          }
        } else if ((xe >= MARGIN) && (xe <= w)) {
          g.setColor(highlight);
          g.fillRect(BORDER, MARGIN, xe - BORDER, h);
        }
      }
      g.setColor(fg);
      int x = MARGIN - moved;
      char echoChar = txt.getEchoChar();
      if (echoChar == 0) {
        g.drawString(text, x, BORDER + MARGIN + fm.getMaxAscent());
      } else {
        char data[] = new char[text.length()];
        for (int i = 0; i < data.length; i++) {
          data[i] = echoChar;
        }
        g.drawChars(data, 0, data.length, x, BORDER + MARGIN + fm.getMaxAscent());
      }
    }

    target.print(g);
  }
Example #17
0
 void clip(Graphics g, HorizontalSliderTick t) {
   g.clipRect(t.x - width / 2, t.y0, width + 1, height + 1);
 }
Example #18
0
  /** Paints the slider control. */
  @Override
  public void paint(Graphics g) {

    if (tick.length == 0) return;

    HorizontalSliderTick t;

    g.clipRect(0, 0, width, height);

    thumb.draw(g, tick[curPos]);

    if (prevPos != curPos) thumb.clip(g, tick[prevPos]);

    g.setColor(getBackground());
    g.fillRect(0, 0, width, height);

    g.setColor(Color.black);

    int x0, x1, y, w = width - 1, h = height - 1;
    boolean end;

    if (showBorder) g.drawRect(0, 0, w, h);

    for (int i = 0; i < tick.length; ++i) {
      end = i == 0 || i == tick.length - 1;

      t = tick[i];

      if (style == TICK_TOP || style == TICK_BOTH)
        g.drawLine(t.x, t.y0 + (end ? 0 : 1), t.x, t.y0 + TICK_HEIGHT);

      if (style == TICK_BOTTOM || style == TICK_BOTH)
        g.drawLine(t.x, t.y1 - TICK_HEIGHT, t.x, t.y1 - (end ? 0 : 1));
    }

    t = tick[0];

    y = (t.y1 + t.y0) / 2;
    x0 = t.x - 5;
    x1 = tick[tick.length - 1].x + 5;

    g.drawLine(x0, y, x1, y);

    g.setColor(Color.gray);
    g.drawLine(x1 + 1, y - 1, x0 - 1, y - 1);
    g.drawLine(x0 - 1, y - 1, x0 - 1, y + 1);

    g.setColor(Color.lightGray);
    g.drawLine(x0, y + 1, x1 + 1, y + 1);
    g.drawLine(x1 + 1, y + 1, x1 + 1, y);

    g.setColor(Color.white);
    g.drawLine(x0 - 1, y + 2, x1 + 2, y + 2);
    g.drawLine(x1 + 2, y + 2, x1 + 2, y - 1);

    g.clipRect(0, 0, width, height);

    thumb.draw(g, tick[curPos]);

    prevPos = curPos;
  }
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Shape old = g.getClip();
   g.clipRect(x, y + myDelegate.getIconHeight() - 2 - myHeight, myWidth, myHeight + 2);
   myDelegate.paintIcon(c, g, x, y);
   g.setClip(old);
 }