summaryrefslogtreecommitdiff
path: root/VS-Sim-Sources/sources/utils
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-08-15 04:09:42 +0000
committerPaul Buetow <paul@buetow.org>2008-08-15 04:09:42 +0000
commitafed274c10a93957f82a009824cafe8d83aa68a8 (patch)
tree4a4d3980a3d9eb32bf7be443a83afe4c21dcdf55 /VS-Sim-Sources/sources/utils
new branches
Diffstat (limited to 'VS-Sim-Sources/sources/utils')
-rw-r--r--VS-Sim-Sources/sources/utils/VS3Tupel.java84
-rw-r--r--VS-Sim-Sources/sources/utils/VSAboutFrame.java106
-rw-r--r--VS-Sim-Sources/sources/utils/VSClassLoader.java55
-rw-r--r--VS-Sim-Sources/sources/utils/VSFrame.java135
-rw-r--r--VS-Sim-Sources/sources/utils/VSInfoArea.java69
-rw-r--r--VS-Sim-Sources/sources/utils/VSPriorityQueue.java55
-rw-r--r--VS-Sim-Sources/sources/utils/VSRandom.java63
-rw-r--r--VS-Sim-Sources/sources/utils/VSTools.java119
8 files changed, 686 insertions, 0 deletions
diff --git a/VS-Sim-Sources/sources/utils/VS3Tupel.java b/VS-Sim-Sources/sources/utils/VS3Tupel.java
new file mode 100644
index 0000000..4d4c896
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VS3Tupel.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+/**
+ * The class VS3Tupel, an object of this class represents a 3-Tupel of objects.
+ * Each object can have its own type.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VS3Tupel<A,B,C> {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The a. */
+ private A a;
+
+ /** The b. */
+ private B b;
+
+ /** The c. */
+ private C c;
+
+ /**
+ * Instantiates a new tupel.
+ *
+ * @param a the a
+ * @param b the b
+ * @param c the c
+ */
+ public VS3Tupel(A a, B b, C c) {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+
+ /**
+ * Gets the a.
+ *
+ * @return the a
+ */
+ public A getA() {
+ return a;
+ }
+
+ /**
+ * Gets the b.
+ *
+ * @return the b
+ */
+ public B getB() {
+ return b;
+ }
+
+ /**
+ * Gets the c.
+ *
+ * @return the c
+ */
+ public C getC() {
+ return c;
+ }
+}
diff --git a/VS-Sim-Sources/sources/utils/VSAboutFrame.java b/VS-Sim-Sources/sources/utils/VSAboutFrame.java
new file mode 100644
index 0000000..2902de1
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSAboutFrame.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+import prefs.*;
+//import utils.*;
+
+/**
+ * The class VSAboutFrame. This class is only for the about window which
+ * shows up if selected in the GUI.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSAboutFrame extends VSFrame {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The prefs. */
+ private VSPrefs prefs;
+
+ /**
+ * Instantiates a new VSAboutFrame object.
+ *
+ * @param prefs the prefs
+ * @param relativeTo the component to open the about window relative to
+ */
+ public VSAboutFrame(VSPrefs prefs, Component relativeTo) {
+ super(prefs.getString("lang.name") + " - "
+ + prefs.getString("lang.about"), relativeTo);
+ this.prefs = prefs;
+
+ disposeWithParent();
+ setContentPane(createContentPane());
+ setSize(350, 250);
+ setResizable(false);
+ setVisible(true);
+ }
+
+ /**
+ * Creates the content pane.
+ *
+ * @return the container
+ */
+ public Container createContentPane() {
+ Container contentPane = getContentPane();
+
+ VSInfoArea infoArea = new VSInfoArea(
+ prefs.getString("lang.about.info"));
+ JPanel buttonPane = createButtonPanel();
+ JScrollPane scrollPane = new JScrollPane(infoArea);
+
+ contentPane.add(scrollPane, BorderLayout.CENTER);
+ contentPane.add(buttonPane, BorderLayout.SOUTH);
+
+ return contentPane;
+ }
+
+ /**
+ * Creates the button panel.
+ *
+ * @return the panel
+ */
+ public JPanel createButtonPanel() {
+ JPanel buttonPane = new JPanel();
+ buttonPane.setBackground(Color.WHITE);
+
+ JButton closeButton = new JButton(
+ prefs.getString("lang.close"));
+ closeButton.setMnemonic(prefs.getInteger("keyevent.close"));
+ closeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String actionCommand = e.getActionCommand();
+ if (actionCommand.equals(prefs.getString("lang.close")))
+ dispose();
+ }
+ });
+ buttonPane.add(closeButton);
+
+ return buttonPane;
+ }
+}
diff --git a/VS-Sim-Sources/sources/utils/VSClassLoader.java b/VS-Sim-Sources/sources/utils/VSClassLoader.java
new file mode 100644
index 0000000..49fcc6b
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSClassLoader.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+/**
+ * The class VSClassLoader. This class is used in order to create new objects
+ * by its classnames.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSClassLoader extends ClassLoader {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new instance of the given classname.
+ *
+ * @param classname the classname
+ *
+ * @return the object
+ */
+ public Object newInstance(String classname) {
+ Object object = null;
+
+ try {
+ object = super.loadClass(classname, true).newInstance();
+
+ } catch (Exception e) {
+ System.out.println(e + "; Classname " + classname);
+ }
+
+ return object;
+ }
+}
diff --git a/VS-Sim-Sources/sources/utils/VSFrame.java b/VS-Sim-Sources/sources/utils/VSFrame.java
new file mode 100644
index 0000000..fbc2139
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSFrame.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+
+/**
+ * The class VSFrame. All frames of the simulator extend this VSFrame class.
+ * This class makes sure that all 'subwindows' get closed if its parent gets
+ * closed. And it also makes sure to open new windows relative to its parent.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSFrame extends JFrame {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The Constant X_LOCATION_OFFSET. */
+ private final static int X_LOCATION_OFFSET = 40;
+
+ /** The Constant Y_LOCATION_OFFSET. */
+ private final static int Y_LOCATION_OFFSET = 80;
+
+ /** The parent window/component. */
+ private Component parent;
+
+ /** True, if the current window will get disposed with its parent. */
+ private boolean dispose;
+
+ /**
+ * Instantiates a VSFrame object.
+ *
+ * @param title the title
+ * @param parent the parent
+ */
+ public VSFrame(String title, Component parent) {
+ super(title);
+ init(parent);
+ }
+
+ /**
+ * Instantiates a new VSFrame object.
+ *
+ * @param title the title
+ */
+ public VSFrame(String title) {
+ super(title);
+ init(null);
+ }
+
+ /**
+ * Inits the VSFrame.
+ *
+ * @param parent the parent
+ */
+ private void init(Component parent) {
+ this.parent = parent;
+ this.dispose = false;
+ }
+
+ /**
+ * Dispose with its parent.
+ */
+ 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;
+ }
+
+ /**
+ * Sets the correct location of the window.
+ */
+ private void setCorrectLocation() {
+ int x = 0, y = 0;
+ final Dimension screenSize =
+ Toolkit.getDefaultToolkit().getScreenSize();
+
+ if (parent == null) {
+ x = (int) (screenSize.width - getWidth()) / 2;
+ y = 50;//(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;
+ }
+
+ if (x + super.getWidth() >= screenSize.width)
+ x = screenSize.width - super.getWidth();
+ else if (x < 0)
+ x = 0;
+
+ if (y + super.getHeight() >= screenSize.height)
+ y = screenSize.height - super.getHeight();
+
+ super.setLocation(x, y);
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.Window#setSize(int, int)
+ */
+ public void setSize(int width, int height) {
+ super.setSize(width, height);
+ setCorrectLocation();
+ }
+}
diff --git a/VS-Sim-Sources/sources/utils/VSInfoArea.java b/VS-Sim-Sources/sources/utils/VSInfoArea.java
new file mode 100644
index 0000000..ce88699
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSInfoArea.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+/**
+ * The class VSInfoArea, an object of this class is used for some information
+ *areas. E.g. in the VSAboutFrame class.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSInfoArea extends JTextPane {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Instantiates a new VSInfoArea.
+ */
+ public VSInfoArea() {
+ init();
+ }
+
+ /**
+ * Instantiates a new VSInfoArea.
+ *
+ * @param text the text to display
+ */
+ public VSInfoArea(String text) {
+ setText(text);
+ init();
+ }
+
+ /**
+ * Inits the info area.
+ */
+ private void init() {
+ 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/VS-Sim-Sources/sources/utils/VSPriorityQueue.java b/VS-Sim-Sources/sources/utils/VSPriorityQueue.java
new file mode 100644
index 0000000..739a886
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSPriorityQueue.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+import java.util.PriorityQueue;
+
+/**
+ * The class VSPriorityQueue. This class is the same like the standard
+ * VSPriorityQueue of the Java API. It only overrides the get(int) method.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSPriorityQueue<T> extends PriorityQueue<T> {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Gets the specific element. If the index is out of bounds, it will return
+ * null.
+ *
+ * @param index the index
+ *
+ * @return the element, or null, if out of bounds
+ */
+ public T get(int index) {
+ int i = 0;
+
+ for (T t : this)
+ if (i++ == index)
+ return t;
+
+ return null;
+ }
+}
diff --git a/VS-Sim-Sources/sources/utils/VSRandom.java b/VS-Sim-Sources/sources/utils/VSRandom.java
new file mode 100644
index 0000000..d955aae
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSRandom.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+import java.util.Random;
+
+/**
+ * The class VSRandom. Some customization of the standard Random class of Java.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSRandom extends Random {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Instantiates a new VSrandom object.
+ *
+ * @param seedAdd the seed to add.
+ */
+ public VSRandom(long seedAdd) {
+ super(seedAdd*System.currentTimeMillis()+seedAdd);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Random#nextInt()
+ */
+ public int nextInt() {
+ return Math.abs(super.nextInt());
+ }
+
+ /**
+ * Next long.
+ *
+ * @param mod the mod
+ *
+ * @return the random long
+ */
+ public long nextLong(long mod) {
+ return Math.abs((super.nextLong() + System.currentTimeMillis()) % mod);
+ }
+}
diff --git a/VS-Sim-Sources/sources/utils/VSTools.java b/VS-Sim-Sources/sources/utils/VSTools.java
new file mode 100644
index 0000000..feece80
--- /dev/null
+++ b/VS-Sim-Sources/sources/utils/VSTools.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package utils;
+
+import java.util.Vector;
+
+/**
+ * The class VSTools. This class contains only static methods. Those methods
+ * are for general usage and don't fit into other classes.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSTools {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Gets the time string.
+ *
+ * @param time the time
+ *
+ * @return the time string
+ */
+ public static String getTimeString(long time) {
+ String ret = ""+time;
+
+ while (ret.length() < 6)
+ ret = "0" + ret;
+
+ return ret + "ms";
+ }
+
+ /**
+ * Gets the string time.
+ *
+ * @param string the string
+ *
+ * @return the string time
+ */
+ 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;
+ }
+
+ /**
+ * Gets the integer vector represented by a comma separated string.
+ *
+ * @param string the string
+ *
+ * @return the parsed vector
+ */
+ public static Vector<Integer> parseIntegerVector(String string)
+ throws exceptions.VSParseIntegerVectorException {
+ Vector<Integer> vec = new Vector<Integer>();
+
+ int index = string.indexOf('[');
+ if (index == -1)
+ throw new exceptions.VSParseIntegerVectorException();
+
+ string = string.substring(index+1);
+
+ index = string.indexOf(']');
+ if (index == -1)
+ throw new exceptions.VSParseIntegerVectorException();
+
+ string = string.substring(0, index);
+
+ try {
+ while ( (index = string.indexOf(',')) != -1 ) {
+ String substring = string.substring(0, index);
+
+ /* Remove leading whitespaces */
+ while (substring.charAt(0) == ' ')
+ substring = substring.substring(1);
+
+ vec.add(Integer.parseInt(substring));
+ string = string.substring(index+1);
+ }
+
+ /* Remove leading whitespaces */
+ while (string.charAt(0) == ' ')
+ string = string.substring(1);
+ vec.add(Integer.parseInt(string));
+
+ } catch (StringIndexOutOfBoundsException e) {
+ } catch (NumberFormatException e) {
+ }
+
+ return vec;
+ }
+}