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

Quick Search    Search Deep

Source code: jpicedt/graphic/io/parser/pstricks/PSTParametersExpression.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.graphic.io.parser.pstricks;
32  
33  import jpicedt.graphic.io.parser.*;
34  import jpicedt.graphic.io.formatter.*;
35  import jpicedt.graphic.model.*;
36  import java.awt.*;
37  
38  /**
39   * PsTricks graphics parameters, e.g. :
40   * - either "[linewidth=5pt, fillcolor=blue,...]" associated with an object command (\\psline...) 
41   * - or the same thing w/o opening and closing brackets, and in this case it's a register command (e.g. \\psset{...})
42   *
43   * Currently supported parameters :
44   * - xunit, yunit, runit, unit
45   * - linestyle=xxx
46   * - linewidth=xxx (with unit) + dash'n dot parameters
47   * - linecolor=xxx (may be a native PsTrick colour, see predefined colours in PsTricksFormater, OR a user-defined colours)
48   * - fillstyle=xxx 
49   * - fillcolor=xxx (same note as for linecolor)
50   * - shadow parameters
51   * - hatch parameters.
52   *
53   * If pushInObject is TRUE, these parameters always act on the current Element, seeing that they always appear as an argument of a PsTricks 
54   * instanciation command (e.g. \\psline[linewidth=5pt]...). If a parameter is missing, we use the default value in the pool 
55   * (this is either a PsTricks default value, or a value set by a previous \\psset command), as a LaTeX compiler would do anyway. 
56   * Actually, it's the instanciation expression *itself* which sets  these default values, and the PSTParametersExpression 
57   * simply overrides them with the "local" values if they're found.
58   *
59   * If pushInObject is FALSE, these parameters get pushed in the parser's pool and will serve as default parameter for instanciation expressions.
60   *
61   */
62  public class PSTParametersExpression extends SequenceExpression implements PicObjectConstants {
63  
64  
65    /**
66     * @param pool parser's pool
67     * @param pushInPool if TRUE, parameters get pushed into the pool, otherwise into the current object
68     */
69    public PSTParametersExpression(LaTeXParser.Pool pool, boolean pushInPool){
70  
71      super(false); // doesn't throw IncompleteSequenceException (which means that there might be nothing b/w [ and ])
72  
73      // opening bracket
74      if (pushInPool) add(new LiteralExpression("\\psset{"));
75      else add(new LiteralExpression("["));
76  
77      // an alternate list of every possible parameters that gets repeated until there are no more parameters to be parsed !
78      AlternateExpression altParms = new AlternateExpression();
79  
80      // ******************************************************************
81      // **************** UNIT LENGTH *******************************
82      // ******************************************************************
83      altParms.add(new PsUnitLengthExpression(pool,PsUnitLengthExpression.XUNIT)); // always push in pool !
84      altParms.add(new PsUnitLengthExpression(pool,PsUnitLengthExpression.YUNIT)); // always push in pool !
85      altParms.add(new PsUnitLengthExpression(pool,PsUnitLengthExpression.RUNIT)); // always push in pool !
86      altParms.add(new PsUnitLengthExpression(pool,PsUnitLengthExpression.UNIT)); // always push in pool !
87      
88      // ******************************************************************
89      // **************** STROKE properties *******************************
90      // ******************************************************************
91  
92      // =============== LINEWIDTH ===========================================
93      // ex : linewidth=13mm or linewidth=5.6 (default to current
94      altParms.add(new PSTLengthParameter(pool, "linewidth", LINE_WIDTH, pushInPool));
95  
96      // ============= LINECOLOR ==============================================
97      // ex : linecolor=green (native) or linecolor=mygray2 (user-defined)
98      altParms.add(new PSTColorExpression(pool, "linecolor", LINE_COLOR, pushInPool));
99  
100     // ============ LINESTYLE ===================================================
101     altParms.add(new PSTLineStyleExpression(pool, pushInPool));
102 
103     // ============= DASH ==============================================
104     altParms.add(new PSTDashExpression(pool, pushInPool));
105 
106     // =============== DOTSEP ===========================================
107     altParms.add(new PSTLengthParameter(pool, "dotsep", DOT_SEP, pushInPool));
108 
109     // ============= DOUBLELINE (true/false) ==============================================
110     altParms.add(new PSTBooleanExpression(pool, "doubleline=", DOUBLE_LINE, pushInPool));
111 
112     // =============== DOUBLESEP ===========================================
113     altParms.add(new PSTLengthParameter(pool, "doublesep", DOUBLE_SEP, pushInPool));
114 
115     // ============= DOUBLECOLOR ==============================================
116     altParms.add(new PSTColorExpression(pool, "doublecolor", DOUBLE_COLOR, pushInPool));
117 
118     // ******************************************************************
119     // **************** FILL properties *******************************
120     // ******************************************************************
121 
122     // ============ FILLSTYLE ===================================================
123     altParms.add(new PSTFillStyleExpression(pool, pushInPool));
124 
125     // ============= FILLCOLOR ==============================================
126     altParms.add(new PSTColorExpression(pool, "fillcolor", FILL_COLOR, pushInPool));
127 
128     // =============== HATCHWIDTH ===========================================
129     altParms.add(new PSTLengthParameter(pool, "hatchwidth", HATCH_WIDTH, pushInPool));
130 
131     // =============== HATCHSEP ===========================================
132     altParms.add(new PSTLengthParameter(pool, "hatchsep", HATCH_SEP, pushInPool));
133 
134     // ============= HATCHCOLOR ==============================================
135     altParms.add(new PSTColorExpression(pool, "hatchcolor", HATCH_COLOR, pushInPool));
136 
137     // ============= HATCHANGLE ==============================================
138     altParms.add(new PSTAngleParameter(pool, "hatchangle", HATCH_ANGLE, pushInPool));
139 
140 
141     // ******************************************************************
142     // **************** SHADOW properties *******************************
143     // ******************************************************************
144 
145     // ============= SHADOW (true/false) ==============================================
146     altParms.add(new PSTBooleanExpression(pool, "shadow=", SHADOW, pushInPool));
147 
148     // ============= SHADOWANGLE ==============================================
149     altParms.add(new PSTAngleParameter(pool, "shadowangle", SHADOW_ANGLE, pushInPool));
150 
151     // =============== SHADOWSIZE ===========================================
152     altParms.add(new PSTLengthParameter(pool, "shadowsize", SHADOW_SIZE, pushInPool));
153 
154     // ============= SHADOWCOLOR ==============================================
155     altParms.add(new PSTColorExpression(pool, "shadowcolor", SHADOW_COLOR, pushInPool));
156 
157 
158 
159 
160 
161     // [pending] =========== NOT PARSABLE PARAMETERS (either not implemented yet, or not syntaxically correct)
162     // Note : non-implemented parameters are, so far : "dimen", "border" and related, "origin" and "swapaxes"
163     // altParms.add(new WordExpression(",",true)) <- doesn't work if this is the last parameter (i.e. followed by a closing bracket) !
164 
165 
166 
167     // ================================================================
168     // build pattern to be repeated
169     SequenceExpression repeatPattern = new SequenceExpression(false);
170     repeatPattern.add(new WhiteSpaces());
171     repeatPattern.add(altParms);
172     repeatPattern.add(new WhiteSpaces());
173     repeatPattern.add(new OptionalExpression(new LiteralExpression(",")));
174     // repeat as many times as possible
175     add(new RepeatExpression(repeatPattern, 0, AT_LEAST));
176     // closing bracket
177     if (pushInPool) add(new LiteralExpression("}"));
178     else add(new LiteralExpression("]"));
179   }
180 }