KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > css > CSS


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.languages.css;
21
22 import org.netbeans.api.languages.ASTNode;
23 import org.netbeans.api.languages.ASTPath;
24 import org.netbeans.api.languages.SyntaxContext;
25 import org.netbeans.api.lexer.Token;
26 import org.netbeans.api.languages.Context;
27 import org.openide.cookies.OpenCookie;
28 import org.openide.filesystems.FileObject;
29 import org.openide.loaders.DataObject;
30 import org.openide.loaders.DataObjectNotFoundException;
31 import org.openide.util.Lookup;
32 import org.openide.windows.TopComponent;
33
34 /**
35  *
36  * @author Jan Jancura
37  */

38 public class CSS {
39
40     public static String JavaDoc tooltip (Context context) {
41         if (!(context instanceof SyntaxContext)) return null;
42         SyntaxContext syntaxContext = (SyntaxContext) context;
43         ASTPath path = syntaxContext.getASTPath ();
44         StringBuilder JavaDoc sb = new StringBuilder JavaDoc ();
45         sb.append ("<html>");
46         sb.append ("<p style=\"");
47         ASTNode ruleset = (ASTNode) path.get (path.size () - 2);
48         ASTNode body = ruleset.getNode ("body");
49         ASTNode declarations = body.getNode ("declarations");
50         if (declarations == null) return null;
51         String JavaDoc s = declarations.getAsText ();
52         s = s.replaceAll ("\"", "");
53         sb.append (s);
54         sb.append ("\">Text Preview.</p>");
55         sb.append ("</html>");
56         return sb.toString ();
57     }
58
59     public static String JavaDoc navigatorTooltip (Context context) {
60         if (!(context instanceof SyntaxContext)) return null;
61         ASTNode n = (ASTNode) ((SyntaxContext) context).getASTPath ().getLeaf ();
62         StringBuilder JavaDoc sb = new StringBuilder JavaDoc ();
63         sb.append ("<html>");
64         sb.append ("<p style=\"");
65         ASTNode body = n.getNode ("body");
66         if (body == null) return null;
67         ASTNode declarations = body.getNode ("declarations");
68         if (declarations == null) return null;
69         String JavaDoc s = declarations.getAsText ();
70         s = s.replaceAll ("\"", "");
71         sb.append (s);
72         sb.append ("\">Text Preview.</p>");
73         sb.append ("</html>");
74         return sb.toString ();
75     }
76     
77     public static Runnable JavaDoc hyperlink (Context context) {
78         Token t = context.getTokenSequence ().token ();
79         String JavaDoc s = t.id ().name ();
80         s = s.substring (1, s.length () - 1);
81         s = s.replace ("%20", " "); // HACK
82
Lookup l = TopComponent.getRegistry ().getActivated ().getLookup ();
83         DataObject dob = (DataObject) l.lookup (DataObject.class);
84         FileObject fo = dob.getPrimaryFile ().getParent ();
85         final FileObject file = fo.getFileObject (s);
86         if (file != null)
87             return new Runnable JavaDoc () {
88                 public void run () {
89                     try {
90                         DataObject d = DataObject.find (file);
91                         OpenCookie oc = (OpenCookie) d.getCookie (OpenCookie.class);
92                         oc.open ();
93                     } catch (DataObjectNotFoundException ex) {
94                     }
95                 }
96             };
97         return null;
98     }
99 }
100
Popular Tags