|
From: <rga...@us...> - 2002-10-18 14:56:48
|
Update of /cvsroot/csms/csms-core/src/java/org/fanfoot/gui
In directory usw-pr-cvs1:/tmp/cvs-serv10082/java/org/fanfoot/gui
Added Files:
ControlCentre.form ControlCentre.java
Log Message:
Initial auto scoring application import
--- NEW FILE: ControlCentre.form ---
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Menu class="javax.swing.JMenuBar" name="mnubarMain">
<SubComponents>
<Menu class="javax.swing.JMenu" name="mnuFile">
<Properties>
<Property name="mnemonic" type="int" value="70"/>
<Property name="text" type="java.lang.String" value="File"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="mnuItemParseFile">
<Properties>
<Property name="mnemonic" type="int" value="70"/>
<Property name="text" type="java.lang.String" value="Parse File"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mnuItemParseFileActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="mnuitemParseURL">
<Properties>
<Property name="text" type="java.lang.String" value="Parse URL"/>
<Property name="toolTipText" type="java.lang.String" value="Load an URL and parse scores from it"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mnuitemParseURLActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="mnuConfig">
<Properties>
<Property name="mnemonic" type="int" value="67"/>
<Property name="text" type="java.lang.String" value="Configuration"/>
<Property name="toolTipText" type="java.lang.String" value="Configure the score calculator"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="setPaths">
<Properties>
<Property name="mnemonic" type="int" value="80"/>
<Property name="text" type="java.lang.String" value="Paths"/>
<Property name="toolTipText" type="java.lang.String" value="Set the paths to configuration files"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="setPathsActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="mnuDebug">
<Properties>
<Property name="mnemonic" type="int" value="68"/>
<Property name="text" type="java.lang.String" value="Debug"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="parseBBCTExt1">
<Properties>
<Property name="mnemonic" type="int" value="49"/>
<Property name="text" type="java.lang.String" value="Parse BBC Test 1"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="parseBBCTExt1ActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents>
</Menu>
</NonVisualComponents>
<Properties>
<Property name="title" type="java.lang.String" value="FanFoot Control Centre"/>
<Property name="maximizedBounds" type="java.awt.Rectangle" editor="org.netbeans.beaninfo.editors.RectangleEditor">
<Rectangle value="[0, 0, 800, 800]"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="mnubarMain"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitForm"/>
</Events>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<SubComponents>
<Container class="javax.swing.JTabbedPane" name="tabpneEvents">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[800, 800]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="North"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
</Container>
</SubComponents>
</Form>
--- NEW FILE: ControlCentre.java ---
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Community Sports Management System.
*
* The Initial Developer of the Original Code is
* We know What you Want.net
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Ross Gardler <ross [at] saafe.org>
* Mike Lever <mikel [at] fanfoot.com>
* Stuart Gardler <stuart [at] wkwyw.net>
*
* ***** END LICENSE BLOCK ***** */
/*
* controlCentre.java
*
* Created on 22 September 2002, 11:10
*/
package org.fanfoot.gui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.EventObject;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.xml.parsers.ParserConfigurationException;
import org.fanfoot.scoring.Event;
import org.fanfoot.scoring.EventParser;
import org.fanfoot.scoring.EventParserConfigurationException;
import org.fanfoot.scoring.EventParserListener;
import org.fanfoot.scoring.Events;
import org.fanfoot.scoring.Scores;
import org.fanfoot.scoring.ScoringConfiguration;
import org.fanfoot.scoring.ScoringConfigurationException;
import org.saafe.ui.gui.dialog.getURL;
import org.saafe.ui.gui.prefs.PreferencesEditor;
import org.saafe.utils.XMLUtils;
import org.w3c.dom.Document;
/**
*
* @author rgardler
*/
public class ControlCentre extends JFrame implements EventParserListener {
//Create a file chooser
final JFileChooser fc = new JFileChooser();
//FIXME: all these default config strings should be load into the prefs object
final String strDefaultEventConfigFile = "http://www.fanfoot.com/test/footballEvents.xml";
final String strDefaultScoringConfigFile = "http://www.fanfoot.com/test/BBCScoringConfig.xsl";
final String strDefaultScores2HTMLXSLFile = "http://www.fanfoot.com/test/Scores2HTML.xsl";
final String[] strDefaultURLs = {
"",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/a/arsenal/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/a/aston_villa/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/b/birmingham_city/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/b/blackburn_rovers/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/b/bolton_wanderers/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/c/charlton_athletic/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/c/chelsea/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/e/everton/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/f/fulham/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/l/leeds_united/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/l/liverpool/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/m/man_city/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/m/man_utd/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/m/middlesbrough/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/n/newcastle_united/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/s/southampton/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/s/sunderland/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/t/tottenham_hotspur/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/w/west_bromwich_albion/live_hi.stm",
"http://news.bbc.co.uk/sport/hi/english/static/football/statistics/teams/w/west_ham_utd/live_hi.stm"
};
final Logger logger = Logger.getLogger("org.fanfoot.gui");
protected String strBBCType = "BBC Text Commentary";
private Preferences prefs;;
private EventParser eventParser;
ScoringConfiguration scoringConfig;
Scores scores;
/** Creates new form controlCentre using the default configuration file.
* @throws FileNotFoundException if the default configuration file cannot be found
* @throws IOException if there is a problem reading the properties file
*/
public ControlCentre() throws FileNotFoundException, IOException {
initEventParser();
initComponents();
prefs = Preferences.userNodeForPackage(ControlCentre.class);
if (prefs.get("debug", "true").toLowerCase().equals("true")) {
mnuDebug.setVisible(true);
} else {
mnuDebug.setVisible(false);
}
scoringConfig = new ScoringConfiguration(prefs.get("ScoringConfigurationFile", strDefaultScoringConfigFile));
}
/** Initialise the EventParser object.
*/
private void initEventParser() {
eventParser = new EventParser();
eventParser.addListener(this);
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
tabpneEvents = new javax.swing.JTabbedPane();
mnubarMain = new javax.swing.JMenuBar();
mnuFile = new javax.swing.JMenu();
mnuItemParseFile = new javax.swing.JMenuItem();
mnuitemParseURL = new javax.swing.JMenuItem();
mnuConfig = new javax.swing.JMenu();
setPaths = new javax.swing.JMenuItem();
mnuDebug = new javax.swing.JMenu();
parseBBCTExt1 = new javax.swing.JMenuItem();
setTitle("FanFoot Control Centre");
setMaximizedBounds(new java.awt.Rectangle(0, 0, 800, 800));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
tabpneEvents.setMaximumSize(new java.awt.Dimension(800, 800));
getContentPane().add(tabpneEvents, java.awt.BorderLayout.NORTH);
mnuFile.setMnemonic('F');
mnuFile.setText("File");
mnuItemParseFile.setMnemonic('F');
mnuItemParseFile.setText("Parse File");
mnuItemParseFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuItemParseFileActionPerformed(evt);
}
});
mnuFile.add(mnuItemParseFile);
mnuitemParseURL.setText("Parse URL");
mnuitemParseURL.setToolTipText("Load an URL and parse scores from it");
mnuitemParseURL.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuitemParseURLActionPerformed(evt);
}
});
mnuFile.add(mnuitemParseURL);
mnubarMain.add(mnuFile);
mnuConfig.setMnemonic('C');
mnuConfig.setText("Configuration");
mnuConfig.setToolTipText("Configure the score calculator");
setPaths.setMnemonic('P');
setPaths.setText("Paths");
setPaths.setToolTipText("Set the paths to configuration files");
setPaths.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
setPathsActionPerformed(evt);
}
});
mnuConfig.add(setPaths);
mnubarMain.add(mnuConfig);
mnuDebug.setMnemonic('D');
mnuDebug.setText("Debug");
parseBBCTExt1.setMnemonic('1');
parseBBCTExt1.setText("Parse BBC Test 1");
parseBBCTExt1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
parseBBCTExt1ActionPerformed(evt);
}
});
mnuDebug.add(parseBBCTExt1);
mnubarMain.add(mnuDebug);
setJMenuBar(mnubarMain);
pack();
}//GEN-END:initComponents
private void mnuitemParseURLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuitemParseURLActionPerformed
getURL dialog = new getURL(this, true, strDefaultURLs);
URL url = dialog.getURL();
generateScores(url);
}//GEN-LAST:event_mnuitemParseURLActionPerformed
private void setPathsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setPathsActionPerformed
try {
PreferencesEditor dlgPrefsEditor = new PreferencesEditor(this, true, prefs);
dlgPrefsEditor.show();
} catch (BackingStoreException bse) {
// FIXME: Inform user of this problem
logger.log(Level.SEVERE, "Unable to create Preferences Editor", bse);
}
}//GEN-LAST:event_setPathsActionPerformed
private void parseBBCTExt1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parseBBCTExt1ActionPerformed
URL url = null;
try {
url = new URL("http://www.fanfoot.com/test/testCommentary_BBC_1.html");
} catch (Exception e) {
}
generateScores(url);
}//GEN-LAST:event_parseBBCTExt1ActionPerformed
private void mnuItemParseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemParseFileActionPerformed
//FIXME detect the type from the file, or have user specify it
String strType = strBBCType;
Events evts; // the events parsed from the file
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
logger.finest("Parsing: " + file.getName() + " of type " + strType +".\n");
try {
eventParser.loadConfiguration(prefs.get("EventConfigurationFile", strDefaultEventConfigFile));
} catch (EventParserConfigurationException epc) {
logger.severe("Cannot load parser config file");
// FIXME Tell the user of this error
}
try {
generateScores(file.toURL());
} catch (java.net.MalformedURLException mue) {
logger.warning("File path does not translate to a valid URL");
// FIXME: Warn the user of this error
}
} else {
logger.finest("Parse command cancelled by user.\n");
}
}//GEN-LAST:event_mnuItemParseFileActionPerformed
/**
* Gerenate the scores from the supplied url using the current configuration.
* Scores are displayed in the GUI.
* @param url the url to load
*/
private void generateScores(URL url) {
Events evts; // the events parsed from the file
// FIXME: currently we download the URL twice, once to display in the Browser and once in the EventParser
org.saafe.utils.BrowserControl.displayURL(url);
try {
eventParser.loadConfiguration(strDefaultEventConfigFile);
logger.info("Loaded Event Config file: " + strDefaultEventConfigFile);
} catch (EventParserConfigurationException epc) {
logger.severe("Cannot load parser config file");
// FIXME Tell the user of this error
}
try {
//FIXME the type of file should be user selectable
evts = eventParser.parse(url, strBBCType);
logger.info("Parsed events from file at: " + url.toString());
populateEventTables(evts);
} catch (IOException io) {
logger.log(Level.SEVERE, "Cannot configure event parser", io);
// FIXME Tell the user of this error
} catch (EventParserConfigurationException epce) {
logger.log(Level.SEVERE, "Cannot configure event parser", epce);
// FIXME Tell the user of this error
}
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
new ControlCentre().show();
} catch (Exception e) {
System.out.println("Unable to load configuration file.");
e.printStackTrace();
}
}
/** Creates an events table for each of the event types
* and adds it to the tabbed pane displaying events.
*@param evts the events to display
*/
private void populateEventTables(Events evts) {
Enumeration evtTypes = evts.getTypes(); // all types of events
String strType; // type of events currently being processed
ArrayList typeEvts; // all events of a certain type
Event evt; // event currently being processed
Enumeration enuPartNames; // part names of current event
Vector columnNames; // table column names
Vector row; // current table row
Vector evtRows; // table rows for a specific event
String strPartName; // name of the part being processed
DefaultTableModel data; // data model for the events table
JTable jtable; // the table of events
JScrollPane scrPane;// the scroll pane for the table
logger.entering("org.fanfoot.gui", "populateEventTables(evts)");
tabpneEvents.removeAll();
javax.swing.JEditorPane htmlEditorPane = new javax.swing.JEditorPane();
htmlEditorPane.setContentType("text/html");
tabpneEvents.add("Summary", htmlEditorPane);
try {
org.saafe.ui.gui.xml.XMLTreePanel xmlTree = new org.saafe.ui.gui.xml.XMLTreePanel();
xmlTree.setDocument(evts.toXMLDoc());
scrPane = new JScrollPane();
scrPane.setViewportView(xmlTree);
tabpneEvents.add("Events", scrPane);
} catch (ParserConfigurationException pce) {
// FIXME Tell the user of this error
logger.log(Level.SEVERE, "XML Parser configuration error", pce);
}
try {
scores = new Scores(evts, scoringConfig);
} catch (ScoringConfigurationException sce) {
logger.log(Level.WARNING, "Unable to calculate scores", sce);
}
org.saafe.ui.gui.xml.XMLTreePanel xmlTree = new org.saafe.ui.gui.xml.XMLTreePanel();
xmlTree.setDocument(scores.getScoresDocument());
scrPane = new JScrollPane();
scrPane.setViewportView(xmlTree);
tabpneEvents.add("Scores", scrPane);
Document docScores2HTML = null;
try {
docScores2HTML = XMLUtils.parseXML(prefs.get("Scores2HTMLStylsheet", strDefaultScores2HTMLXSLFile));
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to load XSL to convert scores doc to HTML.", e);
htmlEditorPane.setText("<h2>Error Parsing Scores</h2><p>" + e + "</p>");
}
try {
Document htmlScores = XMLUtils.transform(scores.getScoresDocument(), docScores2HTML);
String strHTML = XMLUtils.xmlToString(htmlScores);
logger.finest("HTML representation of scores is " + strHTML);
htmlEditorPane.setText(strHTML);
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to convert scores document to HTML.", e);
htmlEditorPane.setText("<h2>Error Parsing Scores</h2><p>" + e + "</p>");
}
logger.finest("Event Types = " + evtTypes.toString());
while (evtTypes.hasMoreElements()) {
strType = (String)evtTypes.nextElement();
typeEvts = evts.getEventsByType(strType);
columnNames = new Vector();
evtRows = new Vector();
logger.finest("Processing events of type " + strType);
for (int i = 0; i < typeEvts.size(); i ++) {
evt = (Event)typeEvts.get(i);
row = new Vector();
enuPartNames = evt.getPartNames();
while (enuPartNames.hasMoreElements()) {
strPartName = (String)enuPartNames.nextElement();
if (! columnNames.contains(strPartName)) {
columnNames.add(strPartName);
logger.finest("Added column name " + strPartName);
}
row.add(evt.getPart(strPartName));
logger.finest("Added column data " + evt.getPart(strPartName));
}
evtRows.add(row);
}
data = new DefaultTableModel(evtRows, columnNames);
jtable = new JTable(data);
scrPane = new JScrollPane();
scrPane.setViewportView(jtable);
tabpneEvents.addTab(strType, null, scrPane, "Display events of type " + strType);
}
this.pack();
logger.exiting("org.fanfoot.gui", "populateEventTables(evts)");
}
/** Loaded Commentay file.
*
*/
public void retrievedCommentary(EventObject e) {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenu mnuDebug;
private javax.swing.JMenuBar mnubarMain;
private javax.swing.JMenuItem parseBBCTExt1;
private javax.swing.JMenuItem setPaths;
private javax.swing.JTabbedPane tabpneEvents;
private javax.swing.JMenuItem mnuItemParseFile;
private javax.swing.JMenuItem mnuitemParseURL;
private javax.swing.JMenu mnuConfig;
private javax.swing.JMenu mnuFile;
// End of variables declaration//GEN-END:variables
}
|