/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Implements View interface for a simple multi-line text view
* that has text in one font and color. The view represents each
* child element as a line of text.
*
* @author Timothy Prinzing
* @see View
*/
/**
* Constructs a new PlainView wrapped on an element.
*
* @param elem the element
*/
super(elem);
}
/**
* Returns the tab size set for the document, defaulting to 8.
*
* @return the tab size
*/
protected int getTabSize() {
return size;
}
/**
* Renders a line of text, suppressing whitespace at the end
* and expanding any tabs. This is implemented to make calls
* to the methods <code>drawUnselectedText</code> and
* <code>drawSelectedText</code> so that the way selected and
* unselected text are rendered can be customized.
*
* @param lineIndex the line to draw >= 0
* @param g the <code>Graphics</code> context
* @param x the starting X position >= 0
* @param y the starting Y position >= 0
* @see #drawUnselectedText
* @see #drawSelectedText
*/
try {
} else {
// this line contains the composed text.
for(int i = 0; i < count; i++) {
}
}
} catch (BadLocationException e) {
}
}
private int drawElement(int lineIndex, Element elem, Graphics g, int x, int y) throws BadLocationException {
if (lineIndex == 0) {
x += firstLineOffset;
}
g.setColor(unselected);
} else {
// no selection, or it is invisible
} else {
}
} else {
}
}
return x;
}
/**
* Renders the given range in the model as normal unselected
* text. Uses the foreground or disabled color to render the text.
*
* @param g the graphics context
* @param x the starting X coordinate >= 0
* @param y the starting Y coordinate >= 0
* @param p0 the beginning position in the model >= 0
* @param p1 the ending position in the model >= 0
* @return the X location of the end of the range >= 0
* @exception BadLocationException if the range is invalid
*/
g.setColor(unselected);
return ret;
}
/**
* Renders the given range in the model as selected text. This
* is implemented to render the text in the color specified in
* the hosting component. It assumes the highlighter will render
* the selected background.
*
* @param g the graphics context
* @param x the starting X coordinate >= 0
* @param y the starting Y coordinate >= 0
* @param p0 the beginning position in the model >= 0
* @param p1 the ending position in the model >= 0
* @return the location of the end of the range
* @exception BadLocationException if the range is invalid
*/
return ret;
}
/**
* Gives access to a buffer that can be used to fetch
* text from the associated document.
*
* @return the buffer
*/
if (lineBuffer == null) {
lineBuffer = new Segment();
}
return lineBuffer;
}
/**
* Checks to see if the font metrics and longest line
* are up-to-date.
*
* @since 1.4
*/
protected void updateMetrics() {
if (font != f) {
// The font changed, we need to recalculate the
// longest line.
}
}
// ---- View methods ----------------------------------------------------
/**
* Determines the preferred span for this view along an
* axis.
*
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into >= 0.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @exception IllegalArgumentException for an invalid axis
*/
switch (axis) {
return getLineWidth(longLine);
default:
}
}
/**
* Renders using the given rendering surface and area on that surface.
* The view may need to do layout and create child views to enable
* itself to render into the given allocation.
*
* @param g the rendering surface to use
* @param a the allocated region to render into
*
* @see View#paint
*/
a = adjustPaintRegion(a);
// If the lines are clipped then we don't expend the effort to
// try and paint them. Since all of the lines are the same height
// with this object, determination of what lines need to be repainted
// is quick.
if (fontHeight > 0) {
linesTotal++;
}
} else {
}
// update the visible lines
int x = lineArea.x;
lineCount--;
(LayeredHighlighter)h : null;
}
else {
}
}
y += fontHeight;
if (line == 0) {
// This should never really happen, in so far as if
// firstLineOffset is non 0, there should only be one
// line of text.
x -= firstLineOffset;
}
}
}
/**
* Should return a shape ideal for painting based on the passed in
* Shape <code>a</code>. This is useful if painting in a different
* region. The default implementation returns <code>a</code>.
*/
return a;
}
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
*
* @param pos the position to convert >= 0
* @param a the allocated region to render into
* @return the bounding box of the given position
* @exception BadLocationException if the given position does not
* represent a valid location in the associated document
* @see View#modelToView
*/
// line coordinates
if (lineIndex < 0) {
return lineToRect(a, 0);
}
// determine span from the start of the line
// fill in the results and return
return lineArea;
}
/**
* Provides a mapping from the view coordinate space to the logical
* coordinate space of the model.
*
* @param fx the X coordinate >= 0
* @param fy the Y coordinate >= 0
* @param a the allocated region to render into
* @return the location within the model that best represents the
* given point in the view >= 0
* @see View#viewToModel
*/
// PENDING(prinz) properly calculate bias
int x = (int) fx;
int y = (int) fy;
if (y < alloc.y) {
// above the area covered by this icon, so the the position
// is assumed to be the start of the coverage for this view.
return getStartOffset();
// below the area covered by this icon, so the the position
// is assumed to be the end of the coverage for this view.
return getEndOffset() - 1;
} else {
// positioned within the coverage of this view vertically,
// so we figure out which line the point corresponds to.
// if the line is greater than the number of lines contained, then
// simply use the last line as it represents the last possible place
// we can position to.
return getEndOffset() - 1;
}
int dx = 0;
if (lineIndex == 0) {
alloc.x += firstLineOffset;
}
if (x < alloc.x) {
// point is to the left of the line
return line.getStartOffset();
// point is to the right of the line
} else {
// Determine the offset into the text
try {
return offs;
} catch (BadLocationException e) {
// should not happen
return -1;
}
}
}
}
/**
* Gives notification that something was inserted into the document
* in a location that this view is responsible for.
*
* @param changes the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#insertUpdate
*/
updateDamage(changes, a, f);
}
/**
* Gives notification that something was removed from the document
* in a location that this view is responsible for.
*
* @param changes the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#removeUpdate
*/
updateDamage(changes, a, f);
}
/**
* Gives notification from the document that attributes were changed
* in a location that this view is responsible for.
*
* @param changes the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#changedUpdate
*/
updateDamage(changes, a, f);
}
/**
* Sets the size of the view. This should cause
* layout of the view along the given axis, if it
* has any layout duties.
*
* @param width the width >= 0
* @param height the height >= 0
*/
}
// --- TabExpander methods ------------------------------------------
/**
* Returns the next tab stop position after a given reference position.
* This implementation does not support things like centering so it
* ignores the tabOffset argument.
*
* @param x the current position >= 0
* @param tabOffset the position within the text stream
* that the tab occurred at >= 0.
* @return the tab stop, measured in points >= 0
*/
if (tabSize == 0) {
return x;
}
}
// --- local methods ------------------------------------------------
/**
* Repaint the region of change covered by the given document
* event. Damages the line that begins the range to cover
* If lines are added or removed, damages the whole
* view. The longest line is checked to see if it has
* changed.
*
* @since 1.4
*/
// lines were added or removed...
int w = getLineWidth(added[i]);
if (w > currWide) {
currWide = w;
}
}
}
break;
}
}
}
preferenceChanged(null, true, true);
} else {
// check to see if the line is longer than current
// longest line.
int w = getLineWidth(longLine);
if (e == longLine) {
preferenceChanged(null, true, false);
} else if (getLineWidth(e) > w) {
longLine = e;
preferenceChanged(null, true, false);
}
// removed from longest line... recalc
preferenceChanged(null, true, false);
}
}
}
}
/**
* Repaint the given line range.
*
* @param host the component hosting the view (used to call repaint)
* @param a the region allocated for the view to render into
* @param line0 the starting line number to repaint. This must
* be a valid line number in the model.
* @param line1 the ending line number to repaint. This must
* be a valid line number in the model.
* @since 1.4
*/
if (a != null) {
} else {
}
}
}
/**
* Determine the rectangle that represents the given line.
*
* @param a the region allocated for the view to render into
* @param line the line number to find the region of. This must
* be a valid line number in the model.
* @since 1.4
*/
if (line == 0) {
alloc.x += firstLineOffset;
}
}
return r;
}
/**
* Iterate over the lines represented by the child elements
* of the element this view represents, looking for the line
* that is the longest. The <em>longLine</em> variable is updated to
* represent the longest line contained. The <em>font</em> variable
* is updated to indicate the font used to calculate the
* longest line.
*/
private void calculateLongestLine() {
Component c = getContainer();
int n = lines.getElementCount();
int maxWidth = -1;
for (int i = 0; i < n; i++) {
int w = getLineWidth(line);
if (w > maxWidth) {
maxWidth = w;
}
}
}
/**
* Calculate the width of the line represented by
* the given element. It is assumed that the font
* and font metrics are up-to-date.
*/
return 0;
}
int w;
try {
} catch (BadLocationException ble) {
w = 0;
}
return w;
}
// --- member variables -----------------------------------------------
/**
* Font metrics for the current font.
*/
/**
* The current longest line. This is used to calculate
* the preferred width of the view. Since the calculation
* is potentially expensive we try to avoid it by stashing
* which line is currently the longest.
*/
/**
* Font used to calculate the longest line... if this
* changes we need to recalculate the longest line
*/
int tabSize;
int tabBase;
int sel0;
int sel1;
/**
* Offset of where to draw the first character on the first line.
* This is a hack and temporary until we can better address the problem
* of text measuring. This field is actually never set directly in
* PlainView, but by FieldView.
*/
int firstLineOffset;
}