diff --git a/scripts/java/FGClient/build.xml b/scripts/java/FGClient/build.xml index 821728615..d10590f81 100644 --- a/scripts/java/FGClient/build.xml +++ b/scripts/java/FGClient/build.xml @@ -19,7 +19,7 @@ - + diff --git a/scripts/java/FGClient/fgfsclient.jar b/scripts/java/FGClient/fgfsclient.jar index c7b1ccd65..5f23d5ccb 100644 Binary files a/scripts/java/FGClient/fgfsclient.jar and b/scripts/java/FGClient/fgfsclient.jar differ diff --git a/scripts/java/FGClient/main-class.txt b/scripts/java/FGClient/main-class.txt new file mode 100644 index 000000000..93a35ba6e --- /dev/null +++ b/scripts/java/FGClient/main-class.txt @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Main-Class: FGFSDemo diff --git a/scripts/java/FGClient/src/FGFSDemo.java b/scripts/java/FGClient/src/FGFSDemo.java index ff0431a14..132689774 100644 --- a/scripts/java/FGClient/src/FGFSDemo.java +++ b/scripts/java/FGClient/src/FGFSDemo.java @@ -2,13 +2,14 @@ import java.io.IOException; -import java.awt.FlowLayout; +import java.util.HashMap; import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JTextField; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; import org.flightgear.fgfsclient.FGFSConnection; +import org.flightgear.fgfsclient.PropertyPage; /** @@ -35,27 +36,104 @@ public class FGFSDemo super("FlightGear Client Console"); fgfs = new FGFSConnection(host, port); + tabs = new JTabbedPane(); + pages = new HashMap(); - getContentPane().setLayout(new FlowLayout()); + PropertyPage page = new PropertyPage(fgfs, "Simulation"); + page.addField("/sim/aircraft", "Aircraft:"); + page.addField("/sim/startup/airport-id", "Airport ID:"); + page.addField("/sim/time/gmt", "Current time (GMT):"); + page.addField("/sim/startup/trim", "Trim on ground (true/false):"); + page.addField("/sim/sound/audible", "Sound enabled (true/false):"); + page.addField("/sim/startup/browser-app", "Web browser:"); + addPage(page); - altitudeLabel = new JTextField(fgfs.get("/position/altitude-ft")); - longitudeLabel = new JTextField(fgfs.get("/position/longitude-deg")); - latitudeLabel = new JTextField(fgfs.get("/position/latitude-deg")); + page = new PropertyPage(fgfs, "View"); + page.addField("/sim/view-mode", "View mode:"); + page.addField("/sim/current-view/field-of-view", + "Field of view (deg):"); + page.addField("/sim/current-view/pitch-offset-deg", + "View pitch offset (deg):"); + page.addField("/sim/current-view/heading-offset-deg", + "View heading offset (deg):"); + addPage(page); - getContentPane().add(new JLabel("Altitude: ")); - getContentPane().add(altitudeLabel); - getContentPane().add(new JLabel("Longitude: ")); - getContentPane().add(longitudeLabel); - getContentPane().add(new JLabel("Latitude: ")); - getContentPane().add(latitudeLabel); + page = new PropertyPage(fgfs, "Location"); + page.addField("/position/altitude-ft", "Altitude (ft):"); + page.addField("/position/longitude-deg", "Longitude (deg):"); + page.addField("/position/latitude-deg", "Latitude (deg):"); + page.addField("/orientation/roll-deg", "Roll (deg):"); + page.addField("/orientation/pitch-deg", "Pitch (deg):"); + page.addField("/orientation/heading-deg", "Heading (deg):"); + addPage(page); + + page = new PropertyPage(fgfs, "Weather"); + page.addField("/environment/wind-from-heading-deg", + "Wind direction (deg FROM):"); + page.addField("/environment/params/base-wind-speed-kt", + "Wind speed (kt):"); + page.addField("/environment/params/gust-wind-speed-kt", + "Maximum gust (kt):"); + page.addField("/environment/wind-from-down-fps", + "Updraft (fps):"); + page.addField("/environment/temperature-degc", "Temperature (degC):"); + page.addField("/environment/dewpoint-degc", "Dewpoint (degC):"); + page.addField("/environment/pressure-sea-level-inhg", + "Altimeter setting (inHG):"); + addPage(page); + + page = new PropertyPage(fgfs, "Clouds"); + page.addField("/environment/clouds/layer[0]/type", + "Layer 0 type:"); + page.addField("/environment/clouds/layer[0]/elevation-ft", + "Layer 0 height (ft):"); + page.addField("/environment/clouds/layer[0]/thickness-ft", + "Layer 0 thickness (ft):"); + page.addField("/environment/clouds/layer[1]/type", + "Layer 1 type:"); + page.addField("/environment/clouds/layer[1]/elevation-ft", + "Layer 1 height (ft):"); + page.addField("/environment/clouds/layer[1]/thickness-ft", + "Layer 1 thickness (ft):"); + page.addField("/environment/clouds/layer[2]/type", + "Layer 2 type:"); + page.addField("/environment/clouds/layer[2]/elevation-ft", + "Layer 2 height (ft):"); + page.addField("/environment/clouds/layer[2]/thickness-ft", + "Layer 2 thickness (ft):"); + page.addField("/environment/clouds/layer[3]/type", + "Layer 3 type:"); + page.addField("/environment/clouds/layer[3]/elevation-ft", + "Layer 3 height (ft):"); + page.addField("/environment/clouds/layer[3]/thickness-ft", + "Layer 3 thickness (ft):"); + page.addField("/environment/clouds/layer[4]/type", + "Layer 4 type:"); + page.addField("/environment/clouds/layer[4]/elevation-ft", + "Layer 4 height (ft):"); + page.addField("/environment/clouds/layer[4]/thickness-ft", + "Layer 4 thickness (ft):"); + addPage(page); + + page = new PropertyPage(fgfs, "Velocities"); + page.addField("/velocities/airspeed-kt", "Airspeed (kt):"); + page.addField("/velocities/speed-down-fps", "Descent speed (fps):"); + addPage(page); + + getContentPane().add(tabs); new Thread(new Updater()).start(); } + private void addPage (PropertyPage page) + { + tabs.add(page.getName(), new JScrollPane(page)); + pages.put(page.getName(), page); + } + private FGFSConnection fgfs; - private JTextField altitudeLabel; - private JTextField longitudeLabel; - private JTextField latitudeLabel; + private JTabbedPane tabs; + private HashMap pages; public static void main (String args[]) throws Exception @@ -77,16 +155,19 @@ public class FGFSDemo 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) { + int index = tabs.getSelectedIndex(); + if (index > -1) { + String name = tabs.getTitleAt(index); + PropertyPage page = (PropertyPage)pages.get(name); + try { + page.update(); + } catch (IOException e) { + } } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } } } diff --git a/scripts/java/FGClient/src/org/flightgear/fgfsclient/PropertyField.java b/scripts/java/FGClient/src/org/flightgear/fgfsclient/PropertyField.java new file mode 100644 index 000000000..14f215b06 --- /dev/null +++ b/scripts/java/FGClient/src/org/flightgear/fgfsclient/PropertyField.java @@ -0,0 +1,59 @@ +package org.flightgear.fgfsclient; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.io.IOException; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +public class PropertyField + extends JPanel +{ + + public PropertyField (FGFSConnection fgfs, + String name, + String caption) + { + this.fgfs = fgfs; + propertyName = name; + label = new JLabel(caption); + value = new JTextField(10); + value.addActionListener(new ActionListener () { + public void actionPerformed (ActionEvent ev) + { + try { + modify(); + grabFocus(); + } catch (IOException ex) { + System.err.println("Failed to update " + propertyName); + } + } + }); + + add(label); + add(value); + + } + + public void update () + throws IOException + { + if (!value.hasFocus()) + value.setText(fgfs.get(propertyName)); + } + + public void modify () + throws IOException + { + fgfs.set(propertyName, value.getText()); + } + + private FGFSConnection fgfs; + private String propertyName; + private JLabel label; + private JTextField value; + +} diff --git a/scripts/java/FGClient/src/org/flightgear/fgfsclient/PropertyPage.java b/scripts/java/FGClient/src/org/flightgear/fgfsclient/PropertyPage.java new file mode 100644 index 000000000..ec18c13ee --- /dev/null +++ b/scripts/java/FGClient/src/org/flightgear/fgfsclient/PropertyPage.java @@ -0,0 +1,48 @@ +package org.flightgear.fgfsclient; + +import java.io.IOException; + +import java.util.ArrayList; +import java.util.Iterator; + +import javax.swing.BoxLayout; +import javax.swing.JPanel; + +public class PropertyPage + extends JPanel +{ + + public PropertyPage (FGFSConnection fgfs, String name) + { + this.fgfs = fgfs; + this.name = name; + fields = new ArrayList(); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + } + + public String getName () + { + return name; + } + + public void addField (String name, String caption) + { + PropertyField field = new PropertyField(fgfs, name, caption); + add(field); + fields.add(field); + } + + public void update () + throws IOException + { + Iterator it = fields.iterator(); + while (it.hasNext()) { + ((PropertyField)it.next()).update(); + } + } + + private FGFSConnection fgfs; + private String name; + private ArrayList fields; + +}