Switch between tabs, this swaps out the Document object that's currently being manipulated.
(SketchCode code)
| 1796 | * that's currently being manipulated. |
| 1797 | */ |
| 1798 | public void setCode(SketchCode code) { |
| 1799 | SyntaxDocument document = (SyntaxDocument) code.getDocument(); |
| 1800 | |
| 1801 | if (document == null) { // this document not yet inited |
| 1802 | document = new SyntaxDocument() { |
| 1803 | @Override |
| 1804 | public void beginCompoundEdit() { |
| 1805 | if (compoundEdit == null) |
| 1806 | startCompoundEdit(); |
| 1807 | super.beginCompoundEdit(); |
| 1808 | } |
| 1809 | |
| 1810 | @Override |
| 1811 | public void endCompoundEdit() { |
| 1812 | stopCompoundEdit(); |
| 1813 | super.endCompoundEdit(); |
| 1814 | } |
| 1815 | }; |
| 1816 | code.setDocument(document); |
| 1817 | |
| 1818 | // turn on syntax highlighting |
| 1819 | document.setTokenMarker(mode.getTokenMarker(code)); |
| 1820 | |
| 1821 | // insert the program text into the document object |
| 1822 | try { |
| 1823 | document.insertString(0, code.getProgram(), null); |
| 1824 | } catch (BadLocationException bl) { |
| 1825 | bl.printStackTrace(); |
| 1826 | } |
| 1827 | |
| 1828 | // set up this guy's own undo manager |
| 1829 | // code.undo = new UndoManager(); |
| 1830 | |
| 1831 | document.addDocumentListener(new DocumentListener() { |
| 1832 | |
| 1833 | public void removeUpdate(DocumentEvent e) { |
| 1834 | if (isInserting && isDirectEdit() && !textarea.isOverwriteEnabled()) { |
| 1835 | endTextEditHistory(); |
| 1836 | } |
| 1837 | isInserting = false; |
| 1838 | } |
| 1839 | |
| 1840 | public void insertUpdate(DocumentEvent e) { |
| 1841 | if (!isInserting && !textarea.isOverwriteEnabled() && isDirectEdit()) { |
| 1842 | endTextEditHistory(); |
| 1843 | } |
| 1844 | |
| 1845 | if (!textarea.isOverwriteEnabled()) { |
| 1846 | isInserting = true; |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | public void changedUpdate(DocumentEvent e) { |
| 1851 | endTextEditHistory(); |
| 1852 | } |
| 1853 | }); |
| 1854 | |
| 1855 | // connect the undo listener to the editor |
no test coverage detected