-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,896 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | ||
<Properties> | ||
<Property name="defaultCloseOperation" type="int" value="3"/> | ||
</Properties> | ||
<SyntheticProperties> | ||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | ||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | ||
</SyntheticProperties> | ||
<AuxValues> | ||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | ||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | ||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | ||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | ||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | ||
</AuxValues> | ||
|
||
<Layout> | ||
<DimensionLayout dim="0"> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/> | ||
</Group> | ||
</DimensionLayout> | ||
<DimensionLayout dim="1"> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/> | ||
</Group> | ||
</DimensionLayout> | ||
</Layout> | ||
</Form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
/** | ||
* | ||
* @author st8511x | ||
*/ | ||
public class dashboard extends javax.swing.JFrame { | ||
|
||
/** | ||
* Creates new form dashboard | ||
*/ | ||
public dashboard() { | ||
initComponents(); | ||
} | ||
|
||
/** | ||
* This method is called from within the constructor to initialize the form. | ||
* WARNING: Do NOT modify this code. The content of this method is always | ||
* regenerated by the Form Editor. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | ||
private void initComponents() { | ||
|
||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | ||
|
||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | ||
getContentPane().setLayout(layout); | ||
layout.setHorizontalGroup( | ||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGap(0, 400, Short.MAX_VALUE) | ||
); | ||
layout.setVerticalGroup( | ||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGap(0, 300, Short.MAX_VALUE) | ||
); | ||
|
||
pack(); | ||
}// </editor-fold> | ||
|
||
/** | ||
* @param args the command line arguments | ||
*/ | ||
public static void main(String args[]) { | ||
/* Set the Nimbus look and feel */ | ||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | ||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | ||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | ||
*/ | ||
try { | ||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | ||
if ("Nimbus".equals(info.getName())) { | ||
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | ||
break; | ||
} | ||
} | ||
} catch (ClassNotFoundException ex) { | ||
java.util.logging.Logger.getLogger(dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | ||
} catch (InstantiationException ex) { | ||
java.util.logging.Logger.getLogger(dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | ||
} catch (IllegalAccessException ex) { | ||
java.util.logging.Logger.getLogger(dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | ||
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | ||
java.util.logging.Logger.getLogger(dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | ||
} | ||
//</editor-fold> | ||
|
||
/* Create and display the form */ | ||
java.awt.EventQueue.invokeLater(new Runnable() { | ||
public void run() { | ||
new dashboard().setVisible(true); | ||
} | ||
}); | ||
} | ||
|
||
// Variables declaration - do not modify | ||
// End of variables declaration | ||
} |
209 changes: 209 additions & 0 deletions
209
src/uk/ac/gre/comp1549/dashboard/DashboardDemoMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
package uk.ac.gre.comp1549.dashboard; | ||
|
||
import java.awt.Color; | ||
import java.awt.FlowLayout; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.util.Locale; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.swing.JButton; | ||
|
||
import javax.swing.JFrame; | ||
import javax.swing.JPanel; | ||
import javax.swing.JTextField; | ||
import javax.swing.WindowConstants; | ||
import javax.swing.event.DocumentEvent; | ||
import javax.swing.event.DocumentListener; | ||
import uk.ac.gre.comp1549.dashboard.controls.BarPanel; | ||
import uk.ac.gre.comp1549.dashboard.controls.DialPanel; | ||
import uk.ac.gre.comp1549.dashboard.controls.IndicatorFactory; | ||
import uk.ac.gre.comp1549.dashboard.events.*; | ||
import uk.ac.gre.comp1549.dashboard.scriptreader.DashboardEventGeneratorFromXML; | ||
import uk.ac.gre.comp1549.dashboard.controls.IIndicator; | ||
import uk.ac.gre.comp1549.dashboard.controls.Singleton; | ||
import uk.ac.gre.comp1549.dashboard.controls.ArrivalBoard; | ||
|
||
/** | ||
* DashboardDemoMain.java Contains the main method for the Dashboard demo | ||
* application. It: a) provides the controller screen which allows user input | ||
* which is passed to the display indicators, b) allows the user to run the XML | ||
* script which changes indicator values, c) creates the dashboard JFrame and | ||
* adds display indicators to it. | ||
* | ||
* @author COMP1549 | ||
* @version 2.0 | ||
*/ | ||
public class DashboardDemoMain extends JFrame { | ||
|
||
/** | ||
* Name of the XML script file - change here if you want to use a different | ||
* filename | ||
*/ | ||
public static final String XML_SCRIPT = "dashboard_script.xml"; | ||
|
||
// fields that appear on the control panel | ||
private JButton btnScript; | ||
|
||
// fields that appear on the dashboard itself | ||
private DialPanel speedDial, fuelDial, compassDial, altitudeDial; | ||
private BarPanel fuelBar; | ||
|
||
/** | ||
* Constructor. Does maybe more work than is good for a constructor. | ||
*/ | ||
public DashboardDemoMain() { | ||
// Set up the frame for the controller | ||
setTitle("Dashboard demonstration controller"); | ||
setLayout(new FlowLayout()); | ||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JPanel panel = new JPanel(); | ||
|
||
btnScript = new JButton("Run XML Script"); | ||
|
||
// When the button is read the XML script will be run | ||
btnScript.addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
new Thread() { | ||
public void run() { | ||
runXMLScript(); | ||
} | ||
}.start(); | ||
} | ||
}); | ||
panel.add(btnScript); | ||
add(panel); | ||
pack();//size determined by contained components | ||
|
||
setLocationRelativeTo(null); // display in centre of screen | ||
// this.setVisible(true); | ||
|
||
// Set up the dashboard screen | ||
JFrame dashboard = new JFrame("Demo dashboard"); | ||
dashboard.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | ||
dashboard.setLayout(new FlowLayout()); | ||
|
||
// IndicatorFactory indicatorFactory = new IndicatorFactory(); | ||
// IIndicator fullDial = indicatorFactory.createIndicator("full"); | ||
compassDial = new DialPanel("full");//full dial | ||
compassDial.setLabel("COMPASS (deg.)"); | ||
dashboard.add(compassDial); | ||
|
||
speedDial = new DialPanel("threequater");//three quaters dial | ||
speedDial.setLabel("AIR SPEED (m/s)"); | ||
dashboard.add(speedDial); | ||
|
||
|
||
altitudeDial = new DialPanel("half");//half dial | ||
altitudeDial.setLabel("ALTITUDE (km)"); | ||
dashboard.add(altitudeDial); | ||
|
||
fuelDial = new DialPanel(("quater"));//quater dial | ||
fuelDial.setLabel("FUEL (1000L)"); | ||
dashboard.add(fuelDial); | ||
|
||
|
||
DocumentListener petrolListener = new PetrolValueListener(); | ||
fuelDial.txtUserInput.getDocument().addDocumentListener(petrolListener); | ||
|
||
// add the petrol Bar | ||
fuelBar = new BarPanel(); | ||
fuelBar.setLabel("FUEL"); | ||
fuelBar.setValue(100); | ||
dashboard.add(fuelBar); | ||
ArrivalBoard ab = new ArrivalBoard(); | ||
dashboard.add(ab); | ||
|
||
//dashboard.pack(); | ||
dashboard.setSize(1000, 300); //w,h | ||
|
||
dashboard.setExtendedState(JFrame.MAXIMIZED_BOTH); | ||
//dashboard.setUndecorated(true); | ||
dashboard.add(panel); | ||
// centre the dashboard frame above the control frame | ||
// Point topLeft = this.getLocationOnScreen(); // top left of control frame (this) | ||
int hControl = this.getHeight(); // height of control frame (this) | ||
int wControl = this.getWidth(); // width of control frame (this) | ||
int hDash = dashboard.getHeight(); // height of dashboard frame | ||
int wDash = dashboard.getWidth(); // width of dashboard frame | ||
// calculate where top left of the dashboard goes to centre it over the control frame | ||
//Point p2 = new Point((int) topLeft.getX() - (wDash - wControl) / 2, (int) topLeft.getY() - (hDash + hControl)); | ||
//dashboard.setLocation(p2); | ||
|
||
dashboard.setVisible(true); | ||
} | ||
|
||
public void setFuel() { | ||
try { | ||
int value = Integer.parseInt(fuelDial.txtUserInput.getText().trim()); | ||
fuelBar.setValue(value); | ||
} catch (NumberFormatException e) { | ||
} | ||
// don't set the speed if the input can't be parsed | ||
} | ||
|
||
/** | ||
* Respond to user input in the Petrol textfield | ||
*/ | ||
private class PetrolValueListener implements DocumentListener { | ||
|
||
@Override | ||
public void insertUpdate(DocumentEvent event) { | ||
setFuel(); | ||
} | ||
|
||
@Override | ||
public void removeUpdate(DocumentEvent event) { | ||
setFuel(); | ||
} | ||
|
||
@Override | ||
public void changedUpdate(DocumentEvent event) { | ||
} | ||
} | ||
|
||
/** | ||
* Run the XML script file which generates events for the dashboard | ||
* indicators | ||
*/ | ||
private void runXMLScript() { | ||
try { | ||
DashboardEventGeneratorFromXML dbegXML = new DashboardEventGeneratorFromXML(); | ||
|
||
// Register for speed events from the XML script file | ||
DashBoardEventListener dbelSpeed = new DashBoardEventListener() { | ||
@Override | ||
public void processDashBoardEvent(Object originator, DashBoardEvent dbe) { | ||
speedDial.setValue(Integer.parseInt(dbe.getValue())); | ||
} | ||
}; | ||
dbegXML.registerDashBoardEventListener("speed", dbelSpeed); | ||
|
||
// Register for petrol events from the XML script file | ||
DashBoardEventListener dbelPetrol = new DashBoardEventListener() { | ||
@Override | ||
public void processDashBoardEvent(Object originator, DashBoardEvent dbe) { | ||
fuelDial.setValue(Integer.parseInt(dbe.getValue())); | ||
fuelBar.setValue(Integer.parseInt(dbe.getValue())); | ||
} | ||
}; | ||
dbegXML.registerDashBoardEventListener("petrol", dbelPetrol); | ||
|
||
// Process the script file - it willgenerate events as it runs | ||
dbegXML.processScriptFile(XML_SCRIPT); | ||
|
||
} catch (Exception ex) { | ||
Logger.getLogger(DashboardDemoMain.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param args - unused | ||
*/ | ||
public static void main(String[] args) { | ||
final DashboardDemoMain me = new DashboardDemoMain(); | ||
} | ||
} |
Oops, something went wrong.