Plug rubberbox function :
[scilab.git] / scilab / modules / renderer / src / java / org / scilab / modules / renderer / JoGLView / interaction / DragPointRubberBox.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-en.txt
10  */
11
12 package org.scilab.modules.renderer.JoGLView.interaction;
13
14 import java.awt.event.MouseEvent;
15
16 import org.scilab.modules.renderer.JoGLView.DrawerVisitor;
17
18 /**
19  * @author Bruno JOFRET
20  */
21 public class DragPointRubberBox extends TwoPointsRubberBox {
22
23     /**
24      * Default constructor.
25      *
26      * @param drawerVisitor parent drawer visitor.
27      */
28     public DragPointRubberBox(DrawerVisitor drawerVisitor) {
29         super(drawerVisitor);
30     }
31     
32     @Override
33     public final void mouseClicked(MouseEvent e) {
34
35     }
36     @Override
37     public void mousePressed(MouseEvent e) {
38         mouseButton = e.getButton();
39         switch (status) {
40         case WAIT_POINT_A:
41             if (setPointA(e.getPoint())) {
42                 status = Status.WAIT_POINT_B;
43             } else {
44                 setEnable(false);
45                 fireRubberBoxEnd();
46             }
47             break;
48         case WAIT_POINT_B:
49             setPointB(e.getPoint());
50             if (pointBComputer.is2D()) {
51                 process();
52                 setEnable(false);
53                 fireRubberBoxEnd();
54             } else {
55                 status = Status.WAIT_POINT_C;
56             }
57             break;
58         case WAIT_POINT_C:
59             setPointC(e.getPoint());
60             status = Status.WAIT_POINT_D;
61             break;
62         case WAIT_POINT_D:
63             setPointD(e.getPoint());
64             process();
65             setEnable(false);
66             fireRubberBoxEnd();
67             break;
68         default:
69         }
70         updateInfoMessage();      
71     }
72
73     @Override
74     public void mouseReleased(MouseEvent e) {
75         mouseButton = e.getButton();
76         switch (status) {
77         case WAIT_POINT_A:
78             if (setPointA(e.getPoint())) {
79                 status = Status.WAIT_POINT_B;
80             } else {
81                 setEnable(false);
82                 fireRubberBoxEnd();
83             }
84             break;
85         case WAIT_POINT_B:
86             setPointB(e.getPoint());
87             if (pointBComputer.is2D()) {
88                 process();
89                 setEnable(false);
90                 fireRubberBoxEnd();
91             } else {
92                 status = Status.WAIT_POINT_C;
93             }
94             break;
95         case WAIT_POINT_C:
96             setPointC(e.getPoint());
97             status = Status.WAIT_POINT_D;
98             break;
99         case WAIT_POINT_D:
100             setPointD(e.getPoint());
101             process();
102             setEnable(false);
103             fireRubberBoxEnd();
104             break;
105         default:
106         }
107         updateInfoMessage();
108     }
109     
110     @Override
111     public final void mouseDragged(MouseEvent e) {
112         switch (status) {
113         case WAIT_POINT_A:
114             setPointA(e.getPoint());
115             getDrawerVisitor().getCanvas().redraw();
116             break;
117         case WAIT_POINT_B:
118             setPointB(e.getPoint());
119             getDrawerVisitor().getCanvas().redraw();
120             break;
121         case WAIT_POINT_C:
122             setPointC(e.getPoint());
123             getDrawerVisitor().getCanvas().redraw();
124             break;
125         case WAIT_POINT_D:
126             setPointD(e.getPoint());
127             getDrawerVisitor().getCanvas().redraw();
128             break;
129         default:
130         }
131         updateInfoMessage();
132     }
133
134     
135 }