3
* This file is part of jReality. jReality is open source software, made
4
* available under a BSD license:
6
* Copyright (c) 2003-2006, jReality Group: Charles Gunn, Tim Hoffmann, Markus
7
* Schmies, Steffen Weissmann.
11
* Redistribution and use in source and binary forms, with or without
12
* modification, are permitted provided that the following conditions are met:
14
* - Redistributions of source code must retain the above copyright notice, this
15
* list of conditions and the following disclaimer.
17
* - Redistributions in binary form must reproduce the above copyright notice,
18
* this list of conditions and the following disclaimer in the documentation
19
* and/or other materials provided with the distribution.
21
* - Neither the name of jReality nor the names of its contributors nor the
22
* names of their associated organizations may be used to endorse or promote
23
* products derived from this software without specific prior written
26
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
* POSSIBILITY OF SUCH DAMAGE.
41
package opencog.spacetime.ui.viewerapp.actions.edit;
43
import java.awt.Component;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.MouseAdapter;
46
import java.awt.event.MouseEvent;
47
import java.util.Arrays;
48
import java.util.LinkedList;
49
import java.util.List;
51
import javax.swing.JDialog;
52
import javax.swing.JList;
53
import javax.swing.JOptionPane;
54
import javax.swing.JScrollPane;
55
import javax.swing.ListSelectionModel;
57
import opencog.spacetime.scene.tool.Tool;
58
import opencog.spacetime.tools.AirplaneTool;
59
import opencog.spacetime.tools.ClickWheelCameraZoomTool;
60
import opencog.spacetime.tools.DampedDraggingTool;
61
import opencog.spacetime.tools.DraggingTool;
62
import opencog.spacetime.tools.EncompassTool;
63
import opencog.spacetime.tools.FlyToPickTool;
64
import opencog.spacetime.tools.FlyTool;
65
import opencog.spacetime.tools.HeadTransformationTool;
66
import opencog.spacetime.tools.LookAtTool;
67
import opencog.spacetime.tools.PickShowTool;
68
import opencog.spacetime.tools.PointerDisplayTool;
69
import opencog.spacetime.tools.RotateTool;
70
import opencog.spacetime.tools.ScaleTool;
71
import opencog.spacetime.tools.ShipNavigationTool;
72
import opencog.spacetime.tools.ShipRotateTool;
73
import opencog.spacetime.tools.ShipScaleTool;
74
import opencog.spacetime.tools.ShowPropertiesTool;
75
import opencog.spacetime.tools.TranslateTool;
76
import opencog.spacetime.ui.viewerapp.SelectionEvent;
77
import opencog.spacetime.ui.viewerapp.SelectionManager;
78
import opencog.spacetime.ui.viewerapp.actions.AbstractSelectionListenerAction;
83
* Adds tools to a selected SceneGraphComponent (if no SceneGraphComponent is selected, this action is disabled).
87
public class AddTool extends AbstractSelectionListenerAction {
89
private boolean initialized = false;
90
private JList toolList = null;
91
private JOptionPane pane = null;
92
private JDialog dialog = null;
95
public AddTool(String name, SelectionManager sm, Component frame) {
97
super(name, sm, frame);
98
setShortDescription("Add Tools");
102
public void actionPerformed(ActionEvent e) {
104
if (!initialized) initializeToolList();
107
dialog.setLocationRelativeTo(parentComp);
108
dialog.setVisible(true);
111
if (pane.getValue() instanceof Integer &&
112
(Integer) pane.getValue() == JOptionPane.OK_OPTION) {
113
Object[] selectedTools = toolList.getSelectedValues();
114
for (int i=0; i<selectedTools.length; i++) {
116
final Tool t = (Tool) Class.forName((String)selectedTools[i]).newInstance();
117
getSelection().getLastComponent().addTool(t);
118
} catch (Exception exc) {
119
exc.printStackTrace();
120
//System.out.println("Could not add tool!");
124
toolList.clearSelection();
129
public boolean isEnabled(SelectionEvent e) {
130
return e.componentSelected();
134
private void initializeToolList() {
136
List<String> tools = new LinkedList<String>();
138
tools.add(AirplaneTool.class.getName());
139
tools.add(ClickWheelCameraZoomTool.class.getName());
140
tools.add(DampedDraggingTool.class.getName());
141
tools.add(DraggingTool.class.getName());
142
tools.add(EncompassTool.class.getName());
143
tools.add(FlyTool.class.getName());
144
tools.add(FlyToPickTool.class.getName());
145
tools.add(HeadTransformationTool.class.getName());
146
tools.add(LookAtTool.class.getName());
147
tools.add(PickShowTool.class.getName());
148
tools.add(PointerDisplayTool.class.getName());
149
tools.add(RotateTool.class.getName());
150
tools.add(ScaleTool.class.getName());
151
tools.add(ShipNavigationTool.class.getName());
152
tools.add(ShipRotateTool.class.getName());
153
tools.add(ShipScaleTool.class.getName());
154
tools.add(ShowPropertiesTool.class.getName());
155
tools.add(TranslateTool.class.getName());
157
try { //different source folder
158
tools.add(Class.forName("de.jreality.tools.PortalHeadMoveTool").getName());
159
} catch (ClassNotFoundException exc) {}
161
//sort tool list entries
162
Object[] obj = tools.toArray();
165
toolList = new JList(obj);
166
toolList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
168
pane = new JOptionPane(new JScrollPane(toolList), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
169
dialog = pane.createDialog(parentComp, "Add Tools");
171
//enable choice by double-click without pressing OK
172
toolList.addMouseListener(new MouseAdapter() {
173
public void mouseClicked(MouseEvent evt) {
174
if (evt.getClickCount() == 2) {
175
dialog.setVisible(false);
176
pane.setValue(JOptionPane.OK_OPTION);
b'\\ No newline at end of file'