cc2d9c10f4fbbde38fa513074a54394c874265f8
[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         double[][] factors = axes.getScaleTranslateFactors();
38         firstPoint = new Vector3d(initialRect[0] * factors[0][0] + factors[1][0],
39                 initialRect[1] * factors[0][1] + factors[1][1],
40                 0);
41         secondPoint = firstPoint;
42         status = Status.WAIT_POINT_B;
43         setEnable(true);
44     }
45
46     @Override
47     public void mouseClicked(MouseEvent e) {
48         mouseButton = e.getButton();
49         setPointB(e.getPoint());
50         process();
51         setEnable(false);
52         fireRubberBoxEnd();
53     }
54
55     /**
56      * Set the first point.
57      * @param point first point AWT coordinate.
58      * @return true if the first point is valid.
59      */
60     protected boolean setPointB(Point point) {
61         axes = getUnderlyingAxes(point);
62         if (axes != null) {
63             PointAComputer pointComputer = new PointAComputer(axes, point);
64             if (pointComputer.isValid()) {
65                 pointBComputer = pointComputer;
66                 secondPoint = pointComputer.getPosition();
67                 return true;
68             }
69         }
70         return false;
71     }
72 }