1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d.gui;
21
22 import camera3d.*;
23 import camera3d.event.*;
24 import javax.swing.*;
25 import java.util.*;
26
27 /***
28 * A version of ViewportFrame that automatically creates a ViewportCommandPane
29 * and a Viewport.
30 * @author Fábio Roberto de Miranda
31 */
32 public final class ViewportCombo extends ViewportFrame implements ViewportChangeListener {
33
34 private boolean debugflag = true;
35 private GUIControl guiControl;
36
37 public ViewportCombo(VcView view, GUIControl guiControl) {
38 super(new Viewport(view, guiControl.getJ3DBase()), new ViewportCommandPane());
39 this.commandPane.setViewport(this.viewportPane.getViewport());
40 if (this.viewportPane.getViewport()==null){
41 debugln("ViewportInternalCombo: NULL VIEWPORT PASSED TO COMMANDPANE.");
42 }
43 this.viewportPane.getViewport().addChangeListener(commandPane);
44 this.viewportPane.getViewport().addChangeListener(this);
45
46 // viewportChanged(this.viewportPane.getViewport());
47 if (view!= null){
48 setTitle(view.getLabel());
49 }
50 this.setGUIControl(guiControl);
51 this.setFrameIcon(new ImageIcon(VcFrame.class.getResource("icons/frameicon.gif")));
52 }
53
54 /***
55 * Sets GUIControl that will receive requests from this object.
56 */
57 public void setGUIControl(GUIControl guiControl){
58 this.guiControl = guiControl;
59 this.commandPane.setGUIControl(guiControl);
60 this.viewportPane.getViewport().setGUIControl(guiControl);
61 }
62
63
64 /***
65 * Tells ViewportCombo that a view has been removed from the scene graph.
66 * This method has been devised to be called by ViewportWindowManager. In
67 * response to the method call, ViewportCombo will check if its own view
68 * coincides with the removed view. In this case, it will switch to the
69 * default view. Following, ViewportCombo will update the list of views in
70 * its ViewportCommandPane.
71 *
72 * @param view the recently removed view.
73 */
74 public void removeView(VcView view){
75 VcView viewportView = viewportPane.getViewport().getView();
76 if(viewportView == view){
77 commandPane.setComboActionListener(false);
78 viewportView = guiControl.getJ3DBase().getDefaultView();
79 viewportPane.getViewport().setView(viewportView);
80 setTitle(viewportView.getLabel());
81 commandPane.setSelectedView(viewportView);
82 commandPane.setComboActionListener(true);
83 }
84 commandPane.removeView(view);
85 }
86
87
88 /***
89 * Adds a view to the list of view which can be selected for exhibition.
90 * @param view new view added to list.
91 */
92 public void addView(VcView view){
93 commandPane.addView(view);
94 }
95
96 /***
97 * Informs this object of changes occurred in the list of Views of the virtual
98 * World.
99 * @param views updated list of views.
100 */
101 public void updateListOfViews(Vector views){
102 /* Here the commandPane gets notified of available views, and the viewport
103 * compares its view against the list of valid views. If it can't find its view
104 * listed as a valid view, it must switch back to another view
105 */
106 debugln("List of views updated in internal window");
107 VcView viewportView = viewportPane.getViewport().getView();
108 VcView alternativeView = null;
109 boolean found = views.contains((Object)viewportView);
110 if (!found){
111 /*
112 * The view this viewport referred to was not found, so we're switching it back
113 * to the first valid view. It would be nice to switch it to the
114 * default view in the future
115 */
116 alternativeView = (VcView)views.get(0);
117 viewportPane.getViewport().setView(alternativeView);
118 }
119
120 /*
121 * Tells the new list of views to the commandPane, and also informs it the currently
122 * selected view
123 */
124 commandPane.setListOfViews(views);
125 /* Code below is now obsolete due to the creation of ViewportChangeListeners
126 if (found){
127 commandPane.setSelectedView(viewportView);
128 this.setTitle(viewportView.getLabel());
129 } else {
130 commandPane.setSelectedView(alternativeView);
131 this.setTitle(alternativeView.getLabel());
132 }
133 */
134 }
135
136 void debugln(String s){
137 if ((debugflag)&&(GUIControl.debugflag)){
138 System.out.println(s);
139 }
140 }
141
142 public void viewportChanged(ViewportEvent vpe){
143 // this view which is shown by this viewport has changed.
144 if(vpe instanceof ViewChangedEvent) {
145 VcView tempView = ((ViewChangedEvent)vpe).getView();
146 if (tempView!= null){
147 // sets the title for this frame.
148 setTitle(tempView.getLabel());
149 }
150 }
151 }
152
153 /***
154 * Shows a message in the canvas.
155 */
156 public void showMessage(String s){
157 this.viewportPane.getViewport().enableMessage(s);
158 }
159
160 /***
161 * Turns of exhibition of messages in the canvas.
162 */
163 public void disableMessage(){
164 this.viewportPane.getViewport().disableMessage();
165 }
166
167 /***
168 * Returns viewport which belongs to this object.
169 */
170 public Viewport getViewport(){
171 return this.viewportPane.getViewport();
172 }
173
174 /***
175 * Sets frame title String.
176 */
177 public void setTitle(String title){
178 if (innerFrame!=null){
179 this.innerFrame.setTitle(title);
180 }
181 if (outerFrame!= null){
182 this.outerFrame.setTitle(title);
183 }
184 }
185
186 }
This page was automatically generated by Maven