Skip to content

Commit

Permalink
[fixed] LwjglFrame size.
Browse files Browse the repository at this point in the history
[fixed] Preferences to use .prefs folder.
[added] Array toString(separator).
  • Loading branch information
nathan.sweet committed Nov 11, 2011
1 parent 2a9a8fa commit 95e520f
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;

public class JoglPreferences implements Preferences {
private final String name;
Expand All @@ -36,7 +38,7 @@ public class JoglPreferences implements Preferences {
this.name = name;
InputStream in = null;
try {
in = new BufferedInputStream(Gdx.files.external(name).read());
in = new BufferedInputStream(Gdx.files.external(".prefs/" + name).read());
properties.loadFromXML(in);
} catch (Throwable t) {
} finally {
Expand Down Expand Up @@ -167,11 +169,14 @@ public void clear () {

@Override
public void flush () {
if (Gdx.files == null) return;
FileHandle file = Gdx.files.external(".prefs/" + name);
OutputStream out = null;
try {
out = new BufferedOutputStream(Gdx.files.external(JoglPreferences.this.name).write(false));
out = new BufferedOutputStream(file.write(false));
properties.storeToXML(out, null);
} catch (Throwable t) {
} catch (Exception ex) {
throw new GdxRuntimeException("Error writing preferences: " + file, ex);
} finally {
if (out != null) try {
out.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class LwjglFrame extends JFrame {
public LwjglFrame (ApplicationListener listener, String title, int width, int height, boolean useGL2) {
super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(width, height);
getContentPane().setPreferredSize(new Dimension(width, height));
pack();
setLocationRelativeTo(null);

lwjglCanvas = new LwjglCanvas(listener, useGL2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LwjglPreferences implements Preferences {
private final Properties properties = new Properties();

LwjglPreferences (String name) {
this(Gdx.files.external(name));
this(Gdx.files.external(".prefs/" + name));
}

public LwjglPreferences (FileHandle file) {
Expand Down Expand Up @@ -174,7 +174,7 @@ public void clear () {
@Override
public void flush () {
if (Gdx.files == null) return;
FileHandle file = Gdx.files.external(LwjglPreferences.this.name);
FileHandle file = Gdx.files.external(".prefs/" + name);
OutputStream out = null;
try {
out = new BufferedOutputStream(file.write(false));
Expand Down
2 changes: 1 addition & 1 deletion gdx/src/com/badlogic/gdx/graphics/TextureDict.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* stores {@link TextureRef}s by their path. If you need to load the same texture in different parts of your application it will
* only be loaded into memory once by the dictionary.
* </p>
*
* @deprecated
* @author Dave Clayton <[email protected]> */
public class TextureDict {

Expand Down
12 changes: 12 additions & 0 deletions gdx/src/com/badlogic/gdx/utils/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ public String toString () {
return buffer.toString();
}

public String toString (String separator) {
if (size == 0) return "";
Object[] items = this.items;
StringBuilder buffer = new StringBuilder(32);
buffer.append(items[0]);
for (int i = 1; i < size; i++) {
buffer.append(separator);
buffer.append(items[i]);
}
return buffer.toString();
}

static public class ArrayIterator<T> implements Iterator<T> {
private final Array<T> array;
int index;
Expand Down
12 changes: 12 additions & 0 deletions gdx/src/com/badlogic/gdx/utils/BooleanArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,16 @@ public String toString () {
buffer.append(']');
return buffer.toString();
}

public String toString (String separator) {
if (size == 0) return "";
boolean[] items = this.items;
StringBuilder buffer = new StringBuilder(32);
buffer.append(items[0]);
for (int i = 1; i < size; i++) {
buffer.append(separator);
buffer.append(items[i]);
}
return buffer.toString();
}
}
12 changes: 12 additions & 0 deletions gdx/src/com/badlogic/gdx/utils/FloatArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,16 @@ public String toString () {
buffer.append(']');
return buffer.toString();
}

public String toString (String separator) {
if (size == 0) return "";
float[] items = this.items;
StringBuilder buffer = new StringBuilder(32);
buffer.append(items[0]);
for (int i = 1; i < size; i++) {
buffer.append(separator);
buffer.append(items[i]);
}
return buffer.toString();
}
}
12 changes: 12 additions & 0 deletions gdx/src/com/badlogic/gdx/utils/IntArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,16 @@ public String toString () {
buffer.append(']');
return buffer.toString();
}

public String toString (String separator) {
if (size == 0) return "";
int[] items = this.items;
StringBuilder buffer = new StringBuilder(32);
buffer.append(items[0]);
for (int i = 1; i < size; i++) {
buffer.append(separator);
buffer.append(items[i]);
}
return buffer.toString();
}
}
12 changes: 12 additions & 0 deletions gdx/src/com/badlogic/gdx/utils/LongArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,16 @@ public String toString () {
buffer.append(']');
return buffer.toString();
}

public String toString (String separator) {
if (size == 0) return "";
long[] items = this.items;
StringBuilder buffer = new StringBuilder(32);
buffer.append(items[0]);
for (int i = 1; i < size; i++) {
buffer.append(separator);
buffer.append(items[i]);
}
return buffer.toString();
}
}
13 changes: 0 additions & 13 deletions tests/gdx-tests-android/default.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void keyPressed (KeyEvent e) {
});

final Preferences prefs = new LwjglPreferences(new FileHandle(new LwjglFiles().getExternalStoragePath()
+ "pennypop-tests"));
+ ".prefs/lwjgl-tests"));
list.setSelectedValue(prefs.getString("last", null), true);

button.addActionListener(new ActionListener() {
Expand Down

0 comments on commit 95e520f

Please sign in to comment.