Source Code Cross Referenced for OsterSQLEntryPanel.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » syntax » oster » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.syntax.oster 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.syntax.oster;
002:
003:        /*
004:         * Copyright (C) 2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:        import java.awt.Font;
022:        import java.awt.dnd.DropTarget;
023:        import java.awt.event.MouseListener;
024:
025:        import javax.swing.event.CaretListener;
026:        import javax.swing.event.UndoableEditListener;
027:        import javax.swing.text.Document;
028:        import javax.swing.text.Element;
029:        import javax.swing.text.JTextComponent;
030:        import javax.swing.text.PlainDocument;
031:        import javax.swing.undo.UndoManager;
032:
033:        import net.sourceforge.squirrel_sql.client.IApplication;
034:        import net.sourceforge.squirrel_sql.client.gui.dnd.FileEditorDropTargetListener;
035:        import net.sourceforge.squirrel_sql.client.session.BaseSQLEntryPanel;
036:        import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
037:        import net.sourceforge.squirrel_sql.client.session.ISession;
038:        import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
039:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
040:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
041:        import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxPreferences;
042:
043:        public class OsterSQLEntryPanel extends BaseSQLEntryPanel {
044:            /** Logger for this class. */
045:            private static final ILogger s_log = LoggerController
046:                    .createLogger(OsterSQLEntryPanel.class);
047:
048:            /** Application API. */
049:            private IApplication _app;
050:
051:            /** Text component. */
052:            private OsterTextControl _textArea;
053:
054:            @SuppressWarnings("unused")
055:            private DropTarget dt;
056:
057:            private ISession _session;
058:
059:            OsterSQLEntryPanel(ISession session, SyntaxPreferences prefs) {
060:                super (session.getApplication());
061:                _session = session;
062:
063:                if (session == null) {
064:                    throw new IllegalArgumentException("Null ISession passed");
065:                }
066:
067:                if (prefs == null) {
068:                    throw new IllegalArgumentException(
069:                            "Null Preferences passed");
070:                }
071:
072:                _app = session.getApplication();
073:
074:                _textArea = new OsterTextControl(session, prefs,
075:                        getIdentifier());
076:
077:                dt = new DropTarget(_textArea,
078:                        new FileEditorDropTargetListener(session));
079:            }
080:
081:            public void endColorerThread() {
082:                _textArea.endColorerThread();
083:            }
084:
085:            /**
086:             * @see ISQLEntryPanel#gettextComponent()
087:             */
088:            public JTextComponent getTextComponent() {
089:                return _textArea;
090:            }
091:
092:            /**
093:             * If the component returned by <TT>getTextComponent</TT> contains
094:             * its own scroll bars return <TT>true</TT> other wise this component
095:             * will be wrapped in the scroll pane when added to the SQL panel.
096:             *
097:             * @return	<TT>true</TT> if text component already handles scrolling.
098:             */
099:            public boolean getDoesTextComponentHaveScroller() {
100:                return false;
101:            }
102:
103:            /**
104:             * @see ISQLEntryPanel#getText()
105:             */
106:            public String getText() {
107:                return _textArea.getText();
108:            }
109:
110:            public void setFont(Font font) {
111:                _textArea.setFont(font);
112:            }
113:
114:            /**
115:             * @see ISQLEntryPanel#getSelectedText()
116:             */
117:            public String getSelectedText() {
118:                return _textArea.getSelectedText();
119:            }
120:
121:            /**
122:             * Replace the contents of the SQL entry area with the passed
123:             * SQL script without selecting it.
124:             *
125:             * @param	sqlScript	The script to be placed in the SQL entry area..
126:             */
127:            public void setText(String text) {
128:                setText(text, true);
129:            }
130:
131:            /**
132:             * Replace the contents of the SQL entry area with the passed
133:             * SQL script and specify whether to select it.
134:             *
135:             * @param	sqlScript	The script to be placed in the SQL entry area..
136:             * @param 	select		If <TT>true</TT> then select the passed script
137:             *						in the sql entry area.
138:             */
139:            public void setText(String text, boolean select) {
140:                _textArea.setText(text);
141:
142:                if (select) {
143:                    setSelectionEnd(_textArea.getDocument().getLength());
144:                    setSelectionStart(0);
145:                }
146:            }
147:
148:            /**
149:             * Append the passed SQL script to the SQL entry area but don't select
150:             * it.
151:             *
152:             * @param	sqlScript	The script to be appended.
153:             */
154:            public void appendText(String sqlScript) {
155:                appendText(sqlScript, false);
156:            }
157:
158:            /**
159:             * Append the passed SQL script to the SQL entry area and specify
160:             * whether it should be selected.
161:             *
162:             * @param	sqlScript	The script to be appended.
163:             * @param	select		If <TT>true</TT> then select the passed script
164:             *						in the sql entry area.
165:             */
166:            public void appendText(String sqlScript, boolean select) {
167:                Document doc = _textArea.getDocument();
168:
169:                try {
170:                    int start = 0;
171:                    if (select) {
172:                        start = doc.getLength();
173:                    }
174:
175:                    doc.insertString(doc.getLength(), sqlScript, null);
176:
177:                    if (select) {
178:                        setSelectionEnd(doc.getLength());
179:                        setSelectionStart(start);
180:                    }
181:                } catch (Exception ex) {
182:                    s_log.error("Error appending text to text area", ex);
183:                }
184:            }
185:
186:            /**
187:             * @see ISQLEntryPanel#getCaretPosition()
188:             */
189:            public int getCaretPosition() {
190:                return _textArea.getCaretPosition();
191:            }
192:
193:            public void setCaretPosition(int value) {
194:                _textArea.setCaretPosition(value);
195:            }
196:
197:            /**
198:             * @see ISQLEntryPanel#setTabSize(int)
199:             */
200:            public void setTabSize(int tabSize) {
201:                _textArea.getDocument().putProperty(
202:                        PlainDocument.tabSizeAttribute,
203:                        Integer.valueOf(tabSize));
204:            }
205:
206:            /**
207:             * @see ISQLEntryPanel#getSelectionStart()
208:             */
209:            public int getSelectionStart() {
210:                return _textArea.getSelectionStart();
211:            }
212:
213:            /**
214:             * @see ISQLEntryPanel#setSelectionStart(int)
215:             */
216:            public void setSelectionStart(int pos) {
217:                _textArea.setSelectionStart(pos);
218:            }
219:
220:            /**
221:             * @see ISQLEntryPanel#getSelectionEnd()
222:             */
223:            public int getSelectionEnd() {
224:                return _textArea.getSelectionEnd();
225:            }
226:
227:            /**
228:             * @see ISQLEntryPanel#setSelectionEnd(int)
229:             */
230:            public void setSelectionEnd(int pos) {
231:                _textArea.setSelectionEnd(pos);
232:            }
233:
234:            /**
235:             * Replace the currently selected text in the SQL entry area
236:             * with the passed text.
237:             *
238:             * @param	sqlScript	The script to be placed in the SQL entry area.
239:             */
240:            public void replaceSelection(String sqlScript) {
241:                _textArea.replaceSelection(sqlScript);
242:            }
243:
244:            /**
245:             * @see ISQLEntryPanel#hasFocus()
246:             */
247:            public boolean hasFocus() {
248:                return _textArea.hasFocus();
249:            }
250:
251:            /**
252:             * @see ISQLEntryPanel#requestFocus()
253:             */
254:            public void requestFocus() {
255:                _textArea.requestFocus();
256:            }
257:
258:            /**
259:             * @see ISQLEntryPanel#addMouseListener(MouseListener)
260:             */
261:            public void addMouseListener(MouseListener lis) {
262:                _textArea.addMouseListener(lis);
263:            }
264:
265:            /**
266:             * @see ISQLEntryPanel#removeMouseListener(MouseListener)
267:             */
268:            public void removeMouseListener(MouseListener lis) {
269:                _textArea.removeMouseListener(lis);
270:            }
271:
272:            public void updateFromPreferences() {
273:                _textArea.updateFromPreferences();
274:            }
275:
276:            /**
277:             * @see ISQLEntryPanel#hasOwnUndoableManager()
278:             */
279:            public boolean hasOwnUndoableManager() {
280:                return false;
281:            }
282:
283:            /**
284:             * @see ISQLEntryPanel#addUndoableEditListener(UndoableEditListener)
285:             */
286:            public void addUndoableEditListener(UndoableEditListener listener) {
287:                _textArea.getDocument().addUndoableEditListener(listener);
288:            }
289:
290:            /**
291:             * @see ISQLEntryPanel#removeUndoableEditListener(UndoableEditListener)
292:             */
293:            public void removeUndoableEditListener(UndoableEditListener listener) {
294:                _textArea.getDocument().removeUndoableEditListener(listener);
295:            }
296:
297:            /* (non-Javadoc)
298:             * @see net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel#setUndoManager(javax.swing.undo.UndoManager)
299:             */
300:            public void setUndoManager(UndoManager manager) {
301:                // no support for undo
302:            }
303:
304:            /**
305:             * @see ISQLEntryPanel#getCaretLineNumber()
306:             */
307:            public int getCaretLineNumber() {
308:                final int pos = getCaretPosition();
309:                final Document doc = _textArea.getStyledDocument();
310:                final Element docElem = doc.getDefaultRootElement();
311:                return docElem.getElementIndex(pos);
312:            }
313:
314:            /**
315:             * @see ISQLEntryPanel#getCaretLinePosition()
316:             */
317:            public int getCaretLinePosition() {
318:                String textTillCarret = getText().substring(0,
319:                        getCaretPosition());
320:
321:                int lineFeedIndex = textTillCarret.lastIndexOf('\n');
322:                if (-1 == lineFeedIndex) {
323:                    return getCaretPosition();
324:                } else {
325:                    return getCaretPosition() - lineFeedIndex - 1;
326:                }
327:
328:                // this didn't work      
329:                //		final int pos = getCaretPosition();
330:                //		final Document doc = _textArea.getStyledDocument();
331:                //		final Element docElem = doc.getDefaultRootElement();
332:                //		final Element lineElem = docElem.getElement(getCaretLineNumber());
333:                //		return lineElem.getElementIndex(pos);
334:            }
335:
336:            /**
337:             * @see ISQLEntryPanel#addCaretListener(CaretListener)
338:             */
339:            public void addCaretListener(CaretListener lis) {
340:                _textArea.addCaretListener(lis);
341:            }
342:
343:            /**
344:             * @see ISQLEntryPanel#removeCaretListener(CaretListener)
345:             */
346:            public void removeCaretListener(CaretListener lis) {
347:                _textArea.removeCaretListener(lis);
348:            }
349:
350:            public void addSQLTokenListener(SQLTokenListener tl) {
351:                _textArea.addSQLTokenListener(tl);
352:            }
353:
354:            public void removeSQLTokenListener(SQLTokenListener tl) {
355:                _textArea.removeSQLTokenListener(tl);
356:            }
357:
358:            public ISession getSession() {
359:                return _session;
360:            }
361:
362:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.