~seh999/jcog/proto3

« back to all changes in this revision

Viewing changes to spacetime/src.ui/opencog/spacetime/ui/viewerapp/actions/edit/AddTool.java

  • Committer: SeH
  • Date: 2009-09-19 22:59:48 UTC
  • Revision ID: seh999@gmail.com-20090919225948-q3ab80xa57i74mm6
start of major jReality refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *
3
 
 * This file is part of jReality. jReality is open source software, made
4
 
 * available under a BSD license:
5
 
 *
6
 
 * Copyright (c) 2003-2006, jReality Group: Charles Gunn, Tim Hoffmann, Markus
7
 
 * Schmies, Steffen Weissmann.
8
 
 *
9
 
 * All rights reserved.
10
 
 *
11
 
 * Redistribution and use in source and binary forms, with or without
12
 
 * modification, are permitted provided that the following conditions are met:
13
 
 *
14
 
 * - Redistributions of source code must retain the above copyright notice, this
15
 
 *   list of conditions and the following disclaimer.
16
 
 *
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.
20
 
 *
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
24
 
 *   permission.
25
 
 *
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.
37
 
 *
38
 
 */
39
 
 
40
 
 
41
 
package opencog.spacetime.ui.viewerapp.actions.edit;
42
 
 
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;
50
 
 
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;
56
 
 
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;
79
 
 
80
 
 
81
 
 
82
 
/**
83
 
 * Adds tools to a selected SceneGraphComponent (if no SceneGraphComponent is selected, this action is disabled).
84
 
 * 
85
 
 * @author msommer
86
 
 */
87
 
public class AddTool extends AbstractSelectionListenerAction {
88
 
 
89
 
  private boolean initialized = false;
90
 
  private JList toolList = null;
91
 
  private JOptionPane pane = null;
92
 
  private JDialog dialog = null;
93
 
  
94
 
  
95
 
  public AddTool(String name, SelectionManager sm, Component frame) {
96
 
    
97
 
    super(name, sm, frame);
98
 
    setShortDescription("Add Tools");
99
 
  }
100
 
 
101
 
 
102
 
  public void actionPerformed(ActionEvent e) {
103
 
    
104
 
    if (!initialized) initializeToolList();
105
 
    
106
 
    //show dialog
107
 
    dialog.setLocationRelativeTo(parentComp);
108
 
    dialog.setVisible(true);
109
 
    
110
 
    //add selected tools
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++) {
115
 
        try {
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!");
121
 
        }
122
 
      }
123
 
    }
124
 
    toolList.clearSelection();
125
 
  }
126
 
  
127
 
  
128
 
  @Override
129
 
  public boolean isEnabled(SelectionEvent e) {
130
 
    return e.componentSelected();
131
 
  }
132
 
 
133
 
  
134
 
  private void initializeToolList() {
135
 
    
136
 
    List<String> tools = new LinkedList<String>();
137
 
    
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());
156
 
 
157
 
    try {  //different source folder
158
 
      tools.add(Class.forName("de.jreality.tools.PortalHeadMoveTool").getName());
159
 
    } catch (ClassNotFoundException exc) {}
160
 
    
161
 
    //sort tool list entries
162
 
    Object[] obj = tools.toArray();
163
 
    Arrays.sort(obj);
164
 
 
165
 
    toolList = new JList(obj);
166
 
    toolList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
167
 
    
168
 
    pane = new JOptionPane(new JScrollPane(toolList), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
169
 
    dialog = pane.createDialog(parentComp, "Add Tools");
170
 
    
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);
177
 
        }
178
 
      }
179
 
    });
180
 
 
181
 
    initialized = true;
182
 
  }
183
 
 
184
 
}
 
 
b'\\ No newline at end of file'