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-2007 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: package org.netbeans.modules.sql.framework.ui.output;
042:
043: import java.awt.Insets;
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.awt.event.KeyEvent;
047: import java.awt.event.KeyListener;
048: import java.util.ArrayList;
049: import java.util.List;
050: import javax.swing.JEditorPane;
051: import javax.swing.text.Document;
052: import javax.swing.text.EditorKit;
053: import javax.swing.text.StyledEditorKit;
054:
055: /**
056: *
057: * @author Nithya Radhakrishnan
058: */
059: public class SQLEditorPanel extends JEditorPane implements
060: ActionListener, KeyListener {
061:
062: /**
063: * the styled sqlDocument that is the model for the textPane
064: */
065: private SyntaxDocument sqlDocument;
066: private List tables = new ArrayList();
067:
068: public SQLEditorPanel() {
069: // Create the sqlDocument model.
070: sqlDocument = new SyntaxDocument(this );
071: //Add support for Code completion(comment out, breaks syntax highlighting)
072: // QueryBuilderSqlCompletion doc = new QueryBuilderSqlCompletion( this, sqlReservedWords);
073: // Create the text pane and configure it.
074:
075: this .setDocument(sqlDocument);
076: this .setCaretPosition(0);
077: this .setMargin(new Insets(5, 5, 5, 5));
078: EditorKit editorKit = new StyledEditorKit() {
079:
080: @Override
081: public Document createDefaultDocument() {
082: String[] syntax = {
083: "ABSOLUTE",
084: "ACTION",
085: "ADD",
086: "ALL",
087: "ALLOCATE",
088: "ALTER", // NOI18N
089: "AND",
090: "ANY",
091: "ARE",
092: "AS",
093: "ASC",
094: "ASSERTION",
095: "AT", // NOI18N
096: "AUTHORIZATION",
097: "AVG",
098: "BEGIN",
099: "BETWEEN",
100: "BIT", // NOI18N
101: "BIT_LENGTH",
102: "BOTH",
103: "BY",
104: "CASCADE",
105: "CASCADED",
106: "CASE", // NOI18N
107: "CAST",
108: "CATALOG",
109: "CHAR",
110: "CHARACTER",
111: "CHAR_LENGTH", // NOI18N
112: "CHARACTER_LENGTH",
113: "CHECK",
114: "CLOSE",
115: "COALESCE",
116: "COLLATE", // NOI18N
117: "COLLATION",
118: "COLUMN",
119: "COMMIT",
120: "CONNECT",
121: "CONNECTION", // NOI18N
122: "CONSTRAINT",
123: "CONSTRAINTS",
124: "CONTINUE",
125: "CONVERT", // NOI18N
126: "CORRESPONDING",
127: "COUNT",
128: "CREATE",
129: "CROSS",
130: "CURRENT", // NOI18N
131: "CURRENT_DATE",
132: "CURRENT_TIME",
133: "CURRENT_TIMESTAMP", // NOI18N
134: "CURRENT_USER",
135: "CURSOR",
136: "DATE",
137: "DAY",
138: "DEALLOCATE",
139: "DEC", // NOI18N
140: "DECIMAL",
141: "DECLARE",
142: "DEFAULT",
143: "DEFERRABLE",
144: "DEFERRED", // NOI18N
145: "DELETE",
146: "DESC",
147: "DESCRIBE",
148: "DESCRIPTOR",
149: "DIAGNOSTICS", // NOI18N
150: "DISCONNECT",
151: "DISTINCT",
152: "DOMAIN",
153: "DOUBLE",
154: "DROP",
155: "ELSE", // NOI18N
156: "END",
157: "END-EXEC",
158: "ESCAPE",
159: "EXCEPT",
160: "EXCEPTION",
161: "EXEC", // NOI18N
162: "EXECUTE",
163: "EXISTS",
164: "EXTERNAL",
165: "EXTRACT",
166: "FALSE",
167: "FETCH", // NOI18N
168: "FIRST",
169: "FLOAT",
170: "FOR",
171: "FOREIGN",
172: "FOUND",
173: "FROM",
174: "FULL", // NOI18N
175: "GET",
176: "GLOBAL",
177: "GO",
178: "GOTO",
179: "GRANT",
180: "GROUP",
181: "HAVING", // NOI18N
182: "HOUR",
183: "IDENTITY",
184: "IMMEDIATE",
185: "IN",
186: "INDICATOR", // NOI18N
187: "INITIALLY",
188: "INNER",
189: "INPUT",
190: "INSENSITIVE",
191: "INSERT",
192: "INT", // NOI18N
193: "INTEGER",
194: "INTERSECT",
195: "INTERVAL",
196: "INTO",
197: "IS",
198: "ISOLATION", // NOI18N
199: "JOIN",
200: "KEY",
201: "LANGUAGE",
202: "LAST",
203: "LEADING",
204: "LEFT",
205: "LEVEL", // NOI18N
206: "LIKE",
207: "LOCAL",
208: "LOWER",
209: "MATCH",
210: "MAX",
211: "MIN",
212: "MINUTE", // NOI18N
213: "MODULE",
214: "MONTH",
215: "NAMES",
216: "NATIONAL",
217: "NATURAL",
218: "NCHAR", // NOI18N
219: "NEXT",
220: "NO",
221: "NOT",
222: "NULL",
223: "NULLIF",
224: "NUMERIC", // NOI18N
225: "OCTET_LENGTH",
226: "OF",
227: "ON",
228: "ONLY",
229: "OPEN",
230: "OPTION",
231: "OR", // NOI18N
232: "ORDER",
233: "OUTER",
234: "OUTPUT",
235: "OVERLAPS",
236: "PAD",
237: "PARTIAL", // NOI18N
238: "POSITION",
239: "PRECISION",
240: "PREPARE",
241: "PRESERVE",
242: "PRIMARY", // NOI18N
243: "PRIOR",
244: "PRIVILEGES",
245: "PROCEDURE",
246: "PUBLIC",
247: "READ",
248: "REAL", // NOI18N
249: "REFERENCES",
250: "RELATIVE",
251: "RESTRICT",
252: "REVOKE",
253: "RIGHT", // NOI18N
254: "ROLLBACK",
255: "ROWS",
256: "SCHEMA",
257: "SCROLL",
258: "SECOND",
259: "SECTION", // NOI18N
260: "SELECT",
261: "SESSION",
262: "SESSION_USER",
263: "SET",
264: "SIZE",
265: "SMALLINT", // NOI18N
266: "SOME",
267: "SPACE",
268: "SQL",
269: "SQLCODE",
270: "SQLERROR",
271: "SQLSTATE", // NOI18N
272: "SUBSTRING",
273: "SUM",
274: "SYSTEM_USER",
275: "TABLE",
276: "TEMPORARY", // NOI18N
277: "THEN",
278: "TIME",
279: "TIMESTAMP",
280: "TIMEZONE_HOUR", // NOI18N
281: "TIMEZONE_MINUTE",
282: "TO",
283: "TRAILING",
284: "TRANSACTION", // NOI18N
285: "TRANSLATE", "TRANSLATION",
286: "TRIM",
287: "TRUE",
288: "UNION",
289: "UNIQUE", // NOI18N
290: "UNKNOWN", "UPDATE", "UPPER", "USAGE",
291: "USER",
292: "USING",
293: "VALUE", // NOI18N
294: "VALUES", "VARCHAR", "VARYING", "VIEW",
295: "WHEN",
296: "WHENEVER", // NOI18N
297: "WHERE", "WITH", "WORK", "WRITE", "YEAR",
298: "ZONE" };
299: return new SyntaxDocument(syntax);
300: }
301: };
302: setEditorKitForContentType("text/x-sql", editorKit);
303: setContentType("text/x-sql");
304: }
305:
306: /**
307: * @return Returns the tables.
308: */
309: public List getTables() {
310: return tables;
311: }
312:
313: /**
314: * @param tables The tables to set.
315: */
316: public void setTables(List tables) {
317: if (tables != null) {
318: this .tables = tables;
319: }
320: }
321:
322: public void actionPerformed(ActionEvent e) {
323: }
324:
325: public void keyTyped(KeyEvent e) {
326: }
327:
328: public void keyPressed(KeyEvent e) {
329: }
330:
331: public void keyReleased(KeyEvent e) {
332: }
333: }
|