Exemple #1
0
  public void restoreState(Element rootElement) {
    List children = PrimitiveXMLEncodeDecode.getChildElements(rootElement);
    int size = children.size();

    Element element = null;
    String name = null;
    AstFigureProps props = null;
    DrawFigure figure = null;
    Mapping oldMapping = null;
    Mapping newMapping = (Mapping) plotSource.getPlot();

    for (int i = 0; i < size; i++) {
      props = new AstFigureProps();
      element = (Element) children.get(i);
      name = PrimitiveXMLEncodeDecode.getElementName(element);
      if (PLOT_TAG.equals(name)) {
        oldMapping = restorePlot(element);
      }
      if (props.getTagName().equals(name)) {
        props.decode(element, oldMapping, newMapping);
        figure = figureFactory.create(props);
        drawActions.addDrawFigure(figure);
        figure.repaint();
      }
    }
  }
Exemple #2
0
  protected Plot restorePlot(Element rootElement) {
    if (astReader == null) {
      astReader = new XAstReader();
    }
    List children = PrimitiveXMLEncodeDecode.getChildElements(rootElement);
    Element plotElement = (Element) children.get(0);

    try {
      return (Plot) astReader.makeAst(plotElement);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Exemple #3
0
 protected void savePlot(Element rootElement) {
   if (plotSource != null) {
     Plot plot = plotSource.getPlot();
     if (plot != null) {
       if (astWriter == null) {
         astWriter = new XAstWriter();
       }
       Element plotElement = PrimitiveXMLEncodeDecode.addChildElement(rootElement, PLOT_TAG);
       plotElement.setAttribute("encoding", "AST-XML");
       Result result = new DOMResult(plotElement);
       Source source = astWriter.makeSource(plot);
       Transformer trans = new SourceReader().getTransformer();
       try {
         trans.transform(source, result);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }