git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7799 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
3f6f694030
commit
2bcc98512e
@ -0,0 +1,94 @@ |
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package com.jme3.gde.assetpack.actions; |
||||
|
||||
import com.jme3.export.binary.BinaryExporter; |
||||
import com.jme3.gde.assetpack.AssetConfiguration; |
||||
import com.jme3.gde.assetpack.AssetPackLoader; |
||||
import com.jme3.gde.core.assets.ProjectAssetManager; |
||||
import com.jme3.scene.Spatial; |
||||
import java.awt.event.ActionEvent; |
||||
import java.beans.PropertyChangeListener; |
||||
import java.io.IOException; |
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
import javax.swing.Action; |
||||
import org.openide.nodes.Node; |
||||
import org.openide.util.Exceptions; |
||||
import org.w3c.dom.Element; |
||||
import com.jme3.gde.scenecomposer.SceneComposerTopComponent; |
||||
import java.io.OutputStream; |
||||
import org.openide.filesystems.FileObject; |
||||
|
||||
public final class AddToProjectAction implements Action { |
||||
|
||||
private final Node context; |
||||
|
||||
public AddToProjectAction(Node context) { |
||||
this.context = context; |
||||
} |
||||
|
||||
public void actionPerformed(ActionEvent ev) { |
||||
ProjectAssetManager pm = context.getLookup().lookup(ProjectAssetManager.class); |
||||
if (pm == null) { |
||||
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "AssetManager not found!"); |
||||
return; |
||||
} |
||||
Element assetElement = context.getLookup().lookup(Element.class); |
||||
String type = assetElement.getAttribute("type"); |
||||
try { |
||||
if ("model".equals(type) || "scene".equals(type)) { |
||||
AssetConfiguration conf = new AssetConfiguration(assetElement); |
||||
Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf); |
||||
if (model != null) { |
||||
FileObject modelFolder = pm.getAssetFolder().getFileObject("Models"); |
||||
if (modelFolder == null) { |
||||
modelFolder = pm.getAssetFolder().createFolder("Models"); |
||||
} |
||||
if (modelFolder.isFolder()) { |
||||
AssetPackLoader.addModelFiles(pm, conf); |
||||
SceneComposerTopComponent.findInstance().addModel(model); |
||||
OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o"); |
||||
BinaryExporter.getInstance().save(model, out); |
||||
out.close(); |
||||
modelFolder.refresh(); |
||||
} else { |
||||
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot copy, file 'Models' exists"); |
||||
} |
||||
} else { |
||||
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error loading model"); |
||||
} |
||||
} else { |
||||
AssetConfiguration conf = new AssetConfiguration(assetElement); |
||||
AssetPackLoader.addAllFiles(pm, conf); |
||||
} |
||||
} catch (IOException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
} |
||||
|
||||
public Object getValue(String key) { |
||||
if (key.equals(NAME)) { |
||||
return "Add to SceneComposer.."; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void putValue(String key, Object value) { |
||||
} |
||||
|
||||
public void setEnabled(boolean b) { |
||||
} |
||||
|
||||
public boolean isEnabled() { |
||||
return true; |
||||
} |
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) { |
||||
} |
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) { |
||||
} |
||||
} |
Loading…
Reference in new issue