Example usage for java.awt Graphics fillRect

List of usage examples for java.awt Graphics fillRect

Introduction

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

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

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

/**
 * {@inheritDoc}//from w ww . j  av  a 2s  .  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:display.ANNFileFilter.java

License:asdf

public void paintComponent(Graphics g) {
    int nValue = 500 / lValue;
    int x = 0;// ww w  .j a  v  a2  s .  c om
    int y = 0;

    int count = 0;
    for (int i = 0; i < (lValue * lValue); i++) {
        Color c = new Color(colorValues[i][0], colorValues[i][1], colorValues[i][2]);
        g.setColor(c);
        g.fillRect(x, y, nValue, nValue);
        x = x + nValue;
        if (count == (lValue - 1)) {
            x = 0;
            y = y + nValue;
            count = -1;
        }
        count++;

    }
}

From source file:com.headswilllol.basiclauncher.Launcher.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setFont(font);/*  w  w  w.  j  a v a 2 s  .  c  o  m*/
    if (updateMsg != null) {
        g.drawString("Update Available!", centerText(g, "Update Available!"), 50);
        g.setFont(smallFont);
        g.drawString(updateMsg, centerText(g, updateMsg), 100);
    }

    else if (progress == null)
        g.drawString(NAME + " Launcher", centerText(g, NAME + " Launcher"), 50);

    else {
        g.drawString(progress, centerText(g, progress), height / 2);
        if (fail != null)
            g.drawString(fail, centerText(g, fail), height / 2 + 50);
        else {
            if (aSize != -1 && eSize != -1) {
                String s = (aSize * 8) + "/" + (int) (eSize * 8) + " B";
                if (eSize * 8 >= 1024)
                    if (eSize * 8 >= 1024 * 1024)
                        s = String.format("%.2f", aSize * 8 / 1024 / 1024) + "/"
                                + String.format("%.2f", eSize * 8 / 1024 / 1024) + " MiB";
                    else
                        s = String.format("%.2f", aSize * 8 / 1024) + "/"
                                + String.format("%.2f", eSize * 8 / 1024) + " KiB";
                g.drawString(s, centerText(g, s), height / 2 + 40);
                String sp = "@" + (int) speed + " B/s";
                if (speed >= 1024)
                    if (speed >= 1024 * 1024)
                        sp = "@" + String.format("%.2f", (speed / 1024 / 1024)) + " MiB/s";
                    else
                        sp = "@" + String.format("%.2f", (speed / 1024)) + " KiB/s";
                g.drawString(sp, centerText(g, sp), height / 2 + 80);
                int barWidth = 500;
                int barHeight = 35;
                g.setColor(Color.LIGHT_GRAY);
                g.drawRect(width / 2 - barWidth / 2, height / 2 + 100, barWidth, barHeight);
                g.setColor(Color.GREEN);
                g.fillRect(width / 2 - barWidth / 2 + 1, height / 2 + 100 + 1,
                        (int) ((aSize / eSize) * (double) barWidth - 2), barHeight - 1);
                g.setColor(new Color(.2f, .2f, .2f));
                int percent = (int) (aSize / (double) eSize * 100);
                g.drawString(percent + "%", centerText(g, percent + "%"), height / 2 + 128);
            }
        }
    }
}

From source file:org.prom5.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g, int imageWidth, int imageHeight, boolean isModel) {
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;/*from   ww  w  .  j a  v  a2  s . c  om*/
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    int clipL, clipR;

    // calculate common coordinates
    int yTop, yBottom, tempBorder, upper, bottom;
    if (isModel) {
        yTop = BORDER;
        yBottom = imageHeight - BORDER;
        clipL = coUtil.getClipL();
        clipR = coUtil.getClipR();
        upper = coUtil.getClipU();
        bottom = coUtil.getClipB();
        tempBorder = BORDER;
    } else {
        yTop = 0;
        yBottom = imageHeight;
        clipL = 0;
        clipR = imageWidth;
        upper = 0;
        bottom = this.getHeight();
        tempBorder = BUFFERBORDER;
    }

    int pixStart = 0;

    // initialize start color
    fgColor = dca.getSettingPanel().getFBcolor();
    bgColor = dca.getSettingPanel().getSBcolor();
    ;

    // paint actual log lane (only the part in the clipping range determined)
    Iterator<String> itr = dcModel.getSortedMapModel().getSortedItemArrayList(dcop.getTimeOption(),
            dcop.getComponentType(), dcop.getSortStandard(), dcop.isDescCheckBoxSelected()).iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));

    int size = dcModel.getComponentSize(dca.getDottedChartOptionPanel().getComponentType());
    int index = 0;

    while (itr.hasNext()) {
        String dimName = itr.next();
        g.setColor(bgColor);
        int top = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        int bot = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        if (bot >= upper && top <= bottom) {
            if (top < upper)
                top = upper;
            if (bot > bottom)
                bot = bottom;
            g.fillRect(pixStart, top - coUtil.getClipU(), clipR, bottom - coUtil.getClipU());
            g.setColor(fgColor);
            if (isModel) {
                if (top + 20 - coUtil.getClipU() <= imageHeight - tempBorder)
                    g.drawString(dimName, pixStart + 5, top + 20 - coUtil.getClipU());
            }
        }
        if (coUtil.unit2CordHeight(index + 1, size, imageHeight, tempBorder) > bottom)
            break;
        index++;
        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));
    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g, int imageWidth, int imageHeight, boolean isModel) {
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;/*from   w ww.  j  a va  2 s . co  m*/
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    int clipL, clipR;

    // calculate common coordinates
    int yTop, yBottom, tempBorder, upper, bottom;
    if (isModel) {
        yTop = BORDER;
        yBottom = imageHeight - BORDER;
        clipL = coUtil.getClipL();
        clipR = coUtil.getClipR();
        upper = coUtil.getClipU();
        bottom = coUtil.getClipB();
        tempBorder = BORDER;
    } else {
        yTop = 0;
        yBottom = imageHeight;
        clipL = 0;
        clipR = imageWidth;
        upper = 0;
        bottom = this.getHeight();
        tempBorder = BUFFERBORDER;
    }

    int pixStart = 0;

    // initialize start color
    fgColor = dca.getSettingPanel().getFBcolor();
    bgColor = dca.getSettingPanel().getSBcolor();
    ;

    // paint actual log lane (only the part in the clipping range
    // determined)
    Iterator<String> itr = dcModel.getSortedMapModel().getSortedItemArrayList(dcop.getTimeOption(),
            dcop.getComponentType(), dcop.getSortStandard(), dcop.isDescCheckBoxSelected()).iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));

    int size = dcModel.getComponentSize(dca.getDottedChartOptionPanel().getComponentType());
    int index = 0;

    while (itr.hasNext()) {
        String dimName = itr.next();
        g.setColor(bgColor);
        int top = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        int bot = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        if (bot >= upper && top <= bottom) {
            if (top < upper)
                top = upper;
            if (bot > bottom)
                bot = bottom;
            g.fillRect(pixStart, top - coUtil.getClipU(), clipR, bottom - coUtil.getClipU());
            g.setColor(fgColor);
            if (isModel) {
                if (top + 20 - coUtil.getClipU() <= imageHeight - tempBorder)
                    g.drawString(dimName, pixStart + 5, top + 20 - coUtil.getClipU());
            }
        }
        if (coUtil.unit2CordHeight(index + 1, size, imageHeight, tempBorder) > bottom)
            break;
        index++;
        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));
    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);
}

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

private void drawSquares(Graphics squares, Point start, Rectangle bounds, Dataset dataset,
        boolean clusterColumns) {
    //        ColorFactory colors = ColorFactoryList.getInstance().getActiveColorFactory(dataset);
    colors = colorFactory.getActiveColorFactory(dataset);
    Rectangle view = getSquaresBounds(dataset);
    squares.translate(start.x, start.y);
    int rows = this.countgenes(this.rowNode);
    int counter = 0;
    double[] gengenscalevals = null;
    int[] upperArrangement = null;
    if (clusterColumns) {
        upperArrangement = upperTree.arrangement;
    } else {/*from w w w.  jav  a 2  s .c om*/
        upperArrangement = new int[dataset.getColumnIds().length];
        for (int x = 0; x < dataset.getColumnIds().length; x++)
            upperArrangement[x] = x;
    }
    double[][] dat = null;
    dat = dataset.getData();
    if (sideTree == null) {
        return;
    }
    for (int i = 0; i < sideTree.arrangement.length; i++) {
        double v = 0;
        Rectangle sqr = new Rectangle(0, 0, squareW, squareL);
        for (int j = 0; j < upperArrangement.length; j++) {
            if (bounds == null || bounds.intersects((j * squareW), (i * squareL), squareW, squareL)) {

                if (upperTree != null) {

                    sqr.setLocation((j * squareW), (i * squareL));
                    if (!view.intersects(sqr)) {
                        continue;
                    }

                    if (sideTree.arrangement[i] != -1 && upperArrangement[j] != -1) {

                        if (dataset.isMissing(sideTree.arrangement[i], upperArrangement[j])) {
                            squares.setColor(colors.getMissing());
                        } else {
                            if (!gengenscale) {
                                v = dat[sideTree.arrangement[i]][upperArrangement[j]];
                                squares.setColor(colors.getColor(v));
                            } else {
                                v = gengenscalevals[upperArrangement[j]];
                                squares.setColor(colors.getColor(v));
                            }
                        }
                        squares.fillRect((j * squareW), (i * squareL), squareW, squareL);
                    }
                } else {
                    sqr.setLocation((j * squareW), (i * squareL));
                    if (!view.intersects(sqr)) {
                        continue;
                    }

                    v = dat[sideTree.arrangement[i]][upperArrangement[j]];

                    if (dataset.isMissing(sideTree.arrangement[i], upperArrangement[j])) {
                        squares.setColor(colors.getMissing());
                    } else {
                        squares.setColor(colors.getColor(v));
                    }

                    squares.fillRect((j * squareW), (i * squareL), squareW, squareL);
                }
            }
        }
        counter++;
        if (counter == rows) {
            break;
        }
    }
    counter = 0;
    if (true) {
        squares.setColor(GridCol);
        for (int i = 0; i < sideTree.arrangement.length + 1; i++) {
            if (bounds == null
                    || bounds.intersects(0, i * squareL, upperArrangement.length * squareW, i * squareL)) {
                squares.drawLine(0, i * squareL, (upperArrangement.length * squareW) + 0, i * squareL);
            }
            counter++;
            if (counter > rows) {
                break;
            }
        }
        for (int j = 0; j < upperArrangement.length; j++) {
            if (bounds == null || bounds.intersects(j * squareW, 0, j * squareW, rows * squareL)) {
                squares.drawLine(j * squareW, 0, j * squareW, rows * squareL);
            }
        }

        if (bounds == null || bounds.intersects(upperArrangement.length * squareW, 0,
                upperArrangement.length * squareW, rows * squareL)) {
            squares.drawLine(upperArrangement.length * squareW, 0, upperArrangement.length * squareW,
                    rows * squareL);
        }

    }
    squares.translate(-start.x, -start.y);
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_//ww w.j  av  a  2 s  . com
 *
 * @param g _more_
 * @param comp _more_
 */
public void paintDashboardBackground(Graphics g, JComponent comp) {
    Graphics2D g2 = (Graphics2D) g;
    Rectangle b = dashboardLbl.getBounds();
    g.setColor(Color.white);
    g.fillRect(0, 0, b.width, b.height);

    if (showDecoration) {
        boolean callRepaint = false;
        for (FlythroughDecorator decorator : decorators) {
            if (!decorator.getShown()) {
                continue;
            }
            if (decorator.paintDashboard(g2, comp)) {
                callRepaint = true;
            }
        }
        if (callRepaint) {
            synchronized (REPAINT_MUTEX) {
                repaintCnt++;
                Misc.runInABit(500, this, "doRepaint", comp);
            }
        }

    }

}

From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g) {

    double percentileL = dcModel.getTimeStatistics().get(0)
            .getPercentile(dca.getSettingPanel().getPercentileforInstanceL());
    double percentileU = dcModel.getTimeStatistics().get(0)
            .getPercentile(dca.getSettingPanel().getPercentileforInstanceU());
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;//from  ww w .  j a  va 2 s.  co  m
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    // calculate common coordinates
    int unitHeight = (this.getHeight() - 2 * border) / getHashMapSize();
    int yTop = border;
    int yBottom = this.getHeight() - border;
    int pixStart = 0;
    String dateStr, timeStr, millisStr = null;

    // calculate area to be painted
    clipL = (int) g.getClipBounds().getMinX() - 1;
    clipR = (int) g.getClipBounds().getMaxX() + 1;

    // initialze start color
    fgColor = colorLogDark;
    bgColor = colorLogBright;

    // calculate current top
    int currentTop = yTop;

    // paint actual log lane (only the part in the clipping range determined)
    Iterator itr = dcModel.getSortedKeySetList().iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));
    int index = 0;
    currentTop = yTop;
    while (itr.hasNext()) {

        String dimName = (String) itr.next();
        LogUnitList tempList = ((LogUnitList) dcModel.getItemMap().get(dimName));
        long tempDuration;
        try {
            tempDuration = (tempList
                    .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep())
                    .getTime()
                    - tempList.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(),
                            dcModel.getInstanceTypeToKeep()).getTime());
        } catch (Exception ce) {
            tempDuration = 0;
        }

        if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName))
            continue;
        g.setColor(bgColor);
        g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight);

        g.setColor(fgColor);

        // for bottleneck
        if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances
                && tempDuration >= percentileL && tempDuration <= percentileU)
            g.setColor(Color.red);
        else
            g.setColor(Color.black);
        g.drawString(dimName, pixStart + 5, currentTop + 20);

        index++;
        currentTop = unit2Cord(index);

        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));

    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);

    clipLeftTs = coord2timeMillis(clipL);
    clipRightTs = coord2timeMillis(clipR);

    // draw vertical lines
    // adjust width
    if (bAdjust) {
        adjustWidth();
        bAdjust = false;
    }

    for (long timeStart = dcModel.getLogBoundaryLeft()
            .getTime(); timeStart < clipRightTs; timeStart += dcOptionPanel.getWidthDivider()) {
        pixStart = time2coord(timeStart) + border;
        cal.setTimeInMillis(timeStart);
        g.setColor(colorTimeLine);
        g.drawLine(pixStart, yTop, pixStart, yBottom);
        g.setColor(colorLogDark);
        g.setColor(Color.black); // to be deleted
        if (timeOption.equals(TIME_ACTUAL)) {
            dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "."
                    + cal.get(Calendar.YEAR);
            g.drawString(dateStr, pixStart + 2, yTop);
            timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":"
                    + cal.get(Calendar.SECOND);
            g.drawString(timeStr, pixStart + 2, yTop + 10);
        } else if (timeOption.equals(TIME_RELATIVE_TIME)) {
            long days = timeStart / 1000 / 60 / 60 / 24;
            long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60;
            long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60;
            long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000
                    - minutes * 60 * 1000) / 1000;
            timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds;
            g.drawString(timeStr, pixStart + 2, yTop);
        } else if (timeOption.equals(TIME_RELATIVE_RATIO)) {
            timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%";
            g.drawString(timeStr, pixStart + 2, yTop);
        } else if (timeOption.equals(TIME_LOGICAL) || timeOption.equals(TIME_LOGICAL_RELATIVE)) {
            timeStr = String.valueOf(timeStart);
            g.drawString(timeStr, pixStart + 2, yTop);
        }

    }
}

From source file:edu.ku.brc.services.mapping.LocalityMapper.java

/**
 * Grabs a new map from the web service and appropriately adorns it
 * with labels and markers.//from  ww w .  j a va2 s .co m
 *
 * @return a map image as an icon
 * @throws HttpException a network error occurred while grabbing the map from the service
 * @throws IOException a network error occurred while grabbing the map from the service
 */
protected Icon grabNewMap() throws HttpException, IOException {
    recalculateBoundingBox();

    if (!cacheValid) {
        //            Image mapImage = getMapFromService("mapus.jpl.nasa.gov",
        //                    "/wms.cgi?request=GetMap&srs=EPSG:4326&format=image/png&styles=visual",
        //                    "global_mosaic",
        //                    mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);
        //
        //            Image overlayImage = getMapFromService("129.237.201.132",
        //                    "/cgi-bin/mapserv?map=/var/www/maps/specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&format=image/png&transparent=true",
        //                    "states,rivers",
        //                    mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);

        Image mapImage = getMapFromService("lifemapper.org", //$NON-NLS-1$
                "/ogc?map=specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&STYLES=&format=image/png&transparent=TRUE", //$NON-NLS-1$
                "global_mosaic,states,rivers", //$NON-NLS-1$
                mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);

        mapIcon = new ImageIcon(mapImage);
        //            overlayIcon = new ImageIcon(overlayImage);
        cacheValid = true;

        mapWidth = mapIcon.getIconWidth();
        mapHeight = mapIcon.getIconHeight();

        if (mapWidth < 0 || mapHeight < 0) {
            throw new IOException("Request for map failed.  Received map has negative width or height."); //$NON-NLS-1$
        }

        mapLatRange = mapMaxLat - mapMinLat;
        mapLongRange = mapMaxLong - mapMinLong;

        pixelPerLatRatio = mapHeight / mapLatRange;
        pixelPerLongRatio = mapWidth / mapLongRange;

        for (int i = 0; i < mapLocations.size(); ++i) {
            MapLocationIFace loc = mapLocations.get(i);
            Point iconLoc = determinePixelCoordsOfMapLocationIFace(loc);
            markerLocations.set(i, iconLoc);
        }

        cacheValid = true;
    }

    Icon icon = new Icon() {
        public void paintIcon(Component c, Graphics g, int x, int y) {
            // this helps keep the labels inside the map
            g.setClip(x, y, mapWidth, mapHeight);
            // log the x and y for the MouseMotionListener
            mostRecentPaintedX = x;
            mostRecentPaintedY = y;
            Point currentLocPoint = null;
            if (currentLoc != null) {
                currentLocPoint = determinePixelCoordsOfMapLocationIFace(currentLoc);
            }

            mapIcon.paintIcon(c, g, x, y);
            //                overlayIcon.paintIcon(c, g, x, y);

            Point lastLoc = null;
            for (int i = 0; i < mapLocations.size(); ++i) {
                Point markerLoc = markerLocations.get(i);
                String label = labels.get(i);
                boolean current = (currentLoc != null) && markerLoc.equals(currentLocPoint);

                if (markerLoc == null) {
                    log.error("A marker location is null"); //$NON-NLS-1$
                    continue;
                }
                if (!pointIsOnMapIcon(x + markerLoc.x, y + markerLoc.y)) {
                    log.error("A marker location is off the map"); //$NON-NLS-1$
                    continue;
                }
                if (showArrows && lastLoc != null) {
                    int x1 = x + lastLoc.x;
                    int y1 = y + lastLoc.y;
                    int x2 = x + markerLoc.x;
                    int y2 = y + markerLoc.y;
                    Color origColor = g.getColor();
                    if (current && !animationInProgress) {
                        g.setColor(getCurrentLocColor());
                    } else {
                        g.setColor(arrowColor);
                    }
                    GraphicsUtils.drawArrow(g, x1, y1, x2, y2, 2, 2);
                    g.setColor(origColor);
                }
                if (current) {
                    currentLocMarker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y);
                } else {
                    marker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y);
                }
                if (label != null) {
                    Color origColor = g.getColor();
                    FontMetrics fm = g.getFontMetrics();
                    int length = fm.stringWidth(label);
                    g.setColor(Color.WHITE);
                    g.fillRect(markerLoc.x + x - (length / 2), markerLoc.y + y - (fm.getHeight() / 2), length,
                            fm.getHeight());
                    g.setColor(labelColor);
                    GraphicsUtils.drawCenteredString(label, g, markerLoc.x + x, markerLoc.y + y);
                    g.setColor(origColor);
                }

                lastLoc = markerLoc;
            }
            if (showArrowAnimations && animationInProgress) {
                int startIndex = mapLocations.indexOf(animStartLoc);
                int endIndex = mapLocations.indexOf(animEndLoc);
                if (startIndex != -1 && endIndex != -1) {
                    Point startPoint = markerLocations.get(startIndex);
                    Point endPoint = markerLocations.get(endIndex);
                    Point arrowEnd = GraphicsUtils.getPointAlongLine(startPoint, endPoint, percent);
                    Color orig = g.getColor();
                    g.setColor(getCurrentLocColor());
                    GraphicsUtils.drawArrow(g, startPoint.x + x, startPoint.y + y, arrowEnd.x + x,
                            arrowEnd.y + y, 5, 3);
                    g.setColor(orig);
                }
            }
        }

        public int getIconWidth() {
            return mapWidth;
        }

        public int getIconHeight() {
            return mapHeight;
        }
    };

    return icon;
}