- use only FileObject instead of File

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7131 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 14 years ago
parent 98b912d748
commit 4d67ee0c3b
  1. 43
      sdk/jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontWizardIterator.java

@ -7,8 +7,8 @@ package com.jme3.gde.angelfont;
import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.assets.ProjectAssetManager;
import java.awt.Component; import java.awt.Component;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections; import java.util.Collections;
@ -23,7 +23,6 @@ import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project; import org.netbeans.api.project.Project;
import org.openide.WizardDescriptor; import org.openide.WizardDescriptor;
import org.openide.filesystems.FileObject; import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions; import org.openide.util.Exceptions;
public final class AngelFontWizardIterator implements WizardDescriptor.InstantiatingIterator { public final class AngelFontWizardIterator implements WizardDescriptor.InstantiatingIterator {
@ -70,6 +69,11 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
return panels; return panels;
} }
/**
* Creates the files based on the info in the WizardDescriptor
* @return
* @throws IOException
*/
public Set<FileObject> instantiate() throws IOException { public Set<FileObject> instantiate() throws IOException {
String name = (String) wizard.getProperty("font_name"); String name = (String) wizard.getProperty("font_name");
int fontSize = (Integer) wizard.getProperty("font_size"); int fontSize = (Integer) wizard.getProperty("font_size");
@ -90,36 +94,39 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
scratch.put(data); scratch.put(data);
scratch.rewind(); scratch.rewind();
name = name.replaceAll(" ", ""); name = name.replaceAll(" ", "");
File outputFile; FileObject imageFile;
FileObject object; FileObject descriptionFile;
try { try {
//create fonts folder if it doesnt exist
if (pm.getAssetFolder().getFileObject("Interface") == null) { if (pm.getAssetFolder().getFileObject("Interface") == null) {
pm.getAssetFolder().createFolder("Interface"); pm.getAssetFolder().createFolder("Interface");
} }
if (pm.getAssetFolder().getFileObject("Interface/Fonts") == null) { if (pm.getAssetFolder().getFileObject("Interface/Fonts") == null) {
pm.getAssetFolder().getFileObject("Interface").createFolder("Fonts"); pm.getAssetFolder().getFileObject("Interface").createFolder("Fonts");
} }
outputFile = FileUtil.toFile(pm.getAssetFolder().getFileObject("Interface/Fonts")); //create PNG file
if (!outputFile.getName().endsWith(".png")) { imageFile = pm.getAssetFolder().getFileObject("Interface/Fonts" + name, "png");
outputFile = new File(outputFile.getAbsoluteFile() + File.separator + name + ".png"); if (imageFile == null) {
} imageFile = pm.getAssetFolder().getFileObject("Interface/Fonts").createData(name, "png");
// write png file
ImageIO.write(fontImage, "PNG", outputFile);
object = pm.getAssetFolder().getFileObject("Interface/Fonts/" + name, "fnt");
if (object == null) {
object = pm.getAssetFolder().getFileObject("Interface/Fonts").createData(name, "fnt");
} }
OutputStreamWriter out = new OutputStreamWriter(object.getOutputStream()); OutputStream out = imageFile.getOutputStream();
out.write(font.getDescription()); ImageIO.write(fontImage, "PNG", out);
out.close(); out.close();
//create fnt file
descriptionFile = pm.getAssetFolder().getFileObject("Interface/Fonts/" + name, "fnt");
if (descriptionFile == null) {
descriptionFile = pm.getAssetFolder().getFileObject("Interface/Fonts").createData(name, "fnt");
}
OutputStreamWriter out2 = new OutputStreamWriter(descriptionFile.getOutputStream());
out2.write(font.getDescription());
out2.close();
} catch (Exception e) { } catch (Exception e) {
Exceptions.printStackTrace(e); Exceptions.printStackTrace(e);
return Collections.EMPTY_SET; return Collections.EMPTY_SET;
} }
Set<FileObject> set = new HashSet<FileObject>(); Set<FileObject> set = new HashSet<FileObject>();
set.add(FileUtil.toFileObject(outputFile)); set.add(imageFile);
set.add(object); set.add(descriptionFile);
return set; return set;
} }

Loading…
Cancel
Save