Search in sources :

Example 1 with NSRange

use of ch.cyberduck.binding.foundation.NSRange in project cyberduck by iterate-ch.

the class HyperlinkAttributedStringFactory method create.

/**
 * @param value     Existing attributes
 * @param hyperlink URL
 * @return Clickable and underlined string to put into text field.
 */
private static NSAttributedString create(final NSMutableAttributedString value, final String hyperlink) {
    final NSRange range = NSRange.NSMakeRange(new NSUInteger(0), value.length());
    value.beginEditing();
    value.addAttributeInRange(NSMutableAttributedString.LinkAttributeName, hyperlink, range);
    // make the text appear in blue
    value.addAttributeInRange(NSMutableAttributedString.ForegroundColorAttributeName, NSColor.blueColor(), range);
    // system font
    value.addAttributeInRange(NSMutableAttributedString.FontAttributeName, NSFont.systemFontOfSize(NSFont.smallSystemFontSize()), range);
    // next make the text appear with an underline
    value.addAttributeInRange(NSMutableAttributedString.UnderlineStyleAttributeName, NSNumber.numberWithInt(NSMutableAttributedString.SingleUnderlineStyle), range);
    value.endEditing();
    return value;
}
Also used : NSRange(ch.cyberduck.binding.foundation.NSRange) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger)

Example 2 with NSRange

use of ch.cyberduck.binding.foundation.NSRange in project cyberduck by iterate-ch.

the class PreferencesController method mark.

private void mark(NSMutableAttributedString text, PatternSyntaxException e) {
    if (null == e) {
        text.removeAttributeInRange(NSAttributedString.ForegroundColorAttributeName, NSRange.NSMakeRange(new NSUInteger(0), text.length()));
        return;
    }
    // The approximate index in the pattern of the error
    int index = e.getIndex();
    NSRange range = null;
    if (-1 == index) {
        range = NSRange.NSMakeRange(new NSUInteger(0), text.length());
    }
    if (index < text.length().intValue()) {
        // Initializes the NSRange with the range elements of location and length;
        range = NSRange.NSMakeRange(new NSUInteger(index), new NSUInteger(1));
    }
    text.addAttributesInRange(RED_FONT, range);
}
Also used : NSRange(ch.cyberduck.binding.foundation.NSRange) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger)

Aggregations

NSRange (ch.cyberduck.binding.foundation.NSRange)2 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)2