summaryrefslogtreecommitdiff
path: root/sources/utils
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-15 23:08:33 +0000
committerPaul Buetow <paul@buetow.org>2008-05-15 23:08:33 +0000
commitd4c1ddcc90c1e2e8660598fc36b3772d2bff6816 (patch)
tree28a0afc255e42f92adbca0d102e785301bc43a58 /sources/utils
parent61599471a5978c1521b9c89c044ac2ce9a88c398 (diff)
1 Moved the stuff to trunk!
Diffstat (limited to 'sources/utils')
-rw-r--r--sources/utils/VSClassLoader.java20
-rw-r--r--sources/utils/VSFrame.java58
-rw-r--r--sources/utils/VSInfoArea.java26
-rw-r--r--sources/utils/VSRandom.java17
-rw-r--r--sources/utils/VSTools.java24
5 files changed, 145 insertions, 0 deletions
diff --git a/sources/utils/VSClassLoader.java b/sources/utils/VSClassLoader.java
new file mode 100644
index 0000000..7d9fdf3
--- /dev/null
+++ b/sources/utils/VSClassLoader.java
@@ -0,0 +1,20 @@
+package utils;
+
+import java.util.*;
+
+import prefs.*;
+
+public class VSClassLoader extends ClassLoader {
+ public Object newInstance(String classname) {
+ Object object = null;
+
+ try {
+ object = loadClass(classname, true).newInstance();
+
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+
+ return object;
+ }
+}
diff --git a/sources/utils/VSFrame.java b/sources/utils/VSFrame.java
new file mode 100644
index 0000000..2725729
--- /dev/null
+++ b/sources/utils/VSFrame.java
@@ -0,0 +1,58 @@
+package utils;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+
+public class VSFrame extends JFrame {
+ private final static int X_LOCATION_OFFSET = 40;
+ private final static int Y_LOCATION_OFFSET = 80;
+ private Component parent;
+ private boolean dispose;
+
+ public VSFrame(String title, Component parent) {
+ super(title);
+ initialize(parent);
+ }
+
+ public VSFrame(String title) {
+ super(title);
+ initialize(null);
+ }
+
+ private void initialize(Component parent) {
+ this.parent = parent;
+ this.dispose = false;
+
+ setLocation();
+ }
+
+ public void disposeWithParent() {
+ if (!dispose && parent != null && parent instanceof Window) {
+ Window window = (Window) parent;
+ window.addWindowListener(new WindowAdapter() {
+ public void windowClosed(WindowEvent we) {
+ VSFrame.this.dispose();
+ }
+ });
+ }
+ dispose = true;
+ }
+
+ private void setLocation() {
+ int x = 0, y = 0;
+
+ if (parent == null) {
+ final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ x = (int) (screenSize.width - getWidth()) / 2;
+ y = (int) (screenSize.height - getHeight()) / 2;
+
+ } else {
+ final Point location = parent.getLocation();
+ x = (int) location.getX() + X_LOCATION_OFFSET;
+ y = (int) location.getY() + Y_LOCATION_OFFSET;
+ }
+
+ setLocation(x, y);
+ }
+}
diff --git a/sources/utils/VSInfoArea.java b/sources/utils/VSInfoArea.java
new file mode 100644
index 0000000..9d3600e
--- /dev/null
+++ b/sources/utils/VSInfoArea.java
@@ -0,0 +1,26 @@
+package utils;
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+public class VSInfoArea extends JTextPane {
+ public VSInfoArea() {
+ initialize();
+ }
+
+ public VSInfoArea(String text) {
+ setText(text);
+ initialize();
+ }
+
+ private void initialize() {
+ setOpaque(false);
+ setBorder(null);
+ setFocusable(false);
+ setBorder(new CompoundBorder(
+ new LineBorder(Color.BLACK),
+ new EmptyBorder(15, 15, 15, 15)));
+ setBackground(Color.WHITE);
+ }
+}
diff --git a/sources/utils/VSRandom.java b/sources/utils/VSRandom.java
new file mode 100644
index 0000000..4f23e7e
--- /dev/null
+++ b/sources/utils/VSRandom.java
@@ -0,0 +1,17 @@
+package utils;
+
+import java.util.Random;
+
+public final class VSRandom extends Random {
+ public VSRandom(long seedAdd) {
+ super(seedAdd*System.currentTimeMillis()+seedAdd);
+ }
+
+ public int nextInt() {
+ return Math.abs(super.nextInt());
+ }
+
+ public long nextLong(long mod) {
+ return Math.abs((super.nextLong() + System.currentTimeMillis()) % mod);
+ }
+}
diff --git a/sources/utils/VSTools.java b/sources/utils/VSTools.java
new file mode 100644
index 0000000..11d93a7
--- /dev/null
+++ b/sources/utils/VSTools.java
@@ -0,0 +1,24 @@
+package utils;
+
+import java.util.*;
+
+public final class VSTools {
+ public static String getTimeString(long time) {
+ String ret = ""+time;
+
+ while (ret.length() < 6)
+ ret = "0" + ret;
+
+ return ret + "ms";
+ }
+ public static long getStringTime(String string) {
+ try {
+ /* Ignore the "ms" postfix */
+ Long longValue = Long.valueOf(string.substring(0, string.length()-2));
+ return longValue.longValue();
+ } catch (NumberFormatException e) {
+ }
+
+ return 0;
+ }
+}