Single tab, editing a single file, in the main window.
| 68 | * Single tab, editing a single file, in the main window. |
| 69 | */ |
| 70 | public class EditorTab extends JPanel implements SketchFile.TextStorage { |
| 71 | protected Editor editor; |
| 72 | protected SketchTextArea textarea; |
| 73 | protected RTextScrollPane scrollPane; |
| 74 | protected SketchFile file; |
| 75 | protected boolean modified; |
| 76 | /** Is external editing mode currently enabled? */ |
| 77 | protected boolean external; |
| 78 | |
| 79 | /** |
| 80 | * Create a new EditorTab |
| 81 | * |
| 82 | * @param editor |
| 83 | * The Editor this tab runs in |
| 84 | * @param file |
| 85 | * The file to display in this tab |
| 86 | * @param contents |
| 87 | * Initial contents to display in this tab. Can be used when editing |
| 88 | * a file that doesn't exist yet. If null is passed, code.load() is |
| 89 | * called and displayed instead. |
| 90 | * @throws IOException |
| 91 | */ |
| 92 | public EditorTab(Editor editor, SketchFile file, String contents) |
| 93 | throws IOException { |
| 94 | super(new BorderLayout()); |
| 95 | |
| 96 | // Load initial contents contents from file if nothing was specified. |
| 97 | if (contents == null) { |
| 98 | contents = file.load(); |
| 99 | modified = false; |
| 100 | } else { |
| 101 | modified = true; |
| 102 | } |
| 103 | |
| 104 | this.editor = editor; |
| 105 | this.file = file; |
| 106 | RSyntaxDocument document = createDocument(contents); |
| 107 | textarea = createTextArea(document); |
| 108 | scrollPane = createScrollPane(textarea); |
| 109 | file.setStorage(this); |
| 110 | applyPreferences(); |
| 111 | add(scrollPane, BorderLayout.CENTER); |
| 112 | editor.base.addEditorFontResizeMouseWheelListener(textarea); |
| 113 | } |
| 114 | |
| 115 | private RSyntaxDocument createDocument(String contents) { |
| 116 | RSyntaxDocument document = new RSyntaxDocument(new ArduinoTokenMakerFactory(editor.base.getPdeKeywords()), RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS); |
| 117 | document.putProperty(PlainDocument.tabSizeAttribute, PreferencesData.getInteger("editor.tabs.size")); |
| 118 | |
| 119 | // insert the program text into the document object |
| 120 | try { |
| 121 | document.insertString(0, contents, null); |
| 122 | } catch (BadLocationException bl) { |
| 123 | bl.printStackTrace(); |
| 124 | } |
| 125 | document.addDocumentListener(new DocumentTextChangeListener( |
| 126 | () -> setModified(true))); |
| 127 | return document; |
nothing calls this directly
no outgoing calls
no test coverage detected