Documentation update from php.net
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / BracketPainter.java
index e105679..e73790b 100644 (file)
@@ -19,43 +19,47 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Point;
 
-
 public final class BracketPainter implements IPainter, PaintListener {
 
-       private PHPPairMatcher fMatcher= new PHPPairMatcher(new char[] { '{', '}', '(', ')', '[', ']' });
-       private Position fBracketPosition= new Position(0, 0);
+       private PHPPairMatcher fMatcher = new PHPPairMatcher(new char[] { '{', '}',
+                       '(', ')', '[', ']' });
+
+       private Position fBracketPosition = new Position(0, 0);
+
        private int fAnchor;
 
-       private boolean fIsActive= false;
+       private boolean fIsActive = false;
+
        private ISourceViewer fSourceViewer;
+
        private StyledText fTextWidget;
+
        private Color fColor;
 
        private IPositionManager fPositionManager;
 
-
        public BracketPainter(ISourceViewer sourceViewer) {
-               fSourceViewer= sourceViewer;
-               fTextWidget= sourceViewer.getTextWidget();
+               fSourceViewer = sourceViewer;
+               fTextWidget = sourceViewer.getTextWidget();
        }
 
        public void setHighlightColor(Color color) {
-               fColor= color;
+               fColor = color;
        }
 
        public void dispose() {
                if (fMatcher != null) {
                        fMatcher.dispose();
-                       fMatcher= null;
+                       fMatcher = null;
                }
 
-               fColor= null;
-               fTextWidget= null;
+               fColor = null;
+               fTextWidget = null;
        }
 
        public void deactivate(boolean redraw) {
                if (fIsActive) {
-                       fIsActive= false;
+                       fIsActive = false;
                        fTextWidget.removePaintListener(this);
                        if (fPositionManager != null)
                                fPositionManager.removeManagedPosition(fBracketPosition);
@@ -74,23 +78,26 @@ public final class BracketPainter implements IPainter, PaintListener {
                if (fBracketPosition.isDeleted)
                        return;
 
-               int offset= fBracketPosition.getOffset();
-               int length= fBracketPosition.getLength();
+               int offset = fBracketPosition.getOffset();
+               int length = fBracketPosition.getLength();
                if (length < 1)
                        return;
 
                if (fSourceViewer instanceof ITextViewerExtension5) {
-                       ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
-                       IRegion widgetRange= extension.modelRange2WidgetRange(new Region(offset, length));
+                       ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
+                       IRegion widgetRange = extension.modelRange2WidgetRange(new Region(
+                                       offset, length));
                        if (widgetRange == null)
                                return;
 
-                       offset= widgetRange.getOffset();
-                       length= widgetRange.getLength();
+                       offset = widgetRange.getOffset();
+                       length = widgetRange.getLength();
 
                } else {
-                       IRegion region= fSourceViewer.getVisibleRegion();
-                       if (region.getOffset() > offset || region.getOffset() + region.getLength() < offset + length)
+                       IRegion region = fSourceViewer.getVisibleRegion();
+                       if (region.getOffset() > offset
+                                       || region.getOffset() + region.getLength() < offset
+                                                       + length)
                                return;
                        offset -= region.getOffset();
                }
@@ -98,16 +105,17 @@ public final class BracketPainter implements IPainter, PaintListener {
                if (PHPPairMatcher.RIGHT == fAnchor)
                        draw(gc, offset, 1);
                else
-                       draw(gc, offset + length -1, 1);
+                       draw(gc, offset + length - 1, 1);
        }
 
        private void draw(GC gc, int offset, int length) {
                if (gc != null) {
-                       Point left= fTextWidget.getLocationAtOffset(offset);
-                       Point right= fTextWidget.getLocationAtOffset(offset + length);
+                       Point left = fTextWidget.getLocationAtOffset(offset);
+                       Point right = fTextWidget.getLocationAtOffset(offset + length);
 
                        gc.setForeground(fColor);
-                       gc.drawRectangle(left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1);
+                       gc.drawRectangle(left.x, left.y, right.x - left.x - 1, gc
+                                       .getFontMetrics().getHeight() - 1);
 
                } else {
                        fTextWidget.redrawRange(offset, length, true);
@@ -118,13 +126,13 @@ public final class BracketPainter implements IPainter, PaintListener {
         * @see IPainter#paint(int)
         */
        public void paint(int reason) {
-               Point selection= fSourceViewer.getSelectedRange();
+               Point selection = fSourceViewer.getSelectedRange();
                if (selection.y > 0) {
                        deactivate(true);
                        return;
                }
 
-               IRegion pair= fMatcher.match(fSourceViewer.getDocument(), selection.x);
+               IRegion pair = fMatcher.match(fSourceViewer.getDocument(), selection.x);
                if (pair == null) {
                        deactivate(true);
                        return;
@@ -132,29 +140,29 @@ public final class BracketPainter implements IPainter, PaintListener {
 
                if (fIsActive) {
                        // only if different
-                       if (pair.getOffset() != fBracketPosition.getOffset() ||
-                                       pair.getLength() != fBracketPosition.getLength() ||
-                                       fMatcher.getAnchor() != fAnchor) {
+                       if (pair.getOffset() != fBracketPosition.getOffset()
+                                       || pair.getLength() != fBracketPosition.getLength()
+                                       || fMatcher.getAnchor() != fAnchor) {
 
                                // remove old highlighting
                                handleDrawRequest(null);
                                // update position
-                               fBracketPosition.isDeleted= false;
-                               fBracketPosition.offset= pair.getOffset();
-                               fBracketPosition.length= pair.getLength();
-                               fAnchor= fMatcher.getAnchor();
+                               fBracketPosition.isDeleted = false;
+                               fBracketPosition.offset = pair.getOffset();
+                               fBracketPosition.length = pair.getLength();
+                               fAnchor = fMatcher.getAnchor();
                                // apply new highlighting
                                handleDrawRequest(null);
 
                        }
                } else {
 
-                       fIsActive= true;
+                       fIsActive = true;
 
-                       fBracketPosition.isDeleted= false;
-                       fBracketPosition.offset= pair.getOffset();
-                       fBracketPosition.length= pair.getLength();
-                       fAnchor= fMatcher.getAnchor();
+                       fBracketPosition.isDeleted = false;
+                       fBracketPosition.offset = pair.getOffset();
+                       fBracketPosition.length = pair.getLength();
+                       fAnchor = fMatcher.getAnchor();
 
                        fTextWidget.addPaintListener(this);
                        fPositionManager.addManagedPosition(fBracketPosition);
@@ -166,6 +174,6 @@ public final class BracketPainter implements IPainter, PaintListener {
         * @see IPainter#setPositionManager(IPositionManager)
         */
        public void setPositionManager(IPositionManager manager) {
-               fPositionManager= manager;
+               fPositionManager = manager;
        }
 }