Java Code Examples for javax.swing.text.StyleConstants#Italic

The following examples show how to use javax.swing.text.StyleConstants#Italic . 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: CSS.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a CSS attribute value to a
 * <code>StyleConstants</code> value.
 * If there is no conversion, returns <code>null</code>.
 * By default, there is no conversion.
 *
 * @param key the <code>StyleConstants</code> attribute
 * @return the <code>StyleConstants</code> attribute value that
 *   represents the CSS attribute value
 */
Object toStyleConstants(StyleConstants key, View v) {
    if (key == StyleConstants.Italic) {
        if (svalue.indexOf("italic") >= 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    } else if (key == StyleConstants.Underline) {
        if (svalue.indexOf("underline") >= 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    } else if (key == StyleConstants.Alignment) {
        if (svalue.equals("right")) {
            return StyleConstants.ALIGN_RIGHT;
        } else if (svalue.equals("center")) {
            return StyleConstants.ALIGN_CENTER;
        } else if  (svalue.equals("justify")) {
            return StyleConstants.ALIGN_JUSTIFIED;
        }
        return StyleConstants.ALIGN_LEFT;
    } else if (key == StyleConstants.StrikeThrough) {
        if (svalue.indexOf("line-through") >= 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    } else if (key == StyleConstants.Superscript) {
        if (svalue.indexOf("super") >= 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    } else if (key == StyleConstants.Subscript) {
        if (svalue.indexOf("sub") >= 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    return null;
}
 
Example 2
Source File: CSS.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a <code>StyleConstants</code> attribute value to
 * a CSS attribute value.  If there is no conversion
 * returns <code>null</code>.
 *
 * @param key the <code>StyleConstants</code> attribute
 * @param value the value of a <code>StyleConstants</code>
 *   attribute to be converted
 * @return the CSS value that represents the
 *   <code>StyleConstants</code> value
 */
Object fromStyleConstants(StyleConstants key, Object value) {
    if (key == StyleConstants.Italic) {
        if (value.equals(Boolean.TRUE)) {
            return parseCssValue("italic");
        }
        return parseCssValue("");
    } else if (key == StyleConstants.Underline) {
        if (value.equals(Boolean.TRUE)) {
            return parseCssValue("underline");
        }
        return parseCssValue("");
    } else if (key == StyleConstants.Alignment) {
        int align = ((Integer)value).intValue();
        String ta;
        switch(align) {
        case StyleConstants.ALIGN_LEFT:
            ta = "left";
            break;
        case StyleConstants.ALIGN_RIGHT:
            ta = "right";
            break;
        case StyleConstants.ALIGN_CENTER:
            ta = "center";
            break;
        case StyleConstants.ALIGN_JUSTIFIED:
            ta = "justify";
            break;
        default:
            ta = "left";
        }
        return parseCssValue(ta);
    } else if (key == StyleConstants.StrikeThrough) {
        if (value.equals(Boolean.TRUE)) {
            return parseCssValue("line-through");
        }
        return parseCssValue("");
    } else if (key == StyleConstants.Superscript) {
        if (value.equals(Boolean.TRUE)) {
            return parseCssValue("super");
        }
        return parseCssValue("");
    } else if (key == StyleConstants.Subscript) {
        if (value.equals(Boolean.TRUE)) {
            return parseCssValue("sub");
        }
        return parseCssValue("");
    }
    return null;
}