Separated some functionality out into reusable classes, and built a
simplistic, text-field oriented interface for major property groups. The JAR is now executable, so the program can be launched with java -jar fgfsclient.jar <host> <port>
This commit is contained in:
parent
2821153720
commit
08848a284b
6 changed files with 216 additions and 26 deletions
|
@ -19,7 +19,7 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jar" depends="compile">
|
<target name="jar" depends="compile">
|
||||||
<jar jarfile="fgfsclient.jar" basedir="classes" excludes="**/Makefile"/>
|
<jar manifest="main-class.txt" jarfile="fgfsclient.jar" basedir="classes" excludes="**/Makefile"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="javadoc" depends="prepare">
|
<target name="javadoc" depends="prepare">
|
||||||
|
|
Binary file not shown.
2
scripts/java/FGClient/main-class.txt
Normal file
2
scripts/java/FGClient/main-class.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: FGFSDemo
|
|
@ -2,13 +2,14 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.awt.FlowLayout;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTabbedPane;
|
||||||
|
|
||||||
import org.flightgear.fgfsclient.FGFSConnection;
|
import org.flightgear.fgfsclient.FGFSConnection;
|
||||||
|
import org.flightgear.fgfsclient.PropertyPage;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,27 +36,104 @@ public class FGFSDemo
|
||||||
super("FlightGear Client Console");
|
super("FlightGear Client Console");
|
||||||
|
|
||||||
fgfs = new FGFSConnection(host, port);
|
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"));
|
page = new PropertyPage(fgfs, "View");
|
||||||
longitudeLabel = new JTextField(fgfs.get("/position/longitude-deg"));
|
page.addField("/sim/view-mode", "View mode:");
|
||||||
latitudeLabel = new JTextField(fgfs.get("/position/latitude-deg"));
|
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: "));
|
page = new PropertyPage(fgfs, "Location");
|
||||||
getContentPane().add(altitudeLabel);
|
page.addField("/position/altitude-ft", "Altitude (ft):");
|
||||||
getContentPane().add(new JLabel("Longitude: "));
|
page.addField("/position/longitude-deg", "Longitude (deg):");
|
||||||
getContentPane().add(longitudeLabel);
|
page.addField("/position/latitude-deg", "Latitude (deg):");
|
||||||
getContentPane().add(new JLabel("Latitude: "));
|
page.addField("/orientation/roll-deg", "Roll (deg):");
|
||||||
getContentPane().add(latitudeLabel);
|
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();
|
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 FGFSConnection fgfs;
|
||||||
private JTextField altitudeLabel;
|
private JTabbedPane tabs;
|
||||||
private JTextField longitudeLabel;
|
private HashMap pages;
|
||||||
private JTextField latitudeLabel;
|
|
||||||
|
|
||||||
public static void main (String args[])
|
public static void main (String args[])
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -77,16 +155,19 @@ public class FGFSDemo
|
||||||
public void run ()
|
public void run ()
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
int index = tabs.getSelectedIndex();
|
||||||
altitudeLabel.setText(fgfs.get("/position/altitude-ft"));
|
if (index > -1) {
|
||||||
longitudeLabel.setText(fgfs.get("/position/longitude-deg"));
|
String name = tabs.getTitleAt(index);
|
||||||
latitudeLabel.setText(fgfs.get("/position/latitude-deg"));
|
PropertyPage page = (PropertyPage)pages.get(name);
|
||||||
} catch (IOException e) {
|
try {
|
||||||
}
|
page.update();
|
||||||
try {
|
} catch (IOException e) {
|
||||||
Thread.sleep(1000);
|
}
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue