01: // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
02: //
03: // This software is made available under the terms of the "MIT License"
04: // A copy of this license is included with this source distribution
05: // in "license.txt" and is also available at:
06: // http://www.opensource.org/licenses/mit-license.html
07: // Any queries should be directed to Michael Kolling mik@bluej.org
08:
09: package bluej.editor.moe;
10:
11: import java.awt.*;
12:
13: import javax.swing.text.*;
14:
15: import bluej.utility.Debug;
16:
17: /**
18: * Specialised highlight painter for painting matching bracket in text component as
19: * a rectangle.
20: */
21: public class BracketMatchPainter extends
22: DefaultHighlighter.DefaultHighlightPainter {
23:
24: public BracketMatchPainter(Color colour) {
25: super (colour);
26: }
27:
28: /**
29: * Paints a rectangle around a matching bracket
30: * This seems to be the only method we need to over-ride.
31: *
32: * @return area highlighted
33: */
34: public Shape paintLayer(Graphics g, int begin, int end,
35: Shape bounds, JTextComponent comp, View view) {
36: g.setColor(getColor());
37: Rectangle rect = null;
38: try {
39: Shape shape = view.modelToView(begin,
40: Position.Bias.Forward, end, Position.Bias.Backward,
41: bounds);
42: rect = shape.getBounds();
43: g.drawRect(rect.x, rect.y, rect.width - 1, rect.height - 1);
44: } catch (BadLocationException ble) {
45: Debug.reportError("bad location exception thrown");
46: ble.printStackTrace();
47: }
48: return rect;
49: }
50:
51: }
|