Example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON

Introduction

In this page you can find the example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.

Prototype

Object VALUE_TEXT_ANTIALIAS_ON

To view the source code for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.

Click Source Link

Document

Text antialiasing hint value -- text rendering is done with some form of antialiasing.

Usage

From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java

private ChartPanel createChartPanel() {
    JFreeChart xyChart = ChartFactory.createXYLineChart("f", "x", "y", plotSeries, PlotOrientation.VERTICAL,
            false, true, false);//from  www. j ava  2s.co m
    RenderingHints hints = xyChart.getRenderingHints();
    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    xyChart.setBackgroundPaint(Color.WHITE);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyChart.getXYPlot().getRenderer();
    renderer.setBaseLinesVisible(isLineVisible);
    renderer.setBaseShapesVisible(isSymbolVisible);

    LegendTitle legend = new LegendTitle(renderer);
    legend.setPosition(RectangleEdge.BOTTOM);
    xyChart.addLegend(legend);

    xyChart.getXYPlot().getRangeAxis().setStandardTickUnits(createTickUnits());
    //xyChart.getXYPlot().getRangeAxis().setStandardTickUnits(new StandardTickUnitSource());
    xyChart.getXYPlot().getRangeAxis().setAutoRangeMinimumSize(1.0e-45);

    chartPanel = new ChartPanel(xyChart);

    JPopupMenu popup = chartPanel.getPopupMenu();
    popup.remove(1); // removes separator
    popup.remove(1); // removes save as...
    popup.add(createLinePropMenu());
    popup.add(createAxesPropMenu());
    popup.addSeparator();
    popup.add(createExportMenu());
    return chartPanel;
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

public void drawTable(Graphics gr, Point UL, Dataset dataset, int[] selection, Graphics navgGr,
        int countNavUnit) {

    Font f = getTableFont(squareL - 1);
    AnnotationManager annManager = AnnotationManager.getAnnotationManager();
    String[] rowIds = dataset.getRowIds();

    Set<String> annotations = dataset.getRowAnnotationNamesInUse();
    if (annotations == null) {
        annotations = annManager.getManagedRowAnnotationNames();
    }//from   w  ww  .j  a  v a  2  s. co  m

    String[][] inf; // row annotation matrix
    String[] headers; // header of the row annotation matrix
    if (annotations.isEmpty()) {
        inf = new String[dataset.getDataLength()][1];
        for (int i = 0; i < inf.length; i++) {
            inf[i][0] = rowIds[i];
        }
        headers = new String[] { "Row ID" };
    } else {
        headers = annotations.toArray(new String[annotations.size()]);
        inf = new String[dataset.getDataLength()][annotations.size()];
        for (int i = 0; i < headers.length; i++) {
            //ann manager need to re implemeinted?
            AnnotationLibrary anns = annManager.getRowAnnotations(headers[i]);
            for (int j = 0; j < inf.length; j++) {
                inf[j][i] = rowIds[j];//anns.getAnnotation(rowIds[j]);//
            }
        }
    }

    Graphics2D g2d = (Graphics2D) gr;
    Graphics2D g2dNav = (Graphics2D) navgGr;
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2dNav.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    int X = UL.x;
    int Y = UL.y;
    //        int H = squareL;

    int L = dataset.getDataLength();
    int W = headers.length;

    JLabel l = new JLabel("    ");
    JLabel lNav = new JLabel(" ");
    //        l.setFont(f);
    //        l.setIconTextGap(2);
    javax.swing.border.Border UB = javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 0, Color.WHITE);
    javax.swing.border.Border LB = javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 0, Color.WHITE);

    //          Color borderColor = hex2Rgb("#e3e3e3");
    javax.swing.border.Border navBorder = javax.swing.BorderFactory.createMatteBorder(2, 0, 0, 0, Color.WHITE);

    l.setMaximumSize(new Dimension(200, squareL));
    lNav.setSize(new Dimension(2, 5));
    lNav.setBorder(navBorder);

    boolean drawTableHeader = false;

    //if there is not enough room for a header.. skip header.
    //        if (UL.y < squareL) {
    //            drawTableHeader = false;
    //        }

    if (Wd == null) {
        Wd = new int[inf[0].length];
        WdSUM = new int[inf[0].length];

        if (drawTableHeader) {
            for (int i = 0; i < headers.length; i++) {
                l.setText(headers[i]);
                l.validate();
                if (l.getPreferredSize().width > Wd[i]) {
                    Wd[i] = l.getPreferredSize().width + 16;
                }
            }
        }
        for (String[] inf1 : inf) {
            for (int j = 0; j < Wd.length; j++) {
                if (squareL < 6) {
                    Wd[j] = 5;
                    continue;
                }
                l.setText(inf1[j]);
                l.validate();
                if (l.getPreferredSize().width > Wd[j]) {
                    Wd[j] = l.getPreferredSize().width + 16;
                }
            }
        }

        WdSUM[0] = 0;

        for (int i = 0; i < Wd.length; i++) {
            WdSUM[i] = -1;
            for (int j = 0; j < i; j++) {
                WdSUM[i] += Wd[j] + 3;
            }
        }
    }

    Rectangle BNDS = new Rectangle();

    l.setBackground(Color.WHITE);
    l.setOpaque(true);

    lNav.setBackground(Color.WHITE);
    lNav.setOpaque(true);

    if (sideTree == null) {
        return;
    }

    f = getTableFont(squareL - 1);
    l.setFont(f);

    int[] LArr = sideTree.arrangement;
    int Rindex = 0;

    //draw the table header.. (if wanted)
    //        if (drawTableHeader) {
    //
    //            l.setBackground(Color.WHITE);
    //            l.setForeground(Color.white);
    //
    //            for (int j = 0; j < W; j++) {
    //                X = UL.x + WdSUM[j];
    //                Y = UL.y;
    //                BNDS.setBounds(X, Y, Wd[j], squareL + 1);
    //
    //                if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(BNDS)) {
    //                    continue;
    //                }
    //                gr.translate(X, Y);
    //                l.setBounds(0, 0, Wd[j] + 1, squareL + 1);
    //                l.setBorder(LB);
    //
    //                if (squareL >= 6) {
    //                    l.setText(headers[j]);
    //                }
    //                l.validate();
    //                l.paint(gr);
    //                gr.translate(-X, -Y);
    //            }
    //        }
    l.setForeground(Color.WHITE);

    boolean[] sel = selectedRows((selection == null ? null : selection), dataset);
    boolean coloredNav = false;
    int navCounter = 0;
    for (int i = 0; i < L; i++) {

        Rindex = LArr[i];
        for (int j = 0; j < W; j++) {
            X = UL.x + WdSUM[j];
            Y = UL.y + (squareL * (i + 1));

            BNDS.setBounds(X, Y, Wd[j], squareL + 1);

            if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(BNDS)) {
                continue;
            }

            if (sel[LArr[i]]) {

                for (Group group : dataset.getRowGroups()) {
                    if (group.isActive()) {
                        if (group.hasMember(Rindex)) {
                            l.setBackground(group.getColor());
                            if (!coloredNav) {
                                lNav.setBackground(Color.RED);
                                lNav.setForeground(Color.RED);
                                coloredNav = true;
                            }

                            break;

                        }
                    }

                }

                //                    l.setBackground(new Color(225, 225, 255));
            } else {
                //                   
                //                    if (!coloredNav) {
                //                                    lNav.setBackground(Color.WHITE);
                //                                    lNav.setForeground(Color.WHITE);                                  
                //                                }

                l.setBackground(Color.WHITE);
            }
            if (i != 0)
                gr.translate(X, Y);
            l.setBounds(0, 0, Wd[j] + 1, squareL + 1);

            if (i < L - 1) {
                l.setBorder(UB);
            } else {
                l.setBounds(0, 0, Wd[j] + 1, squareL + 1);
                l.setBorder(LB);
            }
            if (squareL >= 6) {
                l.setText(inf[Rindex][j]);
            }
            l.validate();
            l.paint(gr);
            gr.translate(-X, -Y);

        }
        if (navCounter >= countNavUnit) {
            navCounter = 0;
            lNav.validate();
            lNav.paint(navgGr);
            navgGr.translate(2, 0);
            coloredNav = false;
            lNav.setBackground(Color.WHITE);
            lNav.setForeground(Color.WHITE);

        }
        navCounter++;
    }

    //        if (squareL < 6) {
    //            return;
    //        }
    //
    //        l.setBackground(Color.WHITE);
    //        f = getTableFont(squareL - 2);
    //        //f = new Font("Arial",1,squareL-2);
    //        l.setFont(f);
    //
    //
    //        for (int j = 0; j < W; j++) {
    //            X = UL.x + WdSUM[j];
    //            Y = UL.y;
    //
    //            BNDS.setBounds(X, Y, Wd[j], squareL + 1);
    //            if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(BNDS)) {
    //                continue;
    //            }
    //
    //            gr.translate(X, Y);
    //            l.setBounds(0, 0, Wd[j], squareL + 1);
    ////            l.setBorder(javax.swing.BorderFactory.createLineBorder(GridCol));
    //            l.setText(headers[j]);
    //            l.validate();
    //            gr.translate(-X, -Y);
    //        }

}

From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java

/**
 * @return//from w  w w  .  j av  a2  s.  c  o  m
 */
public static RenderingHints createTextRenderingHints() {
    RenderingHints renderingHints;
    //RenderingHints renderingHints1 = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    RenderingHints renderingHints2 = new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    //RenderingHints renderingHints3 = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    renderingHints = renderingHints2;

    Object value = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
    try {
        java.lang.reflect.Field declaredField = RenderingHints.class
                .getDeclaredField("VALUE_TEXT_ANTIALIAS_LCD_HRGB");
        value = declaredField.get(null);

    } catch (Exception e) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e);
        // do nothing
    }
    renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, value);
    //renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    //renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    //renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB);
    return renderingHints;
}

From source file:au.com.gaiaresources.bdrs.controller.test.TestDataCreator.java

private byte[] createImage(int width, int height, String text) throws IOException {
    if (width < 0) {
        width = random.nextInt(DEFAULT_MAX_IMAGE_WIDTH - DEFAULT_MIN_IMAGE_WIDTH) + DEFAULT_MIN_IMAGE_WIDTH;
    }/*from   www.  j  av  a  2s .  c  om*/
    if (height < 0) {
        height = random.nextInt(DEFAULT_MAX_IMAGE_HEIGHT - DEFAULT_MIN_IMAGE_HEIGHT) + DEFAULT_MIN_IMAGE_HEIGHT;
    }

    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = (Graphics2D) img.getGraphics();
    g2.setBackground(new Color(220, 220, 220));

    Dimension size;
    float fontSize = g2.getFont().getSize();
    // Make the text as large as possible.
    do {
        g2.setFont(g2.getFont().deriveFont(fontSize));
        FontMetrics metrics = g2.getFontMetrics(g2.getFont());
        int hgt = metrics.getHeight();
        int adv = metrics.stringWidth(text);
        size = new Dimension(adv + 2, hgt + 2);
        fontSize = fontSize + 1f;
    } while (size.width < Math.round(0.9 * width) && size.height < Math.round(0.9 * height));

    g2.setColor(Color.DARK_GRAY);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.drawString(text, (width - size.width) / 2, (height - size.height) / 2);
    g2.setColor(Color.LIGHT_GRAY);
    g2.drawRect(0, 0, width - 1, height - 1);

    ByteArrayOutputStream baos = new ByteArrayOutputStream(width * height);
    ImageIO.write(img, "png", baos);
    baos.flush();
    byte[] rawBytes = baos.toByteArray();
    baos.close();

    return rawBytes;
}

From source file:com.projity.contrib.calendar.JXXMonthView.java

/**
 * {@inheritDoc}//ww w  . j  a  va2s.c om
 */
protected void paintComponent(Graphics g) {
    Object oldAAValue = null;
    Graphics2D g2 = (g instanceof Graphics2D) ? (Graphics2D) g : null;
    if (g2 != null && _antiAlias) {
        oldAAValue = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

    Rectangle clip = g.getClipBounds();

    updateIfNecessary();

    if (isOpaque()) {
        g.setColor(getBackground());
        g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }
    g.setColor(getForeground());
    Color shadowColor = g.getColor();
    shadowColor = new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(),
            (int) (.20 * 255));

    FontMetrics fm = g.getFontMetrics();

    // Reset the calendar.
    _cal.setTimeInMillis(_firstDisplayedDate);

    // Center the calendars vertically in the available space.
    int y = _startY;
    for (int row = 0; row < _numCalRows; row++) {
        // Center the calendars horizontally in the available space.
        int x = _startX;
        int tmpX, tmpY;

        // Check if this row falls in the clip region.
        _bounds.x = 0;
        _bounds.y = _startY + row * (_calendarHeight + CALENDAR_SPACING);
        _bounds.width = getWidth();
        _bounds.height = _calendarHeight;

        if (!_bounds.intersects(clip)) {
            _cal.add(Calendar.MONTH, _numCalCols);
            y += _calendarHeight + CALENDAR_SPACING;
            continue;
        }

        for (int column = 0; column < _numCalCols; column++) {
            String monthName = _monthsOfTheYear[_cal.get(Calendar.MONTH)];
            monthName = monthName + " " + _cal.get(Calendar.YEAR);

            _bounds.x = _ltr ? x : x - _calendarWidth;
            _bounds.y = y + _boxPaddingY;
            _bounds.width = _calendarWidth;
            _bounds.height = _boxHeight;

            if (_bounds.intersects(clip)) {
                // Paint month name background.
                paintMonthStringBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height);

                // Paint month name.
                g.setColor(getForeground());
                tmpX = _ltr ? x + (_calendarWidth / 2) - (fm.stringWidth(monthName) / 2)
                        : x - (_calendarWidth / 2) - (fm.stringWidth(monthName) / 2) - 1;
                tmpY = y + _boxPaddingY + _boxHeight - fm.getDescent();

                g.drawString(monthName, tmpX, tmpY);

                if ((_dropShadowMask & MONTH_DROP_SHADOW) != 0) {
                    g.setColor(shadowColor);
                    g.drawString(monthName, tmpX + 1, tmpY + 1);
                    g.setColor(getForeground());
                }
            }

            _bounds.x = _ltr ? x : x - _calendarWidth;
            _bounds.y = y + _boxPaddingY + _boxHeight + _boxPaddingY + _boxPaddingY;
            _bounds.width = _calendarWidth;
            _bounds.height = _boxHeight;

            if (_bounds.intersects(clip)) {
                _cal.set(Calendar.DAY_OF_MONTH, _cal.getActualMinimum(Calendar.DAY_OF_MONTH));
                Calendar weekCal = (Calendar) _cal.clone();
                // Paint short representation of day of the week.
                int dayIndex = _firstDayOfWeek - 1;
                int month = weekCal.get(Calendar.MONTH);
                //               dayIndex = (_cal.get(Calendar.DAY_OF_WEEK) -1) %7;
                for (int i = 0; i < DAYS_IN_WEEK; i++) {
                    //                  PROJITY_MODIFICATION
                    // set the week calendar to the current day of week and make sure it's still in this month
                    weekCal.set(Calendar.DAY_OF_WEEK, dayIndex + 1);
                    if (weekCal.get(Calendar.MONTH) != month)
                        weekCal.roll(Calendar.DAY_OF_YEAR, 7); // make sure in this month

                    tmpX = _ltr
                            ? x + (i * (_boxPaddingX + _boxWidth + _boxPaddingX)) + _boxPaddingX
                                    + (_boxWidth / 2) - (fm.stringWidth(_daysOfTheWeek[dayIndex]) / 2)
                            : x - (i * (_boxPaddingX + _boxWidth + _boxPaddingX)) - _boxPaddingX
                                    - (_boxWidth / 2) - (fm.stringWidth(_daysOfTheWeek[dayIndex]) / 2);
                    tmpY = y + _boxPaddingY + _boxHeight + _boxPaddingY + _boxPaddingY + fm.getAscent();
                    boolean flagged = _flaggedWeekDates[dayIndex];
                    boolean colored = _coloredWeekDates[dayIndex];
                    calculateBoundsForDay(_bounds, weekCal, true);
                    drawDay(colored, flagged, false, g, _daysOfTheWeek[dayIndex], tmpX, tmpY);

                    //                  if ((_dropShadowMask & WEEK_DROP_SHADOW) != 0) {
                    //                     calculateBoundsForDay(_bounds,weekCal,true); // add shadow arg
                    //                     drawDay(colored,flagged,false,g,_daysOfTheWeek[dayIndex], tmpX + 1,
                    //                           tmpY + 1);
                    //                  }
                    if (_selectedWeekDays[dayIndex]) {
                        paintSelectedDayBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height);
                    }
                    dayIndex++;
                    if (dayIndex == 7) {
                        dayIndex = 0;
                    }
                }

                int lineOffset = 2;
                // Paint a line across bottom of days of the week.
                g.drawLine(_ltr ? x + 2 : x - 3, lineOffset + y + (_boxPaddingY * 3) + (_boxHeight * 2),
                        _ltr ? x + _calendarWidth - 3 : x - _calendarWidth + 2,
                        lineOffset + y + (_boxPaddingY * 3) + (_boxHeight * 2));
                if ((_dropShadowMask & MONTH_LINE_DROP_SHADOW) != 0) {
                    g.setColor(shadowColor);
                    g.drawLine(_ltr ? x + 3 : x - 2, y + (_boxPaddingY * 3) + (_boxHeight * 2) + 1,
                            _ltr ? x + _calendarWidth - 2 : x - _calendarWidth + 3,
                            y + (_boxPaddingY * 3) + (_boxHeight * 2) + 1);
                    g.setColor(getForeground());
                }
            }

            // Check if the month to paint falls in the clip.
            _bounds.x = _startX + (_ltr ? column * (_calendarWidth + CALENDAR_SPACING)
                    : -(column * (_calendarWidth + CALENDAR_SPACING) + _calendarWidth));
            _bounds.y = _startY + row * (_calendarHeight + CALENDAR_SPACING);
            _bounds.width = _calendarWidth;
            _bounds.height = _calendarHeight;

            // Paint the month if it intersects the clip. If we don't move
            // the calendar forward a month as it would have if paintMonth
            // was called.
            if (_bounds.intersects(clip)) {
                paintMonth(g, column, row);
            } else {
                _cal.add(Calendar.MONTH, 1);
            }

            x += _ltr ? _calendarWidth + CALENDAR_SPACING : -(_calendarWidth + CALENDAR_SPACING);
        }
        y += _calendarHeight + CALENDAR_SPACING;
    }

    // Restore the calendar.
    _cal.setTimeInMillis(_firstDisplayedDate);
    if (g2 != null && _antiAlias) {
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldAAValue);
    }
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

public byte[] printImage(float scale, CanvasCommon canvas, Dimension graphsize, String format)
        throws IOException {
    int h_margin = 72, v_margin = 72;
    BufferedImage image = new BufferedImage(graphsize.width + h_margin, graphsize.height + v_margin,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    if (scale > 0)
        g2.scale(scale, scale);/* w  w w. j av a  2  s. co  m*/
    g2.setBackground(Color.WHITE);
    g2.clearRect(0, 0, image.getWidth(), image.getHeight());
    // canvas.paint(g2);
    Color bgsave = canvas.getBackground();
    boolean edsave = canvas.editable;
    canvas.editable = false;
    canvas.setBackground(Color.white);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    canvas.paintComponent(g2);
    canvas.setBackground(bgsave);
    canvas.editable = edsave;
    g2.dispose();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, format, baos);
    image = null;
    Runtime r = Runtime.getRuntime();
    r.gc();
    return baos.toByteArray();
}

From source file:lucee.runtime.img.Image.java

public void setAntiAliasing(boolean antiAlias) throws ExpressionException {
    this.antiAlias = antiAlias ? ANTI_ALIAS_ON : ANTI_ALIAS_OFF;
    Graphics2D graphics = getGraphics();
    if (antiAlias) {
        graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {//  www .  ja v a 2 s. co m
        graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
}

From source file:freemind.controller.Controller.java

public void setTextRenderingHint(Graphics2D g) {
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            (getAntialiasAll()) ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
                    : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            (getAntialiasAll()) ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Creates rendering hints for Text.//from www .  ja v  a2  s  .co m
 */
public static RenderingHints createTextRenderingHints() {
    RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    Object value = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
    try {
        Field declaredField = RenderingHints.class.getDeclaredField("VALUE_TEXT_ANTIALIAS_LCD_HRGB");
        value = declaredField.get(null);

    } catch (Exception e) {
        // do nothing
    }
    renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, value);
    return renderingHints;
}

From source file:DefaultGraphics2D.java

/**
 * Get the rendering context of the <code>Font</code> within this
 * <code>Graphics2D</code> context. The {@link FontRenderContext}
 * encapsulates application hints such as anti-aliasing and fractional
 * metrics, as well as target device specific information such as
 * dots-per-inch. This information should be provided by the application when
 * using objects that perform typographical formatting, such as
 * <code>Font</code> and <code>TextLayout</code>. This information should
 * also be provided by applications that perform their own layout and need
 * accurate measurements of various characteristics of glyphs such as advance
 * and line height when various rendering hints have been applied to the text
 * rendering./*from   ww  w .  j a  v  a 2  s  .c  o  m*/
 * 
 * @return a reference to an instance of FontRenderContext.
 * @see java.awt.font.FontRenderContext
 * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
 * @see java.awt.font.TextLayout
 * @since JDK1.2
 */
public FontRenderContext getFontRenderContext() {
    //
    // Find if antialiasing should be used.
    //
    Object antialiasingHint = hints.get(RenderingHints.KEY_TEXT_ANTIALIASING);
    boolean isAntialiased = true;
    if (antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_ON
            && antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) {

        // If antialias was not turned off, then use the general rendering
        // hint.
        if (antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) {
            antialiasingHint = hints.get(RenderingHints.KEY_ANTIALIASING);

            // Test general hint
            if (antialiasingHint != RenderingHints.VALUE_ANTIALIAS_ON
                    && antialiasingHint != RenderingHints.VALUE_ANTIALIAS_DEFAULT) {
                // Antialiasing was not requested. However, if it was not turned
                // off explicitly, use it.
                if (antialiasingHint == RenderingHints.VALUE_ANTIALIAS_OFF)
                    isAntialiased = false;
            }
        } else
            isAntialiased = false;

    }

    //
    // Find out whether fractional metrics should be used.
    //
    boolean useFractionalMetrics = true;
    if (hints.get(RenderingHints.KEY_FRACTIONALMETRICS) == RenderingHints.VALUE_FRACTIONALMETRICS_OFF)
        useFractionalMetrics = false;

    FontRenderContext frc = new FontRenderContext(defaultTransform, isAntialiased, useFractionalMetrics);
    return frc;
}