Example usage for java.awt Graphics drawLine

List of usage examples for java.awt Graphics drawLine

Introduction

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

Prototype

public abstract void drawLine(int x1, int y1, int x2, int y2);

Source Link

Document

Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

Usage

From source file:se.llbit.chunky.renderer.ui.RenderControls.java

public void drawViewBounds(Graphics g, ChunkView cv) {
    Camera camera = renderMan.scene().camera();
    int width = renderMan.scene().canvasWidth();
    int height = renderMan.scene().canvasHeight();

    double halfWidth = width / (2.0 * height);

    Ray ray = new Ray();

    int[] corners = { -1, -1, -1, -1, -1, -1, -1, -1 };

    camera.calcViewRay(ray, -halfWidth, -0.5);
    findMapPos(corners, 0, 1, ray, cv);//from  ww w.  j  a va 2 s  . c o m

    camera.calcViewRay(ray, -halfWidth, 0.5);
    findMapPos(corners, 2, 3, ray, cv);

    camera.calcViewRay(ray, halfWidth, 0.5);
    findMapPos(corners, 4, 5, ray, cv);

    camera.calcViewRay(ray, halfWidth, -0.5);
    findMapPos(corners, 6, 7, ray, cv);

    g.setColor(Color.YELLOW);

    g.drawLine(corners[0], corners[1], corners[2], corners[3]);
    g.drawLine(corners[2], corners[3], corners[4], corners[5]);
    g.drawLine(corners[4], corners[5], corners[6], corners[7]);
    g.drawLine(corners[6], corners[7], corners[0], corners[1]);

    int ox = (int) (cv.scale * (ray.o.x / 16 - cv.x0));
    int oy = (int) (cv.scale * (ray.o.z / 16 - cv.z0));
    g.drawLine(ox - 5, oy, ox + 5, oy);
    g.drawLine(ox, oy - 5, ox, oy + 5);

    camera.calcViewRay(ray, 0, 0);
    Vector3d o = new Vector3d(ray.o);
    o.x /= 16;
    o.z /= 16;
    o.scaleAdd(1, ray.d);
    int x = (int) (cv.scale * (o.x - cv.x0));
    int y = (int) (cv.scale * (o.z - cv.z0));
    g.drawLine(ox, oy, x, y);

}

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 w  w w. ja v a2s .  c o  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: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 av a  2s  .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:org.kineticsystem.commons.layout.TetrisLayout.java

/**
 * <p>This method draws the layout on a graphics context. Used to test the
 * layout during the design process. Override the 
 * <code>paint(Graphics g)</code> of the container to display the layout.
 * Here is an example code where <code>layout</code> is a 
 * <code>TestrisLayout</code>.</p>
 * <pre>/* w  ww . j  ava 2  s .co m*/
 * JPanel panel = new JPanel(layout) {
 *     public void paint(Graphics g) {
 *         super.paint(g);
 *         ((TetrisLayout) getLayout()).drawLayout(g);
 *     }
 * };
 * </pre>
 * @param g The graphics context.
 */
public void drawLayout(Graphics g) {

    // Draw the spanning layout.

    g.setColor(spanningLayoutColor);

    Insets insets = container.getInsets();
    Dimension size = container.getSize();

    int actualGapFreeWidth = Math
            .max(size.width - insets.left - insets.right - cGaps[cBars.length].getIncSize(), 0);
    int actualGapFreeHeight = Math
            .max(size.height - insets.top - insets.bottom - rGaps[rBars.length].getIncSize(), 0);

    for (Cell cell : constraintsMap.values()) {

        if (cell != null) {

            /*
             * Calculate the center of the first and the last cell spanned
             * by the current component.
             */

            int cx0 = (int) Math.round((cSizes[cell.getCol()].evaluate(actualGapFreeWidth)
                    + cSizes[cell.getCol() + 1].evaluate(actualGapFreeWidth)) / 2);
            int cy0 = (int) Math.round((rSizes[cell.getRow()].evaluate(actualGapFreeHeight)
                    + rSizes[cell.getRow() + 1].evaluate(actualGapFreeHeight)) / 2);
            int cx1 = (int) Math.round((cSizes[cell.getCol() + cell.getCols()].evaluate(actualGapFreeWidth)
                    + cSizes[cell.getCol() + cell.getCols() - 1].evaluate(actualGapFreeWidth)) / 2) + 1;
            int cy1 = (int) Math.round((rSizes[cell.getRow() + cell.getRows()].evaluate(actualGapFreeHeight)
                    + rSizes[cell.getRow() + cell.getRows() - 1].evaluate(actualGapFreeHeight)) / 2) + 1;

            // Actual cell dimension.

            int w = cx1 - cx0;
            int h = cy1 - cy0;

            // Component position correction.

            int xCorrection = insets.left + cGaps[cell.getCol()].getIncSize();
            int yCorrection = insets.top + rGaps[cell.getRow()].getIncSize();

            // Component dimension correction.

            int wCorrection = cGaps[cell.getCol() + cell.getCols() - 1].getIncSize()
                    - cGaps[cell.getCol()].getIncSize();
            int hCorrection = rGaps[cell.getRow() + cell.getRows() - 1].getIncSize()
                    - rGaps[cell.getRow()].getIncSize();

            cx0 += xCorrection;
            cy0 += yCorrection;
            w += wCorrection;
            h += hCorrection;

            int radius = 6;
            g.drawRect(cx0 + 1, cy0 + 1, w - 1, h - 1);
            g.drawOval(cx0 + 1 - radius / 2, cy0 + 1 - radius / 2, radius, radius);
            g.drawOval(cx0 + w - radius / 2, cy0 + h - radius / 2, radius, radius);
        }
    }

    // Draw the internal layout.

    g.setColor(internalLayoutColor);

    int x2 = (int) Math.round(cSizes[cSizes.length - 1].evaluate(actualGapFreeWidth)
            + cGaps[cSizes.length - 1].getIncSize() + insets.left) - 1;
    int y2 = (int) Math.round(rSizes[rSizes.length - 1].evaluate(actualGapFreeHeight)
            + rGaps[rSizes.length - 1].getIncSize() + insets.top) - 1;

    for (int i = 1; i < cSizes.length - 1; i++) {
        int x = (int) Math
                .round(cSizes[i].evaluate(actualGapFreeWidth) + insets.left + cGaps[i - 1].getIncSize());
        g.drawLine(x, insets.top, x, y2);
        g.drawLine(x + cGaps[i].getSize(), insets.top, x + cGaps[i].getSize(), y2);
    }
    for (int i = 1; i < rSizes.length - 1; i++) {
        int y = (int) Math
                .round(rSizes[i].evaluate(actualGapFreeHeight) + insets.top + rGaps[i - 1].getIncSize());
        g.drawLine(insets.left, y, x2, y);
        g.drawLine(insets.left, y + rGaps[i].getSize(), x2, y + rGaps[i].getSize());
    }

    // Draw the layout internal frame.

    g.setColor(externalLayoutColor);
    g.drawRect(insets.left, insets.top, x2 - insets.left, y2 - insets.top);

    // Draw layout external frame.

    g.drawRect(0, 0, x2 + insets.right, y2 + insets.bottom);
}

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 {// ww  w.  j  a va  2s .  co  m
        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: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   w w  w  .jav a2 s . c  o  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:org.processmining.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  w  ww. j a  v  a  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:lu.fisch.unimozer.Diagram.java

private void drawLine(Graphics g, Point a, Point b) {
    g.drawLine(a.x, a.y, b.x, b.y);
}

From source file:lu.fisch.unimozer.Diagram.java

private void printHeaderFooter(Graphics g, PageFormat pageFormat, int page, String className) {
    int origPage = page + 1;

    // Add header
    g.setColor(Color.BLACK);/*  ww w .java 2 s. c  om*/
    int xOffset = (int) pageFormat.getImageableX();
    int topOffset = (int) pageFormat.getImageableY() + 20;
    int bottom = (int) (pageFormat.getImageableY() + pageFormat.getImageableHeight());
    // header line
    g.drawLine(xOffset, topOffset - 8, xOffset + (int) pageFormat.getImageableWidth(), topOffset - 8);
    // footer line
    g.drawLine(xOffset, bottom - 11, xOffset + (int) pageFormat.getImageableWidth(), bottom - 11);
    g.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 10));

    Graphics2D gg = (Graphics2D) g;
    String pageString = "Page " + origPage;
    int tw = (int) gg.getFont().getStringBounds(pageString, gg.getFontRenderContext()).getWidth();
    // footer text
    g.drawString(pageString, xOffset + (int) pageFormat.getImageableWidth() - tw, bottom - 2);

    //System.err.println("Printing: "+directoryName);
    if (directoryName != null) {
        g.setFont(new Font(g.getFont().getFontName(), Font.ITALIC, 10));
        String filename = directoryName;
        if (!className.equals(""))
            filename += System.getProperty("file.separator") + className + ".java";
        // header text
        g.drawString(filename, xOffset, bottom - 2);
        File f = new File(filename);
        //System.err.println("Printing: "+filename);
        if (f.exists()) {
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            java.util.Date date = new java.util.Date();
            date.setTime(f.lastModified());
            String myDate = dateFormat.format(date);
            int w = (int) gg.getFont().getStringBounds(myDate, gg.getFontRenderContext()).getWidth();
            // header text
            g.drawString("File last modified on " + myDate, xOffset, topOffset - 10);
        }
    }
}

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

/**
 * {@inheritDoc}//w w  w .  java 2s  .  c  o  m
 */
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);
    }
}