1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.trend.impl;
14 import java.awt.AlphaComposite;
15 import java.awt.BasicStroke;
16 import java.awt.Color;
17 import java.awt.Composite;
18 import java.awt.Graphics2D;
19 import java.awt.geom.Point2D;
20 import java.awt.geom.Rectangle2D;
22 import org.simantics.scenegraph.g2d.G2DNode;
24 public class SelectionNode extends G2DNode {
26 private static final long serialVersionUID = -8803833805847402592L;
28 public static AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
29 public static final Color COLOR = new Color(.5f, .5f, 1.f);
30 public static final BasicStroke STROKE =
32 BasicStroke.CAP_SQUARE,
33 BasicStroke.CAP_SQUARE,
36 double x1, x2, y1, y2;
37 Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, 1, 1);
38 Rectangle2D.Double rect2 = new Rectangle2D.Double(0, 0, 1, 1);
39 boolean binaryZoom = false, timeZoom = false;
41 public void start(Point2D pt, boolean binaryZoom, boolean timeZoom)
45 rect.setFrame(x1, y1, 0, 0);
46 rect2.setFrame(x1, y1, 0, 0);
47 this.binaryZoom = binaryZoom;
48 this.timeZoom = timeZoom;
51 public void setEndPoint(Point2D pt)
58 public void layout() {
59 TrendNode trend = (TrendNode) getParent();
60 Plot plot = trend.plot;
64 double px = plot.getX();
65 double py = plot.getY()+plot.analogAreaHeight;
66 double pw = plot.getWidth();
67 double ph = plot.binaryAreaHeight;
69 rect2.setFrame( Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2), Math.abs(y1-y2) );
71 double _x1 = Math.min( Math.max( x1, px ), px+pw);
72 double _x2 = Math.min( Math.max( x2, px ), px+pw);
74 rect.setFrame( Math.min(_x1, _x2), py, Math.abs(_x1-_x2), ph );
77 double px = plot.getX();
78 double py = plot.getY();
79 double pw = plot.getWidth();
80 double ph = plot.analogAreaHeight;
82 rect2.setFrame( Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2), Math.abs(y1-y2) );
84 double _x1 = Math.min( Math.max( x1, px ), px+pw);
85 double _x2 = Math.min( Math.max( x2, px ), px+pw);
86 double _y1 = Math.min( Math.max( y1, py ), py+ph);
87 double _y2 = Math.min( Math.max( y2, py ), py+ph);
90 rect.setFrame( Math.min(_x1, _x2), py, Math.abs(_x1-_x2), plot.analogAreaHeight );
92 rect.setFrame( Math.min(_x1, _x2), Math.min(_y1, _y2), Math.abs(_x1-_x2), Math.abs(_y1-_y2) );
99 public void render(Graphics2D g2d) {
100 Composite c = g2d.getComposite();
101 g2d.setComposite( composite );
102 g2d.setColor( COLOR );
104 g2d.setComposite( c );
105 g2d.setStroke( STROKE );
110 public Rectangle2D getBoundsInLocal() {