From: <aki...@us...> - 2006-05-29 08:45:05
|
Revision: 67 Author: akirschbaum Date: 2006-05-29 01:44:37 -0700 (Mon, 29 May 2006) ViewCVS: http://svn.sourceforge.net/gridarta/?rev=67&view=rev Log Message: ----------- Unified classes: whitespace changes, add final/static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/textedit/textarea/JEditTextArea.java trunk/crossfire/src/cfeditor/textedit/textarea/JavaScriptTokenMarker.java trunk/crossfire/src/cfeditor/textedit/textarea/KeywordMap.java trunk/crossfire/src/cfeditor/textedit/textarea/SyntaxDocument.java trunk/crossfire/src/cfeditor/textedit/textarea/SyntaxStyle.java trunk/crossfire/src/cfeditor/textedit/textarea/SyntaxUtilities.java trunk/crossfire/src/cfeditor/textedit/textarea/TextAreaDefaults.java trunk/crossfire/src/cfeditor/textedit/textarea/TextAreaPainter.java trunk/crossfire/src/cfeditor/textedit/textarea/TextUtilities.java trunk/crossfire/src/cfeditor/textedit/textarea/Token.java trunk/crossfire/src/cfeditor/textedit/textarea/XMLTokenMarker.java trunk/daimonin/src/daieditor/textedit/textarea/JEditTextArea.java trunk/daimonin/src/daieditor/textedit/textarea/KeywordMap.java trunk/daimonin/src/daieditor/textedit/textarea/SyntaxDocument.java trunk/daimonin/src/daieditor/textedit/textarea/SyntaxStyle.java trunk/daimonin/src/daieditor/textedit/textarea/SyntaxUtilities.java trunk/daimonin/src/daieditor/textedit/textarea/TextAreaDefaults.java trunk/daimonin/src/daieditor/textedit/textarea/TextAreaPainter.java trunk/daimonin/src/daieditor/textedit/textarea/TextUtilities.java trunk/daimonin/src/daieditor/textedit/textarea/Token.java Modified: trunk/crossfire/src/cfeditor/textedit/textarea/JEditTextArea.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/textarea/JEditTextArea.java 2006-05-28 23:20:56 UTC (rev 66) +++ trunk/crossfire/src/cfeditor/textedit/textarea/JEditTextArea.java 2006-05-29 08:44:37 UTC (rev 67) @@ -82,26 +82,29 @@ * ta.setTokenMarker(new JavaTokenMarker()); * ta.setText("public class Test {\n" * + " public static void main(String[] args) {\n" - * + " System.out.println(\"Hello World\");\n" + * + " System.err.println(\"Hello World\");\n" * + " }\n" * + "}");</pre> * @author Slava Pestov * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @version $Id: JEditTextArea.java,v 1.11 2006/03/26 00:48:57 akirschbaum Exp $ */ -public class JEditTextArea extends JComponent { +public final class JEditTextArea extends JComponent { private static final Logger log = Logger.getLogger(JEditTextArea.class); /** + * Serial Version UID. + */ + private static final long serialVersionUID = -1060281617538289153L; + + /** * Adding components with this name to the text area will place them left * of the horizontal scroll bar. In jEdit, the status bar is added this * way. */ public static final String LEFT_OF_SCROLLBAR = "los"; - private static final long serialVersionUID = -1060281617538289153L; - /** Creates a new JEditTextArea with the default settings. */ public JEditTextArea() { this(TextAreaDefaults.getDefaults()); @@ -111,7 +114,7 @@ * Creates a new JEditTextArea with the specified settings. * @param defaults the default settings */ - public JEditTextArea(TextAreaDefaults defaults) { + public JEditTextArea(final TextAreaDefaults defaults) { // Enable the necessary events enableEvents(AWTEvent.KEY_EVENT_MASK); @@ -160,7 +163,7 @@ * key normally does not "work" inside the text area. But that would be a pity, * because we need the tab key for indentation. * <p/> - * So what this method does is setting the focus traversal to "tab + <control>", + * So what this method does is setting the focus traversal to "tab + <control>", * in order to "free" the tab key from focus traversal events. * In JDKs above 1.4, this task can be accomplished simply by three lines of code: * <code> @@ -181,29 +184,29 @@ private void freeTabKeyFromFocusTraversal() { try { // preparing the key set first, this should be harmless - Set forwardTraversalKeys = new HashSet(); + final Set forwardTraversalKeys = new HashSet(); forwardTraversalKeys.add(KeyStroke.getKeyStroke("control TAB")); // here we try to access java.awt.KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS - Field field = Class.forName("java.awt.KeyboardFocusManager").getField("FORWARD_TRAVERSAL_KEYS"); - Integer value = new Integer(field.getInt(field)); // store the value of this field + final Field field = Class.forName("java.awt.KeyboardFocusManager").getField("FORWARD_TRAVERSAL_KEYS"); + final Integer value = new Integer(field.getInt(field)); // store the value of this field - Method[] methods = getClass().getMethods(); + final Method[] methods = getClass().getMethods(); if (methods != null) { for (int i = 0; i < methods.length; i++) { // here we try to find the method "setFocusTraversalKeys", and execute it if found if (methods[i].getName().equalsIgnoreCase("setFocusTraversalKeys")) { - methods[i].invoke(this, new Object[]{value, forwardTraversalKeys,}); - // System.out.println("freeTabKeyFromFocusTraversal() succeeded!"); + methods[i].invoke(this, new Object[] { value, forwardTraversalKeys, }); + // System.err.println("freeTabKeyFromFocusTraversal() succeeded!"); } } } - } catch (Exception e) { + } catch (final Exception e) { // If something is undefined which was tried to access above, an exception // is thrown and we end up here. But that's okay, it is intended to happen // for all JDKs 1.3.*. Those older JDKs don't need to set focus traversal anyways. - // System.out.println("freeTabKeyFromFocusTraversal() failed: "+e.getClass().getName()+"\n"+e.getMessage()); + // System.err.println("freeTabKeyFromFocusTraversal() failed: "+e.getClass().getName()+"\n"+e.getMessage()); } } @@ -211,7 +214,7 @@ * Set the TextArea font * @param f font */ - public void setFont(Font f) { + public final void setFont(final Font f) { getPainter().setFont(f); } @@ -229,7 +232,7 @@ * Sets the input handler. * @param inputHandler the new input handler */ - public void setInputHandler(InputHandler inputHandler) { + public final void setInputHandler(final InputHandler inputHandler) { this.inputHandler = inputHandler; } @@ -242,7 +245,7 @@ * Toggles caret blinking. * @param caretBlinks true if the caret should blink, false otherwise */ - public void setCaretBlinkEnabled(boolean caretBlinks) { + public final void setCaretBlinkEnabled(final boolean caretBlinks) { this.caretBlinks = caretBlinks; if (!caretBlinks) { blink = false; @@ -260,7 +263,7 @@ * Sets if the caret should be visible. * @param caretVisible true if the caret should be visible, false otherwise */ - public void setCaretVisible(boolean caretVisible) { + public final void setCaretVisible(final boolean caretVisible) { this.caretVisible = caretVisible; blink = true; @@ -291,7 +294,7 @@ * @param electricScroll the number of lines always visible from the top or * bottom */ - public final void setElectricScroll(int electricScroll) { + public final void setElectricScroll(final int electricScroll) { this.electricScroll = electricScroll; } @@ -300,7 +303,7 @@ * number of lines in the document changes, or when the size of the text * are changes. */ - public void updateScrollBars() { + public final void updateScrollBars() { if (vertical != null && visibleLines != 0) { vertical.setValues(firstLine, visibleLines, 0, getLineCount()); //vertical.setUnitIncrement(2); @@ -308,7 +311,7 @@ vertical.setBlockIncrement(visibleLines); } - int width = painter.getWidth(); + final int width = painter.getWidth(); if (horizontal != null && width != 0) { horizontal.setValues(-horizontalOffset, width, 0, width * 5); //horizontal.setUnitIncrement(painter.getFontMetrics().charWidth('w')); @@ -326,7 +329,7 @@ * Sets the line displayed at the text area's origin without updating the * scroll bars. */ - public void setFirstLine(int firstLine) { + public final void setFirstLine(final int firstLine) { if (firstLine == this.firstLine) { return; } @@ -353,17 +356,17 @@ return; } - int height = painter.getHeight(); + final int height = painter.getHeight(); // get line height - int lineHeight; + final int lineHeight; if (painter == null || painter.getFontMetrics() == null) { lineHeight = painter.getDefaultLineHeight(); // default height might be wrong, take it only when needed } else { lineHeight = painter.getFontMetrics().getHeight(); } - int oldVisibleLines = visibleLines; + final int oldVisibleLines = visibleLines; visibleLines = height / lineHeight; updateScrollBars(); } @@ -378,7 +381,7 @@ * horizontal scrolling. * @param horizontalOffset offset The new horizontal offset */ - public void setHorizontalOffset(int horizontalOffset) { + public final void setHorizontalOffset(final int horizontalOffset) { if (horizontalOffset == this.horizontalOffset) { return; } @@ -397,7 +400,7 @@ * @param horizontalOffset the new horizontal offset * @return true if any of the values were changed, false otherwise */ - public boolean setOrigin(int firstLine, int horizontalOffset) { + public final boolean setOrigin(final int firstLine, final int horizontalOffset) { boolean changed = false; int oldFirstLine = this.firstLine; @@ -425,11 +428,10 @@ * @return true if scrolling was actually performed, false if the caret was * already visible */ - public boolean scrollToCaret() { - int line = getCaretLine(); - int lineStart = getLineStartOffset(line); - int offset = Math.max(0, Math.min(getLineLength(line) - 1, - getCaretPosition() - lineStart)); + public final boolean scrollToCaret() { + final int line = getCaretLine(); + final int lineStart = getLineStartOffset(line); + final int offset = Math.max(0, Math.min(getLineLength(line) - 1, getCaretPosition() - lineStart)); return scrollTo(line, offset); } @@ -439,14 +441,14 @@ * registered for keypress-events. The graphics context must be fully * initialized before calling this method. */ - public void setEditingFocus() { + public final void setEditingFocus() { try { requestFocus(); setCaretVisible(true); focusedComponent = this; setCaretPosition(0); // set caret to 0, 0 coords - } catch (NullPointerException e) { - System.out.println("Nullpointer Excepion in JEditTextArea.setEditingFocus()"); + } catch (final NullPointerException e) { + System.err.println("Nullpointer Excepion in JEditTextArea.setEditingFocus()"); } } @@ -458,7 +460,7 @@ * @return true if scrolling was actually performed, false if the line and * offset was already visible */ - public boolean scrollTo(int line, int offset) { + public final boolean scrollTo(final int line, final int offset) { // visibleLines == 0 before the component is realized // we can't do any proper scrolling then, so we have // this hack... @@ -482,8 +484,8 @@ } } - int x = _offsetToX(line, offset); - int width = painter.getFontMetrics().charWidth('w'); + final int x = _offsetToX(line, offset); + final int width = painter.getFontMetrics().charWidth('w'); if (x < 0) { newHorizontalOffset = Math.min(0, horizontalOffset - x + width + 5); @@ -498,8 +500,8 @@ * Converts a line index to a y co-ordinate. * @param line the line */ - public int lineToY(int line) { - FontMetrics fm = painter.getFontMetrics(); + public final int lineToY(final int line) { + final FontMetrics fm = painter.getFontMetrics(); return (line - firstLine) * fm.getHeight() - (fm.getLeading() + fm.getMaxDescent()); } @@ -507,9 +509,9 @@ * Converts a y co-ordinate to a line index. * @param y the y co-ordinate */ - public int yToLine(int y) { - FontMetrics fm = painter.getFontMetrics(); - int height = fm.getHeight(); + public final int yToLine(final int y) { + final FontMetrics fm = painter.getFontMetrics(); + final int height = fm.getHeight(); return Math.max(0, Math.min(getLineCount() - 1, y / height + firstLine)); } @@ -519,7 +521,7 @@ * @param line the line * @param offset the offset, from the start of the line */ - public final int offsetToX(int line, int offset) { + public final int offsetToX(final int line, final int offset) { // don't use cached tokens painter.setCurrentLineTokens(null); return _offsetToX(line, offset); @@ -532,15 +534,15 @@ * @param line the line * @param offset the offset, from the start of the line */ - public int _offsetToX(int line, int offset) { - TokenMarker tokenMarker = getTokenMarker(); + public final int _offsetToX(final int line, final int offset) { + final TokenMarker tokenMarker = getTokenMarker(); /* Use painter's cached info for speed */ FontMetrics fm = painter.getFontMetrics(); getLineText(line, lineSegment); - int segmentOffset = lineSegment.offset; + final int segmentOffset = lineSegment.offset; int x = horizontalOffset; /* If syntax coloring is disabled, do simple translation */ @@ -548,10 +550,9 @@ lineSegment.count = offset; return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); - + } else { /* If syntax coloring is enabled, we have to do this because * tokens can vary in width */ - } else { Token tokens; if (painter.getCurrentLineIndex() == line && painter.getCurrentLineTokens() != null) { tokens = painter.getCurrentLineTokens(); @@ -561,12 +562,12 @@ painter.setCurrentLineTokens(tokens); } - Toolkit toolkit = painter.getToolkit(); - Font defaultFont = painter.getFont(); - SyntaxStyle[] styles = painter.getStyles(); + final Toolkit toolkit = painter.getToolkit(); + final Font defaultFont = painter.getFont(); + final SyntaxStyle[] styles = painter.getStyles(); - for (; ;) { - byte id = tokens.getId(); + while (true) { + final byte id = tokens.getId(); if (id == Token.END) { return x; } @@ -577,7 +578,7 @@ fm = styles[id].getFontMetrics(defaultFont, painter.getGraphics()); } - int length = tokens.getLength(); + final int length = tokens.getLength(); if (offset + segmentOffset < lineSegment.offset + length) { lineSegment.count = offset - (lineSegment.offset - segmentOffset); @@ -597,24 +598,24 @@ * @param line the line * @param x the x co-ordinate */ - public int xToOffset(int line, int x) { - TokenMarker tokenMarker = getTokenMarker(); + public final int xToOffset(final int line, final int x) { + final TokenMarker tokenMarker = getTokenMarker(); /* Use painter's cached info for speed */ FontMetrics fm = painter.getFontMetrics(); getLineText(line, lineSegment); - char[] segmentArray = lineSegment.array; - int segmentOffset = lineSegment.offset; - int segmentCount = lineSegment.count; + final char[] segmentArray = lineSegment.array; + final int segmentOffset = lineSegment.offset; + final int segmentCount = lineSegment.count; int width = horizontalOffset; if (tokenMarker == null) { for (int i = 0; i < segmentCount; i++) { - char c = segmentArray[i + segmentOffset]; - int charWidth; + final char c = segmentArray[i + segmentOffset]; + final int charWidth; if (c == '\t') { charWidth = (int) painter.nextTabStop(width, i) - width; } else { @@ -646,12 +647,12 @@ } int offset = 0; - Toolkit toolkit = painter.getToolkit(); - Font defaultFont = painter.getFont(); - SyntaxStyle[] styles = painter.getStyles(); + final Toolkit toolkit = painter.getToolkit(); + final Font defaultFont = painter.getFont(); + final SyntaxStyle[] styles = painter.getStyles(); - for (; ;) { - byte id = tokens.getId(); + while (true) { + final byte id = tokens.getId(); if (id == Token.END) { return offset; } @@ -662,11 +663,11 @@ fm = styles[id].getFontMetrics(defaultFont, painter.getGraphics()); } - int length = tokens.getLength(); + final int length = tokens.getLength(); for (int i = 0; i < length; i++) { - char c = segmentArray[segmentOffset + offset + i]; - int charWidth; + final char c = segmentArray[segmentOffset + offset + i]; + final int charWidth; if (c == '\t') { charWidth = (int) painter.nextTabStop(width, offset + i) - width; } else { @@ -697,9 +698,9 @@ * @param x the x co-ordinate of the point * @param y the y co-ordinate of the point */ - public int xyToOffset(int x, int y) { - int line = yToLine(y); - int start = getLineStartOffset(line); + public final int xyToOffset(final int x, final int y) { + final int line = yToLine(y); + final int start = getLineStartOffset(line); return start + xToOffset(line, x); } @@ -712,7 +713,7 @@ * Sets the document this text area is editing. * @param document the document */ - public void setDocument(SyntaxDocument document) { + public final void setDocument(final SyntaxDocument document) { if (this.document == document) { return; } @@ -743,7 +744,7 @@ * <code>getDocument().setTokenMarker()</code>. * @param tokenMarker the token marker */ - public final void setTokenMarker(TokenMarker tokenMarker) { + public final void setTokenMarker(final TokenMarker tokenMarker) { document.setTokenMarker(tokenMarker); } @@ -764,7 +765,7 @@ * Returns the line containing the specified offset. * @param offset the offset */ - public final int getLineOfOffset(int offset) { + public final int getLineOfOffset(final int offset) { return document.getDefaultRootElement().getElementIndex(offset); } @@ -774,9 +775,8 @@ * @return the start offset of the specified line, or -1 if the line is * invalid */ - public int getLineStartOffset(int line) { - Element lineElement = document.getDefaultRootElement() - .getElement(line); + public final int getLineStartOffset(final int line) { + final Element lineElement = document.getDefaultRootElement().getElement(line); if (lineElement == null) { return -1; } else { @@ -790,9 +790,8 @@ * @return the end offset of the specified line, or -1 if the line is * invalid */ - public int getLineEndOffset(int line) { - Element lineElement = document.getDefaultRootElement() - .getElement(line); + public final int getLineEndOffset(final int line) { + final Element lineElement = document.getDefaultRootElement().getElement(line); if (lineElement == null) { return -1; } else { @@ -804,9 +803,8 @@ * Returns the length of the specified line. * @param line the line */ - public int getLineLength(int line) { - Element lineElement = document.getDefaultRootElement() - .getElement(line); + public final int getLineLength(final int line) { + final Element lineElement = document.getDefaultRootElement().getElement(line); if (lineElement == null) { return -1; } else { @@ -814,26 +812,30 @@ } } - /** Returns the entire text of this text area. */ - public String getText() { + /** + * Returns the entire text of this text area. + */ + public final String getText() { try { return document.getText(0, document.getLength()); - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); return null; } } - /** Sets the entire text of this text area. */ - public void setText(String text) { + /** + * Sets the entire text of this text area. + */ + public final void setText(final String text) { try { - document.beginCompoundEdit(); + SyntaxDocument.beginCompoundEdit(); document.remove(0, document.getLength()); document.insertString(0, text, null); - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); } finally { - document.endCompoundEdit(); + SyntaxDocument.endCompoundEdit(); } } @@ -843,10 +845,10 @@ * @param len the length of the substring * @return the substring, or null if the offsets are invalid */ - public final String getText(int start, int len) { + public final String getText(final int start, final int len) { try { return document.getText(start, len); - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); return null; } @@ -859,10 +861,10 @@ * @param len the length of the substring * @param segment the segment */ - public final void getText(int start, int len, Segment segment) { + public final void getText(final int start, final int len, final Segment segment) { try { document.getText(start, len, segment); - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); segment.offset = segment.count = 0; } @@ -873,8 +875,8 @@ * @param lineIndex the line * @return the text, or null if the line is invalid */ - public final String getLineText(int lineIndex) { - int start = getLineStartOffset(lineIndex); + public final String getLineText(final int lineIndex) { + final int start = getLineStartOffset(lineIndex); return getText(start, getLineEndOffset(lineIndex) - start - 1); } @@ -883,8 +885,8 @@ * invalid, the segment will contain a null string. * @param lineIndex the line */ - public final void getLineText(int lineIndex, Segment segment) { - int start = getLineStartOffset(lineIndex); + public final void getLineText(final int lineIndex, final Segment segment) { + final int start = getLineStartOffset(lineIndex); getText(start, getLineEndOffset(lineIndex) - start - 1, segment); } @@ -893,17 +895,19 @@ return selectionStart; } - /** Returns the offset where the selection starts on the specified line. */ - public int getSelectionStart(int line) { + /** + * Returns the offset where the selection starts on the specified line. + */ + public final int getSelectionStart(final int line) { if (line == selectionStartLine) { return selectionStart; } else if (rectSelect) { - Element map = document.getDefaultRootElement(); - int start = selectionStart - map.getElement(selectionStartLine).getStartOffset(); + final Element map = document.getDefaultRootElement(); + final int start = selectionStart - map.getElement(selectionStartLine).getStartOffset(); - Element lineElement = map.getElement(line); - int lineStart = lineElement.getStartOffset(); - int lineEnd = lineElement.getEndOffset() - 1; + final Element lineElement = map.getElement(line); + final int lineStart = lineElement.getStartOffset(); + final int lineEnd = lineElement.getEndOffset() - 1; return Math.min(lineEnd, lineStart + start); } else { return getLineStartOffset(line); @@ -921,7 +925,7 @@ * @param selectionStart the selection start * @see #select(int, int) */ - public final void setSelectionStart(int selectionStart) { + public final void setSelectionStart(final int selectionStart) { select(selectionStart, selectionEnd); } @@ -930,17 +934,19 @@ return selectionEnd; } - /** Returns the offset where the selection ends on the specified line. */ - public int getSelectionEnd(int line) { + /** + * Returns the offset where the selection ends on the specified line. + */ + public final int getSelectionEnd(final int line) { if (line == selectionEndLine) { return selectionEnd; } else if (rectSelect) { - Element map = document.getDefaultRootElement(); - int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); + final Element map = document.getDefaultRootElement(); + final int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); - Element lineElement = map.getElement(line); - int lineStart = lineElement.getStartOffset(); - int lineEnd = lineElement.getEndOffset() - 1; + final Element lineElement = map.getElement(line); + final int lineStart = lineElement.getStartOffset(); + final int lineEnd = lineElement.getEndOffset() - 1; return Math.min(lineEnd, lineStart + end); } else { return getLineEndOffset(line) - 1; @@ -958,7 +964,7 @@ * @param selectionEnd the selection end * @see #select(int, int) */ - public final void setSelectionEnd(int selectionEnd) { + public final void setSelectionEnd(final int selectionEnd) { select(selectionStart, selectionEnd); } @@ -996,16 +1002,20 @@ * @param caret the caret position * @see #select(int, int) */ - public final void setCaretPosition(int caret) { + public final void setCaretPosition(final int caret) { select(caret, caret); } - /** Selects all text in the document. */ + /** + * Selects all text in the document. + */ public final void selectAll() { select(0, getDocumentLength()); } - /** Moves the mark to the caret position. */ + /** + * Moves the mark to the caret position. + */ public final void selectNone() { select(getCaretPosition(), getCaretPosition()); } @@ -1017,9 +1027,10 @@ * @param start the start offset * @param end the end offset */ - public void select(int start, int end) { - int newStart, newEnd; - boolean newBias; + public final void select(final int start, final int end) { + final int newStart; + final int newEnd; + final boolean newBias; if (start <= end) { newStart = start; newEnd = end; @@ -1038,8 +1049,8 @@ // do all this crap, however we still do the stuff at // the end (clearing magic position, scrolling) if (newStart != selectionStart || newEnd != selectionEnd || newBias != biasLeft) { - int newStartLine = getLineOfOffset(newStart); - int newEndLine = getLineOfOffset(newEnd); + final int newStartLine = getLineOfOffset(newStart); + final int newEndLine = getLineOfOffset(newEnd); if (painter.isBracketHighlightEnabled()) { if (bracketLine != -1) { @@ -1055,8 +1066,7 @@ painter.invalidateLineRange(selectionStartLine, selectionEndLine); painter.invalidateLineRange(newStartLine, newEndLine); - document.addUndoableEdit(new CaretUndo( - selectionStart, selectionEnd)); + SyntaxDocument.addUndoableEdit(new CaretUndo(selectionStart, selectionEnd)); selectionStart = newStart; selectionEnd = newEnd; @@ -1083,7 +1093,9 @@ scrollToCaret(); } - /** Returns the selected text, or null if no selection is active. */ + /** + * Returns the selected text, or null if no selection is active. + */ public final String getSelectedText() { if (selectionStart == selectionEnd) { return null; @@ -1092,25 +1104,25 @@ if (rectSelect) { // Return each row of the selection on a new line - Element map = document.getDefaultRootElement(); + final Element map = document.getDefaultRootElement(); int start = selectionStart - map.getElement(selectionStartLine).getStartOffset(); int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); // Certain rectangles satisfy this condition... if (end < start) { - int tmp = end; + final int tmp = end; end = start; start = tmp; } - StringBuffer buf = new StringBuffer(); - Segment seg = new Segment(); + final StringBuffer buf = new StringBuffer(); + final Segment seg = new Segment(); for (int i = selectionStartLine; i <= selectionEndLine; i++) { - Element lineElement = map.getElement(i); + final Element lineElement = map.getElement(i); int lineStart = lineElement.getStartOffset(); - int lineEnd = lineElement.getEndOffset() - 1; + final int lineEnd = lineElement.getEndOffset() - 1; int lineLen = lineEnd - lineStart; lineStart = Math.min(lineStart + start, lineEnd); @@ -1134,7 +1146,7 @@ * Replaces the selection with the specified text. * @param selectedText the replacement text for the selection */ - public void setSelectedText(String selectedText) { + public final void setSelectedText(final String selectedText) { if (!editable) { throw new InternalError("Text component read only"); } @@ -1143,14 +1155,14 @@ try { if (rectSelect) { - Element map = document.getDefaultRootElement(); + final Element map = document.getDefaultRootElement(); int start = selectionStart - map.getElement(selectionStartLine).getStartOffset(); int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); // Certain rectangles satisfy this condition... if (end < start) { - int tmp = end; + final int tmp = end; end = start; start = tmp; } @@ -1159,10 +1171,10 @@ int currNewline = 0; for (int i = selectionStartLine; i <= selectionEndLine; i++) { - Element lineElement = map.getElement(i); - int lineStart = lineElement.getStartOffset(); - int lineEnd = lineElement.getEndOffset() - 1; - int rectStart = Math.min(lineEnd, lineStart + start); + final Element lineElement = map.getElement(i); + final int lineStart = lineElement.getStartOffset(); + final int lineEnd = lineElement.getEndOffset() - 1; + final int rectStart = Math.min(lineEnd, lineStart + start); document.remove(rectStart, Math.min(lineEnd - rectStart, end - start)); @@ -1181,7 +1193,7 @@ } if (selectedText != null && currNewline != selectedText.length()) { - int offset = map.getElement(selectionEndLine).getEndOffset() - 1; + final int offset = map.getElement(selectionEndLine).getEndOffset() - 1; document.insertString(offset, "\n", null); document.insertString(offset + 1, selectedText.substring(currNewline + 1), null); } @@ -1191,12 +1203,12 @@ document.insertString(selectionStart, selectedText, null); } } - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); throw new InternalError("Cannot replace selection"); + } finally { // No matter what happends... stops us from leaving document // in a bad state - } finally { document.endCompoundEdit(); } @@ -1213,7 +1225,7 @@ * @param editable true if this text area should be editable, false * otherwise */ - public final void setEditable(boolean editable) { + public final void setEditable(final boolean editable) { this.editable = editable; } @@ -1226,7 +1238,7 @@ * Sets the right click popup menu. * @param popup the popup */ - public final void setRightClickPopup(JPopupMenu popup) { + public final void setRightClickPopup(final JPopupMenu popup) { this.popup = popup; } @@ -1243,7 +1255,7 @@ * position when moving up and down lines. * @param magicCaret the magic caret position */ - public final void setMagicCaretPosition(int magicCaret) { + public final void setMagicCaretPosition(final int magicCaret) { this.magicCaret = magicCaret; } @@ -1254,7 +1266,7 @@ * @see #setSelectedText(String) * @see #isOverwriteEnabled() */ - public void overwriteSetSelectedText(String str) { + public final void overwriteSetSelectedText(final String str) { // Don't overstrike if there is a selection if (!overwrite || selectionStart != selectionEnd) { setSelectedText(str); @@ -1263,22 +1275,22 @@ // Don't overstrike if we're on the end of // the line - int caret = getCaretPosition(); - int caretLineEnd = getLineEndOffset(getCaretLine()); + final int caret = getCaretPosition(); + final int caretLineEnd = getLineEndOffset(getCaretLine()); if (caretLineEnd - caret <= str.length()) { setSelectedText(str); return; } - document.beginCompoundEdit(); + SyntaxDocument.beginCompoundEdit(); try { document.remove(caret, str.length()); document.insertString(caret, str, null); - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); } finally { - document.endCompoundEdit(); + SyntaxDocument.endCompoundEdit(); } } @@ -1292,7 +1304,7 @@ * @param overwrite true if overwrite mode should be enabled, false * otherwise */ - public final void setOverwriteEnabled(boolean overwrite) { + public final void setOverwriteEnabled(final boolean overwrite) { this.overwrite = overwrite; painter.invalidateSelectedLines(); } @@ -1307,7 +1319,7 @@ * @param rectSelect true if the selection should be rectangular, false * otherwise */ - public final void setSelectionRectangular(boolean rectSelect) { + public final void setSelectionRectangular(final boolean rectSelect) { this.rectSelect = rectSelect; painter.invalidateSelectedLines(); } @@ -1332,7 +1344,7 @@ * Adds a caret change listener to this text area. * @param listener the listener */ - public final void addCaretListener(CaretListener listener) { + public final void addCaretListener(final CaretListener listener) { listenerList.add(CaretListener.class, listener); } @@ -1340,7 +1352,7 @@ * Removes a caret change listener from this text area. * @param listener the listener */ - public final void removeCaretListener(CaretListener listener) { + public final void removeCaretListener(final CaretListener listener) { listenerList.remove(CaretListener.class, listener); } @@ -1348,7 +1360,7 @@ * Deletes the selected text from the text area and places it into the * clipboard. */ - public void cut() { + public final void cut() { if (editable) { copy(); setSelectedText(""); @@ -1356,14 +1368,14 @@ } /** Places the selected text into the clipboard. */ - public void copy() { + public final void copy() { if (selectionStart != selectionEnd) { - Clipboard clipboard = getToolkit().getSystemClipboard(); + final Clipboard clipboard = getToolkit().getSystemClipboard(); - String selection = getSelectedText(); + final String selection = getSelectedText(); - int repeatCount = inputHandler.getRepeatCount(); - StringBuffer buf = new StringBuffer(); + final int repeatCount = inputHandler.getRepeatCount(); + final StringBuffer buf = new StringBuffer(); for (int i = 0; i < repeatCount; i++) { buf.append(selection); } @@ -1372,23 +1384,25 @@ } } - /** Inserts the clipboard contents into the text. */ - public void paste() { + /** + * Inserts the clipboard contents into the text. + */ + public final void paste() { if (editable) { - Clipboard clipboard = getToolkit().getSystemClipboard(); + final Clipboard clipboard = getToolkit().getSystemClipboard(); try { // The MacOS MRJ doesn't convert \r to \n, // so do it here String selection = ((String) clipboard.getContents(this).getTransferData(DataFlavor.stringFlavor)).replace('\r', '\n'); - int repeatCount = inputHandler.getRepeatCount(); - StringBuffer buf = new StringBuffer(); + final int repeatCount = inputHandler.getRepeatCount(); + final StringBuffer buf = new StringBuffer(); for (int i = 0; i < repeatCount; i++) { buf.append(selection); } selection = buf.toString(); setSelectedText(selection); - } catch (Exception e) { + } catch (final Exception e) { getToolkit().beep(); log.error("Clipboard does not contain a string"); } @@ -1399,7 +1413,7 @@ * Called by the AWT when this component is removed from it's parent. This * stops clears the currently focused component. */ - public void removeNotify() { + public final void removeNotify() { super.removeNotify(); if (focusedComponent == this) { focusedComponent = null; @@ -1410,7 +1424,7 @@ * Forwards key events directly to the input handler. This is slightly * faster than using a KeyListener because some Swing overhead is avoided. */ - public void processKeyEvent(KeyEvent evt) { + public final void processKeyEvent(final KeyEvent evt) { if (inputHandler == null) { return; } @@ -1431,23 +1445,23 @@ } // protected members - protected static String CENTER = "center"; + protected static final String CENTER = "center"; - protected static String RIGHT = "right"; + protected static final String RIGHT = "right"; - protected static String BOTTOM = "bottom"; + protected static final String BOTTOM = "bottom"; protected static JEditTextArea focusedComponent; - protected static Timer caretTimer; + protected static final Timer caretTimer; - protected TextAreaPainter painter; + protected final TextAreaPainter painter; protected JPopupMenu popup; - protected EventListenerList listenerList; + protected final EventListenerList listenerList; - protected MutableCaretEvent caretEvent; + protected final MutableCaretEvent caretEvent; protected boolean caretBlinks; @@ -1465,9 +1479,9 @@ protected int horizontalOffset; - protected JScrollBar vertical; + protected final JScrollBar vertical; - protected JScrollBar horizontal; + protected final JScrollBar horizontal; protected boolean scrollBarsInitialized; @@ -1475,9 +1489,9 @@ protected SyntaxDocument document; - protected DocumentHandler documentHandler; + protected final DocumentHandler documentHandler; - protected Segment lineSegment; + protected final Segment lineSegment; protected int selectionStart; @@ -1499,8 +1513,8 @@ protected boolean rectSelect; - protected void fireCaretEvent() { - Object[] listeners = listenerList.getListenerList(); + protected final void fireCaretEvent() { + final Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i--) { if (listeners[i] == CaretListener.class) { ((CaretListener) listeners[i + 1]).caretUpdate(caretEvent); @@ -1508,38 +1522,37 @@ } } - protected void updateBracketHighlight(int newCaretPosition) { + protected final void updateBracketHighlight(final int newCaretPosition) { if (newCaretPosition == 0) { bracketPosition = bracketLine = -1; return; } try { - int offset = TextUtilities.findMatchingBracket(document, newCaretPosition - 1); + final int offset = TextUtilities.findMatchingBracket(document, newCaretPosition - 1); if (offset != -1) { bracketLine = getLineOfOffset(offset); bracketPosition = offset - getLineStartOffset(bracketLine); return; } - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); } bracketLine = bracketPosition = -1; } - protected void documentChanged(DocumentEvent evt) { - DocumentEvent.ElementChange ch = evt.getChange( - document.getDefaultRootElement()); + protected final void documentChanged(final DocumentEvent evt) { + final DocumentEvent.ElementChange ch = evt.getChange(document.getDefaultRootElement()); - int count; + final int count; if (ch == null) { count = 0; } else { count = ch.getChildrenAdded().length - ch.getChildrenRemoved().length; } - int line = getLineOfOffset(evt.getOffset()); + final int line = getLineOfOffset(evt.getOffset()); if (count == 0) { painter.invalidateLine(line); } else if (line < firstLine) { @@ -1552,9 +1565,9 @@ } } - class ScrollLayout implements LayoutManager { + final class ScrollLayout implements LayoutManager { - public void addLayoutComponent(String name, Component comp) { + public final void addLayoutComponent(final String name, final Component comp) { if (name.equals(CENTER)) { center = comp; } else if (name.equals(RIGHT)) { @@ -1566,7 +1579,7 @@ } } - public void removeLayoutComponent(Component comp) { + public final void removeLayoutComponent(final Component comp) { if (center == comp) { center = null; } @@ -1582,52 +1595,52 @@ } } - public Dimension preferredLayoutSize(Container parent) { - Dimension dim = new Dimension(); - Insets insets = getInsets(); + public final Dimension preferredLayoutSize(final Container parent) { + final Dimension dim = new Dimension(); + final Insets insets = getInsets(); dim.width = insets.left + insets.right; dim.height = insets.top + insets.bottom; - Dimension centerPref = center.getPreferredSize(); + final Dimension centerPref = center.getPreferredSize(); dim.width += centerPref.width; dim.height += centerPref.height; - Dimension rightPref = right.getPreferredSize(); + final Dimension rightPref = right.getPreferredSize(); dim.width += rightPref.width; - Dimension bottomPref = bottom.getPreferredSize(); + final Dimension bottomPref = bottom.getPreferredSize(); dim.height += bottomPref.height; return dim; } - public Dimension minimumLayoutSize(Container parent) { - Dimension dim = new Dimension(); - Insets insets = getInsets(); + public final Dimension minimumLayoutSize(final Container parent) { + final Dimension dim = new Dimension(); + final Insets insets = getInsets(); dim.width = insets.left + insets.right; dim.height = insets.top + insets.bottom; - Dimension centerPref = center.getMinimumSize(); + final Dimension centerPref = center.getMinimumSize(); dim.width += centerPref.width; dim.height += centerPref.height; - Dimension rightPref = right.getMinimumSize(); + final Dimension rightPref = right.getMinimumSize(); dim.width += rightPref.width; - Dimension bottomPref = bottom.getMinimumSize(); + final Dimension bottomPref = bottom.getMinimumSize(); dim.height += bottomPref.height; return dim; } - public void layoutContainer(Container parent) { - Dimension size = parent.getSize(); - Insets insets = parent.getInsets(); - int itop = insets.top; + public final void layoutContainer(final Container parent) { + final Dimension size = parent.getSize(); + final Insets insets = parent.getInsets(); + final int itop = insets.top; int ileft = insets.left; - int ibottom = insets.bottom; - int iright = insets.right; + final int ibottom = insets.bottom; + final int iright = insets.right; - int rightWidth = right.getPreferredSize().width; - int bottomHeight = bottom.getPreferredSize().height; - int centerWidth = size.width - rightWidth - ileft - iright; - int centerHeight = size.height - bottomHeight - itop - ibottom; + final int rightWidth = right.getPreferredSize().width; + final int bottomHeight = bottom.getPreferredSize().height; + final int centerWidth = size.width - rightWidth - ileft - iright; + final int centerHeight = size.height - bottomHeight - itop - ibottom; center.setBounds( ileft, @@ -1642,14 +1655,11 @@ centerHeight); // Lay out all status components, in order - Enumeration status = leftOfScrollBar.elements(); + final Enumeration status = leftOfScrollBar.elements(); while (status.hasMoreElements()) { - Component comp = (Component) status.nextElement(); - Dimension dim = comp.getPreferredSize(); - comp.setBounds(ileft, - itop + centerHeight, - dim.width, - bottomHeight); + final Component comp = (Component) status.nextElement(); + final Dimension dim = comp.getPreferredSize(); + comp.setBounds(ileft, itop + centerHeight, dim.width, bottomHeight); ileft += dim.width; } @@ -1667,38 +1677,41 @@ private Component bottom; - private Vector leftOfScrollBar = new Vector(); - } + private final Vector leftOfScrollBar = new Vector(); + } // class ScrollLayout - static class CaretBlinker implements ActionListener { + static final class CaretBlinker implements ActionListener { - public void actionPerformed(ActionEvent evt) { + public final void actionPerformed(final ActionEvent evt) { if (focusedComponent != null && focusedComponent.hasFocus()) { focusedComponent.blinkCaret(); } } - } + } // class CaretBlinger - class MutableCaretEvent extends CaretEvent { + final class MutableCaretEvent extends CaretEvent { + /** + * Serial Version UID. + */ private static final long serialVersionUID = -906781128141622273L; MutableCaretEvent() { super(JEditTextArea.this); } - public int getDot() { + public final int getDot() { return getCaretPosition(); } - public int getMark() { + public final int getMark() { return getMarkPosition(); } - } + } // class MutableCaretEvent - class AdjustHandler implements AdjustmentListener { + final class AdjustHandler implements AdjustmentListener { - public void adjustmentValueChanged(final AdjustmentEvent evt) { + public final void adjustmentValueChanged(final AdjustmentEvent evt) { if (!scrollBarsInitialized) { return; } @@ -1716,26 +1729,26 @@ } }); } - } + } // class AdjustHandler - class ComponentHandler extends ComponentAdapter { + final class ComponentHandler extends ComponentAdapter { - public void componentResized(ComponentEvent evt) { + public final void componentResized(final ComponentEvent evt) { recalculateVisibleLines(); scrollBarsInitialized = true; } - } + } // class ComponentHandler - class DocumentHandler implements DocumentListener { + final class DocumentHandler implements DocumentListener { - public void insertUpdate(DocumentEvent evt) { + public final void insertUpdate(final DocumentEvent evt) { documentChanged(evt); - int offset = evt.getOffset(); - int length = evt.getLength(); + final int offset = evt.getOffset(); + final int length = evt.getLength(); - int newStart; - int newEnd; + final int newStart; + final int newEnd; if (selectionStart > offset || (selectionStart == selectionEnd && selectionStart == offset)) { newStart = selectionStart + length; @@ -1752,14 +1765,14 @@ select(newStart, newEnd); } - public void removeUpdate(DocumentEvent evt) { + public final void removeUpdate(final DocumentEvent evt) { documentChanged(evt); - int offset = evt.getOffset(); - int length = evt.getLength(); + final int offset = evt.getOffset(); + final int length = evt.getLength(); - int newStart; - int newEnd; + final int newStart; + final int newEnd; if (selectionStart > offset) { if (selectionStart > offset + length) { @@ -1784,42 +1797,43 @@ select(newStart, newEnd); } - public void changedUpdate(DocumentEvent evt) { + public final void changedUpdate(final DocumentEvent evt) { } - } + } // class DocumentHandler - class DragHandler implements MouseMotionListener { + final class DragHandler implements MouseMotionListener { - public void mouseDragged(MouseEvent evt) { + public final void mouseDragged(final MouseEvent evt) { if (popup != null && popup.isVisible()) { return; } - setSelectionRectangular((evt.getModifiers() - & InputEvent.CTRL_MASK) != 0); + setSelectionRectangular((evt.getModifiers() & InputEvent.CTRL_MASK) != 0); select(getMarkPosition(), xyToOffset(evt.getX(), evt.getY())); } - public void mouseMoved(MouseEvent evt) { + public final void mouseMoved(final MouseEvent evt) { } - } - class FocusHandler implements FocusListener { + } // class DragHandler - public void focusGained(FocusEvent evt) { + final class FocusHandler implements FocusListener { + + public final void focusGained(final FocusEvent evt) { setCaretVisible(true); focusedComponent = JEditTextArea.this; } - public void focusLost(FocusEvent evt) { + public final void focusLost(final FocusEvent evt) { setCaretVisible(false); focusedComponent = null; } - } - class MouseHandler extends MouseAdapter { + } // class FocusHandler - public void mousePressed(MouseEvent evt) { + final class MouseHandler extends MouseAdapter { + + public final void mousePressed(final MouseEvent evt) { requestFocus(); // Focus events not fired sometimes? @@ -1831,9 +1845,9 @@ return; } - int line = yToLine(evt.getY()); - int offset = xToOffset(line, evt.getX()); - int dot = getLineStartOffset(line) + offset; + final int line = yToLine(evt.getY()); + final int offset = xToOffset(line, evt.getX()); + final int dot = getLineStartOffset(line) + offset; switch (evt.getClickCount()) { case 1: @@ -1844,7 +1858,7 @@ // it can throw a BLE try { doDoubleClick(evt, line, offset, dot); - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); } break; @@ -1854,8 +1868,7 @@ } } - private void doSingleClick(MouseEvent evt, int line, - int offset, int dot) { + private void doSingleClick(final MouseEvent evt, final int line, final int offset, final int dot) { if ((evt.getModifiers() & InputEvent.SHIFT_MASK) != 0) { rectSelect = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0; select(getMarkPosition(), dot); @@ -1864,16 +1877,14 @@ } } - private void doDoubleClick(MouseEvent evt, int line, - int offset, int dot) throws BadLocationException { + private void doDoubleClick(final MouseEvent evt, final int line, final int offset, final int dot) throws BadLocationException { // Ignore empty lines if (getLineLength(line) == 0) { return; } try { - int bracket = TextUtilities.findMatchingBracket( - document, Math.max(0, dot - 1)); + int bracket = TextUtilities.findMatchingBracket(document, Math.max(0, dot - 1)); if (bracket != -1) { int mark = getMarkPosition(); // Hack @@ -1884,12 +1895,12 @@ select(mark, bracket); return; } - } catch (BadLocationException bl) { + } catch (final BadLocationException bl) { bl.printStackTrace(); } // Ok, it's not a bracket... select the word - String lineText = getLineText(line); + final String lineText = getLineText(line); char ch = lineText.charAt(Math.max(0, offset - 1)); String noWordSep = (String) document.getProperty("noWordSep"); @@ -1899,9 +1910,7 @@ // If the user clicked on a non-letter char, // we select the surrounding non-letters - boolean selectNoLetter = (!Character - .isLetterOrDigit(ch) - && noWordSep.indexOf(ch) == -1); + final boolean selectNoLetter = !Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1; int wordStart = 0; @@ -1922,7 +1931,7 @@ } } - int lineStart = getLineStartOffset(line); + final int lineStart = getLineStartOffset(line); select(lineStart + wordStart, lineStart + wordEnd); /* @@ -1932,52 +1941,55 @@ int wordEnd = TextUtilities.findWordEnd(lineText, offset, noWordSep); int lineStart = getLineStartOffset(line); - select(lineStart+wordStart, lineStart+wordEnd); + select(lineStart + wordStart, lineStart + wordEnd); */ } - private void doTripleClick(MouseEvent evt, int line, - int offset, int dot) { + private void doTripleClick(final MouseEvent evt, final int line, final int offset, final int dot) { select(getLineStartOffset(line), getLineEndOffset(line) - 1); } - } - class CaretUndo extends AbstractUndoableEdit { + } // class MouseHandler + final class CaretUndo extends AbstractUndoableEdit { + + /** + * Serial Version UID. + */ + private static final long serialVersionUID = -7132615163216882489L; + private int start; private int end; - private static final long serialVersionUID = -7132615163216882489L; - - CaretUndo(int start, int end) { + CaretUndo(final int start, final int end) { this.start = start; this.end = end; } - public boolean isSignificant() { + public final boolean isSignificant() { return false; } - public String getPresentationName() { + public final String getPresentationName() { return "caret move"; } - public void undo() { + public final void undo() { super.undo(); select(start, end); } - public void redo() { + public final void redo() { super.redo(); select(start, end); } - public boolean addEdit(UndoableEdit edit) { + public final boolean addEdit(final UndoableEdit edit) { if (edit instanceof CaretUndo) { - CaretUndo cedit = (CaretUndo) edit; + final CaretUndo ce... [truncated message content] |