javax.swing.text.AttributeSet Java Examples
The following examples show how to use
javax.swing.text.AttributeSet.
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 Project: marathonv5 Author: jalian-systems File: REditorPane.java License: Apache License 2.0 | 6 votes |
public void setHRef(int pos, Document doc) { hRef = null; text = null; if (!(doc instanceof HTMLDocument)) { return; } HTMLDocument hdoc = (HTMLDocument) doc; Iterator iterator = hdoc.getIterator(HTML.Tag.A); while (iterator.isValid()) { if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) { AttributeSet attributes = iterator.getAttributes(); if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) { try { text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim(); hRef = attributes.getAttribute(HTML.Attribute.HREF).toString(); setIndexOfHrefAndText(hdoc, pos, text, hRef); } catch (BadLocationException e) { e.printStackTrace(); } return; } } iterator.next(); } }
Example #2
Source Project: netbeans Author: apache File: Highlighting.java License: Apache License 2.0 | 6 votes |
/** Creates a new instance of Highlighting */ public Highlighting(Document doc) { AttributeSet firstLineFontColor = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(FontColorSettings.class).getTokenFontColors("javadoc-first-sentence"); //NOI18N AttributeSet commentFontColor = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(FontColorSettings.class).getTokenFontColors("comment"); //NOI18N if(firstLineFontColor != null && commentFontColor != null) { Collection<Object> attrs = new LinkedList<>(); for (Enumeration<?> e = firstLineFontColor.getAttributeNames(); e.hasMoreElements(); ) { Object key = e.nextElement(); Object value = firstLineFontColor.getAttribute(key); if (!commentFontColor.containsAttribute(key, value)) { attrs.add(key); attrs.add(value); } } fontColor = AttributesUtilities.createImmutable(attrs.toArray()); } else { fontColor = AttributesUtilities.createImmutable(); LOG.warning("FontColorSettings for javadoc-first-sentence or comment are not available."); //NOI18N } this.document = doc; hierarchy = TokenHierarchy.get(document); if (hierarchy != null) { hierarchy.addTokenHierarchyListener(WeakListeners.create(TokenHierarchyListener.class, this, hierarchy)); } }
Example #3
Source Project: netbeans Author: apache File: ComposedTextHighlighting.java License: Apache License 2.0 | 6 votes |
public ComposedTextHighlighting(JTextComponent component, Document document, String mimeType) { // Prepare the highlight FontColorSettings fcs = MimeLookup.getLookup(MimePath.parse(mimeType)).lookup(FontColorSettings.class); AttributeSet dc = fcs.getFontColors(FontColorNames.DEFAULT_COLORING); Color background = (Color) dc.getAttribute(StyleConstants.Background); Color foreground = (Color) dc.getAttribute(StyleConstants.Foreground); highlightInverse = AttributesUtilities.createImmutable(StyleConstants.Background, foreground, StyleConstants.Foreground, background); highlightUnderlined = AttributesUtilities.createImmutable(StyleConstants.Underline, foreground); // Create the highlights container this.bag = new OffsetsBag(document); this.bag.addHighlightsChangeListener(this); // Start listening on the document this.document = document; this.document.addDocumentListener(WeakListeners.document(this, this.document)); this.component = component; }
Example #4
Source Project: consulo Author: consulo File: ChooseByNameBase.java License: Apache License 2.0 | 6 votes |
private MyTextField() { super(40); enableEvents(AWTEvent.KEY_EVENT_MASK); myCompletionKeyStroke = getShortcut(IdeActions.ACTION_CODE_COMPLETION); forwardStroke = getShortcut(IdeActions.ACTION_GOTO_FORWARD); backStroke = getShortcut(IdeActions.ACTION_GOTO_BACK); setFocusTraversalKeysEnabled(false); putClientProperty("JTextField.variant", "search"); setDocument(new PlainDocument() { @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { super.insertString(offs, str, a); if (str != null && str.length() > 1) { handlePaste(str); } } }); }
Example #5
Source Project: MeteoInfo Author: meteoinfo File: JConsole.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void print( final Object o, final String fontFamilyName, final int size, final Color color, final boolean bold, final boolean italic, final boolean underline ) { invokeAndWait(new Runnable() { @Override public void run() { AttributeSet old = getStyle(); setStyle(fontFamilyName, size, color, bold, italic, underline); append(String.valueOf(o)); resetCommandStart(); text.setCaretPosition(cmdStart); setStyle(old, true); } }); }
Example #6
Source Project: gtasa-savegame-editor Author: gtasa-savegame-editor File: ConnectedTextFieldDocument.java License: MIT License | 6 votes |
@Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { StringBuilder builder = new StringBuilder(); if (chars == null) { if (maxLength > 0 && getLength() + str.length() > maxLength) { builder.append(str, 0, maxLength - getLength()); } else { builder.append(str); } } else { loop: for (int i = 0; i < str.length() && (maxLength < 1 || getLength() < maxLength); i++) { for (char c : chars) { if (str.charAt(i) == c) { builder.append(c); continue loop; } } } } super.insertString(offs, builder.toString(), a); }
Example #7
Source Project: java-swing-tips Author: aterai File: MainPanel.java License: MIT License | 6 votes |
@Override public void insertString(int offset, String text, AttributeSet a) throws BadLocationException { // @see PlainDocument#insertString(...) int length = 0; String str = text; if (Objects.nonNull(str) && str.indexOf(LB) >= 0) { StringBuilder filtered = new StringBuilder(str); int n = filtered.length(); for (int i = 0; i < n; i++) { if (filtered.charAt(i) == LB) { filtered.setCharAt(i, ' '); } } str = filtered.toString(); length = str.length(); } super.insertString(offset, str, a); processChangedLines(offset, length); }
Example #8
Source Project: netbeans Author: apache File: CategoryRenderer.java License: Apache License 2.0 | 6 votes |
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setComponentOrientation(list.getComponentOrientation()); if (isSelected) { setBackground(list.getSelectionBackground ()); setForeground(list.getSelectionForeground ()); } else { setBackground(list.getBackground ()); setForeground(list.getForeground ()); } setIcon((Icon) ((AttributeSet) value).getAttribute ("icon")); setText((String) ((AttributeSet) value).getAttribute (EditorStyleConstants.DisplayName)); setEnabled(list.isEnabled()); setFont(list.getFont()); setBorder(cellHasFocus ? UIManager.getBorder ("List.focusCellHighlightBorder") : noFocusBorder); return this; }
Example #9
Source Project: netbeans Author: apache File: RefactoringUtils.java License: Apache License 2.0 | 6 votes |
public static String getHtml(String text) { StringBuilder buf = new StringBuilder(); // TODO - check whether we need Js highlighting or rhtml highlighting TokenHierarchy tokenH = TokenHierarchy.create(text, PHPTokenId.language()); Lookup lookup = MimeLookup.getLookup(MimePath.get(FileUtils.PHP_MIME_TYPE)); FontColorSettings settings = lookup.lookup(FontColorSettings.class); @SuppressWarnings("unchecked") TokenSequence<? extends TokenId> tok = tokenH.tokenSequence(); while (tok.moveNext()) { Token<? extends TokenId> token = tok.token(); String category = token.id().name(); AttributeSet set = settings.getTokenFontColors(category); if (set == null) { category = token.id().primaryCategory(); if (category == null) { category = "whitespace"; //NOI18N } set = settings.getTokenFontColors(category); } String tokenText = htmlize(token.text().toString()); buf.append(color(tokenText, set)); } return buf.toString(); }
Example #10
Source Project: netbeans Author: apache File: TextRegionManager.java License: Apache License 2.0 | 6 votes |
private static AttributeSet createAttribs(Object... keyValuePairs) { assert keyValuePairs.length % 2 == 0 : "There must be even number of prameters. " + "They are key-value pairs of attributes that will be inserted into the set."; List<Object> list = new ArrayList<Object>(keyValuePairs.length); for (int i = keyValuePairs.length / 2 - 1; i >= 0; i--) { Object attrKey = keyValuePairs[2 * i]; Object attrValue = keyValuePairs[2 * i + 1]; if (attrKey != null && attrValue != null) { list.add(attrKey); list.add(attrValue); } } return AttributesUtilities.createImmutable(list.toArray()); }
Example #11
Source Project: netbeans Author: apache File: ConsoleModel.java License: Apache License 2.0 | 6 votes |
@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { if (!isValid()) { super.replace(fb, offset, length, text, attrs); return; } bypass = fb; int wr = getWritablePos(); if (offset >= wr) { super.replace(fb, offset, length, text, attrs); return; } int endPos = offset + length; if (endPos < wr) { return; } int remainder = offset + length - wr; int prefix = wr - offset; }
Example #12
Source Project: netbeans Author: apache File: MergingPositionsBagTest.java License: Apache License 2.0 | 6 votes |
public void testAddLeftMatchSmallerOverlap() { PositionsBag hs = new PositionsBag(doc, true); SimpleAttributeSet attribsA = new SimpleAttributeSet(); SimpleAttributeSet attribsB = new SimpleAttributeSet(); attribsA.addAttribute("set-A", "attribsA"); attribsB.addAttribute("set-B", "attribsB"); hs.addHighlight(pos(10), pos(20), attribsA); hs.addHighlight(pos(10), pos(15), attribsB); GapList<Position> marks = hs.getMarks(); GapList<AttributeSet> attributes = hs.getAttributes(); assertEquals("Wrong number of highlights", 3, marks.size()); assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset()); assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B"); assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset()); assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A"); assertNull("2. highlight - wrong end", attributes.get(2)); }
Example #13
Source Project: netbeans Author: apache File: DocumentElement.java License: Apache License 2.0 | 5 votes |
public boolean containsAttributes(AttributeSet attributes) { Enumeration e = attributes.getAttributeNames(); while(e.hasMoreElements()) { Object key = e.nextElement(); Object value = attributes.getAttribute(key); if(!containsAttribute(key, value)) return false; } return true; }
Example #14
Source Project: netbeans Author: apache File: UsagesASTEvaluator.java License: Apache License 2.0 | 5 votes |
private static AttributeSet getUnusedLocalVariableAttributes () { if (unusedLocalVariableAttributeSet == null) { SimpleAttributeSet sas = new SimpleAttributeSet (); sas.addAttribute (EditorStyleConstants.WaveUnderlineColor, new Color (153, 153, 153)); unusedLocalVariableAttributeSet = sas; } return unusedLocalVariableAttributeSet; }
Example #15
Source Project: binnavi Author: google File: CFilenameFormatter.java License: Apache License 2.0 | 5 votes |
@Override public void replace(final DocumentFilter.FilterBypass fb, final int offset, final int length, final String string, final AttributeSet attr) throws BadLocationException { if (isValid(string, length)) { super.replace(fb, offset, length, string, attr); } }
Example #16
Source Project: java-swing-tips Author: aterai File: MainPanel.java License: MIT License | 5 votes |
@Override public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { int len = fb.getDocument().getLength(); if (len - length + text.length() > MAX) { Toolkit.getDefaultToolkit().beep(); return; } fb.replace(offset, length, text, attrs); }
Example #17
Source Project: snap-desktop Author: senbox-org File: ConsolePane.java License: GNU General Public License v3.0 | 5 votes |
private void append(String text, AttributeSet attributes) { if (this.isVisible()) { int len = textArea.getDocument().getLength(); textArea.setCaretPosition(len); textArea.setCharacterAttributes(attributes, false); textArea.replaceSelection("\n" + text); textArea.repaint(); } else { buffer.append(text); } }
Example #18
Source Project: netbeans Author: apache File: HighlightingPanel.java License: Apache License 2.0 | 5 votes |
private void fireChanged() { boolean isChanged = false; for (String profile : toBeSaved) { if (profileToCategories.containsKey(profile)) { List<AttributeSet> attributeSet = getCategories(profile); Map<String, AttributeSet> savedHighlightings = EditorSettings.getDefault().getHighlightings(profile); Map<String, AttributeSet> currentHighlightings = toMap(attributeSet); if (savedHighlightings != null && currentHighlightings != null) { if (savedHighlightings.size() >= currentHighlightings.size()) { isChanged |= checkMaps(savedHighlightings, currentHighlightings); } else { isChanged |= checkMaps(currentHighlightings, savedHighlightings); } } else if (savedHighlightings != null && currentHighlightings == null) { isChanged = true; } if (isChanged) { // no need to iterate further changed = true; return; } } else { changed = true; return; } } changed = isChanged; }
Example #19
Source Project: jdk1.8-source-analysis Author: raysonfang File: MockAttributeSet.java License: Apache License 2.0 | 5 votes |
public void addAttributes(AttributeSet attr) { Enumeration as = attr.getAttributeNames(); while(as.hasMoreElements()) { Object el = as.nextElement(); backing.put(el, attr.getAttribute(el)); } }
Example #20
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: Test6968363.java License: GNU General Public License v2.0 | 5 votes |
@Override public void insertString(int offset, String string, AttributeSet set) throws BadLocationException { for (int i = 0; i < string.length(); i++) { System.out.println("i: " + i + "; ch: " + Integer.toHexString(string.charAt(i))); } this.document.insertString(offset, string, set); }
Example #21
Source Project: jdk8u_jdk Author: JetBrains File: ParagraphView.java License: GNU General Public License v2.0 | 5 votes |
/** * Fetches the attributes to use when rendering. This is * implemented to multiplex the attributes specified in the * model with a StyleSheet. */ public AttributeSet getAttributes() { if (attr == null) { StyleSheet sheet = getStyleSheet(); attr = sheet.getViewAttributes(this); } return attr; }
Example #22
Source Project: binnavi Author: google File: SyntaxDocument.java License: Apache License 2.0 | 5 votes |
private void highlightLinesAfter(final String content, final int line) { final int offset = rootElement.getElement(line).getEndOffset(); // Start/End delimiter not found, nothing to do int startDelimiter = indexOf(content, getStartDelimiter(), offset); int endDelimiter = indexOf(content, getEndDelimiter(), offset); if (startDelimiter < 0) { startDelimiter = content.length(); } if (endDelimiter < 0) { endDelimiter = content.length(); } final int delimiter = Math.min(startDelimiter, endDelimiter); if (delimiter < offset) { return; } // Start/End delimiter found, reapply highlighting final int endLine = rootElement.getElementIndex(delimiter); for (int i = line + 1; i < endLine; i++) { final Element branch = rootElement.getElement(i); final Element leaf = doc.getCharacterElement(branch.getStartOffset()); final AttributeSet as = leaf.getAttributes(); if (as.isEqual(comment)) { applyHighlighting(content, i); } } }
Example #23
Source Project: orbit-image-analysis Author: mstritt File: ResultFrame.java License: GNU General Public License v3.0 | 5 votes |
public ResultFrame(String text, String title) { //textArea = new JTextArea(text); if (text != null && (text.startsWith("<html") || text.startsWith("<HTML"))) textArea = new JEditorPane("text/html", text); else textArea = new JTextPane(); if (textArea instanceof JTextPane) { AttributeSet attributes = ((JTextPane) textArea).getParagraphAttributes(); try { textArea.getDocument().insertString(0, text, attributes); } catch (BadLocationException e) { e.printStackTrace(); } } textArea.setEditable(false); textArea.setCaretPosition(0); if (OrbitUtils.DARKUI) { textArea.setForeground(Color.white); textArea.setBackground(Color.darkGray); } JScrollPane scrollPane = new JScrollPane(textArea); add(scrollPane); setSize(600, 600); Toolkit toolkit = getToolkit(); Dimension size = toolkit.getScreenSize(); setLocation((size.width - getWidth()) / 2, (size.height - getHeight()) / 2); setTitle(title); java.net.URL imgURL = this.getClass().getResource(OrbitImageAnalysis.LOGO_NAME); if (imgURL != null) { ImageIcon icon = new ImageIcon(imgURL); this.setFrameIcon(icon); } }
Example #24
Source Project: jdk8u-jdk Author: frohoff File: Map.java License: GNU General Public License v2.0 | 5 votes |
public CircleRegionContainment(AttributeSet as) { int[] coords = Map.extractCoords(as.getAttribute(HTML.Attribute. COORDS)); if (coords == null || coords.length != 3) { throw new RuntimeException("Unable to parse circular area"); } x = coords[0]; y = coords[1]; radiusSquared = coords[2] * coords[2]; if (coords[0] < 0 || coords[1] < 0 || coords[2] < 0) { lastWidth = lastHeight = -1; percentValues = new float[3]; for (int counter = 0; counter < 3; counter++) { if (coords[counter] < 0) { percentValues[counter] = coords[counter] / -100.0f; } else { percentValues[counter] = -1.0f; } } } else { percentValues = null; } }
Example #25
Source Project: binnavi Author: google File: CFilenameFormatter.java License: Apache License 2.0 | 5 votes |
@Override public void insertString(final DocumentFilter.FilterBypass fb, final int offset, final String string, final AttributeSet attr) throws BadLocationException { if (isValid(string, 0)) { super.insertString(fb, offset, string, attr); } }
Example #26
Source Project: energy2d Author: charxie File: ConsoleDocument.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void replace(int offs, int length, String str, AttributeSet attrs) throws BadLocationException { if (offs < offsetAfterPrompt) { if (offs + length < offsetAfterPrompt) { offs = getLength(); length = 0; } else { length -= offsetAfterPrompt - offs; offs = offsetAfterPrompt; } } super.replace(offs, length, str, attUserInput); // consoleTextPane.setCaretPosition(offs + str.length()); }
Example #27
Source Project: groovy Author: apache File: SmartDocumentFilter.java License: Apache License 2.0 | 5 votes |
@Override public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { // text might be null and indicates no replacement text if (text == null) text = ""; // remove problem meta characters returns text = replaceMetaCharacters(text); fb.replace(offset, length, text, attrs); parseDocument(); }
Example #28
Source Project: netbeans Author: apache File: DiffColorsPanel.java License: Apache License 2.0 | 5 votes |
private boolean fireChanged(AttributeSet color) { Color c = (Color) color.getAttribute(StyleConstants.Background); if (ATTR_NAME_ADDED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getAddedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultAddedColor()); } if (ATTR_NAME_CHANGED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getChangedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultChangedColor()); } if (ATTR_NAME_DELETED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getDeletedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultDeletedColor()); } if (ATTR_NAME_MERGE_APPLIED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getAppliedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultAppliedColor()); } if (ATTR_NAME_MERGE_NOTAPPLIED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getNotAppliedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultNotAppliedColor()); } if (ATTR_NAME_MERGE_UNRESOLVED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getUnresolvedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultUnresolvedColor()); } if (ATTR_NAME_SIDEBAR_DELETED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getSidebarDeletedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultSidebarDeletedColor()); } if (ATTR_NAME_SIDEBAR_CHANGED.equals(color.getAttribute(StyleConstants.NameAttribute))) { return !DiffModuleConfig.getDefault().getSidebarChangedColor().equals(c != null ? c : DiffModuleConfig.getDefault().getDefaultSidebarChangedColor()); } return false; }
Example #29
Source Project: jdk8u_jdk Author: JetBrains File: Map.java License: GNU General Public License v2.0 | 5 votes |
public CircleRegionContainment(AttributeSet as) { int[] coords = Map.extractCoords(as.getAttribute(HTML.Attribute. COORDS)); if (coords == null || coords.length != 3) { throw new RuntimeException("Unable to parse circular area"); } x = coords[0]; y = coords[1]; radiusSquared = coords[2] * coords[2]; if (coords[0] < 0 || coords[1] < 0 || coords[2] < 0) { lastWidth = lastHeight = -1; percentValues = new float[3]; for (int counter = 0; counter < 3; counter++) { if (coords[counter] < 0) { percentValues[counter] = coords[counter] / -100.0f; } else { percentValues[counter] = -1.0f; } } } else { percentValues = null; } }
Example #30
Source Project: netbeans Author: apache File: DiffColorsPanel.java License: Apache License 2.0 | 5 votes |
public void applyChanges() { List<AttributeSet> colors = getCategories(); for (AttributeSet color : colors) { if (ATTR_NAME_ADDED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setAddedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_CHANGED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setChangedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_DELETED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setDeletedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_MERGE_APPLIED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setAppliedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_MERGE_NOTAPPLIED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setNotAppliedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_MERGE_UNRESOLVED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setUnresolvedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_SIDEBAR_DELETED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setSidebarDeletedColor((Color) color.getAttribute(StyleConstants.Background)); if (ATTR_NAME_SIDEBAR_CHANGED.equals(color.getAttribute(StyleConstants.NameAttribute))) DiffModuleConfig.getDefault().setSidebarChangedColor((Color) color.getAttribute(StyleConstants.Background)); } changed = false; }