2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009-2010 - DIGITEO - Pierre Lando
4 * Copyright (C) 2012 - Scilab Enterprises - Bruno JOFRET
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 package org.scilab.modules.renderer.JoGLView.interaction;
15 import org.scilab.modules.commons.utils.BlockingResult;
16 import org.scilab.modules.renderer.JoGLView.DrawerVisitor;
19 * @author Pierre Lando
21 public class InteractionManager implements RubberBoxListener {
24 private RubberBox rubberBox;
26 /** The drag, zoom, rotate interaction manager */
27 private final DragZoomRotateInteraction dragZoomRotateInteraction;
29 /** Parent drawer visitor */
30 private DrawerVisitor drawerVisitor;
33 * Default constructor.
34 * @param drawerVisitor parent drawer visitor.
36 public InteractionManager(DrawerVisitor drawerVisitor) {
37 this.drawerVisitor = drawerVisitor;
38 dragZoomRotateInteraction = new DragZoomRotateInteraction(drawerVisitor);
39 dragZoomRotateInteraction.setEnable(true);
44 * @exception Throwable the <code>Exception</code> raised by this method
46 public void finalize() throws Throwable {
47 if (rubberBox != null) {
48 rubberBox.removeListener(this);
54 * Called to start zooming.
56 public void startInteractiveZoom() {
57 final ZoomRubberBox rubberBox = new ZoomRubberBox(drawerVisitor);
58 dragZoomRotateInteraction.setEnable(false);
60 rubberBox.addListener(new RubberBoxListener() {
61 public void rubberBoxEnd() {
62 dragZoomRotateInteraction.setEnable(true);
63 drawerVisitor.removePostRendering(rubberBox);
66 drawerVisitor.addPostRendering(rubberBox);
67 rubberBox.setEnable(true);
70 public double[] startClickRubberBox(double initialRect[]) {
71 final BlockingResult<double []> result = new BlockingResult<double[]>();
72 final PointRubberBox rubberBox;
73 if (initialRect.length == 0) {
74 rubberBox = new TwoPointsRubberBox(drawerVisitor);
76 rubberBox = new OnePointRubberBox(drawerVisitor, initialRect);
79 dragZoomRotateInteraction.setEnable(false);
80 rubberBox.addListener(new RubberBoxListener() {
82 public void rubberBoxEnd() {
83 result.setResult(rubberBox.getResults());
84 dragZoomRotateInteraction.setEnable(true);
85 drawerVisitor.removePostRendering(rubberBox);
88 drawerVisitor.addPostRendering(rubberBox);
89 rubberBox.setEnable(true);
90 return result.getResult();
93 public double[] startDragRubberBox() {
94 final BlockingResult<double []> result = new BlockingResult<double []>();
95 final DragPointRubberBox rubberBox = new DragPointRubberBox(drawerVisitor);
97 dragZoomRotateInteraction.setEnable(false);
98 rubberBox.addListener(new RubberBoxListener() {
100 public void rubberBoxEnd() {
101 result.setResult(rubberBox.getResults());
102 dragZoomRotateInteraction.setEnable(true);
103 drawerVisitor.removePostRendering(rubberBox);
106 drawerVisitor.addPostRendering(rubberBox);
107 rubberBox.setEnable(true);
108 return result.getResult();
112 public void rubberBoxEnd() {
113 dragZoomRotateInteraction.setEnable(true);