List of usage examples for javax.swing.text PlainDocument tabSizeAttribute
String tabSizeAttribute
To view the source code for javax.swing.text PlainDocument tabSizeAttribute.
Click Source Link
From source file:org.docx4all.ui.main.WordMLEditor.java
private JEditorPane createSourceView(WordMLTextPane editorView) { //Create the Source View JEditorPane sourceView = new JEditorPane(); MutableAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setFontFamily(attrs, FontManager.getInstance().getSourceViewFontFamilyName()); StyleConstants.setFontSize(attrs, FontManager.getInstance().getSourceViewFontSize()); // TODO - only do this if the font is available. Font font = new Font("Arial Unicode MS", Font.PLAIN, 12); System.out.println(font.getFamily()); System.out.println(font.getFontName()); System.out.println(font.getPSName()); sourceView.setFont(font);// www. ja va2 s .com //sourceView.setFont(FontManager.getInstance().getFontInAction(attrs)); sourceView.setContentType("text/xml; charset=UTF-16"); // Instantiate a XMLEditorKit with wrapping enabled. XMLEditorKit kit = new XMLEditorKit(true); // Set the wrapping style. kit.setWrapStyleWord(true); sourceView.setEditorKit(kit); WordMLDocument editorViewDoc = (WordMLDocument) editorView.getDocument(); try { editorViewDoc.readLock(); editorView.getWordMLEditorKit().saveCaretText(); DocumentElement elem = (DocumentElement) editorViewDoc.getDefaultRootElement(); WordprocessingMLPackage wmlPackage = ((DocumentML) elem.getElementML()).getWordprocessingMLPackage(); String filePath = (String) editorView.getDocument().getProperty(WordMLDocument.FILE_PATH_PROPERTY); //Do not include the last paragraph which is an extra paragraph. elem = (DocumentElement) elem.getElement(elem.getElementCount() - 1); ElementML paraML = elem.getElementML(); ElementML bodyML = paraML.getParent(); paraML.delete(); Document doc = DocUtil.read(sourceView, wmlPackage); doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath); doc.putProperty(WordMLDocument.WML_PACKAGE_PROPERTY, wmlPackage); doc.addDocumentListener(getToolbarStates()); //Below are the properties used by bounce.jar library //See http://www.edankert.com/bounce/xmleditorkit.html doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4)); doc.putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, Boolean.TRUE); doc.putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, Boolean.TRUE); //Remember to put 'paraML' as last paragraph bodyML.addChild(paraML); } finally { editorViewDoc.readUnlock(); } kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, new Color(255, 0, 0), Font.PLAIN); sourceView.addFocusListener(getToolbarStates()); //sourceView.setDocument(doc); sourceView.putClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG, Boolean.TRUE); return sourceView; }
From source file:processing.app.Editor.java
/** * Switch between tabs, this swaps out the Document object * that's currently being manipulated./*w w w.jav a2 s .c o m*/ */ protected void setCode(final SketchCodeDocument codeDoc) { RSyntaxDocument document = (RSyntaxDocument) codeDoc.getDocument(); if (document == null) { // this document not yet inited document = new RSyntaxDocument(new ArduinoTokenMakerFactory(base.getPdeKeywords()), RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS); document.putProperty(PlainDocument.tabSizeAttribute, PreferencesData.getInteger("editor.tabs.size")); // insert the program text into the document object try { document.insertString(0, codeDoc.getCode().getProgram(), null); } catch (BadLocationException bl) { bl.printStackTrace(); } // set up this guy's own undo manager // code.undo = new UndoManager(); codeDoc.setDocument(document); } if (codeDoc.getUndo() == null) { codeDoc.setUndo(new LastUndoableEditAwareUndoManager(textarea, this)); document.addUndoableEditListener(codeDoc.getUndo()); } // Update the document object that's in use textarea.switchDocument(document, codeDoc.getUndo()); // HACK multiple tabs: for update Listeners of Gutter, forcin call: Gutter.setTextArea(RTextArea) // BUG: https://github.com/bobbylight/RSyntaxTextArea/issues/84 scrollPane.setViewportView(textarea); textarea.select(codeDoc.getSelectionStart(), codeDoc.getSelectionStop()); textarea.requestFocus(); // get the caret blinking final int position = codeDoc.getScrollPosition(); // invokeLater: Expect the document to be rendered correctly to set the new position SwingUtilities.invokeLater(new Runnable() { @Override public void run() { scrollPane.getVerticalScrollBar().setValue(position); undoAction.updateUndoState(); redoAction.updateRedoState(); } }); }
From source file:processing.app.EditorTab.java
private RSyntaxDocument createDocument(String contents) { RSyntaxDocument document = new RSyntaxDocument(new ArduinoTokenMakerFactory(editor.base.getPdeKeywords()), RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS); document.putProperty(PlainDocument.tabSizeAttribute, PreferencesData.getInteger("editor.tabs.size")); // insert the program text into the document object try {/* w w w . j a v a 2 s .co m*/ document.insertString(0, contents, null); } catch (BadLocationException bl) { bl.printStackTrace(); } document.addDocumentListener(new DocumentTextChangeListener(() -> setModified(true))); return document; }
From source file:ro.nextreports.designer.ui.sqleditor.syntax.SyntaxDocument.java
public SyntaxDocument(Lexer lexer) { super();/*from ww w .j a v a 2 s . c o m*/ putProperty(PlainDocument.tabSizeAttribute, 4); // outside ?! this.lexer = lexer; // Listen for undo and redo events addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent event) { if (event.getEdit().isSignificant()) { undo.addEdit(event.getEdit()); } } }); }