Also update the URL to the CeCILL license. Thanks to Paul for noticing that
[scilab.git] / scilab / modules / renderer / src / java / org / scilab / modules / renderer / JoGLView / interaction / OnePointRubberBox.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Bruno JOFRET
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10  */
11
12 package org.scilab.modules.renderer.JoGLView.interaction;
13
14 import java.awt.Point;
15 import java.awt.event.MouseEvent;
16
17 import org.scilab.forge.scirenderer.tranformations.Vector3d;
18 import org.scilab.modules.renderer.JoGLView.DrawerVisitor;
19 import org.scilab.modules.renderer.JoGLView.interaction.util.PointAComputer;
20
21 /**
22  * @author Bruno JOFRET
23  */
24 public class OnePointRubberBox extends RubberBox implements PointRubberBox {
25
26     /**
27      * Default constructor.
28      *
29      * @param drawerVisitor parent drawer visitor.
30      */
31     public OnePointRubberBox(DrawerVisitor drawerVisitor) {
32         super(drawerVisitor);
33     }
34
35     public OnePointRubberBox(DrawerVisitor drawerVisitor, double initialRect[]) {
36         super(drawerVisitor);
37         firstPoint = new Vector3d(initialRect[0], initialRect[1], 0);
38         secondPoint = firstPoint;
39         status = Status.WAIT_POINT_B;
40         setEnable(true);
41     }
42
43     public double[] getResults() {
44         double result[] = {
45             mouseButton - 1,
46             Math.min(firstPoint.getX(), secondPoint.getX()),
47             Math.max(firstPoint.getY(), secondPoint.getY()),
48             Math.max(firstPoint.getZ(), secondPoint.getZ()),
49             Math.abs(firstPoint.getX() - secondPoint.getX()),
50             Math.abs(firstPoint.getY() - secondPoint.getY()),
51             Math.abs(firstPoint.getZ() - secondPoint.getZ())
52         };
53
54         return result;
55     }
56
57     @Override
58     public void mouseClicked(MouseEvent e) {
59         mouseButton = e.getButton();
60         setPointB(e.getPoint());
61         process();
62         setEnable(false);
63         fireRubberBoxEnd();
64     }
65
66     /**
67      * Set the first point.
68      * @param point first point AWT coordinate.
69      * @return true if the first point is valid.
70      */
71     protected boolean setPointB(Point point) {
72         axes = getUnderlyingAxes(point);
73         if (axes != null) {
74             PointAComputer pointComputer = new PointAComputer(axes, point);
75             if (pointComputer.isValid()) {
76                 pointBComputer = pointComputer;
77                 secondPoint = pointComputer.getPosition();
78                 return true;
79             }
80         }
81         return false;
82     }
83 }