diff --git a/scripts/java/FGClient/README b/scripts/java/FGClient/README new file mode 100644 index 000000000..a8a93077b --- /dev/null +++ b/scripts/java/FGClient/README @@ -0,0 +1,11 @@ +This directory contains a simple, Java network client library for the +FlightGear flight simulator. See the JavaDoc documentation for +org.flightgear.fgfsclient.FGFSConnection for more information. + +There is a simple demo application, FGFSDemo, that you can try like this: + + fgfs --telnet=9000 + java FGFSDemo localhost 9000 + +To rebuild the program, use the Apache ant utility. + diff --git a/scripts/java/FGClient/build.xml b/scripts/java/FGClient/build.xml new file mode 100644 index 000000000..821728615 --- /dev/null +++ b/scripts/java/FGClient/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/java/FGClient/docs/javadoc/allclasses-frame.html b/scripts/java/FGClient/docs/javadoc/allclasses-frame.html new file mode 100644 index 000000000..a38b9e560 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/allclasses-frame.html @@ -0,0 +1,25 @@ + + + + + + +All Classes + + + + + +All Classes +
+ + + + + +
FGFSConnection +
+
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/deprecated-list.html b/scripts/java/FGClient/docs/javadoc/deprecated-list.html new file mode 100644 index 000000000..a9e84346c --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/deprecated-list.html @@ -0,0 +1,91 @@ + + + + + + +: Deprecated List + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+Deprecated API

+
+
+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/help-doc.html b/scripts/java/FGClient/docs/javadoc/help-doc.html new file mode 100644 index 000000000..0df8c2e20 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/help-doc.html @@ -0,0 +1,144 @@ + + + + + + +: API Help + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+How This API Document Is Organized

+
+This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

+Package

+
+ +

+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

+
+

+Class/Interface

+
+ +

+Each class, interface, inner class and inner interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+

+Use

+
+Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
+

+Tree (Class Hierarchy)

+
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object. +
+

+Deprecated API

+
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+

+Index

+
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+

+Prev/Next

+These links take you to the next or previous class, interface, package, or related page.

+Frames/No Frames

+These links show and hide the HTML frames. All pages are available with or without frames. +

+

+Serialized Form

+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. +

+ + +This help file applies to API documentation generated using the standard doclet. + +
+


+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/index-all.html b/scripts/java/FGClient/docs/javadoc/index-all.html new file mode 100644 index 000000000..5752d86a0 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/index-all.html @@ -0,0 +1,153 @@ + + + + + + +: Index + + + + + + + + + + + + + + + + + +
+ +
+ + +C F G O S
+

+C

+
+
close() - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Close the connection to FlightGear. +
+
+

+F

+
+
FGFSConnection - class org.flightgear.fgfsclient.FGFSConnection.
A connection to a running instance of FlightGear.
FGFSConnection(String, int) - +Constructor for class org.flightgear.fgfsclient.FGFSConnection +
Constructor. +
+
+

+G

+
+
get(String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Get the raw string value for a property. +
getBoolean(String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Get a property value as a boolean. +
getDouble(String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Get a property value as a double. +
getFloat(String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Get a property value as a float. +
getInt(String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Get a property value as an integer. +
getLong(String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Get a property value as a long. +
+
+

+O

+
+
org.flightgear.fgfsclient - package org.flightgear.fgfsclient
 
+
+

+S

+
+
set(String, String) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Set the raw string value for a property. +
setBoolean(String, boolean) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Set a property value from a boolean. +
setDouble(String, double) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Set a property value from a double. +
setFloat(String, float) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Set a property value from a float. +
setInt(String, int) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Set a property value from an int. +
setLong(String, long) - +Method in class org.flightgear.fgfsclient.FGFSConnection +
Set a property value from a long. +
+
+C F G O S + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/index.html b/scripts/java/FGClient/docs/javadoc/index.html new file mode 100644 index 000000000..fc69defac --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/index.html @@ -0,0 +1,22 @@ + + + + + + +Generated Documentation (Untitled) + + + + + + + +<H2> +Frame Alert</H2> + +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. +<BR> +Link to <A HREF="org/flightgear/fgfsclient/package-summary.html">Non-frame version.</A> + diff --git a/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/FGFSConnection.html b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/FGFSConnection.html new file mode 100644 index 000000000..f9f58ebd5 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/FGFSConnection.html @@ -0,0 +1,533 @@ + + + + + + +: Class FGFSConnection + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+ +

+ +org.flightgear.fgfsclient +
+Class FGFSConnection

+
+java.lang.Object
+  |
+  +--org.flightgear.fgfsclient.FGFSConnection
+
+
+
+
public class FGFSConnection
extends Object
+ +

+A connection to a running instance of FlightGear. + +

This class currently uses the FlightGear telnet interface, + though it may be modified to use a different TCP/IP interface in + the future. Client applications can use this library to examine + and modify internal FlightGear properties.

+ +

To start FlightGear with the telnet server activated, use a + command like this (to listen on port 9000):

+ +
+ fgfs --telnet=9000
+ 
+ +

Then create a connection to FlightGear from your Java client + application:

+ +
+ FGFSConnection fgfs = new FGFSConnection("localhost", 9000);
+ 
+ +

Now you can use the connection to get and set FlightGear + properties:

+ +
+ double altitude = fgfs.getDouble("/position/altitude-ft");
+ fgfs.setDouble("/orientation/heading", 270.0);
+ 
+ +

All methods that communicate directly with FlightGear are + synchronized, since they must work over a single telnet + connection.

+

+


+ +

+ + + + + + + + + + + + + + + + +
+Constructor Summary
FGFSConnection(String host, + int port) + +
+          Constructor.
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidclose() + +
+          Close the connection to FlightGear.
+ Stringget(String name) + +
+          Get the raw string value for a property.
+ booleangetBoolean(String name) + +
+          Get a property value as a boolean.
+ doublegetDouble(String name) + +
+          Get a property value as a double.
+ floatgetFloat(String name) + +
+          Get a property value as a float.
+ intgetInt(String name) + +
+          Get a property value as an integer.
+ longgetLong(String name) + +
+          Get a property value as a long.
+ voidset(String name, + String value) + +
+          Set the raw string value for a property.
+ voidsetBoolean(String name, + boolean value) + +
+          Set a property value from a boolean.
+ voidsetDouble(String name, + double value) + +
+          Set a property value from a double.
+ voidsetFloat(String name, + float value) + +
+          Set a property value from a float.
+ voidsetInt(String name, + int value) + +
+          Set a property value from an int.
+ voidsetLong(String name, + long value) + +
+          Set a property value from a long.
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + + + + +
+Constructor Detail
+ +

+FGFSConnection

+
+public FGFSConnection(String host,
+                      int port)
+               throws IOException
+
+
Constructor. + +

Create a new connection to a running FlightGear program. + The program must have been started with the --telnet=<port> + command-line option.

+
Parameters:
host - The host name or IP address to connect to.
port - The port number where FlightGear is listening.
Throws:
IOException - If it is not possible to connect to + a FlightGear process.
+
+
+ + + + + + + + +
+Method Detail
+ +

+close

+
+public void close()
+           throws IOException
+
+
Close the connection to FlightGear. + +

The client application should always invoke this method when + it has finished with a connection, to allow cleanup.

+
Throws:
IOException - If there is an error closing the + connection.
+
+
+
+ +

+get

+
+public String get(String name)
+           throws IOException
+
+
Get the raw string value for a property. + +

This is the primitive method for all property lookup; + everything comes in as a string, and is only later converted by + methods like getDouble(String). As a result, if you + need the value as a string anyway, it makes sense to use this + method directly rather than forcing extra conversions.

+
Parameters:
name - The FlightGear property name to look up.
Returns:
The property value as a string (non-existant properties + return the empty string).
Throws:
IOException - If there is an error communicating with + FlightGear or if the connection is lost.
See Also:
getBoolean(String), +getInt(String), +getLong(String), +getFloat(String), +getDouble(String)
+
+
+
+ +

+set

+
+public void set(String name,
+                String value)
+         throws IOException
+
+
Set the raw string value for a property. + +

This is the primitive method for all property modification; + everything goes out as a string, after it has been converted by + methods like setDouble(String,double). As a result, if + you have the value as a string already, it makes sense to use + this method directly rather than forcing extra conversions.

+
Parameters:
name - The FlightGear property name to modify or create.
value - The new value for the property, as a string.
Throws:
IOException - If there is an error communicating with + FlightGear or if the connection is lost.
See Also:
setBoolean(String,boolean), +setInt(String,int), +setLong(String,long), +setFloat(String,float), +setDouble(String,double)
+
+
+
+ +

+getBoolean

+
+public boolean getBoolean(String name)
+                   throws IOException
+
+
Get a property value as a boolean.
+
Parameters:
name - The property name to look up.
Returns:
The property value as a boolean.
See Also:
get(String)
+
+
+
+ +

+getInt

+
+public int getInt(String name)
+           throws IOException
+
+
Get a property value as an integer.
+
Parameters:
name - The property name to look up.
Returns:
The property value as an int.
See Also:
get(String)
+
+
+
+ +

+getLong

+
+public long getLong(String name)
+             throws IOException
+
+
Get a property value as a long.
+
Parameters:
name - The property name to look up.
Returns:
The property value as a long.
See Also:
get(String)
+
+
+
+ +

+getFloat

+
+public float getFloat(String name)
+               throws IOException
+
+
Get a property value as a float.
+
Parameters:
name - The property name to look up.
Returns:
The property value as a float.
See Also:
get(String)
+
+
+
+ +

+getDouble

+
+public double getDouble(String name)
+                 throws IOException
+
+
Get a property value as a double.
+
Parameters:
name - The property name to look up.
Returns:
The property value as a double.
See Also:
get(String)
+
+
+
+ +

+setBoolean

+
+public void setBoolean(String name,
+                       boolean value)
+                throws IOException
+
+
Set a property value from a boolean.
+
Parameters:
name - The property name to create or modify.
value - The new property value as a boolean.
See Also:
set(String,String)
+
+
+
+ +

+setInt

+
+public void setInt(String name,
+                   int value)
+            throws IOException
+
+
Set a property value from an int.
+
Parameters:
name - The property name to create or modify.
value - The new property value as an int.
See Also:
set(String,String)
+
+
+
+ +

+setLong

+
+public void setLong(String name,
+                    long value)
+             throws IOException
+
+
Set a property value from a long.
+
Parameters:
name - The property name to create or modify.
value - The new property value as a long.
See Also:
set(String,String)
+
+
+
+ +

+setFloat

+
+public void setFloat(String name,
+                     float value)
+              throws IOException
+
+
Set a property value from a float.
+
Parameters:
name - The property name to create or modify.
value - The new property value as a float.
See Also:
set(String,String)
+
+
+
+ +

+setDouble

+
+public void setDouble(String name,
+                      double value)
+               throws IOException
+
+
Set a property value from a double.
+
Parameters:
name - The property name to create or modify.
value - The new property value as a double.
See Also:
set(String,String)
+
+
+ +
+ + + + + + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/class-use/FGFSConnection.html b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/class-use/FGFSConnection.html new file mode 100644 index 000000000..05335625f --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/class-use/FGFSConnection.html @@ -0,0 +1,93 @@ + + + + + + +: Uses of Class org.flightgear.fgfsclient.FGFSConnection + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+Uses of Class
org.flightgear.fgfsclient.FGFSConnection

+
+No usage of org.flightgear.fgfsclient.FGFSConnection +

+


+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-frame.html b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-frame.html new file mode 100644 index 000000000..02cb4ff1a --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-frame.html @@ -0,0 +1,26 @@ + + + + + + +: Package org.flightgear.fgfsclient + + + + + +org.flightgear.fgfsclient + + + + +
+Classes  + +
+FGFSConnection
+ + + + diff --git a/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-summary.html b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-summary.html new file mode 100644 index 000000000..7fee6cd5c --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-summary.html @@ -0,0 +1,104 @@ + + + + + + +: Package org.flightgear.fgfsclient + + + + + + + + + + + + + + + + + +
+ +
+ + +
+

+Package org.flightgear.fgfsclient +

+ + + + + + + + + +
+Class Summary
FGFSConnectionA connection to a running instance of FlightGear.
+  + +

+


+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-tree.html b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-tree.html new file mode 100644 index 000000000..f83b864fc --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-tree.html @@ -0,0 +1,99 @@ + + + + + + +: org.flightgear.fgfsclient Class Hierarchy + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+Hierarchy For Package org.flightgear.fgfsclient +

+
+

+Class Hierarchy +

+ +
+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-use.html b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-use.html new file mode 100644 index 000000000..3e1e7a0f4 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/org/flightgear/fgfsclient/package-use.html @@ -0,0 +1,93 @@ + + + + + + +: Uses of Package org.flightgear.fgfsclient + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+Uses of Package
org.flightgear.fgfsclient

+
+No usage of org.flightgear.fgfsclient +

+


+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/overview-tree.html b/scripts/java/FGClient/docs/javadoc/overview-tree.html new file mode 100644 index 000000000..c1b77f3e8 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/overview-tree.html @@ -0,0 +1,101 @@ + + + + + + +: Class Hierarchy + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+Hierarchy For All Packages

+
+
+
Package Hierarchies:
org.flightgear.fgfsclient
+
+

+Class Hierarchy +

+ +
+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/package-list b/scripts/java/FGClient/docs/javadoc/package-list new file mode 100644 index 000000000..46a6fc5b9 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/package-list @@ -0,0 +1 @@ +org.flightgear.fgfsclient diff --git a/scripts/java/FGClient/docs/javadoc/packages.html b/scripts/java/FGClient/docs/javadoc/packages.html new file mode 100644 index 000000000..cf02a1292 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/packages.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + +
+ +
+ +
+
+The front page has been relocated.Please see: +
+          Frame version +
+          Non-frame version.
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/serialized-form.html b/scripts/java/FGClient/docs/javadoc/serialized-form.html new file mode 100644 index 000000000..b4b41855a --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/serialized-form.html @@ -0,0 +1,91 @@ + + + + + + +Serialized Form + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+

+Serialized Form

+
+
+ + + + + + + + + + + + + +
+ +
+ + +
+ + + diff --git a/scripts/java/FGClient/docs/javadoc/stylesheet.css b/scripts/java/FGClient/docs/javadoc/stylesheet.css new file mode 100644 index 000000000..95f576498 --- /dev/null +++ b/scripts/java/FGClient/docs/javadoc/stylesheet.css @@ -0,0 +1,29 @@ +/* Javadoc style sheet */ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background color */ +body { background-color: #FFFFFF } + +/* Table colors */ +.TableHeadingColor { background: #CCCCFF } /* Dark mauve */ +.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ +.TableRowColor { background: #FFFFFF } /* White */ + +/* Font used in left-hand frame lists */ +.FrameTitleFont { font-size: normal; font-family: normal } +.FrameHeadingFont { font-size: normal; font-family: normal } +.FrameItemFont { font-size: normal; font-family: normal } + +/* Example of smaller, sans-serif font in frames */ +/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ + +/* Navigation bar fonts and colors */ +.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ +.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ +.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} +.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} + +.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} +.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} + diff --git a/scripts/java/FGClient/fgfsclient.jar b/scripts/java/FGClient/fgfsclient.jar new file mode 100644 index 000000000..c7b1ccd65 Binary files /dev/null and b/scripts/java/FGClient/fgfsclient.jar differ diff --git a/scripts/java/FGClient/src/FGFSDemo.java b/scripts/java/FGClient/src/FGFSDemo.java new file mode 100644 index 000000000..ff0431a14 --- /dev/null +++ b/scripts/java/FGClient/src/FGFSDemo.java @@ -0,0 +1,97 @@ +// FGFSDemo.java - Simple demo application. + +import java.io.IOException; + +import java.awt.FlowLayout; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; + +import org.flightgear.fgfsclient.FGFSConnection; + + +/** + * Simple GUI demo. + * + *

This demo connects to a running FlightGear process and displays + * the current altitude, longitude, and latitude in a GUI window, with + * updates every second.

+ * + *

Usage:

+ * + *
+ * fgfs --telnet=9000
+ * java FGFSDemo localhost 9000
+ * 
+ */ +public class FGFSDemo + extends JFrame +{ + + public FGFSDemo (String host, int port) + throws IOException + { + super("FlightGear Client Console"); + + fgfs = new FGFSConnection(host, port); + + getContentPane().setLayout(new FlowLayout()); + + altitudeLabel = new JTextField(fgfs.get("/position/altitude-ft")); + longitudeLabel = new JTextField(fgfs.get("/position/longitude-deg")); + latitudeLabel = new JTextField(fgfs.get("/position/latitude-deg")); + + getContentPane().add(new JLabel("Altitude: ")); + getContentPane().add(altitudeLabel); + getContentPane().add(new JLabel("Longitude: ")); + getContentPane().add(longitudeLabel); + getContentPane().add(new JLabel("Latitude: ")); + getContentPane().add(latitudeLabel); + + new Thread(new Updater()).start(); + } + + private FGFSConnection fgfs; + private JTextField altitudeLabel; + private JTextField longitudeLabel; + private JTextField latitudeLabel; + + public static void main (String args[]) + throws Exception + { + if (args.length != 2) { + System.err.println("Usage: FGFSDemo "); + System.exit(2); + } + FGFSDemo gui = new FGFSDemo(args[0], Integer.parseInt(args[1])); + gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + gui.pack(); + gui.show(); + } + + class Updater + implements Runnable + { + + public void run () + { + while (true) { + try { + altitudeLabel.setText(fgfs.get("/position/altitude-ft")); + longitudeLabel.setText(fgfs.get("/position/longitude-deg")); + latitudeLabel.setText(fgfs.get("/position/latitude-deg")); + } catch (IOException e) { + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + } + + } + +} + +// end of FGFSDemo.java diff --git a/scripts/java/FGClient/src/org/flightgear/fgfsclient/FGFSConnection.java b/scripts/java/FGClient/src/org/flightgear/fgfsclient/FGFSConnection.java new file mode 100644 index 000000000..e8f1067e5 --- /dev/null +++ b/scripts/java/FGClient/src/org/flightgear/fgfsclient/FGFSConnection.java @@ -0,0 +1,317 @@ +// FGFSConnection.java - client library for the FlightGear flight simulator. +// Started June 2002 by David Megginson, david@megginson.com +// This library is in the Public Domain and comes with NO WARRANTY. + +package org.flightgear.fgfsclient; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.PrintWriter; + +import java.net.Socket; + + +/** + * A connection to a running instance of FlightGear. + * + *

This class currently uses the FlightGear telnet interface, + * though it may be modified to use a different TCP/IP interface in + * the future. Client applications can use this library to examine + * and modify internal FlightGear properties.

+ * + *

To start FlightGear with the telnet server activated, use a + * command like this (to listen on port 9000):

+ * + *
+ * fgfs --telnet=9000
+ * 
+ * + *

Then create a connection to FlightGear from your Java client + * application:

+ * + *
+ * FGFSConnection fgfs = new FGFSConnection("localhost", 9000);
+ * 
+ * + *

Now you can use the connection to get and set FlightGear + * properties:

+ * + *
+ * double altitude = fgfs.getDouble("/position/altitude-ft");
+ * fgfs.setDouble("/orientation/heading", 270.0);
+ * 
+ * + *

All methods that communicate directly with FlightGear are + * synchronized, since they must work over a single telnet + * connection.

+ */ +public class FGFSConnection +{ + + + //////////////////////////////////////////////////////////////////// + // Constructor. + //////////////////////////////////////////////////////////////////// + + + /** + * Constructor. + * + *

Create a new connection to a running FlightGear program. + * The program must have been started with the --telnet=<port> + * command-line option.

+ * + * @param host The host name or IP address to connect to. + * @param port The port number where FlightGear is listening. + * @exception IOException If it is not possible to connect to + * a FlightGear process. + */ + public FGFSConnection (String host, int port) + throws IOException + { + socket = new Socket(host, port); + in = + new BufferedReader(new InputStreamReader(socket.getInputStream())); + out = new PrintWriter(socket.getOutputStream(), true); + out.println("data\r"); + } + + + + //////////////////////////////////////////////////////////////////// + // Primitive getter and setter. + //////////////////////////////////////////////////////////////////// + + + /** + * Close the connection to FlightGear. + * + *

The client application should always invoke this method when + * it has finished with a connection, to allow cleanup.

+ * + * @exception IOException If there is an error closing the + * connection. + */ + public synchronized void close () + throws IOException + { + out.println("quit\r"); + in.close(); + out.close(); + socket.close(); + } + + + /** + * Get the raw string value for a property. + * + *

This is the primitive method for all property lookup; + * everything comes in as a string, and is only later converted by + * methods like {@link #getDouble(String)}. As a result, if you + * need the value as a string anyway, it makes sense to use this + * method directly rather than forcing extra conversions.

+ * + * @param name The FlightGear property name to look up. + * @return The property value as a string (non-existant properties + * return the empty string). + * @exception IOException If there is an error communicating with + * FlightGear or if the connection is lost. + * @see #getBoolean(String) + * @see #getInt(String) + * @see #getLong(String) + * @see #getFloat(String) + * @see #getDouble(String) + */ + public synchronized String get (String name) + throws IOException + { + out.println("get " + name + '\r'); + return in.readLine(); + } + + + /** + * Set the raw string value for a property. + * + *

This is the primitive method for all property modification; + * everything goes out as a string, after it has been converted by + * methods like {@link #setDouble(String,double)}. As a result, if + * you have the value as a string already, it makes sense to use + * this method directly rather than forcing extra conversions.

+ * + * @param name The FlightGear property name to modify or create. + * @param value The new value for the property, as a string. + * @exception IOException If there is an error communicating with + * FlightGear or if the connection is lost. + * @see #setBoolean(String,boolean) + * @see #setInt(String,int) + * @see #setLong(String,long) + * @see #setFloat(String,float) + * @see #setDouble(String,double) + */ + public synchronized void set (String name, String value) + throws IOException + { + out.println("set " + name + ' ' + value + '\r'); + } + + + + //////////////////////////////////////////////////////////////////// + // Derived getters and setters. + //////////////////////////////////////////////////////////////////// + + + /** + * Get a property value as a boolean. + * + * @param name The property name to look up. + * @return The property value as a boolean. + * @see #get(String) + */ + public boolean getBoolean (String name) + throws IOException + { + return get(name).equals("true"); + } + + + /** + * Get a property value as an integer. + * + * @param name The property name to look up. + * @return The property value as an int. + * @see #get(String) + */ + public int getInt (String name) + throws IOException + { + return Integer.parseInt(get(name)); + } + + + /** + * Get a property value as a long. + * + * @param name The property name to look up. + * @return The property value as a long. + * @see #get(String) + */ + public long getLong (String name) + throws IOException + { + return Long.parseLong(get(name)); + } + + + /** + * Get a property value as a float. + * + * @param name The property name to look up. + * @return The property value as a float. + * @see #get(String) + */ + public float getFloat (String name) + throws IOException + { + return Float.parseFloat(get(name)); + } + + + /** + * Get a property value as a double. + * + * @param name The property name to look up. + * @return The property value as a double. + * @see #get(String) + */ + public double getDouble (String name) + throws IOException + { + return Double.parseDouble(get(name)); + } + + + /** + * Set a property value from a boolean. + * + * @param name The property name to create or modify. + * @param value The new property value as a boolean. + * @see #set(String,String) + */ + public void setBoolean (String name, boolean value) + throws IOException + { + set(name, (value ? "true" : "false")); + } + + + /** + * Set a property value from an int. + * + * @param name The property name to create or modify. + * @param value The new property value as an int. + * @see #set(String,String) + */ + public void setInt (String name, int value) + throws IOException + { + set(name, Integer.toString(value)); + } + + + /** + * Set a property value from a long. + * + * @param name The property name to create or modify. + * @param value The new property value as a long. + * @see #set(String,String) + */ + public void setLong (String name, long value) + throws IOException + { + set(name, Long.toString(value)); + } + + + /** + * Set a property value from a float. + * + * @param name The property name to create or modify. + * @param value The new property value as a float. + * @see #set(String,String) + */ + public void setFloat (String name, float value) + throws IOException + { + set(name, Float.toString(value)); + } + + + /** + * Set a property value from a double. + * + * @param name The property name to create or modify. + * @param value The new property value as a double. + * @see #set(String,String) + */ + public void setDouble (String name, double value) + throws IOException + { + set(name, Double.toString(value)); + } + + + + //////////////////////////////////////////////////////////////////// + // Internal state. + //////////////////////////////////////////////////////////////////// + + private Socket socket; + private BufferedReader in; + private PrintWriter out; + +} + +// end of FGFSConnection.java