[TeamTalk 182]: [718] usarsim/Tools: Meters to Unreal Units Conversion Program Source Code and Jar File

bfrisch@edam.speech.cs.cmu.edu bfrisch at edam.speech.cs.cmu.edu
Fri Aug 24 17:25:35 EDT 2007


An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20070824/f0989a36/attachment.html
-------------- next part --------------
Added: usarsim/Tools/metersToUU/.classpath
===================================================================
--- usarsim/Tools/metersToUU/.classpath	                        (rev 0)
+++ usarsim/Tools/metersToUU/.classpath	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path=""/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path=""/>
+</classpath>

Added: usarsim/Tools/metersToUU/.project
===================================================================
--- usarsim/Tools/metersToUU/.project	                        (rev 0)
+++ usarsim/Tools/metersToUU/.project	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Meters to Unreal Units</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: usarsim/Tools/metersToUU/Meters to Unreal Units Conversion Program.jar
===================================================================
(Binary files differ)


Property changes on: usarsim/Tools/metersToUU/Meters to Unreal Units Conversion Program.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: usarsim/Tools/metersToUU/gui/Conversion.java
===================================================================
--- usarsim/Tools/metersToUU/gui/Conversion.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/gui/Conversion.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,85 @@
+package gui;
+import javax.swing.*;
+
+public class Conversion extends xpn.XPnFrame {
+	private static final long serialVersionUID = 7787507204607398191L;
+	
+	java.util.Stack<Double> lastNumsToConvert = new java.util.Stack<Double>();
+
+	public void init() {
+		setTitle("Ben's Meters to Unreal Units Conversion Program 1.2.1");
+		add(new xpn.XPnCenteredLabel("Select an Option"));
+		addButtons(new String[]{"View Past Conversions", "Begin Conversion", "Clear Past Conversions", "Exit"});
+		setSize(new java.awt.Dimension(475, 75));
+		setPreferredSize(new java.awt.Dimension(475, 75));
+		setResizable(false);
+		setAlwaysOnTop(true);
+	}
+	
+	public void onButtonPressed(String label) {
+		if (label.equals("Begin Conversion")) {
+			try {
+				String conversionString = "1";
+				while (conversionString != null && !conversionString.trim().equals("")) { 
+					conversionString = JOptionPane.showInputDialog(this, "Enter the Number of Meters to Convert to Unreal Units", "Ben's Meters to Unreal Units Conversion Program", JOptionPane.QUESTION_MESSAGE, null, null, conversionString).toString();
+					
+					String responseMessage = conversionString + " Meters is " + Double.parseDouble(conversionString) * 250.0 + " Unreal Units";
+					
+					if (lastNumsToConvert.size() > 0) {
+						responseMessage += "\n\n Past Conversions:";
+						
+						java.util.ListIterator<Double> it = lastNumsToConvert.listIterator();
+						String responseValues= "";
+						while (it.hasNext()) {
+							Double curDouble = it.next();
+							responseValues = "\n" + curDouble + " Meters is " + (curDouble * 250.0) + " Unreal Units" + responseValues;
+						}
+						
+						responseMessage += responseValues;
+					}
+					
+					JOptionPane.showMessageDialog(this, responseMessage, "Number of Unreal Units", JOptionPane.INFORMATION_MESSAGE);
+					
+					lastNumsToConvert.push(Double.parseDouble(conversionString));
+				}	
+			}
+			catch (Exception e) {
+				// Do nothing.
+			}
+		}
+		else if (label.equals("View Past Conversions")){
+			String responseMessage = "No Past Conversions";
+			
+			if (lastNumsToConvert.size() > 0) {
+				responseMessage += "\n\nPast Conversions:";
+				
+				java.util.ListIterator<Double> it = lastNumsToConvert.listIterator();
+				String responseValues= "";
+				while (it.hasNext()) {
+					Double curDouble = it.next();
+					responseValues = "\n" + curDouble + " Meters is " + (curDouble * 250.0) + " Unreal Units" + responseValues;
+				}
+				
+				responseMessage += responseValues;
+			}
+			
+			JOptionPane.showMessageDialog(this, responseMessage, "Number of Unreal Units", JOptionPane.INFORMATION_MESSAGE);
+		}
+		else if (label.equals("Clear Past Conversions")) {
+			if (lastNumsToConvert.size() > 0) {
+				lastNumsToConvert.removeAllElements();
+				JOptionPane.showMessageDialog(this, "All Past Conversions Cleared", getTitle(), JOptionPane.INFORMATION_MESSAGE);
+			}
+			else {
+				JOptionPane.showMessageDialog(this, "No Conversions to Clear", getTitle(), JOptionPane.INFORMATION_MESSAGE);
+			}
+		}
+		else {
+			System.exit(1);
+		}
+	}
+	
+	public static void main(String[] args) {
+		new Conversion();
+	}
+}

Added: usarsim/Tools/metersToUU/xpn/XPnCenteredLabel.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnCenteredLabel.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnCenteredLabel.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,24 @@
+package xpn;
+import javax.swing.JLabel;
+
+/**
+ * @author Benjamin Frisch
+ * @version 0.1 Alpha 4
+ */
+
+public class XPnCenteredLabel extends JLabel {
+	private static final long serialVersionUID = 4596263439400590191L;
+
+	/** Creates a new instance of StatusBar */
+    public XPnCenteredLabel(String initalText) {
+        super(initalText);
+        super.setPreferredSize(new java.awt.Dimension(100, 16));
+        super.setAlignmentX(CENTER_ALIGNMENT);
+    }
+    
+    public XPnCenteredLabel() {
+        super();
+        super.setPreferredSize(new java.awt.Dimension(100, 16));
+        super.setAlignmentX(CENTER_ALIGNMENT);
+    }
+}

Added: usarsim/Tools/metersToUU/xpn/XPnComponent.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnComponent.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnComponent.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,78 @@
+package xpn;
+
+import java.awt.Dimension;
+import java.awt.event.*;
+
+import javax.swing.JComponent;
+
+/**
+ * @author David Kosbie
+ * @author Benjamin Frisch
+ * @version 0.1 Alpha 4
+ */
+
+public class XPnComponent extends JComponent {
+	  private static final long serialVersionUID = 1L;
+	  public XPnComponent() {
+	    this.addEventListeners();
+	    this.setPreferredSize(new Dimension(400,400));
+	  } 
+
+	  // override these methods to respond to events
+	  public void onTimer() { }
+	  public void onMousePressed(int x, int y) { }
+	  public void onMouseDragged(int x, int y) { }
+	  public void onMouseReleased(int x, int y) { }
+	  public void onKeyPressed(KeyEvent e, int keyCode, char keyChar) { }
+	  public void onResized() { }
+	  public void onFocusGained() { }
+	  public void onFocusLost() { }
+	  
+	  protected void addEventListeners() {
+	    // add actions in response to mouse events
+	    addMouseListener(new MouseAdapter() {
+	      public void mousePressed(MouseEvent e) {
+	        onMousePressed(e.getX(),e.getY());
+	        repaint();
+	      }
+	      public void mouseReleased(MouseEvent e) {
+	        onMouseReleased(e.getX(),e.getY());
+	        repaint();
+	      }
+	    });
+	    
+	    // and for mouse motion events
+	    addMouseMotionListener(new MouseMotionAdapter() {
+	      public void mouseDragged(MouseEvent e) {
+	        onMouseDragged(e.getX(),e.getY());
+	        repaint();
+	      }
+	    });
+	    
+	    // and for keyboard events
+	    addKeyListener(new KeyAdapter() {
+	      public void keyPressed(KeyEvent e) {
+	        onKeyPressed(e,e.getKeyCode(),e.getKeyChar());
+	        repaint();
+	      }
+	    });
+
+	    // and for component events
+	    addComponentListener(new ComponentAdapter() {
+	      public void componentResized(ComponentEvent e) {
+	        onResized();
+	        repaint();
+	      }
+	    });
+	    
+	    this.addFocusListener(new FocusListener() {
+	    	public void focusGained(FocusEvent e) {
+	    		onFocusGained();
+	    	}
+	    	
+	    	public void focusLost(FocusEvent e) {
+	    		onFocusLost();
+	    	}
+	    });
+	  }
+	}

Added: usarsim/Tools/metersToUU/xpn/XPnDialog.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnDialog.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnDialog.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,122 @@
+package xpn;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+/**
+ * @author David Kosbie
+ * @author Benjamin Frisch
+ * @version 0.9 Alpha 7
+ */
+
+public class XPnDialog extends JDialog {
+	private static final long serialVersionUID = -2898862000185257817L;
+	
+	private boolean autoShowDialog = true;
+
+public void init() {
+  	// override this method to add your buttons, objects, etc
+  }
+
+  public void onTimer() { }  
+
+  // This method lives outside the anonymous inner class Runnable
+  // so that getClass() returns this class (in fact, the overridden subclass)  
+  protected String makeTitle() {
+  	return this.getClass().getName();
+  }
+
+  public XPnDialog() {
+  	super();
+  	privateInit();
+  }
+  
+  public XPnDialog(javax.swing.JFrame frame) {
+	  	super(frame);
+	  	privateInit();
+	  }
+  
+  public XPnDialog(javax.swing.JFrame frame, boolean modal) {
+	  	super(frame, modal);
+	  	privateInit();
+	  }
+  
+  private void privateInit() {
+  	try {
+  	    UIManager.setLookAndFeel(
+  	        UIManager.getSystemLookAndFeelClassName());
+  	} catch (UnsupportedLookAndFeelException ex) {
+  	  System.err.println("Unable to load native look and feel");
+  	}
+  	catch (Exception e) {};
+    Container cp = this.getContentPane();
+  	cp.setBackground(Color.white);
+	cp.setLayout(new BoxLayout(cp,BoxLayout.Y_AXIS));
+    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+    // use invokeLater to allow instance variables (like buttonLabels[])
+    // to be initialized in subclasses before calling init() method
+ 	javax.swing.SwingUtilities.invokeLater(new Runnable() {
+		public void run() {
+			setTitle(makeTitle());
+			init();  // override this method!
+			pack();
+			if (focusComponent != null)
+	  			// send key events to this component!
+  				focusComponent.requestFocusInWindow();
+		  	
+			if (autoShowDialog) {
+				setVisible(true);
+			}
+		}
+ 	});
+  }
+  
+  private XPnComponent focusComponent = null;
+  
+  public Component add(Component c) {
+  	Component result = super.add(c);
+  	if (c instanceof XPnComponent) {
+  		// the first one added gets the keyboard by default
+  		if (focusComponent == null) {
+  			focusComponent = (XPnComponent) c;
+  			// send key events to this component!
+  			focusComponent.requestFocusInWindow();
+  		}
+  	}
+  	return result;
+  }
+
+  public void onButtonPressed(String label) {
+  	System.out.println("onButtonPressed" + label + "\n");
+  }
+  
+  public void addButtons(String[] buttonLabels) {
+  	JPanel buttons = new JPanel();
+  	buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
+  	for (int i=0; i<buttonLabels.length; i++) {
+  		JButton button = new JButton(buttonLabels[i]);
+  		button.setFocusable(false);
+  		button.addActionListener(new ActionListener() {
+  			public void actionPerformed(ActionEvent e) {
+  				onButtonPressed(((JButton)e.getSource()).getText());
+  				repaint();
+  			}
+  		});
+  		buttons.add(button);
+  	}
+  	this.getContentPane().add(buttons);
+  }
+  
+  public void dontAutoShowDialog() {
+	  autoShowDialog = false;
+  }
+}
\ No newline at end of file

Added: usarsim/Tools/metersToUU/xpn/XPnFrame.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnFrame.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnFrame.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,108 @@
+package xpn;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+/**
+ * @author David Kosbie
+ * @author Benjamin Frisch
+ * @version 0.9 Alpha 6
+ */
+
+public class XPnFrame extends JFrame {
+	private static final long serialVersionUID = 4387726429177330603L;
+	
+	private boolean autoShowWindow = true;
+
+public void init() {
+  	// override this method to add your buttons, objects, etc
+  }
+
+  // This method lives outside the anonymous inner class Runnable
+  // so that getClass() returns this class (in fact, the overridden subclass)  
+  protected String makeTitle() {
+  	return this.getClass().getName();
+  }
+
+  public XPnFrame() {
+  	super();
+  	try {
+  	    UIManager.setLookAndFeel(
+  	        UIManager.getSystemLookAndFeelClassName());
+  	} catch (UnsupportedLookAndFeelException ex) {
+  	  System.out.println("Unable to load native look and feel");
+  	}
+  	catch (Exception e) {}
+    Container cp = this.getContentPane();
+  	cp.setBackground(Color.white);
+	cp.setLayout(new BoxLayout(cp,BoxLayout.Y_AXIS));
+    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+    this.setPreferredSize(new java.awt.Dimension(500, 500));
+    // use invokeLater to allow instance variables (like buttonLabels[])
+    // to be initialized in subclasses before calling init() method
+ 	javax.swing.SwingUtilities.invokeLater(new Runnable() {
+		public void run() {
+			setTitle(makeTitle());
+			init();  // override this method!
+			pack();
+			if (focusComponent != null)
+	  			// send key events to this component!
+  				focusComponent.requestFocusInWindow();
+		  	
+			if (autoShowWindow) {
+				setVisible(true);
+				setPreferredSize(null);
+			}
+		}
+ 	});
+  }
+  
+  private XPnComponent focusComponent = null;
+  
+  public Component add(Component c) {
+  	Component result = super.add(c);
+  	if (c instanceof XPnComponent) {
+  		// the first one added gets the keyboard by default
+  		if (focusComponent == null) {
+  			focusComponent = (XPnComponent) c;
+  			// send key events to this component!
+  			focusComponent.requestFocusInWindow();
+  		}
+  	}
+  	return result;
+  }
+
+  public void onButtonPressed(String label) {
+  	System.out.println("onButtonPressed" + label + "\n");
+  }
+  
+  public void addButtons(String[] buttonLabels) {
+  	JPanel buttons = new JPanel();
+  	buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
+  	for (int i=0; i<buttonLabels.length; i++) {
+  		JButton button = new JButton(buttonLabels[i]);
+  		button.setFocusable(false);
+  		button.addActionListener(new ActionListener() {
+  			public void actionPerformed(ActionEvent e) {
+  				onButtonPressed(((JButton)e.getSource()).getText());
+  				repaint();
+  			}
+  		});
+  		buttons.add(button);
+  	}
+  	this.getContentPane().add(buttons);
+  } 
+  
+  public void dontAutoShowWindow() {
+	  autoShowWindow = false;
+  }
+}
\ No newline at end of file

Added: usarsim/Tools/metersToUU/xpn/XPnMenu.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnMenu.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnMenu.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,102 @@
+package xpn;
+
+/**
+ * @author Benjamin Frisch
+ * @version 0.1 Alpha 4
+ */
+
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.*;
+
+public class XPnMenu extends javax.swing.JMenuBar {
+	private static final long serialVersionUID = 7864881585934574143L;
+
+	protected void processSelection (String selection) {}
+		
+	public JMenu makeMenu(JMenu menu, String[] items, char[] accell) {
+		JMenu tempMenu = menu;
+	   
+		ActionListener printListener = new ActionListener(  ) {
+			public void actionPerformed(ActionEvent event) {
+				processSelection(event.getActionCommand());
+			}
+		};
+	   
+		for (int i = 0; i<items.length; i ++) {
+			if (!items[i].equals("|")) {
+				JMenuItem item = new JMenuItem(items[i], accell[i]);
+				item.addActionListener(printListener);
+				if (accell[i] != ' ')
+					item.setAccelerator(KeyStroke.getKeyStroke(accell[i],
+							Toolkit.getDefaultToolkit(  ).getMenuShortcutKeyMask(  ), false));
+				tempMenu.add(item);
+			}
+			else {
+				tempMenu.addSeparator();
+			}
+		}
+		return tempMenu;
+	}
+   
+	public JMenu makeRadioMenu(JMenu menu, String[] items, char[] accell) {
+		JMenu tempMenu = menu;
+	   
+		ActionListener printListener = new ActionListener(  ) {
+			public void actionPerformed(ActionEvent event) {
+				processSelection(event.getActionCommand());
+			}
+		};
+	   
+		ButtonGroup buttonGroup = new ButtonGroup(  );
+	   
+		for (int i = 0; i<items.length; i ++) {
+			if (!items[i].equals("|")) {
+			   
+				JMenuItem item = new JRadioButtonMenuItem(items[i]);
+				buttonGroup.add(item);
+			   item.addActionListener(printListener);
+			   item.setAccelerator(KeyStroke.getKeyStroke(accell[i],
+					   Toolkit.getDefaultToolkit(  ).getMenuShortcutKeyMask(  ), false));
+			   if (i == 0) {item.setSelected(true);}
+			   tempMenu.add(item);
+		   }
+		   else {
+			   tempMenu.addSeparator();
+		   }
+	   }
+	   return tempMenu;
+   }
+   
+   public JMenu makeCheckMenu(JMenu menu, String[] items, char[] accell) {
+	   JMenu tempMenu = menu;
+	   
+	   ActionListener printListener = new ActionListener(  ) {
+		   public void actionPerformed(ActionEvent event) {
+			   processSelection(event.getActionCommand());
+		   }
+	   };
+	   
+	   for (int i = 0; i<items.length; i ++) {
+		   if (!items[i].equals("|")) {
+			   
+			   JMenuItem item = new JCheckBoxMenuItem(items[i]);
+			   item.addActionListener(printListener);
+			   item.setAccelerator(KeyStroke.getKeyStroke(accell[i],
+					   Toolkit.getDefaultToolkit(  ).getMenuShortcutKeyMask(  ), false));
+			   if (i == 0) {item.setSelected(true);}
+			   tempMenu.add(item);
+		   }
+		   else {
+			   tempMenu.addSeparator();
+		   }
+	   }
+	   return tempMenu;
+   }
+   
+   public JFrame getParentFrame() {
+	   return (JFrame) this.getRootPane().getParent();
+   }
+}

Added: usarsim/Tools/metersToUU/xpn/XPnNativePainting.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnNativePainting.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnNativePainting.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,16 @@
+package xpn;
+
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+public abstract class XPnNativePainting {
+	public XPnNativePainting() {
+	  	try {
+	  	    UIManager.setLookAndFeel(
+	  	        UIManager.getSystemLookAndFeelClassName());
+	  	} catch (UnsupportedLookAndFeelException ex) {
+	  	  System.out.println("Unable to load native look and feel");
+	  	}
+	  	catch (Exception e) {}
+	}
+}

Added: usarsim/Tools/metersToUU/xpn/XPnStatusBar.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnStatusBar.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnStatusBar.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,23 @@
+package xpn;
+
+/**
+ * @author Benjamin Frisch
+ * @version 0.1 Alpha 4
+ */
+
+public class XPnStatusBar extends XPnCenteredLabel {
+	private static final long serialVersionUID = 1L;
+	
+    /** Creates a new instance of StatusBar */
+    public XPnStatusBar() {
+        super();
+    }
+    
+    public XPnStatusBar(String initialText) {
+        super(initialText);
+    }
+    
+    public void setMessage(String message) {
+        setText(" "+message);        
+    }        
+}
\ No newline at end of file

Added: usarsim/Tools/metersToUU/xpn/XPnStringBundle.java
===================================================================
--- usarsim/Tools/metersToUU/xpn/XPnStringBundle.java	                        (rev 0)
+++ usarsim/Tools/metersToUU/xpn/XPnStringBundle.java	2007-08-24 21:25:34 UTC (rev 718)
@@ -0,0 +1,27 @@
+package xpn;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author Benjamin Frisch
+ * @version 0.9 Alpha 6
+ */
+
+public class XPnStringBundle {
+	private static final String BUNDLE_NAME = "strings.strings";
+
+	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+			.getBundle(BUNDLE_NAME);
+
+	private XPnStringBundle() {
+	}
+
+	public static String getString(String key) {
+		try {
+			return RESOURCE_BUNDLE.getString(key);
+		} catch (MissingResourceException e) {
+			return '!' + key + '!';
+		}
+	}
+}


More information about the TeamTalk-developers mailing list