blob: 8b6ec57d7629cd990d4e6d67264c07258c80bf78 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*******************************************************************************
* Copyright (c) 2004, 2008 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Krasnay - initial API and implementation
*******************************************************************************/
package org.eclipse.vex.core.internal.layout;
import org.eclipse.vex.core.internal.core.Caret;
import org.eclipse.vex.core.internal.core.Color;
import org.eclipse.vex.core.internal.core.ColorResource;
import org.eclipse.vex.core.internal.core.Graphics;
import org.eclipse.vex.core.internal.core.Rectangle;
/**
* A caret drawn as a vertical line between characters.
*/
public class TextCaret extends Caret {
private static final int LINE_WIDTH = 2;
private int height;
/**
* Class constructor
*
* @param x
* x-coordinate of the caret
* @param y
* y-coordinate of the top of the caret
* @param height
* height of the caret
*/
public TextCaret(int x, int y, int height) {
super(x, y);
this.height = height;
}
public void draw(Graphics g, Color color) {
ColorResource newColor = g.createColor(color);
ColorResource oldColor = g.setColor(newColor);
g.fillRect(this.getX(), this.getY(), LINE_WIDTH, height);
g.setColor(oldColor);
newColor.dispose();
}
public Rectangle getBounds() {
return new Rectangle(this.getX(), this.getY(), LINE_WIDTH, height);
}
}
|