]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/actions/ConstrainedTransformAction.java
latest release (0.41), third attempt
[simantics/3d.git] / org.simantics.proconf.g3d / src / org / simantics / proconf / g3d / actions / ConstrainedTransformAction.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.actions;\r
12 \r
13 import java.util.List;\r
14 \r
15 import org.eclipse.jface.action.Action;\r
16 import org.eclipse.jface.action.IToolBarManager;\r
17 import org.eclipse.jface.resource.ImageDescriptor;\r
18 import org.simantics.proconf.g3d.Activator;\r
19 import org.simantics.proconf.g3d.base.ConstraintDetector;\r
20 import org.simantics.proconf.g3d.base.JmeRenderingComponent;\r
21 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
22 import org.simantics.proconf.g3d.common.OrbitalCamera;\r
23 \r
24 \r
25 public abstract class ConstrainedTransformAction extends WriteInteractiveAction {\r
26         private static final ImageDescriptor LOCK_ICON = Activator.imageDescriptorFromPlugin("org.simantic.proconf.g3d", "icons/silk/lock.png");\r
27         private static final ImageDescriptor LOCK_OPEN_ICON = Activator.imageDescriptorFromPlugin("org.simantic.proconf.g3d", "icons/silk/lock_open.png");\r
28         \r
29         protected JmeRenderingComponent component;\r
30         protected OrbitalCamera camera;\r
31         \r
32     protected boolean useConstraints = false;\r
33     protected ConstraintDetector detector;\r
34     \r
35     protected Action useConstraintsAction;\r
36     \r
37     //protected IToolBarManager manager;\r
38     \r
39         public ConstrainedTransformAction(ThreeDimensionalEditorBase editor) {\r
40                 super(editor, true);\r
41                 component = parent.getRenderingComponent();\r
42                 camera = parent.getCamera();\r
43                 detector = new ConstraintDetector(parent);\r
44                 useConstraintsAction = new Action("Constraints", Action.AS_CHECK_BOX) {\r
45                         public void run() {\r
46                                 useConstraints = this.isChecked();\r
47                         }\r
48 \r
49                         public void setChecked(boolean b) {\r
50                                 super.setChecked(b);\r
51                                 if (b) {\r
52                                         setImageDescriptor(LOCK_ICON);\r
53                                 } else {\r
54                                         setImageDescriptor(LOCK_OPEN_ICON);\r
55                                 }\r
56                         }\r
57                 };\r
58                 useConstraintsAction.setImageDescriptor(LOCK_OPEN_ICON);\r
59 \r
60         }\r
61         \r
62         @Override\r
63         public void deactivate() {\r
64                 detector.clearConstraintHighlights();\r
65         }\r
66         \r
67         @Override\r
68         public void fillToolBar(IToolBarManager manager) {\r
69                  //this.manager = manager;\r
70                  useConstraintsAction.setChecked(useConstraints);\r
71                  manager.add(useConstraintsAction);\r
72         }\r
73 \r
74 }\r