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 File: JConsole.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #2
Source File: ConsoleModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: MergingPositionsBagTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: REditorPane.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: TextRegionManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: Highlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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 #7
Source File: ComposedTextHighlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: RefactoringUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: ChooseByNameBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: CategoryRenderer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@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 #12
Source File: ConnectedTextFieldDocument.java    From gtasa-savegame-editor with MIT License 6 votes vote down vote up
@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 #13
Source File: UsagesASTEvaluator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static AttributeSet getLocalVariableAttributes () {
    if (localVariableAttributeSet == null) {
        SimpleAttributeSet sas = new SimpleAttributeSet ();
        localVariableAttributeSet = sas;
    }
    return localVariableAttributeSet;
}
 
Example #14
Source File: ExternalProgramConfig.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
public void insertString(int offs, String str, AttributeSet a)
                                             throws BadLocationException {

   super.insertString(offs, str, a);
   if (getText(0, getLength()).length() > 0)
      doSomethingEntered();
}
 
Example #15
Source File: DocumentSizeFilter.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
    throws BadLocationException {
  if ((fb.getDocument().getLength() + str.length()) <= maxCharacters)
    super.insertString(fb, offs, str, a);
  else
    Toolkit.getDefaultToolkit().beep();
}
 
Example #16
Source File: ColoringStorageTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAllLanguages() throws IOException {
    EditorSettingsStorage<String, AttributeSet> ess = EditorSettingsStorage.<String, AttributeSet>get(ColoringStorage.ID);
    Map<String, AttributeSet> colorings = ess.load(MimePath.EMPTY, "MyProfileXyz", true); //NOI18N
    assertNotNull("Colorings map should not be null", colorings);
    assertEquals("Wrong number of colorings", 1, colorings.size());
    
    AttributeSet c = colorings.get("test-all-languages-super-default");
    assertNotNull("Should have test-all-languages-super-default coloring", c);
    assertEquals("Wrong bgColor", new Color(0xABCDEF), c.getAttribute(StyleConstants.Background));
}
 
Example #17
Source File: Map.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Defines a region of the Map, based on the passed in AttributeSet.
 */
public void addArea(AttributeSet as) {
    if (as == null) {
        return;
    }
    if (areaAttributes == null) {
        areaAttributes = new Vector<AttributeSet>(2);
    }
    areaAttributes.addElement(as.copyAttributes());
}
 
Example #18
Source File: CompositeFCS.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
     * Gets the coloring for a highlight. Highlights are used for highlighting
     * important things in editor such as a caret row, text selection, marking
     * text found by the last search peration, etc. They are not bound to any
     * tokens and therefore are mime type independent.
     */
    @Override
    public AttributeSet getFontColors(String highlightName) {
        assert highlightName != null : "The parameter highlightName must not be null."; //NOI18N

        AttributeSet attribs = null;
        Map<String, AttributeSet> coloringsMap = EditorSettings.getDefault().getHighlightings(profile);
        if (coloringsMap != null) {
            attribs = coloringsMap.get(highlightName);
        }

        if (highlightName.equals(FontColorNames.DEFAULT_COLORING) && (attribs == null || attribs.getAttribute(StyleConstants.FontFamily) == null) ) {
            ArrayList<AttributeSet> colorings = new ArrayList<>();
            String name = highlightName;

            for (FontColorSettingsImpl fcsi : allFcsi) {
                name = processLayer(fcsi, name, colorings);
            }

            colorings.add(getHardcodedDefaultColoring());
            colorings.add(AttributesUtilities.createImmutable(
                    EditorStyleConstants.RenderingHints, getRenderingHints()));

            return AttributesUtilities.createImmutable(colorings.toArray(new AttributeSet[colorings.size()]));

        }

//        dumpAttribs(attribs, highlightName, false);
        return attribs;
    }
 
Example #19
Source File: AttributesUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Collection<?> getAllKeys() {
    HashSet<Object> allKeys = new HashSet<Object>();

    for(AttributeSet delegate : new AttributeSet[] {delegate0, delegate1}) {
        for(Enumeration<?> keys = delegate.getAttributeNames(); keys.hasMoreElements(); ) {
            Object key = keys.nextElement();
            allKeys.add(key);
        }
    }

    return allKeys;
}
 
Example #20
Source File: Map.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public RectangleRegionContainment(AttributeSet as) {
    int[]    coords = Map.extractCoords(as.getAttribute(HTML.
                                                   Attribute.COORDS));

    percents = null;
    if (coords == null || coords.length != 4) {
        throw new RuntimeException("Unable to parse rectangular area");
    }
    else {
        x0 = coords[0];
        y0 = coords[1];
        x1 = coords[2];
        y1 = coords[3];
        if (x0 < 0 || y0 < 0 || x1 < 0 || y1 < 0) {
            percents = new float[4];
            lastWidth = lastHeight = -1;
            for (int counter = 0; counter < 4; counter++) {
                if (coords[counter] < 0) {
                    percents[counter] = Math.abs
                                (coords[counter]) / 100.0f;
                }
                else {
                    percents[counter] = -1.0f;
                }
            }
        }
    }
}
 
Example #21
Source File: MockAttributeSet.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void addAttributes(AttributeSet attr)
{
    Enumeration as = attr.getAttributeNames();
    while(as.hasMoreElements()) {
        Object el = as.nextElement();
        backing.put(el, attr.getAttribute(el));
    }
}
 
Example #22
Source File: ColoringMap.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void collectNonTokenColorings(
    HashMap<String, Coloring> coloringMap, 
    FontColorSettings fcs
) {
    for (String coloringName: FONT_COLOR_NAMES_COLORINGS) {
        AttributeSet attribs = fcs.getFontColors(coloringName);
        if (attribs != null) {
            LOG.fine("Loading coloring '" + coloringName + "'"); //NOI18N
            coloringMap.put(coloringName, Coloring.fromAttributeSet(attribs));
        }
    }
}
 
Example #23
Source File: Map.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the previously created area.
 */
public void removeArea(AttributeSet as) {
    if (as != null && areaAttributes != null) {
        int numAreas = (areas != null) ? areas.size() : 0;
        for (int counter = areaAttributes.size() - 1; counter >= 0;
             counter--) {
            if (areaAttributes.elementAt(counter).isEqual(as)){
                areaAttributes.removeElementAt(counter);
                if (counter < numAreas) {
                    areas.removeElementAt(counter);
                }
            }
        }
    }
}
 
Example #24
Source File: Map.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Defines a region of the Map, based on the passed in AttributeSet.
 */
public void addArea(AttributeSet as) {
    if (as == null) {
        return;
    }
    if (areaAttributes == null) {
        areaAttributes = new Vector<AttributeSet>(2);
    }
    areaAttributes.addElement(as.copyAttributes());
}
 
Example #25
Source File: DiffColorsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #26
Source File: Map.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #27
Source File: TextAreaReadline.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Output methods
 **/

protected void append(String toAppend, AttributeSet style) {
    try {
        area.getDocument().insertString(area.getDocument().getLength(),
                toAppend, style);
    } catch (BadLocationException e) {
    }
}
 
Example #28
Source File: DiffColorsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 File: SyntaxColoringPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isFontChanged(String language, AttributeSet currentAS, AttributeSet savedAS) {
    String name = (String) getValue(language, currentAS, StyleConstants.FontFamily);
    assert (name != null);
    Integer size = (Integer) getValue(language, currentAS, StyleConstants.FontSize);
    assert (size != null);
    Boolean bold = (Boolean) getValue(language, currentAS, StyleConstants.Bold);
    if (bold == null) {
        bold = Boolean.FALSE;
    }
    Boolean italic = (Boolean) getValue(language, currentAS, StyleConstants.Italic);
    if (italic == null) {
        italic = Boolean.FALSE;
    }
    int style = bold.booleanValue() ? Font.BOLD : Font.PLAIN;
    if (italic.booleanValue()) {
        style += Font.ITALIC;
    }
    Font currentFont = new Font(name, style, size.intValue());
    
    name = (String) getValue(language, savedAS, StyleConstants.FontFamily);
    assert (name != null);
    size = (Integer) getValue(language, savedAS, StyleConstants.FontSize);
    assert (size != null);
    bold = (Boolean) getValue(language, savedAS, StyleConstants.Bold);
    if (bold == null) {
        bold = Boolean.FALSE;
    }
    italic = (Boolean) getValue(language, savedAS, StyleConstants.Italic);
    if (italic == null) {
        italic = Boolean.FALSE;
    }
    style = bold.booleanValue() ? Font.BOLD : Font.PLAIN;
    if (italic.booleanValue()) {
        style += Font.ITALIC;
    }
    Font savedFont = new Font(name, style, size.intValue());
    return !currentFont.equals(savedFont);
}
 
Example #30
Source File: EditableNotificationMessageElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void updateStyle(@Nonnull JEditorPane editorPane, @javax.annotation.Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
  super.updateStyle(editorPane, tree, value, selected, hasFocus);

  final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
  final Style linkStyle = htmlDocument.getStyleSheet().getStyle(LINK_STYLE);
  StyleConstants.setForeground(linkStyle, IdeTooltipManager.getInstance().getLinkForeground(false));
  StyleConstants.setItalic(linkStyle, true);
  HTMLDocument.Iterator iterator = htmlDocument.getIterator(HTML.Tag.A);
  while (iterator.isValid()) {
    boolean disabledLink = false;
    final AttributeSet attributes = iterator.getAttributes();
    if (attributes instanceof SimpleAttributeSet) {
      final Object attribute = attributes.getAttribute(HTML.Attribute.HREF);
      if (attribute instanceof String && disabledLinks.containsKey(attribute)) {
        disabledLink = true;
        //TODO [Vlad] add support for disabled link text update
        ////final String linkText = disabledLinks.get(attribute);
        //if (linkText != null) {
        //}
        ((SimpleAttributeSet)attributes).removeAttribute(HTML.Attribute.HREF);
      }
      if (attribute == null) {
        disabledLink = true;
      }
    }
    if (!disabledLink) {
      htmlDocument.setCharacterAttributes(
              iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset(), linkStyle, false);
    }
    iterator.next();
  }
}