Source code: jpicedt/format/pstricks/parser/PsCircleExpression.java
1 /* jPicEdt version 1.3.2, a picture editor for LaTeX.
2 Copyright (C) 1999-2002 Sylvain Reynal
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 Sylvain Reynal
19 Département de Physique
20 Ecole Nationale Supérieure de l'Electronique et de ses Applications (ENSEA)
21 6, avenue du Ponceau
22 95014 CERGY CEDEX
23 FRANCE
24
25 Tel : 00 +33 130 736 245
26 Fax : 00 +33 130 736 667
27 e-mail : reynal@ensea.fr
28 jPicEdt web page : http://www.jpicedt.org
29 */
30
31 package jpicedt.format.pstricks.parser;
32
33 import jpicedt.graphic.io.parser.*;
34 import jpicedt.graphic.model.*;
35 import jpicedt.graphic.PicPoint;
36
37 /**
38 * Quick circle :<ul>
39 * <li>\\pscircle[parameters](x0,y0)(rad)
40 * <li>\\pscircle*[parameters](x0,y0)(rad)
41 * </ul>
42 * @author $Author: reynal $
43 * @version $Id: PsCircleExpression.java,v 1.2 2002/08/05 16:44:10 reynal Exp $
44 */
45 public class PsCircleExpression extends SequenceExpression implements PicObjectConstants {
46
47 private Pool pool;
48
49 /**
50 * Uses default tag.
51 */
52 public PsCircleExpression(Pool pl){
53 this(pl,null);
54 }
55
56 /**
57 * @param tag if null, default to \\pscircle
58 */
59 public PsCircleExpression(Pool pl, String tag){
60
61 super(true); // throw IncompleteSequence Exception
62 pool = pl;
63 if (tag == null) tag = "\\pscircle";
64
65 add(new PSTInstanciationExpression(tag, new PicEllipse(),pool));
66 add(WHITE_SPACES_OR_EOL);
67 add(new OptionalExpression(new StarExpression(pool)));
68 add(WHITE_SPACES_OR_EOL);
69 // add optional param here
70 add(new OptionalExpression(new EnclosingExpression("[",new PSTParametersExpression(pool,Pool.CURRENT_OBJ_ATTRIBUTES),"]"))); // push in object's attributeSet
71 add(WHITE_SPACES_OR_EOL);
72 // circle's center
73 add(new PSTPicPointExpression(PicEllipse.P_CENTER,pool));
74 add(WHITE_SPACES_OR_EOL);
75 // radius :
76 add(new LiteralExpression("{"));
77 add(WHITE_SPACES_OR_EOL);
78 add(new NumericalExpression(DOUBLE,POSITIVE,"}",true){
79 public void action(ParserEvent e){
80 if (DEBUG) System.out.println(e);
81 ((PicEllipse)(pool.currentObj)).setWidth(((Double)e.getValue()).doubleValue() * 2.0 * pool.getDouble(PstricksParser.KEY_R_UNIT));
82 ((PicEllipse)(pool.currentObj)).setHeight(((Double)e.getValue()).doubleValue() * 2.0 * pool.getDouble(PstricksParser.KEY_R_UNIT));
83 }});
84 }
85 public String toString(){
86 return "[PsCircleExpression]";
87 }
88 }