improve documentation
diff --git a/src/prettify/PrettifyParser.java b/src/prettify/PrettifyParser.java
index 041189a..c02bc71 100644
--- a/src/prettify/PrettifyParser.java
+++ b/src/prettify/PrettifyParser.java
@@ -9,12 +9,19 @@
import syntaxhighlight.Parser;
/**
+ * The prettify parser for syntax highlight.
* @author Chan Wai Shing <cws1989@gmail.com>
*/
public class PrettifyParser implements Parser {
+ /**
+ * The prettify parser.
+ */
protected Prettify prettify;
+ /**
+ * Constructor.
+ */
public PrettifyParser() {
prettify = new Prettify();
}
@@ -28,11 +35,10 @@
List<ParseResult> returnList = new ArrayList<ParseResult>();
- Integer startPos = 0, endPos = 0;
// apply style according to the style list
for (int i = 0, iEnd = decorations.size(); i < iEnd; i += 2) {
- endPos = i + 2 < iEnd ? (Integer) decorations.get(i + 2) : content.length();
- startPos = (Integer) decorations.get(i);
+ int endPos = i + 2 < iEnd ? (Integer) decorations.get(i + 2) : content.length();
+ int startPos = (Integer) decorations.get(i);
returnList.add(new ParseResult(startPos, endPos - startPos, Arrays.asList(new String[]{(String) decorations.get(i + 1)})));
}
diff --git a/src/prettify/example/Example.java b/src/prettify/example/Example.java
index 33f4df3..a5ea2f4 100644
--- a/src/prettify/example/Example.java
+++ b/src/prettify/example/Example.java
@@ -90,8 +90,9 @@
long start, end;
start = System.currentTimeMillis();
- // initialize the parser
+ // the Prettify parser
Parser parser = new PrettifyParser();
+
// use Default theme
SyntaxHighlighter highlighter = new SyntaxHighlighter(parser, new ThemeDefault());
// set the line number count from 10 instead of 1
diff --git a/src/syntaxhighlight/JTextComponentRowHeader.java b/src/syntaxhighlight/JTextComponentRowHeader.java
index 2e76e8e..ffcf383 100644
--- a/src/syntaxhighlight/JTextComponentRowHeader.java
+++ b/src/syntaxhighlight/JTextComponentRowHeader.java
@@ -1,16 +1,23 @@
-// Copyright (C) 2011 Chan Wai Shing
+// Copyright (c) 2012 Chan Wai Shing
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package syntaxhighlight;
import java.awt.Color;
@@ -38,11 +45,10 @@
import javax.swing.text.JTextComponent;
/**
- * A row header panel for JScrollPane.
- * It is used with JTextComponent for line number displaying.
- * Currently it only accept fixed-height line.
- * The usage of this class is not limited to this syntax highlighter, it can be
- * used on all JTextComponent.
+ * A row header panel for {@link JScrollPane} showing the line numbers of
+ * {@link JTextComponent}.
+ *
+ * The text lines in {@link JTextComponent} must be fixed height.
*
* @author Chan Wai Shing <cws1989@gmail.com>
*/
@@ -52,31 +58,31 @@
private static final long serialVersionUID = 1L;
/**
* The anti-aliasing setting of the line number text. See
- * {@link java.awt.RenderingHints}.
+ * {@link RenderingHints}.
*/
- private Object textAntiAliasing = RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT;
+ protected Object textAntiAliasing = RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT;
/**
- * The color of the border that joint the gutter and the script text panel.
+ * The color of the border that joint the gutter and the script text area.
*/
- private Color borderColor = new Color(184, 184, 184);
+ protected Color borderColor = new Color(184, 184, 184);
/**
* The background of the row when it is highlighted.
*/
- private Color highlightedColor = Color.black;
+ protected Color highlightedColor = Color.black;
/**
* The minimum padding from 'the leftmost of the line number text' to
* 'the left margin'.
*/
- private int paddingLeft = 7;
+ protected int paddingLeft = 7;
/**
* The minimum padding from 'the rightmost of the line number text' to
* 'the right margin' (not to the gutter border).
*/
- private int paddingRight = 2;
+ protected int paddingRight = 2;
/**
- * The width of the border that joint the gutter and the script text panel.
+ * The width of the border that joint the gutter and the script text area.
*/
- private int borderWidth = 1;
+ protected int borderWidth = 1;
/**
* The JScrollPane that it be added into.
*/
@@ -110,17 +116,17 @@
* The line number offset. E.g. set offset to 9 will make the first line
* number to appear at line 1 + 9 = 10
*/
- private int lineNumberOffset;
+ protected int lineNumberOffset;
/**
* The list of line numbers that indicate which lines are needed to be
* highlighted.
*/
- private final List<Integer> highlightedLineList;
+ protected final List<Integer> highlightedLineList;
/**
* Indicator indicate whether it is listening to the document change events
* or not.
*/
- private boolean listenToDocumentUpdate;
+ protected boolean listenToDocumentUpdate;
/**
* Constructor.
@@ -377,7 +383,7 @@
}
/**
- * The color of the border that joint the gutter and the script text panel.
+ * The color of the border that joint the gutter and the script text area.
* @return the color
*/
public Color getBorderColor() {
@@ -385,7 +391,7 @@
}
/**
- * The color of the border that joint the gutter and the script text panel.
+ * The color of the border that joint the gutter and the script text area.
* @param borderColor the color
*/
public void setBorderColor(Color borderColor) {
@@ -459,7 +465,7 @@
}
/**
- * The width of the border that joint the gutter and the script text panel.
+ * The width of the border that joint the gutter and the script text area.
*
* @return the width in pixel
*/
@@ -468,7 +474,7 @@
}
/**
- * The width of the border that joint the gutter and the script text panel.
+ * The width of the border that joint the gutter and the script text area.
*
* @param borderWidth the width in pixel
*/
@@ -523,10 +529,19 @@
/**
* Add highlighted line.
* @param lineNumber the line number to highlight
+ * @return see the return value of {@link List#add(Object)}
*/
- public void addHighlightedLine(int lineNumber) {
- highlightedLineList.add(lineNumber);
+ public boolean addHighlightedLine(int lineNumber) {
+ boolean returnValue = highlightedLineList.add(lineNumber);
repaint();
+ return returnValue;
+ }
+
+ /**
+ * Clear highlighted lines.
+ */
+ public void clearHighlightedLine() {
+ highlightedLineList.clear();
}
/**
diff --git a/src/syntaxhighlight/ParseResult.java b/src/syntaxhighlight/ParseResult.java
index a731c73..5080288 100644
--- a/src/syntaxhighlight/ParseResult.java
+++ b/src/syntaxhighlight/ParseResult.java
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 Chan Wai Shing
+// Copyright (c) 2012 Chan Wai Shing
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -26,32 +26,36 @@
import java.util.List;
/**
- * Matched result, it will be generated when parsing the content.
+ * The parser parsed result.
+ *
+ * This class include the information needed to highlight the syntax.
+ * Information includes where the content located in the document (offset and
+ * length) and what style(s) should be applied on that segment of content.
*
* @author Chan Wai Shing <cws1989@gmail.com>
*/
public class ParseResult {
/**
- * The start position in the document for this matched result.
+ * The start position of the content.
*/
protected int offset;
/**
- * The length of the matched result.
+ * The length of the content.
*/
protected int length;
/**
- * The style key for this matched result, see {@link syntaxhighlighter.theme}.
+ * The style keys of the content. The style at higher index of the list will
+ * override the style of the lower index.
*/
protected List<String> styleKeys;
/**
* Constructor.
*
- * @param offset the position in the document for this matched result
- * @param length the length of the matched result.
- * @param styleKeys the style key for this matched result, cannot be null, see
- * {@link syntaxhighlighter.theme}
+ * @param offset the start position of the content
+ * @param length the length of the content
+ * @param styleKeys the style keys of the content
*/
public ParseResult(int offset, int length, List<String> styleKeys) {
this.offset = offset;
@@ -60,37 +64,42 @@
}
/**
- * The position in the document for this matched result.
- * @return the offset in the document
+ * The start position of the content.
+ * @return the start position of the content
*/
public int getOffset() {
return offset;
}
/**
- * The position in the document for this matched result.
- * @param offset the offset in the document
+ * The start position of the content.
+ * @param offset the start position of the content
*/
public void setOffset(int offset) {
this.offset = offset;
}
/**
- * The length of the matched result.
- * @return the length
+ * The length of the content.
+ * @return the length of the content
*/
public int getLength() {
return length;
}
/**
- * The length of the matched result.
- * @param length the length
+ * The length of the content.
+ * @param length the length of the content
*/
public void setLength(int length) {
this.length = length;
}
+ /**
+ * Get the style keys represented by one string key, see
+ * {@link Theme#getStylesAttributeSet(String)}.
+ * @return the style keys of the content
+ */
public String getStyleKeysString() {
StringBuilder sb = new StringBuilder(10);
for (int i = 0, iEnd = styleKeys.size(); i < iEnd; i++) {
@@ -102,18 +111,35 @@
return sb.toString();
}
+ /**
+ * The style keys of the content.
+ * @param styleKeys the style keys of the content
+ */
public void setStyleKeys(List<String> styleKeys) {
this.styleKeys = new ArrayList<String>(styleKeys);
}
+ /**
+ * The style keys of the content.
+ * @param styleKey the style key
+ * @return see the return value of {@link List#add(Object)}
+ */
public boolean addStyleKey(String styleKey) {
return styleKeys.add(styleKey);
}
+ /**
+ * The style keys of the content.
+ * @param styleKey the style key
+ * @return see the return value of {@link List#remove(Object)}
+ */
public boolean removeStyleKey(String styleKey) {
return styleKeys.remove(styleKey);
}
+ /**
+ * The style keys of the content.
+ */
public void clearStyleKeys() {
styleKeys.clear();
}
@@ -126,6 +152,9 @@
return new ArrayList<String>(styleKeys);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
diff --git a/src/syntaxhighlight/Parser.java b/src/syntaxhighlight/Parser.java
index 41eee05..73a1ecf 100644
--- a/src/syntaxhighlight/Parser.java
+++ b/src/syntaxhighlight/Parser.java
@@ -1,9 +1,29 @@
+// Copyright (c) 2012 Chan Wai Shing
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package syntaxhighlight;
import java.util.List;
/**
- * The parser interface for syntax highlight.
+ * The parser for syntax highlight.
*
* @author Chan Wai Shing <cws1989@gmail.com>
*/
@@ -11,7 +31,8 @@
/**
* Parse the {@code content} and return the parsed result.
- * @param fileExtension the file extension of the content, null means not provided
+ * @param fileExtension the file extension of the content, null means not
+ * provided
* @param content the content
* @return the parsed result
*/
diff --git a/src/syntaxhighlight/Style.java b/src/syntaxhighlight/Style.java
index 88f4531..4b58e91 100644
--- a/src/syntaxhighlight/Style.java
+++ b/src/syntaxhighlight/Style.java
@@ -1,16 +1,23 @@
-// Copyright (C) 2012 Chan Wai Shing
+// Copyright (c) 2012 Chan Wai Shing
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package syntaxhighlight;
import java.awt.Color;
@@ -24,16 +31,34 @@
*/
public class Style implements Cloneable {
+ /**
+ * It indicate whether the {@link #attributeSet} has updated after any style
+ * changes.
+ */
protected boolean changed;
+ /**
+ * The {@link AttributeSet} representation of this style.
+ */
protected SimpleAttributeSet attributeSet;
- //
+ /**
+ * Font bold.
+ */
protected boolean bold;
+ /**
+ * Font color.
+ */
protected Color color;
/**
* The background color, null means no background color is set.
*/
protected Color background;
+ /**
+ * Font underline.
+ */
protected boolean underline;
+ /**
+ * Font italic.
+ */
protected boolean italic;
/**
@@ -61,8 +86,8 @@
}
/**
- * Get the AttributeSet from this style.
- * @return the AttributeSet
+ * Get the {@link AttributeSet} of this style.
+ * @return the {@link AttributeSet}
*/
public SimpleAttributeSet getAttributeSet() {
if (changed) {
@@ -89,7 +114,7 @@
/**
* Set the background color.
- * @param background input null means do not set the background
+ * @param background null means do not set the background
*/
public void setBackground(Color background) {
changed = true;
@@ -192,7 +217,7 @@
sb.append(", ");
sb.append("color: ").append(color);
sb.append(", ");
- sb.append("bg: ").append(background);
+ sb.append("background: ").append(background);
sb.append(", ");
sb.append("underline: ").append(underline);
sb.append(", ");
diff --git a/src/syntaxhighlight/SyntaxHighlighter.java b/src/syntaxhighlight/SyntaxHighlighter.java
index df9638a..e948acc 100644
--- a/src/syntaxhighlight/SyntaxHighlighter.java
+++ b/src/syntaxhighlight/SyntaxHighlighter.java
@@ -1,16 +1,23 @@
-// Copyright (C) 2011 Chan Wai Shing
+// Copyright (c) 2012 Chan Wai Shing
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package syntaxhighlight;
import java.io.File;
@@ -29,7 +36,7 @@
private static final long serialVersionUID = 1L;
/**
- * The script text panel.
+ * The script text area.
*/
protected SyntaxHighlighterPane highlighter;
/**
@@ -41,7 +48,7 @@
*/
protected Theme theme;
/**
- * The Prettify object.
+ * The parser.
*/
protected Parser parser;
/**
@@ -51,8 +58,7 @@
/**
* Constructor.
- *
- * @param parser
+ * @param parser the parser to use
* @param theme the theme for the syntax highlighter
*/
public SyntaxHighlighter(Parser parser, Theme theme) {
@@ -61,8 +67,7 @@
/**
* Constructor.
- *
- * @param parser
+ * @param parser the parser to use
* @param theme the theme for the syntax highlighter
* @param highlighterPane the script text pane of the syntax highlighter
*/
@@ -110,9 +115,9 @@
}
/**
- * Get the SyntaxHighlighterPane (the script text panel).
- * <b>Note: Normally should not operate on the SyntaxHighlighterPane directly.</b>
- *
+ * Get the SyntaxHighlighterPane (the script text area).
+ * <b>Note: Normally should not operate on the SyntaxHighlighterPane
+ * directly.</b>
* @return the SyntaxHighlighterPane
*/
public SyntaxHighlighterPane getHighlighter() {
@@ -123,7 +128,6 @@
* Get the JTextComponentRowHeader, the line number panel.
* <b>Note: Normally should not operate on the JTextComponentRowHeader
* directly.</b>
- *
* @return the JTextComponentRowHeader
*/
public JTextComponentRowHeader getHighlighterRowHeader() {
@@ -132,7 +136,6 @@
/**
* Get current theme.
- *
* @return the current theme
*/
public Theme getTheme() {
@@ -143,7 +146,6 @@
* Set the theme.
* Setting the theme will not re-parse the content, but will clear and apply
* the new theme on the script text pane.
- *
* @param theme the theme
*/
public void setTheme(Theme theme) {
@@ -161,7 +163,6 @@
/**
* Set the line number of the first line. E.g. if set 10, the line number will
* start count from 10 instead of 1.
- *
* @param firstLine the line number of the first line
*/
public void setFirstLine(int firstLine) {
@@ -171,7 +172,6 @@
/**
* Get the list of highlighted lines.
- *
* @return a copy of the list
*/
public List<Integer> getHighlightedLineList() {
@@ -181,7 +181,6 @@
/**
* Set highlighted lines. Note that this will clear all previous recorded
* highlighted lines.
- *
* @param highlightedLineList the list that contain the highlighted lines,
* null means highlight no lines
*/
@@ -192,7 +191,6 @@
/**
* Add highlighted line.
- *
* @param lineNumber the line number to highlight
*/
public void addHighlightedLine(int lineNumber) {
@@ -202,7 +200,6 @@
/**
* Check the visibility of the gutter.
- *
* @return true if the gutter is visible, false if not
*/
public boolean isGutterVisible() {
@@ -211,7 +208,6 @@
/**
* Set the visibility of the gutter.
- *
* @param visible true to make visible, false to hide it
*/
public void setGutterVisible(boolean visible) {
@@ -226,7 +222,6 @@
/**
* Check the status of the mouse-over highlight effect. Default is on.
- *
* @return true if turned on, false if turned off
*/
public boolean isHighlightOnMouseOver() {
@@ -236,9 +231,8 @@
/**
* Set turn on the mouse-over highlight effect or not.
* If set true, there will be a highlight effect on the line that the mouse
- * cursor currently is pointing on (on the script text panel only, not on the
+ * cursor currently is pointing on (on the script text area only, not on the
* line number panel).
- *
* @param highlightWhenMouseOver true to turn on, false to turn off
*/
public void setHighlightOnMouseOver(boolean highlightWhenMouseOver) {
@@ -248,9 +242,7 @@
/**
* Set the content of the syntax highlighter. Better set it last after setting
* all other settings.
- *
* @param file the file to read
- *
* @throws IOException error occurred when reading the file
*/
public void setContent(File file) throws IOException {
@@ -260,7 +252,6 @@
/**
* Set the content of the syntax highlighter. It is better to set other
* settings first and set this the last.
- *
* @param content the content to set, null means no content
*/
public void setContent(String content) {
@@ -271,11 +262,8 @@
/**
* Get the string content of a file.
- *
* @param file the file to retrieve the content from
- *
* @return the string content
- *
* @throws IOException error occured when reading the file
*/
protected static String readFile(File file) throws IOException {
diff --git a/src/syntaxhighlight/SyntaxHighlighterPane.java b/src/syntaxhighlight/SyntaxHighlighterPane.java
index 482b87f..95aa1d4 100644
--- a/src/syntaxhighlight/SyntaxHighlighterPane.java
+++ b/src/syntaxhighlight/SyntaxHighlighterPane.java
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 Chan Wai Shing
+// Copyright (c) 2012 Chan Wai Shing
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -411,7 +411,7 @@
* @param offset the offset
*/
public void setLineNumberOffset(int offset) {
- lineNumberOffset = Math.max(lineNumberOffset, offset);
+ lineNumberOffset = Math.max(0, offset);
repaint();
}
@@ -449,7 +449,7 @@
/**
* Set turn on the mouse-over highlight effect or not. Default is on.
* If set true, there will be a highlight effect on the line that the mouse
- * cursor currently is pointing on (on the script text panel only, not on the
+ * cursor currently is pointing on (on the script text area only, not on the
* line number panel).
*
* @param highlightWhenMouseOver true to turn on, false to turn off
diff --git a/src/syntaxhighlight/Theme.java b/src/syntaxhighlight/Theme.java
index 0449e15..d4ab764 100644
--- a/src/syntaxhighlight/Theme.java
+++ b/src/syntaxhighlight/Theme.java
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 Chan Wai Shing
+// Copyright (c) 2012 Chan Wai Shing
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -28,10 +28,12 @@
import javax.swing.text.SimpleAttributeSet;
/**
- * Theme for the syntax highlighter.
- * To make a new theme, either extending this class of initiate this class
- * and set the parameter by the setter. For the default value, please refer to
- * the constructor.
+ * Theme for the {@link SyntaxHighlighterPane} and
+ * {@link JTextComponentRowHeader}.
+ *
+ * To make a new theme, either extending this class or initiate this class and
+ * set parameters using setters. For the default value, find the comment of the
+ * constructor.
*
* @author Chan Wai Shing <cws1989@gmail.com>
*/
@@ -58,11 +60,11 @@
*/
protected Color gutterText;
/**
- * The color of the border that joint the gutter and the script text panel.
+ * The color of the border that joint the gutter and the script text area.
*/
protected Color gutterBorderColor;
/**
- * The width of the border that joint the gutter and the script text panel.
+ * The width of the border that joint the gutter and the script text area.
*/
protected int gutterBorderWidth;
/**
@@ -79,7 +81,17 @@
* 'the right margin' (not to the gutter border).
*/
protected int gutterTextPaddingRight;
+ /**
+ * Text area.
+ */
+ /**
+ * The default style. When the style requested by {@link #getStyle(String)}
+ * not exist, this will be returned.
+ */
protected Style plain;
+ /**
+ * The styles of this theme.
+ */
protected Map<String, Style> styles;
/**
@@ -118,7 +130,7 @@
/**
* Apply the theme to the row header panel.
- * @param rowHeader the row header to apply theme on
+ * @param rowHeader the row header to apply the theme on
*/
public void setTheme(JTextComponentRowHeader rowHeader) {
rowHeader.setBackground(background);
@@ -132,6 +144,10 @@
rowHeader.setPaddingRight(gutterTextPaddingRight);
}
+ /**
+ * Set the default style.
+ * @param plain the style
+ */
public void setPlain(Style plain) {
if (plain == null) {
throw new NullPointerException("argument 'plain' cannot be null");
@@ -139,15 +155,25 @@
this.plain = plain;
}
+ /**
+ * Get the default style.
+ * @return the style
+ */
public Style getPlain() {
return plain;
}
- public SimpleAttributeSet getStyleAttributeSet(String styleKeys) {
+ /**
+ * Get the {@link AttributeSet} of {@code styleKeys}. For more than one
+ * styles, separate the styles by space, e.g. 'plain comments'.
+ * @param styleKeys the style keys with keys separated by space
+ * @return the combined {@link AttributeSet}
+ */
+ public SimpleAttributeSet getStylesAttributeSet(String styleKeys) {
if (styleKeys.indexOf(' ') != -1) {
SimpleAttributeSet returnAttributeSet = new SimpleAttributeSet();
- String[] keys = styleKeys.split(" ");
- for (String _key : keys) {
+ String[] _keys = styleKeys.split(" ");
+ for (String _key : _keys) {
returnAttributeSet.addAttributes(getStyle(_key).getAttributeSet());
}
return returnAttributeSet;
@@ -156,32 +182,48 @@
}
}
+ /**
+ * Add style.
+ * @param styleKey the keyword of the style
+ * @param style the style
+ * @return see the return value of {@link Map#put(Object, Object)}
+ */
public Style addStyle(String styleKey, Style style) {
return styles.put(styleKey, style);
}
+ /**
+ * Remove style by keyword.
+ * @param styleKey the keyword of the style
+ * @return see the return value of {@link Map#remove(Object)}
+ */
public Style removeStyle(String styleKey) {
return styles.remove(styleKey);
}
/**
- * Get the {@link syntaxhighlighter.theme.Style} by keyword.
- *
+ * Get the style by keyword.
* @param key the keyword
- *
* @return the {@link syntaxhighlighter.theme.Style} related to the
- * {@code key}; if the style related to the <code>key</code> not exist,
- * the style of 'plain' will return.
+ * {@code key}; if the style related to the {@code key} not exist, the
+ * style of 'plain' will return.
*/
public Style getStyle(String key) {
Style returnStyle = styles.get(key);
return returnStyle != null ? returnStyle : plain;
}
+ /**
+ * Get all styles.
+ * @return the styles
+ */
public Map<String, Style> getStyles() {
return new HashMap<String, Style>(styles);
}
+ /**
+ * Clear all styles.
+ */
public void clearStyles() {
styles.clear();
}
@@ -263,7 +305,7 @@
}
/**
- * The color of the border that joint the gutter and the script text panel.
+ * The color of the border that joint the gutter and the script text area.
* @return the color
*/
public Color getGutterBorderColor() {
@@ -271,7 +313,7 @@
}
/**
- * The color of the border that joint the gutter and the script text panel.
+ * The color of the border that joint the gutter and the script text area.
* @param gutterBorderColor the color
*/
public void setGutterBorderColor(Color gutterBorderColor) {
@@ -282,7 +324,7 @@
}
/**
- * The width of the border that joint the gutter and the script text panel.
+ * The width of the border that joint the gutter and the script text area.
* @return the width in pixel
*/
public int getGutterBorderWidth() {
@@ -290,7 +332,7 @@
}
/**
- * The width of the border that joint the gutter and the script text panel.
+ * The width of the border that joint the gutter and the script text area.
* @param gutterBorderWidth in pixel
*/
public void setGutterBorderWidth(int gutterBorderWidth) {
@@ -376,16 +418,17 @@
public String toString() {
StringBuilder sb = new StringBuilder();
+ sb.append("[");
sb.append(getClass().getName());
sb.append(": ");
sb.append("font: ").append(getFont());
- sb.append(", ");
+ sb.append("; ");
sb.append("background: ").append(getBackground());
- sb.append(", ");
+ sb.append("; ");
sb.append("highlightedBackground: ").append(getHighlightedBackground());
- sb.append(", ");
+ sb.append("; ");
sb.append("gutterText: ").append(getGutterText());
- sb.append(", ");
+ sb.append("; ");
sb.append("gutterBorderColor: ").append(getGutterBorderColor());
sb.append(", ");
sb.append("gutterBorderWidth: ").append(getGutterBorderWidth());
@@ -395,6 +438,12 @@
sb.append("gutterTextPaddingLeft: ").append(getGutterTextPaddingLeft());
sb.append(", ");
sb.append("gutterTextPaddingRight: ").append(getGutterTextPaddingRight());
+ sb.append(", ");
+ sb.append("styles: ");
+ for (String _key : styles.keySet()) {
+ sb.append(_key).append(":").append(styles.get(_key));
+ }
+ sb.append("]");
return sb.toString();
}