001: /*
002: * Javu WingS - Lightweight Java Component Set
003: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004: * e-mail: ksadlocha@programics.com
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.javujavu.javux.wings.text;
022:
023: import java.awt.Dimension;
024: import java.awt.Graphics;
025: import java.awt.Rectangle;
026: import com.javujavu.javux.wings.Style;
027:
028: /**
029: * A class representing line break in <code>WingTextPane</code>
030: * <br><br>
031: * <b>This class is not thread safe
032: * synchronization is provided by WingTextPane</b>
033: */
034: public class BreakRowNode extends TextPaneNode {
035: public BreakRowNode(Style style) {
036: super (style);
037: }
038:
039: protected Dimension size;
040:
041: public int getWidth() {
042: return size.width;
043: }
044:
045: public int getHeight() {
046: return size.height;
047: }
048:
049: public boolean breaksRow() {
050: return true;
051: }
052:
053: public int length() {
054: return 1;
055: }
056:
057: public String getText(int start, int end) {
058: return "\n";
059: }
060:
061: public void invalidate() {
062: size = null;
063: super .invalidate();
064: }
065:
066: public void layout(LayoutContext lc) {
067: if (size == null || lc.revalidate) {
068: size = new Dimension();
069: size.height = getFont().getHeight();
070: size.width = 0;
071: // support for show-eol-char
072: }
073: lc.add(this , false);
074: lc.endRow();
075: valid = true;
076: }
077:
078: public void paint(Graphics g, int x, int y, int selectionStart,
079: int selectionEnd, Style stSelected) {
080: x += bounds.x;
081: y += bounds.y;
082: Rectangle cb = g.getClipBounds();
083: if (cb.x > x + bounds.width || cb.y > y + bounds.height
084: || cb.x + cb.width < x || cb.y + cb.height < y) {
085: return;
086: }
087: if (selectionStart <= 0 && selectionEnd > 0) {
088: g.setColor(stSelected.background);
089: g.drawLine(x, y, x, y + bounds.height - 1);
090: }
091: // else
092: // {
093: // g.setColor(getStyle().foreground);
094: // g.drawLine(x,y,x,y+bounds.height-1);
095: // }
096: }
097:
098: public Rectangle getCharBounds(int pos) {
099: if (pos != 0 || !valid)
100: return null;
101: return new Rectangle(bounds);
102: }
103:
104: public int posAtPoint(int x, int y) {
105: if (x == bounds.x && y >= bounds.y
106: && y < bounds.y + bounds.height)
107: return 0;
108: return -1;
109: }
110:
111: }
|