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  /**
32   * Taglet class for block equation style formulas<br>
33   * 
34   * Usage: &#064;latex \sum_i x_i<br>
35   * 
36   * This is an example (see below)
37   * @latex \sum_i x_i
38   * 
39   * @author Stephan Dlugosz
40   */
41  public class LaTeXBlockEquationTaglet extends LaTeXTaglet {
42  	/**
43       * Name of the tag
44       */
45      static String NAME="latex"; //$NON-NLS-1$
46  	
47      /**
48       * Return the name of this custom tag.
49       * @return Name
50       */
51      public String getName() {
52          return NAME;
53      }
54      
55      /**
56       * @see stephan.LaTeXTaglet#isInlineTag()
57       */
58      public boolean isInlineTag() {
59          return false;
60      }
61      
62  	/**
63       * Register this Taglet.
64       * @param tagletMap  the map to register this tag to.
65       */
66  	@SuppressWarnings("unchecked")
67  	public static void register(Map tagletMap) {
68         LaTeXBlockEquationTaglet tag = new LaTeXBlockEquationTaglet();
69         Taglet t = (Taglet) tagletMap.get(tag.getName());
70         if (t != null) {
71             tagletMap.remove(tag.getName());
72         }
73         tagletMap.put(tag.getName(), tag);
74      }
75  	
76      public String toString(Tag tag, Configuration conf) {
77          String name = null;
78  	
79      	name = createPicture(tag,conf,true);
80          
81          return "<DL><B>Formula:</B></DL><DD><img src=\""+name+"\" alt=\""+tag.text()+"\" class=\"math-display\"></DD>";  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
82      }
83  
84      public String toString(Tag[] tags, Configuration conf) {
85          if (tags.length == 0) {
86              return null;
87          }
88          return toString(tags[0], conf);
89      }
90      
91      public TagletOutput getTagletOutput(Tag arg0, TagletWriter arg1) throws IllegalArgumentException {
92          TagletOutput ret = arg1.getOutputInstance();
93          ret.setOutput(toString(arg0, arg1.configuration()));
94          return ret;
95      }
96  
97      public TagletOutput getTagletOutput(Doc arg0, TagletWriter arg1) throws IllegalArgumentException {
98          TagletOutput ret = arg1.getOutputInstance();
99          ret.setOutput(toString(arg0.tags(getName()),arg1.configuration()));
100         return ret;
101     }
102 }