javax.swing.text.DefaultStyledDocument Java Examples
The following examples show how to use
javax.swing.text.DefaultStyledDocument.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextPaneSearchInteraction.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * This highlights the text within the specified range * * @param startingIndex where to start the highlight * @param endingIndex where to end the highlight * @param ensureVisible true to scroll to the text * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result. */ public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) { int length = endingIndex - startingIndex; AttributeSet style; if (isEmphasized) { style = emphasizedHighlightStyle; } else { style = highlightStyle; } ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true); if (ensureVisible) { Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex); textComponentToSearch.setCaretPosition(endingIndex); } textComponentToSearch.repaint(); }
Example #2
Source File: ConsoleTextEditor.java From groovy with Apache License 2.0 | 6 votes |
public void enableHighLighter(Class clazz) { DefaultStyledDocument doc = (DefaultStyledDocument) textEditor.getDocument(); try { DocumentFilter documentFilter = (DocumentFilter) clazz.getConstructor(doc.getClass()).newInstance(doc); doc.setDocumentFilter(documentFilter); disableMatchingHighlighter(); if (documentFilter instanceof SmartDocumentFilter) { final SmartDocumentFilter smartDocumentFilter = (SmartDocumentFilter) documentFilter; enableMatchingHighlighter(smartDocumentFilter); } } catch (ReflectiveOperationException e) { e.printStackTrace(); } }
Example #3
Source File: TextPaneSearchInteraction.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
/** * This highlights the text within the specified range * * @param startingIndex where to start the highlight * @param endingIndex where to end the highlight * @param ensureVisible true to scroll to the text * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result. */ public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) { int length = endingIndex - startingIndex; AttributeSet style; if (isEmphasized) { style = emphasizedHighlightStyle; } else { style = highlightStyle; } ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true); if (ensureVisible) { Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex); textComponentToSearch.setCaretPosition(endingIndex); } textComponentToSearch.repaint(); }
Example #4
Source File: TextPaneSearchInteraction.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
/** * This highlights the text within the specified range * * @param startingIndex where to start the highlight * @param endingIndex where to end the highlight * @param ensureVisible true to scroll to the text * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result. */ public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) { int length = endingIndex - startingIndex; AttributeSet style; if (isEmphasized) { style = emphasizedHighlightStyle; } else { style = highlightStyle; } ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true); if (ensureVisible) { Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex); textComponentToSearch.setCaretPosition(endingIndex); } textComponentToSearch.repaint(); }
Example #5
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 6 votes |
/** * @return A new "Password" text field */ public static JPasswordField newPassword() { JPasswordField passwordField = new JPasswordField(BitherUI.PASSWORD_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(passwordField, MessageKey.ENTER_PASSWORD); // Provide a consistent echo character across all components passwordField.setEchoChar(getPasswordEchoChar()); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.PASSWORD_LENGTH)); passwordField.setDocument(doc); // Set the theme passwordField.setBorder(new TextBubbleBorder(Themes.currentTheme.dataEntryBorder())); passwordField.setBackground(Themes.currentTheme.dataEntryBackground()); passwordField.setOpaque(false); return passwordField; }
Example #6
Source File: RTFTextExtractor.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public String extractText(InputStream stream, String type, String encoding) throws IOException { try { RTFEditorKit rek = new RTFEditorKit(); DefaultStyledDocument doc = new DefaultStyledDocument(); rek.read(stream, doc, 0); String text = doc.getText(0, doc.getLength()); return text; } catch (Throwable e) { logger.warn("Failed to extract RTF text content", e); throw new IOException(e.getMessage(), e); } finally { stream.close(); } }
Example #7
Source File: DisplayArea.java From android-classyshark with Apache License 2.0 | 6 votes |
@Override public void displayClass(List<Translator.ELEMENT> elements, String key) { displayDataState = DisplayDataState.INSIDE_CLASS; clearText(); StyleConstants.setFontSize(style, 20); StyleConstants.setBackground(style, theme.getBackgroundColor()); Document doc = new DefaultStyledDocument(); fillTokensToDoc(elements, doc, false); StyleConstants.setForeground(style, theme.getIdentifiersColor()); jTextPane.setDocument(doc); int i = calcScrollingPosition(key); jTextPane.setCaretPosition(i); }
Example #8
Source File: LogArea.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * Try and recover from a BadLocationException thrown when inserting a string * into the log area. This method must only be called on the AWT event * handling thread. */ private void handleBadLocationException(BadLocationException e, String textToInsert, Style style) { originalErr.println("BadLocationException encountered when writing to " + "the log area: " + e); originalErr.println("trying to recover..."); Document newDocument = new DefaultStyledDocument(); try { StringBuilder sb = new StringBuilder(); sb.append("An error occurred when trying to write a message to the log area. The log\n"); sb.append("has been cleared to try and recover from this problem.\n\n"); sb.append(textToInsert); newDocument.insertString(0, sb.toString(), style); } catch(BadLocationException e2) { // oh dear, all bets are off now... e2.printStackTrace(originalErr); return; } // replace the log area's document with the new one setDocument(newDocument); }
Example #9
Source File: DocumentImportStructureProvider.java From uima-uimaj with Apache License 2.0 | 6 votes |
private String convert(InputStream rtfDocumentInputStream) throws IOException { RTFEditorKit aRtfEditorkit = new RTFEditorKit(); StyledDocument styledDoc = new DefaultStyledDocument(); String textDocument; try { aRtfEditorkit.read(rtfDocumentInputStream, styledDoc, 0); textDocument = styledDoc.getText(0, styledDoc.getLength()); } catch (BadLocationException e) { throw new IOException("Error during parsing"); } return textDocument; }
Example #10
Source File: TextPaneSearchInteraction.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * This highlights the text within the specified range * * @param startingIndex where to start the highlight * @param endingIndex where to end the highlight * @param ensureVisible true to scroll to the text * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result. */ public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) { int length = endingIndex - startingIndex; AttributeSet style; if (isEmphasized) { style = emphasizedHighlightStyle; } else { style = highlightStyle; } ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true); if (ensureVisible) { Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex); textComponentToSearch.setCaretPosition(endingIndex); } textComponentToSearch.repaint(); }
Example #11
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 6 votes |
/** * @return A new "Password" text field */ public static JPasswordField newPassword() { JPasswordField passwordField = new JPasswordField(BitherUI.PASSWORD_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(passwordField, MessageKey.ENTER_PASSWORD); // Provide a consistent echo character across all components passwordField.setEchoChar(getPasswordEchoChar()); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.PASSWORD_LENGTH)); passwordField.setDocument(doc); // Set the theme passwordField.setBorder(new TextBubbleBorder(Themes.currentTheme.dataEntryBorder())); passwordField.setBackground(Themes.currentTheme.dataEntryBackground()); passwordField.setOpaque(false); return passwordField; }
Example #12
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @param listener The document listener for detecting changes to the content * @return A new "Notes" text area */ public static JTextArea newEnterPrivateNotes(DocumentListener listener, int width) { JTextArea textArea = new JTextArea(6, width); // Ensure it is accessible AccessibilityDecorator.apply(textArea, MessageKey.PRIVATE_NOTES, MessageKey.PRIVATE_NOTES_TOOLTIP); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.SEED_PHRASE_LENGTH)); textArea.setDocument(doc); // Ensure we monitor changes doc.addDocumentListener(listener); // Ensure line wrapping occurs correctly textArea.setLineWrap(true); textArea.setWrapStyleWord(true); // Ensure TAB transfers focus AbstractAction transferFocus = new AbstractAction() { public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } }; textArea.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "transferFocus"); textArea.getActionMap().put("transferFocus", transferFocus); // Set the theme textArea.setBorder(new TextBubbleBorder(Themes.currentTheme.dataEntryBorder())); textArea.setBackground(Themes.currentTheme.dataEntryBackground()); textArea.setOpaque(false); return textArea; }
Example #13
Source File: MatchingHighlighter.java From groovy with Apache License 2.0 | 5 votes |
public MatchingHighlighter(SmartDocumentFilter smartDocumentFilter, JTextPane textEditor) { this.smartDocumentFilter = smartDocumentFilter; this.textEditor = textEditor; this.doc = (DefaultStyledDocument) textEditor.getStyledDocument(); initStyles(); }
Example #14
Source File: SmartDocumentFilter.java From groovy with Apache License 2.0 | 5 votes |
public SmartDocumentFilter(DefaultStyledDocument styledDocument) { this.styledDocument = styledDocument; this.styleContext = StyleContext.getDefaultStyleContext(); this.defaultStyle = this.styleContext.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(this.defaultStyle, MONOSPACED); initStyles(); }
Example #15
Source File: CasAnnotationViewer.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates the annotation display. */ private void displayAnnotationView() { // for speed, detach document from text pane before updating StyledDocument doc = (StyledDocument) this.textPane.getDocument(); Document blank = new DefaultStyledDocument(); this.textPane.setDocument(blank); // make sure annotationCheckboxPanel is showing this.typeCheckBoxVerticalScrollPanel.removeAll(); // add text from CAS try { doc.remove(0, doc.getLength()); doc.insertString(0, this.cas.getDocumentText(), new SimpleAttributeSet()); } catch (BadLocationException e) { throw new RuntimeException(e); } // Iterate over annotations AnnotationIndex<AnnotationFS> annotationIndex = this.cas.getAnnotationIndex(); if (annotationIndex == null) { return; } FSIterator<AnnotationFS> annotationIterator = annotationIndex.iterator(); if (annotationIterator == null || !annotationIterator.hasNext()) { return; } while (annotationIterator.hasNext()) { this.processOneAnnotationInAnnotationView(doc, annotationIterator.next()); } // now populate panel with checkboxes in order specified in user file. JMP this.addTypeCheckBoxes(); // reattach document to text pane this.textPane.setDocument(doc); }
Example #16
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @return A new "enter transaction label" text field */ public static JTextField newEnterTransactionLabel() { JTextField textField = newTextField(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(textField, MessageKey.TRANSACTION_LABEL, MessageKey.TRANSACTION_LABEL_TOOLTIP); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH)); textField.setDocument(doc); return textField; }
Example #17
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @return A new "enter QR code label" text field */ public static JTextField newEnterQRCodeLabel() { JTextField textField = newTextField(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(textField, MessageKey.QR_CODE_LABEL, MessageKey.QR_CODE_LABEL_TOOLTIP); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH)); textField.setDocument(doc); return textField; }
Example #18
Source File: RTFParser.java From birt with Eclipse Public License 1.0 | 5 votes |
private static void parseElement( DefaultStyledDocument document, Element parent, RTFDocumentHandler handler, boolean lostLast ) { for ( int i = 0; i < parent.getElementCount( ); i++ ) { if (lostLast && i==parent.getElementCount( )-1 && parent.getElementCount( ) != 1) { break; } Element element = parent.getElement( i ); AttributeSet attributeset = element.getAttributes( ); handler.startElement( element.getName( ), attributeset ); if ( element.getName( ).equalsIgnoreCase( "content" ) ) { try { int start = element.getStartOffset( ); int end = element.getEndOffset( ); String s = document.getText( start, end - start ); handler.content( s ); } catch ( BadLocationException e ) { } } parseElement( document, element, handler, false ); handler.endElement( element.getName( ) ); } }
Example #19
Source File: RTFParser.java From birt with Eclipse Public License 1.0 | 5 votes |
public static void parse( String rtfString, RTFDocumentHandler handler ) throws IOException, BadLocationException { RTFEditorKit rtfeditorkit = new RTFEditorKit( ); DefaultStyledDocument document = new DefaultStyledDocument( ); ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream( rtfString.getBytes( ) ); rtfeditorkit.read( bytearrayinputstream, document, 0 ); Element element = document.getDefaultRootElement( ); parseElement( document, element, handler, true ); }
Example #20
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @return A new "seed phrase" text area for entry */ public static JTextArea newEnterSeedPhrase() { // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.SEED_PHRASE_LENGTH)); // Keep this in line with the PASSWORD_AREA constant JTextArea textArea = new JTextArea(doc, "", 6, BitherUI.PASSWORD_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(textArea, MessageKey.SEED_PHRASE); // Ensure TAB transfers focus AbstractAction transferFocus = new AbstractAction() { public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } }; textArea.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "transferFocus"); textArea.getActionMap().put("transferFocus", transferFocus); // Ensure line and word wrapping occur as required textArea.setLineWrap(true); textArea.setWrapStyleWord(true); // Set the theme textArea.setBorder(new TextBubbleBorder(Themes.currentTheme.dataEntryBorder())); textArea.setBackground(Themes.currentTheme.dataEntryBackground()); textArea.setFont(new Font("Courier New", Font.PLAIN, 14)); return textArea; }
Example #21
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @return A new "seed phrase" text area for entry */ public static JTextArea newEnterSeedPhrase() { // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.SEED_PHRASE_LENGTH)); // Keep this in line with the PASSWORD_AREA constant JTextArea textArea = new JTextArea(doc, "", 6, BitherUI.PASSWORD_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(textArea, MessageKey.SEED_PHRASE); // Ensure TAB transfers focus AbstractAction transferFocus = new AbstractAction() { public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } }; textArea.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "transferFocus"); textArea.getActionMap().put("transferFocus", transferFocus); // Ensure line and word wrapping occur as required textArea.setLineWrap(true); textArea.setWrapStyleWord(true); // Set the theme textArea.setBorder(new TextBubbleBorder(Themes.currentTheme.dataEntryBorder())); textArea.setBackground(Themes.currentTheme.dataEntryBackground()); textArea.setFont(new Font("Courier New", Font.PLAIN, 14)); return textArea; }
Example #22
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @param listener The document listener for detecting changes to the content * @return A new "Notes" text area */ public static JTextArea newEnterPrivateNotes(DocumentListener listener, int width) { JTextArea textArea = new JTextArea(6, width); // Ensure it is accessible AccessibilityDecorator.apply(textArea, MessageKey.PRIVATE_NOTES, MessageKey.PRIVATE_NOTES_TOOLTIP); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.SEED_PHRASE_LENGTH)); textArea.setDocument(doc); // Ensure we monitor changes doc.addDocumentListener(listener); // Ensure line wrapping occurs correctly textArea.setLineWrap(true); textArea.setWrapStyleWord(true); // Ensure TAB transfers focus AbstractAction transferFocus = new AbstractAction() { public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } }; textArea.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "transferFocus"); textArea.getActionMap().put("transferFocus", transferFocus); // Set the theme textArea.setBorder(new TextBubbleBorder(Themes.currentTheme.dataEntryBorder())); textArea.setBackground(Themes.currentTheme.dataEntryBackground()); textArea.setOpaque(false); return textArea; }
Example #23
Source File: VersionPane.java From bigtable-sql with Apache License 2.0 | 5 votes |
public void mouseMoved(MouseEvent ev) { JTextPane editor = (JTextPane) ev.getSource(); editor.setEditable(false); Point pt = new Point(ev.getX(), ev.getY()); int pos = editor.viewToModel(pt); if (pos >= 0) { Document eDoc = editor.getDocument(); if (eDoc instanceof DefaultStyledDocument) { DefaultStyledDocument hdoc = (DefaultStyledDocument) eDoc; Element e = hdoc.getCharacterElement(pos); AttributeSet a = e.getAttributes(); AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A); String href = null; if (tagA!=null){ href = (String)tagA.getAttribute(HTML.Attribute.HREF); } if (href != null) { editor.setToolTipText(href); if (editor.getCursor().getType() != Cursor.HAND_CURSOR) { editor.setCursor(new Cursor(Cursor.HAND_CURSOR)); } } else { editor.setToolTipText(null); if (editor.getCursor().getType() != Cursor.DEFAULT_CURSOR) { editor.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } } else { editor.setToolTipText(null); } }
Example #24
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @return A new "enter transaction label" text field */ public static JTextField newEnterTransactionLabel() { JTextField textField = newTextField(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(textField, MessageKey.TRANSACTION_LABEL, MessageKey.TRANSACTION_LABEL_TOOLTIP); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH)); textField.setDocument(doc); return textField; }
Example #25
Source File: TextBoxes.java From bither-desktop-java with Apache License 2.0 | 5 votes |
/** * @return A new "enter QR code label" text field */ public static JTextField newEnterQRCodeLabel() { JTextField textField = newTextField(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH); // Ensure it is accessible AccessibilityDecorator.apply(textField, MessageKey.QR_CODE_LABEL, MessageKey.QR_CODE_LABEL_TOOLTIP); // Limit the length of the underlying document DefaultStyledDocument doc = new DefaultStyledDocument(); doc.setDocumentFilter(new DocumentMaxLengthFilter(BitherUI.RECEIVE_ADDRESS_LABEL_LENGTH)); textField.setDocument(doc); return textField; }
Example #26
Source File: MagicTextPane.java From MtgDesktopCompanion with GNU General Public License v3.0 | 5 votes |
public void updateTextWithIcons() { textPane.setText(textPane.getText().replaceAll("(?m)^[ \t]*\r?\n", "")); Pattern p = Pattern.compile(CardsPatterns.MANA_PATTERN.getPattern()); Matcher m = p.matcher(textPane.getText()); String text = textPane.getText(); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Style italic = context.addStyle("italicStyle", labelStyle); StyleConstants.setItalic(italic, true); int cumule = 0; try { document.insertString(0, text, null); while (m.find()) { Image ic = manaPanel.getManaSymbol(m.group()); int width = 15; if (m.group().equals("{100}")) width = 30; JLabel label = new JLabel(new ImageIcon(ic.getScaledInstance(width, 15, Image.SCALE_DEFAULT))); label.setAlignmentY(SwingConstants.TOP); StyleConstants.setComponent(labelStyle, label); document.remove(m.start() + cumule, (m.end() - m.start())); document.insertString(m.start() + cumule, m.group(), labelStyle); } textPane.setDocument(document); } catch (BadLocationException e) { textPane.setText(text); } }
Example #27
Source File: RTFParser.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
protected String extractText(InputStream input) throws IOException, BadLocationException { RTFEditorKit rek = new RTFEditorKit(); DefaultStyledDocument doc = new DefaultStyledDocument(); rek.read(input, doc, 0); String text = doc.getText(0, doc.getLength()); return text; }
Example #28
Source File: HighlightingTest.java From netbeans with Apache License 2.0 | 5 votes |
private Document createDocument(String text) { try { DefaultStyledDocument doc = new DefaultStyledDocument(); doc.putProperty(Language.class, JavaTokenId.language()); doc.insertString(0, text, SimpleAttributeSet.EMPTY); return doc; } catch (BadLocationException e) { fail(e.getMessage()); } return null; }
Example #29
Source File: HintsControllerImplTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testComputeLineSpan() throws Exception { doTestComputeLineSpan(new DocumentCreator() { public Document createDocument() { return new NbEditorDocument(BaseKit.class); } }); doTestComputeLineSpan(new DocumentCreator() { public Document createDocument() { return new DefaultStyledDocument(); } }); }
Example #30
Source File: SyntaxHighlightingTest.java From netbeans with Apache License 2.0 | 5 votes |
private Document createDocument(Language lang, String text) { try { DefaultStyledDocument doc = new DefaultStyledDocument(); doc.putProperty(Language.class, lang); doc.insertString(0, text, SimpleAttributeSet.EMPTY); return doc; } catch (BadLocationException e) { fail(e.getMessage()); return null; } }