Java Code Examples for java.awt.image.VolatileImage#getWidth()
The following examples show how to use
java.awt.image.VolatileImage#getWidth() .
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: RepaintManager.java From Java8CN with Apache License 2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 2
Source File: LGraphics.java From RipplePower with Apache License 2.0 | 5 votes |
public LGraphics(VolatileImage awtImage) { this.width = awtImage.getWidth(); this.height = awtImage.getHeight(); this.g2d = awtImage.createGraphics(); this.g2d.setClip(0, 0, width, height); this.store.save(g2d); }
Example 3
Source File: RepaintManager.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 4
Source File: RepaintManager.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 5
Source File: RepaintManager.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 6
Source File: RepaintManager.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 7
Source File: LevelIndicator.java From visualvm with GNU General Public License v2.0 | 5 votes |
private Color getColorAt(VolatileImage img, int x, int y) { if ((x <= 0) || (y < 0) || (x > img.getWidth()) || (y > img.getHeight())) { return null; } int RGB = img.getSnapshot().getRGB(x - 1, 0); int red = (RGB & 0x00ff0000) >> 16; int green = (RGB & 0x0000ff00) >> 8; int blue = RGB & 0x000000ff; // and the Java Color is ... return new Color(red, green, blue); }
Example 8
Source File: RepaintManager.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 9
Source File: RepaintManager.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 10
Source File: RepaintManager.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 11
Source File: RepaintManager.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 12
Source File: RepaintManager.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @param c the component * @param proposedWidth the width of the buffer * @param proposedHeight the height of the buffer * * @return the volatile image * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 13
Source File: RepaintManager.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @param c the component * @param proposedWidth the width of the buffer * @param proposedHeight the height of the buffer * * @return the volatile image * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 14
Source File: RepaintManager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 15
Source File: RepaintManager.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 16
Source File: RepaintManager.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 17
Source File: RepaintManager.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 18
Source File: SimpleCachedPainter.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
@Override public void paint(Graphics2D g, Object o, int width, int height) { GraphicsConfiguration gc = g.getDeviceConfiguration(); if (cache == null) { // called for the first time or was invalidated createAndUseCachedImage(g, gc, width, height); return; } VolatileImage vi = cache.get(); if (vi == null) { // soft reference collected createAndUseCachedImage(g, gc, width, height); return; } if (vi.getWidth() != width || vi.getHeight() != height) { // size changed vi.flush(); createAndUseCachedImage(g, gc, width, height); return; } // at this point we have a cached image with the right size int safetyCounter = 0; // to be 100% sure that this is not an infinite loop do { int valCode = vi.validate(gc); // check before rendering if (valCode == VolatileImage.IMAGE_OK) { // simplest case, just use the image g.drawImage(vi, 0, 0, null); } else if (valCode == VolatileImage.IMAGE_RESTORED) { // memory loss, but the the image object can be reused renderAndUseCachedImage(vi, g, width, height); } else if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) { // surface incompatibility: the image has to be recreated vi.flush(); vi = createAndUseCachedImage(g, gc, width, height); } } while (vi.contentsLost() && safetyCounter++ < 3); // check after rendering }
Example 19
Source File: RepaintManager.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Return a volatile offscreen buffer that should be used as a * double buffer with the specified component <code>c</code>. * The image returned will be an instance of VolatileImage, or null * if a VolatileImage object could not be instantiated. * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. * This happens when the maximum double buffer size has been set for this * repaint manager. * * @see java.awt.image.VolatileImage * @since 1.4 */ public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,int proposedHeight) { RepaintManager delegate = getDelegate(c); if (delegate != null) { return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight); } // If the window is non-opaque, it's double-buffered at peer's level Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); if (!w.isOpaque()) { Toolkit tk = Toolkit.getDefaultToolkit(); if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { return null; } } GraphicsConfiguration config = c.getGraphicsConfiguration(); if (config == null) { config = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } Dimension maxSize = getDoubleBufferMaximumSize(); int width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width? maxSize.width : proposedWidth); int height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height? maxSize.height : proposedHeight); VolatileImage image = volatileMap.get(config); if (image == null || image.getWidth() < width || image.getHeight() < height) { if (image != null) { image.flush(); } image = config.createCompatibleVolatileImage(width, height, volatileBufferType); volatileMap.put(config, image); } return image; }
Example 20
Source File: AbstractRegionPainter.java From seaglass with Apache License 2.0 | 4 votes |
/** * Gets the rendered image for this painter at the requested size, either * from cache or create a new one * * @param config the graphics configuration. * @param c the component to paint. * @param w the component width. * @param h the component height. * @param extendedCacheKeys extended cache keys. * * @return the new image. */ private VolatileImage getImage(GraphicsConfiguration config, JComponent c, int w, int h, Object[] extendedCacheKeys) { ImageCache imageCache = ImageCache.getInstance(); // get the buffer for this component VolatileImage buffer = (VolatileImage) imageCache.getImage(config, w, h, this, extendedCacheKeys); int renderCounter = 0; // to avoid any potential, though unlikely, // infinite loop do { // validate the buffer so we can check for surface loss int bufferStatus = VolatileImage.IMAGE_INCOMPATIBLE; if (buffer != null) { bufferStatus = buffer.validate(config); } // If the buffer status is incompatible or restored, then we need to // re-render to the volatile image if (bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE || bufferStatus == VolatileImage.IMAGE_RESTORED) { // if the buffer is null (hasn't been created), or isn't the // right size, or has lost its contents, // then recreate the buffer if (buffer == null || buffer.getWidth() != w || buffer.getHeight() != h || bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE) { // clear any resources related to the old back buffer if (buffer != null) { buffer.flush(); buffer = null; } // recreate the buffer buffer = config.createCompatibleVolatileImage(w, h, Transparency.TRANSLUCENT); // put in cache for future imageCache.setImage(buffer, config, w, h, this, extendedCacheKeys); } // create the graphics context with which to paint to the buffer Graphics2D bg = buffer.createGraphics(); // clear the background before configuring the graphics bg.setComposite(AlphaComposite.Clear); bg.fillRect(0, 0, w, h); bg.setComposite(AlphaComposite.SrcOver); configureGraphics(bg); // paint the painter into buffer paintDirectly(bg, c, w, h, extendedCacheKeys); // close buffer graphics bg.dispose(); } } while (buffer.contentsLost() && renderCounter++ < 3); // check if we failed if (renderCounter == 3) return null; // return image return buffer; }