Example usage for java.awt Graphics getFontMetrics

List of usage examples for java.awt Graphics getFontMetrics

Introduction

In this page you can find the example usage for java.awt Graphics getFontMetrics.

Prototype

public FontMetrics getFontMetrics() 

Source Link

Document

Gets the font metrics of the current font.

Usage

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFNumberColumnCellRenderer.java

public void paint(Graphics g) {
    if (g == null) {
        return;//from w  ww .j av a2  s .  c o m
    }
    Rectangle bounds = getBounds();
    g.setColor(getBackground());
    g.fill3DRect(0, 0, bounds.width, bounds.height, true);
    g.setColor(getForeground());
    String str;
    if (value instanceof BigDecimal) {
        BigDecimal val = (BigDecimal) value;
        Format fmt = getNumberFormat(digits, precis);
        str = fmt.format(val);
    } else if (value instanceof String) {
        str = (String) value;
    } else {
        str = null;
    }
    if (str != null) {
        int firstNewline = str.indexOf('\n');
        if (firstNewline < 0) {
            firstNewline = str.indexOf('\r');
            if (firstNewline < 0) {
                firstNewline = str.indexOf('\f');
                if (firstNewline < 0) {
                    firstNewline = str.length();
                }
            }
        }
        String firstLine = str.substring(0, firstNewline);
        FontMetrics fm = g.getFontMetrics();
        int ascent = fm.getAscent();
        int leading = fm.getLeading();
        int width = fm.stringWidth(firstLine);
        int x = (bounds.width - 8) - width;
        g.drawString(firstLine, x, leading + ascent + 4);
    }
}

From source file:BeanContainer.java

public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Color colorRetainer = g.getColor();

        g.setColor(getBackground());//from w  ww .j  a v  a2 s  .c o m
        g.fillRect(0, 0, getWidth(), getHeight());
        getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

        m_calendar.setTime(new Date()); // get current time
        int hrs = m_calendar.get(Calendar.HOUR_OF_DAY);
        int min = m_calendar.get(Calendar.MINUTE);

        g.setColor(getForeground());
        if (m_digital) {
            String time = "" + hrs + ":" + min;
            g.setFont(getFont());
            FontMetrics fm = g.getFontMetrics();
            int y = (getHeight() + fm.getAscent()) / 2;
            int x = (getWidth() - fm.stringWidth(time)) / 2;
            g.drawString(time, x, y);
        } else {
            int x = getWidth() / 2;
            int y = getHeight() / 2;
            int rh = getHeight() / 4;
            int rm = getHeight() / 3;

            double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI;
            double am = min / 30.0 * Math.PI;

            g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah)));
            g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am)));
        }

        g.setColor(colorRetainer);
    }

From source file:FancyCaret.java

public void paint(Graphics g) {
    JTextComponent comp = getComponent();
    if (comp == null)
        return;//from   w w  w .ja v  a2s  .c  om

    int dot = getDot();
    Rectangle r = null;
    char dotChar;
    try {
        r = comp.modelToView(dot);
        if (r == null)
            return;
        dotChar = comp.getText(dot, 1).charAt(0);
    } catch (BadLocationException e) {
        return;
    }

    if ((x != r.x) || (y != r.y)) {
        repaint();
        x = r.x;
        y = r.y;
        height = r.height;
    }

    g.setColor(comp.getCaretColor());
    g.setXORMode(comp.getBackground());

    if (dotChar == '\n') {
        int diam = r.height;
        if (isVisible())
            g.fillArc(r.x - diam / 2, r.y, diam, diam, 270, 180); // half circle
        width = diam / 2 + 2;
        return;
    }

    if (dotChar == '\t')
        try {
            Rectangle nextr = comp.modelToView(dot + 1);
            if ((r.y == nextr.y) && (r.x < nextr.x)) {
                width = nextr.x - r.x;
                if (isVisible())
                    g.fillRoundRect(r.x, r.y, width, r.height, 12, 12);
                return;
            } else
                dotChar = ' ';
        } catch (BadLocationException e) {
            dotChar = ' ';
        }

    width = g.getFontMetrics().charWidth(dotChar);
    if (isVisible())
        g.fillRect(r.x, r.y, width, r.height);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTimeColumnCellRenderer.java

public void paint(Graphics g) {
    if (g == null) {
        return;//from w  w  w .  j a va  2 s  .  c o  m
    }
    Rectangle bounds = getBounds();
    g.setColor(getBackground());
    g.fill3DRect(0, 0, bounds.width, bounds.height, true);
    g.setColor(getForeground());
    String str;
    if (value instanceof Calendar) {
        Calendar cal = (Calendar) value;
        Format fmt = getDefaultFormat();
        Calendar withoutDate = Calendar.getInstance();
        withoutDate.clear();
        withoutDate.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY));
        withoutDate.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));
        withoutDate.set(Calendar.SECOND, cal.get(Calendar.SECOND));
        str = fmt.format(withoutDate.getTime());
    } else if (value instanceof String) {
        str = (String) value;
    } else {
        str = null;
    }
    if (str != null) {
        int firstNewline = str.indexOf('\n');
        if (firstNewline < 0) {
            firstNewline = str.indexOf('\r');
            if (firstNewline < 0) {
                firstNewline = str.indexOf('\f');
                if (firstNewline < 0) {
                    firstNewline = str.length();
                }
            }
        }
        String firstLine = str.substring(0, firstNewline);
        FontMetrics fm = g.getFontMetrics();
        int ascent = fm.getAscent();
        int leading = fm.getLeading();
        g.drawString(firstLine, 4, leading + ascent + 4);
    }
}

From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextFieldSingle.java

@Override
public void paint(Graphics g) {
    super.paint(g);

    String text = getText();//  w w  w  .  j a v  a2s  .co m

    //System.err.println("isViewOnly "+isViewOnly+"  isEnabled() "+isEnabled()+ "  ["+text+"]  "+(text.length() < bgStr.length()));
    if (!isViewOnly && needsUpdating && isEnabled() && text != null && text.length() < bgStr.length()) {
        FontMetrics fm = g.getFontMetrics();
        int w = fm.stringWidth(text);
        pnt = new Point(inner.left + w, inner.top + fm.getAscent());

        Rectangle r = g.getClipBounds();
        Dimension s = getSize();
        Insets i2 = getBorder().getBorderInsets(this);
        int x = i2.left - 1;
        int y = i2.top - 1;
        //int ww = s.width - i2.right + 1;
        int hh = s.height - i2.bottom + 1;

        String str = bgStr.substring(text.length(), bgStr.length());
        int bgW = fm.stringWidth(str);

        g.setClip(x + w, y, Math.min(x + bgW, g.getClipBounds().width - x), hh);

        g.setColor(textColor);
        g.drawString(str, pnt.x, pnt.y);

        g.setClip(r.x, r.y, r.width, r.height); // reset clip
    }

    //System.out.println(hashCode() + " isNew: " +isNew+"  valState: "+valState+"    isEnabled: "+isEnabled());
    // 3/2/09 - rods - removing !isNew from the condition
    //if (!isNew && valState == UIValidatable.ErrorType.Error && isEnabled())
    if (valState == UIValidatable.ErrorType.Error && isEnabled()) {
        UIHelper.drawRoundedRect((Graphics2D) g, isNew ? new Color(249, 249, 0) : valTextColor.getColor(),
                getSize(), 1);
    } else if (valState == UIValidatable.ErrorType.Incomplete && isEnabled()) {
        UIHelper.drawRoundedRect((Graphics2D) g, new Color(249, 249, 0), getSize(), 1);
    }
}

From source file:uk.ac.babraham.BamQC.Graphs.ScatterGraph.java

@Override
protected void paintComponent(Graphics g) {

    g.setColor(Color.WHITE);//from w  w w . j a  va  2s  .  c o  m
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.BLACK);

    if (g instanceof Graphics2D) {
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }

    double yStart, xStart;
    if (minY % yInterval == 0) {
        yStart = minY;
    } else {
        yStart = yInterval * (((int) minY / yInterval) + 1);
    }

    if (minX % xInterval == 0) {
        xStart = minX;
    } else {
        xStart = xInterval * (((int) minX / xInterval) + 1);
    }

    int xOffset = 0;

    // Draw the yLabel on the left of the yAxis
    int yLabelRightShift = 12;
    if (yLabel == null || yLabel.isEmpty()) {
        yLabelRightShift = 0;
    } else {
        if (g instanceof Graphics2D) {
            Graphics2D g2 = (Graphics2D) g;
            AffineTransform orig = g2.getTransform();
            g2.rotate(-Math.PI / 2);
            g2.setColor(Color.BLACK);
            g2.drawString(yLabel, -getY(-yInterval) / 2 - (g.getFontMetrics().stringWidth(yLabel) / 2),
                    yLabelRightShift);
            g2.setTransform(orig);
        }
    }

    // Draw the y axis labels
    int lastYLabelEnd = Integer.MAX_VALUE;
    for (double i = yStart; i <= maxY; i += yInterval) {
        String label = "" + i;
        label = label.replaceAll(".0$", ""); // Don't leave trailing .0s where we don't need them.
        // Calculate the new xOffset depending on the widest ylabel.
        int width = g.getFontMetrics().stringWidth(label);
        if (width > xOffset) {
            xOffset = width;
        }
        // place the y axis labels so that they don't overlap when the plot is resized.
        int baseNumberHeight = g.getFontMetrics().getHeight();
        int baseNumberPosition = getY(i) + (baseNumberHeight / 2);
        if (baseNumberPosition + baseNumberHeight < lastYLabelEnd) {
            // Draw the y axis labels
            g.drawString(label, yLabelRightShift + 6, baseNumberPosition);
            lastYLabelEnd = baseNumberPosition + 2;
        }
    }

    // Give the x axis a bit of breathing space
    xOffset = xOffset + yLabelRightShift + 8;

    // Now draw horizontal lines across from the y axis
    g.setColor(new Color(180, 180, 180));
    for (double i = yStart; i <= maxY; i += yInterval) {
        g.drawLine(xOffset, getY(i), getWidth() - 10, getY(i));
    }
    g.setColor(Color.BLACK);

    // Draw the graph title
    int titleWidth = g.getFontMetrics().stringWidth(graphTitle);
    g.drawString(graphTitle, (xOffset + ((getWidth() - (xOffset + 10)) / 2)) - (titleWidth / 2), 30);

    // Draw the xLabel under the xAxis
    g.drawString(xLabel, (getWidth() / 2) - (g.getFontMetrics().stringWidth(xLabel) / 2), getHeight() - 5);

    // Now draw the data points
    double baseWidth = (getWidth() - (xOffset + 10)) / (maxX - minX);

    //      System.out.println("Base Width is "+baseWidth);
    // Let's find the longest label, and then work out how often we can draw labels
    int lastXLabelEnd = 0;

    // Draw the x axis labels
    for (double i = xStart; i <= maxX; i += xInterval) {
        g.setColor(Color.BLACK);
        String baseNumber = "" + i;
        baseNumber = baseNumber.replaceAll(".0$", ""); // Don't leave trailing .0s where we don't need them.
        // Calculate the new xOffset depending on the widest ylabel.
        int baseNumberWidth = g.getFontMetrics().stringWidth(baseNumber);
        int baseNumberPosition = (int) (xOffset + (baseWidth * i) - (baseNumberWidth / 2));

        if (baseNumberPosition > lastXLabelEnd) {
            g.drawString(baseNumber, baseNumberPosition, getHeight() - 25);
            lastXLabelEnd = baseNumberPosition + baseNumberWidth + 5;
        }
        // Now draw vertical lines across from the y axis
        g.setColor(new Color(180, 180, 180));
        g.drawLine((int) (xOffset + (baseWidth * i)), getHeight() - 40, (int) (xOffset + (baseWidth * i)), 40);
        g.setColor(Color.BLACK);
    }

    // Now draw the axes
    g.drawLine(xOffset, getHeight() - 40, getWidth() - 10, getHeight() - 40);
    g.drawLine(xOffset, getHeight() - 40, xOffset, 40);

    // Initialise the arrays containing the tooltips
    rectangles = new ArrayList<Rectangle>();
    tips = new ArrayList<String>();

    g.setColor(Color.BLUE);
    // Draw the data points
    double ovalSize = 5;
    // We distinguish two inputs since the x label does not start from 0.
    // used for computing the actual line points as if they were starting from 0.
    double[] inputVar = new double[data.length];
    double[] responseVar = new double[data.length];
    for (int d = 0; d < data.length; d++) {
        double x = getX(xCategories[d], xOffset) - ovalSize / 2;
        double y = getY(data[d]) - ovalSize / 2;
        g.fillOval((int) x, (int) y, (int) (ovalSize), (int) (ovalSize));
        g.drawString(toolTipLabels[d], (int) x + 2, (int) y + 16);
        inputVar[d] = Double.valueOf(xCategories[d]);
        responseVar[d] = data[d];

        // Tool tips
        Rectangle r = new Rectangle((int) x, (int) y, (int) (ovalSize), (int) (ovalSize));
        rectangles.add(r);
        tips.add(toolTipLabels[d]);
    }
    g.setColor(Color.BLACK);

    // Draw the intercept 

    // WARNING: Is drawing a least squares regression line asserting that "the distribution follows a power law" correct?
    // This is our case if we plot log-log..
    // It seems not in this paper (Appendix A) http://arxiv.org/pdf/0706.1062v2.pdf

    if (data.length > 1) {
        LinearRegression linReg = new LinearRegression(inputVar, responseVar);
        double intercept = linReg.intercept();
        double slope = linReg.slope();
        double rSquare = linReg.R2();

        // Let's now calculate the two points (x1, y1) and (xn, yn)
        // (x1, y1). We need to skip the areas where x1<minY and y1>maxY
        double x1 = minX;
        double y1 = slope * minX + intercept;
        if (y1 < minY) {
            x1 = (minY - intercept) / slope;
            y1 = minY;
        } else if (y1 > maxY) {
            x1 = (maxY - intercept) / slope;
            y1 = maxY;
        }
        // (xn, yn). maxX which essentially is inputVar[inputVar.length-1]
        double xn = maxX;
        double yn = slope * maxX + intercept;

        if (g instanceof Graphics2D) {
            ((Graphics2D) g).setStroke(new BasicStroke(1.5f));
        }
        g.setColor(Color.RED);
        g.drawLine(getX(x1, xOffset), getY(y1), getX(xn, xOffset), getY(yn));
        g.setColor(Color.BLACK);
        if (g instanceof Graphics2D) {
            ((Graphics2D) g).setStroke(new BasicStroke(1));
        }

        // Draw the legend for the intercept
        String legendString = "y = " + Precision.round(slope, 3) + "x";
        if (intercept < 0)
            legendString += " - " + Precision.round(-intercept, 3);
        else
            legendString += " + " + Precision.round(intercept, 3);
        int width = g.getFontMetrics().stringWidth(legendString);

        // First draw a box to put the legend in
        g.setColor(Color.WHITE);
        g.fillRect(xOffset + 10, 45, width + 8, 35);
        g.setColor(Color.LIGHT_GRAY);
        g.drawRect(xOffset + 10, 45, width + 8, 35);

        // Now draw the legend label
        g.setColor(Color.RED);
        g.drawString(legendString, xOffset + 13, 60);
        g.drawString("R^2 = " + Precision.round(rSquare, 3), xOffset + 13, 76);
        g.setColor(Color.BLACK);
    }

}

From source file:ubic.basecode.graphics.MatrixDisplay.java

/**
 * @param g/*from ww w.  ja  va2 s .  co m*/
 * @param d
 */
protected void drawScaleBar(Graphics g, Dimension d, double displayMin, double displayMax) {
    /*
     * FIXME this is all a bit of a hack
     */
    g.setColor(Color.white);
    int upperLeftScalebarGutter = 10;
    int scaleBarHeight = 10; // these and text height have to total < SCALE_BAR_ROOM
    int desiredScaleBarLength = (int) Math.min(DEFAULT_SCALE_BAR_WIDTH, d.getWidth());

    if (desiredScaleBarLength < 10) {
        return;
    }

    g.drawRect(upperLeftScalebarGutter, upperLeftScalebarGutter, desiredScaleBarLength,
            upperLeftScalebarGutter);
    JGradientLabel scalebar = new JGradientLabel(new ColorMap(this.getColorMap()).getPalette());
    scalebar.setBackground(Color.white);
    scalebar.setSize(new Dimension(desiredScaleBarLength, scaleBarHeight));
    int actualWidth = scalebar.drawAtLocation(g, upperLeftScalebarGutter, upperLeftScalebarGutter);
    g.setColor(Color.black);
    g.drawString(String.format("%.2g", displayMin), 0,
            upperLeftScalebarGutter + scaleBarHeight + m_fontGutter + g.getFontMetrics().getHeight());
    g.drawString(String.format("%.2g", displayMax), actualWidth,
            upperLeftScalebarGutter + scaleBarHeight + m_fontGutter + g.getFontMetrics().getHeight());
    g.drawRect(upperLeftScalebarGutter, upperLeftScalebarGutter, actualWidth, scaleBarHeight);
}

From source file:edu.purdue.cc.bionet.ui.HeatMap.java

/**
 * This method retrieves a heatmap image from jfreechart and places it on the panel
 * along with black divider lines and labels to create a heat map graph.
 * /*from w  w w.  jav  a 2  s. com*/
 * @param g The Graphics for the jpanel.
 */
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (moleculeList.size() > 0) {
        float tickStep;
        BufferedImage drawing = HeatMapUtilities.createHeatMapImage(this.getDataset(), this.spectrum);
        int leftEdge = this.getWidth() / 8;
        int topEdge = this.getHeight() / 32;
        int bottomEdge = this.getHeight() * 7 / 8;
        int rightEdge = this.getWidth() * 31 / 32;
        mapPosition = new Rectangle(leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge);
        g.drawImage(drawing, leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge,
                this.getBackground(), this);
        // y-axis
        int yAxisPos = leftEdge - 1;
        //      g.drawLine( yAxisPos, topEdge, yAxisPos, bottomEdge );
        tickStep = (bottomEdge - topEdge) / (float) moleculeList.size();
        for (int i = 0; i <= moleculeList.size(); i++) {
            int tickY = Math.round(topEdge + i * tickStep);
            g.drawLine(rightEdge, tickY, yAxisPos - tickSize, tickY);
            if (i < moleculeList.size()) {
                String name = this.moleculeList.get(this.moleculeList.size() - 1 - i).toString();
                g.drawString(name, yAxisPos - 4 - g.getFontMetrics().stringWidth(name),
                        (int) (tickY + tickStep));
            }
        }

        // x-axis
        int xAxisPos = bottomEdge;
        tickStep = (rightEdge - leftEdge) / (float) moleculeList.size();
        //      g.drawLine( leftEdge, xAxisPos, rightEdge, xAxisPos );
        for (int i = 0; i <= moleculeList.size(); i++) {
            int tickX = (int) (leftEdge + i * tickStep);
            g.drawLine(tickX, topEdge, tickX, xAxisPos + tickSize);
        }
        // transform clockwise 90 degrees for the vertical text
        AffineTransform at = new AffineTransform();
        at.quadrantRotate(3);
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.transform(at);
        for (int i = 0; i < moleculeList.size(); i++) {
            int tickX = Math.round(leftEdge + i * tickStep);
            String name = this.moleculeList.get(i).toString();
            g2d.drawString(name, -(int) (xAxisPos + 4 + g.getFontMetrics().stringWidth(name)),
                    (int) (tickX + tickStep));
        }
    }
}

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

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    boolean doScale = true;

    int w = getWidth();
    int h = getHeight();

    Image dspImg = image;/*  w ww  .  ja  v  a2s  .com*/
    boolean doDisplayImage = (image != null && (!isNoAttachment && status == kImageOK)) || isLoading;
    if (isLoading) {
        doDisplayImage = true;
        dspImg = IconManager.getImage("Loading").getImage();
    }
    if (doDisplayImage && dspImg != null) {
        int imgW = dspImg.getWidth(null);
        int imgH = dspImg.getHeight(null);

        if (doScale && (imgW > w || imgH > h)) {
            double scaleW = 1.0;
            double scaleH = 1.0;
            double scale = 1.0;

            if (imgW > w) {
                scaleW = (double) w / imgW;
            }
            if (imgH > h) {
                scaleH = (double) h / imgH;
            }
            scale = Math.min(scaleW, scaleH);

            imgW = (int) (imgW * scale);
            imgH = (int) (imgH * scale);
        }

        int x = 0;
        int y = 0;

        if (imgW < w) {
            x = (w - imgW) / 2;
        }
        if (imgH < h) {
            y = (h - imgH) / 2;
        }
        g.drawImage(dspImg, x, y, imgW, imgH, null);

    } else if (doShowText) {
        GraphicsUtils.turnOnAntialiasedDrawing(g);
        String[] label = this.isNoAttachment ? (isFullImage ? noAttachmentStr : noThumnailStr)
                : loadingAttachmentStr;
        FontMetrics fm = g.getFontMetrics();
        int spacing = 2;
        int yOffset = (h - (fm.getHeight() + spacing) * label.length) / 2;
        if (yOffset < 0)
            yOffset = 0;
        int y = yOffset + fm.getHeight();
        for (String str : label) {
            g.drawString(str, (w - fm.stringWidth(str)) / 2, y);
            y += fm.getHeight() + 2;
        }
    }
}

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

/**
 * Paints a month. It is assumed the calendar, _cal, is already set to the
 * first day of the month to be painted.
 *
 * @param col/*  w w  w  . j av  a2 s . co  m*/
 *            X (column) the calendar is displayed in.
 * @param row
 *            Y (row) the calendar is displayed in.
 * @param g
 *            Graphics object.
 */
private void paintMonth(Graphics g, int col, int row) {
    String numericDay;
    int days = _cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    FontMetrics fm = g.getFontMetrics();
    Rectangle clip = g.getClipBounds();

    long nextFlaggedDate = -1;
    int flaggedDateIndex = 0;
    if (_flaggedDates != null && _flaggedDates.length > 0) {
        nextFlaggedDate = _flaggedDates[flaggedDateIndex];
    }

    long nextColoredDate = -1;
    int coloredDateIndex = 0;
    if (_coloredDates != null && _coloredDates.length > 0) {
        nextColoredDate = _coloredDates[coloredDateIndex];
    }

    for (int i = 0; i < days; i++) {
        calculateBoundsForDay(_bounds, _cal, false);

        if (_bounds.intersects(clip)) {
            numericDay = _dayOfMonthFormatter.format(_cal.getTime());

            //            PROJITY_MODIFICATION
            //            // Paint Sunday
            //            if (_cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
            //                  || _cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
            //
            //               paintSundayAndSaturday(g, _bounds.x, _bounds.y,
            //                     _bounds.width, _bounds.height);
            //
            //               g.setColor(getForeground());
            //
            //            }

            // Paint bounding box around today.
            boolean today = _cal.getTimeInMillis() == _today;
            //            if (_cal.getTimeInMillis() == _today) {
            //               paintTodayBackground(g, _bounds.x, _bounds.y,
            //                     _bounds.width, _bounds.height);
            //
            //               g.setColor(getForeground());
            //            }

            // If the appointment date is less than the current
            // calendar date increment to the next appointment.
            while (nextFlaggedDate != -1 && nextFlaggedDate < _cal.getTimeInMillis()) {
                flaggedDateIndex++;
                if (flaggedDateIndex < _flaggedDates.length) {
                    nextFlaggedDate = _flaggedDates[flaggedDateIndex];
                } else {
                    nextFlaggedDate = -1;
                }
            }
            while (nextColoredDate != -1 && nextColoredDate < _cal.getTimeInMillis()) {
                coloredDateIndex++;
                if (coloredDateIndex < _coloredDates.length) {
                    nextColoredDate = _coloredDates[coloredDateIndex];
                } else {
                    nextColoredDate = -1;
                }
            }

            boolean flagged = nextFlaggedDate != -1 && _cal.getTimeInMillis() == nextFlaggedDate;
            boolean colored = nextColoredDate != -1 && _cal.getTimeInMillis() == nextColoredDate;
            drawDay(colored, flagged, today, g, numericDay,
                    _ltr ? _bounds.x + _boxPaddingX + _boxWidth - fm.stringWidth(numericDay)
                            : _bounds.x + _boxPaddingX + _boxWidth - fm.stringWidth(numericDay) - 1,
                    _bounds.y + _boxPaddingY + fm.getAscent());

            // Paint bounding box around any date that falls within the
            // selection.
            if (isSelectedDate(_cal.getTimeInMillis())) {
                // Keep track of the rectangle for the currently
                // selected date so we don't have to recalculate it
                // later when it becomes unselected. This is only
                // useful for SINGLE_SELECTION mode.
                if (_selectionMode == SINGLE_SELECTION) {
                    _dirtyRect.x = _bounds.x;
                    _dirtyRect.y = _bounds.y;
                    _dirtyRect.width = _bounds.width;
                    _dirtyRect.height = _bounds.height;
                }

                paintSelectedDayBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height);

                g.setColor(getForeground());
            }
            //            PROJITY_MODIFICATION
            //               g.setColor(defaultColor);
            //            } else {
            //               g.drawString(numericDay, _ltr ? _bounds.x + _boxPaddingX
            //                     + _boxWidth - fm.stringWidth(numericDay)
            //                     : _bounds.x + _boxPaddingX + _boxWidth
            //                           - fm.stringWidth(numericDay) - 1, _bounds.y
            //                     + _boxPaddingY + fm.getAscent());
            //            }
            //
            //            // Paint numeric day of the month.
            //            if (nextColoredDate != -1
            //                  && _cal.getTimeInMillis() == nextColoredDate) {
            //               Font oldFont = getFont();
            //               //g.setFont(_derivedFont);
            //
            //
            //               //hk
            //               g.setColor(Color.LIGHT_GRAY);
            //               g.fillRect(_bounds.x, _bounds.y,
            //                     _bounds.width, _bounds.height);
            //               g.setColor(defaultColor);
            //
            //               g.drawString(numericDay, _ltr ? _bounds.x + _boxPaddingX
            //                     + _boxWidth - fm.stringWidth(numericDay)
            //                     : _bounds.x + _boxPaddingX + _boxWidth
            //                           - fm.stringWidth(numericDay) - 1, _bounds.y
            //                     + _boxPaddingY + fm.getAscent());
            //               g.setFont(oldFont);
            //            } else {
            //               g.drawString(numericDay, _ltr ? _bounds.x + _boxPaddingX
            //                     + _boxWidth - fm.stringWidth(numericDay)
            //                     : _bounds.x + _boxPaddingX + _boxWidth
            //                           - fm.stringWidth(numericDay) - 1, _bounds.y
            //                     + _boxPaddingY + fm.getAscent());
            //            }
            //
        }
        _cal.add(Calendar.DAY_OF_MONTH, 1);
    }
}