private static Color getColoring(FontColorSettings fcs, String tokenName) { AttributeSet as = fcs.getTokenFontColors(tokenName); if (as != null) { return (Color) as.getAttribute(StyleConstants.Background); //NOI18N } return null; }
public FoldView(JTextComponent textComponent, Fold fold, FontColorSettings colorSettings, int options) { super(null); int offset = fold.getStartOffset(); int len = fold.getEndOffset() - offset; assert (len > 0) : "length=" + len + " <= 0"; // NOI18N this.length = len; this.textComponent = textComponent; this.fold = fold; this.foldingColors = colorSettings.getFontColors(FontColorNames.CODE_FOLDING_COLORING); this.selectedColors = colorSettings.getFontColors(FontColorNames.SELECTION_COLORING); this.options = options; }
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>(); 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()); }
this.document.putProperty(PROP_HIGLIGHT_BLOCKS_LAYER, this); AttributeSet extendsEolEmptyLine = AttributesUtilities.createImmutable( HighlightsContainer.ATTR_EXTENDS_EOL, Boolean.TRUE, HighlightsContainer.ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE); AttributeSet as = settings.getTokenFontColors("pp-active-block"); //NOI18N if (as != null) { activeBlockHighlight = AttributesUtilities.createImmutable(as, extendsEolEmptyLine); } else { activeBlockHighlight = null; as = settings.getTokenFontColors("pp-inactive-block"); //NOI18N if (as != null) { inactiveBlockHighlight = AttributesUtilities.createImmutable(as, extendsEolEmptyLine); } else { inactiveBlockHighlight = null;
private Coloring getColoring() { if (attribs == null) { if (fcsLookupResult == null) { fcsLookupResult = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)) .lookupResult(FontColorSettings.class); fcsLookupResult.addLookupListener(WeakListeners.create(LookupListener.class, fcsTracker, fcsLookupResult)); } FontColorSettings fcs = fcsLookupResult.allInstances().iterator().next(); AttributeSet attr = fcs.getFontColors(FontColorNames.CODE_FOLDING_BAR_COLORING); if (attr == null) { attr = fcs.getFontColors(FontColorNames.DEFAULT_COLORING); } else { attr = AttributesUtilities.createComposite(attr, fcs.getFontColors(FontColorNames.DEFAULT_COLORING)); } attribs = attr; } return Coloring.fromAttributeSet(attribs); }
private JTextComponent.KeyBinding [] transform(List/*<o.n.api.e.s.MultiKeybinding>*/ keybindings) { ArrayList<JTextComponent.KeyBinding> jtcKeyBindings = new ArrayList<JTextComponent.KeyBinding>(keybindings.size()); for(Iterator i = keybindings.iterator(); i.hasNext(); ) { org.netbeans.api.editor.settings.MultiKeyBinding esMkb = (org.netbeans.api.editor.settings.MultiKeyBinding) i.next(); MultiKeyBinding editorMkb; if (0 == esMkb.getKeyStrokeCount()) { continue; } else if (1 == esMkb.getKeyStrokeCount()) { editorMkb = new MultiKeyBinding(esMkb.getKeyStroke(0), esMkb.getActionName()); } else { KeyStroke [] keyStrokes = (KeyStroke []) esMkb.getKeyStrokeList().toArray(new KeyStroke [esMkb.getKeyStrokeList().size()]); editorMkb = new MultiKeyBinding(keyStrokes, esMkb.getActionName()); } jtcKeyBindings.add(editorMkb); } return jtcKeyBindings.toArray(new JTextComponent.KeyBinding[jtcKeyBindings.size()]); }
protected static AttributeSet getFontColor(FontColorProvider provider, FontColorProvider.Entity entity) { AttributeSet attributes = AttributesUtilities.createComposite(provider.getColor(entity), cleanUp); return attributes; }
private static AttributeSet getHighlightAS () { FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class); AttributeSet as = fcs.getFontColors("synchronized-text-blocks"); //NOI18N return as == null ? defaultSyncedTextBlocksHighlight : as; }
@Override public AttributeSet getColor(Entity color) { synchronized(lock) { final AttributeSet tokenFontColors = fcs.getTokenFontColors(color.getResourceName()); assert tokenFontColors != null : "There is no color for "+color.getResourceName(); return tokenFontColors; } }
private static AttributeSet adjustAttributes(AttributeSet as) { Collection<Object> attrs = new LinkedList<Object>(); for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) { Object key = e.nextElement(); Object value = as.getAttribute(key); if (value != Boolean.FALSE) { attrs.add(key); attrs.add(value); } } return AttributesUtilities.createImmutable(attrs.toArray()); }
@Override public void updateFontColors(FontColorProvider provider) { super.updateFontColors(provider); unusedToolTipColors.put(provider.getMimeType(), AttributesUtilities.createComposite(UNUSED_TOOLTIP, super.getColor(provider.getMimeType()))); } }
private static AttributeSet getSyncedTextBlocksHighlight(String name) { FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class); AttributeSet as = fcs != null ? fcs.getFontColors(name) : null; return as == null ? defaultSyncedTextBlocksHighlight : as; }
private AttributeSet findFontAndColors(FontColorSettings fcs, TokenId tokenId, Language lang) { // First try the token's name String name = tokenId.name(); AttributeSet attribs = fcs.getTokenFontColors(updateColoringName(name)); // Then try the primary category if (attribs == null) { String primary = tokenId.primaryCategory(); if (primary != null) { attribs = fcs.getTokenFontColors(updateColoringName(primary)); } } // Then try all the other categories if (attribs == null) { @SuppressWarnings("unchecked") //NOI18N List<String> categories = ((Language<TokenId>)lang).nonPrimaryTokenCategories(tokenId); for(String c : categories) { attribs = fcs.getTokenFontColors(updateColoringName(c)); if (attribs != null) { break; } } } return attribs; }
EmbeddedSectionsHighlighting(Document document) { this.document = document; // load the background color for the embedding token AttributeSet attribs = null; String mimeType = (String) document.getProperty("mimeType"); //NOI18N FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); if (fcs != null) { Color jsBC = getColoring(fcs, RhtmlTokenId.RUBY.primaryCategory()); if (jsBC != null) { attribs = AttributesUtilities.createImmutable( StyleConstants.Background, jsBC, ATTR_EXTENDS_EOL, Boolean.TRUE); } } rubyBackground = attribs; }
private static Color getHighlight(String name, int defaultRGB) { FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class); AttributeSet as = (fcs != null) ? fcs.getFontColors(name) : null; if (as != null) { return (Color) as.getAttribute(StyleConstants.Background); } else { return new Color(defaultRGB); } }
public HeadersHighlighting(Document document) { this.document = document; this.document.putProperty(PROP_HIGLIGHT_HEADER_LAYER, this); FontColorSettings settings = MimeLookup.getLookup("text/x-java-preprocessor").lookup(FontColorSettings.class); //NOI18N commandHighlight = settings.getTokenFontColors("pp-command"); //NOI18N if (commandHighlight != null) { headersBag = new OffsetsBag(document); headersBag.addHighlightsChangeListener(new HighlightsChangeListener() { public void highlightChanged(HighlightsChangeEvent event) { fireHighlightsChange(event.getStartOffset(), event.getEndOffset()); } }); updateBags(); } else { headersBag = null; } }
private Map<?, ?> getRenderingHints() { Map<?, ?> renderingHints = null; // init hints if any Lookup lookup = MimeLookup.getLookup("text/plain"); // NOI18N if (lookup != null) { FontColorSettings fcs = lookup.lookup(FontColorSettings.class); if (fcs != null) { AttributeSet attributes = fcs.getFontColors(FontColorNames.DEFAULT_COLORING); if (attributes != null) { renderingHints = (Map<?, ?>) attributes.getAttribute(EditorStyleConstants.RenderingHints); } } } return renderingHints; }
/** * Get the colour for drawing text. */ public static Color getTextColor(JTextComponent jtc) { String mimeType = NbEditorUtilities.getMimeType(jtc); FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); AttributeSet fontColors = fcs.getFontColors("default"); Color fg = (Color) fontColors.getAttribute(StyleConstants.Foreground); return fg; // JTextComponent host = (JTextComponent) getContainer(); // return (host.isEnabled()) ? host.getForeground() : host.getDisabledTextColor(); }
public static Color getBackgroundColor(JTextComponent jtc) { String mimeType = NbEditorUtilities.getMimeType(jtc); FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); AttributeSet fontColors = fcs.getFontColors("default"); Color bg = (Color) fontColors.getAttribute(StyleConstants.Background); return bg; }
public static Font getFont(JTextComponent jtc) { String defaultFontName = "Monospaced"; String mimeType = NbEditorUtilities.getMimeType(jtc); FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); String fontName = (String) fcs.getFontColors("default").getAttribute(StyleConstants.FontFamily); Font smallFont = new Font(fontName != null ? fontName : defaultFontName, Font.PLAIN, Options.getFontSize()); return smallFont; } }