~seh999/jcog/proto3

« back to all changes in this revision

Viewing changes to spacetime/src.ui/opencog/spacetime/swing/ui/viewerapp/actions/file/LoadScene.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.swing.ui.viewerapp.actions.file;
 
42
 
 
43
import java.awt.event.ActionEvent;
 
44
import java.awt.event.KeyEvent;
 
45
import java.io.File;
 
46
 
 
47
import javax.swing.JOptionPane;
 
48
 
 
49
import opencog.spacetime.io.JrScene;
 
50
import opencog.spacetime.io.in.ReaderJRS;
 
51
import opencog.spacetime.swing.ui.viewerapp.FileLoaderDialog;
 
52
import opencog.spacetime.swing.ui.viewerapp.ViewerApp;
 
53
import opencog.spacetime.swing.ui.viewerapp.actions.AbstractJrAction;
 
54
import opencog.spacetime.util.Input;
 
55
 
 
56
 
 
57
 
 
58
/**
 
59
 * Opens a saved scene in a new ViewerApp.
 
60
 * 
 
61
 * @author msommer
 
62
 */
 
63
@SuppressWarnings("serial")
 
64
public class LoadScene extends AbstractJrAction {
 
65
 
 
66
  private ViewerApp viewerApp;
 
67
  
 
68
 
 
69
  public LoadScene(String name, ViewerApp v) {
 
70
    super(name);
 
71
    this.parentComp = v.getFrame();
 
72
    this.viewerApp = v;
 
73
    
 
74
    setShortDescription("Open saved scene");
 
75
    setShortCut(KeyEvent.VK_O, 0, true);
 
76
  }
 
77
 
 
78
  
 
79
  @Override
 
80
  public void actionPerformed(ActionEvent e) {
 
81
    File f = FileLoaderDialog.loadFile(parentComp, "jrs", "jReality scene files");
 
82
    if (f == null) return;  //dialog cancelled
 
83
    
 
84
    JrScene scene = null;
 
85
    try {
 
86
      ReaderJRS r = new ReaderJRS();
 
87
      r.setInput(new Input(f));
 
88
      scene = r.getScene();
 
89
      if (scene == null) throw new NullPointerException("couldn't read scene");
 
90
      ViewerApp v = new ViewerApp(scene);
 
91
      v.setAttachNavigator(viewerApp.isAttachNavigator());
 
92
      v.setExternalNavigator(viewerApp.isExternalNavigator());
 
93
      v.setAttachBeanShell(viewerApp.isAttachBeanShell());
 
94
      v.setExternalBeanShell(viewerApp.isExternalBeanShell());
 
95
      viewerApp.dispose();
 
96
      v.update();
 
97
      v.display();
 
98
    } catch (Exception exc) {
 
99
      JOptionPane.showMessageDialog(parentComp, "Load failed: "+exc.getMessage());
 
100
    }
 
101
  }
 
102
 
 
103
}
 
 
b'\\ No newline at end of file'