X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.trend%2Fsrc%2Forg%2Fsimantics%2Ftrend%2Futil%2FKvikDeviationBuilder.java;fp=bundles%2Forg.simantics.trend%2Fsrc%2Forg%2Fsimantics%2Ftrend%2Futil%2FKvikDeviationBuilder.java;h=ca35b71e6755f530960826c4afd4b0ee1e82068d;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=174249a51b6af696cfa565bba70129426d33106c;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.trend/src/org/simantics/trend/util/KvikDeviationBuilder.java b/bundles/org.simantics.trend/src/org/simantics/trend/util/KvikDeviationBuilder.java index 174249a51..ca35b71e6 100644 --- a/bundles/org.simantics.trend/src/org/simantics/trend/util/KvikDeviationBuilder.java +++ b/bundles/org.simantics.trend/src/org/simantics/trend/util/KvikDeviationBuilder.java @@ -1,163 +1,163 @@ -/******************************************************************************* - * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.trend.util; - -import java.awt.Graphics2D; -import java.awt.geom.Line2D; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; -import java.util.List; - -/** - * DeviationBuilder builds a vertical string of rectangles as an AWT Shape. - * Rectangles are added to the shape, each added to the right hand. - * - * @author toni.kalajainen - */ -public class KvikDeviationBuilder { - - List rects = new ArrayList(); - int rectCount = 0; - - public KvikDeviationBuilder() { - reset(); - } - - public void addRectangle(double x1, double x2, double y1, double y2) - { - if (y1>y2) { - double yy = y1; - y1 = y2; - y2 = yy; - } - - if (y2 == Double.NaN || y1 == Double.NaN || y2 == y1) { - return; - } - - Rectangle2D.Double lastRect = lastRect(); - if ( lastRect!=null ) { - double lx1 = lastRect.x; - double lx2 = lastRect.x + lastRect.width; - double ly1 = lastRect.y; - double ly2 = lastRect.y + lastRect.height; - - // Extends min-max of prev rectangle - if (x1==lx1 && x2==lx2) { - if (y2ly2) lastRect.height = y1 - lastRect.y; - return; - } - - // Change the last values - if (x1==lx2 && y1==ly1 && y2==ly2) { - lastRect.width = x2 - lastRect.x; - return; - } - } - - // Add new region - Rectangle2D.Double r = newRect(); - r.x=x1; - r.y=y1; - r.width=x2-x1; - r.height=y2-y1; - } - - /** - * Extend the previous rectangle to the left - * - * @param x1 - * @param x2 - * @param low - * @param high - */ - public void appendRectangle(double xx, double low, double high) - { - Rectangle2D.Double lastRect = lastRect(); - if ( lastRect!=null ) { - addRectangle(lastRect.x+lastRect.width, xx, low, high); - } else { - addRectangle(xx, xx, low, high); - } - } - - public void extendRectangle(double toX) - { - Rectangle2D.Double lastRect = lastRect(); - if ( lastRect == null ) return; - lastRect.width = toX - lastRect.x; - } - - public boolean isEmpty() { - return rectCount == 0; - } - - public void reset() { - rectCount = 0; - } - - /** - * Draw the shape with lines. This is the fastest for screen but not good for printer drawing - * - * @param g - */ - public void drawLines(Graphics2D g) { - Line2D.Double line = new Line2D.Double(); - for (int i=0; i rects = new ArrayList(); + int rectCount = 0; + + public KvikDeviationBuilder() { + reset(); + } + + public void addRectangle(double x1, double x2, double y1, double y2) + { + if (y1>y2) { + double yy = y1; + y1 = y2; + y2 = yy; + } + + if (y2 == Double.NaN || y1 == Double.NaN || y2 == y1) { + return; + } + + Rectangle2D.Double lastRect = lastRect(); + if ( lastRect!=null ) { + double lx1 = lastRect.x; + double lx2 = lastRect.x + lastRect.width; + double ly1 = lastRect.y; + double ly2 = lastRect.y + lastRect.height; + + // Extends min-max of prev rectangle + if (x1==lx1 && x2==lx2) { + if (y2ly2) lastRect.height = y1 - lastRect.y; + return; + } + + // Change the last values + if (x1==lx2 && y1==ly1 && y2==ly2) { + lastRect.width = x2 - lastRect.x; + return; + } + } + + // Add new region + Rectangle2D.Double r = newRect(); + r.x=x1; + r.y=y1; + r.width=x2-x1; + r.height=y2-y1; + } + + /** + * Extend the previous rectangle to the left + * + * @param x1 + * @param x2 + * @param low + * @param high + */ + public void appendRectangle(double xx, double low, double high) + { + Rectangle2D.Double lastRect = lastRect(); + if ( lastRect!=null ) { + addRectangle(lastRect.x+lastRect.width, xx, low, high); + } else { + addRectangle(xx, xx, low, high); + } + } + + public void extendRectangle(double toX) + { + Rectangle2D.Double lastRect = lastRect(); + if ( lastRect == null ) return; + lastRect.width = toX - lastRect.x; + } + + public boolean isEmpty() { + return rectCount == 0; + } + + public void reset() { + rectCount = 0; + } + + /** + * Draw the shape with lines. This is the fastest for screen but not good for printer drawing + * + * @param g + */ + public void drawLines(Graphics2D g) { + Line2D.Double line = new Line2D.Double(); + for (int i=0; i