gvsig-3d / org.gvsig.animation3d / trunk / org.gvsig.animation3d / org.gvsig.animation3d.swing / org.gvsig.animation3d.swing.impl / src / main / java / org / gvsig / animation3d / swing / impl / DefaultAnimation3DPanelController.java @ 688
History | View | Annotate | Download (28.1 KB)
1 |
package org.gvsig.animation3d.swing.impl; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.util.ArrayList; |
7 |
import java.util.Collection; |
8 |
import java.util.List; |
9 |
import java.util.Locale; |
10 |
import java.util.Map; |
11 |
import java.util.Set; |
12 |
|
13 |
import javax.swing.JComponent; |
14 |
import javax.swing.JOptionPane; |
15 |
import javax.swing.JTable; |
16 |
import javax.swing.ListSelectionModel; |
17 |
import javax.swing.event.ListSelectionEvent; |
18 |
import javax.swing.event.ListSelectionListener; |
19 |
import javax.swing.table.DefaultTableModel; |
20 |
|
21 |
import org.apache.commons.lang3.StringUtils; |
22 |
import org.gvsig.animation3d.swing.api.Animation3D; |
23 |
import org.gvsig.animation3d.swing.api.Animation3DPanel; |
24 |
import org.gvsig.animation3d.swing.api.Animation3DSwingLocator; |
25 |
import org.gvsig.animation3d.swing.api.Animation3DSwingManager; |
26 |
import org.gvsig.animation3d.swing.api.Animator; |
27 |
import org.gvsig.animation3d.swing.api.Frame3D; |
28 |
import org.gvsig.animation3d.swing.api.Frame3DCreationException; |
29 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.i18n.I18nManager; |
32 |
import org.gvsig.tools.observer.Notification; |
33 |
import org.gvsig.tools.observer.Observable; |
34 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
35 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
36 |
import org.gvsig.view3d.swing.api.MapControl3D; |
37 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
38 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
39 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
/**
|
44 |
*
|
45 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
46 |
*
|
47 |
*/
|
48 |
public class DefaultAnimation3DPanelController extends DefaultAnimation3DPanelView implements |
49 |
Animation3DPanel { |
50 |
|
51 |
private static final Logger LOG = LoggerFactory |
52 |
.getLogger(DefaultAnimation3DPanelController.class); |
53 |
|
54 |
private static final long serialVersionUID = -142252066138365417L; |
55 |
|
56 |
private Map<String, ExtendedPropertiesSupport> views; |
57 |
|
58 |
/**
|
59 |
* Default constructor
|
60 |
*
|
61 |
* @param views
|
62 |
*/
|
63 |
public DefaultAnimation3DPanelController(Map<String, ExtendedPropertiesSupport> views) { |
64 |
super();
|
65 |
|
66 |
this.views = views;
|
67 |
|
68 |
View3DSwingLocator.getManager().addObserver(this);
|
69 |
|
70 |
initComponents(); |
71 |
} |
72 |
|
73 |
private void initComponents() { |
74 |
|
75 |
initViewsCombo(views.keySet()); |
76 |
initAnimationControlButtons(); |
77 |
initAnimationsTable(); |
78 |
initMapControl3DOptions(); |
79 |
initFrameControlButtons(); |
80 |
initCloseButton(); |
81 |
|
82 |
viewsCombo.setSelectedIndex(0);
|
83 |
translate(); |
84 |
} |
85 |
|
86 |
private void initCloseButton() { |
87 |
close.addActionListener(new ActionListener() { |
88 |
|
89 |
@Override
|
90 |
public void actionPerformed(ActionEvent e) { |
91 |
doClose(); |
92 |
|
93 |
} |
94 |
}); |
95 |
} |
96 |
|
97 |
protected void doClose() { |
98 |
this.dispose();
|
99 |
this.setVisible(false); |
100 |
} |
101 |
|
102 |
private void initMapControl3DOptions() { |
103 |
|
104 |
sphericalOption.addActionListener(new ActionListener() { |
105 |
|
106 |
@Override
|
107 |
public void actionPerformed(ActionEvent e) { |
108 |
doOptionSelected(); |
109 |
|
110 |
} |
111 |
}); |
112 |
|
113 |
flatOption.addActionListener(new ActionListener() { |
114 |
|
115 |
@Override
|
116 |
public void actionPerformed(ActionEvent e) { |
117 |
doOptionSelected(); |
118 |
|
119 |
} |
120 |
}); |
121 |
} |
122 |
|
123 |
protected void doOptionSelected() { |
124 |
|
125 |
if (!animations.getSelectionModel().isSelectionEmpty()) {
|
126 |
// Add frames 3D to table
|
127 |
int selectedRow = animations.getSelectedRow();
|
128 |
DefaultAnimation3DTableModel model = |
129 |
(DefaultAnimation3DTableModel) animations.getModel(); |
130 |
Animation3D animation = model.getAnimation(selectedRow); |
131 |
initFramesTable(animation); |
132 |
|
133 |
String viewName = (String) viewsCombo.getSelectedItem(); |
134 |
ExtendedPropertiesSupport propertiesSupport = views.get(viewName); |
135 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
136 |
if (sphericalOption.isSelected()) {
|
137 |
MapControl3D mapControl3D = manager.getMapControl3D(propertiesSupport, TYPE.SPHERE); |
138 |
if (mapControl3D == null) { |
139 |
addFrame.setEnabled(false);
|
140 |
playAnimation.setEnabled(false);
|
141 |
} else {
|
142 |
addFrame.setEnabled(true);
|
143 |
if (animation.getSphericalFrames().isEmpty()) {
|
144 |
playAnimation.setEnabled(false);
|
145 |
} else {
|
146 |
playAnimation.setEnabled(true);
|
147 |
} |
148 |
} |
149 |
} else if (flatOption.isSelected()) { |
150 |
MapControl3D mapControl3D = manager.getMapControl3D(propertiesSupport, TYPE.FLAT); |
151 |
if (mapControl3D == null) { |
152 |
addFrame.setEnabled(false);
|
153 |
playAnimation.setEnabled(false);
|
154 |
} else {
|
155 |
addFrame.setEnabled(true);
|
156 |
if (animation.getFlatFrames().isEmpty()) {
|
157 |
playAnimation.setEnabled(false);
|
158 |
} else {
|
159 |
playAnimation.setEnabled(true);
|
160 |
} |
161 |
} |
162 |
} |
163 |
} |
164 |
} |
165 |
|
166 |
private void initFrameControlButtons() { |
167 |
|
168 |
frames.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
169 |
|
170 |
@Override
|
171 |
public void valueChanged(ListSelectionEvent arg0) { |
172 |
doFrameSelected(); |
173 |
|
174 |
} |
175 |
}); |
176 |
|
177 |
addFrame.addActionListener(new ActionListener() { |
178 |
|
179 |
@Override
|
180 |
public void actionPerformed(ActionEvent e) { |
181 |
doAddFrameAction(); |
182 |
} |
183 |
}); |
184 |
|
185 |
removeFrame.addActionListener(new ActionListener() { |
186 |
|
187 |
@Override
|
188 |
public void actionPerformed(ActionEvent e) { |
189 |
doRemoveFrameAction(); |
190 |
|
191 |
} |
192 |
}); |
193 |
|
194 |
upFrame.addActionListener(new ActionListener() { |
195 |
|
196 |
@Override
|
197 |
public void actionPerformed(ActionEvent e) { |
198 |
doUpFrameAction(); |
199 |
|
200 |
} |
201 |
}); |
202 |
|
203 |
downFrame.addActionListener(new ActionListener() { |
204 |
|
205 |
@Override
|
206 |
public void actionPerformed(ActionEvent e) { |
207 |
doDownFrameAction(); |
208 |
|
209 |
} |
210 |
}); |
211 |
|
212 |
zoomToFrame.addActionListener(new ActionListener() { |
213 |
|
214 |
@Override
|
215 |
public void actionPerformed(ActionEvent e) { |
216 |
doZoomToFrameAction(); |
217 |
|
218 |
} |
219 |
}); |
220 |
} |
221 |
|
222 |
protected void doFrameSelected() { |
223 |
|
224 |
if (frames.getSelectionModel().isSelectionEmpty()) {
|
225 |
removeFrame.setEnabled(false);
|
226 |
upFrame.setEnabled(false);
|
227 |
downFrame.setEnabled(false);
|
228 |
zoomToFrame.setEnabled(false);
|
229 |
} else {
|
230 |
|
231 |
if (frames.getRowCount() > 1 && frames.getSelectedRows().length == 1) { |
232 |
downFrame.setEnabled(true);
|
233 |
upFrame.setEnabled(true);
|
234 |
} else {
|
235 |
downFrame.setEnabled(false);
|
236 |
upFrame.setEnabled(false);
|
237 |
} |
238 |
|
239 |
removeFrame.setEnabled(true);
|
240 |
|
241 |
if (!sphericalOption.isSelected() && !flatOption.isSelected()) {
|
242 |
addFrame.setEnabled(false);
|
243 |
zoomToFrame.setEnabled(false);
|
244 |
} else if (frames.getSelectedRows().length != 1) { |
245 |
zoomToFrame.setEnabled(false);
|
246 |
} else {
|
247 |
|
248 |
String viewName = (String) viewsCombo.getSelectedItem(); |
249 |
ExtendedPropertiesSupport propertiesSupport = views.get(viewName); |
250 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
251 |
|
252 |
if (sphericalOption.isSelected()) {
|
253 |
MapControl3D mapControl3D = |
254 |
manager.getMapControl3D(propertiesSupport, TYPE.SPHERE); |
255 |
if (mapControl3D == null) { |
256 |
zoomToFrame.setEnabled(false);
|
257 |
} else if (mapControl3D != null) { |
258 |
zoomToFrame.setEnabled(true);
|
259 |
} |
260 |
} else if (flatOption.isSelected()) { |
261 |
MapControl3D mapControl3D = |
262 |
manager.getMapControl3D(propertiesSupport, TYPE.FLAT); |
263 |
if (mapControl3D == null) { |
264 |
zoomToFrame.setEnabled(false);
|
265 |
} else if (mapControl3D != null) { |
266 |
zoomToFrame.setEnabled(true);
|
267 |
} |
268 |
} |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
protected void doAddFrameAction() { |
274 |
|
275 |
MapControl3D mapControl3D; |
276 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
277 |
|
278 |
String viewName = (String) this.viewsCombo.getSelectedItem(); |
279 |
if (sphericalOption.isSelected()) {
|
280 |
mapControl3D = swingManager.getMapControl3D(this.views.get(viewName), TYPE.SPHERE);
|
281 |
} else if (flatOption.isSelected()) { |
282 |
mapControl3D = swingManager.getMapControl3D(this.views.get(viewName), TYPE.FLAT);
|
283 |
} else {
|
284 |
throw new IllegalStateException( |
285 |
"Can not add frame if any mapcontrol type option is selected");
|
286 |
} |
287 |
|
288 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
289 |
String name =
|
290 |
i18nManager.getTranslation("frame_XxnumberxX",
|
291 |
new String[] { String.valueOf(frames.getRowCount()) }); |
292 |
Frame3D newFrame3d = null;
|
293 |
try {
|
294 |
Animation3DSwingManager manager = Animation3DSwingLocator.getManager(); |
295 |
newFrame3d = manager.createFrame3D(name, mapControl3D); |
296 |
} catch (Frame3DCreationException e) {
|
297 |
LOG.error("Error getting frame 3D", e);
|
298 |
ThreadSafeDialogsManager dialogsManager = |
299 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
300 |
dialogsManager.messageDialog( |
301 |
i18nManager.getTranslation("error_getting_frame_of_3D_view"),
|
302 |
i18nManager.getTranslation("_error"), JOptionPane.ERROR_MESSAGE); |
303 |
return;
|
304 |
} |
305 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) frames.getModel(); |
306 |
model.addFrame(newFrame3d); |
307 |
this.playAnimation.setEnabled(true); |
308 |
|
309 |
if (model.getRowCount() > 1 && !this.frames.getSelectionModel().isSelectionEmpty()) { |
310 |
upFrame.setEnabled(true);
|
311 |
downFrame.setEnabled(true);
|
312 |
} |
313 |
} |
314 |
|
315 |
protected void doRemoveFrameAction() { |
316 |
|
317 |
if (this.frames.getSelectionModel().isSelectionEmpty()) { |
318 |
return;
|
319 |
} |
320 |
|
321 |
List<Frame3D> frames = getSelectedFrames();
|
322 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) this.frames.getModel();
|
323 |
for (Frame3D frame : frames) {
|
324 |
model.removeFrame(frame); |
325 |
} |
326 |
|
327 |
if (model.getRowCount() == 0) { |
328 |
playAnimation.setEnabled(false);
|
329 |
removeFrame.setEnabled(false);
|
330 |
upFrame.setEnabled(false);
|
331 |
downFrame.setEnabled(false);
|
332 |
zoomToFrame.setEnabled(false);
|
333 |
} |
334 |
} |
335 |
|
336 |
private List<Frame3D> getSelectedFrames() { |
337 |
List<Frame3D> selectedFrames = new ArrayList<Frame3D>(); |
338 |
int[] selectedRows = this.frames.getSelectedRows(); |
339 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) this.frames.getModel();
|
340 |
for (int selectedRow : selectedRows) { |
341 |
selectedFrames.add(model.getFrame(selectedRow)); |
342 |
} |
343 |
return selectedFrames;
|
344 |
} |
345 |
|
346 |
protected void doUpFrameAction() { |
347 |
if (this.frames.getSelectionModel().isSelectionEmpty()) { |
348 |
return;
|
349 |
} |
350 |
|
351 |
int minSelectionIndex = this.frames.getSelectionModel().getMinSelectionIndex(); |
352 |
int maxSelectionIndex = this.frames.getSelectionModel().getMaxSelectionIndex(); |
353 |
|
354 |
List<Frame3D> selectedFrames = getSelectedFrames();
|
355 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) this.frames.getModel();
|
356 |
for (Frame3D frame3d : selectedFrames) {
|
357 |
model.upFrame(frame3d); |
358 |
} |
359 |
|
360 |
if (minSelectionIndex - 1 > -1 && maxSelectionIndex - 1 > -1) { |
361 |
this.frames.getSelectionModel().setSelectionInterval(minSelectionIndex - 1, |
362 |
maxSelectionIndex - 1);
|
363 |
} |
364 |
} |
365 |
|
366 |
protected void doDownFrameAction() { |
367 |
if (this.frames.getSelectionModel().isSelectionEmpty()) { |
368 |
return;
|
369 |
} |
370 |
|
371 |
int minSelectionIndex = this.frames.getSelectionModel().getMinSelectionIndex(); |
372 |
int maxSelectionIndex = this.frames.getSelectionModel().getMaxSelectionIndex(); |
373 |
|
374 |
List<Frame3D> selectedFrames = getSelectedFrames();
|
375 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) this.frames.getModel();
|
376 |
for (Frame3D frame3d : selectedFrames) {
|
377 |
model.downFrame(frame3d); |
378 |
} |
379 |
|
380 |
if (minSelectionIndex + 1 < this.frames.getRowCount() |
381 |
&& maxSelectionIndex + 1 < this.frames.getRowCount()) { |
382 |
this.frames.getSelectionModel().setSelectionInterval(minSelectionIndex + 1, |
383 |
maxSelectionIndex + 1);
|
384 |
} |
385 |
|
386 |
} |
387 |
|
388 |
protected void doZoomToFrameAction() { |
389 |
if (this.frames.getSelectionModel().isSelectionEmpty()) { |
390 |
return;
|
391 |
} |
392 |
|
393 |
int selectedRow = this.frames.getSelectedRow(); |
394 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) this.frames.getModel();
|
395 |
Frame3D frame = model.getFrame(selectedRow); |
396 |
|
397 |
MapControl3D mapControl3D; |
398 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
399 |
|
400 |
String viewName = (String) this.viewsCombo.getSelectedItem(); |
401 |
if (sphericalOption.isSelected()) {
|
402 |
mapControl3D = swingManager.getMapControl3D(this.views.get(viewName), TYPE.SPHERE);
|
403 |
} else if (flatOption.isSelected()) { |
404 |
mapControl3D = swingManager.getMapControl3D(this.views.get(viewName), TYPE.FLAT);
|
405 |
} else {
|
406 |
return;
|
407 |
} |
408 |
|
409 |
Animation3DSwingManager manager = Animation3DSwingLocator.getManager(); |
410 |
Animator goToAnimator = |
411 |
manager.createGoToAnimator(mapControl3D, frame, 4000, 16000); //TODO Make time configurable |
412 |
manager.addAnimator(mapControl3D, goToAnimator); |
413 |
} |
414 |
|
415 |
private void initAnimationsTable() { |
416 |
|
417 |
animations.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
418 |
animations.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
419 |
|
420 |
@Override
|
421 |
public void valueChanged(ListSelectionEvent e) { |
422 |
doAnimationSelectedAction(); |
423 |
|
424 |
} |
425 |
}); |
426 |
|
427 |
} |
428 |
|
429 |
protected void doAnimationSelectedAction() { |
430 |
|
431 |
String viewName = (String) viewsCombo.getSelectedItem(); |
432 |
ExtendedPropertiesSupport viewProperties = views.get(viewName); |
433 |
if (StringUtils.isBlank(viewName) || viewProperties == null) { |
434 |
addAnimation.setEnabled(false);
|
435 |
removeAnimation.setEnabled(false);
|
436 |
sphericalOption.setEnabled(false);
|
437 |
flatOption.setEnabled(false);
|
438 |
playAnimation.setEnabled(false);
|
439 |
frames.setModel(new DefaultTableModel()); |
440 |
addFrame.setEnabled(false);
|
441 |
removeFrame.setEnabled(false);
|
442 |
upFrame.setEnabled(false);
|
443 |
downFrame.setEnabled(false);
|
444 |
zoomToFrame.setEnabled(false);
|
445 |
return;
|
446 |
} |
447 |
|
448 |
// Enable remove button
|
449 |
if (!animations.getSelectionModel().isSelectionEmpty()) {
|
450 |
removeAnimation.setEnabled(true);
|
451 |
} |
452 |
|
453 |
sphericalOption.setEnabled(true);
|
454 |
flatOption.setEnabled(true);
|
455 |
|
456 |
if (animations.getSelectionModel().isSelectionEmpty()) {
|
457 |
return;
|
458 |
} |
459 |
|
460 |
int selectedRow = animations.getSelectedRow();
|
461 |
DefaultAnimation3DTableModel model = (DefaultAnimation3DTableModel) animations.getModel(); |
462 |
Animation3D animation = model.getAnimation(selectedRow); |
463 |
|
464 |
if (sphericalOption.isSelected()) {
|
465 |
MapControl3D mapControl3D = |
466 |
View3DSwingLocator.getManager().getMapControl3D(viewProperties, TYPE.SPHERE); |
467 |
if (mapControl3D != null) { |
468 |
addFrame.setEnabled(true);
|
469 |
if (animation.getSphericalFrames().isEmpty()) {
|
470 |
playAnimation.setEnabled(false);
|
471 |
} else {
|
472 |
playAnimation.setEnabled(true);
|
473 |
} |
474 |
} else {
|
475 |
addFrame.setEnabled(false);
|
476 |
playAnimation.setEnabled(false);
|
477 |
} |
478 |
|
479 |
} else if (flatOption.isSelected()) { |
480 |
MapControl3D mapControl3D = |
481 |
View3DSwingLocator.getManager().getMapControl3D(viewProperties, TYPE.FLAT); |
482 |
if (mapControl3D != null) { |
483 |
addFrame.setEnabled(true);
|
484 |
if (animation.getFlatFrames().isEmpty()) {
|
485 |
playAnimation.setEnabled(false);
|
486 |
} else {
|
487 |
playAnimation.setEnabled(true);
|
488 |
} |
489 |
} else {
|
490 |
addFrame.setEnabled(false);
|
491 |
playAnimation.setEnabled(false);
|
492 |
} |
493 |
} |
494 |
|
495 |
initFramesTable(animation); |
496 |
} |
497 |
|
498 |
private void initFramesTable(Animation3D animation) { |
499 |
|
500 |
List<Frame3D> frameList = null; |
501 |
if (sphericalOption.isSelected()) {
|
502 |
frameList = animation.getSphericalFrames(); |
503 |
} else if (flatOption.isSelected()) { |
504 |
frameList = animation.getFlatFrames(); |
505 |
} else {
|
506 |
return;
|
507 |
} |
508 |
|
509 |
this.frames.getSelectionModel().setSelectionMode(
|
510 |
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
511 |
DefaultFrame3DTableModel frameTableModel = new DefaultFrame3DTableModel(frameList);
|
512 |
this.frames.setModel(frameTableModel);
|
513 |
this.frames.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); |
514 |
this.frames.getColumnModel().getColumn(0).setMaxWidth(80); |
515 |
this.frames.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
516 |
|
517 |
@Override
|
518 |
public void valueChanged(ListSelectionEvent e) { |
519 |
removeFrame.setEnabled(true);
|
520 |
upFrame.setEnabled(true);
|
521 |
downFrame.setEnabled(true);
|
522 |
zoomToFrame.setEnabled(true);
|
523 |
} |
524 |
}); |
525 |
} |
526 |
|
527 |
private void initAnimationControlButtons() { |
528 |
addAnimation.addActionListener(new ActionListener() { |
529 |
|
530 |
@Override
|
531 |
public void actionPerformed(ActionEvent e) { |
532 |
doAddAnimation(); |
533 |
} |
534 |
}); |
535 |
removeAnimation.addActionListener(new ActionListener() { |
536 |
|
537 |
@Override
|
538 |
public void actionPerformed(ActionEvent e) { |
539 |
doRemoveAnimation(); |
540 |
} |
541 |
}); |
542 |
|
543 |
playAnimation.addActionListener(new ActionListener() { |
544 |
|
545 |
@Override
|
546 |
public void actionPerformed(ActionEvent e) { |
547 |
doPlay(); |
548 |
|
549 |
} |
550 |
}); |
551 |
} |
552 |
|
553 |
protected void doPlay() { |
554 |
|
555 |
MapControl3D mapControl3D = null;
|
556 |
String viewName = (String) this.viewsCombo.getSelectedItem(); |
557 |
ExtendedPropertiesSupport viewProperties = this.views.get(viewName);
|
558 |
if (sphericalOption.isSelected()) {
|
559 |
mapControl3D = |
560 |
View3DSwingLocator.getManager().getMapControl3D(viewProperties, TYPE.SPHERE); |
561 |
} else if (flatOption.isSelected()) { |
562 |
mapControl3D = |
563 |
View3DSwingLocator.getManager().getMapControl3D(viewProperties, TYPE.FLAT); |
564 |
} |
565 |
|
566 |
int selectedRow = this.animations.getSelectedRow(); |
567 |
DefaultAnimation3DTableModel model = |
568 |
(DefaultAnimation3DTableModel) this.animations.getModel();
|
569 |
Animation3D animation = model.getAnimation(selectedRow); |
570 |
List<Frame3D> frames = null; |
571 |
if (sphericalOption.isSelected()) {
|
572 |
frames = animation.getSphericalFrames(); |
573 |
} else {
|
574 |
frames = animation.getFlatFrames(); |
575 |
} |
576 |
|
577 |
Animation3DSwingManager manager = Animation3DSwingLocator.getManager(); |
578 |
Animator goToAnimator = |
579 |
manager.createGoToAnimator(mapControl3D, frames, 4000, 16000); //TODO Make time configurable |
580 |
manager.stopAnimations(mapControl3D); |
581 |
manager.addAnimator(mapControl3D, goToAnimator); |
582 |
} |
583 |
|
584 |
protected void doAddAnimation() { |
585 |
Animation3DSwingManager manager = Animation3DSwingLocator.getManager(); |
586 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
587 |
String name =
|
588 |
i18nManager.getTranslation("animation_XxnumberxX",
|
589 |
new String[] { String.valueOf(animations.getRowCount()) }); |
590 |
Animation3D newAnimation = |
591 |
manager.createAnimation3D(name, new ArrayList<Frame3D>(), new ArrayList<Frame3D>()); |
592 |
DefaultAnimation3DTableModel tableModel = |
593 |
(DefaultAnimation3DTableModel) animations.getModel(); |
594 |
tableModel.addAnimation(newAnimation); |
595 |
} |
596 |
|
597 |
protected void doRemoveAnimation() { |
598 |
if (animations.getSelectionModel().isSelectionEmpty()) {
|
599 |
return;
|
600 |
} |
601 |
int selectedRow = animations.getSelectedRow();
|
602 |
DefaultAnimation3DTableModel tableModel = |
603 |
(DefaultAnimation3DTableModel) animations.getModel(); |
604 |
tableModel.removeAnimation(selectedRow); |
605 |
|
606 |
frames.setModel(new DefaultTableModel(0, 0)); |
607 |
addFrame.setEnabled(false);
|
608 |
buttongroup1.clearSelection(); |
609 |
removeAnimation.setEnabled(false);
|
610 |
sphericalOption.setEnabled(false);
|
611 |
flatOption.setEnabled(false);
|
612 |
playAnimation.setEnabled(false);
|
613 |
} |
614 |
|
615 |
@SuppressWarnings("unchecked") |
616 |
private void initViewsCombo(Set<String> set) { |
617 |
for (String name : set) { |
618 |
viewsCombo.addItem(name); |
619 |
} |
620 |
|
621 |
viewsCombo.addActionListener(new ActionListener() { |
622 |
|
623 |
@Override
|
624 |
public void actionPerformed(ActionEvent e) { |
625 |
doViewSelectedAction(); |
626 |
} |
627 |
}); |
628 |
} |
629 |
|
630 |
protected void doViewSelectedAction() { |
631 |
String viewName = (String) viewsCombo.getSelectedItem(); |
632 |
if (StringUtils.isNotBlank(viewName)) {
|
633 |
ExtendedPropertiesSupport viewProperties = views.get(viewName); |
634 |
Animation3DSwingManager manager = Animation3DSwingLocator.getManager(); |
635 |
List<Animation3D> animations = manager.getAnimations(viewProperties);
|
636 |
DefaultAnimation3DTableModel animationTableModel = |
637 |
new DefaultAnimation3DTableModel(animations);
|
638 |
this.animations.setModel(animationTableModel);
|
639 |
this.addAnimation.setEnabled(true); |
640 |
removeAnimation.setEnabled(false);
|
641 |
sphericalOption.setEnabled(false);
|
642 |
flatOption.setEnabled(false);
|
643 |
playAnimation.setEnabled(false);
|
644 |
frames.setModel(new DefaultTableModel()); |
645 |
addFrame.setEnabled(false);
|
646 |
removeFrame.setEnabled(false);
|
647 |
upFrame.setEnabled(false);
|
648 |
downFrame.setEnabled(false);
|
649 |
zoomToFrame.setEnabled(false);
|
650 |
|
651 |
List<MapControl3D> mapControl3Ds =
|
652 |
View3DSwingLocator.getManager().getMapControl3D(viewProperties); |
653 |
for (MapControl3D mapControl3D : mapControl3Ds) {
|
654 |
mapControl3D.addObserver(this);
|
655 |
} |
656 |
|
657 |
return;
|
658 |
} else {
|
659 |
removeAnimation.setEnabled(false);
|
660 |
buttongroup1.clearSelection(); |
661 |
sphericalOption.setEnabled(false);
|
662 |
flatOption.setEnabled(false);
|
663 |
animations.setModel(new DefaultTableModel()); |
664 |
} |
665 |
} |
666 |
|
667 |
@Override
|
668 |
public void setLocale(Locale l) { |
669 |
if (!getLocale().equals(l)) {
|
670 |
translate(); |
671 |
} |
672 |
super.setLocale(l);
|
673 |
} |
674 |
|
675 |
private void translate() { |
676 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
677 |
viewText.setText(i18nManager.getTranslation(viewText.getText())); |
678 |
addAnimation.setText(i18nManager.getTranslation(addAnimation.getText())); |
679 |
removeAnimation.setText(i18nManager.getTranslation(removeAnimation.getText())); |
680 |
playAnimation.setText(i18nManager.getTranslation(playAnimation.getText())); |
681 |
sphericalOption.setText(i18nManager.getTranslation(sphericalOption.getText())); |
682 |
flatOption.setText(i18nManager.getTranslation(flatOption.getText())); |
683 |
addFrame.setText(i18nManager.getTranslation(addFrame.getText())); |
684 |
removeFrame.setText(i18nManager.getTranslation(removeFrame.getText())); |
685 |
upFrame.setText(i18nManager.getTranslation(upFrame.getText())); |
686 |
downFrame.setText(i18nManager.getTranslation(downFrame.getText())); |
687 |
zoomToFrame.setText(i18nManager.getTranslation(zoomToFrame.getText())); |
688 |
close.setText(i18nManager.getTranslation(close.getText())); |
689 |
} |
690 |
|
691 |
@Override
|
692 |
public JComponent asJComponent() { |
693 |
return this; |
694 |
} |
695 |
|
696 |
@Override
|
697 |
public Dimension getPreferredSize() { |
698 |
return new Dimension(510, 530); |
699 |
} |
700 |
|
701 |
@SuppressWarnings("unchecked") |
702 |
@Override
|
703 |
public void addExtendedPropertiesSupport(String name, ExtendedPropertiesSupport viewDocument) { |
704 |
this.views.put(name, viewDocument);
|
705 |
this.viewsCombo.addItem(name);
|
706 |
} |
707 |
|
708 |
@Override
|
709 |
public void removeExtendedPropertiesSupport(String name) { |
710 |
this.views.remove(name);
|
711 |
this.viewsCombo.removeItem(name);
|
712 |
} |
713 |
|
714 |
@SuppressWarnings("unchecked") |
715 |
@Override
|
716 |
public void changeExtendedPropertiesSupportName(String oldValue, String newValue) { |
717 |
ExtendedPropertiesSupport viewDocument = this.views.remove(oldValue);
|
718 |
this.views.put(newValue, viewDocument);
|
719 |
this.viewsCombo.removeItem(oldValue);
|
720 |
this.viewsCombo.addItem(newValue);
|
721 |
this.viewsCombo.setSelectedItem(newValue);
|
722 |
} |
723 |
|
724 |
@Override
|
725 |
public void update(Observable observable, Object object) { |
726 |
if (object instanceof Notification) { |
727 |
Notification notification = (Notification) object; |
728 |
if (observable instanceof View3DSwingManager || observable instanceof MapControl3D) { |
729 |
|
730 |
if (MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION.equals(notification
|
731 |
.getType())) { |
732 |
doAnimationSelectedAction(); |
733 |
doOptionSelected(); |
734 |
} else if (View3DSwingManager.AFTER_CREATE_MAPCONTROL3D.equals(notification |
735 |
.getType())) { |
736 |
|
737 |
MapControl3D mapControl3D = (MapControl3D) notification.getValue(); |
738 |
mapControl3D.addObserver(this);
|
739 |
|
740 |
if (sphericalOption.isSelected() || flatOption.isSelected()) {
|
741 |
doOptionSelected(); |
742 |
} |
743 |
} |
744 |
} |
745 |
} |
746 |
} |
747 |
|
748 |
@Override
|
749 |
public void dispose() { |
750 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
751 |
manager.deleteObserver(this);
|
752 |
|
753 |
Collection<ExtendedPropertiesSupport> properties = views.values();
|
754 |
for (ExtendedPropertiesSupport extendedProperties : properties) {
|
755 |
|
756 |
List<MapControl3D> mapControl3Ds = manager.getMapControl3D(extendedProperties);
|
757 |
for (MapControl3D mapControl3D : mapControl3Ds) {
|
758 |
mapControl3D.deleteObserver(this);
|
759 |
} |
760 |
} |
761 |
} |
762 |
|
763 |
@Override
|
764 |
public ExtendedPropertiesSupport getSelectedExtendedProperties() {
|
765 |
String name = (String) this.viewsCombo.getSelectedItem(); |
766 |
return this.views.get(name); |
767 |
} |
768 |
|
769 |
@Override
|
770 |
public Animation3D getSelectedAnimation3D() {
|
771 |
|
772 |
if(animations.getSelectionModel().isSelectionEmpty()){
|
773 |
return null; |
774 |
} |
775 |
|
776 |
int selectedRow = this.animations.getSelectedRow(); |
777 |
DefaultAnimation3DTableModel model = |
778 |
(DefaultAnimation3DTableModel) this.animations.getModel();
|
779 |
return model.getAnimation(selectedRow);
|
780 |
} |
781 |
|
782 |
@Override
|
783 |
public List<Frame3D> getSelectedFrames3D() { |
784 |
int[] selectedRows = frames.getSelectedRows(); |
785 |
DefaultFrame3DTableModel model = (DefaultFrame3DTableModel) frames.getModel(); |
786 |
List<Frame3D> selectedFrames = new ArrayList<Frame3D>(); |
787 |
for (int i : selectedRows) { |
788 |
selectedFrames.add(model.getFrame(i)); |
789 |
} |
790 |
return selectedFrames;
|
791 |
} |
792 |
|
793 |
@Override
|
794 |
public boolean isSphericalOptionSelected() { |
795 |
return sphericalOption.isSelected();
|
796 |
} |
797 |
|
798 |
@Override
|
799 |
public boolean isFlatOptionSelected() { |
800 |
return flatOption.isSelected();
|
801 |
} |
802 |
} |