001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.spi.editor.completion;
043:
044: import javax.swing.text.JTextComponent;
045:
046: /**
047: * The basic interface of the code completion querying SPI. Various implementations can
048: * be registered per a document mime-type.
049: *
050: * @author Miloslav Metelka, Dusan Balek
051: * @version 1.01
052: */
053:
054: public interface CompletionProvider {
055:
056: /**
057: * The <code>int</code> value representing the query for a code completion.
058: */
059: public static final int COMPLETION_QUERY_TYPE = 1;
060:
061: /**
062: * The <code>int</code> value representing the query for a documentation.
063: */
064: public static final int DOCUMENTATION_QUERY_TYPE = 2;
065:
066: /**
067: * The <code>int</code> value representing the query for a tooltip hint.
068: */
069: public static final int TOOLTIP_QUERY_TYPE = 4;
070:
071: /**
072: * The <code>int</code> value representing the query for an all code completion.
073: */
074: public static final int COMPLETION_ALL_QUERY_TYPE = 9;
075:
076: /**
077: * Creates a task that performs a query of the given type on the given component.
078: * <br>
079: * This method is invoked in AWT thread only and the returned task
080: * may either be synchronous (if it's not complex)
081: * or it may be asynchonous
082: * (see {@link org.netbeans.spi.editor.completion.support.AsyncCompletionTask}).
083: * <br>
084: * The task usually inspects the component's document, the
085: * text up to the caret position and returns the appropriate result.
086: *
087: * @param queryType a type ot the query. It can be one of the {@link #COMPLETION_QUERY_TYPE},
088: * {@link #COMPLETION_ALL_QUERY_TYPE}, {@link #DOCUMENTATION_QUERY_TYPE},
089: * or {@link #TOOLTIP_QUERY_TYPE} (but not their combination).
090: * @param component a component on which the query is performed
091: *
092: * @return a task performing the query.
093: */
094: public CompletionTask createTask(int queryType,
095: JTextComponent component);
096:
097: /**
098: * Called by the code completion infrastructure to check whether a text just typed
099: * into a text component triggers an automatic query invocation.
100: * <br>
101: * If the particular query type is returned the infrastructure
102: * will then call {@link #createTask(int, JTextComponent)}.
103: *
104: * @param component a component in which typing appeared
105: * @param typedText a typed text
106: *
107: * @return a combination of the {@link #COMPLETION_QUERY_TYPE}, {@link #COMPLETION_ALL_QUERY_TYPE},
108: * {@link #DOCUMENTATION_QUERY_TYPE}, and {@link #TOOLTIP_QUERY_TYPE}
109: * values, or zero if no query should be automatically invoked.
110: */
111: public int getAutoQueryTypes(JTextComponent component,
112: String typedText);
113:
114: }
|