Search in sources :

Example 1 with MetricsPainter

use of org.pentaho.di.core.logging.MetricsPainter in project pentaho-kettle by pentaho.

the class TransMetricsDelegate method refreshImage.

private void refreshImage(GC canvasGc) {
    List<MetricsDuration> durations = MetricsUtil.getAllDurations(transGraph.trans.getLogChannelId());
    if (Utils.isEmpty(durations)) {
        // In case of an empty durations or null there is nothing to draw
        return;
    }
    // Sort the metrics.
    Collections.sort(durations, new Comparator<MetricsDuration>() {

        @Override
        public int compare(MetricsDuration o1, MetricsDuration o2) {
            return o1.getDate().compareTo(o2.getDate());
        }
    });
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    if (transGraph.trans == null) {
        image = null;
        return;
    }
    // 
    if (image != null && (System.currentTimeMillis() - lastRefreshTime) < 5000) {
        return;
    }
    lastRefreshTime = System.currentTimeMillis();
    if (image != null) {
        // prevent out of memory...
        image.dispose();
        image = null;
    }
    // Correct size of canvas.
    org.eclipse.swt.graphics.Point textExtent = canvasGc.textExtent("AagKkiw");
    int height = textExtent.y + 8;
    // Make the height larger if needed for clarify
    // 
    bounds.height = Math.max(durations.size() * height, bounds.height);
    canvas.setSize(bounds.width, bounds.height);
    SWTGC gc = new SWTGC(Display.getCurrent(), new Point(bounds.width, bounds.height), PropsUI.getInstance().getIconSize());
    MetricsPainter painter = new MetricsPainter(gc, height);
    drawAreas = painter.paint(durations);
    image = (Image) gc.getImage();
    // refresh the scrolled composite
    // 
    sMetricsComposite.setMinHeight(bounds.height);
    sMetricsComposite.setMinWidth(bounds.width);
    sMetricsComposite.layout(true, true);
    // Draw the image on the canvas...
    // 
    canvas.redraw();
    // close shop on the SWT GC side.
    // 
    gc.dispose();
}
Also used : SWTGC(org.pentaho.di.ui.spoon.SWTGC) MetricsPainter(org.pentaho.di.core.logging.MetricsPainter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.pentaho.di.core.gui.Point) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Point(org.pentaho.di.core.gui.Point)

Example 2 with MetricsPainter

use of org.pentaho.di.core.logging.MetricsPainter in project pentaho-kettle by pentaho.

the class JobMetricsDelegate method refreshImage.

private void refreshImage(GC canvasGc) {
    List<MetricsDuration> durations = MetricsUtil.getAllDurations(jobGraph.job.getLogChannelId());
    if (Utils.isEmpty(durations)) {
        // In case of an empty durations or null there is nothing to draw
        return;
    }
    // Sort the metrics.
    Collections.sort(durations, new Comparator<MetricsDuration>() {

        @Override
        public int compare(MetricsDuration o1, MetricsDuration o2) {
            return o1.getDate().compareTo(o2.getDate());
        }
    });
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    if (jobGraph.job == null) {
        image = null;
        return;
    }
    // 
    if (image != null && (System.currentTimeMillis() - lastRefreshTime) < 5000) {
        return;
    }
    lastRefreshTime = System.currentTimeMillis();
    if (image != null) {
        // prevent out of memory...
        image.dispose();
        image = null;
    }
    // Correct size of canvas.
    // 
    org.eclipse.swt.graphics.Point textExtent = canvasGc.textExtent("AagKkiw");
    int barHeight = textExtent.y + 8;
    // Make the height larger if needed for clarify
    // 
    bounds.height = Math.max(durations.size() * barHeight, bounds.height);
    canvas.setSize(bounds.width, bounds.height);
    SWTGC gc = new SWTGC(Display.getCurrent(), new Point(bounds.width, bounds.height), PropsUI.getInstance().getIconSize());
    MetricsPainter painter = new MetricsPainter(gc, barHeight);
    // checking according to method's contract
    drawAreas = painter.paint(durations);
    image = (Image) gc.getImage();
    // refresh the scrolled composite
    // 
    // sMetricsComposite.setMinHeight(bounds.height);
    // sMetricsComposite.setMinWidth(bounds.width);
    sMetricsComposite.layout(true, true);
    // close shop on the SWT GC side.
    // 
    gc.dispose();
    // Draw the image on the canvas...
    // 
    canvas.redraw();
}
Also used : SWTGC(org.pentaho.di.ui.spoon.SWTGC) MetricsPainter(org.pentaho.di.core.logging.MetricsPainter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.pentaho.di.core.gui.Point) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Point(org.pentaho.di.core.gui.Point)

Example 3 with MetricsPainter

use of org.pentaho.di.core.logging.MetricsPainter in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceTestMetrics method refreshImage.

private synchronized Image refreshImage() {
    Display device = metricsComposite.getDisplay();
    Rectangle bounds = metricsComposite.getBounds();
    if (image != null) {
        Rectangle imageBounds = image.getBounds();
        // Check if image in cache fits
        if (imageBounds.width == bounds.width && imageBounds.height >= bounds.height) {
            return image;
        } else {
            // Need to regenerate
            image.dispose();
            image = null;
        }
    }
    String metricsMessage = BaseMessages.getString(DataServiceTestController.PKG, "DataServiceTest.MetricsPlaceholder");
    org.eclipse.swt.graphics.Point textExtent = new GC(canvas).textExtent(metricsMessage);
    if (durations.isEmpty()) {
        bounds.height = textExtent.y * 2;
        image = new Image(device, bounds.width, bounds.height);
        GC gc = new GC(image);
        gc.drawText(metricsMessage, (bounds.width - textExtent.x) / 2, textExtent.y / 2);
    } else {
        // Adjust height to fit all bars
        int barHeight = textExtent.y + 5;
        bounds.height = Math.max(20 + durations.size() * (barHeight + 5), bounds.height);
        SWTGC gc = new SWTGC(device, new Point(bounds.width, bounds.height), PropsUI.getInstance().getIconSize());
        MetricsPainter painter = new MetricsPainter(gc, barHeight);
        painter.paint(durations);
        image = (Image) gc.getImage();
        gc.dispose();
    }
    metricsComposite.setMinHeight(bounds.height);
    metricsComposite.layout();
    return image;
}
Also used : SWTGC(org.pentaho.di.ui.spoon.SWTGC) MetricsPainter(org.pentaho.di.core.logging.MetricsPainter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.pentaho.di.core.gui.Point) GC(org.eclipse.swt.graphics.GC) SWTGC(org.pentaho.di.ui.spoon.SWTGC) Image(org.eclipse.swt.graphics.Image) Point(org.pentaho.di.core.gui.Point) Display(org.eclipse.swt.widgets.Display)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)3 Point (org.pentaho.di.core.gui.Point)3 MetricsPainter (org.pentaho.di.core.logging.MetricsPainter)3 SWTGC (org.pentaho.di.ui.spoon.SWTGC)3 MetricsDuration (org.pentaho.di.core.metrics.MetricsDuration)2 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 Display (org.eclipse.swt.widgets.Display)1