Java Code Examples for java.awt.Graphics2D#getRenderingHint()

The following examples show how to use java.awt.Graphics2D#getRenderingHint() . 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: Axis.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws an axis line at the current cursor position and edge.
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    Line2D axisLine = null;
    double x = dataArea.getX();
    double y = dataArea.getY();
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(x, cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(x, cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, y, cursor, dataArea.getMaxY());
    } else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, y, cursor, dataArea.getMaxY());
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(axisLine);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 2
Source File: FastScatterPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea,
        List ticks) {

    if (!isRangeGridlinesVisible()) {
        return;
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        double v = this.rangeAxis.valueToJava2D(tick.getValue(),
                dataArea, RectangleEdge.LEFT);
        Line2D line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
        g2.setPaint(getRangeGridlinePaint());
        g2.setStroke(getRangeGridlineStroke());
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 3
Source File: FastScatterPlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea,
        List ticks) {

    if (!isRangeGridlinesVisible()) {
        return;
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        double v = this.rangeAxis.valueToJava2D(tick.getValue(),
                dataArea, RectangleEdge.LEFT);
        Line2D line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
        g2.setPaint(getRangeGridlinePaint());
        g2.setStroke(getRangeGridlineStroke());
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 4
Source File: DrawPictureShape.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an ImageRenderer for the PictureData
 *
 * @param graphics
 * @return the image renderer
 */
public static ImageRenderer getImageRenderer(Graphics2D graphics, String contentType) {
    ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER);
    if (renderer != null) {
        return renderer;
    }
    
    if (PictureType.WMF.contentType.equals(contentType)) {
        try {
            @SuppressWarnings("unchecked")
            Class<? extends ImageRenderer> irc = (Class<? extends ImageRenderer>)
                Thread.currentThread().getContextClassLoader().loadClass(WMF_IMAGE_RENDERER);
            return irc.newInstance();
        } catch (Exception e) {
            // WMF image renderer is not on the classpath, continuing with BitmapRenderer
            // although this doesn't make much sense ...
            LOG.log(POILogger.ERROR, "WMF image renderer is not on the classpath - include poi-scratchpad jar!", e);
        }
    }
    
    return new BitmapImageRenderer();
}
 
Example 5
Source File: FontPanel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static Integer getDefaultLCDContrast() {
    if (defaultContrast == null) {
        GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    Graphics2D g2d =
        (Graphics2D)(gc.createCompatibleImage(1,1).getGraphics());
    defaultContrast = (Integer)
        g2d.getRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST);
    }
    return defaultContrast;
}
 
Example 6
Source File: AbstractCategoryItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    // TODO: In JFreeChart 1.2.0, put this method in the
    // CategoryItemRenderer interface
    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 7
Source File: XYPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a domain crosshair.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 *
 * @since 1.0.4
 */
protected void drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line;
    if (orientation == PlotOrientation.VERTICAL) {
        double xx = axis.valueToJava2D(value, dataArea,
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
    } else {
        double yy = axis.valueToJava2D(value, dataArea,
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy,
                dataArea.getMaxX(), yy);
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 8
Source File: GraphicsBox.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Graphics2D g2, float x, float y) {
    AffineTransform oldAt = g2.getTransform();
    Object oldKey = null;
    if (interp != null) {
        oldKey = g2.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interp);
    }
    g2.translate(x, y - height);
    g2.scale(scl, scl);
    g2.drawImage(image, 0, 0, null);
    g2.setTransform(oldAt);
    if (oldKey != null) {
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldKey);
    }
}
 
Example 9
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Enables the antialiasing rendering hint for the scaled graphics and
 * returns the previous hint value.
 * The returned null value indicates that the passed graphics is not
 * instance of Graphics2D.
 *
 * @param g the graphics
 * @return the previous antialiasing rendering hint value if the passed
 * graphics is instance of Graphics2D, null otherwise.
 */
public static Object getAndSetAntialisingHintForScaledGraphics(Graphics g) {
    if (isScaledGraphics(g) && isLocalDisplay()) {
        Graphics2D g2d = (Graphics2D) g;
        Object hint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        return hint;
    }
    return null;
}
 
Example 10
Source File: IGCheckBox.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void paint(Graphics g) {
	
	Graphics2D g2 = (Graphics2D)g;
	
	Object rh = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
	g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	
	g2.setFont(getFont());
	
	int size = 16;
	if (isEnabled() || !editable) {
		g2.setColor(getForeground());
	} else {
		g2.setColor(Color.GRAY);
	}
	g2.drawRect(0, check.getHeight() - size, size - 1, size - 1);
	g2.drawRect(1, check.getHeight() - size + 1, size - 3, size - 3);
	
	if (isSelected()) {
		if (isEnabled() || !editable) {
			g2.drawImage(check, 0, 0, null);
		} else {
			g2.drawImage(checkGs, 0, 0, null);
		}
	}
	
	int dy = check.getHeight();
	
	g2.drawString(getText(), size + 6, dy);

	g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, rh);
}
 
Example 11
Source File: AbstractXYItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a grid line against the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the value at which the grid line should be drawn.
 */
@Override
public void drawDomainGridLine(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea,
            plot.getDomainAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }

    Paint paint = plot.getDomainGridlinePaint();
    Stroke stroke = plot.getDomainGridlineStroke();
    g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
    g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 12
Source File: XYPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a domain crosshair.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 *
 * @since 1.0.4
 */
protected void drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line;
    if (orientation == PlotOrientation.VERTICAL) {
        double xx = axis.valueToJava2D(value, dataArea,
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
    } else {
        double yy = axis.valueToJava2D(value, dataArea,
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy,
                dataArea.getMaxX(), yy);
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 13
Source File: AbstractXYItemRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a line perpendicular to the domain axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @since 1.0.5
 */
public void drawDomainLine(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, 
            plot.getDomainAxisEdge());
    if (orientation.isHorizontal()) {
        line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(),
                v);
    } else if (orientation.isVertical()) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 14
Source File: XYPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a range crosshair.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 *
 * @since 1.0.4
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (!axis.getRange().contains(value)) {
        return;
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
    } else {
        double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy,
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 15
Source File: RoundBorder.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        Graphics2D g2 = (Graphics2D)g;

        g2.setPaint(fillColor);
        // NOTE: fillRoundRect seems to have poor performance on Linux
//            g2.fillRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
//                             width - borderStrokeWidth, height - borderStrokeWidth,
//                             arcRadius * 2, arcRadius * 2);

        int arcRadius2 = arcRadius * 2;
        int arcRadius2p1 = arcRadius2 + 1;

        g2.fillArc(x, y, arcRadius2, arcRadius2, 90, 90);
        g2.fillArc(x + width - arcRadius2p1, y, arcRadius2, arcRadius2, 0, 90);
        g2.fillArc(x, y + height - arcRadius2p1, arcRadius2, arcRadius2, 180, 90);
        g2.fillArc(x + width - arcRadius2p1, y + height - arcRadius2p1, arcRadius2, arcRadius2, 270, 90);

        g2.fillRect(x + arcRadius, y, width - arcRadius2p1, height);
        g2.fillRect(x, y + arcRadius, arcRadius, height - arcRadius2p1);
        g2.fillRect(x + width - arcRadius - 1, y + arcRadius, arcRadius, height - arcRadius2p1);

        Object aa = null;
        Object sc = null;
        if (!forceSpeed) {
            aa = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
            sc = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        }

        g2.setStroke(borderStroke);
        g2.setPaint(lineColor);
        g2.drawRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
                         width - borderStrokeWidth, height - borderStrokeWidth,
                         arcRadius * 2, arcRadius * 2);

        if (!forceSpeed) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, sc);
        }
    }
 
Example 16
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public static float drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             float x,
                             float y,
                             boolean useFPAPI) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    float nextX = x + getFontCharsWidth(data, offset, length,
                                        getFontMetrics(c, g),
                                        useFPAPI);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                            trimmedText) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    Object aaHint = (c == null)
                        ? null
                        : c.getClientProperty(KEY_TEXT_ANTIALIASING);

    if (!(g instanceof Graphics2D)) {
        g.drawChars(data, offset, length, (int) x, (int) y);
        return nextX;
    }

    Graphics2D g2 = (Graphics2D) g;
    if (aaHint != null) {

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (aaHint != null && aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, aaHint);
        } else {
            oldAAValue = null;
        }

        Object lcdContrastHint = c.getClientProperty(KEY_TEXT_LCD_CONTRAST);
        if (lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    lcdContrastHint);
            }
        }

        g2.drawString(new String(data, offset, length), x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g2.drawString(new String(data, offset, length), x, y);
    }
    return nextX;
}
 
Example 17
Source File: LineBorder.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the border by filling in the reserved space (in black).
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area) {
    double w = area.getWidth();
    double h = area.getHeight();
    // if the area has zero height or width, we shouldn't draw anything
    if (w <= 0.0 || h <= 0.0) {
        return;
    }
    double t = this.insets.calculateTopInset(h);
    double b = this.insets.calculateBottomInset(h);
    double l = this.insets.calculateLeftInset(w);
    double r = this.insets.calculateRightInset(w);
    double x = area.getX();
    double y = area.getY();
    double x0 = x + l / 2.0;
    double x1 = x + w - r / 2.0;
    double y0 = y + h - b / 2.0;
    double y1 = y + t / 2.0;
    g2.setPaint(getPaint());
    g2.setStroke(getStroke());
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line = new Line2D.Double();
    if (t > 0.0) {
        line.setLine(x0, y1, x1, y1);
        g2.draw(line);
    }
    if (b > 0.0) {
        line.setLine(x0, y0, x1, y0);
        g2.draw(line);
    }
    if (l > 0.0) {
        line.setLine(x0, y0, x0, y1);
        g2.draw(line);
    }
    if (r > 0.0) {
        line.setLine(x1, y0, x1, y1);
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 18
Source File: LineBorder.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the border by filling in the reserved space (in black).
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area) {
    double w = area.getWidth();
    double h = area.getHeight();
    // if the area has zero height or width, we shouldn't draw anything
    if (w <= 0.0 || h <= 0.0) {
        return;
    }
    double t = this.insets.calculateTopInset(h);
    double b = this.insets.calculateBottomInset(h);
    double l = this.insets.calculateLeftInset(w);
    double r = this.insets.calculateRightInset(w);
    double x = area.getX();
    double y = area.getY();
    double x0 = x + l / 2.0;
    double x1 = x + w - r / 2.0;
    double y0 = y + h - b / 2.0;
    double y1 = y + t / 2.0;
    g2.setPaint(getPaint());
    g2.setStroke(getStroke());
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line = new Line2D.Double();
    if (t > 0.0) {
        line.setLine(x0, y1, x1, y1);
        g2.draw(line);
    }
    if (b > 0.0) {
        line.setLine(x0, y0, x1, y0);
        g2.draw(line);
    }
    if (l > 0.0) {
        line.setLine(x0, y0, x0, y1);
        g2.draw(line);
    }
    if (r > 0.0) {
        line.setLine(x1, y0, x1, y1);
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 19
Source File: LineBorder.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the border by filling in the reserved space (in black).
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area) {
    double w = area.getWidth();
    double h = area.getHeight();
    // if the area has zero height or width, we shouldn't draw anything
    if (w <= 0.0 || h <= 0.0) {
        return;
    }
    double t = this.insets.calculateTopInset(h);
    double b = this.insets.calculateBottomInset(h);
    double l = this.insets.calculateLeftInset(w);
    double r = this.insets.calculateRightInset(w);
    double x = area.getX();
    double y = area.getY();
    double x0 = x + l / 2.0;
    double x1 = x + w - r / 2.0;
    double y0 = y + h - b / 2.0;
    double y1 = y + t / 2.0;
    g2.setPaint(getPaint());
    g2.setStroke(getStroke());
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line = new Line2D.Double();
    if (t > 0.0) {
        line.setLine(x0, y1, x1, y1);
        g2.draw(line);
    }
    if (b > 0.0) {
        line.setLine(x0, y0, x1, y0);
        g2.draw(line);
    }
    if (l > 0.0) {
        line.setLine(x0, y0, x0, y1);
        g2.draw(line);
    }
    if (r > 0.0) {
        line.setLine(x1, y0, x1, y1);
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 20
Source File: DrawFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return a FontManager, either registered beforehand or a default implementation
 *
 * @param graphics the graphics context holding potentially a font manager
 * @return the font manager
 */
public DrawFontManager getFontManager(Graphics2D graphics) {
    DrawFontManager fontHandler = (DrawFontManager)graphics.getRenderingHint(Drawable.FONT_HANDLER);
    return (fontHandler != null) ? fontHandler : new DrawFontManagerDefault();
}