KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > ed > VOvrCaret


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.grid.ed;
15
16 import javax.swing.*;
17 import javax.swing.plaf.*;
18 import javax.swing.text.*;
19 import java.awt.*;
20
21 /**
22  * Overwrite Caret
23  *
24  * @author Jorg Janke
25  * @version $Id: VOvrCaret.java,v 1.2 2001/10/16 03:02:12 jjanke Exp $
26  */

27 public class VOvrCaret extends DefaultCaret
28 {
29     /**
30      * Constructor
31      */

32     public VOvrCaret()
33     {
34         super();
35     } // VOvrCaret
36

37     /**
38      * Renders the caret as a top and button bracket.
39      *
40      * @param g the graphics context
41      * @see #damage
42      */

43     public void paint(Graphics g)
44     {
45         boolean dotLTR = true; // left-to-right
46
Position.Bias dotBias = Position.Bias.Forward;
47
48         //
49
if (isVisible())
50         {
51             try
52             {
53                 TextUI mapper = getComponent().getUI();
54                 Rectangle r = mapper.modelToView(getComponent(), getDot(), dotBias);
55                 Rectangle e = mapper.modelToView(getComponent(), getDot()+1, dotBias);
56             // g.setColor(getComponent().getCaretColor());
57
g.setColor(Color.blue);
58                 //
59
int cWidth = e.x-r.x;
60                 int cHeight = 4;
61                 int cThick = 2;
62                 //
63
g.fillRect(r.x-1, r.y, cWidth, cThick); // top
64
g.fillRect(r.x-1, r.y, cThick, cHeight); // |
65
g.fillRect(r.x-1+cWidth, r.y, cThick, cHeight); // |
66
//
67
int yStart = r.y+r.height;
68                 g.fillRect(r.x-1, yStart-cThick, cWidth, cThick); // button
69
g.fillRect(r.x-1, yStart-cHeight, cThick, cHeight); // |
70
g.fillRect(r.x-1+cWidth, yStart-cHeight, cThick, cHeight); // |
71
}
72             catch (BadLocationException e)
73             {
74                 // can't render
75
// System.err.println("Can't render cursor");
76
}
77         } // isVisible
78
} // paint
79

80     /**
81      * Damages the area surrounding the caret to cause
82      * it to be repainted in a new location.
83      * This method should update the caret bounds (x, y, width, and height).
84      *
85      * @param r the current location of the caret
86      * @see #paint
87      */

88     protected synchronized void damage(Rectangle r)
89     {
90         if (r != null)
91         {
92             x = r.x - 4; // start 4 pixles before (one required)
93
y = r.y;
94             width = 18; // sufficent for standard font (18-4=14)
95
height = r.height;
96             repaint();
97         }
98     } // damage
99

100 } // VOvrCaret
101
Popular Tags