Java Code Examples for java.awt.Component#getGraphics()

The following examples show how to use java.awt.Component#getGraphics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BufferedImageGraphicsConfig.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
Example 2
Source File: BufferedImageGraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
Example 3
Source File: AWTComponentRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the graphics context of the given component.
 * @param destination the AWT component used for rendering.
 * @return the graphics context of the given component.
 */
protected Graphics getGraphics(Component destination) {
  if (destination != null) {

    if (destination.getGraphics() != null) {
      return destination.getGraphics();
    } else {
      System.out.println("AWT component "+destination.getClass().getSimpleName()+" does not provide 2D graphics capabilities.");
      return null;
      //throw new IllegalArgumentException("AWT component "+destination.getClass().getSimpleName()+" does not provide 2D graphics capabilities.");
    }
  } else {
    throw new NullPointerException("Component cannot be null.");
  }
}
 
Example 4
Source File: BufferedImageGraphicsConfig.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
Example 5
Source File: BufferedImageGraphicsConfig.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
Example 6
Source File: BufferedImageGraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
Example 7
Source File: BufferedImageGraphicsConfig.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
Example 8
Source File: BufferedImageGraphicsConfig.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp,
                                   double scaleX, double scaleY)
{
    if (comp == null) {
        device = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        device = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.scaleX = scaleX;
    this.scaleY = scaleY;
}
 
Example 9
Source File: RepaintArea.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 10
Source File: RepaintArea.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 11
Source File: RepaintArea.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 12
Source File: RepaintArea.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 13
Source File: RepaintArea.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 14
Source File: RepaintArea.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to {@code paint} or {@code update}
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 15
Source File: RepaintArea.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to {@code paint} or {@code update}
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 16
Source File: RepaintArea.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 17
Source File: RepaintArea.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 18
Source File: RepaintArea.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 19
Source File: RepaintArea.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
Example 20
Source File: RepaintArea.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}