@Override
 public void print(Graphics g) {
   // We assume we print the whole frame,
   // so we expect no clip was set previously
   Shape shape = AWTAccessor.getWindowAccessor().getShape((Window) target);
   if (shape != null) {
     g.setClip(shape);
   }
   super.print(g);
 }
Example #2
0
  private void replaceSurfaceData(
      int newBackBufferCount, BufferCapabilities newBackBufferCaps, boolean blit) {
    synchronized (surfaceDataLock) {
      final SurfaceData oldData = getSurfaceData();
      surfaceData = platformWindow.replaceSurfaceData();
      // TODO: volatile image
      //        VolatileImage oldBB = backBuffer;
      BufferedImage oldBB = backBuffer;
      backBufferCount = newBackBufferCount;
      backBufferCaps = newBackBufferCaps;
      final Rectangle size = getSize();
      if (getSurfaceData() != null && oldData != getSurfaceData()) {
        clearBackground(size.width, size.height);
      }

      if (blit) {
        blitSurfaceData(oldData, getSurfaceData());
      }

      if (oldData != null && oldData != getSurfaceData()) {
        // TODO: drop oldData for D3D/WGL pipelines
        // This can only happen when this peer is being created
        oldData.flush();
      }

      // TODO: volatile image
      //        backBuffer = (VolatileImage)delegate.createBackBuffer();
      backBuffer = (BufferedImage) platformWindow.createBackBuffer();
      if (backBuffer != null) {
        Graphics g = backBuffer.getGraphics();
        try {
          Rectangle r = getBounds();
          if (g instanceof Graphics2D) {
            ((Graphics2D) g).setComposite(AlphaComposite.Src);
          }
          g.setColor(nonOpaqueBackground);
          g.fillRect(0, 0, r.width, r.height);
          if (g instanceof SunGraphics2D) {
            ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion());
          }
          if (!isTextured()) {
            g.setColor(getBackground());
            g.fillRect(0, 0, r.width, r.height);
          }
          if (oldBB != null) {
            // Draw the old back buffer to the new one
            g.drawImage(oldBB, 0, 0, null);
            oldBB.flush();
          }
        } finally {
          g.dispose();
        }
      }
    }
    flushOnscreenGraphics();
  }
Example #3
0
 @Override
 public void flip(int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction) {
   final BufferedImage buffer = (BufferedImage) getBackBuffer();
   if (buffer == null) {
     throw new IllegalStateException("Buffers have not been created");
   }
   final Graphics g = getGraphics();
   try {
     g.drawImage(buffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
   } finally {
     g.dispose();
   }
   if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
     final Graphics2D bg = (Graphics2D) buffer.getGraphics();
     try {
       bg.setBackground(getBackground());
       bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight());
     } finally {
       bg.dispose();
     }
   }
 }
  /*
   * Print the native component by rendering the Motif look ourselves.
   * ToDo(aim): needs to query native motif for more accurate size and
   * color information.
   */
  public void print(Graphics g) {
    Choice ch = (Choice) target;
    Dimension d = ch.size();
    Color bg = ch.getBackground();
    Color fg = ch.getForeground();

    g.setColor(bg);
    g.fillRect(2, 2, d.width - 1, d.height - 1);
    draw3DRect(g, bg, 1, 1, d.width - 2, d.height - 2, true);
    draw3DRect(g, bg, d.width - 18, (d.height / 2) - 3, 10, 6, true);

    g.setColor(fg);
    g.setFont(ch.getFont());
    FontMetrics fm = g.getFontMetrics();
    String lbl = ch.getSelectedItem();
    g.drawString(lbl, 5, (d.height + fm.getMaxAscent() - fm.getMaxDescent()) / 2);

    target.print(g);
  }
Example #5
0
 private void clearBackground(final int w, final int h) {
   final Graphics g = getOnscreenGraphics(getForeground(), getBackground(), getFont());
   if (g != null) {
     try {
       if (g instanceof Graphics2D) {
         ((Graphics2D) g).setComposite(AlphaComposite.Src);
       }
       if (isTranslucent()) {
         g.setColor(nonOpaqueBackground);
         g.fillRect(0, 0, w, h);
       }
       if (!isTextured()) {
         if (g instanceof SunGraphics2D) {
           ((SunGraphics2D) g).constrain(0, 0, w, h, getRegion());
         }
         g.setColor(getBackground());
         g.fillRect(0, 0, w, h);
       }
     } finally {
       g.dispose();
     }
   }
 }
Example #6
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);
  }