KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > editor > EditorIdeas


1 package org.antlr.works.editor;
2
3 import org.antlr.works.components.grammar.CEditorGrammar;
4 import org.antlr.works.idea.*;
5 import org.antlr.works.syntax.element.ElementRule;
6
7 import java.awt.*;
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10 /*
11
12 [The "BSD licence"]
13 Copyright (c) 2005 Jean Bovet
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
19
20 1. Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
22 2. Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
25 3. The name of the author may not be used to endorse or promote products
26 derived from this software without specific prior written permission.
27
28 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39 */

40
41 public class EditorIdeas implements IdeaManagerDelegate, IdeaProvider {
42
43     public IdeaManager ideaManager;
44     public CEditorGrammar editor;
45
46     public EditorIdeas(CEditorGrammar editor) {
47         this.editor = editor;
48     }
49
50     public void awake() {
51         ideaManager = new IdeaManager();
52         ideaManager.setOverlay(new IdeaOverlay(editor, editor.getXJFrame(), editor.getTextPane()));
53         ideaManager.addProvider(this);
54         ideaManager.setDelegate(this);
55     }
56
57     public void close() {
58         ideaManager.close();
59     }
60
61     public void hide() {
62         ideaManager.hide();
63     }
64
65     public void toggleEnabled() {
66         ideaManager.setEnabled(!ideaManager.enabled());
67     }
68
69     public List JavaDoc<IdeaAction> ideaProviderGetActions(int position) {
70         List JavaDoc<IdeaAction> actions = new ArrayList JavaDoc<IdeaAction>();
71         List JavaDoc<EditorInspectorItem> items = editor.editorInspector.getAllItemsAtIndex(position);
72         for (EditorInspectorItem item : items) {
73             List JavaDoc<IdeaAction> itemActions = item.getIdeaActions();
74             if (itemActions != null)
75                 actions.addAll(itemActions);
76         }
77         return actions;
78     }
79
80
81     public boolean ideaManagerWillDisplayIdea() {
82         return !editor.autoCompletionMenu.isVisible();
83     }
84
85     public void display(Point p) {
86         display(editor.getTextPane().viewToModel(p));
87     }
88
89     public void display(int position) {
90         ElementRule enclosingRule = editor.rules.getEnclosingRuleAtPosition(position);
91         if(enclosingRule == null || enclosingRule.isExpanded())
92             ideaManager.displayAnyIdeasAvailable(position);
93     }
94
95 }
96
Popular Tags