1+ /*
2+ * Copyright (c) 2008-2019 Emmanuel Dupuy.
3+ * This project is distributed under the GPLv3 license.
4+ * This is a Copyleft license that gives the user the right to use,
5+ * copy and modify the code freely for non-commercial purposes.
6+ */
7+ package org .jd .gui .service .treenode ;
8+
9+ import org .fife .ui .rsyntaxtextarea .SyntaxConstants ;
10+ import org .jd .gui .api .API ;
11+ import org .jd .gui .api .feature .ContainerEntryGettable ;
12+ import org .jd .gui .api .feature .UriGettable ;
13+ import org .jd .gui .api .model .Container ;
14+ import org .jd .gui .util .ImageUtil ;
15+ import org .jd .gui .view .data .TreeNodeBean ;
16+
17+ import java .io .File ;
18+
19+ import javax .swing .ImageIcon ;
20+ import javax .swing .JComponent ;
21+ import javax .swing .tree .DefaultMutableTreeNode ;
22+
23+ public class GroovyTreeNodeFactoryProvider extends TextFileTreeNodeFactoryProvider {
24+
25+ protected static final ImageIcon ICON = new ImageIcon (ImageUtil .getImage ("/org/jd/gui/images/groovy_obj.png" ));
26+
27+ @ Override
28+ public String [] getSelectors () {
29+ return appendSelectors ("*:file:*.groovy" );
30+ }
31+
32+ @ Override
33+ @ SuppressWarnings ("unchecked" )
34+ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable > T make (API api , Container .Entry entry ) {
35+ int lastSlashIndex = entry .getPath ().lastIndexOf ("/" );
36+ String label = entry .getPath ().substring (lastSlashIndex + 1 );
37+ String location = new File (entry .getUri ()).getPath ();
38+ return (T ) new TreeNode (entry , new TreeNodeBean (label , "Location: " + location , ICON ));
39+ }
40+
41+ protected static class TreeNode extends TextFileTreeNodeFactoryProvider .TreeNode {
42+
43+ private static final long serialVersionUID = 1L ;
44+
45+ public TreeNode (Container .Entry entry , Object userObject ) {
46+ super (entry , userObject );
47+ }
48+
49+ // --- PageCreator --- //
50+ @ Override
51+ @ SuppressWarnings ("unchecked" )
52+ public <T extends JComponent & UriGettable > T createPage (API api ) {
53+ return (T ) new TextFileTreeNodeFactoryProvider .Page (entry ) {
54+
55+ private static final long serialVersionUID = 1L ;
56+
57+ @ Override
58+ public String getSyntaxStyle () {
59+ return SyntaxConstants .SYNTAX_STYLE_GROOVY ;
60+ }
61+ };
62+ }
63+ }
64+ }
0 commit comments