52
52
*/
53
53
public class DiscourseFormat {
54
54
55
- Editor editor ;
55
+ private Editor editor ;
56
56
// JTextArea of the actual Editor
57
- JEditTextArea textarea ;
58
- boolean html ;
57
+ private JEditTextArea textarea ;
58
+ private boolean html ;
59
59
60
60
61
61
/**
@@ -75,7 +75,7 @@ public DiscourseFormat(Editor editor, boolean html) {
75
75
*/
76
76
public void show () {
77
77
// [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 " );
79
79
80
80
int selStart = textarea .getSelectionStart ();
81
81
int selStop = textarea .getSelectionStop ();
@@ -99,7 +99,7 @@ public void show() {
99
99
appendFormattedLine (cf , i );
100
100
}
101
101
102
- cf .append (html ? "\n </pre>" : "\n [/quote ]" );
102
+ cf .append (html ? "\n </pre>" : "\n [/code ]" );
103
103
104
104
StringSelection formatted = new StringSelection (cf .toString ());
105
105
Clipboard clipboard = Toolkit .getDefaultToolkit ().getSystemClipboard ();
@@ -111,17 +111,15 @@ public void lostOwnership(Clipboard clipboard, Transferable contents) {
111
111
Clipboard unixclipboard = Toolkit .getDefaultToolkit ().getSystemSelection ();
112
112
if (unixclipboard != null ) unixclipboard .setContents (formatted , null );
113
113
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." );
117
115
}
118
116
119
117
/**
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.
121
119
* @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.
123
121
*/
124
- private void appendToHTML (char c , StringBuffer buffer ) {
122
+ private void appendToHTML (char c , StringBuilder buffer ) {
125
123
if (!html ) {
126
124
buffer .append (c );
127
125
} else if (c == '<' ) {
@@ -138,7 +136,7 @@ private void appendToHTML(char c, StringBuffer buffer) {
138
136
}
139
137
140
138
// A terrible headache...
141
- public void appendFormattedLine (StringBuffer cf , int line ) {
139
+ public void appendFormattedLine (StringBuilder cf , int line ) {
142
140
Segment segment = new Segment ();
143
141
144
142
TextAreaPainter painter = textarea .getPainter ();
@@ -203,12 +201,14 @@ public void appendFormattedLine(StringBuffer cf, int line) {
203
201
// fm = painter.getFontMetrics();
204
202
} else {
205
203
// 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
+ }
209
209
210
- if (styles [id ].isBold ())
211
- cf .append (html ? "<b>" : "[b] " );
210
+ if (html && styles [id ].isBold ())
211
+ cf .append ("<b>" );
212
212
213
213
// fm = styles[id].getFontMetrics(defaultFont);
214
214
}
@@ -228,10 +228,10 @@ public void appendFormattedLine(StringBuffer cf, int line) {
228
228
appendToHTML (c , cf );
229
229
}
230
230
// 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>" );
235
235
// int charWidth;
236
236
// if (c == '\t') {
237
237
// charWidth = (int) painter
0 commit comments