• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revision13e366af9f8e8d87459618b6709f0e571d6f03bf (tree)
Zeit2013-06-30 03:51:56
Autornormen667 <normen667@75d0...>
Commiternormen667

Log Message

SDK:
- commit disabled code to save scene from scratch

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10685 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Ändern Zusammenfassung

Diff

--- /dev/null
+++ b/sdk/jme3-core/src/com/jme3/gde/core/appstates/NewSceneSaveNode.java
@@ -0,0 +1,129 @@
1+/*
2+ * Copyright (c) 2009-2010 jMonkeyEngine
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are
7+ * met:
8+ *
9+ * * Redistributions of source code must retain the above copyright
10+ * notice, this list of conditions and the following disclaimer.
11+ *
12+ * * Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+ * may be used to endorse or promote products derived from this software
18+ * without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+package com.jme3.gde.core.appstates;
33+
34+import com.jme3.export.binary.BinaryExporter;
35+import com.jme3.gde.core.scene.SceneApplication;
36+import com.jme3.gde.core.scene.SceneRequest;
37+import com.jme3.scene.Spatial;
38+import java.io.File;
39+import java.io.IOException;
40+import java.util.concurrent.Callable;
41+import javax.swing.filechooser.FileFilter;
42+import org.netbeans.api.progress.ProgressHandle;
43+import org.netbeans.api.progress.ProgressHandleFactory;
44+import org.openide.DialogDisplayer;
45+import org.openide.NotifyDescriptor;
46+import org.openide.awt.StatusDisplayer;
47+import org.openide.cookies.SaveCookie;
48+import org.openide.filesystems.FileChooserBuilder;
49+import org.openide.filesystems.FileObject;
50+import org.openide.filesystems.FileUtil;
51+import org.openide.nodes.AbstractNode;
52+import org.openide.nodes.Children;
53+
54+/**
55+ * Node for a not yet existing scene, can be saved as j3o
56+ * @author normenhansen
57+ */
58+public class NewSceneSaveNode extends AbstractNode implements SaveCookie {
59+
60+ private final SceneRequest request;
61+
62+ public NewSceneSaveNode(SceneRequest nodeToSave) {
63+ super(Children.LEAF);
64+ request = nodeToSave;
65+ getCookieSet().assign(SaveCookie.class, this);
66+
67+ }
68+
69+ @Override
70+ public String toString() {
71+ return "NewSceneSaveNode(" + getDisplayName() + ")";
72+ }
73+
74+ public void save() throws IOException {
75+ FileChooserBuilder builder = new FileChooserBuilder(NewSceneSaveNode.class);
76+ builder.addFileFilter(new FileFilter() {
77+ @Override
78+ public boolean accept(File f) {
79+ if (f.getName().toLowerCase().trim().endsWith(".j3o")) {
80+ return true;
81+ }
82+ return false;
83+ }
84+
85+ @Override
86+ public String getDescription() {
87+ return "j3o Files";
88+ }
89+ });
90+
91+ final File file = builder.showSaveDialog();
92+ if (file == null) {
93+ return;
94+ }
95+ SceneApplication.getApplication().enqueue(new Callable<Void>() {
96+ public Void call() throws Exception {
97+ Spatial node = request.getRootNode();
98+ if (node == null) {
99+ return null;
100+ }
101+ if (file.exists()) {
102+ NotifyDescriptor.Confirmation mesg = new NotifyDescriptor.Confirmation("File exists, overwrite?",
103+ "Not Saved",
104+ NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
105+ DialogDisplayer.getDefault().notify(mesg);
106+ if (mesg.getValue() != NotifyDescriptor.Confirmation.YES_OPTION) {
107+ return null;
108+ }
109+ }
110+ ProgressHandle progressHandle = ProgressHandleFactory.createHandle("Saving File..");
111+ progressHandle.start();
112+ try {
113+ BinaryExporter exp = BinaryExporter.getInstance();
114+ exp.save(node, file);
115+ } catch (Exception e) {
116+ } finally {
117+ FileObject fo = FileUtil.toFileObject(file);
118+ if (fo != null) {
119+ StatusDisplayer.getDefault().setStatusText(fo + " saved.");
120+ fo.getParent().refresh();
121+ }
122+ }
123+ progressHandle.finish();
124+ return null;
125+ }
126+ });
127+
128+ }
129+}
--- a/sdk/jme3-core/src/com/jme3/gde/core/appstates/RunAppStateAction.java
+++ b/sdk/jme3-core/src/com/jme3/gde/core/appstates/RunAppStateAction.java
@@ -32,8 +32,11 @@
3232 package com.jme3.gde.core.appstates;
3333
3434 import com.jme3.app.state.AppState;
35+import com.jme3.gde.core.assets.ProjectAssetManager;
3536 import com.jme3.gde.core.scene.FakeApplication;
37+import com.jme3.gde.core.scene.PreviewRequest;
3638 import com.jme3.gde.core.scene.SceneApplication;
39+import com.jme3.gde.core.scene.SceneListener;
3740 import com.jme3.gde.core.scene.SceneRequest;
3841 import com.sun.source.tree.ClassTree;
3942 import com.sun.source.tree.CompilationUnitTree;
@@ -50,6 +53,8 @@ import org.netbeans.api.java.source.CancellableTask;
5053 import org.netbeans.api.java.source.CompilationController;
5154 import org.netbeans.api.java.source.JavaSource;
5255 import org.netbeans.api.java.source.SourceUtils;
56+import org.netbeans.api.project.FileOwnerQuery;
57+import org.netbeans.api.project.Project;
5358 import org.openide.DialogDisplayer;
5459 import org.openide.NotifyDescriptor;
5560 import org.openide.awt.ActionID;
@@ -69,7 +74,6 @@ id = "com.jme3.gde.core.appstates.RunAppStateAction")
6974 @ActionRegistration(
7075 displayName = "#CTL_RunAppState")
7176 @ActionReferences({
72- @ActionReference(path = "Toolbars/Build", position = 325),
7377 @ActionReference(path = "Loaders/text/x-java/Actions", position = 1050),
7478 @ActionReference(path = "Editors/text/x-java/Popup", position = 1740)
7579 })
@@ -77,22 +81,19 @@ displayName = "#CTL_RunAppState")
7781 public class RunAppStateAction implements ContextAwareAction {
7882
7983 private static final Logger logger = Logger.getLogger(RunAppStateAction.class.getName());
80- private String className;
81- private JavaSource source;
84+ private final ActionConfig config;
8285
8386 public RunAppStateAction() {
84- className = null;
85- source = null;
87+ config = null;
8688 }
8789
88- public RunAppStateAction(String className, JavaSource src) {
89- this.className = className;
90- this.source = src;
90+ private RunAppStateAction(ActionConfig config) {
91+ this.config = config;
9192 }
9293
9394 public Action createContextAwareInstance(Lookup actionContext) {
94- checkData(actionContext, "com.jme3.app.state.AppState");
95- return new RunAppStateAction(className, source);
95+ ActionConfig config = checkData(actionContext, "com.jme3.app.state.AppState");
96+ return new RunAppStateAction(config);
9697 }
9798
9899 public Object getValue(String key) {
@@ -109,7 +110,7 @@ public class RunAppStateAction implements ContextAwareAction {
109110 }
110111
111112 public boolean isEnabled() {
112- return className != null;
113+ return config != null ? config.className != null : false;
113114 }
114115
115116 public void addPropertyChangeListener(PropertyChangeListener listener) {
@@ -120,47 +121,72 @@ public class RunAppStateAction implements ContextAwareAction {
120121
121122 public void actionPerformed(ActionEvent e) {
122123 //TODO: better way to access scene request
124+ if (config == null) {
125+ logger.log(Level.SEVERE, "Performing unconfigured RunAppState action");
126+ return;
127+ }
123128 SceneRequest req = SceneApplication.getApplication().getCurrentSceneRequest();
124129 if (req != null) {
125130 FakeApplication app = req.getFakeApp();
126- try {
127- AppState state = (AppState) app.getClassByName(className).newInstance();
128- app.getStateManager().attach(state);
129- AppStateExplorerTopComponent.openExplorer();
130- } catch (InstantiationException ex) {
131- DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, make sure it has an empty constructor!\n" + ex.getMessage()));
132- Exceptions.printStackTrace(ex);
133- } catch (IllegalAccessException ex) {
134- DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, make sure it has an empty constructor!\n" + ex.getMessage()));
135- Exceptions.printStackTrace(ex);
136- } catch (Exception ex) {
137- DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, exception when creating!\n" + ex.getMessage()));
138- Exceptions.printStackTrace(ex);
139- }
131+ assert (app != null);
132+ attachState(app);
140133 } else {
141134 DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("No Scene opened to attach to,\nopen a j3o scene."));
142- logger.log(Level.INFO, "No Scene Request available");
135+ if(5==5)
136+ return;
137+ if (config.manager != null) {
138+ logger.log(Level.INFO, "Try request scene..");
139+ //TODO: rootNode is assigned in SceneApplication.. more elegant system (with scene lookup)
140+ final SceneRequest sceneRequest = new SceneRequest(this, config.manager);
141+ sceneRequest.setWindowTitle("New Scene");
142+ sceneRequest.setDataNode(new NewSceneSaveNode(sceneRequest));
143+ SceneApplication.getApplication().addSceneListener(new SceneListener() {
144+ public void sceneOpened(SceneRequest request) {
145+ if (request == sceneRequest) {
146+ FakeApplication app = request.getFakeApp();
147+ attachState(app);
148+ }
149+ }
150+
151+ public void sceneClosed(SceneRequest request) {
152+ if (request == sceneRequest) {
153+ SceneApplication.getApplication().removeSceneListener(this);
154+ }
155+ }
156+
157+ public void previewCreated(PreviewRequest request) {
158+ }
159+ });
160+ SceneApplication.getApplication().openScene(sceneRequest);
161+ } else {
162+ DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Not a jME project!"));
163+ }
143164 }
144165 }
145-
146- private void checkData(Lookup actionContext, final String name) {
147- source = null;
148- className = null;
166+
167+ private ActionConfig checkData(Lookup actionContext, final String name) {
168+ final ActionConfig ret = new ActionConfig();
149169 try {
150170 DataObject dObj = actionContext.lookup(DataObject.class);
151171 if (dObj == null) {
152172 logger.log(Level.FINE, "No DataObject");
153- return;
173+ return null;
174+ }
175+ Project proj = FileOwnerQuery.getOwner(dObj.getPrimaryFile());;
176+ if (proj != null) {
177+ ret.manager = proj.getLookup().lookup(ProjectAssetManager.class);
178+ } else {
179+ logger.log(Level.INFO, "Project null");
154180 }
155181 FileObject fObj = dObj.getPrimaryFile();
156182 if (fObj == null) {
157183 logger.log(Level.FINE, "No FileObject");
158- return;
184+ return null;
159185 }
160186 final JavaSource src = JavaSource.forFileObject(fObj);
161187 if (src == null) {
162188 logger.log(Level.FINE, "No JavaSource");
163- return;
189+ return null;
164190 }
165191 CancellableTask task = new CancellableTask<CompilationController>() {
166192 public void run(CompilationController controller) throws IOException {
@@ -185,8 +211,8 @@ public class RunAppStateAction implements ContextAwareAction {
185211 TypeMirror elementType = myElement.asType();
186212 logger.log(Level.FINE, "Check {0} against {1}", new Object[]{elementType, appState});
187213 if (elementType != null && SourceUtils.checkTypesAssignable(controller, elementType, appState)) {
188- source = src;
189- className = elementName;
214+ ret.source = src;
215+ ret.className = elementName;
190216 }
191217 }
192218 }
@@ -197,8 +223,35 @@ public class RunAppStateAction implements ContextAwareAction {
197223 }
198224 };
199225 src.runUserActionTask(task, true);
226+ return ret;
200227 } catch (IOException ex) {
201228 Exceptions.printStackTrace(ex);
202229 }
230+ return null;
231+ }
232+
233+ private void attachState(FakeApplication app) {
234+ try {
235+ assert (config.className != null);
236+ AppState state = (AppState) app.getClassByName(config.className).newInstance();
237+ app.getStateManager().attach(state);
238+ AppStateExplorerTopComponent.openExplorer();
239+ } catch (InstantiationException ex) {
240+ DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, is the project compiled?\nAlso make sure it has an empty constructor!\n" + ex.getMessage()));
241+ Exceptions.printStackTrace(ex);
242+ } catch (IllegalAccessException ex) {
243+ DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, is the project compiled?\nAlso make sure it has an empty constructor!\n" + ex.getMessage()));
244+ Exceptions.printStackTrace(ex);
245+ } catch (Exception ex) {
246+ DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, exception when creating!\n" + ex.getMessage()));
247+ Exceptions.printStackTrace(ex);
248+ }
249+ }
250+
251+ private static class ActionConfig {
252+
253+ public String className;
254+ public JavaSource source;
255+ public ProjectAssetManager manager;
203256 }
204257 }
\ No newline at end of file