Package de.xima.fc.graphics
Class ActiveGraphics2D
- java.lang.Object
-
- de.xima.fc.graphics.ActiveGraphics2D
-
- All Implemented Interfaces:
AutoCloseable
public final class ActiveGraphics2D extends Object implements AutoCloseable
Wrapper for aGraphics2D
instance that disposes of the instance automatically when closed. Also has static methods for creating new wrappers.- Author:
- XIMA MEDIA GmbH
-
-
Field Summary
Fields Modifier and Type Field Description Graphics2D
g2d
The underlyingGraphics2D
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static ActiveGraphics2D
fromImage(BufferedImage image)
Creates
and wraps a Graphics2D instance, which can be used to draw into the givenBufferedImage
.static ActiveGraphics2D
wrap(Graphics2D g2d)
Wraps a Graphics2D instance.
-
-
-
Field Detail
-
g2d
public final Graphics2D g2d
The underlyingGraphics2D
instance.
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
fromImage
public static ActiveGraphics2D fromImage(BufferedImage image)
Creates
and wraps a Graphics2D instance, which can be used to draw into the givenBufferedImage
. The wrapper returned by this method implementsAutoCloseable
so that you can use with try-with-resources-statements instead of having to dispose the graphics 2D instance manually.- Parameters:
image
- Buffered image on which to draw.- Returns:
- A
Graphics2D
wrapper thatdisposes
the underlying resource automatically when closed.
-
wrap
public static ActiveGraphics2D wrap(Graphics2D g2d)
Wraps a Graphics2D instance. The wrapper returned by this method implementsAutoCloseable
so that you can use with try-with-resources-statements instead of having to dispose the graphics 2D instance manually.- Parameters:
g2d
- Instance to wrap.- Returns:
- A
Graphics2D
wrapper thatdisposes
the underlying resource automatically when closed.
-
-