Example usage for java.awt Graphics getClipBounds

List of usage examples for java.awt Graphics getClipBounds

Introduction

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

Prototype

public abstract Rectangle getClipBounds();

Source Link

Document

Returns the bounding rectangle of the current clipping area.

Usage

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

/**
 * paints this log item panel and all contained log items as specified.
 * @param g the graphics object used for painting
*//*w  w w .  j a v a2  s. c  o  m*/
public void paintComponent(Graphics grx) {
    selectedIDIndices.clear(); // for exporting
    bDrawLine = dca.getSettingPanel().isDrawLine();
    //todo
    bBottleneck = dca.getSettingPanel().isBottleneck();
    bBottleneckforInstances = dca.getSettingPanel().isBottleneckforInstance();
    double percentileL = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileL());
    double percentileU = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileU());

    Graphics gr = grx.create();

    if (this.isOpaque()) {
        gr.setColor(colorBg);
        gr.fillRect(0, 0, getWidth(), getHeight());
    }

    // paint the time indicator equipped component lane
    paintComponentLane(gr);

    // calculate are to be painted
    int height = (int) ((double) (getHeight() - (2 * border)));
    int unitHeight = height / getHashMapSize();
    int currentTop = 0;

    // paint items
    if (dcModel.getItemMap().size() > 0) {
        String key = null;
        AbstractLogUnit item = null;
        // iterate through sets
        int index = 0;
        for (Iterator itSets = dcModel.getSortedKeySetList().iterator(); itSets.hasNext();) {
            key = (String) itSets.next();
            // if key is not in instanceIDs, skip..
            if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;

            currentTop = unit2Cord(index) + unitHeight / 2;

            LogUnitList tempUnitList = new LogUnitList();
            AbstractLogUnit olditem = null;

            // for bottleneck
            boolean bInstances = false;
            boolean flag = true;
            if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances) {
                LogUnitList tempUnitList2;
                tempUnitList2 = ((LogUnitList) dcModel.getItemMap().get(key));
                double percentile2L = dcModel.getTimeStatistics().get(0)
                        .getPercentile(dca.getSettingPanel().getPercentileforInstanceL());
                double percentile2U = dcModel.getTimeStatistics().get(0)
                        .getPercentile(dca.getSettingPanel().getPercentileforInstanceU());
                long tempDuration = (tempUnitList2
                        .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(),
                                dcModel.getInstanceTypeToKeep())
                        .getTime()
                        - tempUnitList2.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(),
                                dcModel.getInstanceTypeToKeep()).getTime());
                if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances
                        && tempDuration >= percentile2L && tempDuration <= percentile2U)
                    bInstances = true;
            }
            // end for bottleneck ////////

            // iterate through items
            for (Iterator itItm = ((LogUnitList) dcModel.getItemMap().get(key)).iterator(); itItm.hasNext();) {
                item = (AbstractLogUnit) itItm.next();
                if (dcModel.getEventTypeToKeep() != null
                        && (!dcModel.getEventTypeToKeep().contains(item.getType()) || !dcModel
                                .getInstanceTypeToKeep().contains(item.getProcessInstance().getName())))
                    continue;
                if (bDrawLine && item.getType().equals(dca.getSettingPanel().getStartEvent()))
                    tempUnitList.addEvent(item);
                assignColorByItem(item, gr);
                clipL = (int) gr.getClipBounds().getMinX() - 1;
                clipR = (int) gr.getClipBounds().getMaxX() + 1;
                long clipLeftTs2 = coord2timeMillis(clipL);
                long clipRightTs2 = coord2timeMillis(clipR);
                // if line is added
                if (bDrawLine && item.getType().equals(dca.getSettingPanel().getEndEvent())) {
                    for (Iterator itr = tempUnitList.iterator(); itr.hasNext();) {
                        AbstractLogUnit item2 = (AbstractLogUnit) itr.next();
                        if (item2.getElement().equals(item.getElement())
                                && item2.getProcessInstance().equals(item.getProcessInstance())) {
                            paintItemLine(time2coord(item2.getCurrentTimeStamp()) + border, currentTop,
                                    time2coord(item.getCurrentTimeStamp()) + border, gr);
                            tempUnitList.removeEvent(item2);
                            break;
                        }
                    }
                }

                // if item is not shown on the screen, ship drawing
                if (item.getCurrentTimeStamp() == null || item.getCurrentTimeStamp().getTime() < clipLeftTs2
                        || item.getCurrentTimeStamp().getTime() > clipRightTs2)
                    continue;

                // for botteleneck
                if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneck
                        && olditem != null
                        && (item.getCurrentTimeStamp().getTime()
                                - olditem.getCurrentTimeStamp().getTime()) >= percentileL
                        && (item.getCurrentTimeStamp().getTime()
                                - olditem.getCurrentTimeStamp().getTime()) <= percentileU) {
                    paintItemLineBottleneck(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop,
                            time2coord(item.getCurrentTimeStamp()) + border, gr);
                    this.paintHighligtedItem(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, gr,
                            assignShapeByItem(olditem));
                    this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr,
                            assignShapeByItem(item));
                    this.addExportingList(item);
                    olditem = item;
                    continue;
                }
                // paint an item
                if (bInstances) {
                    this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr,
                            assignShapeByItem(item));
                    if (flag) {
                        this.addExportingList(item);
                        flag = false;
                    }
                } else {
                    this.paintItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr,
                            assignShapeByItem(item));
                }
                olditem = item;
            }
            // move y point
            index++;
        }
    }
    // to do box for zoom
    if (p1 != null && p2 != null) {
        int x1 = Math.min(p1.x, p2.x);
        int y1 = Math.min(p1.y, p2.y);
        int width = Math.abs(p1.x - p2.x);
        height = Math.abs(p1.y - p2.y);
        grx.drawRect(x1, y1, width, height);
    }
    // for exporting
    if (selectedIDIndices.size() > 0) {
        int tempArray[] = new int[selectedIDIndices.size()];
        int i = 0;
        for (Iterator itr = selectedIDIndices.iterator(); itr.hasNext();) {
            tempArray[i++] = (int) ((Integer) itr.next());
        }
        dca.setSelectedInstanceIndicesfromScreen(tempArray);
    }
}