Fixes and updates

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

No files matched your search

@@ -18,6 +18,7 @@ import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
@@ -141,6 +142,7 @@ public class GlobalSearchBox extends JFrame {
if (ignoreCase) {
str = str.toLowerCase();
}
String fstr = str;
for (ClassNode cn : Main.classNodes.values()) {
for (MethodNode mn : cn.methods) {
for (AbstractInsnNode insn : mn.instructions.toArray()) {
@@ -154,6 +156,15 @@ public class GlobalSearchBox extends JFrame {
}
}
}
if (mn.visibleAnnotations != null) {
for (AnnotationNode anno : mn.visibleAnnotations) {
if (anno.values == null)
continue;
anno.values.stream().filter(o -> o instanceof String).map(o -> (String) o)
.map(s -> ignoreCase ? s.toLowerCase() : s).filter(s -> s.contains(fstr))
.forEach(s -> set.add(new Info(cn.name, mn.name, mn.desc, mn)));
}
}
}
}
} else {
+8 -123
View File
@@ -106,7 +106,7 @@ public class Disassembler {
AtomicInteger lineFound = new AtomicInteger(-1);
StringContext ctx = new StringContext(18);
ctx.next("// #Annotations:\n");
ctx.next(doAnnotations(classNode.visibleAnnotations, hs));
ctx.next(doAnnotations(classNode.visibleAnnotations, hs, ""));
ctx.next("// #Class v:" + classNode.version + "\n");
if (classNode.signature != null)
ctx.next("// #Signature: " + UnicodeUtils.escapeWithSpaces(hs, classNode.signature) + "\n");
@@ -165,12 +165,12 @@ public class Disassembler {
}
}
private static String doAnnotations(List<AnnotationNode> annotations, HugeStrings hs) {
private static String doAnnotations(List<AnnotationNode> annotations, HugeStrings hs, String linePrefix) {
if (annotations == null)
return "";
StringContext ctx = new StringContext(annotations.size());
for (AnnotationNode annotationNode : annotations) {
String s = "@" + UnicodeUtils.escapeWithSpaces(hs, annotationNode.desc);
String s = linePrefix + "@" + UnicodeUtils.escapeWithSpaces(hs, annotationNode.desc);
if (annotationNode.values != null && !annotationNode.values.isEmpty()) {
s += " (";
boolean valBefore = true;
@@ -213,7 +213,7 @@ public class Disassembler {
s += ", ";
}
s = s.substring(0, s.length() - 2);
s += " }]";
s += " }], ";
} else if (o instanceof String) {
s += "\"" + UnicodeUtils.escapeWithSpaces(hs, (String) o) + "\"], ";
} else {
@@ -249,66 +249,8 @@ public class Disassembler {
String[] dis = disassembleMethod(className, mn, hs);
ms += dis[2];
ms += dis[1];
if (mn.visibleAnnotations != null && !mn.visibleAnnotations.isEmpty()) {
for (AnnotationNode annotationNode : mn.visibleAnnotations) {
ms += "\t@" + annotationNode.desc;
if (annotationNode.values != null && !annotationNode.values.isEmpty()) {
ms += " (";
boolean valBefore = true;
for (Object o : annotationNode.values) {
if (valBefore) {
ms += o + " = [";
valBefore = false;
continue;
} else {
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
ms += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
ms += UnicodeUtils.escapeWithSpaces(hs, rofl) + "]";
}
}
ms += ", ";
} else if (o instanceof List) {
List list = (List) o;
ms += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
ms += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
ms += UnicodeUtils.escapeWithSpaces(hs, rofl);
}
}
} else {
ms += "\"" + UnicodeUtils.escape(hs, String.valueOf(obj))
+ "\"";
}
ms += ", ";
}
ms = ms.substring(0, ms.length() - 2);
ms += " }]";
} else {
ms += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
}
}
if (ms.endsWith(", "))
ms = ms.substring(0, ms.length() - 2);
ms += ")";
}
ms += "\n";
}
}
if (mn.visibleAnnotations != null && !mn.visibleAnnotations.isEmpty())
ms += doAnnotations(mn.visibleAnnotations, hs, "\t");
if (mn.equals(nodeToFind)) {
lineFound.set(ms.split("\\n").length);
}
@@ -359,65 +301,8 @@ public class Disassembler {
String s = "";
if (fn.signature != null)
s += "\t// #Signature: " + UnicodeUtils.escapeWithSpaces(hs, fn.signature) + "\n";
if (fn.visibleAnnotations != null && !fn.visibleAnnotations.isEmpty()) {
for (AnnotationNode annotationNode : fn.visibleAnnotations) {
s += "\t@" + UnicodeUtils.escapeWithSpaces(hs, annotationNode.desc);
if (annotationNode.values != null && !annotationNode.values.isEmpty()) {
s += " (";
boolean valBefore = true;
for (Object o : annotationNode.values) {
if (valBefore) {
s += o + " = [";
valBefore = false;
continue;
} else {
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "]";
}
}
s += ", ";
} else if (o instanceof List) {
List list = (List) o;
s += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(hs, rofl);
}
}
} else {
s += "\"" + UnicodeUtils.escape(hs, String.valueOf(obj)) + "\"";
}
s += ", ";
}
s = s.substring(0, s.length() - 2);
s += " }]";
} else {
s += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
}
}
if (s.endsWith(", "))
s = s.substring(0, s.length() - 2);
s += ")";
}
s += "\n";
}
}
if (fn.visibleAnnotations != null && !fn.visibleAnnotations.isEmpty())
s += doAnnotations(fn.visibleAnnotations, hs, "\t");
if (fn.equals(nodeToFind)) {
lineFound.set(s.split("\\n").length);
}
+14 -12
View File
@@ -33,12 +33,12 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
@@ -311,7 +311,7 @@ public class Main extends JFrame {
new Thread(new Runnable() {
public void run() {
try {
ArchiveTreeModel model = new ArchiveTreeModel(new JarFile(jarFile));
ArchiveTreeModel model = new ArchiveTreeModel(new ZipFile(jarFile));
EventQueue.invokeLater(new Runnable() {
public void run() {
synchronized (treeLock) {
@@ -466,7 +466,7 @@ public class Main extends JFrame {
new Thread(new Runnable() {
public void run() {
try {
ArchiveTreeModel model = new ArchiveTreeModel(new JarFile(jarFile));
ArchiveTreeModel model = new ArchiveTreeModel(new ZipFile(jarFile));
EventQueue.invokeLater(new Runnable() {
public void run() {
synchronized (treeLock) {
@@ -560,7 +560,7 @@ public class Main extends JFrame {
new Thread(new Runnable() {
public void run() {
try {
ArchiveTreeModel model = new ArchiveTreeModel(new JarFile(jarFile));
ArchiveTreeModel model = new ArchiveTreeModel(new ZipFile(jarFile));
EventQueue.invokeLater(new Runnable() {
public void run() {
synchronized (treeLock) {
@@ -786,6 +786,8 @@ public class Main extends JFrame {
public void goToSelected() throws BadLocationException {
int lineStart = txtByteEditView.getLineStartOffsetOfCurrentLine();
int lineEnd = txtByteEditView.getLineEndOffsetOfCurrentLine() - 1;
if (lineEnd < lineStart)
return;
String line = txtByteEditView.getText(lineStart, lineEnd - lineStart);
if (!jumpableInstructionPattern.matcher(line).matches()) {
return;
@@ -1042,7 +1044,7 @@ public class Main extends JFrame {
public void save(File jar, Collection<ClassNode> classes) {
try {
final JarOutputStream output = new JarOutputStream(new FileOutputStream(jar));
final ZipOutputStream output = new ZipOutputStream(new FileOutputStream(jar));
if (tree.getModel().getClass().equals(DefaultTreeModel.class)
|| ((ArchiveTreeModel) tree.getModel()).newCreated) {
int acc = ClassUtil.ACC_PUBLIC | ClassUtil.ACC_STATIC;
@@ -1067,7 +1069,7 @@ public class Main extends JFrame {
((ArchiveTreeModel) tree.getModel()).newCreated = false;
}
for (Entry<String, byte[]> entry : OTHER_FILES.entrySet()) {
JarEntry ent = new JarEntry(entry.getKey());
ZipEntry ent = new ZipEntry(entry.getKey());
output.putNextEntry(ent);
output.write(entry.getValue());
output.closeEntry();
@@ -1082,7 +1084,7 @@ public class Main extends JFrame {
for (ClassNode node : classes) {
ClassWriter writer = new ClassWriter(computeFlags);
node.accept(writer);
output.putNextEntry(new JarEntry(getFullName(node.name)));
output.putNextEntry(new ZipEntry(getFullName(node.name)));
output.write(writer.toByteArray());
output.closeEntry();
}
@@ -1123,16 +1125,16 @@ public class Main extends JFrame {
newCreated = true;
}
public ArchiveTreeModel(JarFile jar) {
public ArchiveTreeModel(ZipFile jar) {
super(new ByteEditTreeNode(jar.getName().split(File.separator.equals("\\") ? "\\\\"
: File.separator)[jar.getName().split(File.separator.equals("\\") ? "\\\\" : File.separator).length
- 1]));
try {
classNodes.clear();
OTHER_FILES.clear();
Enumeration<JarEntry> enumeration = jar.entries();
Enumeration<? extends ZipEntry> enumeration = jar.entries();
while (enumeration.hasMoreElements()) {
JarEntry next = enumeration.nextElement();
ZipEntry next = enumeration.nextElement();
byte[] data = toByteArray(jar.getInputStream(next));
if (next.getSize() != 0 && !next.getName().startsWith("META-INF")
&& (next.getName().endsWith(".class") || next.getName().endsWith(".class/"))) {
+1 -1
View File
@@ -12,7 +12,7 @@
<baseFont size="12"/>
<!-- General editor colors. -->
<background color="ffffff"/>
<background color="c0c0c0"/>
<caret color="000000"/>
<selection bg="dddddd" fg="000000"/>
<currentLineHighlight color="dddddd" fade="false"/>
+3 -3
View File
@@ -12,10 +12,10 @@
<baseFont size="12"/>
<!-- General editor colors. -->
<background color="000000"/>
<background color="2f2f2f"/>
<caret color="eeeeee"/>
<selection bg="222222" fg="eeeeee"/>
<currentLineHighlight color="222222" fade="false"/>
<selection bg="111111" fg="eeeeee"/>
<currentLineHighlight color="111111" fade="false"/>
<marginLine fg="4f4b46"/>
<markAllHighlight color="947e76"/> <!-- TODO: Fix me -->
<markOccurrencesHighlight color="2b2b2b" border="false"/>
+26 -34
View File
@@ -41,8 +41,7 @@ public class DocumentReader extends Reader {
/**
* Constructor.
*
* @param document
* The document we're 'reading'.
* @param document The document we're 'reading'.
*/
public DocumentReader(Document document) {
position = 0;
@@ -55,14 +54,14 @@ public class DocumentReader extends Reader {
* This currently does nothing...
*/
@Override
public void close() {}
public void close() {
}
/**
* Marks the present position in the stream. Subsequent calls to
* <code>reset()</code> will reposition the stream to this point.
*
* @param readAheadLimit
* Ignored.
* @param readAheadLimit Ignored.
*/
@Override
public void mark(int readAheadLimit) {
@@ -70,8 +69,8 @@ public class DocumentReader extends Reader {
}
/**
* Tells whether this reader supports the <code>mark</code> operation.
* This always returns <code>true</code> for <code>DocumentReader</code>.
* Tells whether this reader supports the <code>mark</code> operation. This
* always returns <code>true</code> for <code>DocumentReader</code>.
*/
@Override
public boolean markSupported() {
@@ -98,11 +97,10 @@ public class DocumentReader extends Reader {
}
/**
* Read <code>array.length</code> characters from the beginning
* of the document into <code>array</code>.
* Read <code>array.length</code> characters from the beginning of the document
* into <code>array</code>.
*
* @param array
* The array to read characters into.
* @param array The array to read characters into.
* @return The number of characters read.
*/
@Override
@@ -113,14 +111,11 @@ public class DocumentReader extends Reader {
/**
* Reads characters into a portion of an array.
*
* @param cbuf
* The destination buffer.
* @param off
* Offset at which to start storing characters.
* @param len
* Maximum number of characters to read.
* @return The number of characters read, or <code>-1</code> if the
* end of the stream (document) has been reached.
* @param cbuf The destination buffer.
* @param off Offset at which to start storing characters.
* @param len Maximum number of characters to read.
* @return The number of characters read, or <code>-1</code> if the end of the
* stream (document) has been reached.
*/
@Override
public int read(char[] cbuf, int off, int len) {
@@ -147,12 +142,11 @@ public class DocumentReader extends Reader {
}
/**
* Tells whether this reader is ready to be read without
* blocking for input. <code>DocumentReader</code> will
* always return true.
* Tells whether this reader is ready to be read without blocking for input.
* <code>DocumentReader</code> will always return true.
*
* @return <code>true</code> if the next read operation will
* return without blocking.
* @return <code>true</code> if the next read operation will return without
* blocking.
*/
@Override
public boolean ready() {
@@ -160,9 +154,9 @@ public class DocumentReader extends Reader {
}
/**
* Resets the stream. If the stream has been marked, then attempt to
* reposition it at the mark. If the stream has not been marked, then
* move it to the beginning of the document.
* Resets the stream. If the stream has been marked, then attempt to reposition
* it at the mark. If the stream has not been marked, then move it to the
* beginning of the document.
*/
@Override
public void reset() {
@@ -177,8 +171,7 @@ public class DocumentReader extends Reader {
/**
* Skips characters. This will not 'skip' past the end of the document.
*
* @param n
* The number of characters to skip.
* @param n The number of characters to skip.
* @return The number of characters actually skipped.
*/
@Override
@@ -193,12 +186,11 @@ public class DocumentReader extends Reader {
}
/**
* Move to the specified position in the document. If <code>pos</code>
* is greater than the document's length, the stream's position is moved
* to the end of the document.
* Move to the specified position in the document. If <code>pos</code> is
* greater than the document's length, the stream's position is moved to the end
* of the document.
*
* @param pos
* The position in the document to move to.
* @param pos The position in the document to move to.
*/
public void seek(long pos) {
position = Math.min(pos, document.getLength());
+34 -60
View File
@@ -30,10 +30,9 @@ import java.io.Writer;
public class UnicodeWriter extends Writer {
/**
* If this system property evaluates to "<code>false</code>", ignoring
* case, files written out as UTF-8 will not have a BOM written for them.
* Otherwise (even if the property is not set), UTF-8 files will have a
* BOM written.
* If this system property evaluates to "<code>false</code>", ignoring case,
* files written out as UTF-8 will not have a BOM written for them. Otherwise
* (even if the property is not set), UTF-8 files will have a BOM written.
*/
public static final String PROPERTY_WRITE_UTF8_BOM = "UnicodeWriter.writeUtf8BOM";
/**
@@ -47,30 +46,24 @@ public class UnicodeWriter extends Writer {
private static final byte[] UTF32BE_BOM = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0xFE, (byte) 0xFF };
/**
* This is a utility constructor since the vast majority of the time, this
* class will be used to write Unicode files.
* This is a utility constructor since the vast majority of the time, this class
* will be used to write Unicode files.
*
* @param fileName
* The file to which to write the Unicode output.
* @param encoding
* The encoding to use.
* @throws IOException
* If an IO exception occurs.
* @param fileName The file to which to write the Unicode output.
* @param encoding The encoding to use.
* @throws IOException If an IO exception occurs.
*/
public UnicodeWriter(String fileName, String encoding) throws IOException {
this(new FileOutputStream(fileName), encoding);
}
/**
* This is a utility constructor since the vast majority of the time, this
* class will be used to write Unicode files.
* This is a utility constructor since the vast majority of the time, this class
* will be used to write Unicode files.
*
* @param file
* The file to which to write the Unicode output.
* @param encoding
* The encoding to use.
* @throws IOException
* If an IO exception occurs.
* @param file The file to which to write the Unicode output.
* @param encoding The encoding to use.
* @throws IOException If an IO exception occurs.
*/
public UnicodeWriter(File file, String encoding) throws IOException {
this(new FileOutputStream(file), encoding);
@@ -79,12 +72,9 @@ public class UnicodeWriter extends Writer {
/**
* Creates a new writer.
*
* @param out
* The output stream to write.
* @param encoding
* The encoding to use.
* @throws IOException
* If an IO exception occurs.
* @param out The output stream to write.
* @param encoding The encoding to use.
* @throws IOException If an IO exception occurs.
*/
public UnicodeWriter(OutputStream out, String encoding) throws IOException {
init(out, encoding);
@@ -93,8 +83,7 @@ public class UnicodeWriter extends Writer {
/**
* Closes this writer.
*
* @throws IOException
* If an IO exception occurs.
* @throws IOException If an IO exception occurs.
*/
@Override
public void close() throws IOException {
@@ -104,8 +93,7 @@ public class UnicodeWriter extends Writer {
/**
* Flushes the stream.
*
* @throws IOException
* If an IO exception occurs.
* @throws IOException If an IO exception occurs.
*/
@Override
public void flush() throws IOException {
@@ -139,15 +127,12 @@ public class UnicodeWriter extends Writer {
}
/**
* Initializes the internal output stream and writes the BOM if the
* specified encoding is a Unicode encoding.
* Initializes the internal output stream and writes the BOM if the specified
* encoding is a Unicode encoding.
*
* @param out
* The output stream we are writing.
* @param encoding
* The encoding in which to write.
* @throws IOException
* If an I/O error occurs while writing a BOM.
* @param out The output stream we are writing.
* @param encoding The encoding in which to write.
* @throws IOException If an I/O error occurs while writing a BOM.
*/
private void init(OutputStream out, String encoding) throws IOException {
internalOut = new OutputStreamWriter(out, encoding);
@@ -173,8 +158,7 @@ public class UnicodeWriter extends Writer {
/**
* Sets whether UTF-8 files should have a BOM written in them.
*
* @param write
* Whether to write a BOM.
* @param write Whether to write a BOM.
* @see #getWriteUtf8BOM()
* @see UnicodeWriter
*/
@@ -185,14 +169,10 @@ public class UnicodeWriter extends Writer {
/**
* Writes a portion of an array of characters.
*
* @param cbuf
* The buffer of characters.
* @param off
* The offset from which to start writing characters.
* @param len
* The number of characters to write.
* @throws IOException
* If an I/O error occurs.
* @param cbuf The buffer of characters.
* @param off The offset from which to start writing characters.
* @param len The number of characters to write.
* @throws IOException If an I/O error occurs.
*/
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
@@ -202,10 +182,8 @@ public class UnicodeWriter extends Writer {
/**
* Writes a single character.
*
* @param c
* An integer specifying the character to write.
* @throws IOException
* If an IO error occurs.
* @param c An integer specifying the character to write.
* @throws IOException If an IO error occurs.
*/
@Override
public void write(int c) throws IOException {
@@ -215,14 +193,10 @@ public class UnicodeWriter extends Writer {
/**
* Writes a portion of a string.
*
* @param str
* The string from which to write.
* @param off
* The offset from which to start writing characters.
* @param len
* The number of characters to write.
* @throws IOException
* If an IO error occurs.
* @param str The string from which to write.
* @param off The offset from which to start writing characters.
* @param len The number of characters to write.
* @throws IOException If an IO error occurs.
*/
@Override
public void write(String str, int off, int len) throws IOException {
+55 -78
View File
@@ -55,24 +55,18 @@ public abstract class RPrintUtilities {
/**
* Returns the position closest to, but before, position
* <code>maxCharsPerLine</code> in
* <code>line</code> of one of the chars in <code>breakChars</code>, or
* simply returns
* <code>maxCharsPerLine-1</code> if none of the <code>breakChars</code>
* comes before
* that position. This position represents the logical line break for this
* <code>java.lang.String</code>
* if it is being printed in a monospaced font when lines can only be
* <code>maxCharsPerLine</code>
* characters long.
* <code>maxCharsPerLine</code> in <code>line</code> of one of the chars in
* <code>breakChars</code>, or simply returns <code>maxCharsPerLine-1</code> if
* none of the <code>breakChars</code> comes before that position. This position
* represents the logical line break for this <code>java.lang.String</code> if
* it is being printed in a monospaced font when lines can only be
* <code>maxCharsPerLine</code> characters long.
*
* @param line
* The text being printed.
* @param maxCharsPerLine
* Only up-to this many characters from
* <code>line</code> can be printed on one line.
* @return The logical position at which to stop printing <code>line</code>
* to simulate word wrap.
* @param line The text being printed.
* @param maxCharsPerLine Only up-to this many characters from <code>line</code>
* can be printed on one line.
* @return The logical position at which to stop printing <code>line</code> to
* simulate word wrap.
*/
private static int getLineBreakPoint(String line, final int maxCharsPerLine) {
int breakPoint = -1;
@@ -87,27 +81,20 @@ public abstract class RPrintUtilities {
/**
* Prints a <code>Document</code> using a monospaced font, and does no word
* wrapping (ie,
* words will wrap mid-word to the next line). This method is expected to be
* called from
* Printable 'print(Graphics g)' functions.
* wrapping (ie, words will wrap mid-word to the next line). This method is
* expected to be called from Printable 'print(Graphics g)' functions.
*
* @param g
* The graphics context to write to.
* @param doc
* The <code>javax.swing.text.Document</code> to print.
* @param fontSize
* the point size to use for the monospaced font.
* @param pageIndex
* The page number to print.
* @param pageFormat
* The format to print the page with.
* @param tabSize
* The number of spaces to expand tabs to.
* @param g The graphics context to write to.
* @param doc The <code>javax.swing.text.Document</code> to print.
* @param fontSize the point size to use for the monospaced font.
* @param pageIndex The page number to print.
* @param pageFormat The format to print the page with.
* @param tabSize The number of spaces to expand tabs to.
*
* @see #printDocumentMonospacedWordWrap
*/
public static int printDocumentMonospaced(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat, int tabSize) {
public static int printDocumentMonospaced(Graphics g, Document doc, int fontSize, int pageIndex,
PageFormat pageFormat, int tabSize) {
g.setColor(Color.BLACK);
g.setFont(new Font("Monospaced", Font.PLAIN, fontSize));
// Initialize our static variables (these are used by our tab expander
@@ -204,27 +191,21 @@ public abstract class RPrintUtilities {
}
/**
* Prints a <code>Document</code> using a monospaced font, word wrapping on
* the characters ' ', '\t', '\n', ',', '.', and ';'. This method is
* expected to be called from Printable 'print(Graphics g)' functions.
* Prints a <code>Document</code> using a monospaced font, word wrapping on the
* characters ' ', '\t', '\n', ',', '.', and ';'. This method is expected to be
* called from Printable 'print(Graphics g)' functions.
*
* @param g
* The graphics context to write to.
* @param doc
* The <code>javax.swing.text.Document</code> to print.
* @param fontSize
* the point size to use for the monospaced font.
* @param pageIndex
* The page number to print.
* @param pageFormat
* The format to print the page with.
* @param tabSize
* The number of spaces to expand tabs to.
* @param g The graphics context to write to.
* @param doc The <code>javax.swing.text.Document</code> to print.
* @param fontSize the point size to use for the monospaced font.
* @param pageIndex The page number to print.
* @param pageFormat The format to print the page with.
* @param tabSize The number of spaces to expand tabs to.
*
* @see #printDocumentMonospaced
*/
public static int printDocumentMonospacedWordWrap(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat,
int tabSize) {
public static int printDocumentMonospacedWordWrap(Graphics g, Document doc, int fontSize, int pageIndex,
PageFormat pageFormat, int tabSize) {
g.setColor(Color.BLACK);
g.setFont(new Font("Monospaced", Font.PLAIN, fontSize));
// Initialize our static variables (these are used by our tab expander
@@ -322,28 +303,22 @@ public abstract class RPrintUtilities {
}
/**
* Prints a <code>Document</code> using the specified font, word wrapping
* on the characters ' ', '\t', '\n', ',', '.', and ';'. This method is
* expected to be called from Printable 'print(Graphics g)' functions.
* Prints a <code>Document</code> using the specified font, word wrapping on the
* characters ' ', '\t', '\n', ',', '.', and ';'. This method is expected to be
* called from Printable 'print(Graphics g)' functions.
*
* @param g
* The graphics context to write to.
* @param textComponent
* The <code>javax.swing.text.JTextComponent</code>
* whose text you're printing.
* @param font
* The font to use for printing. If <code>null</code>, then
* @param g The graphics context to write to.
* @param textComponent The <code>javax.swing.text.JTextComponent</code> whose
* text you're printing.
* @param font The font to use for printing. If <code>null</code>, then
* <code>textComponent</code>'s font is used.
* @param pageIndex
* The page number to print.
* @param pageFormat
* The format to print the page with.
* @param tabSize
* The number of spaces to convert tabs to.
* @param pageIndex The page number to print.
* @param pageFormat The format to print the page with.
* @param tabSize The number of spaces to convert tabs to.
*
*/
public static int printDocumentWordWrap(Graphics g, JTextComponent textComponent, Font font, int pageIndex, PageFormat pageFormat,
int tabSize) {
public static int printDocumentWordWrap(Graphics g, JTextComponent textComponent, Font font, int pageIndex,
PageFormat pageFormat, int tabSize) {
// Initialize our graphics object.
g.setColor(Color.BLACK);
g.setFont(font != null ? font : textComponent.getFont());
@@ -389,7 +364,8 @@ public abstract class RPrintUtilities {
// we'd start after the part
// that has already been printed).
try {
doc.getText(currentLineStart + startingOffset, currentLineEnd - (currentLineStart + startingOffset), currentLineSeg);
doc.getText(currentLineStart + startingOffset, currentLineEnd - (currentLineStart + startingOffset),
currentLineSeg);
} catch (BadLocationException ble) {
System.err.println("BadLocationException in print (where there shouldn't be one!): " + ble);
return Printable.NO_SUCH_PAGE;
@@ -452,7 +428,8 @@ public abstract class RPrintUtilities {
System.err.println(ble);
return Printable.NO_SUCH_PAGE;
}
currentLineLengthInPixels = Utilities.getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander, 0);
currentLineLengthInPixels = Utilities.getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander,
0);
} while (currentLineLengthInPixels <= lineLengthInPixels);
currentPos--;
}
@@ -460,8 +437,8 @@ public abstract class RPrintUtilities {
doc.getText((currentLineStart + startingOffset), currentPos, currentLineSeg);
} catch (BadLocationException ble) {
System.err.println("BadLocationException in print (a):");
System.err.println("==> currentLineStart: " + currentLineStart + "; startingOffset: " + startingOffset
+ "; currentPos: " + currentPos);
System.err.println("==> currentLineStart: " + currentLineStart + "; startingOffset: "
+ startingOffset + "; currentPos: " + currentPos);
System.err.println("==> Range: " + (currentLineStart + startingOffset) + " - "
+ (currentLineStart + startingOffset + currentPos));
ble.printStackTrace();
@@ -495,8 +472,7 @@ public abstract class RPrintUtilities {
/**
* Removes any spaces or tabs from the end of the segment.
*
* @param segment
* The segment from which to remove tailing whitespace.
* @param segment The segment from which to remove tailing whitespace.
* @return <code>segment</code> with trailing whitespace removed.
*/
private static Segment removeEndingWhitespace(Segment segment) {
@@ -512,12 +488,13 @@ public abstract class RPrintUtilities {
}
/**
* A tab expander for the document currently being printed with the
* font being used for the printing.
* A tab expander for the document currently being printed with the font being
* used for the printing.
*/
private static class RPrintTabExpander implements TabExpander {
RPrintTabExpander() {}
RPrintTabExpander() {
}
@Override
public float nextTabStop(float x, int tabOffset) {
@@ -17,11 +17,11 @@ import javax.swing.text.JTextComponent;
* lexicographically (ignoring case).
* <p>
*
* This implementation assumes the input text and replacement text are the
* same value. It also returns the input text from its {@link #toString()}
* method (which is what <code>DefaultListCellRenderer</code> uses to render
* objects). Subclasses that wish to override any of this behavior can simply
* override the corresponding method(s) needed to do so.
* This implementation assumes the input text and replacement text are the same
* value. It also returns the input text from its {@link #toString()} method
* (which is what <code>DefaultListCellRenderer</code> uses to render objects).
* Subclasses that wish to override any of this behavior can simply override the
* corresponding method(s) needed to do so.
*
* @author Robert Futrell
* @version 1.0
@@ -38,17 +38,16 @@ public abstract class AbstractCompletion implements Completion {
private Icon icon;
/**
* The relevance of this completion. Completion instances with higher
* "relevance" values are inserted higher into the list of possible
* completions than those with lower values. Completion instances with
* equal relevance values are sorted alphabetically.
* "relevance" values are inserted higher into the list of possible completions
* than those with lower values. Completion instances with equal relevance
* values are sorted alphabetically.
*/
private int relevance;
/**
* Constructor.
*
* @param provider
* The provider that created this completion.
* @param provider The provider that created this completion.
*/
protected AbstractCompletion(CompletionProvider provider) {
this.provider = provider;
@@ -57,10 +56,8 @@ public abstract class AbstractCompletion implements Completion {
/**
* Constructor.
*
* @param provider
* The provider that created this completion.
* @param icon
* The icon for this completion.
* @param provider The provider that created this completion.
* @param icon The icon for this completion.
*/
protected AbstractCompletion(CompletionProvider provider, Icon icon) {
this(provider);
@@ -97,8 +94,8 @@ public abstract class AbstractCompletion implements Completion {
}
/**
* Returns the text the user has to (start) typing for this completion
* to be offered. The default implementation simply returns
* Returns the text the user has to (start) typing for this completion to be
* offered. The default implementation simply returns
* {@link #getReplacementText()}.
*
* @return The text the user has to (start) typing for this completion.
@@ -126,8 +123,8 @@ public abstract class AbstractCompletion implements Completion {
}
/**
* The default implementation returns <code>null</code>. Subclasses
* can override this method.
* The default implementation returns <code>null</code>. Subclasses can override
* this method.
*
* @return The tool tip text.
*/
@@ -139,8 +136,7 @@ public abstract class AbstractCompletion implements Completion {
/**
* Sets the icon to use for this completion.
*
* @param icon
* The icon to use.
* @param icon The icon to use.
* @see #getIcon()
*/
public void setIcon(Icon icon) {
@@ -150,8 +146,7 @@ public abstract class AbstractCompletion implements Completion {
/**
* Sets the relevance of this completion.
*
* @param relevance
* The new relevance of this completion.
* @param relevance The new relevance of this completion.
* @see #getRelevance()
*/
public void setRelevance(int relevance) {
@@ -43,8 +43,8 @@ import javax.swing.event.HyperlinkListener;
import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
/**
* The optional "description" window that describes the currently selected
* item in the auto-completion window.
* The optional "description" window that describes the currently selected item
* in the auto-completion window.
*
* @author Robert Futrell
* @version 1.0
@@ -89,9 +89,8 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
private int historyPos;
/**
* Provides a slight delay between asking to set a description and actually
* displaying it, so that if the user is scrolling quickly through
* completions, those with slow-to-calculate summaries won't bog down the
* scrolling.
* displaying it, so that if the user is scrolling quickly through completions,
* those with slow-to-calculate summaries won't bog down the scrolling.
*/
private Timer timer;
/**
@@ -103,10 +102,9 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
*/
private ResourceBundle bundle;
/**
* The amount of time to wait after the user changes the selected
* completion to refresh the description. This delay is in place to help
* performance for {@link Completion}s that may be slow to compute their
* summary text.
* The amount of time to wait after the user changes the selected completion to
* refresh the description. This delay is in place to help performance for
* {@link Completion}s that may be slow to compute their summary text.
*/
private static final int INITIAL_TIMER_DELAY = 120;
/**
@@ -117,10 +115,8 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Constructor.
*
* @param owner
* The parent window.
* @param ac
* The parent auto-completion.
* @param owner The parent window.
* @param ac The parent auto-completion.
*/
public AutoCompleteDescWindow(Window owner, AutoCompletion ac) {
super(owner);
@@ -183,8 +179,7 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Sets the currently displayed description and updates the history.
*
* @param historyItem
* The item to add to the history.
* @param historyItem The item to add to the history.
*/
private void addToHistory(HistoryEntry historyItem) {
history.add(++historyPos, historyItem);
@@ -214,8 +209,8 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
}
/**
* Copies from the description text area, if it is visible and there is
* a selection.
* Copies from the description text area, if it is visible and there is a
* selection.
*
* @return Whether a copy occurred.
*/
@@ -230,8 +225,7 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Returns the localized message for the specified key.
*
* @param key
* The key.
* @param key The key.
* @return The localized message.
*/
private String getString(String key) {
@@ -244,8 +238,7 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Called when a hyperlink is clicked.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
@@ -261,7 +254,8 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
URL newUrl = redirector.possiblyRedirect(url);
if (newUrl != null && newUrl != url) {
url = newUrl;
e = new HyperlinkEvent(e.getSource(), e.getEventType(), newUrl, e.getDescription(), e.getSourceElement());
e = new HyperlinkEvent(e.getSource(), e.getEventType(), newUrl, e.getDescription(),
e.getSourceElement());
}
}
}
@@ -325,11 +319,9 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
}
/**
* Sets the description displayed in this window. This clears the
* history.
* Sets the description displayed in this window. This clears the history.
*
* @param item
* The item whose description you want to display.
* @param item The item whose description you want to display.
*/
public void setDescriptionFor(Completion item) {
setDescriptionFor(item, false);
@@ -338,11 +330,9 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Sets the description displayed in this window.
*
* @param item
* The item whose description you want to display.
* @param addToHistory
* Whether to add this page to the page history
* (as opposed to clearing it and starting anew).
* @param item The item whose description you want to display.
* @param addToHistory Whether to add this page to the page history (as opposed
* to clearing it and starting anew).
*/
protected void setDescriptionFor(Completion item, boolean addToHistory) {
setDescriptionFor(item, null, addToHistory);
@@ -351,12 +341,10 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Sets the description displayed in this window.
*
* @param item
* The item whose description you want to display.
* @param item The item whose description you want to display.
* @parma anchor The anchor to jump to, or <code>null</code> if none.
* @param addToHistory
* Whether to add this page to the page history
* (as opposed to clearing it and starting anew).
* @param addToHistory Whether to add this page to the page history (as opposed
* to clearing it and starting anew).
*/
protected void setDescriptionFor(Completion item, String anchor, boolean addToHistory) {
timer.stop();
@@ -403,11 +391,9 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
/**
* Callback for custom <code>ExternalURLHandler</code>s.
*
* @param completion
* The completion to display.
* @param anchor
* The anchor in the HTML to jump to, or <code>null</code>
* if none.
* @param completion The completion to display.
* @param anchor The anchor in the HTML to jump to, or <code>null</code> if
* none.
*/
@Override
public void showSummaryFor(Completion completion, String anchor) {
@@ -442,8 +428,8 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener, DescW
}
/**
* Overridden to display a short name for the completion, since it's
* used in the tool tips for the "back" and "forward" buttons.
* Overridden to display a short name for the completion, since it's used in the
* tool tips for the "back" and "forward" buttons.
*
* @return A string representation of this history entry.
*/
@@ -43,10 +43,9 @@ import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
/**
* The actual popup window of choices. When visible, this window intercepts
* certain keystrokes in the parent text component and uses them to navigate
* the completion choices instead. If Enter or Escape is pressed, the window
* hides itself and notifies the {@link AutoCompletion} to insert the selected
* text.
* certain keystrokes in the parent text component and uses them to navigate the
* completion choices instead. If Enter or Escape is pressed, the window hides
* itself and notifies the {@link AutoCompletion} to insert the selected text.
*
* @author Robert Futrell
* @version 1.0
@@ -66,27 +65,26 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
*/
private CompletionListModel model;
/**
* A hack to work around the fact that we clear our completion model (and
* our selection) when hiding the completion window. This allows us to
* still know what the user selected after the popup is hidden.
* A hack to work around the fact that we clear our completion model (and our
* selection) when hiding the completion window. This allows us to still know
* what the user selected after the popup is hidden.
*/
private Completion lastSelection;
/**
* Optional popup window containing a description of the currently
* selected completion.
* Optional popup window containing a description of the currently selected
* completion.
*/
private AutoCompleteDescWindow descWindow;
/**
* The preferred size of the optional description window. This field
* only exists because the user may (and usually will) set the size of
* the description window before it exists (it must be parented to a
* Window).
* The preferred size of the optional description window. This field only exists
* because the user may (and usually will) set the size of the description
* window before it exists (it must be parented to a Window).
*/
private Dimension preferredDescWindowSize;
/**
* Whether the completion window and the optional description window
* should be displayed above the current caret position (as opposed to
* underneath it, which is preferred unless there is not enough space).
* Whether the completion window and the optional description window should be
* displayed above the current caret position (as opposed to underneath it,
* which is preferred unless there is not enough space).
*/
private boolean aboveCaret;
private int lastLine;
@@ -103,7 +101,8 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
private KeyActionPair pageUpKap;
private KeyActionPair pageDownKap;
private KeyActionPair ctrlCKap;
private KeyActionPair oldEscape, oldUp, oldDown, oldLeft, oldRight, oldEnter, oldTab, oldHome, oldEnd, oldPageUp, oldPageDown, oldCtrlC;
private KeyActionPair oldEscape, oldUp, oldDown, oldLeft, oldRight, oldEnter, oldTab, oldHome, oldEnd, oldPageUp,
oldPageDown, oldCtrlC;
/**
* The space between the caret and the completion popup.
*/
@@ -116,10 +115,8 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
/**
* Constructor.
*
* @param parent
* The parent window (hosting the text component).
* @param ac
* The auto-completion instance.
* @param parent The parent window (hosting the text component).
* @param ac The auto-completion instance.
*/
public AutoCompletePopupWindow(Window parent, final AutoCompletion ac) {
super(parent);
@@ -131,7 +128,8 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
list.addListSelectionListener(this);
list.addMouseListener(this);
JPanel contentPane = new JPanel(new BorderLayout());
JScrollPane sp = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JScrollPane sp = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// In 1.4, JScrollPane.setCorner() has a bug where it won't accept
// JScrollPane.LOWER_TRAILING_CORNER, even though that constant is
// defined. So we have to put the logic added in 1.5 to handle it
@@ -188,8 +186,8 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Creates the mappings from keys to Actions we'll be putting into the
* text component's ActionMap and InputMap.
* Creates the mappings from keys to Actions we'll be putting into the text
* component's ActionMap and InputMap.
*/
private void createKeyActionPairs() {
// Actions we'll install.
@@ -237,8 +235,8 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Returns the default list cell renderer used when a completion provider
* does not supply its own.
* Returns the default list cell renderer used when a completion provider does
* not supply its own.
*
* @return The default list cell renderer.
* @see #setListCellRenderer(ListCellRenderer)
@@ -268,8 +266,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Registers keyboard actions to listen for in the text component and
* intercept.
* Registers keyboard actions to listen for in the text component and intercept.
*
* @see #uninstallKeyBindings()
*/
@@ -322,21 +319,25 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
@Override
public void mouseEntered(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {}
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {
}
/**
* Positions the description window relative to the completion choices
* window. We assume there is room on one side of the other for this
* entire window to fit.
* Positions the description window relative to the completion choices window.
* We assume there is room on one side of the other for this entire window to
* fit.
*/
private void positionDescWindow() {
boolean showDescWindow = descWindow != null && ac.getShowDescWindow();
@@ -374,19 +375,14 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* "Puts back" the original key/Action pair for a keystroke. This is used
* when this popup is hidden.
* "Puts back" the original key/Action pair for a keystroke. This is used when
* this popup is hidden.
*
* @param im
* The input map.
* @param am
* The action map.
* @param key
* The keystroke whose key/Action pair to change.
* @param kap
* The (original) key/Action pair.
* @see #replaceAction(InputMap, ActionMap, int, KeyActionPair,
* KeyActionPair)
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose key/Action pair to change.
* @param kap The (original) key/Action pair.
* @see #replaceAction(InputMap, ActionMap, int, KeyActionPair, KeyActionPair)
*/
private void putBackAction(InputMap im, ActionMap am, int key, KeyActionPair kap) {
KeyStroke ks = KeyStroke.getKeyStroke(key, 0);
@@ -395,19 +391,13 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Replaces a key/Action pair in an InputMap and ActionMap with a new
* pair.
* Replaces a key/Action pair in an InputMap and ActionMap with a new pair.
*
* @param im
* The input map.
* @param am
* The action map.
* @param key
* The keystroke whose information to replace.
* @param kap
* The new key/Action pair for <code>key</code>.
* @param old
* A buffer in which to place the old key/Action pair.
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose information to replace.
* @param kap The new key/Action pair for <code>key</code>.
* @param old A buffer in which to place the old key/Action pair.
* @see #putBackAction(InputMap, ActionMap, int, KeyActionPair)
*/
private void replaceAction(InputMap im, ActionMap am, int key, KeyActionPair kap, KeyActionPair old) {
@@ -458,8 +448,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Selects the completion item one "page down" from the currently selected
* one.
* Selects the completion item one "page down" from the currently selected one.
*
* @see #selectPageUpItem()
*/
@@ -471,8 +460,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Selects the completion item one "page up" from the currently selected
* one.
* Selects the completion item one "page up" from the currently selected one.
*
* @see #selectPageDownItem()
*/
@@ -509,11 +497,10 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Sets the completions to display in the choices list. The first
* completion is selected.
* Sets the completions to display in the choices list. The first completion is
* selected.
*
* @param completions
* The completions to display.
* @param completions The completions to display.
*/
public void setCompletions(List<Completion> completions) {
model.setContents(completions);
@@ -523,8 +510,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
/**
* Sets the size of the description window.
*
* @param size
* The new size. This cannot be <code>null</code>.
* @param size The new size. This cannot be <code>null</code>.
*/
public void setDescriptionWindowSize(Dimension size) {
if (descWindow != null) {
@@ -535,12 +521,11 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Sets the default list cell renderer to use when a completion provider
* does not supply its own.
* Sets the default list cell renderer to use when a completion provider does
* not supply its own.
*
* @param renderer
* The renderer to use. If this is <code>null</code>,
* a default renderer is used.
* @param renderer The renderer to use. If this is <code>null</code>, a default
* renderer is used.
* @see #getListCellRenderer()
*/
public void setListCellRenderer(ListCellRenderer renderer) {
@@ -550,11 +535,10 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
/**
* Sets the location of this window to be "good" relative to the specified
* rectangle. That rectangle should be the location of the text
* component's caret, in screen coordinates.
* rectangle. That rectangle should be the location of the text component's
* caret, in screen coordinates.
*
* @param r
* The text component's caret position, in screen coordinates.
* @param r The text component's caret position, in screen coordinates.
*/
public void setLocationRelativeTo(Rectangle r) {
// Multi-monitor support - make sure the completion window (and
@@ -600,8 +584,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
/**
* Toggles the visibility of this popup window.
*
* @param visible
* Whether this window should be visible.
* @param visible Whether this window should be visible.
*/
@Override
public void setVisible(boolean visible) {
@@ -685,8 +668,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
}
/**
* Updates the <tt>LookAndFeel</tt> of this window and the description
* window.
* Updates the <tt>LookAndFeel</tt> of this window and the description window.
*/
public void updateUI() {
SwingUtilities.updateComponentTreeUI(this);
@@ -698,8 +680,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
/**
* Called when a new item is selected in the popup list.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void valueChanged(ListSelectionEvent e) {
@@ -784,7 +765,8 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, ListSele
public Object key;
public Action action;
public KeyActionPair() {}
public KeyActionPair() {
}
public KeyActionPair(Object key, Action a) {
this.key = key;
+158 -198
View File
@@ -49,8 +49,8 @@ import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
/**
* Adds auto-completion to a text component. Provides a popup window with a
* list of auto-complete choices on a given keystroke, such as Crtrl+Space.
* Adds auto-completion to a text component. Provides a popup window with a list
* of auto-complete choices on a given keystroke, such as Crtrl+Space.
* <p>
*
* Depending on the {@link CompletionProvider} installed, the following
@@ -58,14 +58,14 @@ import javax.swing.text.JTextComponent;
*
* <ul>
* <li>An auto-complete choices list made visible via e.g. Ctrl+Space</li>
* <li>A "description" window displayed alongside the choices list that
* provides documentation on the currently selected completion choice
* (as seen in Eclipse and NetBeans).</li>
* <li>A "description" window displayed alongside the choices list that provides
* documentation on the currently selected completion choice (as seen in Eclipse
* and NetBeans).</li>
* <li>Parameter assistance. If this is enabled, if the user enters a
* "parameterized" completion, such as a method or a function, then they
* will receive a tool tip describing the arguments they have to enter to
* the completion. Also, the arguments can be navigated via tab and
* shift+tab (a la Eclipse and NetBeans).</li>
* "parameterized" completion, such as a method or a function, then they will
* receive a tool tip describing the arguments they have to enter to the
* completion. Also, the arguments can be navigated via tab and shift+tab (a la
* Eclipse and NetBeans).</li>
* </ul>
*
* @author Robert Futrell
@@ -93,14 +93,14 @@ public class AutoCompletion {
private AutoCompletePopupWindow popupWindow;
/**
* The preferred size of the completion choices window. This field exists
* because the user will likely set the preferred size of the window before
* it is actually created.
* because the user will likely set the preferred size of the window before it
* is actually created.
*/
private Dimension preferredChoicesWindowSize;
/**
* The preferred size of the optional description window. This field only
* exists because the user may (and usually will) set the size of the
* description window before it exists (it must be parented to a Window).
* The preferred size of the optional description window. This field only exists
* because the user may (and usually will) set the size of the description
* window before it exists (it must be parented to a Window).
*/
private Dimension preferredDescWindowSize;
/**
@@ -112,13 +112,12 @@ public class AutoCompletion {
*/
private CompletionProvider provider;
/**
* The renderer to use for the completion choices. If this is
* <code>null</code>, then a default renderer is used.
* The renderer to use for the completion choices. If this is <code>null</code>,
* then a default renderer is used.
*/
private ListCellRenderer renderer;
/**
* The handler to use when an external URL is clicked in the help
* documentation.
* The handler to use when an external URL is clicked in the help documentation.
*/
private ExternalURLHandler externalURLHandler;
/**
@@ -127,8 +126,8 @@ public class AutoCompletion {
*/
private static LinkRedirector linkRedirector;
/**
* Whether the description window should be displayed along with the
* completion choice window.
* Whether the description window should be displayed along with the completion
* choice window.
*/
private boolean showDescWindow;
/**
@@ -136,14 +135,14 @@ public class AutoCompletion {
*/
private boolean autoCompleteEnabled;
/**
* Whether the auto-activation of auto-complete (after a delay, after the
* user types an appropriate character) is enabled.
* Whether the auto-activation of auto-complete (after a delay, after the user
* types an appropriate character) is enabled.
*/
private boolean autoActivationEnabled;
/**
* Whether or not, when there is only a single auto-complete option that
* matches the text at the current text position, that text should be
* auto-inserted, instead of the completion window displaying.
* Whether or not, when there is only a single auto-complete option that matches
* the text at the current text position, that text should be auto-inserted,
* instead of the completion window displaying.
*/
private boolean autoCompleteSingleChoices;
/**
@@ -166,8 +165,8 @@ public class AutoCompletion {
*/
private Object oldTriggerKey;
/**
* The action previously assigned to {@link #trigger}, so we can reset it if
* the user disables auto-completion.
* The action previously assigned to {@link #trigger}, so we can reset it if the
* user disables auto-completion.
*/
private Action oldTriggerAction;
/**
@@ -186,8 +185,8 @@ public class AutoCompletion {
*/
private ParentWindowListener parentWindowListener;
/**
* Listens for events from the text component that affect the visibility of
* the popup windows.
* Listens for events from the text component that affect the visibility of the
* popup windows.
*/
private TextComponentListener textComponentListener;
/**
@@ -210,14 +209,14 @@ public class AutoCompletion {
private EventListenerList listeners;
/**
* Whether or not the popup should be hidden when user types a space (or any
* character that resets the completion list to "all completions"). Defaults
* to true.
* character that resets the completion list to "all completions"). Defaults to
* true.
*/
private boolean hideOnNoText;
/**
* Whether or not the popup should be hidden when the CompletionProvider
* changes. If set to false, caller has to ensure refresh of the popup
* content. Defaults to true.
* changes. If set to false, caller has to ensure refresh of the popup content.
* Defaults to true.
*/
private boolean hideOnCompletionProviderChange;
/**
@@ -229,21 +228,18 @@ public class AutoCompletion {
*/
private static final String PARAM_COMPLETE_KEY = "AutoCompletion.FunctionStart";
/**
* Stores how to render auto-completion-specific highlights in text
* components.
* Stores how to render auto-completion-specific highlights in text components.
*/
private static final AutoCompletionStyleContext styleContext = new AutoCompletionStyleContext();
/**
* Whether debug messages should be printed to stdout as AutoCompletion
* runs.
* Whether debug messages should be printed to stdout as AutoCompletion runs.
*/
private static final boolean DEBUG = initDebug();
/**
* Constructor.
*
* @param provider
* The completion provider. This cannot be <code>null</code>
* @param provider The completion provider. This cannot be <code>null</code>
*/
public AutoCompletion(CompletionProvider provider) {
setChoicesWindowSize(350, 200);
@@ -267,8 +263,7 @@ public class AutoCompletion {
/**
* Adds a listener interested in popup window events from this instance.
*
* @param l
* The listener to add.
* @param l The listener to add.
* @see #removeAutoCompletionListener(AutoCompletionListener)
*/
public void addAutoCompletionListener(AutoCompletionListener l) {
@@ -286,8 +281,7 @@ public class AutoCompletion {
/**
* Fires an {@link AutoCompletionEvent} of the specified type.
*
* @param type
* The type of event to fire.
* @param type The type of event to fire.
*/
protected void fireAutoCompletionEvent(AutoCompletionEvent.Type type) {
// Guaranteed to return a non-null array
@@ -306,8 +300,8 @@ public class AutoCompletion {
}
/**
* Returns the delay between when the user types a character and when the
* code completion popup should automatically appear (if applicable).
* Returns the delay between when the user types a character and when the code
* completion popup should automatically appear (if applicable).
*
* @return The delay, in milliseconds.
* @see #setAutoActivationDelay(int)
@@ -317,8 +311,8 @@ public class AutoCompletion {
}
/**
* Returns whether, if a single auto-complete choice is available, it should
* be automatically inserted, without displaying the popup menu.
* Returns whether, if a single auto-complete choice is available, it should be
* automatically inserted, without displaying the popup menu.
*
* @return Whether to auto-complete single choices.
* @see #setAutoCompleteSingleChoices(boolean)
@@ -346,8 +340,8 @@ public class AutoCompletion {
}
/**
* Returns the default auto-complete "trigger key" for this OS. For Windows,
* for example, it is Ctrl+Space.
* Returns the default auto-complete "trigger key" for this OS. For Windows, for
* example, it is Ctrl+Space.
*
* @return The default auto-complete trigger key.
*/
@@ -358,8 +352,8 @@ public class AutoCompletion {
}
/**
* Returns the handler to use when an external URL is clicked in the
* description window.
* Returns the handler to use when an external URL is clicked in the description
* window.
*
* @return The handler.
* @see #setExternalURLHandler(ExternalURLHandler)
@@ -386,8 +380,8 @@ public class AutoCompletion {
}
/**
* Returns the default list cell renderer used when a completion provider
* does not supply its own.
* Returns the default list cell renderer used when a completion provider does
* not supply its own.
*
* @return The default list cell renderer.
* @see #setListCellRenderer(ListCellRenderer)
@@ -397,10 +391,10 @@ public class AutoCompletion {
}
/**
* Returns the renderer to use for {@link Completion}s in the optional
* parameter choices popup window (displayed when a
* {@link ParameterizedCompletion} is code-completed). If this returns
* <code>null</code>, a default renderer is used.
* Returns the renderer to use for {@link Completion}s in the optional parameter
* choices popup window (displayed when a {@link ParameterizedCompletion} is
* code-completed). If this returns <code>null</code>, a default renderer is
* used.
*
* @return The renderer to use.
* @see #setParamChoicesRenderer(ListCellRenderer)
@@ -417,14 +411,10 @@ public class AutoCompletion {
* <tt>c.getReplacementText()</tt>. You usually will not need to modify this
* method.
*
* @param c
* The completion being inserted.
* @param doc
* The document being modified.
* @param start
* The start of the text being replaced.
* @param len
* The length of the text being replaced.
* @param c The completion being inserted.
* @param doc The document being modified.
* @param start The start of the text being replaced.
* @param len The length of the text being replaced.
* @return The text to replace with.
*/
protected String getReplacementText(Completion c, Document doc, int start, int len) {
@@ -443,8 +433,8 @@ public class AutoCompletion {
}
/**
* Returns the style context describing how auto-completion related
* highlights in the editor are rendered.
* Returns the style context describing how auto-completion related highlights
* in the editor are rendered.
*
* @return The style context.
*/
@@ -466,8 +456,8 @@ public class AutoCompletion {
/**
* Returns the orientation of the text component we're installed to.
*
* @return The orientation of the text component, or <code>null</code> if we
* are not installed on one.
* @return The orientation of the text component, or <code>null</code> if we are
* not installed on one.
*/
ComponentOrientation getTextComponentOrientation() {
return textComponent == null ? null : textComponent.getComponentOrientation();
@@ -525,8 +515,8 @@ public class AutoCompletion {
}
/**
* Determines whether debug should be enabled for the AutoCompletion
* library. This method checks a system property, but takes care of
* Determines whether debug should be enabled for the AutoCompletion library.
* This method checks a system property, but takes care of
* {@link SecurityException}s in case we're in an applet or WebStart.
*
* @return Whether debug should be enabled.
@@ -545,8 +535,7 @@ public class AutoCompletion {
* Inserts a completion. Any time a code completion event occurs, the actual
* text insertion happens through this method.
*
* @param c
* A completion to insert. This cannot be <code>null</code>.
* @param c A completion to insert. This cannot be <code>null</code>.
*/
protected final void insertCompletion(Completion c) {
insertCompletion(c, false);
@@ -556,11 +545,11 @@ public class AutoCompletion {
* Inserts a completion. Any time a code completion event occurs, the actual
* text insertion happens through this method.
*
* @param c
* A completion to insert. This cannot be <code>null</code>.
* @param typedParamListStartChar
* Whether the parameterized completion start
* character was typed (typically <code>'('</code>).
* @param c A completion to insert. This cannot be
* <code>null</code>.
* @param typedParamListStartChar Whether the parameterized completion start
* character was typed (typically
* <code>'('</code>).
*/
protected void insertCompletion(Completion c, boolean typedParamListStartChar) {
JTextComponent textComp = getTextComponent();
@@ -582,11 +571,10 @@ public class AutoCompletion {
/**
* Installs this auto-completion on a text component. If this
* {@link AutoCompletion} is already installed on another text component,
* it is uninstalled first.
* {@link AutoCompletion} is already installed on another text component, it is
* uninstalled first.
*
* @param c
* The text component.
* @param c The text component.
* @see #uninstall()
*/
public void install(JTextComponent c) {
@@ -624,8 +612,7 @@ public class AutoCompletion {
/**
* Installs a "trigger key" action onto the current text component.
*
* @param ks
* The keystroke that should trigger the action.
* @param ks The keystroke that should trigger the action.
* @see #uninstallTriggerKey()
*/
private void installTriggerKey(KeyStroke ks) {
@@ -639,9 +626,9 @@ public class AutoCompletion {
/**
* Creates and returns the action to call when the user presses the
* auto-completion trigger key (e.g. ctrl+space). This is a hook for
* subclasses that want to provide their own behavior in this scenario.
* The default implementation returns an {@link AutoCompleteAction}.
* auto-completion trigger key (e.g. ctrl+space). This is a hook for subclasses
* that want to provide their own behavior in this scenario. The default
* implementation returns an {@link AutoCompleteAction}.
*
* @return The action to use.
* @see AutoCompleteAction
@@ -651,10 +638,10 @@ public class AutoCompletion {
}
/**
* Returns whether auto-activation is enabled (that is, whether the
* completion popup will automatically appear after a delay when the user
* types an appropriate character). Note that this parameter will be ignored
* if auto-completion is disabled.
* Returns whether auto-activation is enabled (that is, whether the completion
* popup will automatically appear after a delay when the user types an
* appropriate character). Note that this parameter will be ignored if
* auto-completion is disabled.
*
* @return Whether auto-activation is enabled.
* @see #setAutoActivationEnabled(boolean)
@@ -677,8 +664,7 @@ public class AutoCompletion {
/**
* Whether or not the popup should be hidden when the CompletionProvider
* changes. If set to false, caller has to ensure refresh of the popup
* content.
* changes. If set to false, caller has to ensure refresh of the popup content.
*
* @return Whether the popup should be hidden when the completion provider
* changes.
@@ -689,11 +675,11 @@ public class AutoCompletion {
}
/**
* Whether or not the popup should be hidden when user types a space (or
* any character that resets the completion list to "all completions").
* Whether or not the popup should be hidden when user types a space (or any
* character that resets the completion list to "all completions").
*
* @return Whether the popup should be hidden when the completion list is
* reset to show all completions.
* @return Whether the popup should be hidden when the completion list is reset
* to show all completions.
* @see #setHideOnNoText(boolean)
*/
protected boolean isHideOnNoText() {
@@ -720,12 +706,12 @@ public class AutoCompletion {
}
/**
* Refreshes the popup window. First, this method gets the possible
* completions for the current caret position. If there are none, and the
* popup is visible, it is hidden. If there are some completions and the
* popup is hidden, it is made visible and made to display the completions.
* If there are some completions and the popup is visible, its list is
* updated to the current set of completions.
* Refreshes the popup window. First, this method gets the possible completions
* for the current caret position. If there are none, and the popup is visible,
* it is hidden. If there are some completions and the popup is hidden, it is
* made visible and made to display the completions. If there are some
* completions and the popup is visible, its list is updated to the current set
* of completions.
*
* @return The current line number of the caret.
*/
@@ -749,7 +735,8 @@ public class AutoCompletion {
final List<Completion> completions = provider.getCompletions(textComponent);
int count = completions == null ? 0 : completions.size();
if (count > 1 || (count == 1 && (isPopupVisible() || text.equals(completions.get(0).getInputText())))
|| (count == 1 && (isPopupVisible() || textLen == 0)) || (count == 1 && !getAutoCompleteSingleChoices())) {
|| (count == 1 && (isPopupVisible() || textLen == 0))
|| (count == 1 && !getAutoCompleteSingleChoices())) {
if (popupWindow == null) {
popupWindow = new AutoCompletePopupWindow(parentWindow, this);
popupWindowListener.install(popupWindow);
@@ -800,8 +787,7 @@ public class AutoCompletion {
/**
* Removes a listener interested in popup window events from this instance.
*
* @param l
* The listener to remove.
* @param l The listener to remove.
* @see #addAutoCompletionListener(AutoCompletionListener)
*/
public void removeAutoCompletionListener(AutoCompletionListener l) {
@@ -812,8 +798,7 @@ public class AutoCompletion {
* Sets the delay between when the user types a character and when the code
* completion popup should automatically appear (if applicable).
*
* @param ms
* The delay, in milliseconds. This should be greater than zero.
* @param ms The delay, in milliseconds. This should be greater than zero.
* @see #getAutoActivationDelay()
*/
public void setAutoActivationDelay(int ms) {
@@ -823,11 +808,10 @@ public class AutoCompletion {
}
/**
* Toggles whether auto-activation is enabled. Note that auto-activation
* also depends on auto-completion itself being enabled.
* Toggles whether auto-activation is enabled. Note that auto-activation also
* depends on auto-completion itself being enabled.
*
* @param enabled
* Whether auto-activation is enabled.
* @param enabled Whether auto-activation is enabled.
* @see #isAutoActivationEnabled()
* @see #setAutoActivationDelay(int)
*/
@@ -847,8 +831,7 @@ public class AutoCompletion {
/**
* Sets whether auto-completion is enabled.
*
* @param enabled
* Whether auto-completion is enabled.
* @param enabled Whether auto-completion is enabled.
* @see #isAutoCompleteEnabled()
*/
public void setAutoCompleteEnabled(boolean enabled) {
@@ -862,8 +845,7 @@ public class AutoCompletion {
* Sets whether, if a single auto-complete choice is available, it should be
* automatically inserted, without displaying the popup menu.
*
* @param autoComplete
* Whether to auto-complete single choices.
* @param autoComplete Whether to auto-complete single choices.
* @see #getAutoCompleteSingleChoices()
*/
public void setAutoCompleteSingleChoices(boolean autoComplete) {
@@ -873,11 +855,9 @@ public class AutoCompletion {
/**
* Sets the completion provider being used.
*
* @param provider
* The new completion provider. This cannot be
* @param provider The new completion provider. This cannot be
* <code>null</code>.
* @throws IllegalArgumentException
* If <code>provider</code> is
* @throws IllegalArgumentException If <code>provider</code> is
* <code>null</code>.
*/
public void setCompletionProvider(CompletionProvider provider) {
@@ -893,10 +873,8 @@ public class AutoCompletion {
/**
* Sets the size of the completion choices window.
*
* @param w
* The new width.
* @param h
* The new height.
* @param w The new width.
* @param h The new height.
* @see #setDescriptionWindowSize(int, int)
*/
public void setChoicesWindowSize(int w, int h) {
@@ -909,10 +887,8 @@ public class AutoCompletion {
/**
* Sets the size of the description window.
*
* @param w
* The new width.
* @param h
* The new height.
* @param w The new width.
* @param h The new height.
* @see #setChoicesWindowSize(int, int)
*/
public void setDescriptionWindowSize(int w, int h) {
@@ -923,15 +899,14 @@ public class AutoCompletion {
}
/**
* Sets the handler to use when an external URL is clicked in the
* description window. This handler can perform some action, such as open
* the URL in a web browser. The default implementation will open the URL in
* a browser, but only if running in Java 6. If you want browser support for
* Java 5 and below, or otherwise want to respond to hyperlink clicks, you
* will have to install your own handler to do so.
* Sets the handler to use when an external URL is clicked in the description
* window. This handler can perform some action, such as open the URL in a web
* browser. The default implementation will open the URL in a browser, but only
* if running in Java 6. If you want browser support for Java 5 and below, or
* otherwise want to respond to hyperlink clicks, you will have to install your
* own handler to do so.
*
* @param handler
* The new handler.
* @param handler The new handler.
* @see #getExternalURLHandler()
*/
public void setExternalURLHandler(ExternalURLHandler handler) {
@@ -939,13 +914,11 @@ public class AutoCompletion {
}
/**
* Sets whether or not the popup should be hidden when the
* CompletionProvider changes. If set to false, caller has to ensure refresh
* of the popup content.
* Sets whether or not the popup should be hidden when the CompletionProvider
* changes. If set to false, caller has to ensure refresh of the popup content.
*
* @param hideOnCompletionProviderChange
* Whether the popup should be hidden
* when the completion provider changes.
* @param hideOnCompletionProviderChange Whether the popup should be hidden when
* the completion provider changes.
* @see #isHideOnCompletionProviderChange()
*/
protected void setHideOnCompletionProviderChange(boolean hideOnCompletionProviderChange) {
@@ -953,12 +926,11 @@ public class AutoCompletion {
}
/**
* Sets whether or not the popup should be hidden when user types a space
* (or any character that resets the completion list to "all completions").
* Sets whether or not the popup should be hidden when user types a space (or
* any character that resets the completion list to "all completions").
*
* @param hideOnNoText
* Whether the popup sh ould be hidden when the
* completion list is reset to show all completions.
* @param hideOnNoText Whether the popup sh ould be hidden when the completion
* list is reset to show all completions.
* @see #isHideOnNoText()
*/
protected void setHideOnNoText(boolean hideOnNoText) {
@@ -967,12 +939,10 @@ public class AutoCompletion {
/**
* Sets the redirector for external URL's found in code completion
* documentation. When a non-local link in completion popups is clicked,
* this redirector is given the chance to modify the URL fetched and
* displayed.
* documentation. When a non-local link in completion popups is clicked, this
* redirector is given the chance to modify the URL fetched and displayed.
*
* @param linkRedirector
* The link redirector, or <code>null</code> for none.
* @param linkRedirector The link redirector, or <code>null</code> for none.
* @see #getLinkRedirector()
*/
public static void setLinkRedirector(LinkRedirector linkRedirector) {
@@ -980,12 +950,11 @@ public class AutoCompletion {
}
/**
* Sets the default list cell renderer to use when a completion provider
* does not supply its own.
* Sets the default list cell renderer to use when a completion provider does
* not supply its own.
*
* @param renderer
* The renderer to use. If this is <code>null</code>, a
* default renderer is used.
* @param renderer The renderer to use. If this is <code>null</code>, a default
* renderer is used.
* @see #getListCellRenderer()
*/
public void setListCellRenderer(ListCellRenderer renderer) {
@@ -997,13 +966,11 @@ public class AutoCompletion {
}
/**
* Sets the renderer to use for {@link Completion}s in the optional
* parameter choices popup window (displayed when a
* {@link ParameterizedCompletion} is code-completed). If this isn't set, a
* default renderer is used.
* Sets the renderer to use for {@link Completion}s in the optional parameter
* choices popup window (displayed when a {@link ParameterizedCompletion} is
* code-completed). If this isn't set, a default renderer is used.
*
* @param r
* The renderer to use.
* @param r The renderer to use.
* @see #getParamChoicesRenderer()
* @see #setParameterAssistanceEnabled(boolean)
*/
@@ -1013,13 +980,12 @@ public class AutoCompletion {
/**
* Sets whether parameter assistance is enabled. If parameter assistance is
* enabled, and a "parameterized" completion (such as a function or method)
* is inserted, the user will get "assistance" in inserting the parameters
* in the form of a popup window with documentation and easy tabbing through
* the arguments (as seen in Eclipse and NetBeans).
* enabled, and a "parameterized" completion (such as a function or method) is
* inserted, the user will get "assistance" in inserting the parameters in the
* form of a popup window with documentation and easy tabbing through the
* arguments (as seen in Eclipse and NetBeans).
*
* @param enabled
* Whether parameter assistance should be enabled.
* @param enabled Whether parameter assistance should be enabled.
* @see #isParameterAssistanceEnabled()
*/
public void setParameterAssistanceEnabled(boolean enabled) {
@@ -1027,11 +993,10 @@ public class AutoCompletion {
}
/**
* Toggles the visibility of the auto-completion popup window. This fires
* an {@link AutoCompletionEvent} of the appropriate type.
* Toggles the visibility of the auto-completion popup window. This fires an
* {@link AutoCompletionEvent} of the appropriate type.
*
* @param visible
* Whether the window should be made visible or hidden.
* @param visible Whether the window should be made visible or hidden.
* @see #isPopupVisible()
*/
protected void setPopupVisible(boolean visible) {
@@ -1041,11 +1006,10 @@ public class AutoCompletion {
}
/**
* Sets whether the "description window" should be shown beside the
* completion window.
* Sets whether the "description window" should be shown beside the completion
* window.
*
* @param show
* Whether to show the description window.
* @param show Whether to show the description window.
* @see #getShowDescWindow()
*/
public void setShowDescWindow(boolean show) {
@@ -1057,10 +1021,8 @@ public class AutoCompletion {
* Sets the keystroke that should be used to trigger the auto-complete popup
* window.
*
* @param ks
* The keystroke.
* @throws IllegalArgumentException
* If <code>ks</code> is <code>null</code>.
* @param ks The keystroke.
* @throws IllegalArgumentException If <code>ks</code> is <code>null</code>.
* @see #getTriggerKey()
*/
public void setTriggerKey(KeyStroke ks) {
@@ -1081,10 +1043,8 @@ public class AutoCompletion {
/**
* Displays a "tool tip" detailing the inputs to the function just entered.
*
* @param pc
* The completion.
* @param typedParamListStartChar
* Whether the parameterized completion list
* @param pc The completion.
* @param typedParamListStartChar Whether the parameterized completion list
* starting character was typed.
*/
private void startParameterizedCompletionAssistance(ParameterizedCompletion pc, boolean typedParamListStartChar) {
@@ -1159,8 +1119,7 @@ public class AutoCompletion {
/**
* Updates the LookAndFeel of the popup window. Applications can call this
* method as appropriate if they support changing the LookAndFeel at
* runtime.
* method as appropriate if they support changing the LookAndFeel at runtime.
*/
private void updateUI() {
if (popupWindow != null) {
@@ -1176,10 +1135,11 @@ public class AutoCompletion {
}
/**
* Listens for events in the text component to auto-activate the code
* completion popup.
* Listens for events in the text component to auto-activate the code completion
* popup.
*/
private class AutoActivationListener extends FocusAdapter implements DocumentListener, CaretListener, ActionListener {
private class AutoActivationListener extends FocusAdapter
implements DocumentListener, CaretListener, ActionListener {
private Timer timer;
private boolean justInserted;
@@ -1250,8 +1210,8 @@ public class AutoCompletion {
}
/**
* The <code>Action</code> that displays the popup window if auto-completion
* is enabled.
* The <code>Action</code> that displays the popup window if auto-completion is
* enabled.
*/
protected class AutoCompleteAction extends AbstractAction {
@@ -1340,7 +1300,8 @@ public class AutoCompletion {
}
@Override
public void windowGainedFocus(WindowEvent e) {}
public void windowGainedFocus(WindowEvent e) {
}
@Override
public void windowLostFocus(WindowEvent e) {
@@ -1393,12 +1354,11 @@ public class AutoCompletion {
}
/**
* Called when the component hierarchy for our text component changes.
* When the text component is added to a new {@link Window}, this method
* registers listeners on that <code>Window</code>.
* Called when the component hierarchy for our text component changes. When the
* text component is added to a new {@link Window}, this method registers
* listeners on that <code>Window</code>.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void hierarchyChanged(HierarchyEvent e) {
@@ -8,9 +8,9 @@ package org.fife.ui.autocomplete;
import java.util.EventObject;
/**
* An event fired by an instance of {@link AutoCompletion}. This can be
* used by applications that wish to be notified of the auto-complete popup
* window showing and hiding.
* An event fired by an instance of {@link AutoCompletion}. This can be used by
* applications that wish to be notified of the auto-complete popup window
* showing and hiding.
*
* @author Robert Futrell
* @version 1.0
@@ -25,11 +25,8 @@ public class AutoCompletionEvent extends EventObject {
/**
* Constructor.
*
* @param source
* The <code>AutoCompletion</code> instance that fired
* this event.
* @param type
* The event type.
* @param source The <code>AutoCompletion</code> instance that fired this event.
* @param type The event type.
*/
public AutoCompletionEvent(AutoCompletion source, Type type) {
super(source);
@@ -17,11 +17,10 @@ import java.util.EventListener;
public interface AutoCompletionListener extends EventListener {
/**
* Callback notified when a change to the <code>AutoCompletion</code>'s
* status occurs.
* Callback notified when a change to the <code>AutoCompletion</code>'s status
* occurs.
*
* @param e
* The event.
* @param e The event.
*/
void autoCompleteUpdate(AutoCompletionEvent e);
}
@@ -22,13 +22,13 @@ public class AutoCompletionStyleContext {
*/
private Color parameterizedCompletionCursorPositionColor;
/**
* The color used to highlight copies of editable parameters in
* parameterized completions.
* The color used to highlight copies of editable parameters in parameterized
* completions.
*/
private Color parameterCopyColor;
/**
* The color of the outline highlight used to denote editable parameters
* in parameterized completions.
* The color of the outline highlight used to denote editable parameters in
* parameterized completions.
*/
private Color parameterOutlineColor;
@@ -39,8 +39,8 @@ public class AutoCompletionStyleContext {
}
/**
* Returns the color of the highlight painted on copies of editable
* parameters in parameterized completions.
* Returns the color of the highlight painted on copies of editable parameters
* in parameterized completions.
*
* @return The color used.
* @see #setParameterCopyColor(Color)
@@ -50,8 +50,8 @@ public class AutoCompletionStyleContext {
}
/**
* Returns the color used to denote the ending caret position for
* parameterized completions.
* Returns the color used to denote the ending caret position for parameterized
* completions.
*
* @return The color used.
* @see #setParameterizedCompletionCursorPositionColor(Color)
@@ -61,8 +61,8 @@ public class AutoCompletionStyleContext {
}
/**
* Returns the color of the outline highlight used to denote editable
* parameters in parameterized completions.
* Returns the color of the outline highlight used to denote editable parameters
* in parameterized completions.
*
* @return The color used.
* @see #setParameterOutlineColor(Color)
@@ -72,11 +72,10 @@ public class AutoCompletionStyleContext {
}
/**
* Sets the color of the highlight painted on copies of editable
* parameters in parameterized completions.
* Sets the color of the highlight painted on copies of editable parameters in
* parameterized completions.
*
* @param color
* The color to use.
* @param color The color to use.
* @see #setParameterCopyColor(Color)
*/
public void setParameterCopyColor(Color color) {
@@ -84,11 +83,10 @@ public class AutoCompletionStyleContext {
}
/**
* Sets the color used to denote the ending caret position for
* parameterized completions.
* Sets the color used to denote the ending caret position for parameterized
* completions.
*
* @param color
* The color to use.
* @param color The color to use.
* @see #getParameterizedCompletionCursorPositionColor()
*/
public void setParameterizedCompletionCursorPositionColor(Color color) {
@@ -96,11 +94,10 @@ public class AutoCompletionStyleContext {
}
/**
* Sets the color of the outline highlight used to denote editable
* parameters in parameterized completions.
* Sets the color of the outline highlight used to denote editable parameters in
* parameterized completions.
*
* @param color
* The color to use.
* @param color The color to use.
* @see #getParameterOutlineColor()
*/
public void setParameterOutlineColor(Color color) {
@@ -7,9 +7,9 @@
package org.fife.ui.autocomplete;
/**
* A straightforward {@link Completion} implementation. This implementation
* can be used if you have a relatively short number of static completions
* with no (or short) summaries.
* A straightforward {@link Completion} implementation. This implementation can
* be used if you have a relatively short number of static completions with no
* (or short) summaries.
* <p>
*
* This implementation uses the replacement text as the input text. It also
@@ -28,10 +28,8 @@ public class BasicCompletion extends AbstractCompletion {
/**
* Constructor.
*
* @param provider
* The parent completion provider.
* @param replacementText
* The text to replace.
* @param provider The parent completion provider.
* @param replacementText The text to replace.
*/
public BasicCompletion(CompletionProvider provider, String replacementText) {
this(provider, replacementText, null);
@@ -40,12 +38,9 @@ public class BasicCompletion extends AbstractCompletion {
/**
* Constructor.
*
* @param provider
* The parent completion provider.
* @param replacementText
* The text to replace.
* @param shortDesc
* A short description of the completion. This will be
* @param provider The parent completion provider.
* @param replacementText The text to replace.
* @param shortDesc A short description of the completion. This will be
* displayed in the completion list. This may be
* <code>null</code>.
*/
@@ -56,16 +51,12 @@ public class BasicCompletion extends AbstractCompletion {
/**
* Constructor.
*
* @param provider
* The parent completion provider.
* @param replacementText
* The text to replace.
* @param shortDesc
* A short description of the completion. This will be
* @param provider The parent completion provider.
* @param replacementText The text to replace.
* @param shortDesc A short description of the completion. This will be
* displayed in the completion list. This may be
* <code>null</code>.
* @param summary
* The summary of this completion. This should be HTML.
* @param summary The summary of this completion. This should be HTML.
* This may be <code>null</code>.
*/
public BasicCompletion(CompletionProvider provider, String replacementText, String shortDesc, String summary) {
@@ -84,8 +75,8 @@ public class BasicCompletion extends AbstractCompletion {
}
/**
* Returns the short description of this completion, usually used in
* the completion choices list.
* Returns the short description of this completion, usually used in the
* completion choices list.
*
* @return The short description, or <code>null</code> if there is none.
* @see #setShortDescription(String)
@@ -105,8 +96,7 @@ public class BasicCompletion extends AbstractCompletion {
/**
* Sets the short description of this completion.
*
* @param shortDesc
* The short description of this completion.
* @param shortDesc The short description of this completion.
* @see #getShortDescription()
*/
public void setShortDescription(String shortDesc) {
@@ -116,8 +106,7 @@ public class BasicCompletion extends AbstractCompletion {
/**
* Sets the summary for this completion.
*
* @param summary
* The summary for this completion.
* @param summary The summary for this completion.
* @see #getSummary()
*/
public void setSummary(String summary) {
@@ -125,8 +114,8 @@ public class BasicCompletion extends AbstractCompletion {
}
/**
* Returns a string representation of this completion. If the short
* description is not <code>null</code>, this method will return:
* Returns a string representation of this completion. If the short description
* is not <code>null</code>, this method will return:
*
* <code>getInputText() + " - " + shortDesc</code>
*
+42 -50
View File
@@ -10,20 +10,20 @@ import javax.swing.Icon;
import javax.swing.text.JTextComponent;
/**
* Represents a completion choice. A {@link CompletionProvider} returns lists
* of objects implementing this interface. A <tt>Completion</tt> contains the
* Represents a completion choice. A {@link CompletionProvider} returns lists of
* objects implementing this interface. A <tt>Completion</tt> contains the
* following information:
*
* <ul>
* <li>The text the user must (begin to) input for this to be a completion
* choice.
* <li>The text that will be filled in if the user chooses this completion.
* Note that often, this is the same as the text the user must (begin to)
* enter, but this doesn't have to be the case.
* <li>Summary HTML that describes this completion. This is information that
* can be displayed in a helper "tooltip"-style window beside the
* completion list. This may be <code>null</code>. It may also be
* lazily generated to cut down on memory usage.
* <li>The text that will be filled in if the user chooses this completion. Note
* that often, this is the same as the text the user must (begin to) enter, but
* this doesn't have to be the case.
* <li>Summary HTML that describes this completion. This is information that can
* be displayed in a helper "tooltip"-style window beside the completion list.
* This may be <code>null</code>. It may also be lazily generated to cut down on
* memory usage.
* <li>The <tt>CompletionProvider</tt> that returned this completion.
* <li>Tool tip text that can be displayed when a mouse hovers over this
* completion in a text component.
@@ -36,26 +36,23 @@ import javax.swing.text.JTextComponent;
public interface Completion extends Comparable<Completion> {
/**
* Compares this completion to another one lexicographically, ignoring
* case.
* Compares this completion to another one lexicographically, ignoring case.
*
* @param other
* Another completion instance.
* @param other Another completion instance.
* @return How this completion compares to the other one.
*/
@Override
public int compareTo(Completion other);
/**
* Returns the portion of this completion that has already been entered
* into the text component. The match is case-insensitive.
* Returns the portion of this completion that has already been entered into the
* text component. The match is case-insensitive.
* <p>
*
* This is a convenience method for:
* <code>getProvider().getAlreadyEnteredText(comp)</code>.
*
* @param comp
* The text component.
* @param comp The text component.
* @return The already-entered portion of this completion.
*/
public String getAlreadyEntered(JTextComponent comp);
@@ -68,14 +65,14 @@ public interface Completion extends Comparable<Completion> {
public Icon getIcon();
/**
* Returns the text that the user has to (start) typing for this completion
* to be offered. Note that this will usually be the same value as
* {@link #getReplacementText()}, but not always (a completion could be
* a way to implement shorthand, for example, "<code>sysout</code>" mapping
* to "<code>System.out.println(</code>").
* Returns the text that the user has to (start) typing for this completion to
* be offered. Note that this will usually be the same value as
* {@link #getReplacementText()}, but not always (a completion could be a way to
* implement shorthand, for example, "<code>sysout</code>" mapping to
* "<code>System.out.println(</code>").
*
* @return The text the user has to (start) typing for this completion to
* be offered.
* @return The text the user has to (start) typing for this completion to be
* offered.
* @see #getReplacementText()
*/
public String getInputText();
@@ -89,25 +86,25 @@ public interface Completion extends Comparable<Completion> {
/**
* Returns the "relevance" of this completion. This is used when sorting
* completions by their relevance. It is an abstract concept that may
* mean different things to different languages, and may depend on the
* context of the completion.
* completions by their relevance. It is an abstract concept that may mean
* different things to different languages, and may depend on the context of the
* completion.
* <p>
*
* By default, all completions have a relevance of <code>0</code>. The
* higher the value returned by this method, the higher up in the list
* this completion will be; the lower the value returned, the lower it will
* be. <code>Completion</code>s with equal relevance values will be
* sorted alphabetically.
* By default, all completions have a relevance of <code>0</code>. The higher
* the value returned by this method, the higher up in the list this completion
* will be; the lower the value returned, the lower it will be.
* <code>Completion</code>s with equal relevance values will be sorted
* alphabetically.
*
* @return The relevance of this completion.
*/
public int getRelevance();
/**
* Returns the text to insert as the result of this auto-completion. This
* is the "complete" text, including any text that replaces what the user
* has already typed.
* Returns the text to insert as the result of this auto-completion. This is the
* "complete" text, including any text that replaces what the user has already
* typed.
*
* @return The replacement text.
* @see #getInputText()
@@ -115,31 +112,26 @@ public interface Completion extends Comparable<Completion> {
public String getReplacementText();
/**
* Returns the description of this auto-complete choice. This can be
* used in a popup "description window."
* Returns the description of this auto-complete choice. This can be used in a
* popup "description window."
*
* @return This item's description. This should be HTML. It may be
* <code>null</code> if there is no description for this
* completion.
* <code>null</code> if there is no description for this completion.
*/
public String getSummary();
/**
* Returns the tool tip text to display for mouse hovers over this
* completion.
* Returns the tool tip text to display for mouse hovers over this completion.
* <p>
*
* Note that for this functionality to be enabled, a
* <tt>JTextComponent</tt> must be registered with the
* <tt>ToolTipManager</tt>, and the text component must know to search
* for this value. In the case of an
* <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this
* can be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that
* calls into
* Note that for this functionality to be enabled, a <tt>JTextComponent</tt>
* must be registered with the <tt>ToolTipManager</tt>, and the text component
* must know to search for this value. In the case of an
* <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this can
* be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that calls into
* {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}.
*
* @return The tool tip text for this completion, or <code>null</code> if
* none.
* @return The tool tip text for this completion, or <code>null</code> if none.
*/
public String getToolTipText();
}
@@ -26,8 +26,8 @@ import javax.swing.text.View;
/**
* A cell renderer that adds some pizazz when rendering the standard
* {@link Completion} types, like Eclipse and NetBeans do. Specifically,
* this renderer handles:
* {@link Completion} types, like Eclipse and NetBeans do. Specifically, this
* renderer handles:
*
* <ul>
* <li>{@link FunctionCompletion}s</li>
@@ -43,18 +43,18 @@ import javax.swing.text.View;
public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* The alternating background color, or <code>null</code> if alternating
* row colors should not be used.
* The alternating background color, or <code>null</code> if alternating row
* colors should not be used.
*/
private static Color altBG;
/**
* The font to use when rendering items, or <code>null</code> if the
* list's default font should be used.
* The font to use when rendering items, or <code>null</code> if the list's
* default font should be used.
*/
private Font font;
/**
* Whether to display the types of fields and return types of functions
* in the completion text.
* Whether to display the types of fields and return types of functions in the
* completion text.
*/
private boolean showTypes;
/**
@@ -101,14 +101,13 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Constructor. This is primarily a hook for Substance, or any other
* Look and Feel whose renderers look drastically different than standard
* Constructor. This is primarily a hook for Substance, or any other Look and
* Feel whose renderers look drastically different than standard
* <code>DefaultListCellRenderer</code>s. Everything except for the text
* rendering will be done by the delegate. In almost all scenarios, you
* will want to use the no-argument constructor instead of this one.
* rendering will be done by the delegate. In almost all scenarios, you will
* want to use the no-argument constructor instead of this one.
*
* @param delegate
* The delegate renderer.
* @param delegate The delegate renderer.
* @see #delegateToSubstanceRenderer()
*/
public CompletionCellRenderer(DefaultListCellRenderer delegate) {
@@ -117,8 +116,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Creates the icon to use if no icon is found for a specific completion.
* The default implementation returns a 16x16 empty icon.
* Creates the icon to use if no icon is found for a specific completion. The
* default implementation returns a 16x16 empty icon.
*
* @return The icon.
* @see #getEmptyIcon()
@@ -128,8 +127,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Returns a decent "parameter" color based on the current default
* foreground color.
* Returns a decent "parameter" color based on the current default foreground
* color.
*
* @return The parameter color to use.
*/
@@ -138,8 +137,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Returns a decent "type" color based on the current default foreground
* color.
* Returns a decent "type" color based on the current default foreground color.
*
* @return The type color to use.
*/
@@ -148,12 +146,11 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Attempts to delegate rendering to a Substance cell renderer. This
* should only be called if Substance is known to be on the classpath.
* Attempts to delegate rendering to a Substance cell renderer. This should only
* be called if Substance is known to be on the classpath.
*
* @throws Exception
* If Substance is not on the classpath, or some other
* error occurs creating the Substance cell renderer.
* @throws Exception If Substance is not on the classpath, or some other error
* occurs creating the Substance cell renderer.
* @see Util#getUseSubstanceRenderers()
* @see #setDelegateRenderer(DefaultListCellRenderer)
*/
@@ -187,8 +184,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Returns the font used when rendering completions.
*
* @return The font. If this is <code>null</code>, then the default list
* font is used.
* @return The font. If this is <code>null</code>, then the default list font is
* used.
* @see #setDisplayFont(Font)
*/
public Font getDisplayFont() {
@@ -196,8 +193,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Returns the icon to use if no icon is found for a specific completion.
* This icon is lazily created if necessary.
* Returns the icon to use if no icon is found for a specific completion. This
* icon is lazily created if necessary.
*
* @return The icon.
* @see #createEmptyIcon()
@@ -212,9 +209,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Returns an icon.
*
* @param resource
* The icon to retrieve. This should either be a file,
* or a resource loadable by the current ClassLoader.
* @param resource The icon to retrieve. This should either be a file, or a
* resource loadable by the current ClassLoader.
* @return The icon.
*/
protected Icon getIcon(String resource) {
@@ -233,19 +229,15 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Returns the renderer.
*
* @param list
* The list of choices being rendered.
* @param value
* The {@link Completion} being rendered.
* @param index
* The index into <code>list</code> being rendered.
* @param selected
* Whether the item is selected.
* @param hasFocus
* Whether the item has focus.
* @param list The list of choices being rendered.
* @param value The {@link Completion} being rendered.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus) {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected,
boolean hasFocus) {
super.getListCellRendererComponent(list, value, index, selected, hasFocus);
if (font != null) {
setFont(font); // Overrides super's setFont(list.getFont()).
@@ -284,8 +276,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Returns whether the types of fields and return types of methods are
* shown in the completion text.
* Returns whether the types of fields and return types of methods are shown in
* the completion text.
*
* @return Whether to show the types.
* @see #setShowTypes(boolean)
@@ -346,18 +338,14 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Prepares this renderer to display a function completion.
*
* @param list
* The list of choices being rendered.
* @param fc
* The completion to render.
* @param index
* The index into <code>list</code> being rendered.
* @param selected
* Whether the item is selected.
* @param hasFocus
* Whether the item has focus.
* @param list The list of choices being rendered.
* @param fc The completion to render.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
protected void prepareForFunctionCompletion(JList list, FunctionCompletion fc, int index, boolean selected, boolean hasFocus) {
protected void prepareForFunctionCompletion(JList list, FunctionCompletion fc, int index, boolean selected,
boolean hasFocus) {
StringBuilder sb = new StringBuilder(PREFIX);
sb.append(fc.getName());
char paramListStart = fc.getProvider().getParameterListStart();
@@ -408,18 +396,14 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Prepares this renderer to display a markup tag completion.
*
* @param list
* The list of choices being rendered.
* @param mc
* The completion to render.
* @param index
* The index into <code>list</code> being rendered.
* @param selected
* Whether the item is selected.
* @param hasFocus
* Whether the item has focus.
* @param list The list of choices being rendered.
* @param mc The completion to render.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
protected void prepareForMarkupTagCompletion(JList list, MarkupTagCompletion mc, int index, boolean selected, boolean hasFocus) {
protected void prepareForMarkupTagCompletion(JList list, MarkupTagCompletion mc, int index, boolean selected,
boolean hasFocus) {
StringBuilder sb = new StringBuilder(PREFIX);
sb.append(mc.getName());
setText(sb.toString());
@@ -429,16 +413,11 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
* Prepares this renderer to display a completion not specifically handled
* elsewhere.
*
* @param list
* The list of choices being rendered.
* @param c
* The completion to render.
* @param index
* The index into <code>list</code> being rendered.
* @param selected
* Whether the item is selected.
* @param hasFocus
* Whether the item has focus.
* @param list The list of choices being rendered.
* @param c The completion to render.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
protected void prepareForOtherCompletion(JList list, Completion c, int index, boolean selected, boolean hasFocus) {
StringBuilder sb = new StringBuilder(PREFIX);
@@ -462,18 +441,14 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Prepares this renderer to display a template completion.
*
* @param list
* The list of choices being rendered.
* @param tc
* The completion to render.
* @param index
* The index into <code>list</code> being rendered.
* @param selected
* Whether the item is selected.
* @param hasFocus
* Whether the item has focus.
* @param list The list of choices being rendered.
* @param tc The completion to render.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
protected void prepareForTemplateCompletion(JList list, TemplateCompletion tc, int index, boolean selected, boolean hasFocus) {
protected void prepareForTemplateCompletion(JList list, TemplateCompletion tc, int index, boolean selected,
boolean hasFocus) {
StringBuilder sb = new StringBuilder(PREFIX);
sb.append(tc.getInputText());
String definition = tc.getShortDescription();
@@ -493,18 +468,14 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Prepares this renderer to display a variable completion.
*
* @param list
* The list of choices being rendered.
* @param vc
* The completion to render.
* @param index
* The index into <code>list</code> being rendered.
* @param selected
* Whether the item is selected.
* @param hasFocus
* Whether the item has focus.
* @param list The list of choices being rendered.
* @param vc The completion to render.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
protected void prepareForVariableCompletion(JList list, VariableCompletion vc, int index, boolean selected, boolean hasFocus) {
protected void prepareForVariableCompletion(JList list, VariableCompletion vc, int index, boolean selected,
boolean hasFocus) {
StringBuilder sb = new StringBuilder(PREFIX);
sb.append(vc.getName());
if (getShowTypes() && vc.getType() != null) {
@@ -523,8 +494,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Sets the background color to use on alternating lines.
*
* @param altBG
* The new alternate background color. If this is
* @param altBG The new alternate background color. If this is
* <code>null</code>, alternating lines will not use different
* background colors.
* @see #getAlternateBackground()
@@ -534,14 +504,12 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Sets the delegate renderer. Most users will never use this method; it
* is primarily a hook for Substance and other Look and Feels whose
* renderers look drastically different from the standard
* <code>DefaultListCellRenderer</code>.
* Sets the delegate renderer. Most users will never use this method; it is
* primarily a hook for Substance and other Look and Feels whose renderers look
* drastically different from the standard <code>DefaultListCellRenderer</code>.
*
* @param delegate
* The new delegate renderer. If this is <code>null</code>,
* the default rendering of this component is used.
* @param delegate The new delegate renderer. If this is <code>null</code>, the
* default rendering of this component is used.
* @see #getDelegateRenderer()
* @see #delegateToSubstanceRenderer()
*/
@@ -552,9 +520,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Sets the font to use when rendering completion items.
*
* @param font
* The font to use. If this is <code>null</code>, then
* the default list font is used.
* @param font The font to use. If this is <code>null</code>, then the default
* list font is used.
* @see #getDisplayFont()
*/
public void setDisplayFont(Font font) {
@@ -562,11 +529,10 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Sets the icon to display based off of a completion, falling back to the
* empty icon if the completion has no icon.
* Sets the icon to display based off of a completion, falling back to the empty
* icon if the completion has no icon.
*
* @param completion
* The completion to check.
* @param completion The completion to check.
* @see #setIconWithDefault(Completion, Icon)
*/
protected void setIconWithDefault(Completion completion) {
@@ -574,13 +540,11 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Sets the icon to display based off of a completion, falling back to a
* default icon if the completion has no icon.
* Sets the icon to display based off of a completion, falling back to a default
* icon if the completion has no icon.
*
* @param completion
* The completion to check.
* @param defaultIcon
* The icon to use if <code>completion</code> does not
* @param completion The completion to check.
* @param defaultIcon The icon to use if <code>completion</code> does not
* specify an icon.
* @see #setIconWithDefault(Completion)
*/
@@ -592,8 +556,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Sets the color to use for function arguments.
*
* @param color
* The color to use. This is ignored if <code>null</code>.
* @param color The color to use. This is ignored if <code>null</code>.
* @see #setTypeColor(Color)
*/
public void setParamColor(Color color) {
@@ -603,11 +566,10 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
/**
* Sets whether the types of fields and return types of methods are
* shown in the completion text.
* Sets whether the types of fields and return types of methods are shown in the
* completion text.
*
* @param show
* Whether to show the types.
* @param show Whether to show the types.
* @see #getShowTypes()
*/
public void setShowTypes(boolean show) {
@@ -616,11 +578,10 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
* Sets the color to use for function/field types. Note that if
* {@link #getShowTypes()} returns <code>false</code>, this property
* effectively does nothing.
* {@link #getShowTypes()} returns <code>false</code>, this property effectively
* does nothing.
*
* @param color
* The color to use for types. This is ignored if
* @param color The color to use for types. This is ignored if
* <code>null</code>.
* @see #setShowTypes(boolean)
* @see #setParamColor(Color)
@@ -13,9 +13,8 @@ import java.util.List;
import javax.swing.AbstractListModel;
/**
* A list model implementation that allows the bulk addition of elements.
* This is the only feature missing from <code>DefaultListModel</code> that
* we need.
* A list model implementation that allows the bulk addition of elements. This
* is the only feature missing from <code>DefaultListModel</code> that we need.
*
* @author Robert Futrell
* @version 1.0
@@ -35,8 +34,8 @@ class CompletionListModel extends AbstractListModel {
}
/**
* Removes all of the elements from this list. The list will
* be empty after this call returns (unless it throws an exception).
* Removes all of the elements from this list. The list will be empty after this
* call returns (unless it throws an exception).
*
* @see #setContents(Collection)
*/
@@ -67,8 +66,7 @@ class CompletionListModel extends AbstractListModel {
/**
* Sets the contents of this model. All previous contents are removed.
*
* @param contents
* The new contents of this model.
* @param contents The new contents of this model.
*/
public void setContents(Collection<Completion> contents) {
clear();
@@ -36,38 +36,34 @@ public interface CompletionProvider {
public void clearParameterizedCompletionParams();
/**
* Returns the text just before the current caret position that could be
* the start of something auto-completable.
* Returns the text just before the current caret position that could be the
* start of something auto-completable.
*
* @param comp
* The text component.
* @return The text. A return value of <code>null</code> means nothing
* should be auto-completed; a value of an empty string
* (<code>""</code>) means auto-completion should still be
* considered (i.e., all possible choices are valid).
* @param comp The text component.
* @return The text. A return value of <code>null</code> means nothing should be
* auto-completed; a value of an empty string (<code>""</code>) means
* auto-completion should still be considered (i.e., all possible
* choices are valid).
*/
public String getAlreadyEnteredText(JTextComponent comp);
/**
* Gets the possible completions for the text component at the current
* caret position.
* Gets the possible completions for the text component at the current caret
* position.
*
* @param comp
* The text component.
* @return The list of {@link Completion}s. If no completions are
* available, this method should return an empty list.
* @param comp The text component.
* @return The list of {@link Completion}s. If no completions are available,
* this method should return an empty list.
*/
public List<Completion> getCompletions(JTextComponent comp);
/**
* Returns the completions that have been entered at the specified visual
* location. This can be used for tool tips when the user hovers the
* mouse over completed text.
* location. This can be used for tool tips when the user hovers the mouse over
* completed text.
*
* @param comp
* The text component.
* @param p
* The position, usually from a <tt>MouseEvent</tt>.
* @param comp The text component.
* @param p The position, usually from a <tt>MouseEvent</tt>.
* @return The completions, or an empty list if there are none.
*/
public List<Completion> getCompletionsAt(JTextComponent comp, Point p);
@@ -75,8 +71,8 @@ public interface CompletionProvider {
/**
* Returns the cell renderer for completions returned from this provider.
*
* @return The cell renderer, or <code>null</code> if the default should
* be used.
* @return The cell renderer, or <code>null</code> if the default should be
* used.
* @see #setListCellRenderer(ListCellRenderer)
*/
public ListCellRenderer getListCellRenderer();
@@ -87,29 +83,27 @@ public interface CompletionProvider {
* completion, such as a function or method. For any parameter to the
* function/method, this object can return possible completions.
*
* @return The parameter choices provider, or <code>null</code> if
* none is installed.
* @return The parameter choices provider, or <code>null</code> if none is
* installed.
*/
public ParameterChoicesProvider getParameterChoicesProvider();
/**
* Returns a list of parameterized completions that have been entered
* at the current caret position of a text component (and thus can have
* their completion choices displayed).
* Returns a list of parameterized completions that have been entered at the
* current caret position of a text component (and thus can have their
* completion choices displayed).
*
* @param tc
* The text component.
* @return The list of {@link ParameterizedCompletion}s. If no completions
* are available, this may be <code>null</code>.
* @param tc The text component.
* @return The list of {@link ParameterizedCompletion}s. If no completions are
* available, this may be <code>null</code>.
*/
public List<ParameterizedCompletion> getParameterizedCompletions(JTextComponent tc);
/**
* Returns the text that marks the end of a list of parameters to a
* function or method.
* Returns the text that marks the end of a list of parameters to a function or
* method.
*
* @return The text for a parameter list end, for example,
* '<code>)</code>'.
* @return The text for a parameter list end, for example, '<code>)</code>'.
* @see #getParameterListStart()
* @see #getParameterListSeparator()
* @see #setParameterizedCompletionParams(char, String, char)
@@ -119,8 +113,7 @@ public interface CompletionProvider {
/**
* Returns the text that separates parameters to a function or method.
*
* @return The text that separates parameters, for example,
* "<code>, </code>".
* @return The text that separates parameters, for example, "<code>, </code>".
* @see #getParameterListStart()
* @see #getParameterListEnd()
* @see #setParameterizedCompletionParams(char, String, char)
@@ -128,11 +121,10 @@ public interface CompletionProvider {
public String getParameterListSeparator();
/**
* Returns the text that marks the start of a list of parameters to a
* function or method.
* Returns the text that marks the start of a list of parameters to a function
* or method.
*
* @return The text for a parameter list start, for example,
* "<code>(</code>".
* @return The text for a parameter list start, for example, "<code>(</code>".
* @see #getParameterListEnd()
* @see #getParameterListSeparator()
* @see #setParameterizedCompletionParams(char, String, char)
@@ -149,15 +141,14 @@ public interface CompletionProvider {
/**
* This method is called if auto-activation is enabled in the parent
* {@link AutoCompletion} after the user types a single character. This
* provider should check the text at the current caret position of the
* text component, and decide whether auto-activation would be appropriate
* here. For example, a <code>CompletionProvider</code> for Java might
* want to return <code>true</code> for this method only if the last
* character typed was a '<code>.</code>'.
* {@link AutoCompletion} after the user types a single character. This provider
* should check the text at the current caret position of the text component,
* and decide whether auto-activation would be appropriate here. For example, a
* <code>CompletionProvider</code> for Java might want to return
* <code>true</code> for this method only if the last character typed was a
* '<code>.</code>'.
*
* @param tc
* The text component.
* @param tc The text component.
* @return Whether auto-activation would be appropriate.
*/
public boolean isAutoActivateOkay(JTextComponent tc);
@@ -165,30 +156,26 @@ public interface CompletionProvider {
/**
* Sets the renderer to use when displaying completion choices.
*
* @param r
* The renderer to use.
* @param r The renderer to use.
* @see #getListCellRenderer()
*/
public void setListCellRenderer(ListCellRenderer r);
/**
* Sets the values used to identify and insert "parameterized completions"
* (e.g. functions or methods). If this method isn't called, functions
* and methods will not have their parameters auto-completed.
* Sets the values used to identify and insert "parameterized completions" (e.g.
* functions or methods). If this method isn't called, functions and methods
* will not have their parameters auto-completed.
*
* @param listStart
* The character that marks the beginning of a list of
* @param listStart The character that marks the beginning of a list of
* parameters, such as '<tt>(</tt>' in C or Java.
* @param separator
* Text that should separate parameters in a parameter
* list when one is inserted. For example, "<tt>, </tt>".
* @param listEnd
* The character that marks the end of a list of parameters,
* @param separator Text that should separate parameters in a parameter list
* when one is inserted. For example, "<tt>, </tt>".
* @param listEnd The character that marks the end of a list of parameters,
* such as '<tt>)</tt>' in C or Java.
* @throws IllegalArgumentException
* If either <tt>listStart</tt> or
* <tt>listEnd</tt> is not printable ASCII, or if
* <tt>separator</tt> is <code>null</code> or an empty string.
* @throws IllegalArgumentException If either <tt>listStart</tt> or
* <tt>listEnd</tt> is not printable ASCII, or
* if <tt>separator</tt> is <code>null</code>
* or an empty string.
* @see #clearParameterizedCompletionParams()
*/
public void setParameterizedCompletionParams(char listStart, String separator, char listEnd);
@@ -196,9 +183,8 @@ public interface CompletionProvider {
/**
* Sets the parent completion provider.
*
* @param parent
* The parent provider. <code>null</code> means there will
* be no parent provider.
* @param parent The parent provider. <code>null</code> means there will be no
* parent provider.
* @see #getParent()
*/
public void setParent(CompletionProvider parent);
@@ -182,7 +182,8 @@ public abstract class CompletionProviderBase implements CompletionProvider {
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
return (autoActivateAfterLetters && Character.isLetter(ch)) || (autoActivateChars != null && autoActivateChars.indexOf(ch) > -1);
return (autoActivateAfterLetters && Character.isLetter(ch))
|| (autoActivateChars != null && autoActivateChars.indexOf(ch) > -1);
}
/**
@@ -18,9 +18,9 @@ import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Parser for an XML file describing a procedural language such as C. XML
* files will be validated against the <code>CompletionXml.dtd</code> DTD
* found in this package.
* Parser for an XML file describing a procedural language such as C. XML files
* will be validated against the <code>CompletionXml.dtd</code> DTD found in
* this package.
*
* @author Robert Futrell
* @version 1.0
@@ -68,18 +68,16 @@ public class CompletionXMLParser extends DefaultHandler {
*/
private String funcCompletionType;
/**
* The class loader to use to load custom completion classes, such as
* the one defined by {@link #funcCompletionType}. If this is
* <code>null</code>, then a default class loader is used. This field
* will usually be <code>null</code>.
* The class loader to use to load custom completion classes, such as the one
* defined by {@link #funcCompletionType}. If this is <code>null</code>, then a
* default class loader is used. This field will usually be <code>null</code>.
*/
private static ClassLoader DEFAULT_COMPLETION_CLASS_LOADER;
/**
* Constructor.
*
* @param provider
* The provider to get completions for.
* @param provider The provider to get completions for.
* @see #reset(CompletionProvider)
*/
public CompletionXMLParser(CompletionProvider provider) {
@@ -89,15 +87,12 @@ public class CompletionXMLParser extends DefaultHandler {
/**
* Constructor.
*
* @param provider
* The provider to get completions for.
* @param cl
* The class loader to use, if necessary, when loading classes
* @param provider The provider to get completions for.
* @param cl The class loader to use, if necessary, when loading classes
* from the XML (custom {@link FunctionCompletion}s, for
* example).
* This may be <code>null</code> if the default is to be used, or
* if the XML does not define specific classes for completion
* types.
* example). This may be <code>null</code> if the default is to
* be used, or if the XML does not define specific classes for
* completion types.
* @see #reset(CompletionProvider)
*/
public CompletionXMLParser(CompletionProvider provider, ClassLoader cl) {
@@ -295,8 +290,7 @@ public class CompletionXMLParser extends DefaultHandler {
/**
* Resets this parser to grab more completions.
*
* @param provider
* The new provider to get completions for.
* @param provider The new provider to get completions for.
*/
public void reset(CompletionProvider provider) {
this.provider = provider;
@@ -312,16 +306,14 @@ public class CompletionXMLParser extends DefaultHandler {
}
/**
* Sets the class loader to use when loading custom classes to use for
* various {@link Completion} types, such as {@link FunctionCompletion}s,
* from XML.
* Sets the class loader to use when loading custom classes to use for various
* {@link Completion} types, such as {@link FunctionCompletion}s, from XML.
* <p>
*
* Users should very rarely have a need to use this method.
*
* @param cl
* The class loader to use. If this is <code>null</code>, then
* a default is used.
* @param cl The class loader to use. If this is <code>null</code>, then a
* default is used.
*/
public static void setDefaultCompletionClassLoader(ClassLoader cl) {
DEFAULT_COMPLETION_CLASS_LOADER = cl;
@@ -28,9 +28,9 @@ import org.xml.sax.SAXException;
/**
* A basic completion provider implementation. This provider has no
* understanding of language semantics. It simply checks the text entered up
* to the caret position for a match against known completions. This is all
* that is needed in the majority of cases.
* understanding of language semantics. It simply checks the text entered up to
* the caret position for a match against known completions. This is all that is
* needed in the majority of cases.
*
* @author Robert Futrell
* @version 1.0
@@ -43,11 +43,11 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
*/
private String lastCompletionsAtText;
/**
* Used to speed up {@link #getCompletionsAt(JTextComponent, Point)},
* since this may be called multiple times in succession (this is usually
* called by <tt>JTextComponent.getToolTipText()</tt>, and if the user
* wiggles the mouse while a tool tip is displayed, this method gets
* repeatedly called. It can be costly so we try to speed it up a tad).
* Used to speed up {@link #getCompletionsAt(JTextComponent, Point)}, since this
* may be called multiple times in succession (this is usually called by
* <tt>JTextComponent.getToolTipText()</tt>, and if the user wiggles the mouse
* while a tool tip is displayed, this method gets repeatedly called. It can be
* costly so we try to speed it up a tad).
*/
private List<Completion> lastParameterizedCompletionsAt;
@@ -61,11 +61,10 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
}
/**
* Creates a completion provider that provides completion for a simple
* list of words.
* Creates a completion provider that provides completion for a simple list of
* words.
*
* @param words
* The words to offer as completion suggestions. If this is
* @param words The words to offer as completion suggestions. If this is
* <code>null</code>, no completions will be known.
* @see BasicCompletion
*/
@@ -75,12 +74,12 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
}
/**
* Returns the text just before the current caret position that could be
* the start of something auto-completable.
* Returns the text just before the current caret position that could be the
* start of something auto-completable.
* <p>
*
* This method returns all characters before the caret that are matched
* by {@link #isValidChar(char)}.
* This method returns all characters before the caret that are matched by
* {@link #isValidChar(char)}.
*
* {@inheritDoc}
*/
@@ -221,13 +220,12 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
}
/**
* Returns whether the specified character is valid in an auto-completion.
* The default implementation is equivalent to
* "<code>Character.isLetterOrDigit(ch) || ch=='_'</code>". Subclasses
* can override this method to change what characters are matched.
* Returns whether the specified character is valid in an auto-completion. The
* default implementation is equivalent to
* "<code>Character.isLetterOrDigit(ch) || ch=='_'</code>". Subclasses can
* override this method to change what characters are matched.
*
* @param ch
* The character.
* @param ch The character.
* @return Whether the character is valid.
*/
protected boolean isValidChar(char ch) {
@@ -238,10 +236,8 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
* Loads completions from an XML file. The XML should validate against
* <code>CompletionXml.dtd</code>.
*
* @param file
* An XML file to load from.
* @throws IOException
* If an IO error occurs.
* @param file An XML file to load from.
* @throws IOException If an IO error occurs.
*/
public void loadFromXML(File file) throws IOException {
BufferedInputStream bin = new BufferedInputStream(new FileInputStream(file));
@@ -253,32 +249,26 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
}
/**
* Loads completions from an XML input stream. The XML should validate
* against <code>CompletionXml.dtd</code>.
* Loads completions from an XML input stream. The XML should validate against
* <code>CompletionXml.dtd</code>.
*
* @param in
* The input stream to read from.
* @throws IOException
* If an IO error occurs.
* @param in The input stream to read from.
* @throws IOException If an IO error occurs.
*/
public void loadFromXML(InputStream in) throws IOException {
loadFromXML(in, null);
}
/**
* Loads completions from an XML input stream. The XML should validate
* against <code>CompletionXml.dtd</code>.
* Loads completions from an XML input stream. The XML should validate against
* <code>CompletionXml.dtd</code>.
*
* @param in
* The input stream to read from.
* @param cl
* The class loader to use when loading any extra classes defined
* in the XML, such as custom {@link FunctionCompletion}s. This
* may be <code>null</code> if the default is to be used, or if
* no
* custom completions are defined in the XML.
* @throws IOException
* If an IO error occurs.
* @param in The input stream to read from.
* @param cl The class loader to use when loading any extra classes defined in
* the XML, such as custom {@link FunctionCompletion}s. This may be
* <code>null</code> if the default is to be used, or if no custom
* completions are defined in the XML.
* @throws IOException If an IO error occurs.
*/
public void loadFromXML(InputStream in, ClassLoader cl) throws IOException {
// long start = System.currentTimeMillis();
@@ -314,10 +304,8 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
* Loads completions from an XML file. The XML should validate against
* <code>CompletionXml.dtd</code>.
*
* @param resource
* A resource the current ClassLoader can get to.
* @throws IOException
* If an IO error occurs.
* @param resource A resource the current ClassLoader can get to.
* @throws IOException If an IO error occurs.
*/
public void loadFromXML(String resource) throws IOException {
ClassLoader cl = getClass().getClassLoader();
@@ -15,9 +15,9 @@ import javax.swing.JList;
import javax.swing.ListCellRenderer;
/**
* List cell renderer that delegates to a {@link CompletionProvider}'s
* renderer, if it has one. If it doesn't, it calls into a fallback renderer.
* If a fallback renderer isn't specified, it simply renders
* List cell renderer that delegates to a {@link CompletionProvider}'s renderer,
* if it has one. If it doesn't, it calls into a fallback renderer. If a
* fallback renderer isn't specified, it simply renders
* <code>(({@link Completion})value).toString()</code>.
*
* @author Robert Futrell
@@ -26,8 +26,8 @@ import javax.swing.ListCellRenderer;
class DelegatingCellRenderer extends DefaultListCellRenderer {
/**
* The renderer to fall back on if one isn't specified by a provider.
* This is usually <tt>this</tt>.
* The renderer to fall back on if one isn't specified by a provider. This is
* usually <tt>this</tt>.
*/
private ListCellRenderer fallback;
@@ -45,7 +45,8 @@ class DelegatingCellRenderer extends DefaultListCellRenderer {
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus) {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected,
boolean hasFocus) {
Completion c = (Completion) value;
CompletionProvider p = c.getProvider();
ListCellRenderer r = p.getListCellRenderer();
@@ -61,9 +62,8 @@ class DelegatingCellRenderer extends DefaultListCellRenderer {
/**
* Sets the fallback cell renderer.
*
* @param fallback
* The fallback cell renderer. If this is
* <code>null</code>, <tt>this</tt> will be used.
* @param fallback The fallback cell renderer. If this is <code>null</code>,
* <tt>this</tt> will be used.
* @see #getFallbackCellRenderer()
*/
public void setFallbackCellRenderer(ListCellRenderer fallback) {
@@ -16,13 +16,11 @@ package org.fife.ui.autocomplete;
public interface DescWindowCallback {
/**
* Callback allowing a new code completion's description to be displayed
* in the description window.
* Callback allowing a new code completion's description to be displayed in the
* description window.
*
* @param completion
* The new completion.
* @param anchor
* The anchor to scroll to, or <code>null</code> if none.
* @param completion The new completion.
* @param anchor The anchor to scroll to, or <code>null</code> if none.
*/
public void showSummaryFor(Completion completion, String anchor);
}
+2 -1
View File
@@ -39,5 +39,6 @@ public class EmptyIcon implements Icon, Serializable {
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {}
public void paintIcon(Component c, Graphics g, int x, int y) {
}
}
@@ -10,12 +10,12 @@ package org.fife.ui.autocomplete;
import javax.swing.event.HyperlinkEvent;
/**
* A callback for when an external URL is clicked in the description window.
* If no handler is installed, and if running in Java 6, the system default
* web browser is used to open the URL. If not running Java 6, nothing will
* happen. If you want browser support for pre-Java 6 JRE's, you will need
* to register one of these callbacks on your {@link AutoCompletion}, and
* open the URL in a web browser yourself.
* A callback for when an external URL is clicked in the description window. If
* no handler is installed, and if running in Java 6, the system default web
* browser is used to open the URL. If not running Java 6, nothing will happen.
* If you want browser support for pre-Java 6 JRE's, you will need to register
* one of these callbacks on your {@link AutoCompletion}, and open the URL in a
* web browser yourself.
* <p>
*
* Alternatively, folks implementing robust code completion support for a
@@ -31,13 +31,9 @@ public interface ExternalURLHandler {
/**
* Called when an external URL is clicked in the description window.
*
* @param e
* The event containing the hyperlink clicked.
* @param c
* The completion currently being displayed.
* @param callback
* Allows you to display new content in the description
* window.
* @param e The event containing the hyperlink clicked.
* @param c The completion currently being displayed.
* @param callback Allows you to display new content in the description window.
*/
public void urlClicked(HyperlinkEvent e, Completion c, DescWindowCallback callback);
}
+21 -23
View File
@@ -20,14 +20,14 @@ import javax.swing.plaf.basic.BasicListUI;
/**
* A custom list UI, used by the completion choices list. If the number of
* completion choices is "large," it does a fast estimate of the preferred
* width and height of list items. This allows HTML renderers to be used (such
* as {@link CompletionCellRenderer}), with thousands of completion choices,
* with no performance penalty. With standard BasicListUI subclasses, this can
* cause very poor performance <b>each time</b> the list is displayed, which
* is bad for lists that are repeatedly hidden and re-displayed, such as
* completion choices. This is all because the calculation to get the
* preferred size of each list item, when it is displayed with HTML, is slow.
* completion choices is "large," it does a fast estimate of the preferred width
* and height of list items. This allows HTML renderers to be used (such as
* {@link CompletionCellRenderer}), with thousands of completion choices, with
* no performance penalty. With standard BasicListUI subclasses, this can cause
* very poor performance <b>each time</b> the list is displayed, which is bad
* for lists that are repeatedly hidden and re-displayed, such as completion
* choices. This is all because the calculation to get the preferred size of
* each list item, when it is displayed with HTML, is slow.
*
* @author Robert Futrell
* @version 1.0
@@ -35,19 +35,19 @@ import javax.swing.plaf.basic.BasicListUI;
class FastListUI extends BasicListUI {
/**
* Whether the selection background was overridden (usually because of
* Nimbus) so we know to manually uninstall the color we installed.
* Whether the selection background was overridden (usually because of Nimbus)
* so we know to manually uninstall the color we installed.
*/
private boolean overriddenBackground;
/**
* Whether the selection foreground was overridden (usually because of
* Nimbus) so we know to manually uninstall the color we installed.
* Whether the selection foreground was overridden (usually because of Nimbus)
* so we know to manually uninstall the color we installed.
*/
private boolean overriddenForeground;
/**
* If there are more than this many completions in a single list, this
* UI will estimate the cell width and height needed for each item instead
* of computing it, for performance reasons.
* If there are more than this many completions in a single list, this UI will
* estimate the cell width and height needed for each item instead of computing
* it, for performance reasons.
*/
private static final int ESTIMATION_THRESHOLD = 200;
@@ -86,10 +86,9 @@ class FastListUI extends BasicListUI {
}
/**
* Overridden to ensure we have selection background/foreground colors
* defined, even if we're in some weirdo LAF such as Nimbus which doesn't
* define them. Since FastListUI extends BasicListUI, we need these values
* to be defined.
* Overridden to ensure we have selection background/foreground colors defined,
* even if we're in some weirdo LAF such as Nimbus which doesn't define them.
* Since FastListUI extends BasicListUI, we need these values to be defined.
*/
@Override
protected void installDefaults() {
@@ -119,10 +118,9 @@ class FastListUI extends BasicListUI {
}
/**
* Recalculates the cell width and height of each cell in the list. This
* method is overridden to do a fast estimation if the completion list is
* too long, to improve performance for lists with huge amounts of
* completions.
* Recalculates the cell width and height of each cell in the list. This method
* is overridden to do a fast estimation if the completion list is too long, to
* improve performance for lists with huge amounts of completions.
*/
@Override
protected void updateLayoutState() {
@@ -37,12 +37,9 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
/**
* Constructor.
*
* @param provider
* The parent provider.
* @param name
* The name of this function.
* @param returnType
* The return type of this function.
* @param provider The parent provider.
* @param name The name of this function.
* @param returnType The return type of this function.
*/
public FunctionCompletion(CompletionProvider provider, String name, String returnType) {
super(provider, name, returnType);
@@ -58,8 +55,7 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
/**
* Adds HTML describing the parameters to this function to a buffer.
*
* @param sb
* The buffer to append to.
* @param sb The buffer to append to.
*/
protected void addParameters(StringBuilder sb) {
// TODO: Localize me
@@ -90,8 +86,7 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
/**
* Overridden to compare methods by their comparison strings.
*
* @param c2
* A <code>Completion</code> to compare to.
* @param c2 A <code>Completion</code> to compare to.
* @return The sort order.
*/
@Override
@@ -114,11 +109,9 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
*/
private String getCompareString() {
/*
* This string compares the following parts of methods in this order,
* to optimize sort order in completion lists.
* 1. First, by name
* 2. Next, by number of parameters.
* 3. Finally, by parameter type.
* This string compares the following parts of methods in this order, to
* optimize sort order in completion lists. 1. First, by name 2. Next, by number
* of parameters. 3. Finally, by parameter type.
*/
if (compareString == null) {
StringBuilder sb = new StringBuilder(getName());
@@ -141,8 +134,8 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
}
/**
* Returns the "definition string" for this function completion. For
* example, for the C "<code>printf</code>" function, this would return
* Returns the "definition string" for this function completion. For example,
* for the C "<code>printf</code>" function, this would return
* "<code>int printf(const char *, ...)</code>".
*
* @return The definition string.
@@ -269,8 +262,7 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
/**
* Returns the text to insert for a parameter.
*
* @param param
* The parameter.
* @param param The parameter.
* @return The text.
*/
private String getParamText(ParameterizedCompletion.Parameter param) {
@@ -324,8 +316,7 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
/**
* Sets the parameters to this function.
*
* @param params
* The parameters. This should be a list of
* @param params The parameters. This should be a list of
* {@link ParameterizedCompletion.Parameter}s.
* @see #getParam(int)
* @see #getParamCount()
@@ -340,8 +331,7 @@ public class FunctionCompletion extends VariableCompletion implements Parameteri
/**
* Sets the description of the return value of this function.
*
* @param desc
* The description.
* @param desc The description.
* @see #getReturnValueDescription()
*/
public void setReturnValueDescription(String desc) {
@@ -33,13 +33,13 @@ import org.fife.ui.rtextarea.ToolTipSupplier;
* <li>A documentation comment</li>
* </ul>
*
* This allows for different completion choices in comments than in code,
* for example.
* This allows for different completion choices in comments than in code, for
* example.
* <p>
*
* This provider also implements the
* <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> interface, which allows it
* to display tooltips for completion choices. Thus the standard
* <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> interface, which allows it to
* display tooltips for completion choices. Thus the standard
* {@link VariableCompletion} and {@link FunctionCompletion} completions should
* be able to display tooltips with the variable declaration or function
* definition (provided the <tt>RSyntaxTextArea</tt> was registered with the
@@ -51,8 +51,7 @@ import org.fife.ui.rtextarea.ToolTipSupplier;
public class LanguageAwareCompletionProvider extends CompletionProviderBase implements ToolTipSupplier {
/**
* The provider to use when no provider is assigned to a particular token
* type.
* The provider to use when no provider is assigned to a particular token type.
*/
private CompletionProvider defaultProvider;
/**
@@ -69,32 +68,31 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
private CompletionProvider docCommentCompletionProvider;
/**
* Constructor subclasses can use when they don't have their default
* provider created at construction time. They should call
* Constructor subclasses can use when they don't have their default provider
* created at construction time. They should call
* {@link #setDefaultCompletionProvider(CompletionProvider)} in this
* constructor.
*/
protected LanguageAwareCompletionProvider() {}
protected LanguageAwareCompletionProvider() {
}
/**
* Constructor.
*
* @param defaultProvider
* The provider to use when no provider is assigned
* to a particular token type. This cannot be <code>null</code>.
* @param defaultProvider The provider to use when no provider is assigned to a
* particular token type. This cannot be
* <code>null</code>.
*/
public LanguageAwareCompletionProvider(CompletionProvider defaultProvider) {
setDefaultCompletionProvider(defaultProvider);
}
/**
* Calling this method will result in an
* {@link UnsupportedOperationException} being thrown. To set the
* parameter completion parameters, do so on the provider returned by
* {@link #getDefaultCompletionProvider()}.
* Calling this method will result in an {@link UnsupportedOperationException}
* being thrown. To set the parameter completion parameters, do so on the
* provider returned by {@link #getDefaultCompletionProvider()}.
*
* @throws UnsupportedOperationException
* Always.
* @throws UnsupportedOperationException Always.
* @see #setParameterizedCompletionParams(char, String, char)
*/
@Override
@@ -135,10 +133,8 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
/**
* Does the dirty work of creating a list of completions.
*
* @param comp
* The text component to look in.
* @return The list of possible completions, or an empty list if there
* are none.
* @param comp The text component to look in.
* @return The list of possible completions, or an empty list if there are none.
*/
@Override
protected List<Completion> getCompletionsImpl(JTextComponent comp) {
@@ -152,8 +148,8 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
}
/**
* Returns the completion provider used when one isn't defined for a
* particular token type.
* Returns the completion provider used when one isn't defined for a particular
* token type.
*
* @return The completion provider to use.
* @see #setDefaultCompletionProvider(CompletionProvider)
@@ -209,11 +205,10 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
}
/**
* Returns the completion provider to use at the current caret position in
* a text component.
* Returns the completion provider to use at the current caret position in a
* text component.
*
* @param comp
* The text component to check.
* @param comp The text component to check.
* @return The completion provider to use.
*/
private CompletionProvider getProviderFor(JTextComponent comp) {
@@ -304,8 +299,7 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
/**
* Sets the comment completion provider.
*
* @param provider
* The provider to use in comments.
* @param provider The provider to use in comments.
* @see #getCommentCompletionProvider()
*/
public void setCommentCompletionProvider(CompletionProvider provider) {
@@ -315,8 +309,7 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
/**
* Sets the default completion provider.
*
* @param provider
* The provider to use when no provider is assigned to a
* @param provider The provider to use when no provider is assigned to a
* particular token type. This cannot be <code>null</code>.
* @see #getDefaultCompletionProvider()
*/
@@ -330,8 +323,7 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
/**
* Sets the documentation comment completion provider.
*
* @param provider
* The provider to use in comments.
* @param provider The provider to use in comments.
* @see #getDocCommentCompletionProvider()
*/
public void setDocCommentCompletionProvider(CompletionProvider provider) {
@@ -339,13 +331,11 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
}
/**
* Calling this method will result in an
* {@link UnsupportedOperationException} being thrown. To set the
* parameter completion parameters, do so on the provider returned by
* {@link #getDefaultCompletionProvider()}.
* Calling this method will result in an {@link UnsupportedOperationException}
* being thrown. To set the parameter completion parameters, do so on the
* provider returned by {@link #getDefaultCompletionProvider()}.
*
* @throws UnsupportedOperationException
* Always.
* @throws UnsupportedOperationException Always.
* @see #clearParameterizedCompletionParams()
*/
@Override
@@ -356,8 +346,7 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
/**
* Sets the completion provider to use while in a string.
*
* @param provider
* The provider to use.
* @param provider The provider to use.
* @see #getStringCompletionProvider()
*/
public void setStringCompletionProvider(CompletionProvider provider) {
@@ -368,17 +357,15 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase impl
* Returns the tool tip to display for a mouse event.
* <p>
*
* For this method to be called, the <tt>RSyntaxTextArea</tt> must be
* registered with the <tt>javax.swing.ToolTipManager</tt> like so:
* For this method to be called, the <tt>RSyntaxTextArea</tt> must be registered
* with the <tt>javax.swing.ToolTipManager</tt> like so:
*
* <pre>
* ToolTipManager.sharedInstance().registerComponent(textArea);
* </pre>
*
* @param textArea
* The text area.
* @param e
* The mouse event.
* @param textArea The text area.
* @param e The mouse event.
* @return The tool tip text, or <code>null</code> if none.
*/
@Override
@@ -8,9 +8,8 @@ package org.fife.ui.autocomplete;
import java.net.URL;
/**
* Possibly redirects one URL to another. Useful if you want "external" URL's
* in code completion documentation to point to a local copy instead, for
* example.
* Possibly redirects one URL to another. Useful if you want "external" URL's in
* code completion documentation to point to a local copy instead, for example.
*
* @author Robert Futrell
* @version 1.0
@@ -31,10 +31,8 @@ public class MarkupTagCompletion extends AbstractCompletion {
/**
* Constructor.
*
* @param provider
* The parent provider instance.
* @param name
* The name of the tag.
* @param provider The parent provider instance.
* @param name The name of the tag.
*/
public MarkupTagCompletion(CompletionProvider provider, String name) {
super(provider);
@@ -44,8 +42,7 @@ public class MarkupTagCompletion extends AbstractCompletion {
/**
* Adds HTML describing the attributes of this tag to a buffer.
*
* @param sb
* The buffer to append to.
* @param sb The buffer to append to.
*/
protected void addAttributes(StringBuilder sb) {
// TODO: Localize me.
@@ -86,8 +83,7 @@ public class MarkupTagCompletion extends AbstractCompletion {
/**
* Returns the specified {@link ParameterizedCompletion.Parameter}.
*
* @param index
* The index of the attribute to retrieve.
* @param index The index of the attribute to retrieve.
* @return The attribute.
* @see #getAttributeCount()
*/
@@ -116,11 +112,9 @@ public class MarkupTagCompletion extends AbstractCompletion {
}
/**
* Returns a short description of this variable. This should be an
* HTML snippet.
* Returns a short description of this variable. This should be an HTML snippet.
*
* @return A short description of this variable. This may be
* <code>null</code>.
* @return A short description of this variable. This may be <code>null</code>.
* @see #setDescription(String)
*/
public String getDescription() {
@@ -158,11 +152,10 @@ public class MarkupTagCompletion extends AbstractCompletion {
}
/**
* Adds some HTML describing where this variable is defined, if this
* information is known.
* Adds some HTML describing where this variable is defined, if this information
* is known.
*
* @param sb
* The buffer to append to.
* @param sb The buffer to append to.
*/
protected void possiblyAddDefinedIn(StringBuilder sb) {
if (definedIn != null) {
@@ -172,11 +165,9 @@ public class MarkupTagCompletion extends AbstractCompletion {
}
/**
* Adds the description text as HTML to a buffer, if a description is
* defined.
* Adds the description text as HTML to a buffer, if a description is defined.
*
* @param sb
* The buffer to append to.
* @param sb The buffer to append to.
*/
protected void possiblyAddDescription(StringBuilder sb) {
if (desc != null) {
@@ -189,8 +180,7 @@ public class MarkupTagCompletion extends AbstractCompletion {
/**
* Sets where this variable is defined.
*
* @param definedIn
* Where this variable is defined.
* @param definedIn Where this variable is defined.
* @see #getDefinedIn()
*/
public void setDefinedIn(String definedIn) {
@@ -198,12 +188,9 @@ public class MarkupTagCompletion extends AbstractCompletion {
}
/**
* Sets the short description of this tag. This should be an
* HTML snippet.
* Sets the short description of this tag. This should be an HTML snippet.
*
* @param desc
* A short description of this tag. This may be
* <code>null</code>.
* @param desc A short description of this tag. This may be <code>null</code>.
* @see #getDescription()
*/
public void setDescription(String desc) {
@@ -213,8 +200,7 @@ public class MarkupTagCompletion extends AbstractCompletion {
/**
* Sets the attributes of this tag.
*
* @param attrs
* The attributes.
* @param attrs The attributes.
* @see #getAttribute(int)
* @see #getAttributeCount()
*/
@@ -19,16 +19,16 @@ import javax.swing.text.Position;
import javax.swing.text.View;
/**
* Highlight painter that draws an outline around the text. This is used to
* draw bounds around function/method parameters.
* Highlight painter that draws an outline around the text. This is used to draw
* bounds around function/method parameters.
*
* @author Robert Futrell
* @version 1.0
*/
/*
* NOTE: Whenever you see text like "Workaround for Java Highlight issues",
* this is because highlighted text in a JTextComponent gets "pushed" forward
* when the caret is at the Highlight's start, when we need it to instead get
* NOTE: Whenever you see text like "Workaround for Java Highlight issues", this
* is because highlighted text in a JTextComponent gets "pushed" forward when
* the caret is at the Highlight's start, when we need it to instead get
* prepended to. For this reason, the auto-complete package adds its Highlights
* 1 char too long (1 char earlier than where it should really start), but only
* paint the Highlight from the 2nd char on.
@@ -36,17 +36,16 @@ import javax.swing.text.View;
class OutlineHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter {
/**
* DefaultHighlightPainter doesn't allow changing color, so we must cache
* ours here.
* DefaultHighlightPainter doesn't allow changing color, so we must cache ours
* here.
*/
private Color color;
/**
* Constructor.
*
* @param color
* The color to draw the bounding boxes with. This cannot
* be <code>null</code>.
* @param color The color to draw the bounding boxes with. This cannot be
* <code>null</code>.
*/
public OutlineHighlightPainter(Color color) {
super(color);
@@ -114,8 +113,7 @@ class OutlineHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter
/**
* Sets the color to paint the bounding boxes with.
*
* @param color
* The new color. This cannot be <code>null</code>.
* @param color The new color. This cannot be <code>null</code>.
* @see #getColor()
*/
public void setColor(Color color) {
@@ -12,9 +12,9 @@ import java.util.List;
import javax.swing.text.JTextComponent;
/**
* Provides completions for a {@link ParameterizedCompletion}'s parameters.
* So, for example, if the user code-completes a function or method, if
* a <code>ParameterChoicesProvider</code> is installed, it can return possible
* Provides completions for a {@link ParameterizedCompletion}'s parameters. So,
* for example, if the user code-completes a function or method, if a
* <code>ParameterChoicesProvider</code> is installed, it can return possible
* completions for the parameters to that function or method.
*
* @author Robert Futrell
@@ -25,12 +25,10 @@ public interface ParameterChoicesProvider {
/**
* Returns a list of choices for a specific parameter.
*
* @param tc
* The text component.
* @param param
* The currently focused parameter.
* @return The list of parameters. This may be <code>null</code> for
* "no parameters," but might also be an empty list.
* @param tc The text component.
* @param param The currently focused parameter.
* @return The list of parameters. This may be <code>null</code> for "no
* parameters," but might also be an empty list.
*/
public List<Completion> getParameterChoices(JTextComponent tc, ParameterizedCompletion.Parameter param);
}
@@ -17,8 +17,8 @@ import javax.swing.text.JTextComponent;
public interface ParameterizedCompletion extends Completion {
/**
* Returns the "definition string" for this completion. For example,
* for the C "<code>printf</code>" function, this would return
* Returns the "definition string" for this completion. For example, for the C
* "<code>printf</code>" function, this would return
* "<code>int printf(const char *, ...)</code>".
*
* @return The definition string.
@@ -28,8 +28,7 @@ public interface ParameterizedCompletion extends Completion {
/**
* Returns the specified {@link Parameter}.
*
* @param index
* The index of the parameter to retrieve.
* @param index The index of the parameter to retrieve.
* @return The parameter.
* @see #getParamCount()
*/
@@ -46,8 +45,8 @@ public interface ParameterizedCompletion extends Completion {
public ParameterizedCompletionInsertionInfo getInsertionInfo(JTextComponent tc, boolean replaceTabsWithSpaces);
/**
* Returns whether a tool tip displaying assistance for each parameter
* while it is being edited is appropriate for this completion.
* Returns whether a tool tip displaying assistance for each parameter while it
* is being edited is appropriate for this completion.
*
* @return Whether the tool tip is appropriate to display.
*/
@@ -66,16 +65,13 @@ public interface ParameterizedCompletion extends Completion {
/**
* Constructor.
*
* @param type
* The type of this parameter. This may be
* <code>null</code> for languages without specific types,
* dynamic typing, etc. Usually you'll pass a String for this
* value, but you may pass any object representing a type in
* your language, as long as its <code>toString()</code>
* method
* returns a string representation of the type.
* @param name
* The name of the parameter.
* @param type The type of this parameter. This may be <code>null</code> for
* languages without specific types, dynamic typing, etc. Usually
* you'll pass a String for this value, but you may pass any object
* representing a type in your language, as long as its
* <code>toString()</code> method returns a string representation of
* the type.
* @param name The name of the parameter.
*/
public Parameter(Object type, String name) {
this(type, name, false);
@@ -84,25 +80,19 @@ public interface ParameterizedCompletion extends Completion {
/**
* Constructor.
*
* @param type
* The type of this parameter. This may be
* <code>null</code> for languages without specific types,
* dynamic typing, etc. Usually you'll pass a String for this
* value, but you may pass any object representing a type in
* your language, as long as its <code>toString()</code>
* method
* returns a string representation of the type.
* @param name
* The name of the parameter.
* @param endParam
* Whether this parameter is an "ending parameter;"
* that is, whether this parameter is at a logical "ending
* point" in the completion text. If the user types in a
* parameter that is an ending point, parameter completion
* mode
* terminates. Set this to <code>true</code> for a trailing
* parameter after a function call's closing ')', for
* example.
* @param type The type of this parameter. This may be <code>null</code> for
* languages without specific types, dynamic typing, etc.
* Usually you'll pass a String for this value, but you may pass
* any object representing a type in your language, as long as
* its <code>toString()</code> method returns a string
* representation of the type.
* @param name The name of the parameter.
* @param endParam Whether this parameter is an "ending parameter;" that is,
* whether this parameter is at a logical "ending point" in the
* completion text. If the user types in a parameter that is an
* ending point, parameter completion mode terminates. Set this
* to <code>true</code> for a trailing parameter after a
* function call's closing ')', for example.
*/
public Parameter(Object type, String name, boolean endParam) {
this.name = name;
@@ -137,11 +127,10 @@ public interface ParameterizedCompletion extends Completion {
}
/**
* @return Whether this parameter is an "ending parameter;"
* that is, whether this parameter is at a logical "ending
* point" in the completion text. If the user types in a
* parameter that is an ending point, parameter completion mode
* terminates.
* @return Whether this parameter is an "ending parameter;" that is, whether
* this parameter is at a logical "ending point" in the completion text.
* If the user types in a parameter that is an ending point, parameter
* completion mode terminates.
*/
public boolean isEndParam() {
return isEndParam;
@@ -28,11 +28,11 @@ import javax.swing.text.JTextComponent;
import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
/**
* A small popup window offering a list of likely choices for a parameter
* when the user has code-completed a parameterized completion. For example,
* if they have just code-completed the C function "<code>fprintf</code>",
* when entering the file name, this popup might display all local variables
* of type "<code>char *</code>".
* A small popup window offering a list of likely choices for a parameter when
* the user has code-completed a parameterized completion. For example, if they
* have just code-completed the C function "<code>fprintf</code>", when entering
* the file name, this popup might display all local variables of type
* "<code>char *</code>".
*
* @author Robert Futrell
* @version 1.0
@@ -60,22 +60,20 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
*/
private JScrollPane sp;
/**
* Comparator used to sort completions by their relevance before sorting
* them lexicographically.
* Comparator used to sort completions by their relevance before sorting them
* lexicographically.
*/
private static final Comparator<Completion> sortByRelevanceComparator = new SortByRelevanceComparator();
/**
* Constructor.
*
* @param parent
* The parent window (hosting the text component).
* @param ac
* The auto-completion instance.
* @param context
* The completion context.
* @param parent The parent window (hosting the text component).
* @param ac The auto-completion instance.
* @param context The completion context.
*/
public ParameterizedCompletionChoicesWindow(Window parent, AutoCompletion ac, final ParameterizedCompletionContext context) {
public ParameterizedCompletionChoicesWindow(Window parent, AutoCompletion ac,
final ParameterizedCompletionContext context) {
super(parent);
this.ac = ac;
ComponentOrientation o = ac.getTextComponentOrientation();
@@ -107,8 +105,7 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
/**
* Returns the selected value.
*
* @return The selected value, or <code>null</code> if nothing is
* selected.
* @return The selected value, or <code>null</code> if nothing is selected.
*/
public String getSelectedChoice() {
Completion c = (Completion) list.getSelectedValue();
@@ -118,8 +115,7 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
/**
* Changes the selected index.
*
* @param amount
* The amount by which to change the selected index.
* @param amount The amount by which to change the selected index.
*/
public void incSelection(int amount) {
int selection = list.getSelectedIndex();
@@ -135,12 +131,10 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
}
/**
* Initializes this window to offer suggestions for the parameters of
* a specific completion.
* Initializes this window to offer suggestions for the parameters of a specific
* completion.
*
* @param pc
* The completion whose parameters we should offer suggestions
* for.
* @param pc The completion whose parameters we should offer suggestions for.
*/
public void initialize(ParameterizedCompletion pc) {
CompletionProvider provider = pc.getProvider();
@@ -162,8 +156,7 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
/**
* Sets the location of this window relative to the given rectangle.
*
* @param r
* The visual position of the caret (in screen coordinates).
* @param r The visual position of the caret (in screen coordinates).
*/
public void setLocationRelativeTo(Rectangle r) {
// Multi-monitor support - make sure the completion window (and
@@ -189,16 +182,14 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
}
/**
* Displays the choices for the specified parameter matching the given
* text. This will display or hide this popup window as necessary.
* Displays the choices for the specified parameter matching the given text.
* This will display or hide this popup window as necessary.
*
* @param param
* The index of the parameter the caret is currently in.
* This may be <code>-1</code> if not in a parameter (i.e., on
* the comma between parameters).
* @param prefix
* Text in the parameter before the dot. This may
* be <code>null</code> to represent the empty string.
* @param param The index of the parameter the caret is currently in. This may
* be <code>-1</code> if not in a parameter (i.e., on the comma
* between parameters).
* @param prefix Text in the parameter before the dot. This may be
* <code>null</code> to represent the empty string.
*/
public void setParameter(int param, String prefix) {
model.clear();
@@ -254,8 +245,7 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
/**
* Toggles the visibility of this popup window.
*
* @param visible
* Whether this window should be visible.
* @param visible Whether this window should be visible.
*/
@Override
public void setVisible(boolean visible) {
@@ -48,8 +48,8 @@ import org.fife.ui.rtextarea.ChangeableHighlightPainter;
/**
* Manages UI and state specific to parameterized completions - the parameter
* description tool tip, the parameter completion choices list, the actual
* highlights in the editor, etc. This component installs new key bindings
* when appropriate to allow the user to cycle through the parameters of the
* highlights in the editor, etc. This component installs new key bindings when
* appropriate to allow the user to cycle through the parameters of the
* completion, and optionally cycle through completion choices for those
* parameters.
*
@@ -95,13 +95,13 @@ class ParameterizedCompletionContext {
*/
private Listener listener;
/**
* The minimum offset into the document that the caret can move to
* before this tool tip disappears.
* The minimum offset into the document that the caret can move to before this
* tool tip disappears.
*/
private int minPos;
/**
* The maximum offset into the document that the caret can move to
* before this tool tip disappears.
* The maximum offset into the document that the caret can move to before this
* tool tip disappears.
*/
private Position maxPos; // Moves with text inserted.
private Position defaultEndOffs;
@@ -208,8 +208,7 @@ class ParameterizedCompletionContext {
}
/**
* Hides any popup windows and terminates parameterized completion
* assistance.
* Hides any popup windows and terminates parameterized completion assistance.
*
* @see #activate()
*/
@@ -228,13 +227,11 @@ class ParameterizedCompletionContext {
}
/**
* Returns the text inserted for the parameter containing the specified
* offset.
* Returns the text inserted for the parameter containing the specified offset.
*
* @param offs
* The offset into the document.
* @return The text of the parameter containing the offset, or
* <code>null</code> if the offset is not in a parameter.
* @param offs The offset into the document.
* @return The text of the parameter containing the offset, or <code>null</code>
* if the offset is not in a parameter.
*/
public String getArgumentText(int offs) {
List<Highlight> paramHighlights = getParameterHighlights();
@@ -262,8 +259,8 @@ class ParameterizedCompletionContext {
/**
* Returns the highlight of the current parameter.
*
* @return The current parameter's highlight, or <code>null</code> if
* the caret is not in a parameter's bounds.
* @return The current parameter's highlight, or <code>null</code> if the caret
* is not in a parameter's bounds.
* @see #getCurrentParameterStartOffset()
*/
private Highlight getCurrentParameterHighlight() {
@@ -300,8 +297,8 @@ class ParameterizedCompletionContext {
/**
* Returns the starting offset of the current parameter.
*
* @return The current parameter's starting offset, or <code>-1</code> if
* the caret is not in a parameter's bounds.
* @return The current parameter's starting offset, or <code>-1</code> if the
* caret is not in a parameter's bounds.
* @see #getCurrentParameterHighlight()
*/
private int getCurrentParameterStartOffset() {
@@ -310,13 +307,12 @@ class ParameterizedCompletionContext {
}
/**
* Returns the highlight from a list that comes "first" in a list. Even
* though most parameter highlights are ordered, sometimes they aren't
* (e.g. the "cursor" parameter in a template completion is always last,
* even though it can be anywhere in the template).
* Returns the highlight from a list that comes "first" in a list. Even though
* most parameter highlights are ordered, sometimes they aren't (e.g. the
* "cursor" parameter in a template completion is always last, even though it
* can be anywhere in the template).
*
* @param highlights
* The list of highlights. Assumed to be non-empty.
* @param highlights The list of highlights. Assumed to be non-empty.
* @return The highlight that comes first in the document.
* @see #getLastHighlight(List)
*/
@@ -334,13 +330,12 @@ class ParameterizedCompletionContext {
}
/**
* Returns the highlight from a list that comes "last" in that list. Even
* though most parameter highlights are ordered, sometimes they aren't
* (e.g. the "cursor" parameter in a template completion is always last,
* even though it can be anywhere in the template.
* Returns the highlight from a list that comes "last" in that list. Even though
* most parameter highlights are ordered, sometimes they aren't (e.g. the
* "cursor" parameter in a template completion is always last, even though it
* can be anywhere in the template.
*
* @param highlights
* The list of highlights. Assumed to be non-empty.
* @param highlights The list of highlights. Assumed to be non-empty.
* @return The highlight that comes last in the document.
* @see #getFirstHighlight(List)
*/
@@ -373,8 +368,8 @@ class ParameterizedCompletionContext {
/**
* Inserts the choice selected in the parameter choices window.
*
* @return Whether the choice was inserted. This will be <code>false</code>
* if the window is not visible, or no choice is selected.
* @return Whether the choice was inserted. This will be <code>false</code> if
* the window is not visible, or no choice is selected.
*/
boolean insertSelectedChoice() {
if (paramChoicesWindow != null && paramChoicesWindow.isVisible()) {
@@ -398,8 +393,8 @@ class ParameterizedCompletionContext {
}
/**
* Installs key bindings on the text component that facilitate the user
* editing this completion's parameters.
* Installs key bindings on the text component that facilitate the user editing
* this completion's parameters.
*
* @see #uninstallKeyBindings()
*/
@@ -507,8 +502,8 @@ class ParameterizedCompletionContext {
List<Highlight> highlights = getParameterHighlights();
for (int i = 0; i < highlights.size(); i++) {
Highlight h = highlights.get(i);
if (currentPrev == null || currentPrev.getStartOffset() >= dot
|| (h.getStartOffset() < selStart && (h.getStartOffset() > currentPrev.getStartOffset() || pos == lastSelectedParam))) {
if (currentPrev == null || currentPrev.getStartOffset() >= dot || (h.getStartOffset() < selStart
&& (h.getStartOffset() > currentPrev.getStartOffset() || pos == lastSelectedParam))) {
currentPrev = h;
pos = i;
}
@@ -613,17 +608,14 @@ class ParameterizedCompletionContext {
}
/**
* Replaces highlighted text with new text. Takes special care so that
* the highlight stays just around the newly-highlighted text, since
* Swing's <code>Highlight</code> classes are funny about insertions at
* their start offsets.
* Replaces highlighted text with new text. Takes special care so that the
* highlight stays just around the newly-highlighted text, since Swing's
* <code>Highlight</code> classes are funny about insertions at their start
* offsets.
*
* @param doc
* The document.
* @param h
* The highlight whose text to change.
* @param replacement
* The new text to be in the highlight.
* @param doc The document.
* @param h The highlight whose text to change.
* @param replacement The new text to be in the highlight.
* @return The replacement highlight for <code>h</code>.
*/
private Highlight replaceHighlightedText(Document doc, Highlight h, String replacement) {
@@ -684,9 +676,8 @@ class ParameterizedCompletionContext {
}
/**
* Updates the text in the tool tip to have the current parameter
* displayed in bold. The "current parameter" is determined from the
* current caret position.
* Updates the text in the tool tip to have the current parameter displayed in
* bold. The "current parameter" is determined from the current caret position.
*
* @return The "prefix" of text in the caret's parameter before the caret.
*/
@@ -779,8 +770,8 @@ class ParameterizedCompletionContext {
}
/**
* Called when the user types the character marking the closing of the
* parameter list, such as '<code>)</code>'.
* Called when the user types the character marking the closing of the parameter
* list, such as '<code>)</code>'.
*/
private class ClosingAction extends AbstractAction {
@@ -846,8 +837,8 @@ class ParameterizedCompletionContext {
}
/**
* Listens for various events in the text component while this tool tip
* is visible.
* Listens for various events in the text component while this tool tip is
* visible.
*/
private class Listener implements FocusListener, CaretListener, DocumentListener {
@@ -856,8 +847,7 @@ class ParameterizedCompletionContext {
/**
* Called when the text component's caret moves.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void caretUpdate(CaretEvent e) {
@@ -877,13 +867,13 @@ class ParameterizedCompletionContext {
}
@Override
public void changedUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {
}
/**
* Called when the text component gains focus.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void focusGained(FocusEvent e) {
@@ -893,8 +883,7 @@ class ParameterizedCompletionContext {
/**
* Called when the text component loses focus.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void focusLost(FocusEvent e) {
@@ -923,8 +912,7 @@ class ParameterizedCompletionContext {
/**
* Installs this listener onto a text component.
*
* @param tc
* The text component to install onto.
* @param tc The text component to install onto.
* @see #uninstall()
*/
public void install(JTextComponent tc) {
@@ -950,7 +938,8 @@ class ParameterizedCompletionContext {
}
for (int i = 0; i < info.getReplacementCopyCount(); i++) {
ReplacementCopy rc = info.getReplacementCopy(i);
paramCopyInfos.add(new ParamCopyInfo(rc.getId(), (Highlight) h.addHighlight(rc.getStart(), rc.getEnd(), paramCopyP)));
paramCopyInfos.add(new ParamCopyInfo(rc.getId(),
(Highlight) h.addHighlight(rc.getStart(), rc.getEnd(), paramCopyP)));
}
// Go back and start at the first parameter.
tc.setCaretPosition(info.getSelectionStart());
@@ -1007,8 +996,8 @@ class ParameterizedCompletionContext {
}
/**
* Action performed when the user presses the up or down arrow keys and
* the parameter completion choices popup is visible.
* Action performed when the user presses the up or down arrow keys and the
* parameter completion choices popup is visible.
*/
private class NextChoiceAction extends AbstractAction {
@@ -45,19 +45,17 @@ class ParameterizedCompletionDescriptionToolTip {
/**
* Constructor.
*
* @param owner
* The parent window.
* @param ac
* The parent auto-completion.
* @param pc
* The completion being described.
* @param owner The parent window.
* @param ac The parent auto-completion.
* @param pc The completion being described.
*/
public ParameterizedCompletionDescriptionToolTip(Window owner, ParameterizedCompletionContext context, AutoCompletion ac,
ParameterizedCompletion pc) {
public ParameterizedCompletionDescriptionToolTip(Window owner, ParameterizedCompletionContext context,
AutoCompletion ac, ParameterizedCompletion pc) {
tooltip = new JWindow(owner);
this.pc = pc;
descLabel = new JLabel();
descLabel.setBorder(BorderFactory.createCompoundBorder(TipUtil.getToolTipBorder(), BorderFactory.createEmptyBorder(2, 5, 2, 5)));
descLabel.setBorder(BorderFactory.createCompoundBorder(TipUtil.getToolTipBorder(),
BorderFactory.createEmptyBorder(2, 5, 2, 5)));
descLabel.setOpaque(true);
descLabel.setBackground(TipUtil.getToolTipBackground());
// It appears that if a JLabel is set as a content pane directly, when
@@ -91,8 +89,7 @@ class ParameterizedCompletionDescriptionToolTip {
/**
* Sets the location of this tool tip relative to the given rectangle.
*
* @param r
* The visual position of the caret (in screen coordinates).
* @param r The visual position of the caret (in screen coordinates).
*/
public void setLocationRelativeTo(Rectangle r) {
// Multi-monitor support - make sure the completion window (and
@@ -123,8 +120,7 @@ class ParameterizedCompletionDescriptionToolTip {
/**
* Toggles the visibility of this tool tip.
*
* @param visible
* Whether this tool tip should be visible.
* @param visible Whether this tool tip should be visible.
* @see #isVisible()
*/
public void setVisible(boolean visible) {
@@ -132,11 +128,10 @@ class ParameterizedCompletionDescriptionToolTip {
}
/**
* Updates the text in the tool tip to have the current parameter
* displayed in bold.
* Updates the text in the tool tip to have the current parameter displayed in
* bold.
*
* @param selectedParam
* The index of the selected parameter.
* @param selectedParam The index of the selected parameter.
* @return Whether the text needed to be updated.
*/
public boolean updateText(int selectedParam) {
@@ -172,8 +167,7 @@ class ParameterizedCompletionDescriptionToolTip {
}
/**
* Updates the <tt>LookAndFeel</tt> of this window and the description
* window.
* Updates the <tt>LookAndFeel</tt> of this window and the description window.
*/
public void updateUI() {
SwingUtilities.updateComponentTreeUI(tooltip);
@@ -44,13 +44,11 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Marks a region of the replacement text as representing a variable name
* or some other construct that the user should replace.
* Marks a region of the replacement text as representing a variable name or
* some other construct that the user should replace.
*
* @param start
* The start offset.
* @param end
* The end offset.
* @param start The start offset.
* @param end The end offset.
* @see #getReplacementCount()
* @see #getReplacementLocation(int)
*/
@@ -66,8 +64,8 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Returns the maximum offset the caret can move to before being outside
* of the text inserted for this completion.
* Returns the maximum offset the caret can move to before being outside of the
* text inserted for this completion.
*
* @return The maximum offset.
* @see #getMinOffset()
@@ -77,8 +75,8 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Returns the minimum offset the caret can move to before being outside
* of the text inserted for this completion.
* Returns the minimum offset the caret can move to before being outside of the
* text inserted for this completion.
*
* @return The minimum offset.
* @see #getMaxOffset()
@@ -105,11 +103,10 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Returns the starting- and ending-offsets of the replacement regions
* in the completion.
* Returns the starting- and ending-offsets of the replacement regions in the
* completion.
*
* @param index
* The replacement region.
* @param index The replacement region.
* @return The range in the document of that replacement region.
* @see #getReplacementCount()
*/
@@ -118,9 +115,9 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Returns the offset that should be the end of the initially selected
* text when the completion is inserted (i.e., the end offset of the first
* replacement region).
* Returns the offset that should be the end of the initially selected text when
* the completion is inserted (i.e., the end offset of the first replacement
* region).
*
* @return The end offset for the initial selection.
* @see #getSelectionStart()
@@ -130,9 +127,9 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Returns the offset that should be the start of the initially selected
* text when the completion is inserted (i.e., the start offset of the
* first replacement region).
* Returns the offset that should be the start of the initially selected text
* when the completion is inserted (i.e., the start offset of the first
* replacement region).
*
* @return The start offset for the initial selection.
* @see #getSelectionEnd()
@@ -152,8 +149,8 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Returns whether or not there is an initial selected region for the
* completion (i.e., whether the completion actually has any parameters).
* Returns whether or not there is an initial selected region for the completion
* (i.e., whether the completion actually has any parameters).
*
* @return Whether there is a region to initially select for the completion.
*/
@@ -164,10 +161,8 @@ class ParameterizedCompletionInsertionInfo {
/**
* Sets the initially selected region for the completion.
*
* @param selStart
* The selection start.
* @param selEnd
* The selection end.
* @param selStart The selection start.
* @param selEnd The selection end.
* @see #getSelectionEnd()
* @see #getSelectionStart()
*/
@@ -177,13 +172,11 @@ class ParameterizedCompletionInsertionInfo {
}
/**
* Sets the document range the caret can move around in before being
* outside of the text inserted for the completion.
* Sets the document range the caret can move around in before being outside of
* the text inserted for the completion.
*
* @param minOffs
* The minimum offset.
* @param maxOffs
* The maximum offset, that will track its location as the
* @param minOffs The minimum offset.
* @param maxOffs The maximum offset, that will track its location as the
* document is modified.
* @see #getMinOffset()
* @see #getMaxOffset()
@@ -200,8 +193,7 @@ class ParameterizedCompletionInsertionInfo {
/**
* Sets the text to insert for the completion.
*
* @param text
* The text to insert.
* @param text The text to insert.
* @see #getTextToInsert()
*/
public void setTextToInsert(String text) {
@@ -14,8 +14,8 @@ import javax.swing.Action;
/**
* An <code>AutoCompletion</code> that adds the ability to cycle through a set
* of <code>CompletionProvider</code>s via the trigger key. This allows the
* application to logically "group together" completions of similar kinds;
* for example, Java code completions vs. template completions.
* application to logically "group together" completions of similar kinds; for
* example, Java code completions vs. template completions.
* <p>
*
* Usage:
@@ -40,8 +40,7 @@ public class RoundRobinAutoCompletion extends AutoCompletion {
/**
* Constructor.
*
* @param provider
* A single completion provider.
* @param provider A single completion provider.
* @see #addCompletionProvider(CompletionProvider)
*/
public RoundRobinAutoCompletion(CompletionProvider provider) {
@@ -60,23 +59,22 @@ public class RoundRobinAutoCompletion extends AutoCompletion {
}
/**
* Adds an additional <code>CompletionProvider</code> to the list to
* cycle through.
* Adds an additional <code>CompletionProvider</code> to the list to cycle
* through.
*
* @param provider
* The new completion provider.
* @param provider The new completion provider.
*/
public void addCompletionProvider(CompletionProvider provider) {
cycle.add(provider);
}
/**
* Moves to the next Provider internally. Needs refresh of the popup window
* to display the changes.
* Moves to the next Provider internally. Needs refresh of the popup window to
* display the changes.
*
* @return true if the next provider was the default one (thus returned to
* the default view). May be used in case you like to hide the
* popup in this case.
* @return true if the next provider was the default one (thus returned to the
* default view). May be used in case you like to hide the popup in this
* case.
*/
public boolean advanceProvider() {
CompletionProvider currentProvider = getCompletionProvider();
@@ -106,8 +104,8 @@ public class RoundRobinAutoCompletion extends AutoCompletion {
/**
* An implementation of the auto-complete action that ensures the proper
* <code>CompletionProvider</code> is displayed based on the context in
* which the user presses the trigger key.
* <code>CompletionProvider</code> is displayed based on the context in which
* the user presses the trigger key.
*/
private class CycleAutoCompleteAction extends AutoCompleteAction {
@@ -26,12 +26,9 @@ public class ShorthandCompletion extends BasicCompletion {
/**
* Constructor.
*
* @param provider
* The provider that returns this completion.
* @param inputText
* The text the user inputs to get this completion.
* @param replacementText
* The replacement text of the completion.
* @param provider The provider that returns this completion.
* @param inputText The text the user inputs to get this completion.
* @param replacementText The replacement text of the completion.
*/
public ShorthandCompletion(CompletionProvider provider, String inputText, String replacementText) {
super(provider, replacementText);
@@ -41,18 +38,15 @@ public class ShorthandCompletion extends BasicCompletion {
/**
* Constructor.
*
* @param provider
* The provider that returns this completion.
* @param inputText
* The text the user inputs to get this completion.
* @param replacementText
* The replacement text of the completion.
* @param shortDesc
* A short description of the completion. This will be
* @param provider The provider that returns this completion.
* @param inputText The text the user inputs to get this completion.
* @param replacementText The replacement text of the completion.
* @param shortDesc A short description of the completion. This will be
* displayed in the completion list. This may be
* <code>null</code>.
*/
public ShorthandCompletion(CompletionProvider provider, String inputText, String replacementText, String shortDesc) {
public ShorthandCompletion(CompletionProvider provider, String inputText, String replacementText,
String shortDesc) {
super(provider, replacementText, shortDesc);
this.inputText = inputText;
}
@@ -60,21 +54,17 @@ public class ShorthandCompletion extends BasicCompletion {
/**
* Constructor.
*
* @param provider
* The provider that returns this completion.
* @param inputText
* The text the user inputs to get this completion.
* @param replacementText
* The replacement text of the completion.
* @param shortDesc
* A short description of the completion. This will be
* @param provider The provider that returns this completion.
* @param inputText The text the user inputs to get this completion.
* @param replacementText The replacement text of the completion.
* @param shortDesc A short description of the completion. This will be
* displayed in the completion list. This may be
* <code>null</code>.
* @param summary
* The summary of this completion. This should be HTML.
* @param summary The summary of this completion. This should be HTML.
* This may be <code>null</code>.
*/
public ShorthandCompletion(CompletionProvider provider, String inputText, String replacementText, String shortDesc, String summary) {
public ShorthandCompletion(CompletionProvider provider, String inputText, String replacementText, String shortDesc,
String summary) {
super(provider, replacementText, shortDesc, summary);
this.inputText = inputText;
}
@@ -93,8 +83,7 @@ public class ShorthandCompletion extends BasicCompletion {
* If a summary has been set, that summary is returned. Otherwise, the
* replacement text is returned.
*
* @return A description of this completion (the text that will be
* inserted).
* @return A description of this completion (the text that will be inserted).
* @see #getReplacementText()
*/
@Override
@@ -104,9 +93,9 @@ public class ShorthandCompletion extends BasicCompletion {
}
/**
* Returns the "body" of the HTML returned by {@link #getSummary()} when
* no summary text has been set. This is defined to return the replacement
* text in a monospaced font.
* Returns the "body" of the HTML returned by {@link #getSummary()} when no
* summary text has been set. This is defined to return the replacement text in
* a monospaced font.
*
* @return The summary text's body, if no other summary has been defined.
* @see #getReplacementText()
+9 -12
View File
@@ -51,11 +51,10 @@ class SizeGrip extends JPanel {
}
/**
* Overridden to ensure that the cursor for this component is appropriate
* for the orientation.
* Overridden to ensure that the cursor for this component is appropriate for
* the orientation.
*
* @param o
* The new orientation.
* @param o The new orientation.
*/
@Override
public void applyComponentOrientation(ComponentOrientation o) {
@@ -98,8 +97,7 @@ class SizeGrip extends JPanel {
/**
* Paints this panel.
*
* @param g
* The graphics context.
* @param g The graphics context.
*/
@Override
protected void paintComponent(Graphics g) {
@@ -152,8 +150,7 @@ class SizeGrip extends JPanel {
* Ensures that the cursor for this component is appropriate for the
* orientation.
*
* @param ltr
* Whether the current component orientation is LTR.
* @param ltr Whether the current component orientation is LTR.
*/
protected void possiblyFixCursor(boolean ltr) {
int cursor = Cursor.NE_RESIZE_CURSOR;
@@ -184,10 +181,10 @@ class SizeGrip extends JPanel {
* appropriately.
*/
/*
* NOTE: We use SwingUtilities.convertPointToScreen() instead of just using
* the locations relative to the corner component because the latter proved
* buggy - stretch the window too wide and some kind of arithmetic error
* started happening somewhere - our window would grow way too large.
* NOTE: We use SwingUtilities.convertPointToScreen() instead of just using the
* locations relative to the corner component because the latter proved buggy -
* stretch the window too wide and some kind of arithmetic error started
* happening somewhere - our window would grow way too large.
*/
private class MouseHandler extends MouseInputAdapter {
@@ -10,8 +10,8 @@ package org.fife.ui.autocomplete;
import java.util.Comparator;
/**
* Compares two <code>Completion</code>s by their relevance before
* sorting them lexicographically.
* Compares two <code>Completion</code>s by their relevance before sorting them
* lexicographically.
*
* @author Robert Futrell
* @version 1.0
@@ -37,12 +37,12 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
* }
* </pre>
*
* In the above example, the first <code>${i}</code> is a parameter for the
* user to type into; all the other <code>${i}</code> instances are
* automatically changed to what the user types in the first one. The parameter
* named <code>${cursor}</code> is the "ending position" of the template. It's
* where the caret moves after it cycles through all other parameters. If the
* user types into it, template mode terminates. If more than one
* In the above example, the first <code>${i}</code> is a parameter for the user
* to type into; all the other <code>${i}</code> instances are automatically
* changed to what the user types in the first one. The parameter named
* <code>${cursor}</code> is the "ending position" of the template. It's where
* the caret moves after it cycles through all other parameters. If the user
* types into it, template mode terminates. If more than one
* <code>${cursor}</code> parameter is specified, behavior is undefined.
* <p>
*
@@ -51,8 +51,8 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
* fault-tolerant.
* <p>
*
* Leading whitespace is automatically added to lines if the template spans
* more than one line, and if used with a text component using a
* Leading whitespace is automatically added to lines if the template spans more
* than one line, and if used with a text component using a
* <code>PlainDocument</code>, tabs will be converted to spaces if requested.
*
* @author Robert Futrell
@@ -110,8 +110,8 @@ public class TemplateCompletion extends AbstractCompletion implements Parameteri
}
/**
* Returns <code>null</code>; template completions insert all of their
* text via <code>getInsertionInfo()</code>.
* Returns <code>null</code>; template completions insert all of their text via
* <code>getInsertionInfo()</code>.
*
* @return <code>null</code> always.
*/
@@ -234,8 +234,7 @@ public class TemplateCompletion extends AbstractCompletion implements Parameteri
/**
* Returns whether a parameter is already defined with a specific name.
*
* @param name
* The name.
* @param name The name.
* @return Whether a parameter is defined with that name.
*/
private boolean isParamDefined(String name) {
@@ -251,8 +250,7 @@ public class TemplateCompletion extends AbstractCompletion implements Parameteri
/**
* Parses a template string into logical pieces used by this class.
*
* @param template
* The template to parse.
* @param template The template to parse.
*/
private void parse(String template) {
int offs = 0;
@@ -319,8 +317,7 @@ public class TemplateCompletion extends AbstractCompletion implements Parameteri
/**
* Sets the short description of this template completion.
*
* @param shortDesc
* The new short description.
* @param shortDesc The new short description.
* @see #getShortDescription()
*/
public void setShortDescription(String shortDesc) {
@@ -7,8 +7,8 @@
package org.fife.ui.autocomplete;
/**
* A piece of a <code>TemplateCompletion</code>. You add instances of this
* class to template completions to define them.
* A piece of a <code>TemplateCompletion</code>. You add instances of this class
* to template completions to define them.
*
* @author Robert Futrell
* @version 1.0
+17 -18
View File
@@ -22,16 +22,17 @@ import javax.swing.text.html.HTMLDocument;
* Static utility methods for homemade tool tips.
* <p>
*
* This is blatantly ripped off from RSyntaxTextArea's "FocusableTips" class
* of the same name, but isn't re-used to prevent a hard dependency on the
* RSTA library.
* This is blatantly ripped off from RSyntaxTextArea's "FocusableTips" class of
* the same name, but isn't re-used to prevent a hard dependency on the RSTA
* library.
*
* @author Robert Futrell
* @version 1.0
*/
class TipUtil {
private TipUtil() {}
private TipUtil() {
}
/**
* Returns the default background color to use for tool tip windows.
@@ -73,17 +74,16 @@ class TipUtil {
}
/**
* Returns whether a color is a Nimbus DerivedColor, which is troublesome
* in that it doesn't use its RGB values (uses HSB instead?) and so
* querying them is useless.
* Returns whether a color is a Nimbus DerivedColor, which is troublesome in
* that it doesn't use its RGB values (uses HSB instead?) and so querying them
* is useless.
*
* @param c
* The color to check.
* @param c The color to check.
* @return Whether it is a DerivedColor
*/
private static final boolean isDerivedColor(Color c) {
return c != null
&& (c.getClass().getName().endsWith(".DerivedColor") || c.getClass().getName().endsWith(".DerivedColor$UIResource"));
return c != null && (c.getClass().getName().endsWith(".DerivedColor")
|| c.getClass().getName().endsWith(".DerivedColor$UIResource"));
}
/**
@@ -96,12 +96,11 @@ class TipUtil {
}
/**
* Tweaks a <code>JEditorPane</code> so it can be used to render the
* content in a focusable pseudo-tool tip. It is assumed that the editor
* pane is using an <code>HTMLDocument</code>.
* Tweaks a <code>JEditorPane</code> so it can be used to render the content in
* a focusable pseudo-tool tip. It is assumed that the editor pane is using an
* <code>HTMLDocument</code>.
*
* @param textArea
* The editor pane to tweak.
* @param textArea The editor pane to tweak.
*/
public static void tweakTipEditorPane(JEditorPane textArea) {
// Jump through a few hoops to get things looking nice in Nimbus
@@ -134,8 +133,8 @@ class TipUtil {
font = new Font("SansSerif", Font.PLAIN, 12);
}
HTMLDocument doc = (HTMLDocument) textArea.getDocument();
doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt" + "; color: "
+ Util.getHexString(fg) + "; }");
doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt"
+ "; color: " + Util.getHexString(fg) + "; }");
// Always add link foreground rule. Unfortunately these CSS rules
// stack each time the LaF is changed (how can we overwrite them
// without clearing out the important "standard" ones?).
+47 -55
View File
@@ -30,29 +30,29 @@ import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
public class Util {
/**
* If a system property is defined with this name and set, ignoring case,
* to <code>true</code>, this library will not attempt to use Substance
* renderers. Otherwise, if a Substance Look and Feel is installed, we
* will attempt to use Substance cell renderers in all of our dropdowns.
* If a system property is defined with this name and set, ignoring case, to
* <code>true</code>, this library will not attempt to use Substance renderers.
* Otherwise, if a Substance Look and Feel is installed, we will attempt to use
* Substance cell renderers in all of our dropdowns.
* <p>
*
* Note that we do not have a build dependency on Substance, so all access
* to Substance stuff is done via reflection. We will fall back onto
* default renderers if something goes horribly wrong.
* Note that we do not have a build dependency on Substance, so all access to
* Substance stuff is done via reflection. We will fall back onto default
* renderers if something goes horribly wrong.
*/
public static final String PROPERTY_DONT_USE_SUBSTANCE_RENDERERS = "org.fife.ui.autocomplete.DontUseSubstanceRenderers";
/**
* If this system property is <code>true</code>, then even the "main" two
* auto-complete windows will allow window decorations via
* {@link PopupWindowDecorator}. If this property is undefined or
* <code>false</code>, they won't honor such decorations. This is due to
* certain performance issues with translucent windows (used for drop
* shadows), even as of Java 7u2.
* <code>false</code>, they won't honor such decorations. This is due to certain
* performance issues with translucent windows (used for drop shadows), even as
* of Java 7u2.
*/
public static final String PROPERTY_ALLOW_DECORATED_AUTOCOMPLETE_WINDOWS = "org.fife.ui.autocomplete.allowDecoratedAutoCompleteWindows";
/**
* Used for the color of hyperlinks when a LookAndFeel uses light text
* against a dark background.
* Used for the color of hyperlinks when a LookAndFeel uses light text against a
* dark background.
*/
private static final Color LIGHT_HYPERLINK_FG = new Color(0xd8ffff);
private static final Pattern TAG_PATTERN = Pattern.compile("<[^>]*>");
@@ -64,11 +64,10 @@ public class Util {
/**
* Attempts to open a web browser to the specified URI.
*
* @param uri
* The URI to open. If this is <code>null</code>, nothing
* happens and this method returns <code>false</code>.
* @return Whether the operation was successful. This will be
* <code>false</code> on JRE's older than 1.6.
* @param uri The URI to open. If this is <code>null</code>, nothing happens and
* this method returns <code>false</code>.
* @return Whether the operation was successful. This will be <code>false</code>
* on JRE's older than 1.6.
*/
public static boolean browse(URI uri) {
boolean success = false;
@@ -91,8 +90,8 @@ public class Util {
/**
* Returns the singleton <code>java.awt.Desktop</code> instance, or
* <code>null</code> if it is unsupported on this platform (or the JRE
* is older than 1.6).
* <code>null</code> if it is unsupported on this platform (or the JRE is older
* than 1.6).
*
* @return The desktop, as an {@link Object}.
*/
@@ -121,10 +120,9 @@ public class Util {
/**
* Returns a hex string for the specified color, suitable for HTML.
*
* @param c
* The color.
* @return The string representation, in the form "<code>#rrggbb</code>",
* or <code>null</code> if <code>c</code> is <code>null</code>.
* @param c The color.
* @return The string representation, in the form "<code>#rrggbb</code>", or
* <code>null</code> if <code>c</code> is <code>null</code>.
*/
public static String getHexString(Color c) {
if (c == null) {
@@ -152,10 +150,10 @@ public class Util {
}
/**
* Returns the color to use for hyperlink-style components. This method
* will return <code>Color.blue</code> unless it appears that the current
* LookAndFeel uses light text on a dark background, in which case a
* brighter alternative is returned.
* Returns the color to use for hyperlink-style components. This method will
* return <code>Color.blue</code> unless it appears that the current LookAndFeel
* uses light text on a dark background, in which case a brighter alternative is
* returned.
*
* @return The color to use for hyperlinks.
*/
@@ -170,14 +168,12 @@ public class Util {
}
/**
* Returns the screen coordinates for the monitor that contains the
* specified point. This is useful for setups with multiple monitors,
* to ensure that popup windows are positioned properly.
* Returns the screen coordinates for the monitor that contains the specified
* point. This is useful for setups with multiple monitors, to ensure that popup
* windows are positioned properly.
*
* @param x
* The x-coordinate, in screen coordinates.
* @param y
* The y-coordinate, in screen coordinates.
* @param x The x-coordinate, in screen coordinates.
* @param y The y-coordinate, in screen coordinates.
* @return The bounds of the monitor that contains the specified point.
*/
public static Rectangle getScreenBoundsForPoint(int x, int y) {
@@ -195,10 +191,10 @@ public class Util {
}
/**
* Give apps a chance to decorate us with drop shadows, etc. Since very
* scrolly things such as lists (of e.g. completions) are *very* slow when
* in per-pixel translucent windows, even as of Java 7u2, we force the user
* to specify an extra option for the two "main" auto-complete windows.
* Give apps a chance to decorate us with drop shadows, etc. Since very scrolly
* things such as lists (of e.g. completions) are *very* slow when in per-pixel
* translucent windows, even as of Java 7u2, we force the user to specify an
* extra option for the two "main" auto-complete windows.
*
* @return Whether to allow decorating the main auto-complete windows.
* @see #PROPERTY_ALLOW_DECORATED_AUTOCOMPLETE_WINDOWS
@@ -212,10 +208,10 @@ public class Util {
}
/**
* Returns whether we should attempt to use Substance cell renderers and
* styles for things such as completion choices, if a Substance Look and
* Feel is installed. If this is <code>false</code>, we'll use our
* standard rendering for completions, even when Substance is being used.
* Returns whether we should attempt to use Substance cell renderers and styles
* for things such as completion choices, if a Substance Look and Feel is
* installed. If this is <code>false</code>, we'll use our standard rendering
* for completions, even when Substance is being used.
*
* @return Whether to use Substance renderers if Substance is installed.
*/
@@ -224,12 +220,11 @@ public class Util {
}
/**
* Returns whether the specified color is "light" to use as a foreground.
* Colors that return <code>true</code> indicate that the current Look and
* Feel probably uses light text colors on a dark background.
* Returns whether the specified color is "light" to use as a foreground. Colors
* that return <code>true</code> indicate that the current Look and Feel
* probably uses light text colors on a dark background.
*
* @param fg
* The foreground color.
* @param fg The foreground color.
* @return Whether it is a "light" foreground color.
*/
public static final boolean isLightForeground(Color fg) {
@@ -237,13 +232,11 @@ public class Util {
}
/**
* Returns whether a string starts with a specified prefix, ignoring case.
* This method does not support characters outside of the BMP.
* Returns whether a string starts with a specified prefix, ignoring case. This
* method does not support characters outside of the BMP.
*
* @param str
* The string to check. This cannot be {@code null}.
* @param prefix
* The prefix to check for. This cannot be {@code null}.
* @param str The string to check. This cannot be {@code null}.
* @param prefix The prefix to check for. This cannot be {@code null}.
* @return Whether {@code str} starts with {@code prefix}, ignoring case.
*/
public static boolean startsWithIgnoreCase(String str, String prefix) {
@@ -258,8 +251,7 @@ public class Util {
* Strips any HTML from a string. The string must start with
* "<code>&lt;html&gt;</code>" for markup tags to be stripped.
*
* @param text
* The string.
* @param text The string.
* @return The string, with any HTML stripped.
*/
public static String stripHtml(String text) {
@@ -13,10 +13,10 @@ import javax.swing.text.JTextComponent;
* <p>
*
* This completion type uses its <tt>shortDescription</tt> property as part of
* its summary returned by {@link #getSummary()}; for this reason, it may be
* a little longer (even much longer), if desired, than what is recommended
* for <tt>BasicCompletion</tt>s (where the <tt>shortDescription</tt> is used
* in {@link #toString()} for <tt>ListCellRenderers</tt>).
* its summary returned by {@link #getSummary()}; for this reason, it may be a
* little longer (even much longer), if desired, than what is recommended for
* <tt>BasicCompletion</tt>s (where the <tt>shortDescription</tt> is used in
* {@link #toString()} for <tt>ListCellRenderers</tt>).
*
* @author Robert Futrell
* @version 1.0
@@ -35,12 +35,9 @@ public class VariableCompletion extends BasicCompletion {
/**
* Constructor.
*
* @param provider
* The parent provider.
* @param name
* The name of this variable.
* @param type
* The type of this variable (e.g. "<code>int</code>",
* @param provider The parent provider.
* @param name The name of this variable.
* @param type The type of this variable (e.g. "<code>int</code>",
* "<code>String</code>", etc.).
*/
public VariableCompletion(CompletionProvider provider, String name, String type) {
@@ -95,21 +92,17 @@ public class VariableCompletion extends BasicCompletion {
}
/**
* Returns the tool tip text to display for mouse hovers over this
* completion.
* Returns the tool tip text to display for mouse hovers over this completion.
* <p>
*
* Note that for this functionality to be enabled, a
* <tt>JTextComponent</tt> must be registered with the
* <tt>ToolTipManager</tt>, and the text component must know to search
* for this value. In the case of an
* <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this
* can be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that
* calls into
* Note that for this functionality to be enabled, a <tt>JTextComponent</tt>
* must be registered with the <tt>ToolTipManager</tt>, and the text component
* must know to search for this value. In the case of an
* <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this can
* be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that calls into
* {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}.
*
* @return The tool tip text for this completion, or <code>null</code> if
* none.
* @return The tool tip text for this completion, or <code>null</code> if none.
*/
@Override
public String getToolTipText() {
@@ -126,11 +119,10 @@ public class VariableCompletion extends BasicCompletion {
}
/**
* Adds some HTML describing where this variable is defined, if this
* information is known.
* Adds some HTML describing where this variable is defined, if this information
* is known.
*
* @param sb
* The buffer to append to.
* @param sb The buffer to append to.
*/
protected void possiblyAddDefinedIn(StringBuilder sb) {
if (definedIn != null) {
@@ -140,11 +132,9 @@ public class VariableCompletion extends BasicCompletion {
}
/**
* Adds the description text as HTML to a buffer, if a description is
* defined.
* Adds the description text as HTML to a buffer, if a description is defined.
*
* @param sb
* The buffer to append to.
* @param sb The buffer to append to.
* @return Whether there was a description to add.
*/
protected boolean possiblyAddDescription(StringBuilder sb) {
@@ -160,8 +150,7 @@ public class VariableCompletion extends BasicCompletion {
/**
* Sets where this variable is defined.
*
* @param definedIn
* Where this variable is defined.
* @param definedIn Where this variable is defined.
* @see #getDefinedIn()
*/
public void setDefinedIn(String definedIn) {
@@ -39,9 +39,9 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
/**
* Creates and returns the action to use when the user inserts a newline.
* The default implementation intelligently closes multi-line comments.
* Subclasses can override.
* Creates and returns the action to use when the user inserts a newline. The
* default implementation intelligently closes multi-line comments. Subclasses
* can override.
*
* @return The action.
* @see #getInsertBreakAction()
@@ -51,8 +51,8 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
/**
* Returns <code>true</code> always as C-style languages use curly braces
* to denote code blocks.
* Returns <code>true</code> always as C-style languages use curly braces to
* denote code blocks.
*
* @return <code>true</code> always.
*/
@@ -62,9 +62,8 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
/**
* Returns an action to handle "insert break" key presses (i.e. Enter).
* An action is returned that handles newlines differently in multi-line
* comments.
* Returns an action to handle "insert break" key presses (i.e. Enter). An
* action is returned that handles newlines differently in multi-line comments.
*
* @return The action.
*/
@@ -94,17 +93,15 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
/**
* Returns whether a given token is an internal token type that represents
* an MLC or documentation comment continuing on to the next line. This is
* done by languages such as JavaScript that are a little more verbose
* than necessary so that their code can be copy-and-pasted into other
* <code>TokenMaker</code>s that use them as nested languages (such as
* HTML, JSP, etc.).
* Returns whether a given token is an internal token type that represents an
* MLC or documentation comment continuing on to the next line. This is done by
* languages such as JavaScript that are a little more verbose than necessary so
* that their code can be copy-and-pasted into other <code>TokenMaker</code>s
* that use them as nested languages (such as HTML, JSP, etc.).
*
* @param t
* The token to check. This cannot be <code>null</code>.
* @return Whether the token is an internal token representing the end of
* a line for an MLC/doc comment continuing on to the next line.
* @param t The token to check. This cannot be <code>null</code>.
* @return Whether the token is an internal token representing the end of a line
* for an MLC/doc comment continuing on to the next line.
*/
private boolean isInternalEolTokenForMLCs(Token t) {
int type = t.getType();
@@ -116,8 +113,8 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
/**
* Action that knows how to special-case inserting a newline in a
* multi-line comment for languages like C and Java.
* Action that knows how to special-case inserting a newline in a multi-line
* comment for languages like C and Java.
*/
protected class CStyleInsertBreakAction extends RSyntaxTextAreaEditorKit.InsertBreakAction {
@@ -143,11 +140,10 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
/**
* Returns whether the MLC token containing <code>offs</code> appears
* to have a "nested" comment (i.e., contains "<code>/*</code>"
* somewhere inside of it). This implies that it is likely a "new" MLC
* and needs to be closed. While not foolproof, this is usually good
* enough of a sign.
* Returns whether the MLC token containing <code>offs</code> appears to have a
* "nested" comment (i.e., contains "<code>/*</code>" somewhere inside of it).
* This implies that it is likely a "new" MLC and needs to be closed. While not
* foolproof, this is usually good enough of a sign.
*
* @param textArea
* @param line
@@ -11,8 +11,8 @@ import javax.swing.text.Segment;
/**
* Base class for JFlex-generated token makers. This class attempts to factor
* out all common code from these classes. Many methods <em>almost</em> could
* be factored out into this class, but cannot because they reference JFlex
* out all common code from these classes. Many methods <em>almost</em> could be
* factored out into this class, but cannot because they reference JFlex
* variables that we cannot access from this class.
*
* @author Robert Futrell
@@ -28,18 +28,15 @@ public abstract class AbstractJFlexTokenMaker extends TokenMakerBase {
/**
* Declared here so we can define overloads that refer to this method.
*
* @param newState
* The new JFlex state to enter.
* @param newState The new JFlex state to enter.
*/
public abstract void yybegin(int newState);
/**
* Starts a new JFlex state and changes the current language index.
*
* @param state
* The new JFlex state to enter.
* @param languageIndex
* The new language index.
* @param state The new JFlex state to enter.
* @param languageIndex The new language index.
*/
protected void yybegin(int state, int languageIndex) {
yybegin(state);
@@ -8,9 +8,9 @@ package org.fife.ui.rsyntaxtextarea;
/**
* An abstract implementation of the
* {@link org.fife.ui.rsyntaxtextarea.TokenMaker} interface. It should
* be overridden for every language for which you want to provide
* syntax highlighting.
* {@link org.fife.ui.rsyntaxtextarea.TokenMaker} interface. It should be
* overridden for every language for which you want to provide syntax
* highlighting.
* <p>
*
* @see Token
@@ -21,10 +21,9 @@ package org.fife.ui.rsyntaxtextarea;
public abstract class AbstractTokenMaker extends TokenMakerBase {
/**
* Hash table of words to highlight and what token type they are.
* The keys are the words to highlight, and their values are the
* token types, for example, <code>Token.RESERVED_WORD</code> or
* <code>Token.FUNCTION</code>.
* Hash table of words to highlight and what token type they are. The keys are
* the words to highlight, and their values are the token types, for example,
* <code>Token.RESERVED_WORD</code> or <code>Token.FUNCTION</code>.
*/
protected TokenMap wordsToHighlight;
@@ -38,15 +37,15 @@ public abstract class AbstractTokenMaker extends TokenMakerBase {
/**
* Returns the words to highlight for this programming language.
*
* @return A <code>TokenMap</code> containing the words to highlight for
* this programming language.
* @return A <code>TokenMap</code> containing the words to highlight for this
* programming language.
*/
public abstract TokenMap getWordsToHighlight();
/**
* Removes the token last added from the linked list of tokens. The
* programmer should never have to call this directly; it can be called
* by subclasses of <code>TokenMaker</code> if necessary.
* Removes the token last added from the linked list of tokens. The programmer
* should never have to call this directly; it can be called by subclasses of
* <code>TokenMaker</code> if necessary.
*/
public void removeLastToken() {
if (previousToken == null) {
@@ -20,10 +20,9 @@ import java.util.Set;
public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
/**
* A mapping from keys to the names of {@link TokenMaker} implementation
* class names. When {@link #getTokenMaker(String)} is called with a key
* defined in this map, a <code>TokenMaker</code> of the corresponding type
* is returned.
* A mapping from keys to the names of {@link TokenMaker} implementation class
* names. When {@link #getTokenMaker(String)} is called with a key defined in
* this map, a <code>TokenMaker</code> of the corresponding type is returned.
*/
private Map<String, Object> tokenMakerMap;
@@ -38,10 +37,9 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
/**
* Returns a {@link TokenMaker} for the specified key.
*
* @param key
* The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code>
* if none matches the specified key.
* @param key The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code> if
* none matches the specified key.
*/
@Override
protected TokenMaker getTokenMakerImpl(String key) {
@@ -60,8 +58,8 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
/**
* Populates the mapping from keys to instances of
* <code>TokenMakerCreator</code>s. Subclasses should override this method
* and call one of the <code>putMapping</code> overloads to register
* <code>TokenMakerCreator</code>s. Subclasses should override this method and
* call one of the <code>putMapping</code> overloads to register
* {@link TokenMaker}s for syntax constants.
*
* @see #putMapping(String, String)
@@ -78,13 +76,11 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
}
/**
* Adds a mapping from a key to a <code>TokenMaker</code> implementation
* class name.
* Adds a mapping from a key to a <code>TokenMaker</code> implementation class
* name.
*
* @param key
* The key.
* @param className
* The <code>TokenMaker</code> class name.
* @param key The key.
* @param className The <code>TokenMaker</code> class name.
* @see #putMapping(String, String, ClassLoader)
*/
public void putMapping(String key, String className) {
@@ -92,15 +88,12 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
}
/**
* Adds a mapping from a key to a <code>TokenMaker</code> implementation
* class name.
* Adds a mapping from a key to a <code>TokenMaker</code> implementation class
* name.
*
* @param key
* The key.
* @param className
* The <code>TokenMaker</code> class name.
* @param cl
* The class loader to use when loading the class.
* @param key The key.
* @param className The <code>TokenMaker</code> class name.
* @param cl The class loader to use when loading the class.
* @see #putMapping(String, String)
*/
public void putMapping(String key, String className, ClassLoader cl) {
@@ -24,14 +24,11 @@ public class ActiveLineRangeEvent extends EventObject {
/**
* Constructor.
*
* @param source
* The text area.
* @param min
* The first line in the active line range, or
* <code>-1</code> if the line range is being cleared.
* @param max
* The last line in the active line range, or
* <code>-1</code> if the line range is being cleared.
* @param source The text area.
* @param min The first line in the active line range, or <code>-1</code> if
* the line range is being cleared.
* @param max The last line in the active line range, or <code>-1</code> if
* the line range is being cleared.
*/
public ActiveLineRangeEvent(RSyntaxTextArea source, int min, int max) {
super(source);
@@ -42,8 +39,7 @@ public class ActiveLineRangeEvent extends EventObject {
/**
* Returns the last line in the active line range.
*
* @return The last line, or <code>-1</code> if the range is being
* cleared.
* @return The last line, or <code>-1</code> if the range is being cleared.
* @see #getMin()
*/
public int getMax() {
@@ -53,8 +49,7 @@ public class ActiveLineRangeEvent extends EventObject {
/**
* Returns the first line in the active line range.
*
* @return The first line, or <code>-1</code> if the range is being
* cleared.
* @return The first line, or <code>-1</code> if the range is being cleared.
* @see #getMax()
*/
public int getMin() {
@@ -13,15 +13,15 @@ import java.util.EventListener;
* Listens for "active line range" events from an <code>RSyntaxTextArea</code>.
* If a text area contains some semantic knowledge of the programming language
* being edited, it may broadcast {@link ActiveLineRangeEvent}s whenever the
* caret moves into a new "block" of code. Listeners can listen for these
* events and respond accordingly.
* caret moves into a new "block" of code. Listeners can listen for these events
* and respond accordingly.
* <p>
*
* See the <code>RSTALanguageSupport</code> project at
* <a href="http://fifesoft.com">http://fifesoft.com</a> for some
* <code>LanguageSupport</code> implementations that may broadcast these
* events. Note that if an RSTA/LanguageSupport does not support broadcasting
* these events, the listener will simply never receive any notifications.
* <code>LanguageSupport</code> implementations that may broadcast these events.
* Note that if an RSTA/LanguageSupport does not support broadcasting these
* events, the listener will simply never receive any notifications.
*
* @author Robert Futrell
* @version 1.0
@@ -31,11 +31,9 @@ public interface ActiveLineRangeListener extends EventListener {
/**
* Called whenever the "active line range" changes.
*
* @param e
* Information about the line range change. If there is no longer
* an "active line range," the "minimum" and "maximum" line
* values
* should both be <code>-1</code>.
* @param e Information about the line range change. If there is no longer an
* "active line range," the "minimum" and "maximum" line values should
* both be <code>-1</code>.
*/
void activeLineRangeChanged(ActiveLineRangeEvent e);
}
@@ -13,8 +13,8 @@ import javax.swing.text.Caret;
import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* The default implementation of {@link OccurrenceMarker}. It goes through
* the document and marks all instances of the specified token.
* The default implementation of {@link OccurrenceMarker}. It goes through the
* document and marks all instances of the specified token.
*
* @author Robert Futrell
* @version 1.0
@@ -66,16 +66,13 @@ class DefaultOccurrenceMarker implements OccurrenceMarker {
* Highlights all instances of tokens identical to <code>t</code> in the
* specified document.
*
* @param doc
* The document.
* @param t
* The document whose relevant occurrences should be marked.
* @param h
* The highlighter to add the highlights to.
* @param p
* The painter for the highlights.
* @param doc The document.
* @param t The document whose relevant occurrences should be marked.
* @param h The highlighter to add the highlights to.
* @param p The painter for the highlights.
*/
public static final void markOccurrencesOfToken(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p) {
public static final void markOccurrencesOfToken(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h,
SmartHighlightPainter p) {
char[] lexeme = t.getLexeme().toCharArray();
int type = t.getType();
int lineCount = doc.getDefaultRootElement().getElementCount();
@@ -10,18 +10,18 @@ import javax.swing.text.Segment;
/**
* This class generates tokens for a {@link TokenMaker}. This class is here
* because it reuses tokens when they aren't needed anymore to prevent
* This class doesn't actually create new tokens every time
* <code>createToken</code> is called. Instead, it internally keeps a stack of
* available already-created tokens. When more tokens are needed to properly
* display a line, more tokens are added to the available stack. This saves
* from needless repetitive memory allocation. However, it makes it IMPERATIVE
* that users call <code>resetTokenList</code> when creating a new token list so
* that the token maker can keep an accurate list of available tokens.
* because it reuses tokens when they aren't needed anymore to prevent This
* class doesn't actually create new tokens every time <code>createToken</code>
* is called. Instead, it internally keeps a stack of available already-created
* tokens. When more tokens are needed to properly display a line, more tokens
* are added to the available stack. This saves from needless repetitive memory
* allocation. However, it makes it IMPERATIVE that users call
* <code>resetTokenList</code> when creating a new token list so that the token
* maker can keep an accurate list of available tokens.
* <p>
*
* NOTE: This class should only be used by {@link TokenMaker}; nobody else
* needs it!
* NOTE: This class should only be used by {@link TokenMaker}; nobody else needs
* it!
*
* @author Robert Futrell
* @version 0.1
@@ -45,11 +45,8 @@ class DefaultTokenFactory implements TokenFactory {
/**
* Constructor.
*
* @param size
* The initial number of tokens in this factory.
* @param increment
* How many tokens to increment by when the stack gets
* empty.
* @param size The initial number of tokens in this factory.
* @param increment How many tokens to increment by when the stack gets empty.
*/
DefaultTokenFactory(int size, int increment) {
this.size = size;
@@ -63,8 +60,8 @@ class DefaultTokenFactory implements TokenFactory {
}
/**
* Adds tokens to the internal token list. This is called whenever a
* request is made and no more tokens are available.
* Adds tokens to the internal token list. This is called whenever a request is
* made and no more tokens are available.
*/
private void augmentTokenList() {
TokenImpl[] temp = new TokenImpl[size + increment];
@@ -83,12 +80,8 @@ class DefaultTokenFactory implements TokenFactory {
@Override
public TokenImpl createToken() {
TokenImpl token = tokenList[currentFreeToken];
token.text = null;
token.setType(Token.NULL);
token.setOffset(-1);
token.setNextToken(null);
currentFreeToken++;
if (currentFreeToken == size) {
token.reset();
if (++currentFreeToken == size) {
augmentTokenList();
}
return token;
@@ -98,7 +91,8 @@ class DefaultTokenFactory implements TokenFactory {
* {@inheritDoc}
*/
@Override
public TokenImpl createToken(final Segment line, final int beg, final int end, final int startOffset, final int type) {
public TokenImpl createToken(final Segment line, final int beg, final int end, final int startOffset,
final int type) {
return createToken(line.array, beg, end, startOffset, type);
}
@@ -106,7 +100,8 @@ class DefaultTokenFactory implements TokenFactory {
* {@inheritDoc}
*/
@Override
public TokenImpl createToken(final char[] line, final int beg, final int end, final int startOffset, final int type) {
public TokenImpl createToken(final char[] line, final int beg, final int end, final int startOffset,
final int type) {
TokenImpl token = tokenList[currentFreeToken];
token.set(line, beg, end, startOffset, type);
currentFreeToken++;
@@ -117,9 +112,9 @@ class DefaultTokenFactory implements TokenFactory {
}
/**
* Resets the state of this token maker. This method should be called
* by the <code>TokenMaker</code> every time a token list is generated for
* a new line so the tokens can be reused.
* Resets the state of this token maker. This method should be called by the
* <code>TokenMaker</code> every time a token list is generated for a new line
* so the tokens can be reused.
*/
@Override
public void resetAllTokens() {
@@ -26,9 +26,9 @@ class DefaultTokenPainter implements TokenPainter {
*/
private Rectangle2D.Float bgRect;
/**
* Micro-optimization; buffer used to compute tab width. If the width is
* correct it's not re-allocated, to prevent lots of very small garbage.
* Only used when painting tab lines.
* Micro-optimization; buffer used to compute tab width. If the width is correct
* it's not re-allocated, to prevent lots of very small garbage. Only used when
* painting tab lines.
*/
private static char[] tabBuf;
@@ -48,7 +48,8 @@ class DefaultTokenPainter implements TokenPainter {
* {@inheritDoc}
*/
@Override
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart) {
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart) {
return paintImpl(token, g, x, y, host, e, clipStart, false, false);
}
@@ -56,33 +57,26 @@ class DefaultTokenPainter implements TokenPainter {
* {@inheritDoc}
*/
@Override
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean paintBG) {
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean paintBG) {
return paintImpl(token, g, x, y, host, e, clipStart, !paintBG, false);
}
/**
* Paints the background of a token.
*
* @param x
* The x-coordinate of the token.
* @param y
* The y-coordinate of the token.
* @param width
* The width of the token (actually, the width of the part of
* @param x The x-coordinate of the token.
* @param y The y-coordinate of the token.
* @param width The width of the token (actually, the width of the part of
* the token to paint).
* @param height
* The height of the token.
* @param g
* The graphics context with which to paint.
* @param fontAscent
* The ascent of the token's font.
* @param host
* The text area.
* @param color
* The color with which to paint.
* @param height The height of the token.
* @param g The graphics context with which to paint.
* @param fontAscent The ascent of the token's font.
* @param host The text area.
* @param color The color with which to paint.
*/
protected void paintBackground(float x, float y, float width, float height, Graphics2D g, int fontAscent, RSyntaxTextArea host,
Color color) {
protected void paintBackground(float x, float y, float width, float height, Graphics2D g, int fontAscent,
RSyntaxTextArea host, Color color) {
g.setColor(color);
bgRect.setRect(x, y - fontAscent, width, height);
// g.fill(bgRect);
@@ -92,8 +86,8 @@ class DefaultTokenPainter implements TokenPainter {
/**
* Does the dirty-work of actually painting the token.
*/
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean selected, boolean useSTC) {
int origX = (int) x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
@@ -157,7 +151,8 @@ class DefaultTokenPainter implements TokenPainter {
* {@inheritDoc}
*/
@Override
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, boolean useSTC) {
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
boolean useSTC) {
return paintSelected(token, g, x, y, host, e, 0, useSTC);
}
@@ -165,35 +160,29 @@ class DefaultTokenPainter implements TokenPainter {
* {@inheritDoc}
*/
@Override
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean useSTC) {
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean useSTC) {
return paintImpl(token, g, x, y, host, e, clipStart, true, useSTC);
}
/**
* Paints dotted "tab" lines; that is, lines that show where your caret
* would go to on the line if you hit "tab". This visual effect is usually
* done in the leading whitespace token(s) of lines.
* Paints dotted "tab" lines; that is, lines that show where your caret would go
* to on the line if you hit "tab". This visual effect is usually done in the
* leading whitespace token(s) of lines.
*
* @param token
* The token to render.
* @param x
* The starting x-offset of this token. It is assumed that this
* is the left margin of the text area (may be non-zero due to
* @param token The token to render.
* @param x The starting x-offset of this token. It is assumed that this is
* the left margin of the text area (may be non-zero due to
* insets), since tab lines are only painted for leading
* whitespace.
* @param y
* The baseline where this token was painted.
* @param endX
* The ending x-offset of this token.
* @param g
* The graphics context.
* @param e
* Used to expand tabs.
* @param host
* The text area.
* @param y The baseline where this token was painted.
* @param endX The ending x-offset of this token.
* @param g The graphics context.
* @param e Used to expand tabs.
* @param host The text area.
*/
protected void paintTabLines(Token token, int x, int y, int endX, Graphics2D g, TabExpander e, RSyntaxTextArea host) {
protected void paintTabLines(Token token, int x, int y, int endX, Graphics2D g, TabExpander e,
RSyntaxTextArea host) {
// We allow tab lines to be painted in more than just Token.WHITESPACE,
// i.e. for MLC's and Token.IDENTIFIERS (for TokenMakers that return
// whitespace as identifiers for performance). But we only paint tab
@@ -20,13 +20,11 @@ public class DocumentRange implements Comparable<DocumentRange> {
/**
* Constructor.
*
* @param startOffs
* The starting offset in the document, inclusive.
* @param endOffs
* The ending offset in the document, exclusive.
* @throws IllegalArgumentException
* If <code>endOffs</code> is less than
* <code>startOffs</code>, or either argument is less than zero.
* @param startOffs The starting offset in the document, inclusive.
* @param endOffs The ending offset in the document, exclusive.
* @throws IllegalArgumentException If <code>endOffs</code> is less than
* <code>startOffs</code>, or either argument
* is less than zero.
*/
public DocumentRange(int startOffs, int endOffs) {
set(startOffs, endOffs);
@@ -35,8 +33,7 @@ public class DocumentRange implements Comparable<DocumentRange> {
/**
* Compares this document range to another.
*
* @param other
* Another document range.
* @param other Another document range.
* @return How the two should be sorted relative to each other.
*/
@Override
@@ -54,10 +51,9 @@ public class DocumentRange implements Comparable<DocumentRange> {
/**
* Returns whether this document range is equal to another one.
*
* @param other
* Another object, presumably a document range.
* @return Whether <code>other</code> is also a document range, and equal
* to this one.
* @param other Another object, presumably a document range.
* @return Whether <code>other</code> is also a document range, and equal to
* this one.
*/
@Override
public boolean equals(Object other) {
@@ -102,10 +98,9 @@ public class DocumentRange implements Comparable<DocumentRange> {
}
/**
* Returns whether this document range has zero length. This can happen,
* for example, with regex searches of forms like
* <code>"foo|"</code>, where the right-hand sub-expression matches empty
* strings.
* Returns whether this document range has zero length. This can happen, for
* example, with regex searches of forms like <code>"foo|"</code>, where the
* right-hand sub-expression matches empty strings.
*
* @return Whether this document range has zero length.
*/
@@ -116,13 +111,11 @@ public class DocumentRange implements Comparable<DocumentRange> {
/**
* Sets the document range.
*
* @param start
* The new start value, inclusive.
* @param end
* The new end value, exclusive.
* @throws IllegalArgumentException
* If <code>end</code> is less than
* <code>start</code>, or either argument is less than zero.
* @param start The new start value, inclusive.
* @param end The new end value, exclusive.
* @throws IllegalArgumentException If <code>end</code> is less than
* <code>start</code>, or either argument is
* less than zero.
*/
public void set(int start, int end) {
if (start < 0 || end < 0) {
@@ -148,8 +141,7 @@ public class DocumentRange implements Comparable<DocumentRange> {
/**
* Translates this document range by a given amount.
*
* @param amount
* The amount to translate this range by.
* @param amount The amount to translate this range by.
* @return This (modified) range.
*/
public DocumentRange translate(int amount) {
+49 -66
View File
@@ -39,16 +39,15 @@ import org.fife.ui.rsyntaxtextarea.parser.TaskTagParser.TaskNotice;
import org.fife.ui.rtextarea.RTextArea;
/**
* A component to sit alongside an {@link RSyntaxTextArea} that displays
* colored markers for locations of interest (parser errors, marked
* occurrences, etc.).
* A component to sit alongside an {@link RSyntaxTextArea} that displays colored
* markers for locations of interest (parser errors, marked occurrences, etc.).
* <p>
*
* <code>ErrorStrip</code>s display <code>ParserNotice</code>s from
* {@link Parser}s. Currently, the only way to get lines flagged in this
* component is to register a <code>Parser</code> on an RSyntaxTextArea and
* return <code>ParserNotice</code>s for each line to display an icon for.
* The severity of each notice must be at least the threshold set by
* return <code>ParserNotice</code>s for each line to display an icon for. The
* severity of each notice must be at least the threshold set by
* {@link #setLevelThreshold(org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level)}
* to be displayed in this error strip. The default threshold is
* {@link org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level#WARNING}.
@@ -86,23 +85,23 @@ public class ErrorStrip extends JPanel {
*/
private transient Listener listener;
/**
* Whether "marked occurrences" in the text area should be shown in this
* error strip.
* Whether "marked occurrences" in the text area should be shown in this error
* strip.
*/
private boolean showMarkedOccurrences;
/**
* Whether markers for "mark all" highlights should be shown in this
* error strip.
* Whether markers for "mark all" highlights should be shown in this error
* strip.
*/
private boolean showMarkAll;
/**
* Mapping of colors to brighter colors. This is kept to prevent
* unnecessary creation of the same Colors over and over.
* Mapping of colors to brighter colors. This is kept to prevent unnecessary
* creation of the same Colors over and over.
*/
private Map<Color, Color> brighterColors;
/**
* Only notices of this severity (or worse) will be displayed in this
* error strip.
* Only notices of this severity (or worse) will be displayed in this error
* strip.
*/
private ParserNotice.Level levelThreshold;
/**
@@ -134,8 +133,7 @@ public class ErrorStrip extends JPanel {
/**
* Constructor.
*
* @param textArea
* The text area we are examining.
* @param textArea The text area we are examining.
*/
public ErrorStrip(RSyntaxTextArea textArea) {
this.textArea = textArea;
@@ -152,8 +150,8 @@ public class ErrorStrip extends JPanel {
}
/**
* Overridden so we only start listening for parser notices when this
* component (and presumably the text area) are visible.
* Overridden so we only start listening for parser notices when this component
* (and presumably the text area) are visible.
*/
@Override
public void addNotify() {
@@ -181,8 +179,7 @@ public class ErrorStrip extends JPanel {
/**
* Returns a "brighter" color.
*
* @param c
* The color.
* @param c The color.
* @return A brighter color.
*/
private Color getBrighterColor(Color c) {
@@ -232,9 +229,9 @@ public class ErrorStrip extends JPanel {
}
/**
* Returns the minimum severity a parser notice must be for it to be
* displayed in this error strip. This will be one of the constants
* defined in the <code>ParserNotice</code> class.
* Returns the minimum severity a parser notice must be for it to be displayed
* in this error strip. This will be one of the constants defined in the
* <code>ParserNotice</code> class.
*
* @return The minimum severity.
* @see #setLevelThreshold(org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level)
@@ -278,11 +275,10 @@ public class ErrorStrip extends JPanel {
}
/**
* Returns the y-offset in this component corresponding to a line in the
* text component.
* Returns the y-offset in this component corresponding to a line in the text
* component.
*
* @param line
* The line.
* @param line The line.
* @return The y-offset.
* @see #yToLine(int)
*/
@@ -295,8 +291,7 @@ public class ErrorStrip extends JPanel {
/**
* Overridden to (possibly) draw the caret's position.
*
* @param g
* The graphics context.
* @param g The graphics context.
*/
@Override
protected void paintComponent(Graphics g) {
@@ -310,8 +305,7 @@ public class ErrorStrip extends JPanel {
/**
* Returns a possibly brighter component for a color.
*
* @param i
* An RGB component for a color (0-255).
* @param i An RGB component for a color (0-255).
* @return A possibly brighter value for the component.
*/
private static int possiblyBrighter(int i) {
@@ -358,12 +352,9 @@ public class ErrorStrip extends JPanel {
/**
* Adds markers for a list of ranges in the document.
*
* @param ranges
* The list of ranges in the document.
* @param markerMap
* A mapping from line number to <code>Marker</code>.
* @param color
* The color to use for the markers.
* @param ranges The list of ranges in the document.
* @param markerMap A mapping from line number to <code>Marker</code>.
* @param color The color to use for the markers.
*/
private void addMarkersForRanges(List<DocumentRange> ranges, Map<Integer, Marker> markerMap, Color color) {
for (DocumentRange range : ranges) {
@@ -405,8 +396,7 @@ public class ErrorStrip extends JPanel {
/**
* Sets the color to use when painting the caret marker.
*
* @param color
* The new caret marker color.
* @param color The new caret marker color.
* @see #getCaretMarkerColor()
*/
public void setCaretMarkerColor(Color color) {
@@ -419,8 +409,7 @@ public class ErrorStrip extends JPanel {
/**
* Toggles whether the caret's current location should be drawn.
*
* @param follow
* Whether the caret's current location should be followed.
* @param follow Whether the caret's current location should be followed.
* @see #getFollowCaret()
*/
public void setFollowCaret(boolean follow) {
@@ -436,13 +425,12 @@ public class ErrorStrip extends JPanel {
}
/**
* Sets the minimum severity a parser notice must be for it to be displayed
* in this error strip. This should be one of the constants defined in
* the <code>ParserNotice</code> class. The default value is
* Sets the minimum severity a parser notice must be for it to be displayed in
* this error strip. This should be one of the constants defined in the
* <code>ParserNotice</code> class. The default value is
* {@link org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level#WARNING}.
*
* @param level
* The new severity threshold.
* @param level The new severity threshold.
* @see #getLevelThreshold()
* @see ParserNotice
*/
@@ -454,12 +442,11 @@ public class ErrorStrip extends JPanel {
}
/**
* Sets the provider of tool tips for markers in this error strip.
* Applications can use this method to control the content and format of
* the tool tip descriptions of line markers.
* Sets the provider of tool tips for markers in this error strip. Applications
* can use this method to control the content and format of the tool tip
* descriptions of line markers.
*
* @param provider
* The provider. If this is <code>null</code>, a default
* @param provider The provider. If this is <code>null</code>, a default
* implementation will be used.
*/
public void setMarkerToolTipProvider(ErrorStripMarkerToolTipProvider provider) {
@@ -469,8 +456,7 @@ public class ErrorStrip extends JPanel {
/**
* Sets whether "mark all" highlights are shown in this error strip.
*
* @param show
* Whether to show markers for "mark all" highlights.
* @param show Whether to show markers for "mark all" highlights.
* @see #getShowMarkAll()
*/
public void setShowMarkAll(boolean show) {
@@ -485,8 +471,7 @@ public class ErrorStrip extends JPanel {
/**
* Sets whether marked occurrences are shown in this error strip.
*
* @param show
* Whether to show marked occurrences.
* @param show Whether to show marked occurrences.
* @see #getShowMarkedOccurrences()
*/
public void setShowMarkedOccurrences(boolean show) {
@@ -502,8 +487,7 @@ public class ErrorStrip extends JPanel {
* Returns the line in the text area corresponding to a y-offset in this
* component.
*
* @param y
* The y-offset.
* @param y The y-offset.
* @return The line.
* @see #lineToY(int)
*/
@@ -518,8 +502,8 @@ public class ErrorStrip extends JPanel {
}
/**
* The default implementation of the provider of tool tips for markers in
* an error strip.
* The default implementation of the provider of tool tips for markers in an
* error strip.
*
* @author predi
*/
@@ -547,21 +531,20 @@ public class ErrorStrip extends JPanel {
}
/**
* Returns tool tip text for the markers in an {@link ErrorStrip} that
* denote one or more parser notices.
* Returns tool tip text for the markers in an {@link ErrorStrip} that denote
* one or more parser notices.
*
* @author predi
*/
public interface ErrorStripMarkerToolTipProvider {
/**
* Returns the tool tip text for a marker in an <code>ErrorStrip</code>
* that denotes a given list of parser notices.
* Returns the tool tip text for a marker in an <code>ErrorStrip</code> that
* denotes a given list of parser notices.
*
* @param notices
* The list of parser notices.
* @return The tool tip text. This may be HTML. Returning
* <code>null</code> will result in no tool tip being displayed.
* @param notices The list of parser notices.
* @return The tool tip text. This may be HTML. Returning <code>null</code> will
* result in no tool tip being displayed.
*/
String getToolTipText(List<ParserNotice> notices);
}
@@ -29,8 +29,7 @@ class FileFileLocation extends FileLocation {
/**
* Constructor.
*
* @param file
* The local file.
* @param file The local file.
*/
FileFileLocation(File file) {
try {
@@ -96,8 +95,8 @@ class FileFileLocation extends FileLocation {
}
/**
* Since file locations of this type are guaranteed to be local, this
* method returns whether the file exists.
* Since file locations of this type are guaranteed to be local, this method
* returns whether the file exists.
*
* @return Whether this local file actually exists.
* @see #isLocal()
@@ -14,8 +14,8 @@ import java.net.MalformedURLException;
import java.net.URL;
/**
* Holds the location of a local or remote file. This provides a common way
* to read, write, and check properties of both local and remote files.
* Holds the location of a local or remote file. This provides a common way to
* read, write, and check properties of both local and remote files.
*
* @author Robert Futrell
* @version 1.0
@@ -25,12 +25,12 @@ public abstract class FileLocation {
/**
* Creates a {@link FileLocation} instance for the specified local file.
*
* @param fileFullPath
* The full path to a local file.
* @param fileFullPath The full path to a local file.
* @return The file's location.
*/
public static FileLocation create(String fileFullPath) {
if (fileFullPath.startsWith("http://") || fileFullPath.startsWith("https://") || fileFullPath.startsWith("ftp://")) {
if (fileFullPath.startsWith("http://") || fileFullPath.startsWith("https://")
|| fileFullPath.startsWith("ftp://")) {
try {
return new URLFileLocation(new URL(fileFullPath));
} catch (MalformedURLException mue) {
@@ -43,8 +43,7 @@ public abstract class FileLocation {
/**
* Creates a {@link FileLocation} instance for the specified local file.
*
* @param file
* A local file.
* @param file A local file.
* @return The file's location.
*/
public static FileLocation create(File file) {
@@ -54,8 +53,7 @@ public abstract class FileLocation {
/**
* Creates a {@link FileLocation} instance for the specified file.
*
* @param url
* The URL of a file.
* @param url The URL of a file.
* @return The file's location.
*/
public static FileLocation create(URL url) {
@@ -67,16 +65,16 @@ public abstract class FileLocation {
/**
* Returns the last time this file was modified, or
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be
* computed (such as for a remote file).
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be computed
* (such as for a remote file).
*
* @return The last time this file was modified.
*/
protected abstract long getActualLastModified();
/**
* Returns the full path to the file. This will be stripped of
* sensitive information such as passwords for remote files.
* Returns the full path to the file. This will be stripped of sensitive
* information such as passwords for remote files.
*
* @return The full path to the file.
* @see #getFileName()
@@ -95,8 +93,7 @@ public abstract class FileLocation {
* Opens an input stream for reading from this file.
*
* @return The input stream.
* @throws IOException
* If the file does not exist, or some other IO error
* @throws IOException If the file does not exist, or some other IO error
* occurs.
*/
protected abstract InputStream getInputStream() throws IOException;
@@ -105,8 +102,7 @@ public abstract class FileLocation {
* Opens an output stream for writing this file.
*
* @return An output stream.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
protected abstract OutputStream getOutputStream() throws IOException;
@@ -119,8 +115,7 @@ public abstract class FileLocation {
public abstract boolean isLocal();
/**
* Returns whether this file location is a local file that already
* exists.
* Returns whether this file location is a local file that already exists.
*
* @return Whether this file is local and actually exists.
* @see #isLocal()
@@ -32,8 +32,7 @@ public class FoldingAwareIconRowHeader extends IconRowHeader {
/**
* Constructor.
*
* @param textArea
* The parent text area.
* @param textArea The parent text area.
*/
public FoldingAwareIconRowHeader(RSyntaxTextArea textArea) {
super(textArea);
@@ -162,9 +161,9 @@ public class FoldingAwareIconRowHeader extends IconRowHeader {
}
/**
* Paints icons when line wrapping is enabled. Note that this does not
* override the parent class's implementation to avoid this version being
* called when line wrapping is disabled.
* Paints icons when line wrapping is enabled. Note that this does not override
* the parent class's implementation to avoid this version being called when
* line wrapping is disabled.
*/
private void paintComponentWrapped(Graphics g) {
// The variables we use are as follows:
@@ -20,8 +20,8 @@ import javax.swing.text.Element;
import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* Marks occurrences of the current token for HTML. Tags that require a
* closing tag have their "opposite" tag closed.
* Marks occurrences of the current token for HTML. Tags that require a closing
* tag have their "opposite" tag closed.
*
* @author Robert Futrell
* @version 1.0
@@ -33,36 +33,36 @@ public class HtmlOccurrenceMarker implements OccurrenceMarker {
private static final Set<String> TAGS_REQUIRING_CLOSING = getRequiredClosingTags();
public static final Set<String> getRequiredClosingTags() {
final String[] tags = { "html", "head", "title", "style", "script", "noscript", "body", "section", "nav", "article", "aside", "h1",
"h2", "h3", "h4", "h5", "h6", "header", "footer", "address", "pre", "dialog", "blockquote", "ol", "ul", "dl", "a", "q",
"cite", "em", "strong", "small", "mark", "dfn", "abbr", "time", "progress", "meter", "code", "var", "samp", "kbd", "sub",
"sup", "span", "i", "b", "bdo", "ruby", "rt", "rp", "ins", "del", "figure", "iframe", "object", "video", "audio", "canvas",
"map", "table", "caption", "form", "fieldset", "label", "button", "select", "datalist", "textarea", "output", "details",
"bb", "menu", "legend", "div",
final String[] tags = { "html", "head", "title", "style", "script", "noscript", "body", "section", "nav",
"article", "aside", "h1", "h2", "h3", "h4", "h5", "h6", "header", "footer", "address", "pre", "dialog",
"blockquote", "ol", "ul", "dl", "a", "q", "cite", "em", "strong", "small", "mark", "dfn", "abbr",
"time", "progress", "meter", "code", "var", "samp", "kbd", "sub", "sup", "span", "i", "b", "bdo",
"ruby", "rt", "rp", "ins", "del", "figure", "iframe", "object", "video", "audio", "canvas", "map",
"table", "caption", "form", "fieldset", "label", "button", "select", "datalist", "textarea", "output",
"details", "bb", "menu", "legend", "div",
// Obsolete elements
"acronym", "applet", "big", "blink", "center", "dir", "font", "frame", "frameset", "isindex", "listing", "marquee", "nobr",
"noembed", "noframes", "plaintext", "s", "spacer", "strike", "tt", "u", "xmp", };
"acronym", "applet", "big", "blink", "center", "dir", "font", "frame", "frameset", "isindex", "listing",
"marquee", "nobr", "noembed", "noframes", "plaintext", "s", "spacer", "strike", "tt", "u", "xmp", };
return new HashSet<String>(Arrays.asList(tags));
}
/**
* If the caret is inside of a tag, this method returns the token
* representing the tag name; otherwise, <code>null</code> is returned.
* If the caret is inside of a tag, this method returns the token representing
* the tag name; otherwise, <code>null</code> is returned.
* <p>
*
* Currently, this method only checks for tag names on the same line as
* the caret, for simplicity. In the future it could check prior lines
* until the tag name is found.
* Currently, this method only checks for tag names on the same line as the
* caret, for simplicity. In the future it could check prior lines until the tag
* name is found.
*
* @param textArea
* The text area.
* @param occurrenceMarker
* The occurrence marker.
* @return The token to mark occurrences of. Note that, if the
* specified occurrence marker identifies tokens other than
* tag names, these other element types may be returned.
* @param textArea The text area.
* @param occurrenceMarker The occurrence marker.
* @return The token to mark occurrences of. Note that, if the specified
* occurrence marker identifies tokens other than tag names, these other
* element types may be returned.
*/
public static final Token getTagNameTokenForCaretOffset(RSyntaxTextArea textArea, OccurrenceMarker occurrenceMarker) {
public static final Token getTagNameTokenForCaretOffset(RSyntaxTextArea textArea,
OccurrenceMarker occurrenceMarker) {
// Get the tag name token.
// For now, we only check for tags on the current line, for simplicity.
int dot = textArea.getCaretPosition();
@@ -31,14 +31,11 @@ public interface LinkGenerator {
/**
* If a region of text under the mouse position should be considered a
* hyperlink, a result object is returned. This object describes what
* region of text is the link, and what action to perform if the link is
* clicked.
* hyperlink, a result object is returned. This object describes what region of
* text is the link, and what action to perform if the link is clicked.
*
* @param textArea
* The text component.
* @param offs
* The offset in the document under the mouse position.
* @param textArea The text component.
* @param offs The offset in the document under the mouse position.
* @return The link information, or <code>null</code> if no link is at the
* specified offset.
*/
@@ -25,10 +25,10 @@ import javax.swing.event.HyperlinkEvent;
public interface LinkGeneratorResult {
/**
* Executes the action associated with this object. If the result is a
* URL to open, a standard hyperlink event can be returned. Alternatively,
* <code>null</code> can be returned and the action performed in this
* method itself.
* Executes the action associated with this object. If the result is a URL to
* open, a standard hyperlink event can be returned. Alternatively,
* <code>null</code> can be returned and the action performed in this method
* itself.
*
* @return The hyperlink event to broadcast from the text area, or
* <code>null</code> if the action's behavior occurs in this method
@@ -19,8 +19,8 @@ import javax.swing.text.Caret;
import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* Marks all occurrences of the token at the current caret position, if it is
* an identifier.
* Marks all occurrences of the token at the current caret position, if it is an
* identifier.
*
* @author Robert Futrell
* @version 1.0
@@ -50,10 +50,9 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
/**
* Constructor.
*
* @param delay
* The delay between when the caret last moves and when the
* text should be scanned for matching occurrences. This should
* be in milliseconds.
* @param delay The delay between when the caret last moves and when the text
* should be scanned for matching occurrences. This should be in
* milliseconds.
*/
MarkOccurrencesSupport(int delay) {
this(delay, DEFAULT_COLOR);
@@ -62,12 +61,10 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
/**
* Constructor.
*
* @param delay
* The delay between when the caret last moves and when the
* text should be scanned for matching occurrences. This should
* be in milliseconds.
* @param color
* The color to use to mark the occurrences. This cannot be
* @param delay The delay between when the caret last moves and when the text
* should be scanned for matching occurrences. This should be in
* milliseconds.
* @param color The color to use to mark the occurrences. This cannot be
* <code>null</code>.
*/
MarkOccurrencesSupport(int delay, Color color) {
@@ -78,16 +75,15 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
}
/**
* Called after the caret has been moved and a fixed time delay has
* elapsed. This locates and highlights all occurrences of the identifier
* at the caret position, if any.
* Called after the caret has been moved and a fixed time delay has elapsed.
* This locates and highlights all occurrences of the identifier at the caret
* position, if any.
* <p>
*
* Callers should not call this method directly, but should rather prefer
* {@link #doMarkOccurrences()} to mark occurrences.
*
* @param e
* The event.
* @param e The event.
* @see #doMarkOccurrences()
*/
@Override
@@ -128,8 +124,7 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
/**
* Called when the caret moves in the text area.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void caretUpdate(CaretEvent e) {
@@ -147,8 +142,7 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
}
/**
* Immediately marks all occurrences of the token at the current caret
* position.
* Immediately marks all occurrences of the token at the current caret position.
*/
public void doMarkOccurrences() {
timer.stop();
@@ -187,11 +181,10 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
}
/**
* Installs this listener on a text area. If it is already installed on
* another text area, it is uninstalled first.
* Installs this listener on a text area. If it is already installed on another
* text area, it is uninstalled first.
*
* @param textArea
* The text area to install on.
* @param textArea The text area to install on.
*/
public void install(RSyntaxTextArea textArea) {
if (this.textArea != null) {
@@ -207,8 +200,7 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
/**
* Sets the color to use when marking occurrences.
*
* @param color
* The color to use.
* @param color The color to use.
* @see #getColor()
* @see #setPaintBorder(boolean)
*/
@@ -221,12 +213,11 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
}
/**
* Sets the delay between the last caret position change and when the
* text is scanned for matching identifiers. A delay is needed to prevent
* repeated scanning while the user is typing.
* Sets the delay between the last caret position change and when the text is
* scanned for matching identifiers. A delay is needed to prevent repeated
* scanning while the user is typing.
*
* @param delay
* The new delay.
* @param delay The new delay.
* @see #getDelay()
*/
public void setDelay(int delay) {
@@ -236,8 +227,7 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
/**
* Toggles whether a border is painted around marked highlights.
*
* @param paint
* Whether to paint a border.
* @param paint Whether to paint a border.
* @see #getPaintBorder()
* @see #setColor(Color)
*/
@@ -251,8 +241,8 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
}
/**
* Uninstalls this listener from the current text area. Does nothing if
* it not currently installed on any text area.
* Uninstalls this listener from the current text area. Does nothing if it not
* currently installed on any text area.
*
* @see #install(RSyntaxTextArea)
*/
@@ -123,8 +123,7 @@ class MatchedBracketPopup extends JWindow {
}
/**
* Positions this popup to be in the top right-hand corner of the parent
* editor.
* Positions this popup to be in the top right-hand corner of the parent editor.
*/
private void setLocation() {
Point topLeft = textArea.getVisibleRect().getLocation();
@@ -10,9 +10,9 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* An <code>OccurrenceMarker</code> is called when the caret stops moving after
* a short period. If the current {@link TokenMaker} returns an instance of
* this class, it is told to mark all occurrences of the identifier at the
* caret position.
* a short period. If the current {@link TokenMaker} returns an instance of this
* class, it is told to mark all occurrences of the identifier at the caret
* position.
*
* @author Robert Futrell
* @version 1.0
@@ -20,27 +20,23 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
public interface OccurrenceMarker {
/**
* Returns the token to mark occurrences, of, provided it matches the
* criteria put forth by {@link #isValidType(RSyntaxTextArea, Token)}.
* For most languages, this method should return the token at the caret
* position.
* Returns the token to mark occurrences, of, provided it matches the criteria
* put forth by {@link #isValidType(RSyntaxTextArea, Token)}. For most
* languages, this method should return the token at the caret position.
*
* @param textArea
* The text area.
* @return The token to (possibly) mark occurrences of, or
* <code>null</code> if none.
* @param textArea The text area.
* @return The token to (possibly) mark occurrences of, or <code>null</code> if
* none.
*/
Token getTokenToMark(RSyntaxTextArea textArea);
/**
* Returns whether the specified token is a type that we can do a
* "mark occurrences" of. Typically, this will delegate to
* Returns whether the specified token is a type that we can do a "mark
* occurrences" of. Typically, this will delegate to
* {@link RSyntaxTextArea#getMarkOccurrencesOfTokenType(int)}.
*
* @param textArea
* The text area.
* @param t
* The token.
* @param textArea The text area.
* @param t The token.
* @return Whether we should mark all occurrences of this token.
*/
boolean isValidType(RSyntaxTextArea textArea, Token t);
@@ -48,14 +44,10 @@ public interface OccurrenceMarker {
/**
* Called when occurrences of a token should be marked.
*
* @param doc
* The document.
* @param t
* The document whose relevant occurrences should be marked.
* @param h
* The highlighter to add the highlights to.
* @param p
* The painter for the highlights.
* @param doc The document.
* @param t The document whose relevant occurrences should be marked.
* @param h The highlighter to add the highlights to.
* @param p The painter for the highlights.
*/
void markOccurrences(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p);
}
@@ -55,20 +55,21 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
private Position firstOffsetModded;
private Position lastOffsetModded;
/**
* Mapping of notices to their highlights in the editor. Can't use a Map
* since parsers could return two <code>ParserNotice</code>s that compare
* equally via <code>equals()</code>. Real-world example: The Perl
* compiler will return 2+ identical error messages if the same error is
* committed in a single line more than once.
* Mapping of notices to their highlights in the editor. Can't use a Map since
* parsers could return two <code>ParserNotice</code>s that compare equally via
* <code>equals()</code>. Real-world example: The Perl compiler will return 2+
* identical error messages if the same error is committed in a single line more
* than once.
*/
private List<NoticeHighlightPair> noticeHighlightPairs;
/**
* Painter used to underline errors.
*/
private SquiggleUnderlineHighlightPainter parserErrorHighlightPainter = new SquiggleUnderlineHighlightPainter(Color.RED);
private SquiggleUnderlineHighlightPainter parserErrorHighlightPainter = new SquiggleUnderlineHighlightPainter(
Color.RED);
/**
* If this system property is set to <code>true</code>, debug messages
* will be printed to stdout to help diagnose parsing issues.
* If this system property is set to <code>true</code>, debug messages will be
* printed to stdout to help diagnose parsing issues.
*/
private static final String PROPERTY_DEBUG_PARSING = "rsta.debugParsing";
/**
@@ -76,17 +77,15 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
*/
private static final boolean DEBUG_PARSING;
/**
* The default delay between the last key press and when the document
* is parsed, in milliseconds.
* The default delay between the last key press and when the document is parsed,
* in milliseconds.
*/
private static final int DEFAULT_DELAY_MS = 1250;
/**
* Constructor.
*
* @param textArea
* The text area whose document the parser will be
* parsing.
* @param textArea The text area whose document the parser will be parsing.
*/
ParserManager(RSyntaxTextArea textArea) {
this(DEFAULT_DELAY_MS, textArea);
@@ -95,12 +94,9 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Constructor.
*
* @param delay
* The delay between the last key press and when the document
* is parsed.
* @param textArea
* The text area whose document the parser will be
* parsing.
* @param delay The delay between the last key press and when the document is
* parsed.
* @param textArea The text area whose document the parser will be parsing.
*/
ParserManager(int delay, RSyntaxTextArea textArea) {
this.textArea = textArea;
@@ -115,8 +111,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Called when the timer fires (e.g. it's time to parse the document).
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void actionPerformed(ActionEvent e) {
@@ -132,7 +127,8 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
Element root = doc.getDefaultRootElement();
int firstLine = firstOffsetModded == null ? 0 : root.getElementIndex(firstOffsetModded.getOffset());
int lastLine = lastOffsetModded == null ? root.getElementCount() - 1 : root.getElementIndex(lastOffsetModded.getOffset());
int lastLine = lastOffsetModded == null ? root.getElementCount() - 1
: root.getElementIndex(lastOffsetModded.getOffset());
firstOffsetModded = lastOffsetModded = null;
if (DEBUG_PARSING) {
System.out.println("[DEBUG]: Minimum lines to parse: " + firstLine + "-" + lastLine);
@@ -162,9 +158,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Adds a parser for the text area.
*
* @param parser
* The new parser. If this is <code>null</code>, nothing
* happens.
* @param parser The new parser. If this is <code>null</code>, nothing happens.
* @see #getParser(int)
* @see #removeParser(Parser)
*/
@@ -185,11 +179,10 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Adds highlights for a list of parser notices. Any current notices
* from the same Parser, in the same parsed range, are removed.
* Adds highlights for a list of parser notices. Any current notices from the
* same Parser, in the same parsed range, are removed.
*
* @param res
* The result of a parsing.
* @param res The result of a parsing.
* @see #clearParserNoticeHighlights()
*/
private void addParserNoticeHighlights(ParseResult res) {
@@ -231,11 +224,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void changedUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {
}
private void clearParserNoticeHighlights() {
RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) textArea.getHighlighter();
@@ -250,8 +243,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Removes all parser notice highlights for a specific parser.
*
* @param parser
* The parser whose highlights to remove.
* @param parser The parser whose highlights to remove.
*/
private void clearParserNoticeHighlights(Parser parser) {
RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) textArea.getHighlighter();
@@ -282,18 +274,16 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Forces the given {@link Parser} to re-parse the content of this text
* area.
* Forces the given {@link Parser} to re-parse the content of this text area.
* <p>
*
* This method can be useful when a <code>Parser</code> can be configured
* as to what notices it returns. For example, if a Java language parser
* can be configured to set whether no serialVersionUID is a warning,
* error, or ignored, this method can be called after changing the expected
* notice type to have the document re-parsed.
* This method can be useful when a <code>Parser</code> can be configured as to
* what notices it returns. For example, if a Java language parser can be
* configured to set whether no serialVersionUID is a warning, error, or
* ignored, this method can be called after changing the expected notice type to
* have the document re-parsed.
*
* @param parser
* The index of the <code>Parser</code> to re-run.
* @param parser The index of the <code>Parser</code> to re-run.
* @see #getParser(int)
*/
public void forceReparsing(int parser) {
@@ -315,8 +305,8 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Returns the delay between the last "concurrent" edit and when the
* document is re-parsed.
* Returns the delay between the last "concurrent" edit and when the document is
* re-parsed.
*
* @return The delay, in milliseconds.
* @see #setDelay(int)
@@ -328,8 +318,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Returns the specified parser.
*
* @param index
* The index of the parser.
* @param index The index of the parser.
* @return The parser.
* @see #getParserCount()
* @see #addParser(Parser)
@@ -349,12 +338,10 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Returns a list of the current parser notices for this text area.
* This method (like most Swing methods) should only be called on the
* EDT.
* Returns a list of the current parser notices for this text area. This method
* (like most Swing methods) should only be called on the EDT.
*
* @return The list of notices. This will be an empty list if there are
* none.
* @return The list of notices. This will be an empty list if there are none.
*/
public List<ParserNotice> getParserNotices() {
List<ParserNotice> notices = new ArrayList<ParserNotice>();
@@ -367,13 +354,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Returns the tool tip to display for a mouse event at the given
* location. This method is overridden to give a registered parser a
* chance to display a tool tip (such as an error description when the
* mouse is over an error highlight).
* Returns the tool tip to display for a mouse event at the given location. This
* method is overridden to give a registered parser a chance to display a tool
* tip (such as an error description when the mouse is over an error highlight).
*
* @param e
* The mouse event.
* @param e The mouse event.
* @return The tool tip to display, and possibly a hyperlink event handler.
*/
public ToolTipInfo getToolTipText(MouseEvent e) {
@@ -385,19 +370,12 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
int pos = textArea.viewToModel(p);
/*
* Highlighter.Highlight[] highlights = textArea.getHighlighter().
* getHighlights();
* for (int i=0; i<highlights.length; i++) {
* Highlighter.Highlight h = highlights[i];
* //if (h instanceof ParserNoticeHighlight) {
* // ParserNoticeHighlight pnh = (ParserNoticeHighlight)h;
* int start = h.getStartOffset();
* int end = h.getEndOffset();
* if (start<=pos && end>=pos) {
* //return pnh.getMessage();
* return textArea.getText(start, end-start);
* }
* //}
* }
* getHighlights(); for (int i=0; i<highlights.length; i++) {
* Highlighter.Highlight h = highlights[i]; //if (h instanceof
* ParserNoticeHighlight) { // ParserNoticeHighlight pnh =
* (ParserNoticeHighlight)h; int start = h.getStartOffset(); int end =
* h.getEndOffset(); if (start<=pos && end>=pos) { //return pnh.getMessage();
* return textArea.getText(start, end-start); } //} }
*/
if (noticeHighlightPairs != null) {
for (NoticeHighlightPair pair : noticeHighlightPairs) {
@@ -422,8 +400,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
public void handleDocumentEvent(DocumentEvent e) {
if (running && parsers.size() > 0) {
@@ -435,8 +412,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
* Called when the user clicks a hyperlink in a
* {@link org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip}.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
@@ -448,8 +424,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void insertUpdate(DocumentEvent e) {
@@ -473,10 +448,8 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Returns whether a parser notice contains the specified offset.
*
* @param notice
* The notice.
* @param offs
* The offset.
* @param notice The notice.
* @param offs The offset.
* @return Whether the notice contains the offset.
*/
private boolean noticeContainsPosition(ParserNotice notice, int offs) {
@@ -494,18 +467,16 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Since <code>viewToModel()</code> returns the <em>closest</em> model
* position, and the position doesn't <em>necessarily</em> contain the
* point passed in as an argument, this method checks whether the point is
* indeed contained in the view rectangle for the specified offset.
* Since <code>viewToModel()</code> returns the <em>closest</em> model position,
* and the position doesn't <em>necessarily</em> contain the point passed in as
* an argument, this method checks whether the point is indeed contained in the
* view rectangle for the specified offset.
*
* @param notice
* The parser notice.
* @param p
* The point possibly contained in the view range of the
* parser notice.
* @return Whether the parser notice actually contains the specified point
* in the view.
* @param notice The parser notice.
* @param p The point possibly contained in the view range of the parser
* notice.
* @return Whether the parser notice actually contains the specified point in
* the view.
*/
private boolean noticeContainsPointInView(ParserNotice notice, Point p) {
try {
@@ -547,8 +518,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Called when a property we're interested in changes.
*
* @param e
* The property change event.
* @param e The property change event.
*/
@Override
public void propertyChange(PropertyChangeEvent e) {
@@ -569,8 +539,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Removes a parser.
*
* @param parser
* The parser to remove.
* @param parser The parser to remove.
* @return Whether the parser was found.
* @see #addParser(Parser)
* @see #getParser(int)
@@ -585,11 +554,10 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Removes all parser notices (and clears highlights in the editor) from
* a particular parser.
* Removes all parser notices (and clears highlights in the editor) from a
* particular parser.
*
* @param parser
* The parser.
* @param parser The parser.
*/
private void removeParserNotices(Parser parser) {
if (noticeHighlightPairs != null) {
@@ -605,12 +573,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Removes any currently stored notices (and the corresponding highlights
* from the editor) from the same Parser, and in the given line range,
* as in the results.
* Removes any currently stored notices (and the corresponding highlights from
* the editor) from the same Parser, and in the given line range, as in the
* results.
*
* @param res
* The results.
* @param res The results.
*/
private void removeParserNotices(ParseResult res) {
if (noticeHighlightPairs != null) {
@@ -636,8 +603,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void removeUpdate(DocumentEvent e) {
@@ -670,12 +636,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Sets the delay between the last "concurrent" edit and when the document
* is re-parsed.
* Sets the delay between the last "concurrent" edit and when the document is
* re-parsed.
*
* @param millis
* The new delay, in milliseconds. This must be greater
* than <code>0</code>.
* @param millis The new delay, in milliseconds. This must be greater than
* <code>0</code>.
* @see #getDelay()
*/
public void setDelay(int millis) {
@@ -690,18 +655,16 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
/**
* Returns whether a parser notice should be removed, based on a parse
* result.
* Returns whether a parser notice should be removed, based on a parse result.
*
* @param notice
* The notice in question.
* @param res
* The result.
* @param notice The notice in question.
* @param res The result.
* @return Whether the notice should be removed.
*/
private boolean shouldRemoveNotice(ParserNotice notice, ParseResult res) {
if (DEBUG_PARSING) {
System.out.println("[DEBUG]: ... ... shouldRemoveNotice " + notice + ": " + (notice.getParser() == res.getParser()));
System.out.println(
"[DEBUG]: ... ... shouldRemoveNotice " + notice + ": " + (notice.getParser() == res.getParser()));
}
// NOTE: We must currently remove all notices for the parser. Parser
// implementors are required to parse the entire document each parsing
@@ -12,8 +12,8 @@ import javax.swing.JWindow;
/**
* A hook allowing hosting applications to decorate JWindows created by the
* AutoComplete library. For example, you could use the
* <a href="http://jgoodies.com/">JGoodies</a> library to add drop shadows
* to the windows.
* <a href="http://jgoodies.com/">JGoodies</a> library to add drop shadows to
* the windows.
*
* @author Robert Futrell
* @version 1.0
@@ -27,20 +27,18 @@ public abstract class PopupWindowDecorator {
/**
* Callback called whenever an appropriate JWindow is created by the
* AutoComplete library. Implementations can decorate the window however
* they see fit.
* AutoComplete library. Implementations can decorate the window however they
* see fit.
*
* @param window
* The newly-created window.
* @param window The newly-created window.
*/
public abstract void decorate(JWindow window);
/**
* Returns the singleton instance of this class. This should only be
* called on the EDT.
* Returns the singleton instance of this class. This should only be called on
* the EDT.
*
* @return The singleton instance of this class, or <code>null</code>
* for none.
* @return The singleton instance of this class, or <code>null</code> for none.
* @see #set(PopupWindowDecorator)
*/
public static PopupWindowDecorator get() {
@@ -48,11 +46,10 @@ public abstract class PopupWindowDecorator {
}
/**
* Sets the singleton instance of this class. This should only be called
* on the EDT.
* Sets the singleton instance of this class. This should only be called on the
* EDT.
*
* @param decorator
* The new instance of this class. This may be
* @param decorator The new instance of this class. This may be
* <code>null</code>.
* @see #get()
*/
+18 -26
View File
@@ -22,20 +22,16 @@ interface RSTAView {
* Returns the y-coordinate of the specified line.
* <p>
*
* This method is quicker than using traditional
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
* computed.
* This method is quicker than using traditional <code>modelToView(int)</code>
* calls, as the entire bounding box isn't computed.
*
* @param alloc
* The area the text area can render into.
* @param line
* The line number.
* @return The y-coordinate of the top of the line, or <code>-1</code> if
* this text area doesn't yet have a positive size or the line is
* hidden (i.e. from folding).
* @throws BadLocationException
* If <code>line</code> isn't a valid line
* number for this document.
* @param alloc The area the text area can render into.
* @param line The line number.
* @return The y-coordinate of the top of the line, or <code>-1</code> if this
* text area doesn't yet have a positive size or the line is hidden
* (i.e. from folding).
* @throws BadLocationException If <code>line</code> isn't a valid line number
* for this document.
*/
int yForLine(Rectangle alloc, int line) throws BadLocationException;
@@ -43,20 +39,16 @@ interface RSTAView {
* Returns the y-coordinate of the line containing a specified offset.
* <p>
*
* This method is quicker than using traditional
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
* computed.
* This method is quicker than using traditional <code>modelToView(int)</code>
* calls, as the entire bounding box isn't computed.
*
* @param alloc
* The area the text area can render into.
* @param offs
* The offset info the document.
* @return The y-coordinate of the top of the offset, or <code>-1</code> if
* this text area doesn't yet have a positive size or the line is
* hidden (i.e. from folding).
* @throws BadLocationException
* If <code>offs</code> isn't a valid offset
* into the document.
* @param alloc The area the text area can render into.
* @param offs The offset info the document.
* @return The y-coordinate of the top of the offset, or <code>-1</code> if this
* text area doesn't yet have a positive size or the line is hidden
* (i.e. from folding).
* @throws BadLocationException If <code>offs</code> isn't a valid offset into
* the document.
*/
int yForLineContaining(Rectangle alloc, int offs) throws BadLocationException;
}
@@ -51,8 +51,7 @@ import me.ByteEdit.edit.JavaAssemblyTokenMaker;
public class RSyntaxDocument extends RDocument implements Iterable<Token>, SyntaxConstants {
/**
* Creates a {@link TokenMaker} appropriate for a given programming
* language.
* Creates a {@link TokenMaker} appropriate for a given programming language.
*/
private transient TokenMakerFactory tokenMakerFactory;
/**
@@ -64,8 +63,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
*/
private String syntaxStyle;
/**
* Array of values representing the "last token type" on each line. This is
* used
* Array of values representing the "last token type" on each line. This is used
* in cases such as multi-line comments: if the previous line ended with an
* (unclosed) multi-line comment, we can use this knowledge and start the
* current line's syntax highlighting in multi-line comment state.
@@ -77,35 +75,28 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
private transient int tokenRetrievalCount = 0;
private transient Segment s;
/**
* If this is set to <code>true</code>, debug information about how much
* token
* If this is set to <code>true</code>, debug information about how much token
* caching is helping is printed to stdout.
*/
private static final boolean DEBUG_TOKEN_CACHING = false;
/**
* Constructs a plain text document. A default root element is created, and
* the
* Constructs a plain text document. A default root element is created, and the
* tab size set to 5.
*
* @param syntaxStyle
* The syntax highlighting scheme to use.
* @param syntaxStyle The syntax highlighting scheme to use.
*/
public RSyntaxDocument(String syntaxStyle) {
this(null, syntaxStyle);
}
/**
* Constructs a plain text document. A default root element is created, and
* the
* Constructs a plain text document. A default root element is created, and the
* tab size set to 5.
*
* @param tmf
* The <code>TokenMakerFactory</code> for this document. If this
* is
* <code>null</code>, a default factory is used.
* @param syntaxStyle
* The syntax highlighting scheme to use.
* @param tmf The <code>TokenMakerFactory</code> for this document. If
* this is <code>null</code>, a default factory is used.
* @param syntaxStyle The syntax highlighting scheme to use.
*/
public RSyntaxDocument(TokenMakerFactory tmf, String syntaxStyle) {
putProperty(tabSizeAttribute, Integer.valueOf(5));
@@ -117,25 +108,21 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Alerts all listeners to this document of an insertion. This is overridden
* so
* Alerts all listeners to this document of an insertion. This is overridden so
* we can update our syntax highlighting stuff.
* <p>
* The syntax highlighting stuff has to be here instead of in
* <code>insertUpdate</code> because <code>insertUpdate</code> is not called
* by
* <code>insertUpdate</code> because <code>insertUpdate</code> is not called by
* the undo/redo actions, but this method is.
*
* @param e
* The change.
* @param e The change.
*/
@Override
protected void fireInsertUpdate(DocumentEvent e) {
cachedTokenList = null;
/*
* Now that the text is actually inserted into the content and element
* structure, we can update our token elements and
* "last tokens on lines"
* structure, we can update our token elements and "last tokens on lines"
* structure.
*/
Element lineMap = getDefaultRootElement();
@@ -176,21 +163,18 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* This method is called AFTER the content has been inserted into the
* document
* This method is called AFTER the content has been inserted into the document
* and the element structure has been updated.
* <p>
* The syntax-highlighting updates need to be done here (as opposed to an
* override of <code>postRemoveUpdate</code>) as this method is called in
* response to undo/redo events, whereas <code>postRemoveUpdate</code> is
* not.
* response to undo/redo events, whereas <code>postRemoveUpdate</code> is not.
* <p>
* Now that the text is actually inserted into the content and element
* structure, we can update our token elements and "last tokens on lines"
* structure.
*
* @param chng
* The change that occurred.
* @param chng The change that occurred.
* @see #removeUpdate
*/
@Override
@@ -245,10 +229,8 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
* Returns the closest {@link TokenTypes "standard" token type} for a given
* "internal" token type (e.g. one whose value is <code>&lt; 0</code>).
*
* @param type
* The token type.
* @return The closest "standard" token type. If a mapping is not defined
* for
* @param type The token type.
* @return The closest "standard" token type. If a mapping is not defined for
* this language, then <code>type</code> is returned.
*/
public int getClosestStandardTokenTypeForInternalType(int type) {
@@ -256,10 +238,8 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Returns whether closing markup tags should be automatically completed.
* This
* method only returns <code>true</code> if {@link #getLanguageIsMarkup()}
* also
* Returns whether closing markup tags should be automatically completed. This
* method only returns <code>true</code> if {@link #getLanguageIsMarkup()} also
* returns <code>true</code>.
*
* @return Whether markup closing tags should be automatically completed.
@@ -274,12 +254,11 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
* Returns whether the current programming language uses curly braces
* ('<code>{</code>' and '<code>}</code>') to denote code blocks.
*
* @param languageIndex
* The language index at the offset in question. Since some
* <code>TokenMaker</code>s effectively have nested languages
* (such
* as JavaScript in HTML), this parameter tells the
* <code>TokenMaker</code> what sub-language to look at.
* @param languageIndex The language index at the offset in question. Since some
* <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter
* tells the <code>TokenMaker</code> what sub-language to
* look at.
* @return Whether curly braces denote code blocks.
*/
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex) {
@@ -287,8 +266,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Returns whether the current language is a markup language, such as HTML,
* XML
* Returns whether the current language is a markup language, such as HTML, XML
* or PHP.
*
* @return Whether the current language is a markup language.
@@ -300,10 +278,8 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
/**
* Returns the token type of the last token on the given line.
*
* @param line
* The line to inspect.
* @return The token type of the last token on the specified line. If the
* line
* @param line The line to inspect.
* @return The token type of the last token on the specified line. If the line
* is invalid, an exception is thrown.
*/
public int getLastTokenTypeOnLine(int line) {
@@ -311,15 +287,12 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Returns the text to place at the beginning and end of a line to "comment"
* it
* Returns the text to place at the beginning and end of a line to "comment" it
* in this programming language.
*
* @return The start and end strings to add to a line to "comment" it out. A
* <code>null</code> value for either means there is no string to
* add
* for that part. A value of <code>null</code> for the array means
* this
* <code>null</code> value for either means there is no string to add
* for that part. A value of <code>null</code> for the array means this
* language does not support commenting/uncommenting lines.
*/
public String[] getLineCommentStartAndEnd(int languageIndex) {
@@ -327,14 +300,11 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Returns whether tokens of the specified type should have "mark
* occurrences"
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @param type The token type.
* @return Whether tokens of this type should have "mark occurrences" enabled.
*/
boolean getMarkOccurrencesOfTokenType(int type) {
return tokenMaker.getMarkOccurrencesOfTokenType(type);
@@ -353,8 +323,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
* This method returns whether auto indentation should be done if Enter is
* pressed at the end of the specified line.
*
* @param line
* The line to check.
* @param line The line to check.
* @return Whether an extra indentation should be done.
*/
public boolean getShouldIndentNextLine(int line) {
@@ -376,12 +345,10 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
/**
* Returns a token list for the specified segment of text representing the
* specified line number. This method is basically a wrapper for
* <code>tokenMaker.getTokenList</code> that takes into account the last
* token
* <code>tokenMaker.getTokenList</code> that takes into account the last token
* on the previous line to assure token accuracy.
*
* @param line
* The line number of <code>text</code> in the document, &gt;= 0.
* @param line The line number of <code>text</code> in the document, &gt;= 0.
* @return A token list representing the specified line.
*/
public final Token getTokenListForLine(int line) {
@@ -424,14 +391,11 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
/**
* Returns whether a character could be part of an "identifier" token in a
* specific language. This is used to identify such things as the bounds of
* the
* specific language. This is used to identify such things as the bounds of the
* "word" to select on double-clicking.
*
* @param languageIndex
* The language index the character was found in.
* @param ch
* The character.
* @param languageIndex The language index the character was found in.
* @param ch The character.
* @return Whether the character could be part of an "identifier" token.
*/
public boolean isIdentifierChar(int languageIndex, char ch) {
@@ -439,10 +403,8 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Returns an iterator over the paintable tokens in this document. Results
* are
* undefined if this document is modified while the iterator is being
* iterated
* Returns an iterator over the paintable tokens in this document. Results are
* undefined if this document is modified while the iterator is being iterated
* through, so this should only be used on the EDT.
* <p>
*
@@ -459,8 +421,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
/**
* Deserializes a document.
*
* @param in
* The stream to read from.
* @param in The stream to read from.
* @throws ClassNotFoundException
* @throws IOException
*/
@@ -478,14 +439,11 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Makes our private <code>Segment s</code> point to the text in our
* document
* referenced by the specified element. Note that <code>line</code> MUST be
* a
* Makes our private <code>Segment s</code> point to the text in our document
* referenced by the specified element. Note that <code>line</code> MUST be a
* valid line number in the document.
*
* @param line
* The line number you want to get.
* @param line The line number you want to get.
*/
private void setSharedSegment(int line) {
Element map = getDefaultRootElement();
@@ -506,17 +464,14 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Sets the syntax style being used for syntax highlighting in this
* document.
* Sets the syntax style being used for syntax highlighting in this document.
* What styles are supported by a document is determined by its
* {@link TokenMakerFactory}. By default, all <code>RSyntaxDocument</code>s
* support all languages built into <code>RSyntaxTextArea</code>.
*
* @param styleKey
* The new style to use, such as
* @param styleKey The new style to use, such as
* {@link SyntaxConstants#SYNTAX_STYLE_JAVA}. If this style is
* not
* known or supported by this document, then
* not known or supported by this document, then
* {@link SyntaxConstants#SYNTAX_STYLE_NONE} is used.
* @see #setSyntaxStyle(TokenMaker)
* @see #getSyntaxStyle()
@@ -532,13 +487,11 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Sets the syntax style being used for syntax highlighting in this
* document.
* Sets the syntax style being used for syntax highlighting in this document.
* You should call this method if you've created a custom token maker for a
* language not normally supported by <code>RSyntaxTextArea</code>.
*
* @param tokenMaker
* The new token maker to use.
* @param tokenMaker The new token maker to use.
* @see #setSyntaxStyle(String)
*/
public void setSyntaxStyle(TokenMaker tokenMaker) {
@@ -550,9 +503,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
/**
* Sets the token maker factory used by this document.
*
* @param tmf
* The <code>TokenMakerFactory</code> for this document. If this
* is
* @param tmf The <code>TokenMakerFactory</code> for this document. If this is
* <code>null</code>, a default factory is used.
*/
public void setTokenMakerFactory(TokenMakerFactory tmf) {
@@ -560,20 +511,15 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
/**
* Loops through the last-tokens-on-lines array from a specified point
* onward,
* updating last-token values until they stop changing. This should be
* called
* when lines are updated/inserted/removed, as doing so may cause lines
* below to
* Loops through the last-tokens-on-lines array from a specified point onward,
* updating last-token values until they stop changing. This should be called
* when lines are updated/inserted/removed, as doing so may cause lines below to
* change color.
*
* @param line
* The first line to check for a change in last-token value.
* @param numLines
* The number of lines in the document.
* @param previousTokenType
* The last-token value of the line just before
* @param line The first line to check for a change in last-token
* value.
* @param numLines The number of lines in the document.
* @param previousTokenType The last-token value of the line just before
* <code>line</code>.
* @return The last line that needs repainting.
*/
File diff suppressed because it is too large. Load diff
@@ -27,8 +27,8 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* The highlighter implementation used by {@link RSyntaxTextArea}s. It knows to
* always paint "marked occurrences" highlights below selection highlights,
* and squiggle underline highlights above all other highlights.
* always paint "marked occurrences" highlights below selection highlights, and
* squiggle underline highlights above all other highlights.
* <p>
*
* Most of this code is copied from javax.swing.text.DefaultHighlighter;
@@ -40,13 +40,13 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
/**
* Marked occurrences in the document (to be painted separately from
* other highlights).
* Marked occurrences in the document (to be painted separately from other
* highlights).
*/
private List<SyntaxLayeredHighlightInfoImpl> markedOccurrences;
/**
* Highlights from document parsers. These should be painted "on top of"
* all other highlights to ensure they are always above the selection.
* Highlights from document parsers. These should be painted "on top of" all
* other highlights to ensure they are always above the selection.
*/
private List<SyntaxLayeredHighlightInfoImpl> parserHighlights;
/**
@@ -92,8 +92,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
/**
* Adds a highlight from a parser.
*
* @param notice
* The notice from a {@link Parser}.
* @param notice The notice from a {@link Parser}.
* @return A tag with which to reference the highlight.
* @throws BadLocationException
* @see #clearParserHighlights()
@@ -161,8 +160,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
/**
* Removes all of the highlights for a specific parser.
*
* @param parser
* The parser.
* @param parser The parser.
*/
public void clearParserHighlights(Parser parser) {
Iterator<SyntaxLayeredHighlightInfoImpl> i = parserHighlights.iterator();
@@ -188,8 +186,8 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
/**
* Returns a list of "marked occurrences" in the text area. If there are
* no marked occurrences, this will be an empty list.
* Returns a list of "marked occurrences" in the text area. If there are no
* marked occurrences, this will be an empty list.
*
* @return The list of marked occurrences, or an empty list if none. The
* contents of this list will be of type {@link DocumentRange}.
@@ -212,7 +210,8 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
@Override
public void paintLayeredHighlights(Graphics g, int lineStart, int lineEnd, Shape viewBounds, JTextComponent editor, View view) {
public void paintLayeredHighlights(Graphics g, int lineStart, int lineEnd, Shape viewBounds, JTextComponent editor,
View view) {
paintListLayered(g, lineStart, lineEnd, viewBounds, editor, view, markedOccurrences);
super.paintLayeredHighlights(g, lineStart, lineEnd, viewBounds, editor, view);
paintListLayered(g, lineStart, lineEnd, viewBounds, editor, view, parserHighlights);
@@ -221,8 +220,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
/**
* Removes a parser highlight from this view.
*
* @param tag
* The reference to the highlight.
* @param tag The reference to the highlight.
* @see #addParserHighlight(ParserNotice,
* javax.swing.text.Highlighter.HighlightPainter)
*/
@@ -232,8 +230,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
/**
* Highlight info implementation used for parser notices and marked
* occurrences.
* Highlight info implementation used for parser notices and marked occurrences.
*/
private static class SyntaxLayeredHighlightInfoImpl extends LayeredHighlightInfoImpl {
@@ -255,8 +252,8 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
@Override
public String toString() {
return "[SyntaxLayeredHighlightInfoImpl: " + "startOffs=" + getStartOffset() + ", endOffs=" + getEndOffset() + ", color="
+ getColor() + "]";
return "[SyntaxLayeredHighlightInfoImpl: " + "startOffs=" + getStartOffset() + ", endOffs=" + getEndOffset()
+ ", color=" + getColor() + "]";
}
}
}
@@ -27,8 +27,8 @@ import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaUI;
/**
* UI used by <code>RSyntaxTextArea</code>. This allows us to implement
* syntax highlighting.
* UI used by <code>RSyntaxTextArea</code>. This allows us to implement syntax
* highlighting.
*
* @author Robert Futrell
* @version 0.1
@@ -53,8 +53,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
/**
* Creates the view for an element.
*
* @param elem
* The element.
* @param elem The element.
* @return The view.
*/
@Override
@@ -84,9 +83,9 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
}
/**
* Returns the name to use to cache/fetch the shared action map. This
* should be overridden by subclasses if the subclass has its own custom
* editor kit to install, so its actions get picked up.
* Returns the name to use to cache/fetch the shared action map. This should be
* overridden by subclasses if the subclass has its own custom editor kit to
* install, so its actions get picked up.
*
* @return The name of the cached action map.
*/
@@ -98,8 +97,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
/**
* Fetches the EditorKit for the UI.
*
* @param tc
* The text component for which this UI is installed.
* @param tc The text component for which this UI is installed.
* @return The editor capabilities.
* @see javax.swing.plaf.TextUI#getEditorKit
*/
@@ -112,11 +110,11 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
* Get the InputMap to use for the UI.
* <p>
*
* This method is not named <code>getInputMap()</code> because there is
* a package-private method in <code>BasicTextAreaUI</code> with that name.
* Thus, creating a new method with that name causes certain compilers to
* issue warnings that you are not actually overriding the original method
* (since it is package-private).
* This method is not named <code>getInputMap()</code> because there is a
* package-private method in <code>BasicTextAreaUI</code> with that name. Thus,
* creating a new method with that name causes certain compilers to issue
* warnings that you are not actually overriding the original method (since it
* is package-private).
*/
@Override
protected InputMap getRTextAreaInputMap() {
@@ -142,8 +140,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
/**
* Paints the "matched bracket", if any.
*
* @param g
* The graphics context.
* @param g The graphics context.
*/
protected void paintMatchedBracket(Graphics g) {
RSyntaxTextArea rsta = (RSyntaxTextArea) textArea;
@@ -188,8 +185,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
* Gets called whenever a bound property is changed on this UI's
* <code>RSyntaxTextArea</code>.
*
* @param e
* The property change event.
* @param e The property change event.
*/
@Override
protected void propertyChange(PropertyChangeEvent e) {
@@ -217,9 +213,8 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
* Returns the y-coordinate of the specified line.
* <p>
*
* This method is quicker than using traditional
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
* computed.
* This method is quicker than using traditional <code>modelToView(int)</code>
* calls, as the entire bounding box isn't computed.
*/
@Override
public int yForLine(int line) throws BadLocationException {
@@ -60,13 +60,13 @@ public final class RSyntaxUtilities implements SwingConstants {
*/
public static final int OS_LINUX = 4;
/**
* Integer constant representing an "unknown" OS. 99.99% of the
* time, this means some UNIX variant (AIX, SunOS, etc.).
* Integer constant representing an "unknown" OS. 99.99% of the time, this means
* some UNIX variant (AIX, SunOS, etc.).
*/
public static final int OS_OTHER = 8;
/**
* Used for the color of hyperlinks when a LookAndFeel uses light text
* against a dark background.
* Used for the color of hyperlinks when a LookAndFeel uses light text against a
* dark background.
*/
private static final Color LIGHT_HYPERLINK_FG = new Color(0xd8ffff);
private static final int OS = getOSImpl();
@@ -79,12 +79,12 @@ public final class RSyntaxUtilities implements SwingConstants {
private static final int BRACKET_MASK = 64;
private static final int JAVA_OPERATOR_MASK = 128;
/**
* A lookup table used to quickly decide if a 16-bit Java char is a
* US-ASCII letter (A-Z or a-z), a digit, a whitespace char (either space
* (0x0020) or tab (0x0009)), etc. This method should be faster
* than <code>Character.isLetter</code>, <code>Character.isDigit</code>,
* and <code>Character.isWhitespace</code> because we know we are dealing
* with ASCII chars and so don't have to worry about code planes, etc.
* A lookup table used to quickly decide if a 16-bit Java char is a US-ASCII
* letter (A-Z or a-z), a digit, a whitespace char (either space (0x0020) or tab
* (0x0009)), etc. This method should be faster than
* <code>Character.isLetter</code>, <code>Character.isDigit</code>, and
* <code>Character.isWhitespace</code> because we know we are dealing with ASCII
* chars and so don't have to worry about code planes, etc.
*/
private static final int[] DATA_TABLE = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, // 0-15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
@@ -132,18 +132,17 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns a string with characters that are special to HTML (such as
* <code>&lt;</code>, <code>&gt;</code> and <code>&amp;</code>) replaced
* by their HTML escape sequences.
* <code>&lt;</code>, <code>&gt;</code> and <code>&amp;</code>) replaced by
* their HTML escape sequences.
*
* @param s
* The input string.
* @param newlineReplacement
* What to replace newline characters with.
* If this is <code>null</code>, they are simply removed.
* @param inPreBlock
* Whether this HTML will be in within <code>pre</code>
* tags. If this is <code>true</code>, spaces will be kept as-is;
* otherwise, they will be converted to "<code>&nbsp;</code>".
* @param s The input string.
* @param newlineReplacement What to replace newline characters with. If this is
* <code>null</code>, they are simply removed.
* @param inPreBlock Whether this HTML will be in within
* <code>pre</code> tags. If this is
* <code>true</code>, spaces will be kept as-is;
* otherwise, they will be converted to
* "<code>&nbsp;</code>".
* @return The escaped version of <code>s</code>.
*/
public static String escapeForHtml(String s, String newlineReplacement, boolean inPreBlock) {
@@ -209,8 +208,8 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the rendering hints for text that will most accurately reflect
* those of the native windowing system.
* Returns the rendering hints for text that will most accurately reflect those
* of the native windowing system.
*
* @return The rendering hints, or <code>null</code> if they cannot be
* determined.
@@ -222,8 +221,7 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the color to use for the line underneath a folded region line.
*
* @param textArea
* The text area.
* @param textArea The text area.
* @return The color to use.
*/
public static Color getFoldedLineBottomColor(RSyntaxTextArea textArea) {
@@ -236,13 +234,12 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the gutter component of the scroll pane containing a text
* area, if any.
* Returns the gutter component of the scroll pane containing a text area, if
* any.
*
* @param textArea
* The text area.
* @return The gutter, or <code>null</code> if the text area is not in
* an {@link RTextScrollPane}.
* @param textArea The text area.
* @return The gutter, or <code>null</code> if the text area is not in an
* {@link RTextScrollPane}.
* @see RTextScrollPane#getGutter()
*/
public static Gutter getGutter(RTextArea textArea) {
@@ -259,10 +256,10 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the color to use for hyperlink-style components. This method
* will return <code>Color.blue</code> unless it appears that the current
* LookAndFeel uses light text on a dark background, in which case a
* brighter alternative is returned.
* Returns the color to use for hyperlink-style components. This method will
* return <code>Color.blue</code> unless it appears that the current LookAndFeel
* uses light text on a dark background, in which case a brighter alternative is
* returned.
*
* @return The color to use for hyperlinks.
* @see #isLightForeground(Color)
@@ -280,8 +277,7 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the leading whitespace of a string.
*
* @param text
* The String to check.
* @param text The String to check.
* @return The leading whitespace.
* @see #getLeadingWhitespace(Document, int)
*/
@@ -297,14 +293,11 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the leading whitespace of a specific line in a document.
*
* @param doc
* The document.
* @param offs
* The offset whose line to get the leading whitespace for.
* @param doc The document.
* @param offs The offset whose line to get the leading whitespace for.
* @return The leading whitespace.
* @throws BadLocationException
* If <code>offs</code> is not a valid offset
* in the document.
* @throws BadLocationException If <code>offs</code> is not a valid offset in
* the document.
* @see #getLeadingWhitespace(String)
*/
public static String getLeadingWhitespace(Document doc, int offs) throws BadLocationException {
@@ -328,43 +321,35 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the bounding box (in the current view) of a specified position
* in the model. This method is designed for line-wrapped views to use,
* as it allows you to specify a "starting position" in the line, from
* which the x-value is assumed to be zero. The idea is that you specify
* the first character in a physical line as <code>p0</code>, as this is
* the character where the x-pixel value is 0.
* Returns the bounding box (in the current view) of a specified position in the
* model. This method is designed for line-wrapped views to use, as it allows
* you to specify a "starting position" in the line, from which the x-value is
* assumed to be zero. The idea is that you specify the first character in a
* physical line as <code>p0</code>, as this is the character where the x-pixel
* value is 0.
*
* @param textArea
* The text area containing the text.
* @param s
* A segment in which to load the line. This is passed in so we
* @param textArea The text area containing the text.
* @param s A segment in which to load the line. This is passed in so we
* don't have to reallocate a new <code>Segment</code> for each
* call.
* @param p0
* The starting position in the physical line in the document.
* @param p1
* The position for which to get the bounding box in the view.
* @param e
* How to expand tabs.
* @param rect
* The rectangle whose x- and width-values are changed to
* @param p0 The starting position in the physical line in the document.
* @param p1 The position for which to get the bounding box in the view.
* @param e How to expand tabs.
* @param rect The rectangle whose x- and width-values are changed to
* represent the bounding box of <code>p1</code>. This is reused
* to keep from needlessly reallocating Rectangles.
* @param x0
* The x-coordinate (pixel) marking the left-hand border of the
* @param x0 The x-coordinate (pixel) marking the left-hand border of the
* text. This is useful if the text area has a border, for
* example.
* @return The bounding box in the view of the character <code>p1</code>.
* @throws BadLocationException
* If <code>p0</code> or <code>p1</code> is
* not a valid location in the specified text area's document.
* @throws IllegalArgumentException
* If <code>p0</code> and <code>p1</code>
* are not on the same line.
* @throws BadLocationException If <code>p0</code> or <code>p1</code> is not
* a valid location in the specified text
* area's document.
* @throws IllegalArgumentException If <code>p0</code> and <code>p1</code> are
* not on the same line.
*/
public static Rectangle getLineWidthUpTo(RSyntaxTextArea textArea, Segment s, int p0, int p1, TabExpander e, Rectangle rect, int x0)
throws BadLocationException {
public static Rectangle getLineWidthUpTo(RSyntaxTextArea textArea, Segment s, int p0, int p1, TabExpander e,
Rectangle rect, int x0) throws BadLocationException {
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
// Ensure p0 and p1 are valid document positions.
if (p0 < 0) {
@@ -394,20 +379,17 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the location of the bracket paired with the one at the current
* caret position.
* Returns the location of the bracket paired with the one at the current caret
* position.
*
* @param textArea
* The text area.
* @param input
* A point to use as the return value. If this is
* @param textArea The text area.
* @param input A point to use as the return value. If this is
* <code>null</code>, a new object is created and returned.
* @return A point representing the matched bracket info. The "x" field
* is the offset of the bracket at the caret position (either just
* before or just after the caret), and the "y" field is the offset
* of the matched bracket. Both "x" and "y" will be
* <code>-1</code> if there isn't a matching bracket (or the caret
* isn't on a bracket).
* @return A point representing the matched bracket info. The "x" field is the
* offset of the bracket at the caret position (either just before or
* just after the caret), and the "y" field is the offset of the matched
* bracket. Both "x" and "y" will be <code>-1</code> if there isn't a
* matching bracket (or the caret isn't on a bracket).
*/
public static Point getMatchingBracketPosition(RSyntaxTextArea textArea, Point input) {
if (input == null) {
@@ -491,7 +473,8 @@ public final class RSyntaxUtilities implements SwingConstants {
token = RSyntaxUtilities.getTokenAtOffset(token, offset);
if (token.getType() == Token.SEPARATOR && token.getLanguageIndex() == languageIndex) {
if (numEmbedded == 0) {
if (textArea.isCodeFoldingEnabled() && textArea.getFoldManager().isLineHidden(curLine)) {
if (textArea.isCodeFoldingEnabled()
&& textArea.getFoldManager().isLineHidden(curLine)) {
return input; // Match hidden in a fold
}
input.setLocation(caretPosition, offset);
@@ -579,14 +562,11 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the next non-whitespace, non-comment token in a text area.
*
* @param t
* The next token in this line's token list.
* @param textArea
* The text area.
* @param line
* The current line index (the line index of <code>t</code>).
* @return The next non-whitespace, non-comment token, or <code>null</code>
* if there isn't one.
* @param t The next token in this line's token list.
* @param textArea The text area.
* @param line The current line index (the line index of <code>t</code>).
* @return The next non-whitespace, non-comment token, or <code>null</code> if
* there isn't one.
* @see #getPreviousImportantToken(RSyntaxDocument, int)
* @see #getPreviousImportantTokenFromOffs(RSyntaxDocument, int)
*/
@@ -602,11 +582,10 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Provides a way to determine the next visually represented model
* location at which one might place a caret.
* Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
* Provides a way to determine the next visually represented model location at
* which one might place a caret. Some views may not be visible, they might not
* be in the same order found in the model, or they just might not allow access
* to some of the locations in the model.
* <p>
*
* NOTE: You should only call this method if the passed-in
@@ -614,29 +593,25 @@ public final class RSyntaxUtilities implements SwingConstants {
* {@link TokenOrientedView} and <code>javax.swing.text.TabExpander</code>;
* otherwise, a <code>ClassCastException</code> could be thrown.
*
* @param pos
* the position to convert &gt;= 0
* @param a
* the allocated region in which to render
* @param direction
* the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard.
* This will be one of the following values:
* @param pos the position to convert &gt;= 0
* @param a the allocated region in which to render
* @param direction the direction from the current position that can be thought
* of as the arrow keys typically found on a keyboard. This
* will be one of the following values:
* <ul>
* <li>SwingConstants.WEST
* <li>SwingConstants.EAST
* <li>SwingConstants.NORTH
* <li>SwingConstants.SOUTH
* </ul>
* @return the location within the model that best represents the next
* location visual position
* @return the location within the model that best represents the next location
* visual position
* @exception BadLocationException
* @exception IllegalArgumentException
* if <code>direction</code>
* doesn't have one of the legal values above
* @exception IllegalArgumentException if <code>direction</code> doesn't have
* one of the legal values above
*/
public static int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet, View view)
throws BadLocationException {
public static int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction,
Position.Bias[] biasRet, View view) throws BadLocationException {
RSyntaxTextArea target = (RSyntaxTextArea) view.getContainer();
biasRet[0] = Position.Bias.Forward;
// Do we want the "next position" above, below, to the left or right?
@@ -681,7 +656,8 @@ public final class RSyntaxUtilities implements SwingConstants {
if (last != current) { // If moving up a line...
FoldManager fm = target.getFoldManager();
if (fm.isLineHidden(current)) {
while (--current > 0 && fm.isLineHidden(current));
while (--current > 0 && fm.isLineHidden(current))
;
pos = target.getLineEndOffset(current) - 1;
}
}
@@ -700,7 +676,8 @@ public final class RSyntaxUtilities implements SwingConstants {
FoldManager fm = target.getFoldManager();
if (fm.isLineHidden(current)) {
int lineCount = target.getLineCount();
while (++current < lineCount && fm.isLineHidden(current));
while (++current < lineCount && fm.isLineHidden(current))
;
pos = current == lineCount ? target.getLineEndOffset(last) - 1 : // Was
// the
// last
@@ -720,8 +697,8 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns an integer constant representing the OS. This can be handy for
* special case situations such as Mac OS-X (special application
* registration) or Windows (allow mixed case, etc.).
* special case situations such as Mac OS-X (special application registration)
* or Windows (allow mixed case, etc.).
*
* @return An integer constant representing the OS.
*/
@@ -731,8 +708,8 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns an integer constant representing the OS. This can be handy for
* special case situations such as Mac OS-X (special application
* registration) or Windows (allow mixed case, etc.).
* special case situations such as Mac OS-X (special application registration)
* or Windows (allow mixed case, etc.).
*
* @return An integer constant representing the OS.
*/
@@ -757,10 +734,8 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the flags necessary to create a {@link Pattern}.
*
* @param matchCase
* Whether the pattern should be case sensitive.
* @param others
* Any other flags. This may be <code>0</code>.
* @param matchCase Whether the pattern should be case sensitive.
* @param others Any other flags. This may be <code>0</code>.
* @return The flags.
*/
public static int getPatternFlags(boolean matchCase, int others) {
@@ -771,23 +746,20 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Determines the position in the model that is closest to the given
* view location in the row above. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
* Determines the position in the model that is closest to the given view
* location in the row above. The component given must have a size to compute
* the result. If the component doesn't have a size a value of -1 will be
* returned.
*
* @param c
* the editor
* @param offs
* the offset in the document &gt;= 0
* @param x
* the X coordinate &gt;= 0
* @return the position &gt;= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException
* if the offset is out of range
* @param c the editor
* @param offs the offset in the document &gt;= 0
* @param x the X coordinate &gt;= 0
* @return the position &gt;= 0 if the request can be computed, otherwise a
* value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static int getPositionAbove(RSyntaxTextArea c, int offs, float x, TabExpander e) throws BadLocationException {
public static int getPositionAbove(RSyntaxTextArea c, int offs, float x, TabExpander e)
throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView) e;
Token token = tov.getTokenListForPhysicalLineAbove(offs);
if (token == null) {
@@ -801,23 +773,20 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Determines the position in the model that is closest to the given
* view location in the row below. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
* Determines the position in the model that is closest to the given view
* location in the row below. The component given must have a size to compute
* the result. If the component doesn't have a size a value of -1 will be
* returned.
*
* @param c
* the editor
* @param offs
* the offset in the document &gt;= 0
* @param x
* the X coordinate &gt;= 0
* @return the position &gt;= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException
* if the offset is out of range
* @param c the editor
* @param offs the offset in the document &gt;= 0
* @param x the X coordinate &gt;= 0
* @return the position &gt;= 0 if the request can be computed, otherwise a
* value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static int getPositionBelow(RSyntaxTextArea c, int offs, float x, TabExpander e) throws BadLocationException {
public static int getPositionBelow(RSyntaxTextArea c, int offs, float x, TabExpander e)
throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView) e;
Token token = tov.getTokenListForPhysicalLineBelow(offs);
if (token == null) {
@@ -838,12 +807,10 @@ public final class RSyntaxUtilities implements SwingConstants {
* Returns the last non-whitespace, non-comment token, starting with the
* specified line.
*
* @param doc
* The document.
* @param line
* The line at which to start looking.
* @return The last non-whitespace, non-comment token, or <code>null</code>
* if there isn't one.
* @param doc The document.
* @param line The line at which to start looking.
* @return The last non-whitespace, non-comment token, or <code>null</code> if
* there isn't one.
* @see #getNextImportantToken(Token, RSyntaxTextArea, int)
* @see #getPreviousImportantTokenFromOffs(RSyntaxDocument, int)
*/
@@ -862,15 +829,13 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the last non-whitespace, non-comment token, before the
* specified offset.
* Returns the last non-whitespace, non-comment token, before the specified
* offset.
*
* @param doc
* The document.
* @param offs
* The ending offset for the search.
* @return The last non-whitespace, non-comment token, or <code>null</code>
* if there isn't one.
* @param doc The document.
* @param offs The ending offset for the search.
* @return The last non-whitespace, non-comment token, or <code>null</code> if
* there isn't one.
* @see #getPreviousImportantToken(RSyntaxDocument, int)
* @see #getNextImportantToken(Token, RSyntaxTextArea, int)
*/
@@ -896,10 +861,8 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the token at the specified offset.
*
* @param textArea
* The text area.
* @param offset
* The offset of the token.
* @param textArea The text area.
* @param offset The offset of the token.
* @return The token, or <code>null</code> if the offset is not valid.
* @see #getTokenAtOffset(RSyntaxDocument, int)
* @see #getTokenAtOffset(Token, int)
@@ -912,10 +875,8 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the token at the specified offset.
*
* @param doc
* The document.
* @param offset
* The offset of the token.
* @param doc The document.
* @param offset The offset of the token.
* @return The token, or <code>null</code> if the offset is not valid.
* @see #getTokenAtOffset(RSyntaxTextArea, int)
* @see #getTokenAtOffset(Token, int)
@@ -928,17 +889,15 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns the token at the specified index, or <code>null</code> if
* the given offset isn't in this token list's range.<br>
* Note that this method does NOT check to see if <code>tokenList</code>
* is null; callers should check for themselves.
* Returns the token at the specified index, or <code>null</code> if the given
* offset isn't in this token list's range.<br>
* Note that this method does NOT check to see if <code>tokenList</code> is
* null; callers should check for themselves.
*
* @param tokenList
* The list of tokens in which to search.
* @param offset
* The offset at which to get the token.
* @return The token at <code>offset</code>, or <code>null</code> if
* none of the tokens are at that offset.
* @param tokenList The list of tokens in which to search.
* @param offset The offset at which to get the token.
* @return The token at <code>offset</code>, or <code>null</code> if none of the
* tokens are at that offset.
* @see #getTokenAtOffset(RSyntaxTextArea, int)
* @see #getTokenAtOffset(RSyntaxDocument, int)
*/
@@ -954,13 +913,10 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the end of the word at the given offset.
*
* @param textArea
* The text area.
* @param offs
* The offset into the text area's content.
* @param textArea The text area.
* @param offs The offset into the text area's content.
* @return The end offset of the word.
* @throws BadLocationException
* If <code>offs</code> is invalid.
* @throws BadLocationException If <code>offs</code> is invalid.
* @see #getWordStart(RSyntaxTextArea, int)
*/
public static int getWordEnd(RSyntaxTextArea textArea, int offs) throws BadLocationException {
@@ -976,9 +932,11 @@ public final class RSyntaxUtilities implements SwingConstants {
int count = s.length();
char ch = s.charAt(i);
if (Character.isWhitespace(ch)) {
while (i < count && Character.isWhitespace(s.charAt(i++)));
while (i < count && Character.isWhitespace(s.charAt(i++)))
;
} else if (Character.isLetterOrDigit(ch)) {
while (i < count && Character.isLetterOrDigit(s.charAt(i++)));
while (i < count && Character.isLetterOrDigit(s.charAt(i++)))
;
} else {
i = 2;
}
@@ -990,13 +948,10 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns the start of the word at the given offset.
*
* @param textArea
* The text area.
* @param offs
* The offset into the text area's content.
* @param textArea The text area.
* @param offs The offset into the text area's content.
* @return The start offset of the word.
* @throws BadLocationException
* If <code>offs</code> is invalid.
* @throws BadLocationException If <code>offs</code> is invalid.
* @see #getWordEnd(RSyntaxTextArea, int)
*/
public static int getWordStart(RSyntaxTextArea textArea, int offs) throws BadLocationException {
@@ -1030,20 +985,17 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Determines the width of the given token list taking tabs
* into consideration. This is implemented in a 1.1 style coordinate
* system where ints are used and 72dpi is assumed.
* Determines the width of the given token list taking tabs into consideration.
* This is implemented in a 1.1 style coordinate system where ints are used and
* 72dpi is assumed.
* <p>
*
* This method also assumes that the passed-in token list begins at
* x-pixel <code>0</code> in the view (for tab purposes).
* This method also assumes that the passed-in token list begins at x-pixel
* <code>0</code> in the view (for tab purposes).
*
* @param tokenList
* The tokenList list representing the text.
* @param textArea
* The text area in which this token list resides.
* @param e
* The tab expander. This value cannot be <code>null</code>.
* @param tokenList The tokenList list representing the text.
* @param textArea The text area in which this token list resides.
* @param e The tab expander. This value cannot be <code>null</code>.
* @return The width of the token list, in pixels.
*/
public static float getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, TabExpander e) {
@@ -1051,19 +1003,15 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Determines the width of the given token list taking tabs
* into consideration. This is implemented in a 1.1 style coordinate
* system where ints are used and 72dpi is assumed.
* Determines the width of the given token list taking tabs into consideration.
* This is implemented in a 1.1 style coordinate system where ints are used and
* 72dpi is assumed.
* <p>
*
* @param tokenList
* The token list list representing the text.
* @param textArea
* The text area in which this token list resides.
* @param e
* The tab expander. This value cannot be <code>null</code>.
* @param x0
* The x-pixel coordinate of the start of the token list.
* @param tokenList The token list list representing the text.
* @param textArea The text area in which this token list resides.
* @param e The tab expander. This value cannot be <code>null</code>.
* @param x0 The x-pixel coordinate of the start of the token list.
* @return The width of the token list, in pixels.
* @see #getTokenListWidthUpTo
*/
@@ -1076,29 +1024,24 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Determines the width of the given token list taking tabs into
* consideration and only up to the given index in the document
* (exclusive).
* Determines the width of the given token list taking tabs into consideration
* and only up to the given index in the document (exclusive).
*
* @param tokenList
* The token list representing the text.
* @param textArea
* The text area in which this token list resides.
* @param e
* The tab expander. This value cannot be <code>null</code>.
* @param x0
* The x-pixel coordinate of the start of the token list.
* @param upTo
* The document position at which you want to stop,
* exclusive. If this position is before the starting position
* of the token list, a width of <code>0</code> will be
* returned; similarly, if this position comes after the entire
* token list, the width of the entire token list is returned.
* @return The width of the token list, in pixels, up to, but not
* including, the character at position <code>upTo</code>.
* @param tokenList The token list representing the text.
* @param textArea The text area in which this token list resides.
* @param e The tab expander. This value cannot be <code>null</code>.
* @param x0 The x-pixel coordinate of the start of the token list.
* @param upTo The document position at which you want to stop, exclusive.
* If this position is before the starting position of the
* token list, a width of <code>0</code> will be returned;
* similarly, if this position comes after the entire token
* list, the width of the entire token list is returned.
* @return The width of the token list, in pixels, up to, but not including, the
* character at position <code>upTo</code>.
* @see #getTokenListWidth
*/
public static float getTokenListWidthUpTo(final Token tokenList, RSyntaxTextArea textArea, TabExpander e, float x0, int upTo) {
public static float getTokenListWidthUpTo(final Token tokenList, RSyntaxTextArea textArea, TabExpander e, float x0,
int upTo) {
float width = 0;
for (Token t = tokenList; t != null && t.isPaintable(); t = t.getNextToken()) {
if (t.containsPosition(upTo)) {
@@ -1110,13 +1053,12 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether or not this character is a "bracket" to be matched by
* such programming languages as C, C++, and Java.
* Returns whether or not this character is a "bracket" to be matched by such
* programming languages as C, C++, and Java.
*
* @param ch
* The character to check.
* @return Whether or not the character is a "bracket" - one of '(', ')',
* '[', ']', '{', and '}'.
* @param ch The character to check.
* @return Whether or not the character is a "bracket" - one of '(', ')', '[',
* ']', '{', and '}'.
*/
public static boolean isBracket(char ch) {
// We need the first condition as it might be that ch>255, and thus
@@ -1128,8 +1070,7 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns whether or not a character is a digit (0-9).
*
* @param ch
* The character to check.
* @param ch The character to check.
* @return Whether or not the character is a digit.
*/
public static boolean isDigit(char ch) {
@@ -1140,13 +1081,11 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether or not this character is a hex character. This method
* accepts both upper- and lower-case letters a-f.
* Returns whether or not this character is a hex character. This method accepts
* both upper- and lower-case letters a-f.
*
* @param ch
* The character to check.
* @return Whether or not the character is a hex character 0-9, a-f, or
* A-F.
* @param ch The character to check.
* @return Whether or not the character is a hex character 0-9, a-f, or A-F.
*/
public static boolean isHexCharacter(char ch) {
// We need the first condition as it could be that ch>255 (and thus
@@ -1156,11 +1095,10 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether a character is a Java operator. Note that C and C++
* operators are the same as Java operators.
* Returns whether a character is a Java operator. Note that C and C++ operators
* are the same as Java operators.
*
* @param ch
* The character to check.
* @param ch The character to check.
* @return Whether or not the character is a Java operator.
*/
public static boolean isJavaOperator(char ch) {
@@ -1173,8 +1111,7 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns whether a character is a US-ASCII letter (A-Z or a-z).
*
* @param ch
* The character to check.
* @param ch The character to check.
* @return Whether or not the character is a US-ASCII letter.
*/
public static boolean isLetter(char ch) {
@@ -1186,8 +1123,7 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Returns whether or not a character is a US-ASCII letter or a digit.
*
* @param ch
* The character to check.
* @param ch The character to check.
* @return Whether or not the character is a US-ASCII letter or a digit.
*/
public static boolean isLetterOrDigit(char ch) {
@@ -1197,12 +1133,11 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether the specified color is "light" to use as a foreground.
* Colors that return <code>true</code> indicate that the current Look and
* Feel probably uses light text colors on a dark background.
* Returns whether the specified color is "light" to use as a foreground. Colors
* that return <code>true</code> indicate that the current Look and Feel
* probably uses light text colors on a dark background.
*
* @param fg
* The foreground color.
* @param fg The foreground color.
* @return Whether it is a "light" foreground color.
* @see #getHyperlinkForeground()
*/
@@ -1211,14 +1146,13 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether the specified token is a single non-word char (e.g. not
* in <code>[A-Za-z]</code>. This is a HACK to work around the fact that
* many standard token makers return things like semicolons and periods as
* {@link Token#IDENTIFIER}s just to make the syntax highlighting coloring
* look a little better.
* Returns whether the specified token is a single non-word char (e.g. not in
* <code>[A-Za-z]</code>. This is a HACK to work around the fact that many
* standard token makers return things like semicolons and periods as
* {@link Token#IDENTIFIER}s just to make the syntax highlighting coloring look
* a little better.
*
* @param t
* The token to check. This cannot be <code>null</code>.
* @param t The token to check. This cannot be <code>null</code>.
* @return Whether the token is a single non-word char.
*/
public static boolean isNonWordChar(Token t) {
@@ -1226,12 +1160,11 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether or not a character is a whitespace character (either
* a space ' ' or tab '\t'). This checks for the Unicode character values
* 0x0020 and 0x0009.
* Returns whether or not a character is a whitespace character (either a space
* ' ' or tab '\t'). This checks for the Unicode character values 0x0020 and
* 0x0009.
*
* @param ch
* The character to check.
* @param ch The character to check.
* @return Whether or not the character is a whitespace character.
*/
public static boolean isWhitespace(char ch) {
@@ -1244,8 +1177,7 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Repaints the gutter in a text area's scroll pane, if necessary.
*
* @param textArea
* The text area.
* @param textArea The text area.
*/
public static void possiblyRepaintGutter(RTextArea textArea) {
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
@@ -1255,21 +1187,19 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Returns whether a regular expression token can follow the specified
* token in JavaScript.
*
* @param t
* The token to check, which may be <code>null</code>.
* @return Whether a regular expression token may follow this one in
* Returns whether a regular expression token can follow the specified token in
* JavaScript.
*
* @param t The token to check, which may be <code>null</code>.
* @return Whether a regular expression token may follow this one in JavaScript.
*/
public static boolean regexCanFollowInJavaScript(Token t) {
char ch;
// We basically try to mimic Eclipse's JS editor's behavior here.
return t == null ||
// t.isOperator() ||
(t.length() == 1 && ((ch = t.charAt(0)) == '=' || ch == '(' || ch == ',' || ch == '?' || ch == ':' || ch == '[' || ch == '!'
|| ch == '&'))
(t.length() == 1 && ((ch = t.charAt(0)) == '=' || ch == '(' || ch == ',' || ch == '?' || ch == ':'
|| ch == '[' || ch == '!' || ch == '&'))
||
/* Operators "==", "===", "!=", "!==", "&&", "||" */
(t.getType() == Token.OPERATOR && (t.charAt(t.length() - 1) == '=' || t.is(JS_AND) || t.is(JS_OR)))
@@ -1277,14 +1207,12 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* Selects a range of text in a text component. If the new selection is
* outside of the previous viewable rectangle, then the view is centered
* around the new selection.
* Selects a range of text in a text component. If the new selection is outside
* of the previous viewable rectangle, then the view is centered around the new
* selection.
*
* @param textArea
* The text component whose selection is to be centered.
* @param range
* The range to select.
* @param textArea The text component whose selection is to be centered.
* @param range The range to select.
*/
public static void selectAndPossiblyCenter(JTextArea textArea, DocumentRange range, boolean select) {
int start = range.getStartOffset();
@@ -1353,12 +1281,10 @@ public final class RSyntaxUtilities implements SwingConstants {
}
/**
* If the character is an upper-case US-ASCII letter, it returns the
* lower-case version of that letter; otherwise, it just returns the
* character.
* If the character is an upper-case US-ASCII letter, it returns the lower-case
* version of that letter; otherwise, it just returns the character.
*
* @param ch
* The character to lower-case (if it is a US-ASCII upper-case
* @param ch The character to lower-case (if it is a US-ASCII upper-case
* character).
* @return The lower-case version of the character.
*/
@@ -1378,12 +1304,9 @@ public final class RSyntaxUtilities implements SwingConstants {
/**
* Creates a regular expression pattern that matches a "wildcard" pattern.
*
* @param wildcard
* The wildcard pattern.
* @param matchCase
* Whether the pattern should be case sensitive.
* @param escapeStartChar
* Whether to escape a starting <code>'^'</code>
* @param wildcard The wildcard pattern.
* @param matchCase Whether the pattern should be case sensitive.
* @param escapeStartChar Whether to escape a starting <code>'^'</code>
* character.
* @return The pattern.
*/
+25 -37
View File
@@ -20,8 +20,8 @@ import java.io.StringReader;
* Gets the plain text version of RTF documents.
* <p>
*
* This is used by <code>RtfTransferable</code> to return the plain text
* version of the transferable when the receiver does not support RTF.
* This is used by <code>RtfTransferable</code> to return the plain text version
* of the transferable when the receiver does not support RTF.
*
* @author Robert Futrell
* @version 1.0
@@ -37,8 +37,7 @@ final class RtfToText {
/**
* Private constructor.
*
* @param r
* The reader to read RTF text from.
* @param r The reader to read RTF text from.
*/
private RtfToText(Reader r) {
this.r = r;
@@ -49,13 +48,12 @@ final class RtfToText {
}
/**
* Converts the RTF text read from this converter's <code>Reader</code>
* into plain text. It is the caller's responsibility to close the
* reader after this method is called.
* Converts the RTF text read from this converter's <code>Reader</code> into
* plain text. It is the caller's responsibility to close the reader after this
* method is called.
*
* @return The plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
private String convert() throws IOException {
// Skip over first curly brace as the whole file is in '{' and '}'
@@ -133,9 +131,9 @@ final class RtfToText {
}
/**
* Ends a control word. Checks whether it is a common one that affects
* the plain text output (such as "<code>par</code>" or "<code>tab</code>")
* and updates the text buffer accordingly.
* Ends a control word. Checks whether it is a common one that affects the plain
* text output (such as "<code>par</code>" or "<code>tab</code>") and updates
* the text buffer accordingly.
*/
private void endControlWord() {
String word = controlWord.toString();
@@ -149,14 +147,12 @@ final class RtfToText {
}
/**
* Converts the contents of the specified byte array representing
* an RTF document into plain text.
* Converts the contents of the specified byte array representing an RTF
* document into plain text.
*
* @param rtf
* The byte array representing an RTF document.
* @param rtf The byte array representing an RTF document.
* @return The contents of the RTF document, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(byte[] rtf) throws IOException {
return getPlainText(new ByteArrayInputStream(rtf));
@@ -165,26 +161,22 @@ final class RtfToText {
/**
* Converts the contents of the specified RTF file to plain text.
*
* @param file
* The RTF file to convert.
* @param file The RTF file to convert.
* @return The contents of the file, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(File file) throws IOException {
return getPlainText(new BufferedReader(new FileReader(file)));
}
/**
* Converts the contents of the specified input stream to plain text.
* The input stream will be closed when this method returns.
* Converts the contents of the specified input stream to plain text. The input
* stream will be closed when this method returns.
*
* @param in
* The input stream to convert. This will be closed when this
* method returns.
* @param in The input stream to convert. This will be closed when this method
* returns.
* @return The contents of the stream, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(InputStream in) throws IOException {
return getPlainText(new InputStreamReader(in, "US-ASCII"));
@@ -193,12 +185,10 @@ final class RtfToText {
/**
* Converts the contents of the specified <code>Reader</code> to plain text.
*
* @param r
* The <code>Reader</code>. This will be closed when this method
* @param r The <code>Reader</code>. This will be closed when this method
* returns.
* @return The contents of the <code>Reader</code>, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
private static String getPlainText(Reader r) throws IOException {
try {
@@ -212,11 +202,9 @@ final class RtfToText {
/**
* Converts the contents of the specified String to plain text.
*
* @param rtf
* A string whose contents represent an RTF document.
* @param rtf A string whose contents represent an RTF document.
* @return The contents of the String, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(String rtf) throws IOException {
return getPlainText(new StringReader(rtf));
@@ -27,12 +27,10 @@ import org.fife.ui.rtextarea.RTextArea;
* </ul>
*
* The RTF generated isn't really "optimized," but it will do, especially for
* small amounts of text, such as what's common when copy-and-pasting. It
* tries to be sufficient for the use case of copying syntax highlighted
* code:
* small amounts of text, such as what's common when copy-and-pasting. It tries
* to be sufficient for the use case of copying syntax highlighted code:
* <ul>
* <li>It assumes that tokens changing foreground color often is fairly
* common.
* <li>It assumes that tokens changing foreground color often is fairly common.
* <li>It assumes that background highlighting is fairly uncommon.
* </ul>
*
@@ -53,13 +51,12 @@ public class RtfGenerator {
/**
* Java2D assumes a 72 dpi screen resolution, but on Windows the screen
* resolution is either 96 dpi or 120 dpi, depending on your font display
* settings. This is an attempt to make the RTF generated match the
* size of what's displayed in the RSyntaxTextArea.
* settings. This is an attempt to make the RTF generated match the size of
* what's displayed in the RSyntaxTextArea.
*/
private int screenRes;
/**
* The default font size for RTF. This is point size, in half
* points.
* The default font size for RTF. This is point size, in half points.
*/
private static final int DEFAULT_FONT_SIZE = 12;// 24;
@@ -87,17 +84,13 @@ public class RtfGenerator {
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg
* The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg
* The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the default
* font is used.
* @param fg The foreground of the text. If this is <code>null</code>, the
* default foreground color is used.
* @param bg The background color of the text. If this is <code>null</code>,
* the default background color is used.
* @see #appendNewline()
*/
public void appendToDoc(String text, Font f, Color fg, Color bg) {
@@ -107,16 +100,12 @@ public class RtfGenerator {
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the
* default font is used.
* @param bg
* The background color of the text. If this is
* @param bg The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline
* Whether the text should be underlined.
* @param underline Whether the text should be underlined.
* @see #appendNewline()
*/
public void appendToDocNoFG(String text, Font f, Color bg, boolean underline) {
@@ -126,19 +115,14 @@ public class RtfGenerator {
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg
* The foreground of the text. If this is <code>null</code>,
* @param fg The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg
* The background color of the text. If this is
* @param bg The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline
* Whether the text should be underlined.
* @param underline Whether the text should be underlined.
* @see #appendNewline()
*/
public void appendToDoc(String text, Font f, Color fg, Color bg, boolean underline) {
@@ -148,21 +132,15 @@ public class RtfGenerator {
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg
* The foreground of the text. If this is <code>null</code>,
* @param fg The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg
* The background color of the text. If this is
* @param bg The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline
* Whether the text should be underlined.
* @param setFG
* Whether the foreground specified by <code>fg</code> should
* @param underline Whether the text should be underlined.
* @param setFG Whether the foreground specified by <code>fg</code> should
* be honored (if it is non-<code>null</code>).
* @see #appendNewline()
*/
@@ -250,19 +228,16 @@ public class RtfGenerator {
}
/**
* Appends some text to a buffer, with special care taken for special
* characters as defined by the RTF spec.
* Appends some text to a buffer, with special care taken for special characters
* as defined by the RTF spec.
*
* <ul>
* <li>All tab characters are replaced with the string
* "<code>\tab</code>"
* <li>All tab characters are replaced with the string "<code>\tab</code>"
* <li>'\', '{' and '}' are changed to "\\", "\{" and "\}"
* </ul>
*
* @param text
* The text to append (with tab chars substituted).
* @param sb
* The buffer to append to.
* @param text The text to append (with tab chars substituted).
* @param sb The buffer to append to.
*/
private void escapeAndAdd(StringBuilder sb, String text) {
int count = text.length();
@@ -301,17 +276,15 @@ public class RtfGenerator {
* Returns a font point size, adjusted for the current screen resolution.
* <p>
*
* Java2D assumes 72 dpi. On systems with larger dpi (Windows, GTK, etc.),
* font rendering will appear too small if we simply return a Java "Font"
* object's getSize() value. We need to adjust it for the screen
* resolution.
* Java2D assumes 72 dpi. On systems with larger dpi (Windows, GTK, etc.), font
* rendering will appear too small if we simply return a Java "Font" object's
* getSize() value. We need to adjust it for the screen resolution.
*
* @param pointSize
* A Java Font's point size, as returned from
* @param pointSize A Java Font's point size, as returned from
* <code>getSize2D()</code>.
* @return The font point size, adjusted for the current screen resolution.
* This will allow other applications to render fonts the same
* size as they appear in the Java application.
* @return The font point size, adjusted for the current screen resolution. This
* will allow other applications to render fonts the same size as they
* appear in the Java application.
*/
private int fixFontSize(float pointSize) {
if (screenRes != 72) { // Java2D assumes 72 dpi
@@ -321,13 +294,11 @@ public class RtfGenerator {
}
/**
* Returns the index of the specified item in a list. If the item
* is not in the list, it is added, and its new index is returned.
* Returns the index of the specified item in a list. If the item is not in the
* list, it is added, and its new index is returned.
*
* @param list
* The list (possibly) containing the item.
* @param item
* The item to get the index of.
* @param list The list (possibly) containing the item.
* @param item The item to get the index of.
* @return The index of the item.
*/
private static int getColorIndex(List<Color> list, Color item) {
@@ -355,18 +326,15 @@ public class RtfGenerator {
}
/**
* Returns the index of the specified font in a list of fonts. This
* method only checks for a font by its family name; its attributes such
* as bold and italic are ignored.
* Returns the index of the specified font in a list of fonts. This method only
* checks for a font by its family name; its attributes such as bold and italic
* are ignored.
* <p>
*
* If the font is not in the list, it is added, and its new index is
* returned.
* If the font is not in the list, it is added, and its new index is returned.
*
* @param list
* The list (possibly) containing the font.
* @param font
* The font to get the index of.
* @param list The list (possibly) containing the font.
* @param font The font to get the index of.
* @return The index of the font.
*/
private static int getFontIndex(List<Font> list, Font font) {
@@ -404,8 +372,8 @@ public class RtfGenerator {
}
/**
* Returns a good "default" monospaced font to use when Java's logical
* font "Monospaced" is found.
* Returns a good "default" monospaced font to use when Java's logical font
* "Monospaced" is found.
*
* @return The monospaced font family to use.
*/
@@ -442,8 +410,7 @@ public class RtfGenerator {
}
/**
* Resets this generator. All document information and content is
* cleared.
* Resets this generator. All document information and content is cleared.
*/
public void reset() {
fontList.clear();
@@ -14,11 +14,10 @@ import java.io.IOException;
import java.io.StringReader;
/**
* Object used during copy/paste and DnD operations to represent RTF text.
* It can return the text being moved as either RTF or plain text. This
* class is basically the same as
* <code>java.awt.datatransfer.StringSelection</code>, except that it can also
* return the text as RTF.
* Object used during copy/paste and DnD operations to represent RTF text. It
* can return the text being moved as either RTF or plain text. This class is
* basically the same as <code>java.awt.datatransfer.StringSelection</code>,
* except that it can also return the text as RTF.
*
* @author Robert Futrell
* @version 1.0
@@ -32,14 +31,14 @@ class RtfTransferable implements Transferable {
/**
* The "flavors" the text can be returned as.
*/
private static final DataFlavor[] FLAVORS = { new DataFlavor("text/rtf", "RTF"), DataFlavor.stringFlavor, DataFlavor.plainTextFlavor // deprecated
private static final DataFlavor[] FLAVORS = { new DataFlavor("text/rtf", "RTF"), DataFlavor.stringFlavor,
DataFlavor.plainTextFlavor // deprecated
};
/**
* Constructor.
*
* @param data
* The RTF data.
* @param data The RTF data.
*/
RtfTransferable(byte[] data) {
this.data = data;
@@ -11,9 +11,9 @@ package org.fife.ui.rsyntaxtextarea;
import javax.swing.event.HyperlinkEvent;
/**
* A link generator result that selects a region of text in the text area.
* This will typically be used by IDE-style applications, to provide support
* for "linking" the use of a variable in a document to its declaration.
* A link generator result that selects a region of text in the text area. This
* will typically be used by IDE-style applications, to provide support for
* "linking" the use of a variable in a document to its declaration.
*
* @author Robert Futrell
* @version 1.0
@@ -38,9 +38,7 @@ public class SquiggleUnderlineHighlightPainter extends ChangeableHighlightPainte
/**
* Constructor.
*
* @param color
* The color of the squiggle. This cannot be
* <code>null</code>.
* @param color The color of the squiggle. This cannot be <code>null</code>.
*/
public SquiggleUnderlineHighlightPainter(Color color) {
super(color);
@@ -50,19 +48,13 @@ public class SquiggleUnderlineHighlightPainter extends ChangeableHighlightPainte
/**
* Paints a portion of a highlight.
*
* @param g
* the graphics context
* @param offs0
* the starting model offset &gt;= 0
* @param offs1
* the ending model offset &gt;= offs1
* @param bounds
* the bounding box of the view, which is not
* necessarily the region to paint.
* @param c
* the editor
* @param view
* View painting for
* @param g the graphics context
* @param offs0 the starting model offset &gt;= 0
* @param offs1 the ending model offset &gt;= offs1
* @param bounds the bounding box of the view, which is not necessarily the
* region to paint.
* @param c the editor
* @param view View painting for
* @return region drawing occurred in
*/
@Override
@@ -96,10 +88,8 @@ public class SquiggleUnderlineHighlightPainter extends ChangeableHighlightPainte
/**
* Paints a squiggle underneath text in the specified rectangle.
*
* @param g
* The graphics context with which to paint.
* @param r
* The rectangle containing the text.
* @param g The graphics context with which to paint.
* @param r The rectangle containing the text.
*/
protected void paintSquiggle(Graphics g, Rectangle r) {
int x = r.x;
@@ -8,8 +8,8 @@ package org.fife.ui.rsyntaxtextarea;
/**
* Constants that define the different programming languages understood by
* <code>RSyntaxTextArea</code>. These constants are the values you can pass
* to {@link RSyntaxTextArea#setSyntaxEditingStyle(String)} to get syntax
* <code>RSyntaxTextArea</code>. These constants are the values you can pass to
* {@link RSyntaxTextArea#setSyntaxEditingStyle(String)} to get syntax
* highlighting.
* <p>
*
@@ -123,8 +123,8 @@ public interface SyntaxConstants {
*/
String SYNTAX_STYLE_JSON = "text/json";
/**
* Style for highlighting .jshintrc files (JSON with comments, so can be
* used for other times when you want this behavior).
* Style for highlighting .jshintrc files (JSON with comments, so can be used
* for other times when you want this behavior).
*/
String SYNTAX_STYLE_JSON_WITH_COMMENTS = "text/jshintrc";
/**
+155 -216
View File
@@ -30,14 +30,14 @@ import org.fife.ui.rsyntaxtextarea.folding.FoldManager;
/**
* The <code>javax.swing.text.View</code> object used by {@link RSyntaxTextArea}
* when word wrap is disabled. It implements syntax highlighting for
* programming languages using the colors and font styles specified by the
* when word wrap is disabled. It implements syntax highlighting for programming
* languages using the colors and font styles specified by the
* <code>RSyntaxTextArea</code>.
* <p>
*
* You don't really have to do anything to use this class, as
* {@link RSyntaxTextAreaUI} automatically sets the text area's view to be
* an instance of this class if word wrap is disabled.
* {@link RSyntaxTextAreaUI} automatically sets the text area's view to be an
* instance of this class if word wrap is disabled.
* <p>
*
* The tokens that specify how to paint the syntax-highlighted text are gleaned
@@ -58,9 +58,9 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
*/
private FontMetrics metrics;
/**
* The current longest line. This is used to calculate the preferred width
* of the view. Since the calculation is potentially expensive, we try to
* avoid it by stashing which line is currently the longest.
* The current longest line. This is used to calculate the preferred width of
* the view. Since the calculation is potentially expensive, we try to avoid it
* by stashing which line is currently the longest.
*/
private Element longLine;
private float longLineWidth;
@@ -78,17 +78,16 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
private int clipStart;
private int clipEnd;
/**
* Temporary token used when we need to "modify" tokens for rendering
* purposes. Since tokens returned from RSyntaxDocuments are treated as
* immutable, we use this temporary token to do that work.
* Temporary token used when we need to "modify" tokens for rendering purposes.
* Since tokens returned from RSyntaxDocuments are treated as immutable, we use
* this temporary token to do that work.
*/
private TokenImpl tempToken;
/**
* Constructs a new <code>SyntaxView</code> wrapped around an element.
*
* @param elem
* The element representing the text to display.
* @param elem The element representing the text to display.
*/
public SyntaxView(Element elem) {
super(elem);
@@ -96,12 +95,11 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Iterate over the lines represented by the child elements
* of the element this view represents, looking for the line
* that is the longest. The <em>longLine</em> variable is updated to
* represent the longest line contained. The <em>font</em> variable
* is updated to indicate the font used to calculate the
* longest line.
* Iterate over the lines represented by the child elements of the element this
* view represents, looking for the line that is the longest. The
* <em>longLine</em> variable is updated to represent the longest line
* contained. The <em>font</em> variable is updated to indicate the font used to
* calculate the longest line.
*/
void calculateLongestLine() {
Component c = getContainer();
@@ -121,15 +119,12 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* 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 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#changedUpdate
*/
@Override
@@ -140,16 +135,12 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
/**
* Repaint the given line range.
*
* @param line0
* The starting line number to repaint. This must
* be a valid line number in the model.
* @param line1
* The ending line number to repaint. This must
* be a valid line number in the model.
* @param a
* The region allocated for the view to render into.
* @param host
* The component hosting the view (used to call repaint).
* @param line0 The starting line number to repaint. This must be a valid line
* number in the model.
* @param line1 The ending line number to repaint. This must be a valid line
* number in the model.
* @param a The region allocated for the view to render into.
* @param host The component hosting the view (used to call repaint).
*/
protected void damageLineRange(int line0, int line1, Shape a, Component host) {
if (a != null) {
@@ -165,21 +156,15 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Draws the passed-in text using syntax highlighting for the current
* language. It is assumed that the entire line is either not in a
* selected region, or painting with a selection-foreground color is turned
* off.
* Draws the passed-in text using syntax highlighting for the current language.
* It is assumed that the entire line is either not in a selected region, or
* painting with a selection-foreground color is turned off.
*
* @param painter
* The painter to render the tokens.
* @param token
* The list of tokens to draw.
* @param g
* The graphics context in which to draw.
* @param x
* The x-coordinate at which to draw.
* @param y
* The y-coordinate at which to draw.
* @param painter The painter to render the tokens.
* @param token The list of tokens to draw.
* @param g The graphics context in which to draw.
* @param x The x-coordinate at which to draw.
* @param y The y-coordinate at which to draw.
* @return The x-coordinate representing the end of the painted text.
*/
private float drawLine(TokenPainter painter, Token token, Graphics2D g, float x, float y, int line) {
@@ -201,27 +186,21 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Draws the passed-in text using syntax highlighting for the current
* language. Tokens are checked for being in a selected region, and are
* rendered appropriately if they are.
* Draws the passed-in text using syntax highlighting for the current language.
* Tokens are checked for being in a selected region, and are rendered
* appropriately if they are.
*
* @param painter
* The painter to render the tokens.
* @param token
* The list of tokens to draw.
* @param g
* The graphics context in which to draw.
* @param x
* The x-coordinate at which to draw.
* @param y
* The y-coordinate at which to draw.
* @param selStart
* The start of the selection.
* @param selEnd
* The end of the selection.
* @param painter The painter to render the tokens.
* @param token The list of tokens to draw.
* @param g The graphics context in which to draw.
* @param x The x-coordinate at which to draw.
* @param y The y-coordinate at which to draw.
* @param selStart The start of the selection.
* @param selEnd The end of the selection.
* @return The x-coordinate representing the end of the painted text.
*/
private float drawLineWithSelection(TokenPainter painter, Token token, Graphics2D g, float x, float y, int selStart, int selEnd) {
private float drawLineWithSelection(TokenPainter painter, Token token, Graphics2D g, float x, float y, int selStart,
int selEnd) {
float nextX = x; // The x-value at the end of our text.
boolean useSTC = host.getUseSelectedTextColor();
while (token != null && token.isPaintable() && nextX < clipEnd) {
@@ -285,10 +264,8 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
/**
* Calculates the width of the line represented by the given element.
*
* @param line
* The line for which to get the length.
* @param lineNumber
* The line number of the specified line in the document.
* @param line The line for which to get the length.
* @param lineNumber The line number of the specified line in the document.
* @return The width of the line.
*/
private float getLineWidth(int lineNumber) {
@@ -297,25 +274,21 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Provides a way to determine the next visually represented model
* location that one might place a caret. Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
* Provides a way to determine the next visually represented model location that
* one might place a caret. Some views may not be visible, they might not be in
* the same order found in the model, or they just might not allow access to
* some of the locations in the model.
*
* @param pos
* the position to convert &gt;= 0
* @param a
* the allocated region to render into
* @param direction
* the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard.
* This may be SwingConstants.WEST, SwingConstants.EAST,
* @param pos the position to convert &gt;= 0
* @param a the allocated region to render into
* @param direction the direction from the current position that can be thought
* of as the arrow keys typically found on a keyboard. This may
* be SwingConstants.WEST, SwingConstants.EAST,
* SwingConstants.NORTH, or SwingConstants.SOUTH.
* @return the location within the model that best represents the next
* location visual position.
* @return the location within the model that best represents the next location
* visual position.
* @exception BadLocationException
* @exception IllegalArgumentException
* for an invalid direction
* @exception IllegalArgumentException for an invalid direction
*/
@Override
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
@@ -324,17 +297,14 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* 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 View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into &gt;= 0.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @exception IllegalArgumentException
* for an invalid axis
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into &gt;= 0. Typically
* the view is told to render into the span that is returned, although
* there is no guarantee. The parent may choose to resize or break the
* view.
* @exception IllegalArgumentException for an invalid axis
*/
@Override
public float getPreferredSpan(int axis) {
@@ -363,8 +333,8 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Workaround for JTextComponents allowing the caret to be rendered
* entirely off-screen if the entire "previous" character fit entirely.
* Workaround for JTextComponents allowing the caret to be rendered entirely
* off-screen if the entire "previous" character fit entirely.
*
* @return The amount of space to add to the x-axis preferred span.
*/
@@ -388,17 +358,15 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Returns a token list for the <i>physical</i> line above the physical
* line containing the specified offset into the document. Note that for
* this plain (non-wrapped) view, this is simply the token list for the
* logical line above the line containing <code>offset</code>, since lines
* are not wrapped.
* Returns a token list for the <i>physical</i> line above the physical line
* containing the specified offset into the document. Note that for this plain
* (non-wrapped) view, this is simply the token list for the logical line above
* the line containing <code>offset</code>, since lines are not wrapped.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* before this one. If <code>offset</code> is in the first line in
* the document, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line before
* this one. If <code>offset</code> is in the first line in the
* document, <code>null</code> is returned.
*/
@Override
public Token getTokenListForPhysicalLineAbove(int offset) {
@@ -424,17 +392,15 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Returns a token list for the <i>physical</i> line below the physical
* line containing the specified offset into the document. Note that for
* this plain (non-wrapped) view, this is simply the token list for the
* logical line below the line containing <code>offset</code>, since lines
* are not wrapped.
* Returns a token list for the <i>physical</i> line below the physical line
* containing the specified offset into the document. Note that for this plain
* (non-wrapped) view, this is simply the token list for the logical line below
* the line containing <code>offset</code>, since lines are not wrapped.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* after this one. If <code>offset</code> is in the last physical
* line in the document, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line after
* this one. If <code>offset</code> is in the last physical line in the
* document, <code>null</code> is returned.
*/
@Override
public Token getTokenListForPhysicalLineBelow(int offset) {
@@ -461,15 +427,12 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Gives notification that something was inserted into the document
* in a location that this view is responsible for.
* Gives notification that something was inserted into the document in a
* location that this view is responsible for.
*
* @param changes
* The change information from the associated document.
* @param a
* The current allocation of the view.
* @param f
* The factory to use to rebuild if the view has children.
* @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.
*/
@Override
public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
@@ -479,11 +442,9 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
/**
* Determine the rectangle that represents the given line.
*
* @param a
* The region allocated for the view to render into
* @param line
* The line number to find the region of. This must
* be a valid line number in the model.
* @param a The region allocated for the view to render into
* @param line The line number to find the region of. This must be a valid line
* number in the model.
*/
protected Rectangle lineToRect(Shape a, int line) {
Rectangle r = null;
@@ -505,17 +466,14 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* 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 &gt;= 0
* @param a
* the allocated region to render into
* @param pos the position to convert &gt;= 0
* @param a the allocated region to render into
* @return the bounding box of the given position
* @exception BadLocationException
* if the given position does not
* represent a valid location in the associated document
* @exception BadLocationException if the given position does not represent a
* valid location in the associated document
* @see View#modelToView
*/
@Override
@@ -537,46 +495,41 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* 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:
* @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 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
@@ -620,15 +573,13 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* 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
@@ -644,10 +595,8 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
* Actually paints the text area. Only lines that have been damaged are
* repainted.
*
* @param g
* The graphics context with which to paint.
* @param a
* The allocated region in which to render.
* @param g The graphics context with which to paint.
* @param a The allocated region in which to render.
*/
@Override
public void paint(Graphics g, Shape a) {
@@ -728,13 +677,11 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* If the passed-in line is longer than the current longest line, then
* the longest line is updated.
* If the passed-in line is longer than the current longest line, then the
* longest line is updated.
*
* @param line
* The line to test against the current longest.
* @param lineNumber
* The line number of the passed-in line.
* @param line The line to test against the current longest.
* @param lineNumber The line number of the passed-in line.
* @return <code>true</code> iff the current longest line was updated.
*/
private boolean possiblyUpdateLongLine(Element line, int lineNumber) {
@@ -748,15 +695,12 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Gives notification that something was removed from the document
* in a location that this view is responsible for.
* Gives notification that something was removed from the document in a location
* that this view is responsible for.
*
* @param changes
* the change information from the associated document
* @param a
* the current allocation of the view
* @param f
* the factory to use to rebuild if the view has children
* @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
*/
@Override
public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
@@ -770,12 +714,10 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* Repaint the region of change covered by the given document
* event. Damages the line that begins the range to cover
* the case when the insert/remove is only on one line.
* If lines are added or removed, damages the whole
* view. The longest line is checked to see if it has
* changed.
* Repaint the region of change covered by the given document event. Damages the
* line that begins the range to cover the case when the insert/remove is only
* on one line. If lines are added or removed, damages the whole view. The
* longest line is checked to see if it has changed.
*/
protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
Component host = getContainer();
@@ -856,17 +798,14 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
/**
* 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 &gt;= 0
* @param fy
* the Y coordinate &gt;= 0
* @param a
* the allocated region to render into
* @return the location within the model that best represents the
* given point in the view &gt;= 0
* @param fx the X coordinate &gt;= 0
* @param fy the Y coordinate &gt;= 0
* @param a the allocated region to render into
* @return the location within the model that best represents the given point in
* the view &gt;= 0
*/
@Override
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
@@ -28,8 +28,8 @@ import org.fife.io.UnicodeWriter;
import org.fife.ui.rtextarea.RTextAreaEditorKit;
/**
* An extension of {@link org.fife.ui.rsyntaxtextarea.RSyntaxTextArea}
* that adds information about the file being edited, such as:
* An extension of {@link org.fife.ui.rsyntaxtextarea.RSyntaxTextArea} that adds
* information about the file being edited, such as:
*
* <ul>
* <li>Its name and location.
@@ -43,10 +43,10 @@ import org.fife.ui.rtextarea.RTextAreaEditorKit;
* Loading and saving is also built into the editor.
* <p>
*
* When saving UTF-8 files, whether or not a BOM is written is controlled by
* the {@link UnicodeWriter} class.
* Use {@link UnicodeWriter#setWriteUtf8BOM(boolean)} to toggle writing BOMs
* for UTF-8 files.
* When saving UTF-8 files, whether or not a BOM is written is controlled by the
* {@link UnicodeWriter} class. Use
* {@link UnicodeWriter#setWriteUtf8BOM(boolean)} to toggle writing BOMs for
* UTF-8 files.
* <p>
*
* Both local and remote files (e.g. ftp) are supported. See the
@@ -60,8 +60,8 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
private static final long serialVersionUID = 1L;
/**
* Property change event fired when the file path this text area references
* is updated.
* Property change event fired when the file path this text area references is
* updated.
*
* @see #load(FileLocation, String)
* @see #saveAs(FileLocation)
@@ -103,9 +103,8 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
*/
private boolean dirty;
/**
* The last time this file was modified on disk, for local files.
* For remote files, this value should always be
* {@link #LAST_MODIFIED_UNKNOWN}.
* The last time this file was modified on disk, for local files. For remote
* files, this value should always be {@link #LAST_MODIFIED_UNKNOWN}.
*/
private long lastSaveOrLoadTime;
/**
@@ -127,8 +126,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Constructor. The file will be given a default name.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
*/
public TextEditorPane(int textMode) {
@@ -136,14 +134,12 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Creates a new <code>TextEditorPane</code>. The file will be given
* a default name.
* Creates a new <code>TextEditorPane</code>. The file will be given a default
* name.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled
* Whether or not to use word wrap in this pane.
* @param wordWrapEnabled Whether or not to use word wrap in this pane.
*/
public TextEditorPane(int textMode, boolean wordWrapEnabled) {
super(textMode);
@@ -158,18 +154,13 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Creates a new <code>TextEditorPane</code>.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled
* Whether or not to use word wrap in this pane.
* @param loc
* The location of the text file being edited. If this value
* is <code>null</code>, a file named "Untitled.txt" in the
* current
* directory is used.
* @throws IOException
* If an IO error occurs reading the file at
* @param wordWrapEnabled Whether or not to use word wrap in this pane.
* @param loc The location of the text file being edited. If this
* value is <code>null</code>, a file named
* "Untitled.txt" in the current directory is used.
* @throws IOException If an IO error occurs reading the file at
* <code>loc</code>. This of course won't happen if
* <code>loc</code> is <code>null</code>.
*/
@@ -180,42 +171,36 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Creates a new <code>TextEditorPane</code>.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled
* Whether or not to use word wrap in this pane.
* @param loc
* The location of the text file being edited. If this value
* is <code>null</code>, a file named "Untitled.txt" in the
* current
* directory is used. This file is displayed as empty even if it
* actually exists.
* @param defaultEnc
* The default encoding to use when opening the file,
* if the file is not Unicode. If this value is
* <code>null</code>,
* a system default value is used.
* @throws IOException
* If an IO error occurs reading the file at
* @param wordWrapEnabled Whether or not to use word wrap in this pane.
* @param loc The location of the text file being edited. If this
* value is <code>null</code>, a file named
* "Untitled.txt" in the current directory is used. This
* file is displayed as empty even if it actually exists.
* @param defaultEnc The default encoding to use when opening the file, if
* the file is not Unicode. If this value is
* <code>null</code>, a system default value is used.
* @throws IOException If an IO error occurs reading the file at
* <code>loc</code>. This of course won't happen if
* <code>loc</code> is <code>null</code>.
*/
public TextEditorPane(int textMode, boolean wordWrapEnabled, FileLocation loc, String defaultEnc) throws IOException {
public TextEditorPane(int textMode, boolean wordWrapEnabled, FileLocation loc, String defaultEnc)
throws IOException {
super(textMode);
setLineWrap(wordWrapEnabled);
init(loc, defaultEnc);
}
/**
* Callback for when styles in the current document change.
* This method is never called.
* Callback for when styles in the current document change. This method is never
* called.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void changedUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {
}
/**
* Returns the default encoding for this operating system.
@@ -269,18 +254,18 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Returns the timestamp for when this file was last loaded or saved
* <em>by this editor pane</em>. If the file has been modified on disk by
* another process after it was loaded into this editor pane, this method
* will not return the actual file's last modified time.
* Returns the timestamp for when this file was last loaded or saved <em>by this
* editor pane</em>. If the file has been modified on disk by another process
* after it was loaded into this editor pane, this method will not return the
* actual file's last modified time.
* <p>
*
* For remote files, this method will always return
* {@link #LAST_MODIFIED_UNKNOWN}.
*
* @return The timestamp when this file was last loaded or saved by this
* editor pane, if it is a local file, or
* {@link #LAST_MODIFIED_UNKNOWN} if it is a remote file.
* @return The timestamp when this file was last loaded or saved by this editor
* pane, if it is a local file, or {@link #LAST_MODIFIED_UNKNOWN} if it
* is a remote file.
* @see #isModifiedOutsideEditor()
*/
public long getLastSaveOrLoadTime() {
@@ -292,15 +277,15 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
* "<code>\n</code>", "<code>\r\n</code>", or "<code>\r</code>").
* <p>
*
* Note that this value is an <code>Object</code> and not a
* <code>String</code> as that is the way the {@link Document} interface
* defines its property values. If you always use
* {@link #setLineSeparator(String)} to modify this value, then the value
* returned from this method will always be a <code>String</code>.
* Note that this value is an <code>Object</code> and not a <code>String</code>
* as that is the way the {@link Document} interface defines its property
* values. If you always use {@link #setLineSeparator(String)} to modify this
* value, then the value returned from this method will always be a
* <code>String</code>.
*
* @return The line separator. If this value is <code>null</code>, then
* the system default line separator is used (usually the value
* of <code>System.getProperty("line.separator")</code>).
* @return The line separator. If this value is <code>null</code>, then the
* system default line separator is used (usually the value of
* <code>System.getProperty("line.separator")</code>).
* @see #setLineSeparator(String)
* @see #setLineSeparator(String, boolean)
*/
@@ -311,17 +296,14 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Initializes this editor with the specified file location.
*
* @param loc
* The file location. If this is <code>null</code>, a default
* @param loc The file location. If this is <code>null</code>, a default
* location is used and an empty file is displayed.
* @param defaultEnc
* The default encoding to use when opening the file,
* if the file is not Unicode. If this value is
* <code>null</code>,
* a system default value is used.
* @throws IOException
* If an IO error occurs reading from <code>loc</code>.
* If <code>loc</code> is <code>null</code>, this cannot happen.
* @param defaultEnc The default encoding to use when opening the file, if the
* file is not Unicode. If this value is <code>null</code>, a
* system default value is used.
* @throws IOException If an IO error occurs reading from <code>loc</code>. If
* <code>loc</code> is <code>null</code>, this cannot
* happen.
*/
private void init(FileLocation loc, String defaultEnc) throws IOException {
if (loc == null) {
@@ -351,8 +333,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Callback for when text is inserted into the document.
*
* @param e
* Information on the insertion.
* @param e Information on the insertion.
*/
@Override
public void insertUpdate(DocumentEvent e) {
@@ -390,17 +371,16 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Returns whether the text file has been modified outside of this editor
* since the last load or save operation. Note that if this is a remote
* file, this method will always return <code>false</code>.
* Returns whether the text file has been modified outside of this editor since
* the last load or save operation. Note that if this is a remote file, this
* method will always return <code>false</code>.
* <p>
*
* This method may be used by applications to implement a reloading
* feature, where the user is prompted to reload a file if it has been
* modified since their last open or save.
* This method may be used by applications to implement a reloading feature,
* where the user is prompted to reload a file if it has been modified since
* their last open or save.
*
* @return Whether the text file has been modified outside of this
* editor.
* @return Whether the text file has been modified outside of this editor.
* @see #getLastSaveOrLoadTime()
*/
public boolean isModifiedOutsideEditor() {
@@ -418,20 +398,16 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Loads the specified file in this editor. This method fires a property
* change event of type {@link #FULL_PATH_PROPERTY}.
* Loads the specified file in this editor. This method fires a property change
* event of type {@link #FULL_PATH_PROPERTY}.
*
* @param loc
* The location of the file to load. This cannot be
* @param loc The location of the file to load. This cannot be
* <code>null</code>.
* @param defaultEnc
* The encoding to use when loading/saving the file.
* This encoding will only be used if the file is not Unicode.
* If this value is <code>null</code>, the system default
* encoding
* is used.
* @throws IOException
* If an IO error occurs.
* @param defaultEnc The encoding to use when loading/saving the file. This
* encoding will only be used if the file is not Unicode. If
* this value is <code>null</code>, the system default
* encoding is used.
* @throws IOException If an IO error occurs.
* @see #save()
* @see #saveAs(FileLocation)
*/
@@ -470,23 +446,22 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Reloads this file from disk. The file must exist for this operation
* to not throw an exception.
* Reloads this file from disk. The file must exist for this operation to not
* throw an exception.
* <p>
*
* The file's "dirty" state will be set to <code>false</code> after this
* operation. If this is a local file, its "last modified" time is
* updated to reflect that of the actual file.
* operation. If this is a local file, its "last modified" time is updated to
* reflect that of the actual file.
* <p>
*
* Note that if the file has been modified on disk, and is now a Unicode
* encoding when before it wasn't (or if it is a different Unicode now),
* this will cause this {@link TextEditorPane}'s encoding to change.
* Otherwise, the file's encoding will stay the same.
* encoding when before it wasn't (or if it is a different Unicode now), this
* will cause this {@link TextEditorPane}'s encoding to change. Otherwise, the
* file's encoding will stay the same.
*
* @throws IOException
* If the file does not exist, or if an IO error
* occurs reading the file.
* @throws IOException If the file does not exist, or if an IO error occurs
* reading the file.
* @see #isLocalAndExists()
*/
public void reload() throws IOException {
@@ -508,8 +483,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Called whenever text is removed from this editor.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void removeUpdate(DocumentEvent e) {
@@ -522,11 +496,10 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
* Saves the file in its current encoding.
* <p>
*
* The text area's "dirty" state is set to <code>false</code>, and if
* this is a local file, its "last modified" time is updated.
* The text area's "dirty" state is set to <code>false</code>, and if this is a
* local file, its "last modified" time is updated.
*
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
* @see #saveAs(FileLocation)
* @see #load(FileLocation, String)
*/
@@ -537,13 +510,11 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Saves this file in a new local location. This method fires a property
* change event of type {@link #FULL_PATH_PROPERTY}.
* Saves this file in a new local location. This method fires a property change
* event of type {@link #FULL_PATH_PROPERTY}.
*
* @param loc
* The location to save to.
* @throws IOException
* If an IO error occurs.
* @param loc The location to save to.
* @throws IOException If an IO error occurs.
* @see #save()
* @see #load(FileLocation, String)
*/
@@ -560,10 +531,8 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Saves the text in this editor to the specified location.
*
* @param loc
* The location to save to.
* @throws IOException
* If an IO error occurs.
* @param loc The location to save to.
* @throws IOException If an IO error occurs.
*/
private void saveImpl(FileLocation loc) throws IOException {
OutputStream out = loc.getOutputStream();
@@ -576,21 +545,20 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Sets whether or not this text in this editor has unsaved changes.
* This fires a property change event of type {@link #DIRTY_PROPERTY}.
* Sets whether or not this text in this editor has unsaved changes. This fires
* a property change event of type {@link #DIRTY_PROPERTY}.
* <p>
*
* Applications will usually have no need to call this method directly; the
* only time you might have a need to call this method directly is if you
* have to initialize an instance of TextEditorPane with content that does
* not come from a file. <code>TextEditorPane</code> automatically sets its
* own dirty flag when its content is edited, when its encoding is changed,
* or when its line ending property is changed. It is cleared whenever
* <code>load()</code>, <code>reload()</code>, <code>save()</code>, or
* <code>saveAs()</code> are called.
* Applications will usually have no need to call this method directly; the only
* time you might have a need to call this method directly is if you have to
* initialize an instance of TextEditorPane with content that does not come from
* a file. <code>TextEditorPane</code> automatically sets its own dirty flag
* when its content is edited, when its encoding is changed, or when its line
* ending property is changed. It is cleared whenever <code>load()</code>,
* <code>reload()</code>, <code>save()</code>, or <code>saveAs()</code> are
* called.
*
* @param dirty
* Whether or not the text has been modified.
* @param dirty Whether or not the text has been modified.
* @see #isDirty()
*/
public void setDirty(boolean dirty) {
@@ -603,8 +571,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
/**
* Sets the document for this editor.
*
* @param doc
* The new document.
* @param doc The new document.
*/
@Override
public void setDocument(Document doc) {
@@ -617,16 +584,13 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Sets the encoding to use when reading or writing this file. This
* method sets the editor's dirty flag when the encoding is changed, and
* fires a property change event of type {@link #ENCODING_PROPERTY}.
* Sets the encoding to use when reading or writing this file. This method sets
* the editor's dirty flag when the encoding is changed, and fires a property
* change event of type {@link #ENCODING_PROPERTY}.
*
* @param encoding
* The new encoding.
* @throws UnsupportedCharsetException
* If the encoding is not supported.
* @throws NullPointerException
* If <code>encoding</code> is
* @param encoding The new encoding.
* @throws UnsupportedCharsetException If the encoding is not supported.
* @throws NullPointerException If <code>encoding</code> is
* <code>null</code>.
* @see #getEncoding()
*/
@@ -649,17 +613,14 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
* "<code>\n</code>", "<code>\r\n</code>" or "<code>\r</code>").
*
* Besides parameter checking, this method is preferred over
* <code>getDocument().putProperty()</code> because it sets the editor's
* dirty flag when the line separator is changed.
* <code>getDocument().putProperty()</code> because it sets the editor's dirty
* flag when the line separator is changed.
*
* @param separator
* The new line separator.
* @throws NullPointerException
* If <code>separator</code> is
* @param separator The new line separator.
* @throws NullPointerException If <code>separator</code> is
* <code>null</code>.
* @throws IllegalArgumentException
* If <code>separator</code> is not one
* of "<code>\n</code>", "<code>\r\n</code>" or
* @throws IllegalArgumentException If <code>separator</code> is not one of
* "<code>\n</code>", "<code>\r\n</code>" or
* "<code>\r</code>".
* @see #getLineSeparator()
*/
@@ -672,20 +633,16 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
* "<code>\n</code>", "<code>\r\n</code>" or "<code>\r</code>").
*
* Besides parameter checking, this method is preferred over
* <code>getDocument().putProperty()</code> because can set the editor's
* dirty flag when the line separator is changed.
* <code>getDocument().putProperty()</code> because can set the editor's dirty
* flag when the line separator is changed.
*
* @param separator
* The new line separator.
* @param setDirty
* Whether the dirty flag should be set if the line
* separator is changed.
* @throws NullPointerException
* If <code>separator</code> is
* @param separator The new line separator.
* @param setDirty Whether the dirty flag should be set if the line separator
* is changed.
* @throws NullPointerException If <code>separator</code> is
* <code>null</code>.
* @throws IllegalArgumentException
* If <code>separator</code> is not one
* of "<code>\n</code>", "<code>\r\n</code>" or
* @throws IllegalArgumentException If <code>separator</code> is not one of
* "<code>\n</code>", "<code>\r\n</code>" or
* "<code>\r</code>".
* @see #getLineSeparator()
*/
@@ -707,11 +664,10 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Sets whether or not this text area should be treated as read-only.
* This fires a property change event of type {@link #READ_ONLY_PROPERTY}.
* Sets whether or not this text area should be treated as read-only. This fires
* a property change event of type {@link #READ_ONLY_PROPERTY}.
*
* @param readOnly
* Whether or not the document is read-only.
* @param readOnly Whether or not the document is read-only.
* @see #isReadOnly()
*/
public void setReadOnly(boolean readOnly) {
@@ -722,14 +678,14 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
/**
* Syncs this text area's "last saved or loaded" time to that of the file
* being edited, if that file is local and exists. If the file is
* remote or is local but does not yet exist, nothing happens.
* Syncs this text area's "last saved or loaded" time to that of the file being
* edited, if that file is local and exists. If the file is remote or is local
* but does not yet exist, nothing happens.
* <p>
*
* You normally do not have to call this method, as the "last saved or
* loaded" time for {@link TextEditorPane}s is kept up-to-date internally
* during such operations as {@link #save()}, {@link #reload()}, etc.
* You normally do not have to call this method, as the "last saved or loaded"
* time for {@link TextEditorPane}s is kept up-to-date internally during such
* operations as {@link #save()}, {@link #reload()}, etc.
*
* @see #getLastSaveOrLoadTime()
* @see #isModifiedOutsideEditor()
+140 -193
View File
@@ -40,50 +40,43 @@ import javax.swing.text.TabExpander;
public interface Token extends TokenTypes {
/**
* Appends HTML code for painting this token, using the given text area's
* color scheme.
* Appends HTML code for painting this token, using the given text area's color
* scheme.
*
* @param sb
* The buffer to append to.
* @param textArea
* The text area whose color scheme to use.
* @param fontFamily
* Whether to include the font family in the HTML for
* this token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be monospaced,
* and don't want any crazy fonts being used in the editor to be
* reflected in your HTML.
* @param sb The buffer to append to.
* @param textArea The text area whose color scheme to use.
* @param fontFamily Whether to include the font family in the HTML for this
* token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be
* monospaced, and don't want any crazy fonts being used in
* the editor to be reflected in your HTML.
* @return The buffer appended to.
* @see #getHTMLRepresentation(RSyntaxTextArea)
*/
StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily);
/**
* Appends HTML code for painting this token, using the given text area's
* color scheme.
* Appends HTML code for painting this token, using the given text area's color
* scheme.
*
* @param sb
* The buffer to append to.
* @param textArea
* The text area whose color scheme to use.
* @param fontFamily
* Whether to include the font family in the HTML for
* this token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be monospaced,
* and don't want any crazy fonts being used in the editor to be
* reflected in your HTML.
* @param tabsToSpaces
* Whether to convert tabs into spaces.
* @param sb The buffer to append to.
* @param textArea The text area whose color scheme to use.
* @param fontFamily Whether to include the font family in the HTML for this
* token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be
* monospaced, and don't want any crazy fonts being used in
* the editor to be reflected in your HTML.
* @param tabsToSpaces Whether to convert tabs into spaces.
* @return The buffer appended to.
* @see #getHTMLRepresentation(RSyntaxTextArea)
*/
StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily, boolean tabsToSpaces);
StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily,
boolean tabsToSpaces);
/**
* Returns the character at the specified offset in the token.
*
* @param index
* The index. This should be in the range
* @param index The index. This should be in the range
* <code>0-({@link #length()}-1)</code>.
* @return The character.
* @see #length()
@@ -91,28 +84,25 @@ public interface Token extends TokenTypes {
char charAt(int index);
/**
* Returns whether the token straddles the specified position in the
* document.
* Returns whether the token straddles the specified position in the document.
*
* @param pos
* The position in the document to check.
* @param pos The position in the document to check.
* @return Whether the specified position is straddled by this token.
*/
boolean containsPosition(int pos);
/**
* Returns the position in the token's internal char array corresponding
* to the specified document position.
* Returns the position in the token's internal char array corresponding to the
* specified document position.
* <p>
* Note that this method does NOT do any bounds checking; you can pass in
* a document position that does not correspond to a position in this
* token, and you will not receive an Exception or any other notification;
* it is up to the caller to ensure valid input.
* Note that this method does NOT do any bounds checking; you can pass in a
* document position that does not correspond to a position in this token, and
* you will not receive an Exception or any other notification; it is up to the
* caller to ensure valid input.
*
* @param pos
* A position in the document that is represented by this token.
* @return The corresponding token position &gt;= <code>textOffset</code>
* and &lt; <code>textOffset+textCount</code>.
* @param pos A position in the document that is represented by this token.
* @return The corresponding token position &gt;= <code>textOffset</code> and
* &lt; <code>textOffset+textCount</code>.
* @see #tokenToDocument
*/
int documentToToken(int pos);
@@ -120,17 +110,15 @@ public interface Token extends TokenTypes {
/**
* Returns whether this token's lexeme ends with the specified characters.
*
* @param ch
* The characters.
* @param ch The characters.
* @return Whether this token's lexeme ends with the specified characters.
* @see #startsWith(char[])
*/
boolean endsWith(char[] ch);
/**
* Returns the end offset of this token in the document (exclusive). In
* other words, the token ranges from
* <code>[getOffset(), getEndOffset())</code>.
* Returns the end offset of this token in the document (exclusive). In other
* words, the token ranges from <code>[getOffset(), getEndOffset())</code>.
*
* @return The end offset of this token.
* @see #getOffset()
@@ -138,11 +126,10 @@ public interface Token extends TokenTypes {
int getEndOffset();
/**
* Returns a <code>String</code> containing HTML code for painting this
* token, using the given text area's color scheme.
* Returns a <code>String</code> containing HTML code for painting this token,
* using the given text area's color scheme.
*
* @param textArea
* The text area whose color scheme to use.
* @param textArea The text area whose color scheme to use.
* @return The HTML representation of the token.
* @see #appendHTMLRepresentation(StringBuilder, RSyntaxTextArea, boolean)
*/
@@ -151,25 +138,23 @@ public interface Token extends TokenTypes {
/**
* Returns the language index of this token.
*
* @return The language index. A value of <code>0</code> denotes the
* "main" language, any positive value denotes a specific secondary
* language.
* @return The language index. A value of <code>0</code> denotes the "main"
* language, any positive value denotes a specific secondary language.
* @see #setLanguageIndex(int)
*/
int getLanguageIndex();
/**
* Returns the last token in this list that is not whitespace or a
* comment.
* Returns the last token in this list that is not whitespace or a comment.
*
* @return The last non-comment, non-whitespace token, or <code>null</code>
* if there isn't one.
* @return The last non-comment, non-whitespace token, or <code>null</code> if
* there isn't one.
*/
Token getLastNonCommentNonWhitespaceToken();
/**
* Returns the last paintable token in this token list, or <code>null</code>
* if there is no paintable token.
* Returns the last paintable token in this token list, or <code>null</code> if
* there is no paintable token.
*
* @return The last paintable token in this token list.
*/
@@ -179,44 +164,37 @@ public interface Token extends TokenTypes {
* Returns the text of this token, as a string.
* <p>
*
* Note that this method isn't used much by the
* <code>ryntaxtextarea</code> package internally, as it tries to limit
* memory allocation.
* Note that this method isn't used much by the <code>ryntaxtextarea</code>
* package internally, as it tries to limit memory allocation.
*
* @return The text of this token.
*/
String getLexeme();
/**
* Determines the offset into this token list (i.e., into the
* document) that covers pixel location <code>x</code> if the token list
* starts at pixel location <code>x0</code>
* Determines the offset into this token list (i.e., into the document) that
* covers pixel location <code>x</code> if the token list starts at pixel
* location <code>x0</code>
* <p>
* .
* This method will return the document position "closest" to the
* x-coordinate (i.e., if they click on the "right-half" of the
* <code>w</code> in <code>awe</code>, the caret will be placed in
* between the <code>w</code> and <code>e</code>; similarly, clicking on
* the left-half places the caret between the <code>a</code> and
* <code>w</code>). This makes it useful for methods such as
* <code>viewToModel</code> found in <code>javax.swing.text.View</code>
* . This method will return the document position "closest" to the x-coordinate
* (i.e., if they click on the "right-half" of the <code>w</code> in
* <code>awe</code>, the caret will be placed in between the <code>w</code> and
* <code>e</code>; similarly, clicking on the left-half places the caret between
* the <code>a</code> and <code>w</code>). This makes it useful for methods such
* as <code>viewToModel</code> found in <code>javax.swing.text.View</code>
* subclasses.
*
* @param textArea
* The text area from which the token list was derived.
* @param e
* How to expand tabs.
* @param x0
* The pixel x-location that is the beginning of
* @param textArea The text area from which the token list was derived.
* @param e How to expand tabs.
* @param x0 The pixel x-location that is the beginning of
* <code>tokenList</code>.
* @param x
* The pixel-position for which you want to get the corresponding
* offset.
* @return The position (in the document, NOT into the token list!) that
* covers the pixel location. If <code>tokenList</code> is
* <code>null</code> or has type <code>Token.NULL</code>, then
* <code>-1</code> is returned; the caller should recognize this and
* return the actual end position of the (empty) line.
* @param x The pixel-position for which you want to get the
* corresponding offset.
* @return The position (in the document, NOT into the token list!) that covers
* the pixel location. If <code>tokenList</code> is <code>null</code> or
* has type <code>Token.NULL</code>, then <code>-1</code> is returned;
* the caller should recognize this and return the actual end position
* of the (empty) line.
*/
int getListOffset(RSyntaxTextArea textArea, TabExpander e, float x0, float x);
@@ -236,40 +214,34 @@ public interface Token extends TokenTypes {
int getOffset();
/**
* Returns the position in the document that represents the last character
* in the token that will fit into <code>endBeforeX-startX</code> pixels.
* For example, if you're using a monospaced 8-pixel-per-character font,
* have the token "while" and <code>startX</code> is <code>0</code> and
* Returns the position in the document that represents the last character in
* the token that will fit into <code>endBeforeX-startX</code> pixels. For
* example, if you're using a monospaced 8-pixel-per-character font, have the
* token "while" and <code>startX</code> is <code>0</code> and
* <code>endBeforeX</code> is <code>30</code>, this method will return the
* document position of the "i" in "while", because the "i" ends at pixel
* <code>24</code>, while the "l" ends at <code>32</code>. If not even the
* first character fits in <code>endBeforeX-startX</code>, the first
* character's position is still returned so calling methods don't go into
* infinite loops.
* <code>24</code>, while the "l" ends at <code>32</code>. If not even the first
* character fits in <code>endBeforeX-startX</code>, the first character's
* position is still returned so calling methods don't go into infinite loops.
*
* @param textArea
* The text area in which this token is being painted.
* @param e
* How to expand tabs.
* @param startX
* The x-coordinate at which the token will be painted. This
* @param textArea The text area in which this token is being painted.
* @param e How to expand tabs.
* @param startX The x-coordinate at which the token will be painted. This
* is needed because of tabs.
* @param endBeforeX
* The x-coordinate for which you want to find the last
* @param endBeforeX The x-coordinate for which you want to find the last
* character of <code>t</code> which comes before it.
* @return The last document position that will fit in the specified amount
* of pixels.
* @return The last document position that will fit in the specified amount of
* pixels.
*/
/*
* @see #getTokenListOffsetBeforeX
* FIXME: This method does not compute correctly! It needs to be abstract
* and implemented by subclasses.
* @see #getTokenListOffsetBeforeX FIXME: This method does not compute
* correctly! It needs to be abstract and implemented by subclasses.
*/
int getOffsetBeforeX(RSyntaxTextArea textArea, TabExpander e, float startX, float endBeforeX);
/**
* Returns the character array backing the lexeme of this token. This
* value should be treated as read-only.
* Returns the character array backing the lexeme of this token. This value
* should be treated as read-only.
*
* @return A character array containing the lexeme of this token.
* @see #getTextOffset()
@@ -298,13 +270,10 @@ public interface Token extends TokenTypes {
/**
* Returns the width of this token given the specified parameters.
*
* @param textArea
* The text area in which the token is being painted.
* @param e
* Describes how to expand tabs. This parameter cannot be
* @param textArea The text area in which the token is being painted.
* @param e Describes how to expand tabs. This parameter cannot be
* <code>null</code>.
* @param x0
* The pixel-location at which the token begins. This is needed
* @param x0 The pixel-location at which the token begins. This is needed
* because of tabs.
* @return The width of the token, in pixels.
* @see #getWidthUpTo
@@ -312,18 +281,14 @@ public interface Token extends TokenTypes {
float getWidth(RSyntaxTextArea textArea, TabExpander e, float x0);
/**
* Returns the width of a specified number of characters in this token.
* For example, for the token "while", specifying a value of <code>3</code>
* here returns the width of the "whi" portion of the token.
* Returns the width of a specified number of characters in this token. For
* example, for the token "while", specifying a value of <code>3</code> here
* returns the width of the "whi" portion of the token.
*
* @param numChars
* The number of characters for which to get the width.
* @param textArea
* The text area in which the token is being painted.
* @param e
* How to expand tabs. This value cannot be <code>null</code>.
* @param x0
* The pixel-location at which this token begins. This is needed
* @param numChars The number of characters for which to get the width.
* @param textArea The text area in which the token is being painted.
* @param e How to expand tabs. This value cannot be <code>null</code>.
* @param x0 The pixel-location at which this token begins. This is needed
* because of tabs.
* @return The width of the specified number of characters in this token.
* @see #getWidth
@@ -333,8 +298,7 @@ public interface Token extends TokenTypes {
/**
* Returns whether this token's lexeme matches a specific character array.
*
* @param lexeme
* The lexeme to check for.
* @param lexeme The lexeme to check for.
* @return Whether this token has that lexeme.
* @see #is(int, char[])
* @see #is(int, String)
@@ -347,14 +311,12 @@ public interface Token extends TokenTypes {
* Returns whether this token is of the specified type, with the specified
* lexeme.
* <p>
* This method is preferred over the other overload in performance-critical
* code where this operation may be called frequently, since it does not
* involve any String allocations.
* This method is preferred over the other overload in performance-critical code
* where this operation may be called frequently, since it does not involve any
* String allocations.
*
* @param type
* The type to check for.
* @param lexeme
* The lexeme to check for.
* @param type The type to check for.
* @param lexeme The lexeme to check for.
* @return Whether this token has that type and lexeme.
* @see #is(int, String)
* @see #is(char[])
@@ -368,13 +330,11 @@ public interface Token extends TokenTypes {
* lexeme.
* <p>
* The other overload of this method is preferred over this one in
* performance-critical code, as this one involves a String allocation
* while the other does not.
* performance-critical code, as this one involves a String allocation while the
* other does not.
*
* @param type
* The type to check for.
* @param lexeme
* The lexeme to check for.
* @param type The type to check for.
* @param lexeme The lexeme to check for.
* @return Whether this token has that type and lexeme.
* @see #is(int, char[])
* @see #isSingleChar(int, char)
@@ -416,8 +376,8 @@ public interface Token extends TokenTypes {
boolean isIdentifier();
/**
* Returns whether this token is a {@link #SEPARATOR} representing a single
* left curly brace.
* Returns whether this token is a {@link #SEPARATOR} representing a single left
* curly brace.
*
* @return Whether this token is a left curly brace.
* @see #isRightCurly()
@@ -434,10 +394,10 @@ public interface Token extends TokenTypes {
boolean isRightCurly();
/**
* Returns whether or not this token is "paintable;" i.e., whether or not
* the type of this token is one such that it has an associated syntax
* style. What this boils down to is whether the token type is greater
* than <code>Token.NULL</code>.
* Returns whether or not this token is "paintable;" i.e., whether or not the
* type of this token is one such that it has an associated syntax style. What
* this boils down to is whether the token type is greater than
* <code>Token.NULL</code>.
*
* @return Whether or not this token is paintable.
*/
@@ -446,8 +406,7 @@ public interface Token extends TokenTypes {
/**
* Returns whether this token is the specified single character.
*
* @param ch
* The character to check for.
* @param ch The character to check for.
* @return Whether this token's lexeme is the single character specified.
* @see #isSingleChar(int, char)
*/
@@ -457,10 +416,8 @@ public interface Token extends TokenTypes {
* Returns whether this token is the specified single character, and of a
* specific type.
*
* @param type
* The token type.
* @param ch
* The character to check for.
* @param type The token type.
* @param ch The character to check for.
* @return Whether this token is of the specified type, and with a lexeme
* Equaling the single character specified.
* @see #isSingleChar(char)
@@ -485,22 +442,17 @@ public interface Token extends TokenTypes {
int length();
/**
* Returns the bounding box for the specified document location. The
* location must be in the specified token list; if it isn't,
* <code>null</code> is returned.
* Returns the bounding box for the specified document location. The location
* must be in the specified token list; if it isn't, <code>null</code> is
* returned.
*
* @param textArea
* The text area from which the token list was derived.
* @param e
* How to expand tabs.
* @param pos
* The position in the document for which to get the bounding
* @param textArea The text area from which the token list was derived.
* @param e How to expand tabs.
* @param pos The position in the document for which to get the bounding
* box in the view.
* @param x0
* The pixel x-location that is the beginning of
* @param x0 The pixel x-location that is the beginning of
* <code>tokenList</code>.
* @param rect
* The rectangle in which we'll be returning the results. This
* @param rect The rectangle in which we'll be returning the results. This
* object is reused to keep from frequent memory allocations.
* @return The bounding box for the specified position in the model.
*/
@@ -509,24 +461,22 @@ public interface Token extends TokenTypes {
/**
* Sets whether this token is a hyperlink.
*
* @param hyperlink
* Whether this token is a hyperlink.
* @param hyperlink Whether this token is a hyperlink.
* @see #isHyperlink()
*/
void setHyperlink(boolean hyperlink);
/**
* Sets the language index for this token. If this value is positive, it
* denotes a specific "secondary" language this token represents (such as
* JavaScript code or CSS embedded in an HTML file). If this value is
* <code>0</code>, this token is in the "main" language being edited.
* Negative values are invalid and treated as <code>0</code>.
* Sets the language index for this token. If this value is positive, it denotes
* a specific "secondary" language this token represents (such as JavaScript
* code or CSS embedded in an HTML file). If this value is <code>0</code>, this
* token is in the "main" language being edited. Negative values are invalid and
* treated as <code>0</code>.
*
* @param languageIndex
* The new language index. A value of
* <code>0</code> denotes the "main" language, any positive value
* denotes a specific secondary language. Negative values will
* be treated as <code>0</code>.
* @param languageIndex The new language index. A value of <code>0</code>
* denotes the "main" language, any positive value denotes
* a specific secondary language. Negative values will be
* treated as <code>0</code>.
* @see #getLanguageIndex()
*/
void setLanguageIndex(int languageIndex);
@@ -534,8 +484,7 @@ public interface Token extends TokenTypes {
/**
* Sets the type of this token.
*
* @param type
* The new token type.
* @param type The new token type.
* @see TokenTypes
* @see #getType()
*/
@@ -544,8 +493,7 @@ public interface Token extends TokenTypes {
/**
* Returns whether this token starts with the specified characters.
*
* @param chars
* The characters.
* @param chars The characters.
* @return Whether this token starts with those characters.
* @see #endsWith(char[])
* @see #is(int, char[])
@@ -553,17 +501,16 @@ public interface Token extends TokenTypes {
boolean startsWith(char[] chars);
/**
* Returns the position in the document corresponding to the specified
* position in this token's internal char array (<code>textOffset</code> -
* Returns the position in the document corresponding to the specified position
* in this token's internal char array (<code>textOffset</code> -
* <code>textOffset+textCount-1</code>).
* <p>
* Note that this method does NOT do any bounds checking; you can pass in
* an invalid token position, and you will not receive an Exception or any
* other indication that the returned document position is invalid. It is
* up to the user to ensure valid input.
* Note that this method does NOT do any bounds checking; you can pass in an
* invalid token position, and you will not receive an Exception or any other
* indication that the returned document position is invalid. It is up to the
* user to ensure valid input.
*
* @param pos
* A position in the token's internal char array
* @param pos A position in the token's internal char array
* (<code>textOffset</code> - <code>textOffset+textCount</code>).
* @return The corresponding position in the document.
* @see #documentToToken(int)
@@ -26,16 +26,11 @@ interface TokenFactory {
/**
* Returns a token.
*
* @param line
* The segment from which to get the token's text.
* @param beg
* The starting offset of the token's text in the segment.
* @param end
* The ending offset of the token's text in the segment.
* @param startOffset
* The offset in the document of the token.
* @param type
* The type of token.
* @param line The segment from which to get the token's text.
* @param beg The starting offset of the token's text in the segment.
* @param end The ending offset of the token's text in the segment.
* @param startOffset The offset in the document of the token.
* @param type The type of token.
* @return The token.
*/
TokenImpl createToken(final Segment line, final int beg, final int end, final int startOffset, final int type);
@@ -43,24 +38,19 @@ interface TokenFactory {
/**
* Returns a token.
*
* @param line
* The char array from which to get the token's text.
* @param beg
* The starting offset of the token's text in the char array.
* @param end
* The ending offset of the token's text in the char array.
* @param startOffset
* The offset in the document of the token.
* @param type
* The type of token.
* @param line The char array from which to get the token's text.
* @param beg The starting offset of the token's text in the char array.
* @param end The ending offset of the token's text in the char array.
* @param startOffset The offset in the document of the token.
* @param type The type of token.
* @return The token.
*/
TokenImpl createToken(final char[] line, final int beg, final int end, final int startOffset, final int type);
/**
* Resets the state of this token maker. This method should be called
* by the <code>TokenMaker</code> every time a token list is generated for
* a new line so the tokens can be reused.
* Resets the state of this token maker. This method should be called by the
* <code>TokenMaker</code> every time a token list is generated for a new line
* so the tokens can be reused.
*/
void resetAllTokens();
}
@@ -24,8 +24,7 @@ class TokenIterator implements Iterator<Token> {
/**
* Constructor.
*
* @param doc
* The document whose tokens we should iterate over.
* @param doc The document whose tokens we should iterate over.
*/
TokenIterator(RSyntaxDocument doc) {
this.doc = doc;
@@ -98,11 +97,10 @@ class TokenIterator implements Iterator<Token> {
}
/**
* Always throws {@link UnsupportedOperationException}, as
* <code>Token</code> removal is not supported.
* Always throws {@link UnsupportedOperationException}, as <code>Token</code>
* removal is not supported.
*
* @throws UnsupportedOperationException
* always.
* @throws UnsupportedOperationException always.
*/
@Override
public void remove() {
+70 -92
View File
@@ -12,8 +12,8 @@ import javax.swing.text.Segment;
/**
* An implementation of <code>TokenMaker</code> is a class that turns text into
* a linked list of <code>Token</code>s for syntax highlighting
* in a particular language.
* a linked list of <code>Token</code>s for syntax highlighting in a particular
* language.
*
* @see Token
* @see AbstractTokenMaker
@@ -24,26 +24,20 @@ import javax.swing.text.Segment;
public interface TokenMaker {
/**
* Adds a null token to the end of the current linked list of tokens.
* This should be put at the end of the linked list whenever the last
* token on the current line is NOT a multi-line token.
* Adds a null token to the end of the current linked list of tokens. This
* should be put at the end of the linked list whenever the last token on the
* current line is NOT a multi-line token.
*/
public void addNullToken();
/**
* Adds the token specified to the current linked list of tokens.
*
* @param array
* The character array from which to get the text.
* @param start
* Start offset in <code>segment</code> of token.
* @param end
* End offset in <code>segment</code> of token.
* @param tokenType
* The token's type.
* @param startOffset
* The offset in the document at which this token
* occurs.
* @param array The character array from which to get the text.
* @param start Start offset in <code>segment</code> of token.
* @param end End offset in <code>segment</code> of token.
* @param tokenType The token's type.
* @param startOffset The offset in the document at which this token occurs.
*/
public void addToken(char[] array, int start, int end, int tokenType, int startOffset);
@@ -51,131 +45,115 @@ public interface TokenMaker {
* Returns the closest {@link TokenTypes "standard" token type} for a given
* "internal" token type (e.g. one whose value is <code>&lt; 0</code>).
*
* @param type
* The token type.
* @return The closest "standard" token type. If a mapping is not defined
* for this language, then <code>type</code> is returned.
* @param type The token type.
* @return The closest "standard" token type. If a mapping is not defined for
* this language, then <code>type</code> is returned.
*/
public int getClosestStandardTokenTypeForInternalType(int type);
/**
* Returns whether this programming language uses curly braces
* ('<code>{</code>' and '<code>}</code>') to denote code blocks.
* Returns whether this programming language uses curly braces ('<code>{</code>'
* and '<code>}</code>') to denote code blocks.
*
* @param languageIndex
* The language index at the offset in question.
* Since some <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter tells
* the
* <code>TokenMaker</code> what sub-language to look at.
* @param languageIndex The language index at the offset in question. Since some
* <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter
* tells the <code>TokenMaker</code> what sub-language to
* look at.
* @return Whether curly braces denote code blocks.
*/
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex);
/**
* Returns the last token on this line's type if the token is "unfinished",
* or {@link Token#NULL} if it was finished. For example, if C-style
* syntax highlighting is being implemented, and <code>text</code>
* contained a line of code that contained the beginning of a comment but
* no end-comment marker ("*\/"), then this method would return
* {@link Token#COMMENT_MULTILINE} for that line. This is useful
* for doing syntax highlighting.
* Returns the last token on this line's type if the token is "unfinished", or
* {@link Token#NULL} if it was finished. For example, if C-style syntax
* highlighting is being implemented, and <code>text</code> contained a line of
* code that contained the beginning of a comment but no end-comment marker
* ("*\/"), then this method would return {@link Token#COMMENT_MULTILINE} for
* that line. This is useful for doing syntax highlighting.
*
* @param text
* The line of tokens to examine.
* @param initialTokenType
* The token type to start with (i.e., the value
* of <code>getLastTokenTypeOnLine</code> for the line before
* <code>text</code>).
* @return The last token on this line's type, or {@link Token#NULL}
* if the line was completed.
* @param text The line of tokens to examine.
* @param initialTokenType The token type to start with (i.e., the value of
* <code>getLastTokenTypeOnLine</code> for the line
* before <code>text</code>).
* @return The last token on this line's type, or {@link Token#NULL} if the line
* was completed.
*/
public int getLastTokenTypeOnLine(Segment text, int initialTokenType);
/**
* Returns the text to place at the beginning and end of a
* line to "comment" it in this programming language.
* Returns the text to place at the beginning and end of a line to "comment" it
* in this programming language.
*
* @param languageIndex
* The language index at the offset in question.
* Since some <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter tells
* the
* <code>TokenMaker</code> what sub-language to look at.
* @return The start and end strings to add to a line to "comment"
* it out. A <code>null</code> value for either means there
* is no string to add for that part. A value of
* <code>null</code> for the array means this language
* does not support commenting/uncommenting lines.
* @param languageIndex The language index at the offset in question. Since some
* <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter
* tells the <code>TokenMaker</code> what sub-language to
* look at.
* @return The start and end strings to add to a line to "comment" it out. A
* <code>null</code> value for either means there is no string to add
* for that part. A value of <code>null</code> for the array means this
* language does not support commenting/uncommenting lines.
*/
public String[] getLineCommentStartAndEnd(int languageIndex);
/**
* Returns an action to handle "insert break" key presses (i.e. Enter).
*
* @return The action, or <code>null</code> if the default action should
* be used.
* @return The action, or <code>null</code> if the default action should be
* used.
*/
public Action getInsertBreakAction();
/**
* Returns whether tokens of the specified type should have "mark
* occurrences" enabled for the current programming language.
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @param type The token type.
* @return Whether tokens of this type should have "mark occurrences" enabled.
*/
public boolean getMarkOccurrencesOfTokenType(int type);
/**
* Returns the object in charge of marking all occurrences of the token
* at the current caret position, if it is a relevant token. If
* <code>null</code> is returned, a default <code>OccurrenceMarker</code>
* is used.
* Returns the object in charge of marking all occurrences of the token at the
* current caret position, if it is a relevant token. If <code>null</code> is
* returned, a default <code>OccurrenceMarker</code> is used.
*
* @return The occurrence marker for this language, or <code>null</code>
* for none.
* @return The occurrence marker for this language, or <code>null</code> for
* none.
*/
public OccurrenceMarker getOccurrenceMarker();
/**
* If a line ends in the specified token, this method returns whether
* a new line inserted after that line should be indented.
* If a line ends in the specified token, this method returns whether a new line
* inserted after that line should be indented.
*
* @param token
* The token the previous line ends with.
* @param token The token the previous line ends with.
* @return Whether the next line should be indented.
*/
public boolean getShouldIndentNextLineAfter(Token token);
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
public Token getTokenList(Segment text, int initialTokenType, int startOffset);
/**
* Returns whether a character could be part of an "identifier" token
* in a specific language. This is used to identify such things as the
* bounds of the "word" to select on double-clicking.
* Returns whether a character could be part of an "identifier" token in a
* specific language. This is used to identify such things as the bounds of the
* "word" to select on double-clicking.
*
* @param languageIndex
* The language index the character was found in.
* @param ch
* The character.
* @param languageIndex The language index the character was found in.
* @param ch The character.
* @return Whether the character could be part of an "identifier" token.
*/
public boolean isIdentifierChar(int languageIndex, char ch);
@@ -34,17 +34,15 @@ public abstract class TokenMakerBase implements TokenMaker {
*/
private TokenFactory tokenFactory;
/**
* Highlights occurrences of the current token in the editor, if it is
* relevant.
* Highlights occurrences of the current token in the editor, if it is relevant.
*/
private OccurrenceMarker occurrenceMarker;
/**
* "0" implies this is the "main" language being highlighted. Positive
* values imply various "secondary" or "embedded" languages, such as CSS
* or JavaScript in HTML. While this value is non-zero, tokens will be
* generated with this language index so they can (possibly) be painted
* differently, so "embedded" languages can be rendered with a special
* background.
* "0" implies this is the "main" language being highlighted. Positive values
* imply various "secondary" or "embedded" languages, such as CSS or JavaScript
* in HTML. While this value is non-zero, tokens will be generated with this
* language index so they can (possibly) be painted differently, so "embedded"
* languages can be rendered with a special background.
*/
private int languageIndex;
@@ -76,17 +74,11 @@ public abstract class TokenMakerBase implements TokenMaker {
/**
* Adds the token specified to the current linked list of tokens.
*
* @param segment
* <code>Segment</code> to get text from.
* @param start
* Start offset in <code>segment</code> of token.
* @param end
* End offset in <code>segment</code> of token.
* @param tokenType
* The token's type.
* @param startOffset
* The offset in the document at which this token
* occurs.
* @param segment <code>Segment</code> to get text from.
* @param start Start offset in <code>segment</code> of token.
* @param end End offset in <code>segment</code> of token.
* @param tokenType The token's type.
* @param startOffset The offset in the document at which this token occurs.
*/
public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) {
addToken(segment.array, start, end, tokenType, startOffset);
@@ -103,19 +95,12 @@ public abstract class TokenMakerBase implements TokenMaker {
/**
* Adds the token specified to the current linked list of tokens.
*
* @param array
* The character array.
* @param start
* The starting offset in the array.
* @param end
* The ending offset in the array.
* @param tokenType
* The token's type.
* @param startOffset
* The offset in the document at which this token
* occurs.
* @param hyperlink
* Whether this token is a hyperlink.
* @param array The character array.
* @param start The starting offset in the array.
* @param end The ending offset in the array.
* @param tokenType The token's type.
* @param startOffset The offset in the document at which this token occurs.
* @param hyperlink Whether this token is a hyperlink.
*/
public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) {
if (firstToken == null) {
@@ -132,8 +117,8 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Returns the occurrence marker to use for this token maker. Subclasses
* can override to use different implementations.
* Returns the occurrence marker to use for this token maker. Subclasses can
* override to use different implementations.
*
* @return The occurrence marker to use.
*/
@@ -146,12 +131,11 @@ public abstract class TokenMakerBase implements TokenMaker {
* "internal" token type (e.g. one whose value is <code>&lt; 0</code>).
* <p>
*
* The default implementation returns <code>type</code> always, which
* denotes that a mapping from internal token types to standard token types
* is not defined; subclasses can override.
* The default implementation returns <code>type</code> always, which denotes
* that a mapping from internal token types to standard token types is not
* defined; subclasses can override.
*
* @param type
* The token type.
* @param type The token type.
* @return The closest "standard" token type.
*/
@Override
@@ -160,18 +144,17 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Returns whether this programming language uses curly braces
* ('<code>{</code>' and '<code>}</code>') to denote code blocks.
* Returns whether this programming language uses curly braces ('<code>{</code>'
* and '<code>}</code>') to denote code blocks.
*
* The default implementation returns <code>false</code>; subclasses can
* override this method if necessary.
*
* @param languageIndex
* The language index at the offset in question.
* Since some <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter tells
* the
* <code>TokenMaker</code> what sub-language to look at.
* @param languageIndex The language index at the offset in question. Since some
* <code>TokenMaker</code>s effectively have nested
* languages (such as JavaScript in HTML), this parameter
* tells the <code>TokenMaker</code> what sub-language to
* look at.
* @return Whether curly braces denote code blocks.
*/
@Override
@@ -180,9 +163,8 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Returns an action to handle "insert break" key presses (i.e. Enter).
* The default implementation returns <code>null</code>. Subclasses
* can override.
* Returns an action to handle "insert break" key presses (i.e. Enter). The
* default implementation returns <code>null</code>. Subclasses can override.
*
* @return The default implementation always returns <code>null</code>.
*/
@@ -223,16 +205,14 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Returns whether tokens of the specified type should have "mark
* occurrences" enabled for the current programming language. The default
* implementation returns true if <tt>type</tt> is {@link Token#IDENTIFIER}.
* Subclasses can override this method to support other token types, such
* as {@link Token#VARIABLE}.
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language. The default implementation
* returns true if <tt>type</tt> is {@link Token#IDENTIFIER}. Subclasses can
* override this method to support other token types, such as
* {@link Token#VARIABLE}.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @param type The token type.
* @return Whether tokens of this type should have "mark occurrences" enabled.
*/
@Override
public boolean getMarkOccurrencesOfTokenType(int type) {
@@ -251,11 +231,10 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* The default implementation returns <code>false</code> always. Languages
* that wish to better support auto-indentation can override this method.
* The default implementation returns <code>false</code> always. Languages that
* wish to better support auto-indentation can override this method.
*
* @param token
* The token the previous line ends with.
* @param token The token the previous line ends with.
* @return Whether the next line should be indented.
*/
@Override
@@ -264,9 +243,9 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Returns whether a character could be part of an "identifier" token
* in a specific language. The default implementation returns
* <code>true</code> for letters, numbers, and certain symbols.
* Returns whether a character could be part of an "identifier" token in a
* specific language. The default implementation returns <code>true</code> for
* letters, numbers, and certain symbols.
*/
@Override
public boolean isIdentifierChar(int languageIndex, char ch) {
@@ -274,9 +253,9 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* The default implementation returns <code>false</code> always.
* Subclasses that are highlighting a markup language should override this
* method to return <code>true</code>.
* The default implementation returns <code>false</code> always. Subclasses that
* are highlighting a markup language should override this method to return
* <code>true</code>.
*
* @return <code>false</code> always.
*/
@@ -286,10 +265,9 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Deletes the linked list of tokens so we can begin anew. This should
* never have to be called by the programmer, as it is automatically
* called whenever the user calls
* {@link #getLastTokenTypeOnLine(Segment, int)} or
* Deletes the linked list of tokens so we can begin anew. This should never
* have to be called by the programmer, as it is automatically called whenever
* the user calls {@link #getLastTokenTypeOnLine(Segment, int)} or
* {@link #getTokenList(Segment, int, int)}.
*/
protected void resetTokenList() {
@@ -298,15 +276,14 @@ public abstract class TokenMakerBase implements TokenMaker {
}
/**
* Sets the language index to assign to tokens moving forward. This
* property is used to designate tokens as being in "secondary" languages
* (such as CSS or JavaScript in HTML).
* Sets the language index to assign to tokens moving forward. This property is
* used to designate tokens as being in "secondary" languages (such as CSS or
* JavaScript in HTML).
*
* @param languageIndex
* The new language index. A value of
* <code>0</code> denotes the "main" language, any positive value
* denotes a specific secondary language. Negative values will
* be treated as <code>0</code>.
* @param languageIndex The new language index. A value of <code>0</code>
* denotes the "main" language, any positive value denotes
* a specific secondary language. Negative values will be
* treated as <code>0</code>.
* @see #getLanguageIndex()
*/
protected void setLanguageIndex(int languageIndex) {
@@ -20,8 +20,7 @@ import org.fife.ui.rsyntaxtextarea.modes.PlainTextTokenMaker;
public abstract class TokenMakerFactory {
/**
* If this system property is set, a custom <code>TokenMakerFactory</code>
* of
* If this system property is set, a custom <code>TokenMakerFactory</code> of
* the specified class will be used as the default token maker factory.
*/
public static final String PROPERTY_DEFAULT_TOKEN_MAKER_FACTORY = "TokenMakerFactory";
@@ -63,8 +62,7 @@ public abstract class TokenMakerFactory {
/**
* Returns a {@link TokenMaker} for the specified key.
*
* @param key
* The key.
* @param key The key.
* @return The corresponding <code>TokenMaker</code>, or
* {@link PlainTextTokenMaker} if none matches the specified key.
*/
@@ -79,10 +77,8 @@ public abstract class TokenMakerFactory {
/**
* Returns a {@link TokenMaker} for the specified key.
*
* @param key
* The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code>
* if
* @param key The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code> if
* none matches the specified key.
*/
protected abstract TokenMaker getTokenMakerImpl(String key);
@@ -95,16 +91,13 @@ public abstract class TokenMakerFactory {
public abstract Set<String> keySet();
/**
* Sets the default <code>TokenMakerFactory</code> instance. This is the
* factory
* Sets the default <code>TokenMakerFactory</code> instance. This is the factory
* used by all future {@link RSyntaxDocument}s by default.
* <code>RSyntaxDocument</code>s that have already been created are not
* affected.
*
* @param tmf
* The factory.
* @throws IllegalArgumentException
* If <code>tmf</code> is <code>null</code>.
* @param tmf The factory.
* @throws IllegalArgumentException If <code>tmf</code> is <code>null</code>.
* @see #getDefaultInstance()
*/
public static synchronized void setDefaultInstance(TokenMakerFactory tmf) {
+49 -69
View File
@@ -10,8 +10,8 @@ package org.fife.ui.rsyntaxtextarea;
import javax.swing.text.Segment;
/**
* A hash table for reserved words, etc. defined by a {@link TokenMaker}.
* This class is designed for the quick lookup of tokens, as it can compare
* A hash table for reserved words, etc. defined by a {@link TokenMaker}. This
* class is designed for the quick lookup of tokens, as it can compare
* <code>Segment</code>s without the need to allocate a new string.
* <p>
*
@@ -43,8 +43,7 @@ public class TokenMap {
/**
* Constructs a new token map that is case-sensitive.
*
* @param size
* The size of the token map.
* @param size The size of the token map.
*/
public TokenMap(int size) {
this(size, false);
@@ -53,9 +52,8 @@ public class TokenMap {
/**
* Constructs a new token map.
*
* @param ignoreCase
* Whether or not this token map should ignore case
* when comparing tokens.
* @param ignoreCase Whether or not this token map should ignore case when
* comparing tokens.
*/
public TokenMap(boolean ignoreCase) {
this(DEFAULT_TOKEN_MAP_SIZE, ignoreCase);
@@ -64,11 +62,9 @@ public class TokenMap {
/**
* Constructs a new token map.
*
* @param size
* The size of the token map.
* @param ignoreCase
* Whether or not this token map should ignore case
* when comparing tokens.
* @param size The size of the token map.
* @param ignoreCase Whether or not this token map should ignore case when
* comparing tokens.
*/
public TokenMap(int size, boolean ignoreCase) {
this.size = size;
@@ -79,10 +75,8 @@ public class TokenMap {
/**
* Adds a token to a specified bucket in the token map.
*
* @param bucket
* The bucket in which to add the token.
* @param token
* The token to add.
* @param bucket The bucket in which to add the token.
* @param token The token to add.
*/
private void addTokenToBucket(int bucket, TokenMapToken token) {
TokenMapToken old = tokenMap[bucket];
@@ -91,34 +85,28 @@ public class TokenMap {
}
/**
* Returns the token type associated with the given text, if the given
* text is in this token map. If it isn't, <code>-1</code> is returned.
* Returns the token type associated with the given text, if the given text is
* in this token map. If it isn't, <code>-1</code> is returned.
*
* @param text
* The segment from which to get the text to compare.
* @param start
* The starting index in the segment of the text.
* @param end
* The ending index in the segment of the text.
* @return The token type associated with the given text, or
* <code>-1</code> if this token was not specified in this map.
* @param text The segment from which to get the text to compare.
* @param start The starting index in the segment of the text.
* @param end The ending index in the segment of the text.
* @return The token type associated with the given text, or <code>-1</code> if
* this token was not specified in this map.
*/
public int get(Segment text, int start, int end) {
return get(text.array, start, end);
}
/**
* Returns the token type associated with the given text, if the given
* text is in this token map. If it isn't, <code>-1</code> is returned.
* Returns the token type associated with the given text, if the given text is
* in this token map. If it isn't, <code>-1</code> is returned.
*
* @param array1
* An array of characters containing the text.
* @param start
* The starting index in the array of the text.
* @param end
* The ending index in the array of the text.
* @return The token type associated with the given text, or
* <code>-1</code> if this token was not specified in this map.
* @param array1 An array of characters containing the text.
* @param start The starting index in the array of the text.
* @param end The ending index in the array of the text.
* @return The token type associated with the given text, or <code>-1</code> if
* this token was not specified in this map.
*/
public int get(char[] array1, int start, int end) {
int length1 = end - start + 1;
@@ -129,14 +117,13 @@ public class TokenMap {
int offset1;
int length;
/*
* We check whether or not to ignore case before doing any looping to
* minimize the number of extraneous comparisons we do. This makes
* for slightly redundant code, but it'll be a little more efficient.
* We check whether or not to ignore case before doing any looping to minimize
* the number of extraneous comparisons we do. This makes for slightly redundant
* code, but it'll be a little more efficient.
*/
// If matches are case-sensitive (C, C++, Java, etc.)...
if (!ignoreCase) {
mainLoop:
while (token != null) {
mainLoop: while (token != null) {
if (token.length == length1) {
array2 = token.text;
offset2 = token.offset;
@@ -157,8 +144,7 @@ public class TokenMap {
// Note that all tokens saved in this map were converted to
// lower-case already.
else {
mainLoop2:
while (token != null) {
mainLoop2: while (token != null) {
if (token.length == length1) {
array2 = token.text;
offset2 = token.offset;
@@ -182,22 +168,20 @@ public class TokenMap {
/**
* Returns the hash code for a given string.
*
* @param text
* The text to hash.
* @param offset
* The offset into the text at which to start hashing.
* @param length
* The last character in the text to hash.
* @param text The text to hash.
* @param offset The offset into the text at which to start hashing.
* @param length The last character in the text to hash.
* @return The hash code.
*/
private int getHashCode(char[] text, int offset, int length) {
return (RSyntaxUtilities.toLowerCase(text[offset]) + RSyntaxUtilities.toLowerCase(text[offset + length - 1])) % size;
return (RSyntaxUtilities.toLowerCase(text[offset]) + RSyntaxUtilities.toLowerCase(text[offset + length - 1]))
% size;
}
/**
* Returns whether this token map ignores case when checking for tokens.
* This property is set in the constructor and cannot be changed, as this
* is an intrinsic property of a particular programming language.
* Returns whether this token map ignores case when checking for tokens. This
* property is set in the constructor and cannot be changed, as this is an
* intrinsic property of a particular programming language.
*
* @return Whether or not this token maker is ignoring case.
*/
@@ -208,10 +192,8 @@ public class TokenMap {
/**
* Adds a string to this token map.
*
* @param string
* The string to add.
* @param tokenType
* The type of token the string is.
* @param string The string to add.
* @param tokenType The type of token the string is.
*/
public void put(final String string, final int tokenType) {
if (isIgnoringCase()) {
@@ -222,16 +204,14 @@ public class TokenMap {
}
/**
* Adds a string to this token map. The char array passed-in will be used
* as the actual data for the token, so it may well be modified (such as
* lower-casing it if <code>ignoreCase</code> is <code>true</code>). This
* shouldn't be an issue though as this method is only called from the
* public <code>put</code> method, which allocates a new char array.
* Adds a string to this token map. The char array passed-in will be used as the
* actual data for the token, so it may well be modified (such as lower-casing
* it if <code>ignoreCase</code> is <code>true</code>). This shouldn't be an
* issue though as this method is only called from the public <code>put</code>
* method, which allocates a new char array.
*
* @param string
* The string to add.
* @param tokenType
* The type of token the string is.
* @param string The string to add.
* @param tokenType The type of token the string is.
*/
private void put(char[] string, int tokenType) {
int hashCode = getHashCode(string, 0, string.length);
@@ -239,9 +219,9 @@ public class TokenMap {
}
/**
* The "token" used by a token map. Note that this isn't the same thing
* as the {@link Token} class, but it's basically a 1-1 correspondence
* for reserved words, etc.
* The "token" used by a token map. Note that this isn't the same thing as the
* {@link Token} class, but it's basically a 1-1 correspondence for reserved
* words, etc.
*/
private static final class TokenMapToken {
@@ -24,34 +24,30 @@ package org.fife.ui.rsyntaxtextarea;
public interface TokenOrientedView {
/**
* Returns a token list for the <i>physical</i> line above the physical
* line containing the specified offset into the document. Note that for
* a plain (non-wrapped) view, this is simply the token list for the
* logical line above the line containing <code>offset</code>, since lines
* are not wrapped. For a wrapped view, this may or may not be tokens from
* the same line.
* Returns a token list for the <i>physical</i> line above the physical line
* containing the specified offset into the document. Note that for a plain
* (non-wrapped) view, this is simply the token list for the logical line above
* the line containing <code>offset</code>, since lines are not wrapped. For a
* wrapped view, this may or may not be tokens from the same line.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* before this one. If no physical line is above the one
* containing <code>offset</code>, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line before
* this one. If no physical line is above the one containing
* <code>offset</code>, <code>null</code> is returned.
*/
Token getTokenListForPhysicalLineAbove(int offset);
/**
* Returns a token list for the <i>physical</i> line below the physical
* line containing the specified offset into the document. Note that for
* a plain (non-wrapped) view, this is simply the token list for the
* logical line below the line containing <code>offset</code>, since lines
* are not wrapped. For a wrapped view, this may or may not be tokens from
* the same line.
* Returns a token list for the <i>physical</i> line below the physical line
* containing the specified offset into the document. Note that for a plain
* (non-wrapped) view, this is simply the token list for the logical line below
* the line containing <code>offset</code>, since lines are not wrapped. For a
* wrapped view, this may or may not be tokens from the same line.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* after this one. If no physical line is after the one
* containing <code>offset</code>, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line after
* this one. If no physical line is after the one containing
* <code>offset</code>, <code>null</code> is returned.
*/
Token getTokenListForPhysicalLineBelow(int offset);
}
@@ -11,8 +11,8 @@ import java.awt.Graphics2D;
import javax.swing.text.TabExpander;
/**
* Renders tokens in an instance of {@link RSyntaxTextArea}. One instance
* may render tokens "regularly," another may render visible whitespace, for
* Renders tokens in an instance of {@link RSyntaxTextArea}. One instance may
* render tokens "regularly," another may render visible whitespace, for
* example.
*
* @author Robert Futrell
@@ -23,18 +23,12 @@ interface TokenPainter {
/**
* Paints this token.
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @return The x-coordinate representing the end of the painted text.
*/
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e);
@@ -42,22 +36,16 @@ interface TokenPainter {
/**
* Paints this token.
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param clipStart
* The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not paint
* paint when this token is "to the left" of the clip rectangle.
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param clipStart The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not
* paint paint when this token is "to the left" of the clip
* rectangle.
* @return The x-coordinate representing the end of the painted text.
*/
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart);
@@ -65,75 +53,57 @@ interface TokenPainter {
/**
* Paints this token.
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param clipStart
* The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not paint
* paint when this token is "to the left" of the clip rectangle.
* @param paintBG
* Whether to paint the background.
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param clipStart The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not
* paint paint when this token is "to the left" of the clip
* rectangle.
* @param paintBG Whether to paint the background.
* @return The x-coordinate representing the end of the painted text.
*/
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean paintBG);
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean paintBG);
/**
* Paints this token as it should appear in a selected region of text
* (assuming painting with a selection-foreground color is enabled in the
* parent <code>RSyntaxTextArea</code>).
* Paints this token as it should appear in a selected region of text (assuming
* painting with a selection-foreground color is enabled in the parent
* <code>RSyntaxTextArea</code>).
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param useSTC
* Whether to use the text area's "selected text color."
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param useSTC Whether to use the text area's "selected text color."
* @return The x-coordinate representing the end of the painted text.
*/
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, boolean useSTC);
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
boolean useSTC);
/**
* Paints this token as it should appear in a selected region of text
* (assuming painting with a selection-foreground color is enabled in the
* parent <code>RSyntaxTextArea</code>).
* Paints this token as it should appear in a selected region of text (assuming
* painting with a selection-foreground color is enabled in the parent
* <code>RSyntaxTextArea</code>).
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param clipStart
* The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not paint
* paint when this token is "to the left" of the clip rectangle.
* @param useSTC
* Whether to use the text area's "selected text color."
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param clipStart The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not
* paint paint when this token is "to the left" of the clip
* rectangle.
* @param useSTC Whether to use the text area's "selected text color."
* @return The x-coordinate representing the end of the painted text.
*/
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean useSTC);
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean useSTC);
}
@@ -11,8 +11,8 @@ package org.fife.ui.rsyntaxtextarea;
* <p>
*
* Note that all valid token types are &gt;= 0, so extensions of the TokenMaker
* class are free to internally use all ints &lt; 0 ONLY for "end-of-line"
* style markers; they are ignored by painting implementations.
* class are free to internally use all ints &lt; 0 ONLY for "end-of-line" style
* markers; they are ignored by painting implementations.
*
* @author Robert Futrell
* @version 1.0
@@ -20,8 +20,8 @@ package org.fife.ui.rsyntaxtextarea;
public interface TokenTypes {
/**
* Tokens of type <code>NULL</code> mark the end of lines with no
* multi-line token at the end (such as a block comment in C++).
* Tokens of type <code>NULL</code> mark the end of lines with no multi-line
* token at the end (such as a block comment in C++).
*/
int NULL = 0;
int COMMENT_EOL = 1;
@@ -36,8 +36,7 @@ class URLFileLocation extends FileLocation {
/**
* Constructor.
*
* @param url
* The URL of the file.
* @param url The URL of the file.
*/
URLFileLocation(URL url) {
this.url = url;
@@ -46,8 +45,8 @@ class URLFileLocation extends FileLocation {
}
/**
* Creates a "prettied-up" URL to use. This will be stripped of
* sensitive information such as passwords.
* Creates a "prettied-up" URL to use. This will be stripped of sensitive
* information such as passwords.
*
* @return The full path to use.
*/
@@ -74,8 +73,8 @@ class URLFileLocation extends FileLocation {
/**
* Returns the last time this file was modified, or
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be
* computed (such as for a remote file).
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be computed
* (such as for a remote file).
*
* @return The last time this file was modified. This will always be
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} for URL's.
@@ -129,9 +128,9 @@ class URLFileLocation extends FileLocation {
}
/**
* Returns whether this file location is a local file and already
* exists. This method always returns <code>false</code> since we
* cannot check this value easily.
* Returns whether this file location is a local file and already exists. This
* method always returns <code>false</code> since we cannot check this value
* easily.
*
* @return <code>false</code> always.
* @see #isLocal()
@@ -20,13 +20,11 @@ import javax.swing.text.TabExpander;
* The current implementation paints as follows:
* <ul>
* <li>The first tab or space, if any, is found in the token.</li>
* <li>If a tab was found, all characters up to it are painted as a
* group.</li>
* <li>If a space was found, all characters up to and including it are
* painted (it is painted with a special symbol to denote it as
* a space).</li>
* <li>If neither a tab nor a whitespace was found, all characters in the
* token are painted.</li>
* <li>If a tab was found, all characters up to it are painted as a group.</li>
* <li>If a space was found, all characters up to and including it are painted
* (it is painted with a special symbol to denote it as a space).</li>
* <li>If neither a tab nor a whitespace was found, all characters in the token
* are painted.</li>
* <li>Repeat until all characters are painted.</li>
* </ul>
* This means that rendering hints are applied to all groups of characters
@@ -51,8 +49,8 @@ class VisibleWhitespaceTokenPainter extends DefaultTokenPainter {
* {@inheritDoc}
*/
@Override
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean selected, boolean useSTC) {
int origX = (int) x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
@@ -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);
@@ -89,12 +88,10 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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()
@@ -153,15 +150,12 @@ 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
@@ -170,10 +164,10 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -194,23 +188,18 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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();
@@ -264,29 +253,21 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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)) {
@@ -428,13 +410,10 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
* <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) {
@@ -457,10 +436,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
* <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) {
@@ -482,19 +459,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -508,19 +481,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -534,19 +503,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -612,16 +577,13 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -636,15 +598,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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) {
@@ -693,46 +652,41 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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:
* @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 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
@@ -776,15 +730,13 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -799,10 +751,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
/**
* 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) {
@@ -856,16 +806,13 @@ 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
@@ -880,18 +827,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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 {
@@ -906,13 +849,11 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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) {
@@ -928,8 +869,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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();
@@ -1026,11 +966,9 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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 {
@@ -1041,8 +979,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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,29 +1014,21 @@ 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
@@ -1123,14 +1054,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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
@@ -1139,17 +1068,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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;
@@ -1197,17 +1126,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
/**
* 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.
@@ -9,8 +9,8 @@ import javax.swing.text.Element;
// import javax.swing.text.View;
/**
* Replacement for the old <code>WrappedSyntaxView</code> class, designed to
* be faster with large wrapped documents. Heavily based off of
* Replacement for the old <code>WrappedSyntaxView</code> class, designed to be
* faster with large wrapped documents. Heavily based off of
* <code>BoxView</code>, but streamlined to only care about the y-axis, and
* takes code folding into account.
* <p>
@@ -33,8 +33,8 @@ import javax.swing.event.MouseInputAdapter;
import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
/**
* A focusable tool tip, similar to those found in Eclipse. The user
* can click in the tip and it becomes a "real," resizable window.
* A focusable tool tip, similar to those found in Eclipse. The user can click
* in the tip and it becomes a "real," resizable window.
*
* @author Robert Futrell
* @version 1.0
@@ -49,8 +49,8 @@ public class FocusableTip {
private String lastText;
private Dimension maxSize; // null to automatic.
/**
* The screen bounds in which the mouse has to stay for the currently
* displayed tip to stay visible.
* The screen bounds in which the mouse has to stay for the currently displayed
* tip to stay visible.
*/
private Rectangle tipVisibleBounds;
/**
@@ -61,7 +61,8 @@ public class FocusableTip {
* Margin from mouse cursor at which to draw focusable tip.
*/
private static final int Y_MARGIN = 12;
private static final ResourceBundle MSG = ResourceBundle.getBundle("org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip");
private static final ResourceBundle MSG = ResourceBundle
.getBundle("org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip");
public FocusableTip(JTextArea textArea, HyperlinkListener listener) {
setTextArea(textArea);
@@ -71,8 +72,8 @@ public class FocusableTip {
}
/**
* Compute the bounds in which the user can move the mouse without the
* tip window disappearing.
* Compute the bounds in which the user can move the mouse without the tip
* window disappearing.
*/
private void computeTipVisibleBounds() {
// Compute area that the mouse can move in without hiding the
@@ -173,8 +174,7 @@ public class FocusableTip {
/**
* Returns localized text for the given key.
*
* @param key
* The key into the resource bundle.
* @param key The key into the resource bundle.
* @return The localized text.
*/
static String getString(String key) {
@@ -203,8 +203,7 @@ public class FocusableTip {
/**
* Sets the base URL to use when loading images in this focusable tip.
*
* @param url
* The base URL to use.
* @param url The base URL to use.
* @see #getImageBase()
*/
public void setImageBase(URL url) {
@@ -214,9 +213,8 @@ public class FocusableTip {
/**
* Sets the maximum size for unfocused tool tips.
*
* @param maxSize
* The new maximum size. A value of <code>null</code> will
* cause a default size to be used.
* @param maxSize The new maximum size. A value of <code>null</code> will cause
* a default size to be used.
* @see #getMaxSize()
*/
public void setMaxSize(Dimension maxSize) {
@@ -244,7 +242,8 @@ public class FocusableTip {
/**
* Listens for events in a text area.
*/
private class TextAreaListener extends MouseInputAdapter implements CaretListener, ComponentListener, FocusListener, KeyListener {
private class TextAreaListener extends MouseInputAdapter
implements CaretListener, ComponentListener, FocusListener, KeyListener {
@Override
public void caretUpdate(CaretEvent e) {
@@ -275,7 +274,8 @@ public class FocusableTip {
}
@Override
public void focusGained(FocusEvent e) {}
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
@@ -284,7 +284,8 @@ public class FocusableTip {
// calling SwingUtilities.getWindowAncestor() to guard against an
// NPE.
Component c = e.getOppositeComponent();
boolean tipClicked = (c instanceof TipWindow) || (c != null && SwingUtilities.getWindowAncestor(c) instanceof TipWindow);
boolean tipClicked = (c instanceof TipWindow)
|| (c != null && SwingUtilities.getWindowAncestor(c) instanceof TipWindow);
if (!tipClicked) {
possiblyDisposeOfTipWindow();
}
@@ -316,10 +317,12 @@ public class FocusableTip {
}
@Override
public void keyReleased(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
@@ -31,15 +31,15 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
*/
public final class TipUtil {
private TipUtil() {}
private TipUtil() {
}
/**
* Returns a hex string for the specified color, suitable for HTML.
*
* @param c
* The color.
* @return The string representation, in the form "<code>#rrggbb</code>",
* or <code>null</code> if <code>c</code> is <code>null</code>.
* @param c The color.
* @return The string representation, in the form "<code>#rrggbb</code>", or
* <code>null</code> if <code>c</code> is <code>null</code>.
*/
private static String getHexString(Color c) {
if (c == null) {
@@ -65,14 +65,12 @@ public final class TipUtil {
}
/**
* Returns the screen coordinates for the monitor that contains the
* specified point. This is useful for setups with multiple monitors,
* to ensure that popup windows are positioned properly.
* Returns the screen coordinates for the monitor that contains the specified
* point. This is useful for setups with multiple monitors, to ensure that popup
* windows are positioned properly.
*
* @param x
* The x-coordinate, in screen coordinates.
* @param y
* The y-coordinate, in screen coordinates.
* @param x The x-coordinate, in screen coordinates.
* @param y The y-coordinate, in screen coordinates.
* @return The bounds of the monitor that contains the specified point.
*/
public static Rectangle getScreenBoundsForPoint(int x, int y) {
@@ -131,12 +129,11 @@ public final class TipUtil {
}
/**
* Returns whether a color is a Nimbus DerivedColor, which is troublesome
* in that it doesn't use its RGB values (uses HSB instead?) and so
* querying them is useless.
* Returns whether a color is a Nimbus DerivedColor, which is troublesome in
* that it doesn't use its RGB values (uses HSB instead?) and so querying them
* is useless.
*
* @param c
* The color to check.
* @param c The color to check.
* @return Whether it is a DerivedColor
*/
private static boolean isDerivedColor(Color c) {
@@ -153,12 +150,11 @@ public final class TipUtil {
}
/**
* Tweaks a <code>JEditorPane</code> so it can be used to render the
* content in a focusable pseudo-tool tip. It is assumed that the editor
* pane is using an <code>HTMLDocument</code>.
* Tweaks a <code>JEditorPane</code> so it can be used to render the content in
* a focusable pseudo-tool tip. It is assumed that the editor pane is using an
* <code>HTMLDocument</code>.
*
* @param textArea
* The editor pane to tweak.
* @param textArea The editor pane to tweak.
*/
public static void tweakTipEditorPane(JEditorPane textArea) {
// Jump through a few hoops to get things looking nice in Nimbus
@@ -200,19 +196,16 @@ public final class TipUtil {
}
/**
* Sets the default font for an HTML document (e.g., in a tool tip
* displaying HTML). This is here because when rendering HTML,
* {@code setFont()} is not honored.
* Sets the default font for an HTML document (e.g., in a tool tip displaying
* HTML). This is here because when rendering HTML, {@code setFont()} is not
* honored.
*
* @param doc
* The document to modify.
* @param font
* The font to use.
* @param fg
* The default foreground color.
* @param doc The document to modify.
* @param font The font to use.
* @param fg The default foreground color.
*/
public static void setFont(HTMLDocument doc, Font font, Color fg) {
doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt" + "; color: "
+ getHexString(fg) + "; }");
doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt"
+ "; color: " + getHexString(fg) + "; }");
}
}
Loaded 100 of 204 files, more files were not shown because too many files have changed in this diff. Show more