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