Update of /cvsroot/squirrel-sql/sql12/plugins/syntax/src/net/sourceforge/squirrel_sql/plugins/syntax/rsyntax
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv1806/plugins/syntax/src/net/sourceforge/squirrel_sql/plugins/syntax/rsyntax
Added Files:
RSyntaxHighlightTokenMatcherProxy.java
RSyntaxPropertiesWrapper.java SquirrelTokenMarkerFactory.java
RSyntaxSQLEntryPanel.java RSyntaxHighlightTokenMatcher.java
SquirrelSyntaxScheme.java I18NStrings.properties
SquirrelTokenMakerBase.flex SquirreLRSyntaxTextAreaUI.java
RSyntaxSQLEntryAreaFactory.java SquirrelTokenMarker.java
SquirrelTokenMakerBase.java SquirrelRSyntaxTextArea.java
Log Message:
RSyntax editor integration
--- NEW FILE: RSyntaxPropertiesWrapper.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcherFactory;
import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessor;
import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessorFactory;
import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
import java.util.HashMap;
public class RSyntaxPropertiesWrapper
{
private HashMap<String, Object> _props;
public RSyntaxPropertiesWrapper(HashMap<String, Object> props)
{
_props = props;
}
public IParserEventsProcessor getParserEventsProcessor(IIdentifier sqlEntryPanelIdentifier, ISession sess)
{
if(false == _props.containsKey(IParserEventsProcessorFactory.class.getName()))
{
return sess.getParserEventsProcessor(sqlEntryPanelIdentifier);
}
else if(null == _props.get(IParserEventsProcessorFactory.class.getName()))
{
return null;
}
else
{
IParserEventsProcessorFactory fact = (IParserEventsProcessorFactory) _props.get(IParserEventsProcessorFactory.class.getName());
return fact.getParserEventsProcessor(sqlEntryPanelIdentifier, sess);
}
}
public ISyntaxHighlightTokenMatcher getSyntaxHighlightTokenMatcher(ISession sess, SquirrelRSyntaxTextArea rSyntaxTextArea, IIdentifier sqlEntryPanelIdentifier)
{
if(false == _props.containsKey(ISyntaxHighlightTokenMatcherFactory.class.getName()))
{
return new RSyntaxHighlightTokenMatcher(sess, rSyntaxTextArea, sqlEntryPanelIdentifier, this);
}
else
{
ISyntaxHighlightTokenMatcherFactory fact = (ISyntaxHighlightTokenMatcherFactory) _props.get(ISyntaxHighlightTokenMatcherFactory.class.getName());
return fact.getSyntaxHighlightTokenMatcher(sess, rSyntaxTextArea);
}
}
}
--- NEW FILE: SquirrelTokenMarker.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import org.fife.ui.rsyntaxtextarea.Token;
import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
public class SquirrelTokenMarker extends SquirrelTokenMakerBase
{
private static int _curTokenArrayIndex =Token.NUM_TOKEN_TYPES;
public static final int TOKEN_IDENTIFIER_TABLE = _curTokenArrayIndex++;
public static final int TOKEN_IDENTIFIER_DATA_TYPE = _curTokenArrayIndex++;
public static final int TOKEN_IDENTIFIER_COLUMN = _curTokenArrayIndex++;
public static final int TOKEN_IDENTIFIER_FUNCTION = _curTokenArrayIndex++;
public static final int TOKEN_IDENTIFIER_STATEMENT_SEPARATOR = _curTokenArrayIndex++;
// public static final int TOKEN_IDENTIFIER_ERROR = _curTokenArrayIndex++;
// public static final int TOKEN_IDENTIFIER_SCHEMA = _curTokenArrayIndex++;
// public static final int TOKEN_IDENTIFIER_CATALOG = _curTokenArrayIndex++;
private ISyntaxHighlightTokenMatcher _syntaxHighlightTokenMatcher;
public static int getNumTokenTypes()
{
return _curTokenArrayIndex;
}
public SquirrelTokenMarker(final SquirrelRSyntaxTextArea squirrelRSyntaxTextArea, ISyntaxHighlightTokenMatcher syntaxHighlightTokenMatcher)
{
_syntaxHighlightTokenMatcher = syntaxHighlightTokenMatcher;
}
public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink)
{
int len = end + 1 - start;
if(_syntaxHighlightTokenMatcher.isError(startOffset, len))
{
// Errors must be first.
super.addToken(array, start, end, Token.ERROR_IDENTIFIER, startOffset, hyperlink);
}
else if(Token.IDENTIFIER == tokenType)
{
// String s = new String(array).substring(start, end+1);
// System.out.println("Squirrel: -->" + s + "<--");
if(_syntaxHighlightTokenMatcher.isKeyword(array, start, len))
{
super.addToken(array, start, end, Token.RESERVED_WORD, startOffset, hyperlink);
}
else if(_syntaxHighlightTokenMatcher.isTable(array, start, len))
{
super.addToken(array, start, end, TOKEN_IDENTIFIER_TABLE, startOffset, hyperlink);
}
else if(_syntaxHighlightTokenMatcher.isDataType(array, start, len))
{
super.addToken(array, start, end, TOKEN_IDENTIFIER_DATA_TYPE, startOffset, hyperlink);
}
else if(_syntaxHighlightTokenMatcher.isColumn(array, start, len))
{
super.addToken(array, start, end, TOKEN_IDENTIFIER_COLUMN, startOffset, hyperlink);
}
else if(_syntaxHighlightTokenMatcher.isFunction(array, start, len))
{
super.addToken(array, start, end, TOKEN_IDENTIFIER_FUNCTION, startOffset, hyperlink);
}
else if(_syntaxHighlightTokenMatcher.isStatementSeparator(array, start, len))
{
super.addToken(array, start, end, TOKEN_IDENTIFIER_STATEMENT_SEPARATOR, startOffset, hyperlink);
}
else
{
super.addToken(array, start, end, tokenType, startOffset, hyperlink);
}
}
else
{
super.addToken(array, start, end, tokenType, startOffset, hyperlink);
}
}
}
--- NEW FILE: I18NStrings.properties ---
syntax.useNoDDrawOnWIn32=Please use the Java-VM parameter -Dsun.java2d.noddraw=true in your SQuirreL start batch to prevent performance problems
--- NEW FILE: RSyntaxHighlightTokenMatcherProxy.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
import javax.swing.text.JTextComponent;
public class RSyntaxHighlightTokenMatcherProxy implements ISyntaxHighlightTokenMatcher
{
private ISyntaxHighlightTokenMatcher _delegate;
private JTextComponent _editorPane;
@Override
public boolean isError(int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isError(offset, len);
}
public boolean isTable(char[] buffer, int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isTable(buffer, offset, len);
}
public boolean isFunction(char[] buffer, int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isFunction(buffer, offset, len);
}
public boolean isDataType(char[] buffer, int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isDataType(buffer, offset, len);
}
public boolean isStatementSeparator(char[] buffer, int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isStatementSeparator(buffer, offset, len);
}
public boolean isColumn(char[] buffer, int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isColumn(buffer, offset, len);
}
public boolean isKeyword(char[] buffer, int offset, int len)
{
if(null == _delegate)
{
return false;
}
return _delegate.isKeyword(buffer, offset, len);
}
public void removeSQLTokenListener(SQLTokenListener tl)
{
if(null == _delegate)
{
return;
}
_delegate.removeSQLTokenListener(tl);
}
public void addSQLTokenListener(SQLTokenListener tl)
{
if(null == _delegate)
{
return;
}
_delegate.addSQLTokenListener(tl);
}
public void setDelegate(ISyntaxHighlightTokenMatcher delegate)
{
_delegate = delegate;
if(null != _editorPane)
{
_editorPane.repaint();
}
}
public void setEditorPane(JTextComponent editorPane)
{
_editorPane = editorPane;
_editorPane.repaint();
}
}
--- NEW FILE: SquirreLRSyntaxTextAreaUI.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import net.sourceforge.squirrel_sql.client.session.mainpanel.IUndoHandler;
import net.sourceforge.squirrel_sql.client.session.SQLEntryPanelUtil;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaDefaultInputMap;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaUI;
import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaEditorKit;
import javax.swing.*;
import javax.swing.plaf.InputMapUIResource;
import javax.swing.text.EditorKit;
import javax.swing.text.JTextComponent;
import javax.swing.text.TextAction;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class SquirreLRSyntaxTextAreaUI extends RSyntaxTextAreaUI
{
public static final String RS_ACCELERATOR_STRING_TO_UPPER_CASE = "ctrl shift u";
public static final String RS_ACCELERATOR_STRING_TO_LOWER_CASE = "ctrl shift l";
private static final EditorKit _squirrel_defaultKit =
new RSyntaxTextAreaEditorKit()
{
@Override
public Action[] getActions()
{
return TextAction.augmentList(super.getActions(), new Action[]{new SQuirrelSelectWordAction()});
}
};
private SquirrelRSyntaxTextArea _squirrelRSyntaxTextArea;
public SquirreLRSyntaxTextAreaUI(SquirrelRSyntaxTextArea squirrelRSyntaxTextArea)
{
super(squirrelRSyntaxTextArea);
_squirrelRSyntaxTextArea = squirrelRSyntaxTextArea;
}
protected InputMap getRTextAreaInputMap()
{
// Except from modifiyKeystrokes() this is copied from RSyntaxTextAreaUI.
// Not too nice
InputMap map = new InputMapUIResource();
InputMap shared = (InputMap)UIManager.get("RSyntaxTextAreaUI.inputMap");
if (shared==null) {
shared = new RSyntaxTextAreaDefaultInputMap();
modifiyKeystrokes(shared);
UIManager.put("RSyntaxTextAreaUI.inputMap", shared);
}
//KeyStroke[] keys = shared.allKeys();
//for (int i=0; i<keys.length; i++)
// System.err.println(keys[i] + " -> " + shared.get(keys[i]));
map.setParent(shared);
return map;
}
private void modifiyKeystrokes(InputMap shared)
{
shared.remove(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK));
shared.remove(KeyStroke.getKeyStroke(KeyEvent.VK_J, InputEvent.CTRL_MASK));
shared.remove(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
shared.put(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK), RTextAreaEditorKit.rtaUpperSelectionCaseAction);
shared.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK), RTextAreaEditorKit.rtaLowerSelectionCaseAction);
KeyStroke rsyntaxRedoStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK);
KeyStroke squirrelRedoStroke = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK);
shared.put(squirrelRedoStroke,shared.get(rsyntaxRedoStroke));
}
public IUndoHandler createUndoHandler()
{
return new IUndoHandler()
{
@Override
public Action getUndoAction()
{
return onGetUndoAction();
}
@Override
public Action getRedoAction()
{
return onGetRedoAction();
}
};
}
private Action onGetUndoAction()
{
return getActionForName(_squirrelRSyntaxTextArea, RTextAreaEditorKit.rtaUndoAction);
}
private Action onGetRedoAction()
{
return getActionForName(_squirrelRSyntaxTextArea, RTextAreaEditorKit.rtaRedoAction);
}
public static Action getActionForName(SquirrelRSyntaxTextArea squirrelRSyntaxTextArea, String actionName)
{
Action[] actions = squirrelRSyntaxTextArea.getUI().getEditorKit(squirrelRSyntaxTextArea).getActions();
for (Action action : actions)
{
if(actionName.equals(action.getValue(Action.NAME)))
{
return action;
}
}
throw new IllegalStateException("Action " + actionName + "not found");
}
@Override
public EditorKit getEditorKit(JTextComponent tc)
{
return _squirrel_defaultKit;
}
private static class SQuirrelSelectWordAction extends RSyntaxTextAreaEditorKit.SelectWordAction
{
public void actionPerformedImpl(ActionEvent e, RTextArea textArea)
{
int[] wordBoundsAtCursor = SQLEntryPanelUtil.getWordBoundsAtCursor(textArea, false);
textArea.setSelectionStart(wordBoundsAtCursor[0]);
textArea.setSelectionEnd(wordBoundsAtCursor[1]);
}
}
}
--- NEW FILE: SquirrelRSyntaxTextArea.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
import net.sourceforge.squirrel_sql.client.session.parser.ParserEventsAdapter;
import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessor;
import net.sourceforge.squirrel_sql.client.session.parser.kernel.ErrorInfo;
import net.sourceforge.squirrel_sql.client.session.mainpanel.IUndoHandler;
import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
import net.sourceforge.squirrel_sql.plugins.syntax.KeyManager;
import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxPreferences;
import net.sourceforge.squirrel_sql.plugins.syntax.rsyntax.search.SquirrelRSyntaxSearchEngine;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
import org.fife.ui.rtextarea.RTextAreaUI;
import javax.swing.*;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.Document;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
public class SquirrelRSyntaxTextArea extends RSyntaxTextArea
{
private static final StringManager s_stringMgr =
StringManagerFactory.getStringManager(SquirrelRSyntaxTextArea.class);
private ISession _session;
private SyntaxPreferences _prefs;
private RSyntaxPropertiesWrapper _propertiesWrapper;
private IIdentifier _sqlEntryPanelIdentifier;
private RSyntaxHighlightTokenMatcherProxy _rSyntaxHighlightTokenMatcherProxy;
private IUndoHandler _undoHandler;
private SquirrelSyntaxScheme _squirrelSyntaxScheme;
private ErrorInfo[] _currentErrorInfos = new ErrorInfo[0];
private boolean _parsingInitialized;
private SquirrelRSyntaxSearchEngine _squirrelRSyntaxSearchEngine;
public SquirrelRSyntaxTextArea(ISession session, SyntaxPreferences prefs, RSyntaxPropertiesWrapper propertiesWrapper, IIdentifier sqlEntryPanelIdentifier)
{
_session = session;
_prefs = prefs;
_propertiesWrapper = propertiesWrapper;
_sqlEntryPanelIdentifier = sqlEntryPanelIdentifier;
_rSyntaxHighlightTokenMatcherProxy.setDelegate(_propertiesWrapper.getSyntaxHighlightTokenMatcher(session, this, sqlEntryPanelIdentifier));
updateFromPreferences();
new KeyManager(this);
_squirrelRSyntaxSearchEngine = new SquirrelRSyntaxSearchEngine(_session, this);
setToolTipText("Just to make getToolTiptext() to be called");
setMarginLineEnabled(prefs.isTextLimitLineVisible());
setMarginLinePosition(prefs.getTextLimitLineWidth());
setHighlightCurrentLine(prefs.isHighlightCurrentLine());
if(null != System.getProperty("os.name") && System.getProperty("os.name").toUpperCase().startsWith("WINDOWS"))
{
if(null == System.getProperty("sun.java2d.noddraw") || false == "true".equals(System.getProperty("sun.java2d.noddraw")))
{
session.getApplication().getMessageHandler().showWarningMessage(s_stringMgr.getString("syntax.useNoDDrawOnWIn32"));
}
}
}
protected RTextAreaUI createRTextAreaUI()
{
// Will be called from the super class constructor
SquirreLRSyntaxTextAreaUI ret = new SquirreLRSyntaxTextAreaUI(this);
_undoHandler = ret.createUndoHandler();
return ret;
}
@Override
protected JPopupMenu createPopupMenu()
{
// SQuirreL creates its own popup menu.
return null;
}
protected Document createDefaultModel()
{
// Is called from the super class constructor.
// That is why initialization takes place here.
_rSyntaxHighlightTokenMatcherProxy = new RSyntaxHighlightTokenMatcherProxy();
RSyntaxDocument ret = new RSyntaxDocument(new SquirrelTokenMarkerFactory(this, _rSyntaxHighlightTokenMatcherProxy), SYNTAX_STYLE_SQL);
return ret;
}
public SyntaxScheme getDefaultSyntaxScheme()
{
// Is called from the super class constructor.
// That is why initialization takes place here.
_squirrelSyntaxScheme = new SquirrelSyntaxScheme();
return _squirrelSyntaxScheme;
}
public IUndoHandler createUndoHandler()
{
return _undoHandler;
}
public void addUndoableEditListener(UndoableEditListener um)
{
getDocument().addUndoableEditListener(um);
}
public void updateFromPreferences()
{
_squirrelSyntaxScheme.initSytles(_prefs);
repaint();
}
public void addSQLTokenListeners(ISession session, SQLTokenListener tl)
{
_rSyntaxHighlightTokenMatcherProxy.addSQLTokenListener(tl);
}
public void removeSQLTokenListeners(ISession session, SQLTokenListener tl)
{
_rSyntaxHighlightTokenMatcherProxy.removeSQLTokenListener(tl);
}
public String getToolTipText(MouseEvent event)
{
int pos = viewToModel(event.getPoint());
initParsing();
for (int i = 0; i < _currentErrorInfos.length; i++)
{
if(_currentErrorInfos[i].beginPos-1 <= pos && pos <= _currentErrorInfos[i].endPos)
{
return _currentErrorInfos[i].message;
}
}
return null;
}
private void initParsing()
{
IParserEventsProcessor parserEventsProcessor = _propertiesWrapper.getParserEventsProcessor(_sqlEntryPanelIdentifier, _session);
if(false == _parsingInitialized && null != parserEventsProcessor)
{
_parsingInitialized = true;
parserEventsProcessor.addParserEventsListener(new ParserEventsAdapter()
{
public void errorsFound(ErrorInfo[] errorInfos)
{
onErrorsFound(errorInfos);
}
});
}
}
private void onErrorsFound(ErrorInfo[] errorInfos)
{
_currentErrorInfos = errorInfos;
}
public void showFindDialog(ActionEvent evt)
{
_squirrelRSyntaxSearchEngine.find(evt);
}
public void findSelected(ActionEvent evt)
{
_squirrelRSyntaxSearchEngine.findSelected(evt);
}
public void repeatLastFind(ActionEvent evt)
{
_squirrelRSyntaxSearchEngine.repeatLastFind(evt);
}
public void markSelected(ActionEvent evt)
{
_squirrelRSyntaxSearchEngine.markSelected(evt);
}
public void unmarkAll()
{
_squirrelRSyntaxSearchEngine.unmarkAll();
}
public void showReplaceDialog(ActionEvent evt)
{
_squirrelRSyntaxSearchEngine.replace(evt);
}
public void showGoToLineDialog(ActionEvent evt)
{
_squirrelRSyntaxSearchEngine.goToLine();
}
}
--- NEW FILE: RSyntaxSQLEntryPanel.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
/*
* Copyright (C) 2004 Gerd Wagner
* co...@us...
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import net.sourceforge.squirrel_sql.client.gui.dnd.FileEditorDropTargetListener;
import net.sourceforge.squirrel_sql.client.session.BaseSQLEntryPanel;
import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
import net.sourceforge.squirrel_sql.client.session.mainpanel.IUndoHandler;
import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessor;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxPreferences;
import javax.swing.*;
import javax.swing.event.CaretListener;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
import javax.swing.text.PlainDocument;
import javax.swing.undo.UndoManager;
import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.MouseListener;
import java.util.HashMap;
import org.fife.ui.rtextarea.RTextScrollPane;
public class RSyntaxSQLEntryPanel extends BaseSQLEntryPanel
{
/** Logger for this class. */
private static final ILogger s_log = LoggerController.createLogger(RSyntaxSQLEntryPanel.class);
/** Text component. */
private SquirrelRSyntaxTextArea _textArea;
private ISession _session;
private RSyntaxPropertiesWrapper _propertiesWrapper;
@SuppressWarnings("unused")
private DropTarget dt;
private RTextScrollPane _textScrollPane;
RSyntaxSQLEntryPanel(ISession session, SyntaxPreferences prefs, HashMap<String, Object> props)
{
super(session.getApplication());
if (session == null)
{
throw new IllegalArgumentException("Null ISession passed");
}
_session = session;
_propertiesWrapper = new RSyntaxPropertiesWrapper(props);
_textArea = new SquirrelRSyntaxTextArea(session, prefs, _propertiesWrapper, getIdentifier());
_textScrollPane = new RTextScrollPane(_textArea);
_textScrollPane.setLineNumbersEnabled(prefs.isLineNumbersEnabled());
dt = new DropTarget(_textArea, new FileEditorDropTargetListener(session));
}
public int getCaretLineNumber()
{
final int pos = getCaretPosition();
final Document doc = _textArea.getDocument();
final Element docElem = doc.getDefaultRootElement();
return docElem.getElementIndex(pos);
}
/**
* @see ISQLEntryPanel#gettextComponent()
*/
public JTextComponent getTextComponent()
{
return _textArea;
}
/**
* If the component returned by <TT>getTextComponent</TT> contains its own
* scroll bars return <TT>true</TT> other wise this component will be
* wrapped in the scroll pane when added to the SQL panel.
*
* @return <TT>true</TT> if text component already handles scrolling.
*/
public boolean getDoesTextComponentHaveScroller()
{
return false;
}
/**
* @see ISQLEntryPanel#getText()
*/
public String getText()
{
return _textArea.getText();
}
public void setFont(Font font)
{
// See SQLSettingsInitializer to find out how fonts are
// _textArea.setFont(font);
}
/**
* @see ISQLEntryPanel#getSelectedText()
*/
public String getSelectedText()
{
return _textArea.getSelectedText();
}
/**
* Replace the contents of the SQL entry area with the passed SQL script
* without selecting it.
*
* @param sqlScript
* The script to be placed in the SQL entry area..
*/
public void setText(String text)
{
setText(text, true);
triggerParser();
}
/**
* Replace the contents of the SQL entry area with the passed SQL script and
* specify whether to select it.
*
* @param sqlScript
* The script to be placed in the SQL entry area..
* @param select
* If <TT>true</TT> then select the passed script in the sql
* entry area.
*/
public void setText(String text, boolean select)
{
_textArea.setText(text);
if (select)
{
setSelectionEnd(_textArea.getDocument().getLength());
setSelectionStart(0);
}
triggerParser();
}
/**
* Append the passed SQL script to the SQL entry area but don't select it.
*
* @param sqlScript
* The script to be appended.
*/
public void appendText(String sqlScript)
{
appendText(sqlScript, false);
}
/**
* Append the passed SQL script to the SQL entry area and specify whether it
* should be selected.
*
* @param sqlScript
* The script to be appended.
* @param select
* If <TT>true</TT> then select the passed script in the sql
* entry area.
*/
public void appendText(String sqlScript, boolean select)
{
Document doc = _textArea.getDocument();
try
{
int start = 0;
if (select)
{
start = doc.getLength();
}
doc.insertString(doc.getLength(), sqlScript, null);
if (select)
{
setSelectionEnd(doc.getLength());
setSelectionStart(start);
}
triggerParser();
} catch (Exception ex)
{
s_log.error("Error appending text to text area", ex);
}
}
/**
* @see ISQLEntryPanel#getCaretPosition()
*/
public int getCaretPosition()
{
return _textArea.getCaretPosition();
}
public void setCaretPosition(int value)
{
_textArea.setCaretPosition(value);
}
/**
* @see ISQLEntryPanel#setTabSize(int)
*/
public void setTabSize(int tabSize)
{
_textArea.getDocument().putProperty(PlainDocument.tabSizeAttribute,
Integer.valueOf(tabSize));
}
/**
* @see ISQLEntryPanel#getSelectionStart()
*/
public int getSelectionStart()
{
return _textArea.getSelectionStart();
}
/**
* @see ISQLEntryPanel#setSelectionStart(int)
*/
public void setSelectionStart(int pos)
{
_textArea.setSelectionStart(pos);
}
/**
* @see ISQLEntryPanel#getSelectionEnd()
*/
public int getSelectionEnd()
{
return _textArea.getSelectionEnd();
}
/**
* @see ISQLEntryPanel#setSelectionEnd(int)
*/
public void setSelectionEnd(int pos)
{
_textArea.setSelectionEnd(pos);
}
/**
* Replace the currently selected text in the SQL entry area with the passed
* text.
*
* @param sqlScript
* The script to be placed in the SQL entry area.
*/
public void replaceSelection(String sqlScript)
{
_textArea.replaceSelection(sqlScript);
triggerParser();
}
private void triggerParser()
{
IParserEventsProcessor parserEventsProcessor = _propertiesWrapper.getParserEventsProcessor(getIdentifier(), _session);
if (null != parserEventsProcessor)
{
parserEventsProcessor.triggerParser();
}
}
/**
* @see ISQLEntryPanel#hasFocus()
*/
public boolean hasFocus()
{
return _textArea.hasFocus();
}
/**
* @see ISQLEntryPanel#requestFocus()
*/
public void requestFocus()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
_textArea.requestFocus();
}
});
}
/**
* @see ISQLEntryPanel#addMouseListener(java.awt.event.MouseListener)
*/
public void addMouseListener(MouseListener lis)
{
_textArea.addMouseListener(lis);
}
/**
* @see ISQLEntryPanel#removeMouseListener(java.awt.event.MouseListener)
*/
public void removeMouseListener(MouseListener lis)
{
_textArea.removeMouseListener(lis);
}
public void updateFromPreferences()
{
_textArea.updateFromPreferences();
}
/**
* @see ISQLEntryPanel#addUndoableEditListener(javax.swing.event.UndoableEditListener)
*/
public void addUndoableEditListener(UndoableEditListener listener)
{
_textArea.addUndoableEditListener(listener);
}
/**
* @see ISQLEntryPanel#removeUndoableEditListener(javax.swing.event.UndoableEditListener)
*/
public void removeUndoableEditListener(UndoableEditListener listener)
{
_textArea.getDocument().removeUndoableEditListener(listener);
}
/**
* @see ISQLEntryPanel#getCaretLinePosition()
*/
public int getCaretLinePosition()
{
String textTillCarret = getText().substring(0, getCaretPosition());
int lineFeedIndex = textTillCarret.lastIndexOf('\n');
if (-1 == lineFeedIndex)
{
return getCaretPosition();
} else
{
return getCaretPosition() - lineFeedIndex - 1;
}
// this didn't work
// final int pos = getCaretPosition();
// final Document doc = _textArea.getStyledDocument();
// final Element docElem = doc.getDefaultRootElement();
// final Element lineElem = docElem.getElement(getCaretLineNumber());
// return lineElem.getElementIndex(pos);
}
/**
* @see ISQLEntryPanel#addCaretListener(javax.swing.event.CaretListener)
*/
public void addCaretListener(CaretListener lis)
{
_textArea.addCaretListener(lis);
}
/**
* @see ISQLEntryPanel#removeCaretListener(javax.swing.event.CaretListener)
*/
public void removeCaretListener(CaretListener lis)
{
_textArea.removeCaretListener(lis);
}
public void addSQLTokenListener(SQLTokenListener tl)
{
_textArea.addSQLTokenListeners(_session, tl);
}
public void removeSQLTokenListener(SQLTokenListener tl)
{
_textArea.removeSQLTokenListeners(_session, tl);
}
public ISession getSession()
{
return _session;
}
// public void showFindDialog(ActionEvent evt)
// {
// SQLKit kit = (SQLKit) _textArea.getEditorKit();
// kit.getActionByName(ExtKit.findAction).actionPerformed(evt);
// }
//
// public void showReplaceDialog(ActionEvent evt)
// {
// SQLKit kit = (SQLKit) _textArea.getEditorKit();
// kit.getActionByName(ExtKit.replaceAction).actionPerformed(evt);
// }
/**
* @see ISQLEntryPanel#hasOwnUndoableManager()
*/
public boolean hasOwnUndoableManager()
{
return true;
}
@Override
public IUndoHandler createUndoHandler()
{
return _textArea.createUndoHandler(); //To change body of overridden methods use File | Settings | File Templates.
}
public void setUndoManager(UndoManager manager)
{
//_textArea.setUndoManager(manager);
}
/**
* Sets the session referenced by this class to null so that it can be
* garbage-collected.
*/
public void sessionEnding()
{
_session = null;
}
@Override
public JScrollPane createScrollPane(JTextComponent textComponent)
{
return _textScrollPane;
}
}
--- NEW FILE: SquirrelTokenMakerBase.java ---
/* The following code was generated by JFlex 1.4.3 on 18.10.09 22:57 */
/*
* 02/15/2005
*
* SQLTokenMaker.java - Scanner for SQL.
* Copyright (C) 2005 Robert Futrell
* robert_futrell at users.sourceforge.net
* http://fifesoft.com/rsyntaxtextarea
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import java.io.*;
import javax.swing.text.Segment;
import org.fife.ui.rsyntaxtextarea.*;
/**
* This class generates tokens representing a text stream as SQL.<p>
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.<p>
*
* The actual algorithm generated for scanning has, of course, not been
* modified.<p>
*
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated SQLTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
* @version 0.5
*
*/
public class SquirrelTokenMakerBase extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
public static final int STRING = 2;
public static final int YYINITIAL = 0;
public static final int MLC = 6;
public static final int CHAR = 4;
/**
* Translates characters to character classes
*/
private static final String ZZ_CMAP_PACKED =
"\11\0\1\4\1\1\25\0\1\4\1\0\1\21\4\0\1\22\2\15"+
"\1\13\1\11\1\0\1\12\1\17\1\14\12\3\1\16\1\0\1\10"+
"\1\7\1\6\2\0\4\2\1\20\25\2\1\23\1\0\1\24\1\0"+
"\1\5\1\0\4\2\1\20\25\2\uff85\0";
/**
* Translates characters to character classes
*/
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
/**
* Translates DFA states to action switch labels.
*/
private static final int [] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 =
"\10\0\1\1\1\2\1\1\1\3\1\4\7\5\1\6"+
"\1\1\1\7\1\10\1\11\1\12\1\13\1\14\1\15"+
"\1\13\1\16\1\17\1\13\1\20\1\13\1\1\1\3"+
"\1\7\1\0\1\4\3\5\1\21\1\22\1\1\1\7"+
"\1\0\1\12\1\23\2\13\1\24\1\7\1\0\1\7"+
"\1\0\1\21\1\1\1\7\1\0\1\7\1\0";
private static int [] zzUnpackAction() {
int [] result = new int[63];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\0\0\25\0\25\0\52\0\52\0\77\0\77"+
"\0\124\0\124\0\151\0\176\0\223\0\250\0\124\0\275"+
"\0\124\0\322\0\124\0\347\0\124\0\374\0\u0111\0\124"+
"\0\124\0\u0126\0\u013b\0\124\0\u0150\0\u0165\0\124\0\u017a"+
"\0\u018f\0\124\0\u01a4\0\151\0\176\0\u01b9\0\u01ce\0\223"+
"\0\124\0\124\0\124\0\u01e3\0\124\0\u01f8\0\u0111\0\u020d"+
"\0\u0126\0\124\0\124\0\124\0\124\0\u01b9\0\u0222\0\u0237"+
"\0\u0237\0\u01e3\0\u01f8\0\u024c\0\u024c\0\u0261\0\u0261";
private static int [] zzUnpackRowMap() {
int [] result = new int[63];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int high = packed.charAt(i++) << 16;
result[j++] = high | packed.charAt(i++);
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int [] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 =
"\1\11\1\12\1\13\1\14\1\15\1\11\1\16\1\17"+
"\1\20\1\21\1\22\1\23\1\24\1\25\1\26\1\27"+
"\1\13\1\30\1\31\1\32\1\11\1\33\1\34\17\33"+
"\1\35\3\33\1\36\1\37\20\36\1\40\2\36\1\41"+
"\1\42\11\41\1\43\11\41\27\0\2\44\1\0\1\44"+
"\12\0\1\44\7\0\1\45\13\0\1\46\1\47\10\0"+
"\1\50\27\0\1\51\23\0\1\52\1\53\27\0\1\54"+
"\25\0\1\55\13\0\1\56\15\0\1\56\7\0\1\57"+
"\14\0\1\60\4\0\24\61\1\62\1\33\1\0\17\33"+
"\1\0\3\33\21\0\1\63\3\0\1\36\1\0\20\36"+
"\1\0\2\36\22\0\1\64\2\0\1\41\1\0\11\41"+
"\1\0\11\41\14\0\1\65\13\0\1\66\14\0\1\67"+
"\7\0\1\70\5\0\2\71\12\0\1\72\1\0\23\72"+
"\2\0\2\73\1\0\1\73\12\0\1\73\7\0\1\74"+
"\5\0\2\75\15\0\1\76\5\0\2\77\15\0\1\70"+
"\24\0\1\74\24\0\1\76\21\0";
private static int [] zzUnpackTrans() {
int [] result = new int[630];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
value--;
do result[j++] = value; while (--count > 0);
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2;
/* error messages for the codes above */
private static final String ZZ_ERROR_MSG[] = {
"Unkown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};
/**
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\10\0\2\11\4\1\1\11\1\1\1\11\1\1\1\11"+
"\1\1\1\11\2\1\2\11\2\1\1\11\2\1\1\11"+
"\2\1\1\11\4\1\1\0\1\1\3\11\1\1\1\11"+
"\2\1\1\0\1\1\4\11\1\1\1\0\1\1\1\0"+
"\3\1\1\0\1\1\1\0";
private static int [] zzUnpackAttribute() {
int [] result = new int[63];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
private int zzState;
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/** this buffer contains the current text to be matched and is
the source of the yytext() string */
private char zzBuffer[];
/** the textposition at the last accepting state */
private int zzMarkedPos;
/** the current text position in the buffer */
private int zzCurrentPos;
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/** endRead marks the last character in the buffer, that has been read
from input */
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
*/
public SquirrelTokenMakerBase() {
super();
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos-1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start,end, tokenType, so);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param array The character array.
* @param start The starting offset in the array.
* @param end The ending offset in the array.
* @param tokenType The token's type.
* @param startOffset The offset in the document at which this token
* occurs.
*/
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start,end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* Returns the text to place at the beginning and end of a
* line to "comment" it in a this programming language.
*
* @return The start and end strings to add to a line to "comment"
* it out.
*/
public String[] getLineCommentStartAndEnd() {
return new String[] { "--", null };
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
*
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
*/
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
resetTokenList();
this.offsetShift = -text.offset + startOffset;
// Start off in the proper state.
int state = Token.NULL;
switch (initialTokenType) {
case Token.LITERAL_STRING_DOUBLE_QUOTE:
state = STRING;
start = text.offset;
break;
case Token.LITERAL_CHAR:
state = CHAR;
start = text.offset;
break;
case Token.COMMENT_MULTILINE:
state = MLC;
start = text.offset;
break;
default:
state = Token.NULL;
}
s = text;
try {
yyreset(zzReader);
yybegin(state);
return yylex();
} catch (IOException ioe) {
ioe.printStackTrace();
return new DefaultToken();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos>=s.offset+s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
*
* @param reader the new input stream
*/
public final void yyreset(java.io.Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
*/
//zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
zzEndRead = zzStartRead + s.count - 1;
zzCurrentPos = zzMarkedPos = s.offset;
zzLexicalState = YYINITIAL;
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
*
* @param in the java.io.Reader to read input from.
*/
public SquirrelTokenMakerBase(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
*
* @param in the java.io.Inputstream to read input from.
*/
public SquirrelTokenMakerBase(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char [] zzUnpackCMap(String packed) {
char [] map = new char[0x10000];
int i = 0; /* index in packed string */
int j = 0; /* index in unpacked array */
while (i < 72) {
int count = packed.charAt(i++);
char value = packed.charAt(i++);
do map[j++] = value; while (--count > 0);
}
return map;
}
/**
* Closes the input stream.
*/
public final void yyclose() throws java.io.IOException {
zzAtEOF = true; /* indicate end of file */
zzEndRead = zzStartRead; /* invalidate buffer */
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState the new lexical state
*/
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos the position of the character to fetch.
* A value from 0 to yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead+pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
* This number must not be greater than yylength()!
*/
public void yypushback(int number) {
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
char [] zzBufferL = zzBuffer;
char [] zzCMapL = ZZ_CMAP;
int [] zzTransL = ZZ_TRANS;
int [] zzRowMapL = ZZ_ROWMAP;
int [] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
}
else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
}
else {
zzInput = zzBufferL[zzCurrentPosL++];
}
}
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
if (zzNext == -1) break zzForAction;
zzState = zzNext;
int zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 19:
{ addToken(Token.PREPROCESSOR);
}
case 21: break;
case 2:
{ addNullToken(); return firstToken;
}
case 22: break;
case 20:
{ yybegin(YYINITIAL); addToken(start,zzStartRead+1, Token.COMMENT_MULTILINE);
}
case 23: break;
case 18:
{ start = zzMarkedPos-2; yybegin(MLC);
}
case 24: break;
case 4:
{ addToken(Token.WHITESPACE);
}
case 25: break;
case 14:
{ addToken(start,zzStartRead-1, Token.LITERAL_CHAR); return firstToken;
}
case 26: break;
case 9:
{ start = zzMarkedPos-1; yybegin(CHAR);
}
case 27: break;
case 7:
{ addToken(Token.LITERAL_NUMBER_FLOAT);
}
case 28: break;
case 6:
{ addToken(Token.SEPARATOR);
}
case 29: break;
case 15:
{ yybegin(YYINITIAL); addToken(start,zzStartRead, Token.LITERAL_CHAR);
}
case 30: break;
case 1:
{ addToken(Token.IDENTIFIER);
}
case 31: break;
case 12:
{ addToken(start,zzStartRead-1, Token.LITERAL_STRING_DOUBLE_QUOTE); return firstToken;
}
case 32: break;
case 17:
{ addToken(Token.COMMENT_EOL);
}
case 33: break;
case 8:
{ start = zzMarkedPos-1; yybegin(STRING);
}
case 34: break;
case 3:
{ addToken(Token.LITERAL_NUMBER_DECIMAL_INT);
}
case 35: break;
case 5:
{ addToken(Token.OPERATOR);
}
case 36: break;
case 13:
{ yybegin(YYINITIAL); addToken(start,zzStartRead, Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 37: break;
case 10:
{ addToken(Token.ERROR_IDENTIFIER); addNullToken(); return firstToken;
}
case 38: break;
case 11:
{
}
case 39: break;
case 16:
{ addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken;
}
case 40: break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case STRING: {
addToken(start,zzStartRead-1, Token.LITERAL_STRING_DOUBLE_QUOTE); return firstToken;
}
case 64: break;
case YYINITIAL: {
addNullToken(); return firstToken;
}
case 65: break;
case MLC: {
addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken;
}
case 66: break;
case CHAR: {
addToken(start,zzStartRead-1, Token.LITERAL_CHAR); return firstToken;
}
case 67: break;
default:
return null;
}
}
else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
}
--- NEW FILE: RSyntaxHighlightTokenMatcher.java ---
package net.sourceforge.squirrel_sql.plugins.syntax.rsyntax;
import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessor;
import net.sourceforge.squirrel_sql.client.session.parser.ParserEventsAdapter;
import net.sourceforge.squirrel_sql.client.session.parser.kernel.ErrorInfo;
import net.sourceforge.squirrel_sql.client.session.schemainfo.SchemaInfo;
import net.sourceforge.squirrel_sql.client.session.schemainfo.CaseInsensitiveString;
import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
import javax.swing.*;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Arrays;
public class RSyntaxHighlightTokenMatcher implements ISyntaxHighlightTokenMatcher
{
private ISession _sess;
private SquirrelRSyntaxTextArea _squirrelRSyntaxTextArea;
private CaseInsensitiveString _caseInsensitiveStringBuffer = new CaseInsensitiveString();
private Hashtable<CaseInsensitiveString, String> _knownTables =
new Hashtable<CaseInsensitiveString, String>();
private Vector<SQLTokenListener> _sqlTokenListeners = new Vector<SQLTokenListener>();
private Vector<ErrorInfo> _currentErrorInfos = new Vector<ErrorInfo>();
public RSyntaxHighlightTokenMatcher(ISession sess, SquirrelRSyntaxTextArea squirrelRSyntaxTextArea, IParserEventsProcessor parserEventsProcessor)
{
}
public RSyntaxHighlightTokenMatcher(ISession sess, SquirrelRSyntaxTextArea squirrelRSyntaxTextArea, final IIdentifier sqlEntryPanelIdentifier, final RSyntaxPropertiesWrapper rSyntaxPropertiesWrapper)
{
_sess = sess;
_squirrelRSyntaxTextArea = squirrelRSyntaxTextArea;
SwingUtilities.invokeLater(new Runnable()
{
// Invoke later because of initialization problems when getParserEventsProcessor() is called directly from the constructor.
public void run()
{
initParsing(rSyntaxPropertiesWrapper, sqlEntryPanelIdentifier);
}
});
}
private void initParsing(RSyntaxPropertiesWrapper rSyntaxPropertiesWrapper, IIdentifier sqlEntryPanelIdentifier)
{
IParserEventsProcessor parserEventsProcessor = rSyntaxPropertiesWrapper.getParserEventsProcessor(sqlEntryPanelIdentifier, _sess);
if (null != parserEventsProcessor)
{
parserEventsProcessor.addParserEventsListener(new ParserEventsAdapter()
{
@Override
public void errorsFound(ErrorInfo[] errorInfos)
{
onErrorsFound(errorInfos);
}
});
}
}
private void onErrorsFound(ErrorInfo[] errorInfos)
{
boolean errorsChanged = false;
if(_currentErrorInfos.size() == errorInfos.length)
{
for (int i = 0; i < errorInfos.length; i++)
{
if(false == errorInfos[i].equals(_currentErrorInfos.get(i)))
{
errorsChanged = true;
break;
}
}
}
else
{
errorsChanged = true;
}
if(errorsChanged)
{
_currentErrorInfos.clear();
_currentErrorInfos.addAll(Arrays.asList(errorInfos));
_squirrelRSyntaxTextArea.repaint();
}
}
@Override
public boolean isError(int offset, int len)
{
//System.out.println("Error: offset = " + offset + " len = " + len);
for (int i = 0; i < _currentErrorInfos.size(); i++)
{
ErrorInfo errInf = _currentErrorInfos.elementAt(i);
if(offset <= errInf.beginPos && errInf.endPos <= offset + len)
{
return true;
}
}
return false;
}
public boolean isTable(char[] buffer, int offset, int len)
{
_caseInsensitiveStringBuffer.setCharBuffer(buffer, offset, len);
// No new here, method is called very often
int tableExtRes = _sess.getSchemaInfo().isTableExt(_caseInsensitiveStringBuffer);
if(SchemaInfo.TABLE_EXT_COLS_LOADED_BEFORE == tableExtRes || SchemaInfo.TABLE_EXT_COLS_LOADED_IN_THIS_CALL == tableExtRes)
{
// _knownTables is just a cache to prevent creating a new String each time
String table = _knownTables.get(_caseInsensitiveStringBuffer);
if(null == table)
{
table = new String(buffer, offset, len);
_knownTables.put(new CaseInsensitiveString(table), table);
}
if(SchemaInfo.TABLE_EXT_COLS_LOADED_IN_THIS_CALL == tableExtRes)
{
_squirrelRSyntaxTextArea.repaint();
}
fireTableOrViewFound(table);
return true;
}
return false;
}
private void fireTableOrViewFound(String tableOrViewName)
{
for (int i = 0; i < _sqlTokenListeners.size(); i++)
{
SQLTokenListener sqlTokenListener = _sqlTokenListeners.elementAt(i);
sqlTokenListener.tableOrViewFound(tableOrViewName);
}
}
public void addSQLTokenListener(SQLTokenListener tl)
{
removeSQLTokenListener(tl);
_sqlTokenListeners.add(tl);
}
public boolean isFunction(char[] buffer, int offset, int len)
{
_caseInsensitiveStringBuffer.setCharBuffer(buffer, offset, len);
if(_sess.getSchemaInfo().isFunction(_caseInsensitiveStringBuffer))
{
return true;
}
if(_sess.getSchemaInfo().isProcedure(_caseInsensitiveStringBuffer))
{
return true;
}
return false;
}
public boolean isDataType(char[] buffer, int offset, int len)
{
_caseInsensitiveStringBuffer.setCharBuffer(buffer, offset, len);
if(_sess.getSchemaInfo().isDataType(_caseInsensitiveStringBuffer))
{
return true;
}
return false;
}
public boolean isStatementSeparator(char[] buffer, int offset, int len)
{
_caseInsensitiveStringBuffer.setCharBuffer(buffer, offset, len);
String statSep = _sess.getQueryTokenizer().getSQLStatementSeparator();
if(statSep.length() != len)
{
return false;
}
// no new here, method is called very often.
for(int i=0; i < statSep.length(); ++i)
{
if(buffer[offset +i] != statSep.charAt(i))
{
return false;
}
}
return true;
}
public boolean isColumn(char[] buffer, int offset, int len)
{
// No new here, method is called very often
//String s = new String(buffer, ...
[truncated message content] |