Browse Source

Tidyup of graph XML input/output.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@81 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 20 years ago
parent
commit
ce7d19aab3
  1. 2
      prism/classes/dtds/chartformat.dtd
  2. 11
      prism/src/chart/Makefile
  3. 67
      prism/src/chart/MultiGraphModel.java

2
prism/classes/dtds/chartformat.dtd

@ -8,12 +8,10 @@
Describes the structure of XML files used by PRISM's
chart package.
TODO define vocabulary identification data
PUBLIC ID : -//vendor//vocabulary//EN
SYSTEM ID : http://server/path/chartformat.dtd
-->
<!-- TODO define your own vocabulary/syntax. Example follows: -->
<!ELEMENT chartFormat (layout, axis, axis, (graph)*)>
<!ATTLIST chartFormat

11
prism/src/chart/Makefile

@ -10,16 +10,7 @@
THIS_DIR = chart
PRISM_DIR_REL = ../..
JAVA_FILES = \
ChartColorChooser.java ChartObject.java FourBorders.java GraphListEditor.java GraphList.java GraphOptionsPanel.java GraphPoint.java HorizontalGraphBorder.java MultiGraphModel.java MultiGraphOptions.java MultiGraphView.java NegativeTest.java PrismColorChooserPanel.java PrismFileFilter.java Resizer.java SeriesDataEditor.java SeriesDataRenderer.java SeriesDataSetting.java SeriesList.java VerticalGraphBorder.java
#echo `/bin/ls *.java`
#JAVA_FILES:sh = /bin/ls *.java
#JAVA_FILES = $(wildcard *.java)
JAVA_FILES = $(wildcard *.java)
CLASS_FILES = $(JAVA_FILES:%.java=$(PRISM_DIR_REL)/$(CLASSES_DIR)/$(THIS_DIR)/%.class)
default: all

67
prism/src/chart/MultiGraphModel.java

@ -37,9 +37,7 @@ import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.*;
/*import userinterface.util.*;
import userinterface.GUIPrism;
@ -2664,16 +2662,43 @@ public class MultiGraphModel extends Observable implements SettingOwner, ListMod
// saving methods
public MultiGraphModel load(File f) throws Exception
public MultiGraphModel load(File f) throws ChartException
{
DocumentBuilderFactory factory;
DocumentBuilder builder;
Document doc = null;
// Create XML parser
factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
try {
builder = factory.newDocumentBuilder();
builder.setEntityResolver(this);
builder.setErrorHandler(new ErrorHandler() {
public void fatalError(SAXParseException e) throws SAXException { throw e; }
public void error(SAXParseException e) throws SAXException { throw e; }
public void warning(SAXParseException e) {}
});
}
catch (ParserConfigurationException e) {
throw new ChartException("Couldn't create XML parser");
}
// Parse
try {
doc = builder.parse(f);
}
catch (IOException e) {
throw new ChartException("Couldn't load file \""+f.getPath()+"\"");
}
catch (SAXException e) {
throw new ChartException("Invalid XML file:\n"+ e.getMessage());
}
// Extract graph info from XML
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(this);
Document doc = builder.parse(f);
Element chartFormat = doc.getDocumentElement();
//graph title property
@ -3414,7 +3439,7 @@ public class MultiGraphModel extends Observable implements SettingOwner, ListMod
}
catch(NumberFormatException e)
{
throw new Exception(seriesHeading+" has a seriesColour property with an invalid value which should be a real number.");
throw new ChartException(seriesHeading+" has a seriesColour property with an invalid value which should be a real number.");
}
Color col = new Color(r,g,b);
String seriesShape = graph.getAttribute("seriesShape");
@ -3439,7 +3464,7 @@ public class MultiGraphModel extends Observable implements SettingOwner, ListMod
}
catch(NumberFormatException e)
{
throw new Exception(seriesHeading+" has a lineWidth property with an invalid value which should be a real number.");
throw new ChartException(seriesHeading+" has a lineWidth property with an invalid value which should be a real number.");
}
gl.setLineWidth(width);
String lineStyle = graph.getAttribute("lineStyle");
@ -3452,7 +3477,7 @@ public class MultiGraphModel extends Observable implements SettingOwner, ListMod
catch(SettingException e)
{
//Shouldn't ever happen
throw new Exception("An unexpected exception has occured when setting lineStyle of "+seriesHeading);
throw new ChartException("An unexpected exception has occured when setting lineStyle of "+seriesHeading);
}
@ -3479,13 +3504,13 @@ public class MultiGraphModel extends Observable implements SettingOwner, ListMod
notifyObservers();
return this;
}
catch(Exception e)
catch (SettingException e)
{
throw new Exception("Error in loading chart: "+e);
throw new ChartException(e.getMessage());
}
}
public void save(File f) throws Exception
public void save(File f) throws ChartException
{
try
{
@ -3689,23 +3714,23 @@ public class MultiGraphModel extends Observable implements SettingOwner, ListMod
catch(DOMException e)
{
throw new Exception("Problem saving graph: DOM Exception: "+e);
throw new ChartException("Problem saving graph: DOM Exception: "+e);
}
catch(ParserConfigurationException e)
{
throw new Exception("Problem saving graph: Parser Exception: "+e);
throw new ChartException("Problem saving graph: Parser Exception: "+e);
}
catch(TransformerConfigurationException e)
{
throw new Exception("Problem saving graph: Error in creating XML: "+e);
throw new ChartException("Problem saving graph: Error in creating XML: "+e);
}
catch(FileNotFoundException e)
{
throw new Exception("Problem saving graph: File Not Found: "+e);
throw new ChartException("Problem saving graph: File Not Found: "+e);
}
catch(TransformerException e)
{
throw new Exception("Problem saving graph: Transformer Exception: "+e);
throw new ChartException("Problem saving graph: Transformer Exception: "+e);
}
}

Loading…
Cancel
Save