Mercurial > hg > RemoteEditor > Eclipse
changeset 175:db798192c966
*** empty log message ***
author | pin |
---|---|
date | Sat, 30 Aug 2008 11:44:32 +0900 |
parents | d234a9d2a172 |
children | 9e38daf60905 |
files | bin/remoteeditor/editors/ColorManager.class bin/remoteeditor/editors/IXMLColorConstants.class bin/remoteeditor/editors/NonRuleBasedDamagerRepairer.class bin/remoteeditor/editors/TagRule.class bin/remoteeditor/editors/XMLConfiguration.class bin/remoteeditor/editors/XMLDocumentProvider.class bin/remoteeditor/editors/XMLDoubleClickStrategy.class bin/remoteeditor/editors/XMLEditor.class bin/remoteeditor/editors/XMLPartitionScanner.class bin/remoteeditor/editors/XMLScanner.class bin/remoteeditor/editors/XMLTagScanner.class bin/remoteeditor/editors/XMLWhitespaceDetector.class src/remoteeditor/editors/ColorManager.java src/remoteeditor/editors/IXMLColorConstants.java src/remoteeditor/editors/NonRuleBasedDamagerRepairer.java src/remoteeditor/editors/TagRule.java src/remoteeditor/editors/XMLConfiguration.java src/remoteeditor/editors/XMLDocumentProvider.java src/remoteeditor/editors/XMLDoubleClickStrategy.java src/remoteeditor/editors/XMLEditor.java src/remoteeditor/editors/XMLPartitionScanner.java src/remoteeditor/editors/XMLScanner.java src/remoteeditor/editors/XMLTagScanner.java src/remoteeditor/editors/XMLWhitespaceDetector.java |
diffstat | 24 files changed, 0 insertions(+), 521 deletions(-) [+] |
line wrap: on
line diff
--- a/src/remoteeditor/editors/ColorManager.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package remoteeditor.editors; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -public class ColorManager { - - protected Map<RGB, Color> fColorTable = new HashMap<RGB, Color>(10); - - public void dispose() { - Iterator<Color> e = fColorTable.values().iterator(); - while (e.hasNext()) - e.next().dispose(); - } - public Color getColor(RGB rgb) { - Color color = fColorTable.get(rgb); - if (color == null) { - color = new Color(Display.getCurrent(), rgb); - fColorTable.put(rgb, color); - } - return color; - } -}
--- a/src/remoteeditor/editors/IXMLColorConstants.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.swt.graphics.RGB; - -public interface IXMLColorConstants { - RGB XML_COMMENT = new RGB(128, 0, 0); - RGB PROC_INSTR = new RGB(128, 128, 128); - RGB STRING = new RGB(0, 128, 0); - RGB DEFAULT = new RGB(0, 0, 0); - RGB TAG = new RGB(0, 0, 128); -}
--- a/src/remoteeditor/editors/NonRuleBasedDamagerRepairer.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.presentation.IPresentationDamager; -import org.eclipse.jface.text.presentation.IPresentationRepairer; -import org.eclipse.jface.util.Assert; -import org.eclipse.swt.custom.StyleRange; - -public class NonRuleBasedDamagerRepairer - implements IPresentationDamager, IPresentationRepairer { - - /** The document this object works on */ - protected IDocument fDocument; - /** The default text attribute if non is returned as data by the current token */ - protected TextAttribute fDefaultTextAttribute; - - /** - * Constructor for NonRuleBasedDamagerRepairer. - */ - public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) { - Assert.isNotNull(defaultTextAttribute); - - fDefaultTextAttribute = defaultTextAttribute; - } - - /** - * @see IPresentationRepairer#setDocument(IDocument) - */ - public void setDocument(IDocument document) { - fDocument = document; - } - - /** - * Returns the end offset of the line that contains the specified offset or - * if the offset is inside a line delimiter, the end offset of the next line. - * - * @param offset the offset whose line end offset must be computed - * @return the line end offset for the given offset - * @exception BadLocationException if offset is invalid in the current document - */ - protected int endOfLineOf(int offset) throws BadLocationException { - - IRegion info = fDocument.getLineInformationOfOffset(offset); - if (offset <= info.getOffset() + info.getLength()) - return info.getOffset() + info.getLength(); - - int line = fDocument.getLineOfOffset(offset); - try { - info = fDocument.getLineInformation(line + 1); - return info.getOffset() + info.getLength(); - } catch (BadLocationException x) { - return fDocument.getLength(); - } - } - - /** - * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean) - */ - public IRegion getDamageRegion( - ITypedRegion partition, - DocumentEvent event, - boolean documentPartitioningChanged) { - if (!documentPartitioningChanged) { - try { - - IRegion info = - fDocument.getLineInformationOfOffset(event.getOffset()); - int start = Math.max(partition.getOffset(), info.getOffset()); - - int end = - event.getOffset() - + (event.getText() == null - ? event.getLength() - : event.getText().length()); - - if (info.getOffset() <= end - && end <= info.getOffset() + info.getLength()) { - // optimize the case of the same line - end = info.getOffset() + info.getLength(); - } else - end = endOfLineOf(end); - - end = - Math.min( - partition.getOffset() + partition.getLength(), - end); - return new Region(start, end - start); - - } catch (BadLocationException x) { - } - } - - return partition; - } - - /** - * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion) - */ - public void createPresentation( - TextPresentation presentation, - ITypedRegion region) { - addRange( - presentation, - region.getOffset(), - region.getLength(), - fDefaultTextAttribute); - } - - /** - * Adds style information to the given text presentation. - * - * @param presentation the text presentation to be extended - * @param offset the offset of the range to be styled - * @param length the length of the range to be styled - * @param attr the attribute describing the style of the range to be styled - */ - protected void addRange( - TextPresentation presentation, - int offset, - int length, - TextAttribute attr) { - if (attr != null) - presentation.addStyleRange( - new StyleRange( - offset, - length, - attr.getForeground(), - attr.getBackground(), - attr.getStyle())); - } -} \ No newline at end of file
--- a/src/remoteeditor/editors/TagRule.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.rules.*; - -public class TagRule extends MultiLineRule { - - public TagRule(IToken token) { - super("<", ">", token); - } - protected boolean sequenceDetected( - ICharacterScanner scanner, - char[] sequence, - boolean eofAllowed) { - int c = scanner.read(); - if (sequence[0] == '<') { - if (c == '?') { - // processing instruction - abort - scanner.unread(); - return false; - } - if (c == '!') { - scanner.unread(); - // comment - abort - return false; - } - } else if (sequence[0] == '>') { - scanner.unread(); - } - return super.sequenceDetected(scanner, sequence, eofAllowed); - } -}
--- a/src/remoteeditor/editors/XMLConfiguration.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextDoubleClickStrategy; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.PresentationReconciler; -import org.eclipse.jface.text.rules.DefaultDamagerRepairer; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; - -public class XMLConfiguration extends SourceViewerConfiguration { - private XMLDoubleClickStrategy doubleClickStrategy; - private XMLTagScanner tagScanner; - private XMLScanner scanner; - private ColorManager colorManager; - - public XMLConfiguration(ColorManager colorManager) { - this.colorManager = colorManager; - } - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return new String[] { - IDocument.DEFAULT_CONTENT_TYPE, - XMLPartitionScanner.XML_COMMENT, - XMLPartitionScanner.XML_TAG }; - } - public ITextDoubleClickStrategy getDoubleClickStrategy( - ISourceViewer sourceViewer, - String contentType) { - if (doubleClickStrategy == null) - doubleClickStrategy = new XMLDoubleClickStrategy(); - return doubleClickStrategy; - } - - protected XMLScanner getXMLScanner() { - if (scanner == null) { - scanner = new XMLScanner(colorManager); - scanner.setDefaultReturnToken( - new Token( - new TextAttribute( - colorManager.getColor(IXMLColorConstants.DEFAULT)))); - } - return scanner; - } - protected XMLTagScanner getXMLTagScanner() { - if (tagScanner == null) { - tagScanner = new XMLTagScanner(colorManager); - tagScanner.setDefaultReturnToken( - new Token( - new TextAttribute( - colorManager.getColor(IXMLColorConstants.TAG)))); - } - return tagScanner; - } - - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - PresentationReconciler reconciler = new PresentationReconciler(); - - DefaultDamagerRepairer dr = - new DefaultDamagerRepairer(getXMLTagScanner()); - reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG); - reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG); - - dr = new DefaultDamagerRepairer(getXMLScanner()); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - - NonRuleBasedDamagerRepairer ndr = - new NonRuleBasedDamagerRepairer( - new TextAttribute( - colorManager.getColor(IXMLColorConstants.XML_COMMENT))); - reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT); - reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT); - - return reconciler; - } - -} \ No newline at end of file
--- a/src/remoteeditor/editors/XMLDocumentProvider.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.rules.FastPartitioner; -import org.eclipse.ui.editors.text.FileDocumentProvider; - -public class XMLDocumentProvider extends FileDocumentProvider { - - protected IDocument createDocument(Object element) throws CoreException { - IDocument document = super.createDocument(element); - if (document != null) { - IDocumentPartitioner partitioner = - new FastPartitioner( - new XMLPartitionScanner(), - new String[] { - XMLPartitionScanner.XML_TAG, - XMLPartitionScanner.XML_COMMENT }); - partitioner.connect(document); - document.setDocumentPartitioner(partitioner); - } - return document; - } -} \ No newline at end of file
--- a/src/remoteeditor/editors/XMLDoubleClickStrategy.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.*; - -public class XMLDoubleClickStrategy implements ITextDoubleClickStrategy { - protected ITextViewer fText; - - public void doubleClicked(ITextViewer part) { - int pos = part.getSelectedRange().x; - - if (pos < 0) - return; - - fText = part; - - if (!selectComment(pos)) { - selectWord(pos); - } - } - protected boolean selectComment(int caretPos) { - IDocument doc = fText.getDocument(); - int startPos, endPos; - - try { - int pos = caretPos; - char c = ' '; - - while (pos >= 0) { - c = doc.getChar(pos); - if (c == '\\') { - pos -= 2; - continue; - } - if (c == Character.LINE_SEPARATOR || c == '\"') - break; - --pos; - } - - if (c != '\"') - return false; - - startPos = pos; - - pos = caretPos; - int length = doc.getLength(); - c = ' '; - - while (pos < length) { - c = doc.getChar(pos); - if (c == Character.LINE_SEPARATOR || c == '\"') - break; - ++pos; - } - if (c != '\"') - return false; - - endPos = pos; - - int offset = startPos + 1; - int len = endPos - offset; - fText.setSelectedRange(offset, len); - return true; - } catch (BadLocationException x) { - } - - return false; - } - protected boolean selectWord(int caretPos) { - - IDocument doc = fText.getDocument(); - int startPos, endPos; - - try { - - int pos = caretPos; - char c; - - while (pos >= 0) { - c = doc.getChar(pos); - if (!Character.isJavaIdentifierPart(c)) - break; - --pos; - } - - startPos = pos; - - pos = caretPos; - int length = doc.getLength(); - - while (pos < length) { - c = doc.getChar(pos); - if (!Character.isJavaIdentifierPart(c)) - break; - ++pos; - } - - endPos = pos; - selectRange(startPos, endPos); - return true; - - } catch (BadLocationException x) { - } - - return false; - } - - private void selectRange(int startPos, int stopPos) { - int offset = startPos + 1; - int length = stopPos - offset; - fText.setSelectedRange(offset, length); - } -} \ No newline at end of file
--- a/src/remoteeditor/editors/XMLEditor.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.ui.editors.text.TextEditor; - -public class XMLEditor extends TextEditor { - - private ColorManager colorManager; - - public XMLEditor() { - super(); - colorManager = new ColorManager(); - setSourceViewerConfiguration(new XMLConfiguration(colorManager)); - setDocumentProvider(new XMLDocumentProvider()); - } - public void dispose() { - colorManager.dispose(); - super.dispose(); - } - -}
--- a/src/remoteeditor/editors/XMLPartitionScanner.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.rules.*; - -public class XMLPartitionScanner extends RuleBasedPartitionScanner { - public final static String XML_COMMENT = "__xml_comment"; - public final static String XML_TAG = "__xml_tag"; - - public XMLPartitionScanner() { - - IToken xmlComment = new Token(XML_COMMENT); - IToken tag = new Token(XML_TAG); - - IPredicateRule[] rules = new IPredicateRule[2]; - - rules[0] = new MultiLineRule("<!--", "-->", xmlComment); - rules[1] = new TagRule(tag); - - setPredicateRules(rules); - } -}
--- a/src/remoteeditor/editors/XMLScanner.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.rules.*; -import org.eclipse.jface.text.*; - -public class XMLScanner extends RuleBasedScanner { - - public XMLScanner(ColorManager manager) { - IToken procInstr = - new Token( - new TextAttribute( - manager.getColor(IXMLColorConstants.PROC_INSTR))); - - IRule[] rules = new IRule[2]; - //Add rule for processing instructions - rules[0] = new SingleLineRule("<?", "?>", procInstr); - // Add generic whitespace rule. - rules[1] = new WhitespaceRule(new XMLWhitespaceDetector()); - - setRules(rules); - } -}
--- a/src/remoteeditor/editors/XMLTagScanner.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.*; -import org.eclipse.jface.text.rules.*; - -public class XMLTagScanner extends RuleBasedScanner { - - public XMLTagScanner(ColorManager manager) { - IToken string = - new Token( - new TextAttribute(manager.getColor(IXMLColorConstants.STRING))); - - IRule[] rules = new IRule[3]; - - // Add rule for double quotes - rules[0] = new SingleLineRule("\"", "\"", string, '\\'); - // Add a rule for single quotes - rules[1] = new SingleLineRule("'", "'", string, '\\'); - // Add generic whitespace rule. - rules[2] = new WhitespaceRule(new XMLWhitespaceDetector()); - - setRules(rules); - } -}
--- a/src/remoteeditor/editors/XMLWhitespaceDetector.java Sat Aug 30 11:35:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -package remoteeditor.editors; - -import org.eclipse.jface.text.rules.IWhitespaceDetector; - -public class XMLWhitespaceDetector implements IWhitespaceDetector { - - public boolean isWhitespace(char c) { - return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); - } -}