Fixes and updates

This commit is contained in:
Nico committed 2021-03-07 15:22:55 +01:00
1 parent d1710ea6a5
commit fb4da77359
211 files changed
+45363 -45571

No files matched your search

@@ -43,7 +43,7 @@ import org.fife.ui.rtextarea.Gutter;
* @version 0.2
*/
public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView {
private boolean widthChanging;
private int tabBase;
private int tabSize;
@@ -67,17 +67,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// */
// private static final char[] eolMarker = { '.' };
/**
* The width of this view cannot be below this amount, as if the width
* is ever 0 (really a bug), we'll go into an infinite loop.
* The width of this view cannot be below this amount, as if the width is ever 0
* (really a bug), we'll go into an infinite loop.
*/
private static final int MIN_WIDTH = 20;
/**
* Creates a new WrappedSyntaxView. Lines will be wrapped
* on character boundaries.
* Creates a new WrappedSyntaxView. Lines will be wrapped on character
* boundaries.
*
* @param elem
* the element underlying the view
* @param elem the element underlying the view
*/
public WrappedSyntaxView(Element elem) {
super(elem, Y_AXIS);
@@ -87,14 +86,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
tempRect = new Rectangle();
lineCountTempToken = new TokenImpl();
}
/**
* This is called by the nested wrapped line
* views to determine the break location. This can
* be reimplemented to alter the breaking behavior.
* It will either break at word or character boundaries
* depending upon the break argument given at
* construction.
* This is called by the nested wrapped line views to determine the break
* location. This can be reimplemented to alter the breaking behavior. It will
* either break at word or character boundaries depending upon the break
* argument given at construction.
*/
protected int calculateBreakPosition(int p0, Token tokenList, float x0) {
// System.err.println("------ beginning calculateBreakPosition()
@@ -143,7 +140,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// return p;
return p + 1;
}
// private int getBreakLocation(Token t, FontMetrics fm, int x0, int x,
// TabExpander e) {
// Segment s = new Segment();
@@ -153,27 +150,24 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// return t.offset + Utilities.getBreakLocation(s, fm, x0, x, e, t.offset);
// }
/**
* Gives notification from the document that attributes were changed
* in a location that this view is responsible for.
* Gives notification from the document that attributes were changed in a
* location that this view is responsible for.
*
* @param e
* 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
* @param e 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
*/
@Override
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
updateChildren(e, a);
}
/**
* Sets the allocation rectangle for a given line's view, but sets the
* y value to the passed-in value. This should be used instead of
* {@link #childAllocation(int, Rectangle)} since it allows you to account
* for hidden lines in collapsed fold regions.
* Sets the allocation rectangle for a given line's view, but sets the y value
* to the passed-in value. This should be used instead of
* {@link #childAllocation(int, Rectangle)} since it allows you to account for
* hidden lines in collapsed fold regions.
*
* @param line
* @param y
@@ -192,25 +186,20 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
alloc.y -= margin.top;
}
}
/**
* Draws a single view (i.e., a line of text for a wrapped view),
* wrapping the text onto multiple lines if necessary.
* Draws a single view (i.e., a line of text for a wrapped view), wrapping the
* text onto multiple lines if necessary.
*
* @param painter
* The painter to use to render tokens.
* @param g
* The graphics context in which to paint.
* @param r
* The rectangle in which to paint.
* @param view
* The <code>View</code> to paint.
* @param fontHeight
* The height of the font being used.
* @param y
* The y-coordinate at which to begin painting.
* @param painter The painter to use to render tokens.
* @param g The graphics context in which to paint.
* @param r The rectangle in which to paint.
* @param view The <code>View</code> to paint.
* @param fontHeight The height of the font being used.
* @param y The y-coordinate at which to begin painting.
*/
protected void drawView(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int line) {
protected void drawView(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y,
int line) {
float x = r.x;
LayeredHighlighter h = (LayeredHighlighter) host.getHighlighter();
RSyntaxDocument document = (RSyntaxDocument) getDocument();
@@ -262,31 +251,23 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
g.drawString("\u00B6", x, (float) y - fontHeight);
}
}
/**
* Draws a single view (i.e., a line of text for a wrapped view), wrapping
* the text onto multiple lines if necessary. Any selected text is
* rendered with the editor's "selected text" color.
* Draws a single view (i.e., a line of text for a wrapped view), wrapping the
* text onto multiple lines if necessary. Any selected text is rendered with the
* editor's "selected text" color.
*
* @param painter
* The painter to use to render tokens.
* @param g
* The graphics context in which to paint.
* @param r
* The rectangle in which to paint.
* @param view
* The <code>View</code> to paint.
* @param fontHeight
* The height of the font being used.
* @param y
* The y-coordinate at which to begin painting.
* @param selStart
* The start of the selection.
* @param selEnd
* The end of the selection.
* @param painter The painter to use to render tokens.
* @param g The graphics context in which to paint.
* @param r The rectangle in which to paint.
* @param view The <code>View</code> to paint.
* @param fontHeight The height of the font being used.
* @param y The y-coordinate at which to begin painting.
* @param selStart The start of the selection.
* @param selEnd The end of the selection.
*/
protected void drawViewWithSelection(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int selStart,
int selEnd) {
protected void drawViewWithSelection(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight,
int y, int selStart, int selEnd) {
float x = r.x;
boolean useSTC = host.getUseSelectedTextColor();
LayeredHighlighter h = (LayeredHighlighter) host.getHighlighter();
@@ -363,7 +344,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
if (token != null && token.isPaintable() && token.getOffset() < p) {
int tokenOffset = token.getOffset();
Token orig = token;
token = new TokenImpl(drawSeg, tokenOffset - start, p - 1 - start, tokenOffset, token.getType(), token.getLanguageIndex());
token = new TokenImpl(drawSeg, tokenOffset - start, p - 1 - start, tokenOffset, token.getType(),
token.getLanguageIndex());
token.setLanguageIndex(token.getLanguageIndex());
// Selection starts in this token
if (token.containsPosition(selStart)) {
@@ -422,19 +404,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
g.drawString("\u00B6", x, (float) y - fontHeight);
}
}
/**
* Fetches the allocation for the given child view.
* <p>
* Overridden to account for code folding.
*
* @param index
* The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount().
* @param a
* The allocation to this view
* @return The allocation to the child; or <code>null</code> if
* <code>a</code> is <code>null</code>; or <code>null</code> if the
* layout is invalid
* @param index The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount().
* @param a The allocation to this view
* @return The allocation to the child; or <code>null</code> if <code>a</code>
* is <code>null</code>; or <code>null</code> if the layout is invalid
*/
@Override
public Shape getChildAllocation(int index, Shape a) {
@@ -451,16 +430,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return null;
}
/**
* Fetches the allocation for the given child view to render into.
* <p>
* Overridden to account for lines hidden by collapsed folded regions.
*
* @param line
* The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount()
* @param a
* The allocation to this view
* @param line The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount()
* @param a The allocation to this view
* @return The allocation to the child
*/
public Shape getChildAllocationImpl(int line, Shape a) {
@@ -480,21 +457,17 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
childAllocation2(line, y, alloc);
return alloc;
}
/**
* Determines the maximum span for this view along an
* axis. This is implemented to provide the superclass
* behavior after first making sure that the current font
* metrics are cached (for the nested lines which use
* the metrics to determine the height of the potentially
* wrapped lines).
* Determines the maximum span for this view along an axis. This is implemented
* to provide the superclass behavior after first making sure that the current
* font metrics are cached (for the nested lines which use the metrics to
* determine the height of the potentially wrapped lines).
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into.
* 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.
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into. 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.
* @see View#getMaximumSpan
*/
@Override
@@ -506,21 +479,17 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return span;
}
/**
* Determines the minimum span for this view along an
* axis. This is implemented to provide the superclass
* behavior after first making sure that the current font
* metrics are cached (for the nested lines which use
* the metrics to determine the height of the potentially
* wrapped lines).
* Determines the minimum span for this view along an axis. This is implemented
* to provide the superclass behavior after first making sure that the current
* font metrics are cached (for the nested lines which use the metrics to
* determine the height of the potentially wrapped lines).
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into.
* 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.
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into. 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.
* @see View#getMinimumSpan
*/
@Override
@@ -532,21 +501,17 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return span;
}
/**
* Determines the preferred span for this view along an
* axis. This is implemented to provide the superclass
* behavior after first making sure that the current font
* metrics are cached (for the nested lines which use
* the metrics to determine the height of the potentially
* wrapped lines).
* Determines the preferred span for this view along an axis. This is
* implemented to provide the superclass behavior after first making sure that
* the current font metrics are cached (for the nested lines which use the
* metrics to determine the height of the potentially wrapped lines).
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into.
* 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.
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into. 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.
* @see View#getPreferredSpan
*/
@Override
@@ -573,7 +538,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return span;
}
/**
* Returns the tab size set for the document, defaulting to 5.
*
@@ -584,7 +549,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
int size = (i != null) ? i.intValue() : 5;
return size;
}
/**
* Overridden to allow for folded regions.
*/
@@ -610,18 +575,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
childAllocation2(lineCount - 1, curY, alloc);
return getView(lineCount - 1);
}
/**
* Gives notification that something was inserted into the
* document in a location that this view is responsible for.
* This is implemented to simply update the children.
* Gives notification that something was inserted into the document in a
* location that this view is responsible for. This is implemented to simply
* update the children.
*
* @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
* @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
*/
@Override
@@ -634,17 +596,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
v.insertUpdate(changes, alloc, f);
}
}
/**
* Loads all of the children to initialize the view.
* This is called by the <code>setParent</code> method.
* Subclasses can re-implement this to initialize their
* child views in a different manner. The default
* implementation creates a child view for each
* child element.
* Loads all of the children to initialize the view. This is called by the
* <code>setParent</code> method. Subclasses can re-implement this to initialize
* their child views in a different manner. The default implementation creates a
* child view for each child element.
*
* @param f
* the view factory
* @param f the view factory
*/
@Override
protected void loadChildren(ViewFactory f) {
@@ -658,7 +617,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
replace(0, 0, added);
}
}
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
if (!isAllocationValid()) {
@@ -691,48 +650,43 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
throw new BadLocationException("Position not represented by view", pos);
}
/**
* Provides a mapping, for a given region, from the document model
* coordinate space to the view coordinate space. The specified region is
* created as a union of the first and last character positions.
* Provides a mapping, for a given region, from the document model coordinate
* space to the view coordinate space. The specified region is created as a
* union of the first and last character positions.
* <p>
*
* This is implemented to subtract the width of the second character, as
* this view's <code>modelToView</code> actually returns the width of the
* character instead of "1" or "0" like the View implementations in
* <code>javax.swing.text</code>. Thus, if we don't override this method,
* the <code>View</code> implementation will return one character's width
* too much for its consumers (implementations of
* This is implemented to subtract the width of the second character, as this
* view's <code>modelToView</code> actually returns the width of the character
* instead of "1" or "0" like the View implementations in
* <code>javax.swing.text</code>. Thus, if we don't override this method, the
* <code>View</code> implementation will return one character's width too much
* for its consumers (implementations of
* <code>javax.swing.text.Highlighter</code>).
*
* @param p0
* the position of the first character (&gt;=0)
* @param b0
* The bias of the first character position, toward the previous
* character or the next character represented by the offset, in
* case the position is a boundary of two views; <code>b0</code>
* will have one of these values:
* <ul>
* <li><code>Position.Bias.Forward</code>
* <li><code>Position.Bias.Backward</code>
* </ul>
* @param p1
* the position of the last character (&gt;=0)
* @param b1
* the bias for the second character position, defined
* one of the legal values shown above
* @param a
* the area of the view, which encompasses the requested region
* @return the bounding box which is a union of the region specified
* by the first and last character positions
* @exception BadLocationException
* if the given position does
* not represent a valid location in the associated document
* @exception IllegalArgumentException
* if <code>b0</code> or
* <code>b1</code> are not one of the
* legal <code>Position.Bias</code> values listed above
* @param p0 the position of the first character (&gt;=0)
* @param b0 The bias of the first character position, toward the previous
* character or the next character represented by the offset, in case
* the position is a boundary of two views; <code>b0</code> will have
* one of these values:
* <ul>
* <li><code>Position.Bias.Forward</code>
* <li><code>Position.Bias.Backward</code>
* </ul>
* @param p1 the position of the last character (&gt;=0)
* @param b1 the bias for the second character position, defined one of the
* legal values shown above
* @param a the area of the view, which encompasses the requested region
* @return the bounding box which is a union of the region specified by the
* first and last character positions
* @exception BadLocationException if the given position does not represent
* a valid location in the associated
* document
* @exception IllegalArgumentException if <code>b0</code> or <code>b1</code> are
* not one of the legal
* <code>Position.Bias</code> values listed
* above
* @see View#viewToModel
*/
@Override
@@ -774,17 +728,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return r0;
}
/**
* 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.
* 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 &gt;= 0
* @param tabOffset
* the position within the text stream
* that the tab occurred at &gt;= 0.
* @param x the current position &gt;= 0
* @param tabOffset the position within the text stream that the tab occurred at
* &gt;= 0.
* @return the tab stop, measured in points &gt;= 0
*/
@Override
@@ -795,14 +747,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
int ntabs = ((int) x - tabBase) / tabSize;
return tabBase + ((ntabs + 1f) * tabSize);
}
/**
* Paints the word-wrapped text.
*
* @param g
* The graphics context in which to paint.
* @param a
* The shape (usually a rectangle) in which to paint.
* @param g The graphics context in which to paint.
* @param a The shape (usually a rectangle) in which to paint.
*/
@Override
public void paint(Graphics g, Shape a) {
@@ -854,18 +804,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
}
}
/**
* Gives notification that something was removed from the
* document in a location that this view is responsible for.
* This is implemented to simply update the children.
* Gives notification that something was removed from the document in a location
* that this view is responsible for. This is implemented to simply update the
* children.
*
* @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
* @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
*/
@Override
@@ -878,20 +825,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
v.removeUpdate(changes, alloc, f);
}
}
/**
* Makes a <code>Segment</code> point to the text in our
* document between the given positions. Note that the positions MUST be
* valid positions in the document.
* Makes a <code>Segment</code> point to the text in our document between the
* given positions. Note that the positions MUST be valid positions in the
* document.
*
* @param p0
* The first position in the document.
* @param p1
* The second position in the document.
* @param document
* The document from which you want to get the text.
* @param seg
* The segment in which to load the text.
* @param p0 The first position in the document.
* @param p1 The second position in the document.
* @param document The document from which you want to get the text.
* @param seg The segment in which to load the text.
*/
private void setSegment(int p0, int p1, Document document, Segment seg) {
try {
@@ -904,15 +847,13 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
ble.printStackTrace();
}
}
/**
* Sets the size of the view. This should cause layout of the view along
* the given axis, if it has any layout duties.
* 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 &gt;= 0
* @param height
* the height &gt;= 0
* @param width the width &gt;= 0
* @param height the height &gt;= 0
*/
@Override
public void setSize(float width, float height) {
@@ -926,10 +867,9 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
super.setSize(width, height);
widthChanging = false;
}
/**
* Update the child views in response to a
* document event.
* Update the child views in response to a document event.
*/
void updateChildren(DocumentEvent e, Shape a) {
Element elem = getElement();
@@ -962,14 +902,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// update font metrics which may be used by the child views
updateMetrics();
}
final void updateMetrics() {
Component host = getContainer();
Font f = host.getFont();
metrics = host.getFontMetrics(f); // Metrics for the default font.
tabSize = getTabSize() * metrics.charWidth('m');
}
@Override
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
int offs = -1;
@@ -992,7 +932,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return offs;
}
/**
* {@inheritDoc}
*/
@@ -1001,7 +941,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
return yForLineContaining(alloc, getElement().getElement(line).getStartOffset());
// return alloc.y + getOffset(Y_AXIS, line);
}
/**
* {@inheritDoc}
*/
@@ -1024,25 +964,23 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return -1;
}
/**
* Simple view of a line that wraps if it doesn't
* fit within the horizontal space allocated.
* This class tries to be lightweight by carrying little
* state of it's own and sharing the state of the outer class
* with it's siblings.
* Simple view of a line that wraps if it doesn't fit within the horizontal
* space allocated. This class tries to be lightweight by carrying little state
* of it's own and sharing the state of the outer class with it's siblings.
*/
class WrappedLine extends View {
private int nlines;
WrappedLine(Element elem) {
super(elem);
}
/**
* Calculate the number of lines that will be rendered
* by logical line when it is wrapped.
* Calculate the number of lines that will be rendered by logical line when it
* is wrapped.
*/
final int calculateLineCount() {
int nlines = 0;
@@ -1062,7 +1000,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
for (int p0 = startOffset; p0 < p1;) {
// System.err.println("... ... " + p0 + ", " + p1);
nlines += 1;
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0, lineCountTempToken);
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0,
lineCountTempToken);
x0 = subList != null ? subList.x : x0;
tokenList = subList != null ? subList.tokenList : null;
int p = calculateBreakPosition(p0, tokenList, x0);
@@ -1075,81 +1014,68 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// System.err.println("... ... ... new p0==" + p0);
}
/*
* int numLines = 0;
* try {
* numLines = textArea.getLineCount();
* } catch (BadLocationException ble) {
* ble.printStackTrace();
* }
* System.err.
* println(">>> >>> calculated number of lines for this view (line "
* + line + "/" + numLines + ": " + nlines);
* int numLines = 0; try { numLines = textArea.getLineCount(); } catch
* (BadLocationException ble) { ble.printStackTrace(); } System.err.
* println(">>> >>> calculated number of lines for this view (line " + line +
* "/" + numLines + ": " + nlines);
*/
return nlines;
}
/**
* Determines the preferred span for this view along an
* axis.
* Determines the preferred span for this view along an axis.
*
* @param axis
* may be either X_AXIS or Y_AXIS
* @return the span the view would like to be rendered into.
* 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.
* @param axis may be either X_AXIS or Y_AXIS
* @return the span the view would like to be rendered into. 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.
* @see View#getPreferredSpan
*/
@Override
public float getPreferredSpan(int axis) {
switch (axis) {
case View.X_AXIS:
float width = getWidth();
if (width == Integer.MAX_VALUE) {
// We have been initially set to MAX_VALUE, but we don't
// want this as our preferred.
return 100f;
}
return width;
case View.Y_AXIS:
if (nlines == 0 || widthChanging) {
nlines = calculateLineCount();
}
int h = nlines * ((RSyntaxTextArea) getContainer()).getLineHeight();
return h;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
case View.X_AXIS:
float width = getWidth();
if (width == Integer.MAX_VALUE) {
// We have been initially set to MAX_VALUE, but we don't
// want this as our preferred.
return 100f;
}
return width;
case View.Y_AXIS:
if (nlines == 0 || widthChanging) {
nlines = calculateLineCount();
}
int h = nlines * ((RSyntaxTextArea) getContainer()).getLineHeight();
return h;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
/**
* 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.
* 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
* @param g the rendering surface to use
* @param a the allocated region to render into
* @see View#paint
*/
@Override
public void paint(Graphics g, Shape a) {
// This is done by drawView() above.
}
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
* 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
* @param a
* the allocated region to render into
* @param pos the position to convert
* @param a the allocated region to render into
* @return the bounding box of the given position is returned
* @exception BadLocationException
* if the given position does not
* represent a valid location in the associated document.
* @exception BadLocationException if the given position does not represent a
* valid location in the associated document.
*/
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
@@ -1170,13 +1096,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
Token tokenList = doc.getTokenListForLine(line);
float x0 = alloc.x;// 0;
while (p0 < p1) {
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0, lineCountTempToken);
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0,
lineCountTempToken);
x0 = subList != null ? subList.x : x0;
tokenList = subList != null ? subList.tokenList : null;
int p = calculateBreakPosition(p0, tokenList, x0);
if ((pos >= p0) && (testP < p)) {// pos < p)) {
// it's in this line
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc, alloc.x);
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc,
alloc.x);
// System.err.println("--- end modelToView ---");
return alloc;
}
@@ -1184,7 +1112,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
if (p == p1 - 1 && pos == p1 - 1) {
// Wants end.
if (pos > p0) {
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc, alloc.x);
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc,
alloc.x);
}
// System.err.println("--- end modelToView ---");
return alloc;
@@ -1195,19 +1124,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
throw new BadLocationException(null, pos);
}
/**
* Provides a mapping from the view coordinate space to the logical
* coordinate space of the model.
* Provides a mapping from the view coordinate space to the logical coordinate
* space of the model.
*
* @param fx
* the X coordinate
* @param fy
* the Y coordinate
* @param a
* the allocated region to render into
* @return the location within the model that best represents the
* given point in the view
* @param fx the X coordinate
* @param fy the Y coordinate
* @param a the allocated region to render into
* @return the location within the model that best represents the given point in
* the view
* @see View#viewToModel
*/
@Override
@@ -1247,8 +1173,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// We can always use alloc.x since we always break
// lines so they start at the beginning of a physical
// line.
TokenSubList subList = TokenUtils.getSubTokenList(tlist, p0, WrappedSyntaxView.this, textArea, alloc.x,
lineCountTempToken);
TokenSubList subList = TokenUtils.getSubTokenList(tlist, p0, WrappedSyntaxView.this, textArea,
alloc.x, lineCountTempToken);
tlist = subList != null ? subList.tokenList : null;
int p = calculateBreakPosition(p0, tlist, alloc.x);
// If desired view position is in this physical chunk.
@@ -1281,7 +1207,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
return getEndOffset() - 1;
} // End of else.
}
private void handleDocumentEvent(DocumentEvent e, Shape a, ViewFactory f) {
int n = calculateLineCount();
if (this.nlines != n) {
@@ -1303,12 +1229,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
@Override
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
handleDocumentEvent(e, a, f);
}
@Override
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
handleDocumentEvent(e, a, f);