5252 */
5353public class DiscourseFormat {
5454
55- Editor editor ;
55+ private Editor editor ;
5656 // JTextArea of the actual Editor
57- JEditTextArea textarea ;
58- boolean html ;
57+ private JEditTextArea textarea ;
58+ private boolean html ;
5959
6060
6161 /**
@@ -75,7 +75,7 @@ public DiscourseFormat(Editor editor, boolean html) {
7575 */
7676 public void show () {
7777 // [code] tag cancels other tags, using [quote]
78- StringBuffer cf = new StringBuffer (html ? "<pre>\n " : "[quote ]\n " );
78+ StringBuilder cf = new StringBuilder (html ? "<pre>\n " : "[code ]\n " );
7979
8080 int selStart = textarea .getSelectionStart ();
8181 int selStop = textarea .getSelectionStop ();
@@ -99,7 +99,7 @@ public void show() {
9999 appendFormattedLine (cf , i );
100100 }
101101
102- cf .append (html ? "\n </pre>" : "\n [/quote ]" );
102+ cf .append (html ? "\n </pre>" : "\n [/code ]" );
103103
104104 StringSelection formatted = new StringSelection (cf .toString ());
105105 Clipboard clipboard = Toolkit .getDefaultToolkit ().getSystemClipboard ();
@@ -111,17 +111,15 @@ public void lostOwnership(Clipboard clipboard, Transferable contents) {
111111 Clipboard unixclipboard = Toolkit .getDefaultToolkit ().getSystemSelection ();
112112 if (unixclipboard != null ) unixclipboard .setContents (formatted , null );
113113
114- editor .statusNotice ("Code formatted for " +
115- (html ? "HTML" : "the Arduino forum " ) +
116- " has been copied to the clipboard." );
114+ editor .statusNotice ("Code formatted for " + (html ? "HTML" : "the Arduino forum" ) + " has been copied to the clipboard." );
117115 }
118116
119117 /**
120- * Append a char to a stringbuffer while escaping for proper display in HTML.
118+ * Append a char to a StringBuilder while escaping for proper display in HTML.
121119 * @param c input char to escape
122- * @param buffer StringBuffer to append html-safe version of c to.
120+ * @param buffer StringBuilder to append html-safe version of c to.
123121 */
124- private void appendToHTML (char c , StringBuffer buffer ) {
122+ private void appendToHTML (char c , StringBuilder buffer ) {
125123 if (!html ) {
126124 buffer .append (c );
127125 } else if (c == '<' ) {
@@ -138,7 +136,7 @@ private void appendToHTML(char c, StringBuffer buffer) {
138136 }
139137
140138 // A terrible headache...
141- public void appendFormattedLine (StringBuffer cf , int line ) {
139+ public void appendFormattedLine (StringBuilder cf , int line ) {
142140 Segment segment = new Segment ();
143141
144142 TextAreaPainter painter = textarea .getPainter ();
@@ -203,12 +201,14 @@ public void appendFormattedLine(StringBuffer cf, int line) {
203201// fm = painter.getFontMetrics();
204202 } else {
205203 // Place open tags []
206- cf .append (html ? "<span style=\" color: #" : "[color=#" );
207- cf .append (PApplet .hex (styles [id ].getColor ().getRGB () & 0xFFFFFF , 6 ));
208- cf .append (html ? ";\" >" : "]" );
204+ if (html ) {
205+ cf .append ("<span style=\" color: #" );
206+ cf .append (PApplet .hex (styles [id ].getColor ().getRGB () & 0xFFFFFF , 6 ));
207+ cf .append (";\" >" );
208+ }
209209
210- if (styles [id ].isBold ())
211- cf .append (html ? "<b>" : "[b] " );
210+ if (html && styles [id ].isBold ())
211+ cf .append ("<b>" );
212212
213213// fm = styles[id].getFontMetrics(defaultFont);
214214 }
@@ -228,10 +228,10 @@ public void appendFormattedLine(StringBuffer cf, int line) {
228228 appendToHTML (c , cf );
229229 }
230230 // Place close tags [/]
231- if (j == (length - 1 ) && id != Token .NULL && styles [id ].isBold ())
232- cf .append (html ? "</b>" : "[/b] " );
233- if (j == (length - 1 ) && id != Token .NULL )
234- cf .append (html ? "</span>" : "[/color] " );
231+ if (html && j == (length - 1 ) && id != Token .NULL && styles [id ].isBold ())
232+ cf .append ("</b>" );
233+ if (html && j == (length - 1 ) && id != Token .NULL )
234+ cf .append ("</span>" );
235235// int charWidth;
236236// if (c == '\t') {
237237// charWidth = (int) painter
0 commit comments