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

Quick Search    Search Deep

Source code: jpicedt/format/pstricks/PicPolygonFormatter.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;
32  
33  import jpicedt.graphic.io.formatter.*;
34  import jpicedt.graphic.*;
35  import jpicedt.graphic.model.*;
36  
37  import java.awt.*;
38  
39  /**
40   * Pstricks formatter for PicPolygon objects.
41   * @author $Author: reynal $
42   * @version $Id: PicPolygonFormatter.java,v 1.3 2002/08/05 16:44:10 reynal Exp $ 
43   */
44  public class PicPolygonFormatter implements Formatter, PicObjectConstants, PstricksConstants {
45  
46    /** the Element this formatter acts upon */
47    private PicPolygon obj;
48    private PstricksFormatter factory;
49  
50    /**
51     *
52     */
53    public PicPolygonFormatter(PicPolygon obj, PstricksFormatter factory){
54      this.obj = obj;
55      this.factory=factory;
56    }
57  
58    /**
59     * @return a String representing this Element in the PsTricks 
60     */
61    public String format(){
62  
63      StringBuffer buf = new StringBuffer(100); // 100 as initial capacity seems to be a good guess
64  
65      // first handle possibly user-defined colours
66      PstricksFormatter.ParameterString paramStr = factory.createParameterString(obj);
67      if (paramStr.isDefinedColourString()) buf.append(paramStr.getUserDefinedColourBuffer());
68  
69      if (obj.getAttribute(POLYGON_STYLE)==POLYGON_DOTS) buf.append("\\psdots");
70      else if (obj.isClosed() && obj.getLastPointIndex()>1) buf.append("\\pspolygon"); // 3 points min.
71      else buf.append("\\psline");
72      // parameters
73      buf.append("[");
74      buf.append(paramStr.getParameterBuffer());
75      buf.append("]");
76      // arrows if NOT dots !
77      if (obj.getAttribute(POLYGON_STYLE)!=POLYGON_DOTS){
78        if (!obj.isClosed() || obj.getLastPointIndex()<=1) 
79          buf.append(PstricksUtilities.createPstricksStringFromArrows(obj));
80      }
81      // points
82      for (int i=obj.getFirstPointIndex(); i<=obj.getLastPointIndex(); i++){
83        buf.append(obj.getPoint(i,null));
84      }
85      buf.append(CR_LF);
86      return buf.toString();
87    }
88  
89  } // class PicPolygonLatexFormatter