X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph.swing%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fswing%2FMultiVariableTrendNode.java;h=23fb1465ba6d7422095091316f633c9fdc2a6a67;hb=b2f1da4c219c646ba3fce0498bf757d64c6dca6d;hp=1d4a6c4b88f8ef3322e5ef59b50e2ca901f2558f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/MultiVariableTrendNode.java b/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/MultiVariableTrendNode.java index 1d4a6c4b8..23fb1465b 100644 --- a/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/MultiVariableTrendNode.java +++ b/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/MultiVariableTrendNode.java @@ -1,34 +1,34 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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 - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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.scenegraph.swing; -import java.awt.Graphics2D; -import java.awt.geom.AffineTransform; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.simantics.scenegraph.ExportableWidget.RasterOutputWidget; -import org.simantics.scenegraph.g2d.nodes.Trend2DNode.TrendPoint; - +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JPanel; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.simantics.scenegraph.ExportableWidget.RasterOutputWidget; +import org.simantics.scenegraph.g2d.nodes.Trend2DNode.TrendPoint; + @RasterOutputWidget public class MultiVariableTrendNode extends ComponentNode { @@ -36,65 +36,65 @@ public class MultiVariableTrendNode extends ComponentNode { * */ private static final long serialVersionUID = 8508750881358776559L; - + protected transient JFreeChart chart = null; protected transient List> points = new ArrayList>(); - protected transient XYSeriesCollection dataset = null; + protected transient XYSeriesCollection dataset = null; - @Override - public void init() { - XYSeries serie = new XYSeries("Trend"); - dataset = new XYSeriesCollection(serie); - scale = false; - - chart = ChartFactory.createXYLineChart( - "Trend", // Title - "Value", // X-title - "Time", // Y-title - dataset, - PlotOrientation.VERTICAL, - false, - true, - false - ); - final XYPlot plot = chart.getXYPlot(); - ValueAxis axis = plot.getDomainAxis(); - axis.setAutoRange(true); -// axis.setFixedAutoRange(60000.0); // 60 seconds - - component = new ChartPanel(chart, false); - ((ChartPanel)component).setRefreshBuffer(false); - component.setIgnoreRepaint(true); - component.setDoubleBuffered(false); - if(bounds != null) { - component.setBounds(0, 0, 0, 0); - } - - for(int i = 0; i < points.size(); i++) { - if(dataset.getSeriesCount() < i) { - XYSeries s = new XYSeries("Serie "+(i+1)); - dataset.addSeries(s); - dataset.addSeries(s); - } - for(TrendPoint p : points.get(i)) { - try { - dataset.getSeries(i).add(p.getX(), p.getY()); - } catch(org.jfree.data.general.SeriesException e) { - - } - } - } - super.init(); - } + @Override + public void init() { + XYSeries serie = new XYSeries("Trend"); + dataset = new XYSeriesCollection(serie); + scale = false; + + chart = ChartFactory.createXYLineChart( + "Trend", // Title + "Value", // X-title + "Time", // Y-title + dataset, + PlotOrientation.VERTICAL, + false, + true, + false + ); + final XYPlot plot = chart.getXYPlot(); + ValueAxis axis = plot.getDomainAxis(); + axis.setAutoRange(true); +// axis.setFixedAutoRange(60000.0); // 60 seconds + + component = new ChartPanel(chart, false); + ((ChartPanel)component).setRefreshBuffer(false); + component.setIgnoreRepaint(true); + component.setDoubleBuffered(false); + if(bounds != null) { + component.setBounds(0, 0, 0, 0); + } + + for(int i = 0; i < points.size(); i++) { + if(dataset.getSeriesCount() < i) { + XYSeries s = new XYSeries("Serie "+(i+1)); + dataset.addSeries(s); + dataset.addSeries(s); + } + for(TrendPoint p : points.get(i)) { + try { + dataset.getSeries(i).add(p.getX(), p.getY()); + } catch(org.jfree.data.general.SeriesException e) { + + } + } + } + super.init(); + } @Override public void render(Graphics2D g2d) { - if (component != null) { - AffineTransform ot = g2d.getTransform(); - g2d.transform(transform); + if (component != null) { + AffineTransform ot = g2d.getTransform(); + g2d.transform(transform); double scaleX = g2d.getTransform().getScaleX(); double scaleY = g2d.getTransform().getScaleY(); - + AffineTransform at = new AffineTransform(); at.setToTranslation(bounds.getMinX(), bounds.getMinY()); at.scale(1/scaleX, 1/scaleY); @@ -102,55 +102,55 @@ public class MultiVariableTrendNode extends ComponentNode { int width = (int)(bounds.getWidth() * scaleX); int height = (int)(bounds.getHeight() * scaleY); - synchronized(component) { - component.setLocation((int)g2d.getTransform().getTranslateX(), (int)g2d.getTransform().getTranslateY()); + synchronized(component) { + component.setLocation((int)g2d.getTransform().getTranslateX(), (int)g2d.getTransform().getTranslateY()); if(component.getSize().getWidth() != width || component.getSize().getHeight() != height) { - component.setSize(width, height); + component.setSize(width, height); } - component.paint(g2d); - } + component.paint(g2d); + } g2d.setTransform(ot); } - } - + } + @PropertySetter("Title") @ClientSide public void setTitle(String title) { if(component != null) { - synchronized(component) { - ((ChartPanel)component).getChart().setTitle(title); - } + synchronized(component) { + ((ChartPanel)component).getChart().setTitle(title); + } } } - + @PropertySetter("X-Axis Label") - @ClientSide + @ClientSide public void setXTitle(String xTitle) { - if(component != null) { - synchronized(component) { - ((ChartPanel)component).getChart().getXYPlot().getDomainAxis().setLabel(xTitle); - } - } + if(component != null) { + synchronized(component) { + ((ChartPanel)component).getChart().getXYPlot().getDomainAxis().setLabel(xTitle); + } + } } - + @PropertySetter("Y-Axis Label") - @ClientSide + @ClientSide public void setYTitle(String yTitle) { - if(component != null) { - synchronized(component) { - ((ChartPanel)component).getChart().getXYPlot().getRangeAxis().setLabel(yTitle); - } - } - } + if(component != null) { + synchronized(component) { + ((ChartPanel)component).getChart().getXYPlot().getRangeAxis().setLabel(yTitle); + } + } + } - @ClientSide - public void setPoints(List points, Integer serie) { - while(dataset.getSeriesCount() <= serie) { - this.points.add(new ArrayList()); - dataset.addSeries(new XYSeries("Trend "+(dataset.getSeriesCount()+1))); + @ClientSide + public void setPoints(List points, Integer serie) { + while(dataset.getSeriesCount() <= serie) { + this.points.add(new ArrayList()); + dataset.addSeries(new XYSeries("Trend "+(dataset.getSeriesCount()+1))); } this.points.add(serie, points); - synchronized(component) { + synchronized(component) { dataset.getSeries(serie.intValue()).clear(); for(TrendPoint p : points) { try { @@ -158,16 +158,16 @@ public class MultiVariableTrendNode extends ComponentNode { } catch(org.jfree.data.general.SeriesException e) { } - } + } } } @ClientSide protected void appendPoints(List points, Integer serie) { - while(dataset.getSeriesCount() <= serie) { - this.points.add(new ArrayList()); - dataset.addSeries(new XYSeries("Trend "+(dataset.getSeriesCount()+1))); - } + while(dataset.getSeriesCount() <= serie) { + this.points.add(new ArrayList()); + dataset.addSeries(new XYSeries("Trend "+(dataset.getSeriesCount()+1))); + } /** * We need to have the same set of points on the both sides, so locally the points are just updated, * but on remote side we send only the new points.