]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/impl/TrendGraphicalNode.java
Render last known value in time series chart hairline value tip
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / impl / TrendGraphicalNode.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.trend.impl;
13
14 import java.awt.Graphics2D;
15 import java.awt.geom.AffineTransform;
16 import java.awt.geom.Rectangle2D;
17
18 import org.simantics.scenegraph.g2d.G2DNode;
19
20 public abstract class TrendGraphicalNode extends G2DNode implements TrendLayout {
21
22         private static final long serialVersionUID = 1L;
23         
24         Rectangle2D bounds = new Rectangle2D.Double();
25
26         public double getWidth() { 
27                 return bounds.getWidth();
28         }
29         
30         public double getHeight() {
31                 return bounds.getHeight();
32         }
33         
34         public void setSize(double w, double h) {
35                 if (bounds.getWidth()==w && bounds.getHeight()==h) return;
36                 bounds.setFrame(0, 0, w, h);
37         }
38         
39         public double getX() {
40                 return transform.getTranslateX();
41         }
42         
43         public double getY() {
44                 return transform.getTranslateY();
45         }
46         
47         public void setTranslate(double x, double y) {
48                 setTransform(AffineTransform.getTranslateInstance(x, y));
49         }
50         
51         @Override
52         public Rectangle2D getBoundsInLocal() {
53                 return bounds;
54         }
55
56         @Override
57         public void render(Graphics2D g2d) {
58                 AffineTransform at = g2d.getTransform();
59                 g2d.transform( transform );
60                 try {
61                         doRender(g2d);
62                 } finally {
63                         g2d.setTransform(at);
64                 }
65         }
66         
67         public TrendNode getTrend() {
68                 return (TrendNode) getParent();
69         }
70         
71         protected abstract void doRender(Graphics2D g2d);
72
73         
74 }