Skip to content

Commit

Permalink
Merge commit 'aead840509c92072a3dbaaa253fa7521f57e9d7b'
Browse files Browse the repository at this point in the history
  • Loading branch information
tisoft committed Jul 14, 2021
2 parents cc583e6 + aead840 commit 87c0d9a
Show file tree
Hide file tree
Showing 120 changed files with 15,103 additions and 6,319 deletions.
39 changes: 19 additions & 20 deletions third_party/RSyntaxTextArea/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Coverage Status](https://coveralls.io/repos/bobbylight/RSyntaxTextArea/badge.svg)](https://coveralls.io/r/bobbylight/RSyntaxTextArea)

RSyntaxTextArea is a customizable, syntax highlighting text component for Java Swing applications. Out of
the box, it supports syntax highlighting for 40+ programming languages, code folding, search and replace,
the box, it supports syntax highlighting for 50+ programming languages, code folding, search and replace,
and has add-on libraries for code completion and spell checking. Syntax highlighting for additional languages
[can be added](https://github.com/bobbylight/RSyntaxTextArea/wiki) via tools such as [JFlex](http://jflex.de).

Expand All @@ -30,35 +30,34 @@ RSyntaxTextArea is simply a subclass of JTextComponent, so it can be dropped int
```java
import javax.swing.*;
import java.awt.BorderLayout;

import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;

public class TextEditorDemo extends JFrame {

public TextEditorDemo() {
public TextEditorDemo() {

JPanel cp = new JPanel(new BorderLayout());
JPanel cp = new JPanel(new BorderLayout());

RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setCodeFoldingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(textArea);
cp.add(sp);
RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setCodeFoldingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(textArea);
cp.add(sp);

setContentPane(cp);
setTitle("Text Editor Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
setContentPane(cp);
setTitle("Text Editor Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);

}
}

public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(() -> {
new TextEditorDemo().setVisible(true);
});
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(() -> new TextEditorDemo().setVisible(true));
}

}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,28 @@ private void init(OutputStream out, String encoding) throws IOException {

// Write the proper BOM if they specified a Unicode encoding.
// NOTE: Creating an OutputStreamWriter with encoding "UTF-16" DOES
// DOES write out the BOM; "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE"
// write out the BOM; "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE"
// and "UTF-32BE" don't.
if ("UTF-8".equals(encoding)) {
if (getWriteUtf8BOM()) {
out.write(UTF8_BOM, 0, UTF8_BOM.length);
}
}
else if ("UTF-16LE".equals(encoding)) {
out.write(UTF16LE_BOM, 0, UTF16LE_BOM.length);
}
else if (/*"UTF-16".equals(encoding) || */"UTF-16BE".equals(encoding)) {
out.write(UTF16BE_BOM, 0, UTF16BE_BOM.length);
}
else if ("UTF-32LE".equals(encoding)) {
out.write(UTF32LE_BOM, 0, UTF32LE_BOM.length);
}
else if ("UTF-32".equals(encoding) || "UTF-32BE".equals(encoding)) {
out.write(UTF32BE_BOM, 0, UTF32BE_BOM.length);
switch (encoding) {
case "UTF-8":
if (getWriteUtf8BOM()) {
out.write(UTF8_BOM, 0, UTF8_BOM.length);
}
break;
case "UTF-16LE":
out.write(UTF16LE_BOM, 0, UTF16LE_BOM.length);
break;
//case "UTF-16": // Already writes the BOM, so we don't
case "UTF-16BE":
out.write(UTF16BE_BOM, 0, UTF16BE_BOM.length);
break;
case "UTF-32LE":
out.write(UTF32LE_BOM, 0, UTF32LE_BOM.length);
break;
case "UTF-32":
case "UTF-32BE":
out.write(UTF32BE_BOM, 0, UTF32BE_BOM.length);
break;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static int printDocumentMonospaced(Graphics g, Document doc, int fontSize
}
}

curLineString = curLineString.substring(maxCharsPerLine, curLineString.length());
curLineString = curLineString.substring(maxCharsPerLine);

}

Expand Down Expand Up @@ -298,7 +298,7 @@ public static int printDocumentMonospacedWordWrap(Graphics g, Document doc,
}

// If this document line is too long to fit on one printed line on the page,
// break it up into multpile lines.
// break it up into multiple lines.
while (curLineString.length() > maxCharsPerLine) {

int breakPoint = getLineBreakPoint(curLineString, maxCharsPerLine) + 1;
Expand All @@ -312,7 +312,7 @@ public static int printDocumentMonospacedWordWrap(Graphics g, Document doc,
}
}

curLineString = curLineString.substring(breakPoint, curLineString.length());
curLineString = curLineString.substring(breakPoint);

}

Expand Down Expand Up @@ -415,7 +415,7 @@ public static int printDocumentWordWrap(Graphics g, JTextComponent textComponent
// Remove any spaces and/or tabs from the end of the segment (would cause problems if you left 'em).
currentLineSeg = removeEndingWhitespace(currentLineSeg);

// Figger out how long the line is, in pixels.
// Figure out how long the line is, in pixels.
int currentLineLengthInPixels = Utilities.getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander, 0);

//System.err.println("'" + currentLineSeg + "' - " + currentLineLengthInPixels + "/" + LINE_LENGTH_IN_PIXELS);
Expand Down Expand Up @@ -464,7 +464,7 @@ public static int printDocumentWordWrap(Graphics g, JTextComponent textComponent
try {
doc.getText(currentLineStart+startingOffset, currentPos, currentLineSeg);
} catch (BadLocationException ble) {
System.err.println(ble);
ble.printStackTrace();
return Printable.NO_SUCH_PAGE;
}
currentLineLengthInPixels = Utilities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected void initTokenMakerMap() {
putMapping(SYNTAX_STYLE_JSON_WITH_COMMENTS, pkg + "JshintrcTokenMaker");
putMapping(SYNTAX_STYLE_JSON, pkg + "JsonTokenMaker");
putMapping(SYNTAX_STYLE_JSP, pkg + "JSPTokenMaker");
putMapping(SYNTAX_STYLE_KOTLIN, pkg + "KotlinTokenMaker");
putMapping(SYNTAX_STYLE_LATEX, pkg + "LatexTokenMaker");
putMapping(SYNTAX_STYLE_LESS, pkg + "LessTokenMaker");
putMapping(SYNTAX_STYLE_LISP, pkg + "LispTokenMaker");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,67 @@ private HtmlUtil() {
public static String escapeForHtml(String s, String newlineReplacement,
boolean inPreBlock) {

if (s==null) {
return null;
}
if (newlineReplacement==null) {
newlineReplacement = "";
}

// Always all   instead of an initial ' ' so we always play
// nice when there's intermixed spaces and tabs
String tabString = inPreBlock ? " " : "    ";
boolean lastWasSpace = false;

StringBuilder sb = new StringBuilder();

for (int i=0; i<s.length(); i++) {
char ch = s.charAt(i);
switch (ch) {
case ' ':
if (inPreBlock) {
if (inPreBlock || !lastWasSpace) {
sb.append(' ');
}
else {
sb.append("&nbsp;");
}
lastWasSpace = true;
break;
case '\n':
sb.append(newlineReplacement);
lastWasSpace = false;
break;
case '&':
sb.append("&amp;");
lastWasSpace = false;
break;
case '\t':
sb.append(tabString);
lastWasSpace = true;
break;
case '<':
sb.append("&lt;");
lastWasSpace = false;
break;
case '>':
sb.append("&gt;");
lastWasSpace = false;
break;
case '\'':
sb.append("&#39;");
lastWasSpace = false;
break;
case '"':
sb.append("&#34;");
lastWasSpace = false;
break;
case '/': // OWASP-recommended even though unnecessary
sb.append("&#47;");
lastWasSpace = false;
break;
default:
sb.append(ch);
lastWasSpace = false;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,48 @@
* @author Robert Futrell
* @version 1.0
*/
class MatchedBracketPopup extends JWindow {
public class MatchedBracketPopup extends JWindow {

/**
* If this system property is defined and set to {@code true},
* matched bracket popups may render with the text area's background
* color if necessary to facilitate contrast between their text content
* (typically code) and their backgrounds. This is necessary for
* good looking popups when a text area's background may be drastically
* different than the Look and Feel's tool tip color (e.g. dark editor
* embedded in a "light" themed application, or vice versa).
* If this is omitted or does NOT evaluate to {@code true},
* matched bracket popups will always render like "native" tool tips
* according to the current Look and Feel.
* Users typically don't need to set this to {@code true} unless
* their application allows users to select a theme or color scheme
* for {@code RSyntaxTextArea} instances separately from the Look
* and Feel. For applications that instead only have one Look and
* Feel/RSTA theme combo, or allow toggling between fixed light and
* dark themes, the default of {@code false} is fine.
*/
public static final String PROPERTY_CONSIDER_TEXTAREA_BACKGROUND =
"rsta.matchedBracket.considerTextAreaBackground";

private RSyntaxTextArea textArea;

private transient Listener listener;

private static final int LEFT_EMPTY_BORDER = 5;

private static final boolean CONSIDER_TEXTAREA_BG =
Boolean.getBoolean(PROPERTY_CONSIDER_TEXTAREA_BACKGROUND);

MatchedBracketPopup(Window parent, RSyntaxTextArea textArea, int
offsToRender) {

super(parent);
this.textArea = textArea;
JPanel cp = new JPanel(new BorderLayout());
RSyntaxTextArea toolTipParam = CONSIDER_TEXTAREA_BG ? textArea : null;
cp.setBorder(BorderFactory.createCompoundBorder(
TipUtil.getToolTipBorder(),
TipUtil.getToolTipBorder(toolTipParam),
BorderFactory.createEmptyBorder(2, LEFT_EMPTY_BORDER, 5, 5)));
cp.setBackground(TipUtil.getToolTipBackground());
cp.setBackground(TipUtil.getToolTipBackground(toolTipParam));
setContentPane(cp);

cp.add(new JLabel(getText(offsToRender)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
* </td>
* <td style="vertical-align: top">
* <ul>
* <li>Kotlin
* <li>LaTeX
* <li>Lisp
* <li>Lua
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,89 +147,6 @@ private RSyntaxUtilities() { // NOSONAR
}


/**
* 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.
*
* @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) {

if (s==null) {
return null;
}
if (newlineReplacement==null) {
newlineReplacement = "";
}
final String tabString = " ";
boolean lastWasSpace = false;

StringBuilder sb = new StringBuilder();

for (int i=0; i<s.length(); i++) {
char ch = s.charAt(i);
switch (ch) {
case ' ':
if (inPreBlock || !lastWasSpace) {
sb.append(' ');
}
else {
sb.append("&nbsp;");
}
lastWasSpace = true;
break;
case '\n':
sb.append(newlineReplacement);
lastWasSpace = false;
break;
case '&':
sb.append("&amp;");
lastWasSpace = false;
break;
case '\t':
sb.append(tabString);
lastWasSpace = false;
break;
case '<':
sb.append("&lt;");
lastWasSpace = false;
break;
case '>':
sb.append("&gt;");
lastWasSpace = false;
break;
case '\'':
sb.append("&#39;");
lastWasSpace = false;
break;
case '"':
sb.append("&#34;");
lastWasSpace = false;
break;
case '/': // OWASP-recommended even though unnecessary
sb.append("&#47;");
lastWasSpace = false;
break;
default:
sb.append(ch);
lastWasSpace = false;
break;
}
}

return sb.toString();

}


/**
* Returns the rendering hints for text that will most accurately reflect
* those of the native windowing system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ public interface SyntaxConstants {
String SYNTAX_STYLE_JSP = "text/jsp";


/**
* Style for highlighting Kotlin.
*/
String SYNTAX_STYLE_KOTLIN = "text/kotlin";


/**
* Style for highlighting LaTeX.
*/
Expand Down
Loading

0 comments on commit 87c0d9a

Please sign in to comment.