KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > features > LanguagesGenerateFoldPopupAction


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.features;
21
22 import java.util.Collection JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.JMenu JavaDoc;
29 import javax.swing.text.JTextComponent JavaDoc;
30 import org.netbeans.api.languages.LanguagesManager;
31 import org.netbeans.api.languages.ParseException;
32 import org.netbeans.modules.editor.NbEditorKit.GenerateFoldPopupAction;
33 import org.netbeans.modules.languages.Feature;
34 import org.netbeans.modules.languages.Language;
35 import org.netbeans.modules.languages.LanguagesManagerImpl;
36
37
38 /**
39  *
40  * @author Jan Jancura
41  */

42 public class LanguagesGenerateFoldPopupAction extends GenerateFoldPopupAction {
43
44     protected void addAdditionalItems (JTextComponent JavaDoc target, JMenu JavaDoc menu) {
45         try {
46             String JavaDoc mimeType = (java.lang.String JavaDoc) target.getDocument ().getProperty ("mimeType");
47             Language l = ((LanguagesManagerImpl) LanguagesManager.getDefault ()).getLanguage (mimeType);
48             Set JavaDoc expands = new HashSet JavaDoc ();
49             addFoldTypes (target, menu, l, expands);
50             Iterator JavaDoc<Language> it = l.getImportedLanguages ().iterator ();
51             while (it.hasNext ())
52                 addFoldTypes (target, menu, it.next (), expands);
53         } catch (ParseException ex) {
54         }
55     }
56
57     private void addFoldTypes (JTextComponent JavaDoc target, JMenu JavaDoc menu, Language l, Set JavaDoc expands) {
58         List JavaDoc<Feature> features = l.getFeatures (Language.FOLD);
59         Iterator JavaDoc<Feature> it = features.iterator ();
60         while (it.hasNext ()) {
61             Feature fold = it.next ();
62             String JavaDoc expand = (String JavaDoc) fold.getValue ("expand_type_action_name");
63             if (expand == null) continue;
64             if (expands.contains (expand))
65                 continue;
66             expands.add (expand);
67             String JavaDoc collapse = (String JavaDoc) fold.getValue ("collapse_type_action_name");
68             if (collapse == null) continue;
69             addAction (target, menu, expand);
70             addAction (target, menu, collapse);
71             setAddSeparatorBeforeNextAction (true);
72         }
73     }
74 }
75     
Popular Tags