summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2009-02-02 22:56:13 +0000
committerPaul Buetow <paul@buetow.org>2009-02-02 22:56:13 +0000
commit11c138d4971d686817b11c6da84fbb2aeedd489b (patch)
tree7740ac198af546717a3cb4aef22f0762f274a8eb
released v0.2v0.2
-rw-r--r--CHANGELOG4
-rw-r--r--LICENSE21
-rw-r--r--build.xml62
-rwxr-xr-xscripts/beforecommit.sh21
-rwxr-xr-xscripts/checklinelengths.sh27
-rwxr-xr-xscripts/formatthecode.sh19
-rwxr-xr-xscripts/printstatistics.sh19
-rwxr-xr-xscripts/replaceastring.sh25
-rw-r--r--sources/smstrade/SFrame.java134
-rw-r--r--sources/smstrade/SMain.java277
-rw-r--r--sources/smstrade/SPrefs.java135
11 files changed, 744 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..9ca35c6
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,4 @@
+Mon Feb 2 - Changes from v0.1 -> v0.2
+ Default language is now english (used to be german)
+ Bugfix: If a message > 160 chars has been typed, the form will not
+ freeze any more
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..48f37d2
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+/* JSMSTrade v0.2
+ * Copyright (c) 2008 - 2009 Dipl.-Inform. (FH) Paul C. Buetow
+ * jsmstrade@dev.buetow.org - http://jsmstrade.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.
+ */
diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..25a9ecb
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,62 @@
+<project name="JSMSTrade QuickPanel" default="dist" basedir=".">
+ <description>This is a small tool to use with SMSTRADE.de!</description>
+
+ <!-- set global properties for this build -->
+ <property name="sources" location="sources" />
+ <property name="dist" location="dist" />
+ <property name="classes" location="classes" />
+
+ <target name="init">
+ <tstamp />
+ <mkdir dir="${classes}" />
+ </target>
+
+ <target name="compile" depends="init" description="compile the source" >
+ <javac srcdir="${sources}" destdir="${classes}">
+ <compilerarg value="-Xlint:deprecation,unchecked" />
+ </javac>
+ </target>
+
+ <target name="dist" depends="compile" description="generate the distribution" >
+ <delete file="MANIFEST.MF" />
+
+ <manifest file="MANIFEST.MF">
+ <attribute name="Built-By" value="Paul C. Buetow" />
+ <attribute name="Main-Class" value="smstrade/SMain" />
+ </manifest>
+
+ <mkdir dir="${dist}/lib" />
+ <jar jarfile="${dist}/lib/JSMSTrade-${DSTAMP}.jar" basedir="${classes}" manifest="MANIFEST.MF" />
+ <copy file="${dist}/lib/JSMSTrade-${DSTAMP}.jar" tofile="${dist}/lib/JSMSTrade-Latest.jar" />
+ </target>
+
+ <target name="clean" description="clean up" >
+ <delete dir="${basedir}/javadoc/" />
+ <delete dir="${classes}" />
+ <delete dir="${dist}" />
+ <delete file="MANIFEST.MF" />
+ </target>
+
+ <target name="rundist" depends="dist">
+ <java jar="${dist}/lib/JSMSTrade-Latest.jar" fork="true" />
+ </target>
+
+ <target name="run" depends="compile">
+ <java dir="${classes}" classname="smstrade.SMain" fork="true" />
+ </target>
+
+ <target name="testdist" depends="dist,rundist" />
+
+ <target name="test" depends="compile">
+ <java dir="${classes}" classname="smstrade.SMain" fork="true">
+ <!-- <arg value="-debug" /> -->
+ </java>
+ </target>
+
+ <target name="javadoc" description="Generate Javadocs">
+ <mkdir dir="${basedir}/javadoc/"/>
+ <javadoc destdir="${basedir}/javadoc/">
+ <fileset dir="${basedir}/" includes="**/*.java" />
+ </javadoc>
+ </target>
+</project>
diff --git a/scripts/beforecommit.sh b/scripts/beforecommit.sh
new file mode 100755
index 0000000..a06ee8f
--- /dev/null
+++ b/scripts/beforecommit.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# 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.
+
+./scripts/formatthecode.sh
+./scripts/checklinelengths.sh
+
diff --git a/scripts/checklinelengths.sh b/scripts/checklinelengths.sh
new file mode 100755
index 0000000..7cfcacf
--- /dev/null
+++ b/scripts/checklinelengths.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# 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.
+
+MAXLEN=80
+
+for i in `find ./sources -name \*.java`
+do
+ awk -v MAXLEN=$MAXLEN -v file=$i '{
+ if (length > MAXLEN)
+ print file " line " NR " is " length " chars long "
+ }' $i
+done
diff --git a/scripts/formatthecode.sh b/scripts/formatthecode.sh
new file mode 100755
index 0000000..5733c31
--- /dev/null
+++ b/scripts/formatthecode.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# 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.
+
+find ./sources -name \*.java | xargs astyle --style=java --mode=java -n
diff --git a/scripts/printstatistics.sh b/scripts/printstatistics.sh
new file mode 100755
index 0000000..ca356b5
--- /dev/null
+++ b/scripts/printstatistics.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# 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.
+
+find ./sources -name \*.java | xargs wc -l
diff --git a/scripts/replaceastring.sh b/scripts/replaceastring.sh
new file mode 100755
index 0000000..6b50b83
--- /dev/null
+++ b/scripts/replaceastring.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# 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.
+
+FROM=$1
+INTO=$2
+
+echo "Replaceing $FROM with $INTO"
+
+find ./sources -name \*.java -exec sh -c "sed -n 's/$FROM/$INTO/g; \
+ w .tmp' {} && mv -f .tmp {}" \;
diff --git a/sources/smstrade/SFrame.java b/sources/smstrade/SFrame.java
new file mode 100644
index 0000000..0c223a5
--- /dev/null
+++ b/sources/smstrade/SFrame.java
@@ -0,0 +1,134 @@
+/* JSMSTrade v0.2
+ * Copyright (c) 2008, 2009 Dipl.-Inform. (FH) Paul C. Buetow
+ * jsmstrade@dev.buetow.org - http://jsmstrade.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.
+ */
+
+package smstrade;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+
+/**
+ * The class SFrame. All frames of the tool extend this SFrame 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 SFrame 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 SFrame object.
+ *
+ * @param title the title
+ * @param parent the parent
+ */
+ public SFrame(String title, Component parent) {
+ super(title);
+ init(parent);
+ }
+
+ /**
+ * Instantiates a new SFrame object.
+ *
+ * @param title the title
+ */
+ public SFrame(String title) {
+ super(title);
+ init(null);
+ }
+
+ /**
+ * Inits the SFrame.
+ *
+ * @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) {
+ SFrame.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/sources/smstrade/SMain.java b/sources/smstrade/SMain.java
new file mode 100644
index 0000000..b9f3c8d
--- /dev/null
+++ b/sources/smstrade/SMain.java
@@ -0,0 +1,277 @@
+/* JSMSTrade v0.2
+ * Copyright (c) 2008, 2009 Dipl.-Inform. (FH) Paul C. Buetow
+ * jsmstrade@dev.buetow.org - http://jsmstrade.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.
+ */
+
+package smstrade;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import javax.swing.*;
+import javax.swing.event.*;
+
+/**
+ * The class SMain.
+ *
+ * @author Paul C. Buetow
+ */
+public class SMain extends SFrame {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The max length of a SMS message */
+ private static final int MESSAGE_MAX_LENGTH = 160;
+
+ /** The program version */
+ private static final double VERSION = 0.2;
+
+ /** The save file */
+ public static final String SAVE_FILE = "jsmstrade.dat";
+
+ /** The default URL */
+ public static final String DEFAULT_URL =
+ "https://gateway.smstrade.de?key=KEY&to=TO&route=basic&message=";
+
+ /** The options map */
+ private HashMap<String,String> options = null;
+
+ /** The text area */
+ private JTextArea textArea = new JTextArea();
+
+ /** The send button */
+ private JButton sendButton = new JButton("Send it");
+
+ /** The clear button */
+ private JButton clearButton = new JButton("Delete");
+
+ /** The counter label button */
+ private JLabel counterLabel = new JLabel(" 160");
+
+ /** The counter text label button */
+ private JLabel counterTextLabel = new JLabel("Chars");
+
+ /** The button panel */
+ private JPanel buttonPanel = new JPanel();
+
+ /** The menu bar */
+ private JMenuBar menuBar = new JMenuBar();
+
+ /** The file menu */
+ private JMenu fileMenu = new JMenu("File");
+
+ /**
+ * Instantiates a new SMain object.
+ */
+ public SMain(HashMap<String,String> options) {
+ super("JSMSTrade v" + VERSION);
+ this.options = options;
+
+ setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ setSize(300, 150);
+ setResizable(false);
+
+ fillMenuBar();
+ fillContentPane();
+ setVisible(true);
+ }
+
+ /**
+ * Fills the menu bar
+ */
+ private void fillMenuBar() {
+ menuBar.add(fileMenu);
+
+ ActionListener listener = new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ JMenuItem source = (JMenuItem) ae.getSource();
+ String text = source.getText();
+
+ if (text.equals("Preferences")) {
+ new SPrefs(SMain.this, options);
+
+ } else if (text.equals("Quit")) {
+ System.exit(0);
+ }
+ }
+ };
+
+ JMenuItem prefsItem = new JMenuItem("Preferences");
+ prefsItem.addActionListener(listener);
+ fileMenu.add(prefsItem);
+
+ fileMenu.addSeparator();
+ JMenuItem exitItem = new JMenuItem("Quit");
+ exitItem.addActionListener(listener);
+ fileMenu.add(exitItem);
+
+ setJMenuBar(menuBar);
+ }
+
+ /**
+ * Fills the content pane
+ */
+ private void fillContentPane() {
+ JPanel contentPanel = (JPanel) getContentPane();
+ contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
+ contentPanel.add(textArea);
+ contentPanel.add(createButtonPanel());
+
+ textArea.addKeyListener(new KeyListener() {
+ public void keyTyped(KeyEvent ke) {
+ updateCounter(ke);
+ }
+
+ public void keyReleased(KeyEvent ke) {
+ updateCounter(ke);
+ }
+
+ public void keyPressed(KeyEvent ke) {
+ updateCounter(ke);
+ }
+
+ private void updateCounter(KeyEvent ke) {
+ int length = textArea.getText().length();
+
+ if (length > MESSAGE_MAX_LENGTH) {
+ int diff = length - MESSAGE_MAX_LENGTH;
+ textArea.setText(
+ textArea.getText().substring(0, length-diff));
+ ke.consume();
+
+ } else {
+ buttonPanel.remove(2);
+ counterLabel = new JLabel(" "+(160-length));
+ buttonPanel.add(counterLabel, 2);
+ buttonPanel.updateUI();
+ if (length == 0) {
+ clearButton.setEnabled(false);
+ sendButton.setEnabled(false);
+ } else {
+ clearButton.setEnabled(true);
+ sendButton.setEnabled(true);
+ }
+ }
+ }
+ });
+
+ textArea.setLineWrap(true);
+ textArea.setWrapStyleWord(true);
+ }
+
+ /**
+ * Creates the button panel
+ *
+ * @return The button panel
+ */
+ private JPanel createButtonPanel() {
+ ActionListener listener = new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ JButton source = (JButton) ae.getSource();
+ String text = source.getText();
+
+ if (text.equals("Senden")) {
+ String message = textArea.getText();
+ textArea.setText("");
+ buttonPanel.remove(2);
+ counterLabel = new JLabel(" 160");
+ buttonPanel.add(counterLabel, 2);
+ buttonPanel.updateUI();
+ clearButton.setEnabled(false);
+ sendButton.setEnabled(false);
+
+ try {
+ String urlString = options.get("URL")
+ + URLEncoder.encode(
+ message, "ISO-8859-1");
+
+ URL url = new URL(urlString);
+ URLConnection conn = url.openConnection();
+ InputStream is = conn.getInputStream();
+
+ int ch = 0;
+ while ((ch = is.read()) != -1) {
+ }
+ is.close();
+
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+
+ } else if (text.equals("Delete")) {
+ textArea.setText("");
+ buttonPanel.remove(2);
+ counterLabel = new JLabel(" 160");
+ buttonPanel.add(counterLabel, 2);
+ buttonPanel.updateUI();
+ clearButton.setEnabled(false);
+ sendButton.setEnabled(false);
+ }
+ }
+ };
+
+ buttonPanel.add(sendButton);
+ buttonPanel.add(clearButton);
+ buttonPanel.add(counterLabel);
+ buttonPanel.add(counterTextLabel);
+
+ sendButton.addActionListener(listener);
+ clearButton.addActionListener(listener);
+
+ clearButton.setEnabled(false);
+ sendButton.setEnabled(false);
+
+ return buttonPanel;
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ */
+ @SuppressWarnings("unchecked")
+ public static void main(String[] args) {
+ try {
+ UIManager.setLookAndFeel(
+ UIManager.getCrossPlatformLookAndFeelClassName());
+ } catch (Exception e) { }
+
+ File file = new File(SMain.SAVE_FILE);
+ HashMap<String,String> options = null;
+
+ if (file.exists()) {
+ try {
+ FileInputStream fis = new FileInputStream(file);
+ ObjectInputStream ois = new ObjectInputStream(fis);
+ options = (HashMap<String,String>) ois.readObject();
+
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+
+ } else {
+ options = new HashMap<String, String>();
+ }
+
+ new SMain(options);
+ }
+}
diff --git a/sources/smstrade/SPrefs.java b/sources/smstrade/SPrefs.java
new file mode 100644
index 0000000..16d6109
--- /dev/null
+++ b/sources/smstrade/SPrefs.java
@@ -0,0 +1,135 @@
+/* JSMSTrade v0.2
+ * Copyright (c) 2008, 2009 Dipl.-Inform. (FH) Paul C. Buetow
+ * jsmstrade@dev.buetow.org - http://jsmstrade.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.
+ */
+
+package smstrade;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.util.*;
+import javax.swing.*;
+import javax.swing.event.*;
+
+/**
+ * The class SPrefs.
+ *
+ * @author Paul C. Buetow
+ */
+public class SPrefs extends SFrame {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The options map */
+ private HashMap<String,String> options = null;
+
+ /** The text area */
+ private JTextArea textArea = new JTextArea();
+
+ /** The button panel */
+ private JPanel buttonPanel = new JPanel();
+
+ /** The ok button */
+ private JButton okButton = new JButton("OK");
+
+ /** The save button */
+ private JButton saveButton = new JButton("Save");
+
+ /**
+ * Instantiates a new SMain object.
+ */
+ public SPrefs(Component parent, HashMap<String,String> options) {
+ super("Preferences", parent);
+ this.options = options;
+
+ disposeWithParent();
+ setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ setSize(300, 150);
+ setResizable(false);
+
+ fillContentPane();
+ setVisible(true);
+ }
+
+ /**
+ * Fills the content pane
+ */
+ private void fillContentPane() {
+ JPanel contentPanel = (JPanel) getContentPane();
+ contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
+
+ if (options.containsKey("URL"))
+ textArea.setText(options.get("URL"));
+ else
+ textArea.setText(SMain.DEFAULT_URL);
+
+ textArea.setLineWrap(true);
+
+ contentPanel.add(textArea);
+ contentPanel.add(createButtonPanel());
+ }
+
+ /**
+ * Creates the button panel
+ *
+ * @return The button panel
+ */
+ private JPanel createButtonPanel() {
+ ActionListener listener = new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ JButton source = (JButton) ae.getSource();
+ String text = source.getText();
+
+ if (text.equals("OK")) {
+ save();
+ dispose();
+
+ } else if (text.equals("Save")) {
+ save();
+ }
+ }
+
+ private void save() {
+ options.put("URL", textArea.getText());
+
+ try {
+ FileOutputStream fos =
+ new FileOutputStream(SMain.SAVE_FILE);
+ ObjectOutputStream oos =
+ new ObjectOutputStream(fos);
+
+ oos.writeObject(options);
+
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+ };
+
+ buttonPanel.add(okButton);
+ buttonPanel.add(saveButton);
+
+ okButton.addActionListener(listener);
+ saveButton.addActionListener(listener);
+
+ return buttonPanel;
+ }
+}