Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jpicedt/format/pstricks/parser/PSTInstanciationExpression.java


1   /*
2    PSTInstanciationExpression.java - March 29, 2002 - jPicEdt 1.3.2, a picture editor for LaTeX.
3    Copyright (C) 1999-2002 Sylvain Reynal
4   
5    Département de Physique
6    Ecole Nationale Supérieure de l'Electronique et de ses Applications (ENSEA)
7    6, avenue du Ponceau
8    F-95014 CERGY CEDEX
9   
10   Tel : +33 130 736 245
11   Fax : +33 130 736 667
12   e-mail : reynal@ensea.fr
13   jPicEdt web page : http://www.jpicedt.org
14    
15   This program is free software; you can redistribute it and/or
16   modify it under the terms of the GNU General Public License
17   as published by the Free Software Foundation; either version 2
18   of the License, or any later version.
19    
20   This program is distributed in the hope that it will be useful,
21   but WITHOUT ANY WARRANTY; without even the implied warranty of
22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   GNU General Public License for more details.
24    
25   You should have received a copy of the GNU General Public License
26   along with this program; if not, write to the Free Software
27   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28   */
29  
30  package jpicedt.format.pstricks.parser;
31  
32  import jpicedt.graphic.model.*;
33  import jpicedt.graphic.io.parser.*;
34  
35  import java.util.*;
36  import java.io.*;
37  
38  /**
39   * Instanciates a new Element by cloning the given object, when the given tag gets found.
40   * Then adds it to the current PicGroup in the Pool.
41   * @author $Author: reynal $
42   * @version $Id: PSTInstanciationExpression.java,v 1.2 2002/08/05 16:44:10 reynal Exp $ 
43   */
44  public class PSTInstanciationExpression extends LiteralExpression  implements ExpressionConstants {
45  
46    private Element prototype;
47    private Pool pool;
48    private String tag;
49    private PSTParametersExpression paramExp;
50  
51    /**
52     * @param tag expression to be matched
53     * @param prototype element to be instanciated by cloning
54     * @param pl pool where to add the instanciated element ; also used to fetch the current attribute set for PsTricks
55     */
56    public PSTInstanciationExpression(String tag, Element prototype,Pool pl){
57  
58      super(tag);
59      this.tag = tag;
60      this.prototype = prototype;
61      this.pool = pl;
62      paramExp = new PSTParametersExpression(this.pool, Pool.CURRENT_OBJ_ATTRIBUTES);
63    }
64  
65    public void action(ParserEvent e) throws ParserException {
66  
67      if (DEBUG) System.out.println(e);
68      pool.currentObj = (Element)prototype.clone();
69      pool.currentObj.setAttributeSet(pool.getAttributeSet(PstricksParser.KEY_ATTRIBUTES));
70      pool.currentGroup.addChild(pool.currentObj);
71      // possibly retrieve a parameter string associated with the tag, if it's been previously set by 
72      // PsObjectExpression :
73      HashMap map = (HashMap)pool.get(PstricksParser.KEY_NEWPSOBJECTS); 
74      String paramStr = (String)map.get(tag);
75      if (paramStr != null){ // ok, there exists such a tag, previously set by a \\newpsobject command
76        try {
77          Context tmpContext = new Context(new StringReader(paramStr));
78          paramExp.interpret(tmpContext); // set attributes for currentObj
79        } catch (ParserException.EOF ex){}
80      }
81      
82    }
83  
84    public String toString(){
85  
86      return "[PSTInstanciationExpression:tag="+tag+" prototype="+prototype.getClass().getName()+"]";
87    }
88  }
89