OSDN Git Service

[changed] Forgot to update JOGL with the files changes.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 17 Nov 2010 05:55:19 +0000 (05:55 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 17 Nov 2010 05:55:19 +0000 (05:55 +0000)
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglMusic.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglSound.java

index e0b6022..2b7502b 100644 (file)
 package com.badlogic.gdx.backends.jogl;\r
 \r
 import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.InputStream;\r
 \r
 import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.files.FileHandle;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * A {@link FileHandle} implementation for the desktop.\r
@@ -28,40 +24,23 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * @author mzechner\r
  * \r
  */\r
-public class JoglFileHandle implements FileHandle {\r
-       /** the file **/\r
-       private final File file;\r
-       private final FileType type;\r
-\r
+public class JoglFileHandle extends FileHandle {\r
        JoglFileHandle (File file, FileType type) {\r
-               this.file = file;\r
-               this.type = type;\r
+               super(file, type);\r
        }\r
 \r
-       /**\r
-        * @return the underlying {@link File}.\r
-        */\r
-       public File getFile () {\r
-               return file;\r
+       public FileHandle child (String name) {\r
+               return new JoglFileHandle(new File(file, name), type);\r
        }\r
 \r
-       public InputStream readFile () {\r
-               if (type == FileType.Internal) {\r
-                       InputStream input = JoglFileHandle.class.getResourceAsStream("/" + file);\r
-                       if (input != null) return input;\r
-               }\r
-               try {\r
-                       return new FileInputStream(file);\r
-               } catch (FileNotFoundException ex) {\r
-                       throw new GdxRuntimeException("Error reading file: " + file, ex);\r
+       public FileHandle parent () {\r
+               File parent = file.getParentFile();\r
+               if (parent == null) {\r
+                       if (type == FileType.Absolute)\r
+                               parent = new File("/");\r
+                       else\r
+                               parent = new File(".");\r
                }\r
-       }\r
-\r
-       public String toString () {\r
-               return file.toString();\r
-       }\r
-\r
-       @Override public String getPath () {\r
-               return file.toString();\r
+               return new JoglFileHandle(parent, type);\r
        }\r
 }\r
index acd5dfa..d55e144 100644 (file)
 \r
 package com.badlogic.gdx.backends.jogl;\r
 \r
+import java.io.File;\r
+\r
 import com.badlogic.gdx.Files;\r
 import com.badlogic.gdx.files.FileHandle;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
-import java.io.*;\r
-\r
 /**\r
  * Implementation for a desktop application of {@link Files}. Internal resources are relative to the application root directory,\r
  * external files are relative to the user's home directory.\r
@@ -29,75 +29,35 @@ import java.io.*;
 final class JoglFiles implements Files {\r
        private final String externalPath = System.getProperty("user.home") + "/";\r
 \r
-       public FileHandle getFileHandle (String fileName, FileType type) {\r
-               if (type == FileType.External) fileName = this.externalPath + fileName;\r
-               File file = new File(fileName);\r
-\r
-               if (JoglFileHandle.class.getResource("/" + fileName) == null && file.exists() == false)\r
-                       throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
-               else\r
-                       return new JoglFileHandle(file, type);\r
-       }\r
-\r
-       public String[] listDirectory (String directory, FileType type) {\r
-               if (type == FileType.External) directory = this.externalPath + directory;\r
-               File file = new File(directory);\r
-\r
-               if (file.exists() == false) throw new GdxRuntimeException("Directory not found: " + directory + " (" + type + ")");\r
-\r
-               return file.list();\r
-       }\r
-\r
-       public boolean makeDirectory (String directory, FileType type) {\r
-               if (type == FileType.Internal) return false;\r
-\r
-               File file = null;\r
-               if (type == FileType.Absolute)\r
-                       file = new File(directory);\r
-               else\r
-                       file = new File(this.externalPath + directory);\r
-               return file.mkdirs();\r
-       }\r
-\r
-       public InputStream readFile (String fileName, FileType type) {\r
+       @Override public FileHandle getFileHandle (String fileName, FileType type) {\r
+               File file;\r
                if (type == FileType.External)\r
-                       fileName = this.externalPath + fileName;\r
+                       file = new File(this.externalPath + fileName);\r
                else if (type == FileType.Internal) {\r
-            final String path = fileName.startsWith("/") ? fileName : "/" + fileName;\r
-            InputStream input = JoglFileHandle.class.getResourceAsStream(path);\r
-                       if (input != null) return input;\r
-               }\r
-\r
-               try {\r
-                       return new FileInputStream(fileName);\r
-               } catch (FileNotFoundException ex) {\r
-                       throw new GdxRuntimeException("Error reading file: " + fileName);\r
+                       file = new File(fileName);\r
+                       if (FileHandle.class.getResourceAsStream("/" + fileName) == null && !file.exists())\r
+                               throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
                }\r
+               return new JoglFileHandle(new File(fileName), type);\r
        }\r
 \r
-       public OutputStream writeFile (String fileName, FileType type) {\r
-               if (type == FileType.Internal) return null;\r
+       @Override public FileHandle internal (String path) {\r
+               return getFileHandle(path, FileType.Internal);\r
+       }\r
 \r
-               File file = null;\r
-               if (type == FileType.Absolute)\r
-                       file = new File(fileName);\r
-               else\r
-                       file = new File(this.externalPath + fileName);\r
+       @Override public FileHandle external (String path) {\r
+               return getFileHandle(path, FileType.External);\r
+       }\r
 \r
-               try {\r
-                       return new FileOutputStream(file);\r
-               } catch (FileNotFoundException e) {\r
-                       throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
-               }\r
+       @Override public FileHandle absolute (String path) {\r
+               return getFileHandle(path, FileType.Absolute);\r
        }\r
 \r
-       @Override\r
-       public String getExternalStoragePath() {\r
+       @Override public String getExternalStoragePath () {\r
                return externalPath;\r
        }\r
 \r
-       @Override\r
-       public boolean isExternalStorageAvailable() {\r
+       @Override public boolean isExternalStorageAvailable () {\r
                return true;\r
        }\r
 }\r
index ef4b300..cb75109 100644 (file)
@@ -204,7 +204,7 @@ public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
 \r
        @Override\r
        public Pixmap newPixmap(FileHandle file) {\r
-               return newPixmap(file.readFile());\r
+               return newPixmap(file.read());\r
        }\r
 \r
        @Override\r
index 597d265..bca3c4d 100644 (file)
@@ -60,7 +60,7 @@ public class JoglMusic implements Music, Runnable {
        }\r
 \r
        private void openAudioInputStream () throws UnsupportedAudioFileException, IOException {\r
-               ain = AudioSystem.getAudioInputStream(new BufferedInputStream(handle.readFile()));\r
+               ain = AudioSystem.getAudioInputStream(new BufferedInputStream(handle.read()));\r
                AudioFormat baseFormat = ain.getFormat();\r
                AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,\r
                        baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);\r
index 6608aef..35a5e86 100644 (file)
@@ -50,7 +50,7 @@ public class JoglSound implements Sound {
 \r
        public JoglSound (JoglAudio audio, JoglFileHandle file) throws UnsupportedAudioFileException, IOException {\r
                this.audio = audio;\r
-               InputStream fin = new BufferedInputStream(file.readFile());\r
+               InputStream fin = new BufferedInputStream(file.read());\r
                AudioInputStream ain = AudioSystem.getAudioInputStream(fin);\r
                AudioFormat baseFormat = ain.getFormat();\r
                AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,\r