View Javadoc

1   /*
2    * Copyright (C) Stephan Dlugosz, 2007. All Rights Reserved.
3    *
4    * LaTeXTaglet is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser Public License as published by
6    * the Free Software Foundation; either version 2.1 of the License, or
7    * (at your option) any later version.
8    *
9    * LaTeXTaglet 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 Lesser Public License for more details.
13   * 
14   * You should have received a copy of the GNU Lesser Public License
15   * along with LaTeXTaglet; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   */
18  
19  package net.sf.latextaglet;
20  import java.util.Map;
21  
22  import net.sf.latextaglet.internal.LaTeXTaglet;
23  
24  import com.sun.javadoc.Doc;
25  import com.sun.javadoc.Tag;
26  import com.sun.tools.doclets.Taglet;
27  import com.sun.tools.doclets.internal.toolkit.Configuration;
28  import com.sun.tools.doclets.internal.toolkit.taglets.TagletOutput;
29  import com.sun.tools.doclets.internal.toolkit.taglets.TagletWriter;
30  
31  /**getTagletOutput
32   * Taglet class for equation style formulas<br>
33   * 
34   * Usage: {&#064;latex[ \sum_i x_i }<br>
35   * 
36   * Example: {@latex[ \sum_i x_i }
37   * 
38   * @author Stephan Dlugosz
39   */
40  public class LaTeXEquationTaglet extends LaTeXTaglet {
41  	/**
42       * 
43       */
44      static String NAME="latex["; //$NON-NLS-1$
45  	
46      /**
47       * Return the name of this custom tag.
48       * @return Name
49       */
50      public String getName() {
51          return NAME;
52      }
53      
54      /**
55       * @see stephan.LaTeXTaglet#isInlineTag()
56       */
57      public boolean isInlineTag() {
58          return true;
59      }
60  
61  	/**
62       * Register this Taglet.
63       * @param tagletMap  the map to register this tag to.
64       */
65  	@SuppressWarnings("unchecked")
66  	public static void register(Map tagletMap) {
67         LaTeXEquationTaglet tag = new LaTeXEquationTaglet();
68         Taglet t = (Taglet) tagletMap.get(tag.getName());
69         if (t != null) {
70             tagletMap.remove(tag.getName());
71         }
72         tagletMap.put(tag.getName(), tag);
73      }
74  	
75      public String toString(Tag tag, Configuration conf) {
76          String name = null;
77  	
78      	name = createPicture(tag,conf, true);
79  
80          return "<DD><img src=\""+name+"\" alt=\""+tag.text()+"\" class=\"math-display\"></DD>";  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
81      }
82      
83      public String toString(Tag[] tags, Configuration conf) {
84          if (tags.length == 0) {
85              return null;
86          }
87          return toString(tags[0], conf);
88      }
89      
90      public TagletOutput getTagletOutput(Tag arg0, TagletWriter arg1) throws IllegalArgumentException {
91          TagletOutput ret = arg1.getOutputInstance();
92          ret.setOutput(toString(arg0, arg1.configuration()));
93          return ret;
94      }
95  
96      public TagletOutput getTagletOutput(Doc arg0, TagletWriter arg1) throws IllegalArgumentException {
97          TagletOutput ret = arg1.getOutputInstance();
98          ret.setOutput(toString(arg0.tags(getName()),arg1.configuration()));
99          return ret;
100     }
101 }