@@ -58,6 +58,7 @@ This file is part of the iText (R) project.
58
58
import com .itextpdf .rups .view .contextmenu .StreamPanelContextMenu ;
59
59
import com .itextpdf .rups .view .itext .editor .Latin1Filter ;
60
60
import com .itextpdf .rups .view .itext .editor .PdfFoldParser ;
61
+ import com .itextpdf .rups .view .itext .editor .PdfParser ;
61
62
import com .itextpdf .rups .view .itext .editor .PdfTokenMaker ;
62
63
import com .itextpdf .rups .view .itext .editor .PdfTokenPainterFactory ;
63
64
import com .itextpdf .rups .view .itext .treenodes .PdfObjectTreeNode ;
@@ -73,6 +74,7 @@ This file is part of the iText (R) project.
73
74
import org .fife .ui .rsyntaxtextarea .DefaultTokenPainterFactory ;
74
75
import org .fife .ui .rsyntaxtextarea .RSyntaxDocument ;
75
76
import org .fife .ui .rsyntaxtextarea .RSyntaxTextArea ;
77
+ import org .fife .ui .rsyntaxtextarea .SyntaxConstants ;
76
78
import org .fife .ui .rsyntaxtextarea .TokenMakerFactory ;
77
79
import org .fife .ui .rsyntaxtextarea .folding .FoldParserManager ;
78
80
import org .fife .ui .rtextarea .ExpandedFoldRenderStrategy ;
@@ -82,11 +84,7 @@ public final class StreamTextEditorPane extends RTextScrollPane implements IRups
82
84
/**
83
85
* MIME type for a PDF content stream.
84
86
*/
85
- private static final String MIME_PDF = "application/pdf" ;
86
- /**
87
- * MIME type for plain text.
88
- */
89
- private static final String MIME_PLAIN_TEXT = "plain/text" ;
87
+ private static final String SYNTAX_STYLE_PDF = "application/pdf" ;
90
88
91
89
/**
92
90
* Char buffer with a single LF character.
@@ -115,8 +113,8 @@ public final class StreamTextEditorPane extends RTextScrollPane implements IRups
115
113
*/
116
114
final AbstractTokenMakerFactory tokenMakerFactory =
117
115
(AbstractTokenMakerFactory ) TokenMakerFactory .getDefaultInstance ();
118
- tokenMakerFactory .putMapping (MIME_PDF , PdfTokenMaker .class .getName ());
119
- FoldParserManager .get ().addFoldParserMapping (MIME_PDF , new PdfFoldParser ());
116
+ tokenMakerFactory .putMapping (SYNTAX_STYLE_PDF , PdfTokenMaker .class .getName ());
117
+ FoldParserManager .get ().addFoldParserMapping (SYNTAX_STYLE_PDF , new PdfFoldParser ());
120
118
/*
121
119
* There doesn't seem to be a good way to detect, whether you can call
122
120
* setData on a PdfStream or not in advance. It cannot be called if a
@@ -187,7 +185,7 @@ public void render(PdfObjectTreeNode target) {
187
185
// Assuming that this will stop parsing for a moment...
188
186
getTextArea ().setVisible (false );
189
187
String textToSet ;
190
- String mimeToSet ;
188
+ String styleToSet ;
191
189
boolean editableToSet ;
192
190
/*
193
191
* TODO: Differentiate between different content. See below.
@@ -207,21 +205,21 @@ public void render(PdfObjectTreeNode target) {
207
205
try {
208
206
if (isFont (stream ) || isImage (stream )) {
209
207
textToSet = getText (stream , false );
210
- mimeToSet = MIME_PLAIN_TEXT ;
208
+ styleToSet = SyntaxConstants . SYNTAX_STYLE_NONE ;
211
209
editableToSet = false ;
212
210
} else {
213
211
textToSet = prepareContentStreamText (getText (stream , true ));
214
- mimeToSet = MIME_PDF ;
212
+ styleToSet = SYNTAX_STYLE_PDF ;
215
213
editableToSet = true ;
216
214
}
217
215
setTextEditableRoutine (true );
218
216
} catch (RuntimeException e ) {
219
217
LoggerHelper .error (Language .ERROR_UNEXPECTED_EXCEPTION .getString (), e , getClass ());
220
218
textToSet = "" ;
221
- mimeToSet = MIME_PLAIN_TEXT ;
219
+ styleToSet = SyntaxConstants . SYNTAX_STYLE_NONE ;
222
220
editableToSet = false ;
223
221
}
224
- setContentType (mimeToSet );
222
+ setContentType (styleToSet );
225
223
getTextArea ().setText (textToSet );
226
224
getTextArea ().setCaretPosition (0 );
227
225
setTextEditableRoutine (editableToSet );
@@ -316,8 +314,8 @@ private void clearPane() {
316
314
setTextEditableRoutine (false );
317
315
}
318
316
319
- private void setContentType (String mime ) {
320
- setContentType (getTextArea (), mime );
317
+ private void setContentType (String style ) {
318
+ setContentType (getTextArea (), style );
321
319
}
322
320
323
321
private void setUndoEnabled (boolean enabled ) {
@@ -404,7 +402,8 @@ private static RSyntaxTextArea createTextArea() {
404
402
* metadata we should just use the regular XML editor available. But
405
403
* by default we will just assume a PDF content stream.
406
404
*/
407
- setContentType (textArea , MIME_PDF );
405
+ setContentType (textArea , SYNTAX_STYLE_PDF );
406
+ textArea .addParser (new PdfParser ());
408
407
// This will allow to fold code blocks (like BT/ET blocks)
409
408
textArea .setCodeFoldingEnabled (true );
410
409
// This will automatically add tabulations, when you enter a new line
@@ -417,15 +416,15 @@ private static RSyntaxTextArea createTextArea() {
417
416
return textArea ;
418
417
}
419
418
420
- private static void setContentType (RSyntaxTextArea textArea , String mime ) {
421
- if (MIME_PDF .equals (mime )) {
419
+ private static void setContentType (RSyntaxTextArea textArea , String style ) {
420
+ if (SYNTAX_STYLE_PDF .equals (style )) {
422
421
getDocument (textArea ).setDocumentFilter (new Latin1Filter ());
423
422
textArea .setTokenPainterFactory (new PdfTokenPainterFactory ());
424
423
} else {
425
424
getDocument (textArea ).setDocumentFilter (null );
426
425
textArea .setTokenPainterFactory (new DefaultTokenPainterFactory ());
427
426
}
428
- textArea .setSyntaxEditingStyle (mime );
427
+ textArea .setSyntaxEditingStyle (style );
429
428
}
430
429
431
430
private static String getText (PdfStream stream , boolean decoded ) {
0 commit comments