Example usage for java.awt Font HANGING_BASELINE

List of usage examples for java.awt Font HANGING_BASELINE

Introduction

In this page you can find the example usage for java.awt Font HANGING_BASELINE.

Prototype

int HANGING_BASELINE

To view the source code for java.awt Font HANGING_BASELINE.

Click Source Link

Document

The baseline used in Devanagari and similar scripts when laying out text.

Usage

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

/**
 * Calculates size information necessary for laying out the month view.
 *//*  ww  w . j a  v  a  2s  . c  o  m*/
private void update() {
    // Loop through year and get largest representation of the month.
    // Keep track of the longest month so we can loop through it to
    // determine the width of a date box.
    int currDays;
    int longestMonth = 0;
    int daysInLongestMonth = 0;

    int currWidth;
    int longestMonthWidth = 0;

    // We use a bold font for figuring out size constraints since
    // it's larger and flaggedDates will be noted in this style.

    _derivedFont = getFont().deriveFont(Font.BOLD);
    _baselineFont = getFont().deriveFont(Font.HANGING_BASELINE);
    FontMetrics fm = getFontMetrics(_derivedFont);

    _cal.set(Calendar.MONTH, _cal.getMinimum(Calendar.MONTH));
    _cal.set(Calendar.DAY_OF_MONTH, _cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    for (int i = 0; i < _cal.getMaximum(Calendar.MONTH); i++) {
        currWidth = fm.stringWidth(_monthsOfTheYear[i]);
        if (currWidth > longestMonthWidth) {
            longestMonthWidth = currWidth;
        }
        currDays = _cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        if (currDays > daysInLongestMonth) {
            longestMonth = _cal.get(Calendar.MONTH);
            daysInLongestMonth = currDays;
        }
        _cal.add(Calendar.MONTH, 1);
    }

    // Loop through longest month and get largest representation of the day
    // of the month.
    _cal.set(Calendar.MONTH, longestMonth);
    _cal.set(Calendar.DAY_OF_MONTH, _cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    _boxHeight = fm.getHeight();
    for (int i = 0; i < daysInLongestMonth; i++) {
        currWidth = fm.stringWidth(_dayOfMonthFormatter.format(_cal.getTime()));
        if (currWidth > _boxWidth) {
            _boxWidth = currWidth;
        }
        _cal.add(Calendar.DAY_OF_MONTH, 1);
    }

    // Modify _boxWidth if month string is longer
    _dim.width = (_boxWidth + (2 * _boxPaddingX)) * DAYS_IN_WEEK;
    if (_dim.width < longestMonthWidth) {
        double diff = longestMonthWidth - _dim.width;
        _boxWidth += Math.ceil(diff / (double) DAYS_IN_WEEK);
        _dim.width = (_boxWidth + (2 * _boxPaddingX)) * DAYS_IN_WEEK;
    }

    // Keep track of calendar width and height for use later.
    _calendarWidth = (_boxWidth + (2 * _boxPaddingX)) * DAYS_IN_WEEK;
    _calendarHeight = (_boxPaddingY + _boxHeight + _boxPaddingY) * 8;

    // Calculate minimum width/height for the component.
    _dim.height = (_calendarHeight * _minCalRows) + (CALENDAR_SPACING * (_minCalRows - 1));

    _dim.width = (_calendarWidth * _minCalCols) + (CALENDAR_SPACING * (_minCalCols - 1));

    // Add insets to the dimensions.
    Insets insets = getInsets();
    _dim.width += insets.left + insets.right;
    _dim.height += insets.top + insets.bottom;

    // Restore calendar.
    _cal.setTimeInMillis(_firstDisplayedDate);
}