Source code: jpicedt/format/eepic/parser/EepicDrawlineCommand.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.eepic.parser;
32
33 import jpicedt.format.latex.parser.*;
34
35 import jpicedt.graphic.io.parser.*;
36 import jpicedt.graphic.model.*;
37 import jpicedt.graphic.PicPoint;
38
39 /**
40 * Eepic open polygon, possibly dashed :
41 * \\drawline[stretch](x1,y1)...(xN,yN)<p>
42 * This package requires the jpicedt.format.latex package.<p>
43 * [todo] use "stretch" parameter to set dash attribute (not used yet)
44 */
45 public class EepicDrawlineCommand extends SequenceExpression implements ExpressionConstants {
46
47 private Pool pool;
48
49 public EepicDrawlineCommand(Pool pl){
50
51 super(true); // throw IncompleteSequence Exception
52 pool = pl;
53 add(new LaTeXInstanciationExpression("\\drawline", new PicPolygon(),pool));
54 add(WHITE_SPACES_OR_EOL);
55 // [stretch] (though unused at the moment -> normally affects dash value)
56 add(new OptionalExpression(
57 new SequenceExpression(
58 new LiteralExpression("["),
59 new NumericalExpression(INTEGER, ANY_SIGN, "]",true)
60 )));
61 // (x1,y1)...(xN,yN)
62 add(new RepeatExpression(
63 new SequenceExpression(
64 WHITE_SPACES_OR_EOL,
65 new PicPointExpression("(",",",")"){
66 public void action(ParserEvent e){
67 if (DEBUG) System.out.println(e);
68 PicPoint pt = (PicPoint)e.getValue();
69 ((PicPolygon)(pool.currentObj)).addPoint(pt.toMm(pool.getDouble(LaTeXParser.KEY_UNIT_LENGTH)));
70 }
71 }),2, AT_LEAST)
72 );
73 }
74 }