KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > completion > XMLCompletion


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.xml.text.completion;
21
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.util.*;
24 import java.awt.Component JavaDoc;
25
26 import javax.swing.*;
27
28 import org.netbeans.editor.ext.*;
29
30 import org.netbeans.modules.xml.text.syntax.*;
31
32 /**
33  * XML Completion query specifications
34  *
35  * @author Petr Nejedly
36  * @author Sandeep Randhawa
37  * @version 1.0
38  */

39
40 public class XMLCompletion extends Completion {
41
42     public static final String JavaDoc FULLY_VALID = "Fully valid"; //???
43
public static final String JavaDoc INSERT_END_TAG = "Insert End Tag"; //???
44

45     public XMLCompletion(ExtEditorUI extEditorUI) {
46         super(extEditorUI);
47     }
48     
49     protected CompletionView createView() {
50         return new ListCompletionView(new DelegatingCellRenderer());
51     }
52     
53     protected CompletionQuery createQuery() {
54         return new XMLCompletionQuery();
55     }
56     
57     /** Substitute the document's text with the text
58      * that is appopriate for the selection
59      * in the view. This function is usually triggered
60      * upon pressing the Enter key.
61      * @return true if the substitution was performed
62      * false if not.
63      */

64     public synchronized boolean substituteText( boolean flag ) {
65         if( getLastResult() != null ) {
66             int index = getView().getSelectedIndex();
67             if (index >= 0) {
68                 getLastResult().substituteText( index, flag );
69             }
70             return true;
71         } else {
72             return false;
73         }
74     }
75     
76     
77     /* -------------------------------------------------------------------------- */
78     // This would go out as the interfaces of all completions will meet
79
public class DelegatingCellRenderer implements ListCellRenderer {
80         ListCellRenderer defaultRenderer = new DefaultListCellRenderer();
81         
82         
83         public Component JavaDoc getListCellRendererComponent(JList list, Object JavaDoc value,
84         int index, boolean isSelected, boolean cellHasFocus) {
85             if( value instanceof CompletionQuery.ResultItem ) {
86                 return ((CompletionQuery.ResultItem)value).getPaintComponent( list, isSelected, cellHasFocus );
87             } else {
88                 return defaultRenderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus);
89             }
90         }
91     }
92     
93 }
94
95
Popular Tags