Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /nyar4psg/trunk/resources/code/ExampleTaglet.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations) (download) (as text)
Tue Jan 6 07:38:11 2015 UTC (9 years, 3 months ago) by nyatla
File MIME type: text/x-java
File size: 7214 byte(s)
パッケージ構成をProcessing2.0向けに更新

1 nyatla 1158 /*
2     * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
3     *
4     * Redistribution and use in source and binary forms, with or
5     * without modification, are permitted provided that the following
6     * conditions are met:
7     *
8     * -Redistributions of source code must retain the above copyright
9     * notice, this list of conditions and the following disclaimer.
10     *
11     * -Redistribution in binary form must reproduce the above copyright
12     * notice, this list of conditions and the following disclaimer in
13     * the documentation and/or other materials provided with the
14     * distribution.
15     *
16     * Neither the name of Sun Microsystems, Inc. or the names of
17     * contributors may be used to endorse or promote products derived
18     * from this software without specific prior written permission.
19     *
20     * This software is provided "AS IS," without a warranty of any
21     * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22     * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23     * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24     * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
25     * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
26     * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
27     * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
28     * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
29     * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
30     * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
31     * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
32     * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33     *
34     * You acknowledge that Software is not designed, licensed or
35     * intended for use in the design, construction, operation or
36     * maintenance of any nuclear facility.
37     */
38    
39     import com.sun.tools.doclets.Taglet;
40     import com.sun.javadoc.*;
41     import java.util.Map;
42     import java.io.*;
43     /**
44     * A sample Taglet representing @example. This tag can be used in any kind of
45     * {@link com.sun.javadoc.Doc}. It is not an inline tag. The text is displayed
46     * in yellow to remind the developer to perform a task. For
47     * example, "@example Hello" would be shown as:
48     * <DL>
49     * <DT>
50     * <B>To Do:</B>
51     * <DD><table cellpadding=2 cellspacing=0><tr><td bgcolor="yellow">Fix this!
52     * </td></tr></table></DD>
53     * </DL>
54     *
55     * @author Jamie Ho
56     * @since 1.4
57     */
58    
59     public class ExampleTaglet implements Taglet {
60    
61     private static final String NAME = "example";
62     private static final String HEADER = "example To Do:";
63    
64     /**
65     * Return the name of this custom tag.
66     */
67     public String getName() {
68     return NAME;
69     }
70    
71     /**
72     * Will return true since <code>@example</code>
73     * can be used in field documentation.
74     * @return true since <code>@example</code>
75     * can be used in field documentation and false
76     * otherwise.
77     */
78     public boolean inField() {
79     return true;
80     }
81    
82     /**
83     * Will return true since <code>@example</code>
84     * can be used in constructor documentation.
85     * @return true since <code>@example</code>
86     * can be used in constructor documentation and false
87     * otherwise.
88     */
89     public boolean inConstructor() {
90     return true;
91     }
92    
93     /**
94     * Will return true since <code>@example</code>
95     * can be used in method documentation.
96     * @return true since <code>@example</code>
97     * can be used in method documentation and false
98     * otherwise.
99     */
100     public boolean inMethod() {
101     return true;
102     }
103    
104     /**
105     * Will return true since <code>@example</code>
106     * can be used in method documentation.
107     * @return true since <code>@example</code>
108     * can be used in overview documentation and false
109     * otherwise.
110     */
111     public boolean inOverview() {
112     return true;
113     }
114    
115     /**
116     * Will return true since <code>@example</code>
117     * can be used in package documentation.
118     * @return true since <code>@example</code>
119     * can be used in package documentation and false
120     * otherwise.
121     */
122     public boolean inPackage() {
123     return true;
124     }
125    
126     /**
127     * Will return true since <code>@example</code>
128     * can be used in type documentation (classes or interfaces).
129     * @return true since <code>@example</code>
130     * can be used in type documentation and false
131     * otherwise.
132     */
133     public boolean inType() {
134     return true;
135     }
136    
137     /**
138     * Will return false since <code>@example</code>
139     * is not an inline tag.
140     * @return false since <code>@example</code>
141     * is not an inline tag.
142     */
143    
144     public boolean isInlineTag() {
145     return false;
146     }
147    
148     /**
149     * Register this Taglet.
150     * @param tagletMap the map to register this tag to.
151     */
152     public static void register(Map tagletMap) {
153     ExampleTaglet tag = new ExampleTaglet();
154     Taglet t = (Taglet) tagletMap.get(tag.getName());
155     if (t != null) {
156     tagletMap.remove(tag.getName());
157     }
158     tagletMap.put(tag.getName(), tag);
159     }
160    
161     /**
162     * Given the <code>Tag</code> representation of this custom
163     * tag, return its string representation.
164     * @param tag the <code>Tag</code> representation of this custom tag.
165     */
166     public String toString(Tag tag) {
167     return createHTML(readFile(tag.text()));
168     }
169    
170    
171     /**
172     * Given an array of <code>Tag</code>s representing this custom
173     * tag, return its string representation.
174     * @param tags the array of <code>Tag</code>s representing of this custom tag.
175     */
176     public String toString(Tag[] tags) {
177     if (tags.length == 0) {
178     return null;
179     }
180     return createHTML(readFile(tags[0].text()));
181     }
182    
183    
184    
185     String createHTML(String theString) {
186     if(theString!=null) {
187     String dd = "<script type=\"text/javascript\">\n" +
188     "<!--\n"+
189     "document.getElementsByTagName('html')[0].className = 'isjs';" +
190     "function toggle(dt) { var display, dd=dt; do{ dd = dd.nextSibling } while(dd.tagName!='DD'); toOpen =!dd.style.display;" +
191     "dd.style.display = toOpen? 'block':''; dt.getElementsByTagName('span')[0].innerHTML = toOpen? '-':'+' ; }\n" +
192     "-->\n</script>";
193    
194     return dd+"\n<div id=\"test\" class=\"toggleList\">" +
195     "<dl><dt onclick=\"toggle(this);\"><span>+</span>Example</dt>" +
196     "<dd><pre>"+theString+"</pre>" +
197     "</dd></dl></div>";
198     }
199     return "";
200     }
201    
202    
203     /**
204     * check if the examples directory exists and return the example as given in the tag.
205     * @param theExample the name of the example
206     */
207     String readFile(String theExample) {
208     String record = "";
209     String myResult = "";
210     int recCount = 0;
211     String myDir = "../examples";
212     File file=new File(myDir);
213     if(file.exists()==false) {
214     myDir = "./examples";
215     }
216     try {
217     FileReader fr = new FileReader(myDir+"/"+theExample+"/"+theExample+".pde");
218     BufferedReader br = new BufferedReader(fr);
219     record = new String();
220     while ((record = br.readLine()) != null) {
221     myResult += record+"\n";
222     }
223     } catch (IOException e) {
224     System.out.println(e);
225     return null;
226     }
227     return myResult;
228     }
229     }
230    
231    

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26