Java Utililty Methods Graphics Settings

List of utility methods to do Graphics Settings

Description

The list of methods to do Graphics Settings are organized into topic(s).

Method

GraphicsConfigurationgetTransparentGraphicsConfiguration()
get Transparent Graphics Configuration
try {
    Class<?> awtUtilitiesType = Class.forName("com.sun.awt.AWTUtilities");
    Method isTC = awtUtilitiesType.getMethod("isTranslucencyCapable",
            new Class[] { GraphicsConfiguration.class });
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    GraphicsConfiguration translucencyCapableGC = null;
    for (int i = 0; (i < devices.length) && (translucencyCapableGC == null); ++i) {
...
voidgradientFillShape(Graphics2D g, Color startColor, Color endColor, Shape shape)
gradient Fill Shape
initializeGraphics2D(g);
GradientPaint gp = getGradientPaint(startColor, endColor, shape);
g.setPaint(gp);
g.fill(shape);
voidgradientPaint(Graphics2D g2d, Point2D startPosition, Color startColor, Point2D endPosition, Color endColor, int sx, int sy, int ex, int ey)
gradient Paint
GradientPaint gradient = new GradientPaint(startPosition, startColor, endPosition, endColor, true);
g2d.setPaint(gradient);
g2d.fillRect(sx, sy, ex, ey);
voidsetClip(Graphics g, Rectangle clipBounds)
set Clip
Rectangle currentClipBounds;
clipBounds = new Rectangle(clipBounds);
clipBounds.width += 1;
clipBounds.height += 1;
currentClipBounds = g.getClipBounds();
if (currentClipBounds != null) {
    clipBounds = clipBounds.intersection(g.getClipBounds());
clipBoundsStack.push(currentClipBounds);
g.setClip(clipBounds);
voidsetRenderingHints(Graphics2D g)
set optimal rendering
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
        RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
...
voidsetRenderingHints(Graphics2D g2d)
set Rendering Hints
RenderingHints rh = g2d.getRenderingHints();
rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHints(rh);
voidsetTextRenderingHints(Graphics2D g2d)
set Text Rendering Hints
RenderingHints rh = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
rh.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
rh.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
rh.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, new Integer(140));
rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
...
voidsetupGraphics(Graphics2D pG2d)
setup Graphics
pG2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
pG2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
pG2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
        RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
pG2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
pG2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
pG2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
...