01: /*
02: * Sun Public License Notice
03: *
04: * The contents of this file are subject to the Sun Public License
05: * Version 1.0 (the "License"). You may not use this file except in
06: * compliance with the License. A copy of the License is available at
07: * http://www.sun.com/
08: *
09: * The Original Code is NetBeans. The Initial Developer of the Original
10: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11: * Microsystems, Inc. All Rights Reserved.
12: */
13: package org.netbeans.editor.ext.html;
14:
15: import java.awt.Component;
16:
17: import javax.swing.DefaultListCellRenderer;
18: import javax.swing.JList;
19: import javax.swing.ListCellRenderer;
20:
21: import org.netbeans.editor.ext.Completion;
22: import org.netbeans.editor.ext.CompletionQuery;
23: import org.netbeans.editor.ext.CompletionView;
24: import org.netbeans.editor.ext.ExtEditorUI;
25: import org.netbeans.editor.ext.ListCompletionView;
26:
27: /**
28: * HTML Completion query specifications
29: *
30: * @author Petr Nejedly
31: * @version 1.0
32: */
33:
34: public class HTMLCompletion extends Completion {
35:
36: public HTMLCompletion(ExtEditorUI extEditorUI) {
37: super (extEditorUI);
38: }
39:
40: protected CompletionView createView() {
41: return new ListCompletionView(new DelegatingCellRenderer());
42: }
43:
44: protected CompletionQuery createQuery() {
45: return new HTMLCompletionQuery();
46: }
47:
48: /**
49: * Substitute the document's text with the text that is appopriate for the
50: * selection in the view. This function is usually triggered upon pressing
51: * the Enter key.
52: *
53: * @return true if the substitution was performed false if not.
54: */
55: public synchronized boolean substituteText(boolean flag) {
56: if (getLastResult() != null) {
57: int index = getView().getSelectedIndex();
58: if (index >= 0) {
59: getLastResult().substituteText(index, flag);
60: }
61: return true;
62: } else {
63: return false;
64: }
65: }
66:
67: /* -------------------------------------------------------------------------- */
68: // This would go out as the interfaces of all completions will meet
69: public class DelegatingCellRenderer implements ListCellRenderer {
70: ListCellRenderer defaultRenderer = new DefaultListCellRenderer();
71:
72: public Component getListCellRendererComponent(JList list,
73: Object value, int index, boolean isSelected,
74: boolean cellHasFocus) {
75: if (value instanceof CompletionQuery.ResultItem) {
76: return ((CompletionQuery.ResultItem) value)
77: .getPaintComponent(list, isSelected,
78: cellHasFocus);
79: } else {
80: return defaultRenderer.getListCellRendererComponent(
81: list, value, index, isSelected, cellHasFocus);
82: }
83: }
84: }
85:
86: }
|