X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.scenegraph.swing%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fswing%2FJFreeTrendNode.java;h=f2c61f88ba9218b1853819cc3f38f9079fd0a08f;hb=refs%2Fchanges%2F38%2F238%2F2;hp=380aa5c9879d7bd034e12999a3e419009910d093;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/JFreeTrendNode.java b/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/JFreeTrendNode.java index 380aa5c98..f2c61f88b 100644 --- a/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/JFreeTrendNode.java +++ b/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/JFreeTrendNode.java @@ -1,36 +1,36 @@ -/******************************************************************************* - * 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.awt.geom.Rectangle2D; -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.IdentityAffineTransform; -import org.simantics.scenegraph.g2d.nodes.Trend2DNode.TrendPoint; - +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +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.IdentityAffineTransform; +import org.simantics.scenegraph.g2d.nodes.Trend2DNode.TrendPoint; + @RasterOutputWidget public class JFreeTrendNode extends ComponentNode { @@ -44,62 +44,62 @@ public class JFreeTrendNode extends ComponentNode { protected String xTitle = null; protected transient List points = null; - protected transient XYSeries series = null; + protected transient XYSeries series = null; - @Override - public void init() { - series = new XYSeries("Trend"); - final XYSeriesCollection dataset = new XYSeriesCollection(series); - if(title == null) title = "Trend"; - if(xTitle == null) xTitle = "Value"; - if(yTitle == null) yTitle = "Time"; - scale = true; - - - final JFreeChart chart = ChartFactory.createXYLineChart( - title, - xTitle, - yTitle, - 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); - } - - if(points != null) { - for(TrendPoint p : points) { - try { - series.add(p.getX(), p.getY()); - } catch(org.jfree.data.general.SeriesException e) { - - } - } - } - super.init(); - } + @Override + public void init() { + series = new XYSeries("Trend"); + final XYSeriesCollection dataset = new XYSeriesCollection(series); + if(title == null) title = "Trend"; + if(xTitle == null) xTitle = "Value"; + if(yTitle == null) yTitle = "Time"; + scale = true; + + + final JFreeChart chart = ChartFactory.createXYLineChart( + title, + xTitle, + yTitle, + 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); + } + + if(points != null) { + for(TrendPoint p : points) { + try { + series.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(); - + AffineTransform ot = g2d.getTransform(); + double scaleX = ot.getScaleX(); double scaleY = ot.getScaleY(); - - if (transform == IdentityAffineTransform.INSTANCE) + + if (transform == IdentityAffineTransform.INSTANCE) transform = new AffineTransform(); synchronized(transform) { transform.setToTranslation(bounds.getMinX(), bounds.getMinY()); @@ -111,13 +111,13 @@ public class JFreeTrendNode extends ComponentNode { 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); } - } + } @SyncField("title") public void setTitle(String title) { @@ -129,21 +129,21 @@ public class JFreeTrendNode extends ComponentNode { @SyncField("xTitle") public void setXTitle(String xTitle) { this.xTitle = xTitle; - if(component != null) - ((ChartPanel)component).getChart().getXYPlot().getDomainAxis().setLabel(xTitle); + if(component != null) + ((ChartPanel)component).getChart().getXYPlot().getDomainAxis().setLabel(xTitle); } @SyncField("yTitle") public void setYTitle(String yTitle) { this.yTitle = yTitle; - if(component != null) - ((ChartPanel)component).getChart().getXYPlot().getRangeAxis().setLabel(yTitle); + if(component != null) + ((ChartPanel)component).getChart().getXYPlot().getRangeAxis().setLabel(yTitle); } @SyncField("bounds") public void setBounds(Rectangle2D bounds) { - this.bounds = bounds; -// width = (int)bounds.getWidth(); + this.bounds = bounds; +// width = (int)bounds.getWidth(); // height = (int)bounds.getHeight(); }