/* * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.text.html; import java.awt.Color; import java.awt.Font; import java.awt.HeadlessException; import java.awt.Image; import java.awt.Toolkit; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import javax.swing.ImageIcon; import javax.swing.SizeRequirements; import javax.swing.text.AttributeSet; import javax.swing.text.Element; import javax.swing.text.MutableAttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.View; /** * Defines a set of * CSS attributes * as a typesafe enumeration. The HTML View implementations use * CSS attributes to determine how they will render. This also defines * methods to map between CSS/HTML/StyleConstants. Any shorthand * properties, such as font, are mapped to the intrinsic properties. *

The following describes the CSS properties that are supported by the * rendering engine: *

* The following are modeled, but currently not rendered. * *

Note: for the time being we do not fully support relative units, * unless noted, so that * p { margin-top: 10% } will be treated as if no margin-top was specified. * * @author Timothy Prinzing * @author Scott Violet * @see StyleSheet */ @SuppressWarnings("serial") // Same-version serialization only public class CSS implements Serializable { /** * Definitions to be used as a key on AttributeSet's * that might hold CSS attributes. Since this is a * closed set (i.e. defined exactly by the specification), * it is final and cannot be extended. */ public static final class Attribute { private Attribute(String name, String defaultValue, boolean inherited) { this.name = name; this.defaultValue = defaultValue; this.inherited = inherited; } /** * The string representation of the attribute. This * should exactly match the string specified in the * CSS specification. */ public String toString() { return name; } /** * Fetch the default value for the attribute. * If there is no default value (such as for * composite attributes), null will be returned. * * @return default value for the attribute */ public String getDefaultValue() { return defaultValue; } /** * Indicates if the attribute should be inherited * from the parent or not. * * @return true if the attribute should be inherited from the parent */ public boolean isInherited() { return inherited; } private String name; private String defaultValue; private boolean inherited; /** * CSS attribute "background". */ public static final Attribute BACKGROUND = new Attribute("background", null, false); /** * CSS attribute "background-attachment". */ public static final Attribute BACKGROUND_ATTACHMENT = new Attribute("background-attachment", "scroll", false); /** * CSS attribute "background-color". */ public static final Attribute BACKGROUND_COLOR = new Attribute("background-color", "transparent", false); /** * CSS attribute "background-image". */ public static final Attribute BACKGROUND_IMAGE = new Attribute("background-image", "none", false); /** * CSS attribute "background-position". */ public static final Attribute BACKGROUND_POSITION = new Attribute("background-position", null, false); /** * CSS attribute "background-repeat". */ public static final Attribute BACKGROUND_REPEAT = new Attribute("background-repeat", "repeat", false); /** * CSS attribute "border". */ public static final Attribute BORDER = new Attribute("border", null, false); /** * CSS attribute "border-bottom". */ public static final Attribute BORDER_BOTTOM = new Attribute("border-bottom", null, false); /** * CSS attribute "border-bottom-color". */ public static final Attribute BORDER_BOTTOM_COLOR = new Attribute("border-bottom-color", null, false); /** * CSS attribute "border-bottom-style". */ public static final Attribute BORDER_BOTTOM_STYLE = new Attribute("border-bottom-style", "none", false); /** * CSS attribute "border-bottom-width". */ public static final Attribute BORDER_BOTTOM_WIDTH = new Attribute("border-bottom-width", "medium", false); /** * CSS attribute "border-color". */ public static final Attribute BORDER_COLOR = new Attribute("border-color", null, false); /** * CSS attribute "border-left". */ public static final Attribute BORDER_LEFT = new Attribute("border-left", null, false); /** * CSS attribute "margin-right". */ public static final Attribute BORDER_LEFT_COLOR = new Attribute("border-left-color", null, false); /** * CSS attribute "border-left-style". */ public static final Attribute BORDER_LEFT_STYLE = new Attribute("border-left-style", "none", false); /** * CSS attribute "border-left-width". */ public static final Attribute BORDER_LEFT_WIDTH = new Attribute("border-left-width", "medium", false); /** * CSS attribute "border-right". */ public static final Attribute BORDER_RIGHT = new Attribute("border-right", null, false); /** * CSS attribute "border-right-color". */ public static final Attribute BORDER_RIGHT_COLOR = new Attribute("border-right-color", null, false); /** * CSS attribute "border-right-style". */ public static final Attribute BORDER_RIGHT_STYLE = new Attribute("border-right-style", "none", false); /** * CSS attribute "border-right-width". */ public static final Attribute BORDER_RIGHT_WIDTH = new Attribute("border-right-width", "medium", false); /** * CSS attribute "border-style". */ public static final Attribute BORDER_STYLE = new Attribute("border-style", "none", false); /** * CSS attribute "border-top". */ public static final Attribute BORDER_TOP = new Attribute("border-top", null, false); /** * CSS attribute "border-top-color". */ public static final Attribute BORDER_TOP_COLOR = new Attribute("border-top-color", null, false); /** * CSS attribute "border-top-style". */ public static final Attribute BORDER_TOP_STYLE = new Attribute("border-top-style", "none", false); /** * CSS attribute "border-top-width". */ public static final Attribute BORDER_TOP_WIDTH = new Attribute("border-top-width", "medium", false); /** * CSS attribute "border-width". */ public static final Attribute BORDER_WIDTH = new Attribute("border-width", "medium", false); /** * CSS attribute "clear". */ public static final Attribute CLEAR = new Attribute("clear", "none", false); /** * CSS attribute "color". */ public static final Attribute COLOR = new Attribute("color", "black", true); /** * CSS attribute "display". */ public static final Attribute DISPLAY = new Attribute("display", "block", false); /** * CSS attribute "float". */ public static final Attribute FLOAT = new Attribute("float", "none", false); /** * CSS attribute "font". */ public static final Attribute FONT = new Attribute("font", null, true); /** * CSS attribute "font-family". */ public static final Attribute FONT_FAMILY = new Attribute("font-family", null, true); /** * CSS attribute "font-size". */ public static final Attribute FONT_SIZE = new Attribute("font-size", "medium", true); /** * CSS attribute "font-style". */ public static final Attribute FONT_STYLE = new Attribute("font-style", "normal", true); /** * CSS attribute "font-variant". */ public static final Attribute FONT_VARIANT = new Attribute("font-variant", "normal", true); /** * CSS attribute "font-weight". */ public static final Attribute FONT_WEIGHT = new Attribute("font-weight", "normal", true); /** * CSS attribute "height". */ public static final Attribute HEIGHT = new Attribute("height", "auto", false); /** * CSS attribute "letter-spacing". */ public static final Attribute LETTER_SPACING = new Attribute("letter-spacing", "normal", true); /** * CSS attribute "line-height". */ public static final Attribute LINE_HEIGHT = new Attribute("line-height", "normal", true); /** * CSS attribute "list-style". */ public static final Attribute LIST_STYLE = new Attribute("list-style", null, true); /** * CSS attribute "list-style-image". */ public static final Attribute LIST_STYLE_IMAGE = new Attribute("list-style-image", "none", true); /** * CSS attribute "list-style-position". */ public static final Attribute LIST_STYLE_POSITION = new Attribute("list-style-position", "outside", true); /** * CSS attribute "list-style-type". */ public static final Attribute LIST_STYLE_TYPE = new Attribute("list-style-type", "disc", true); /** * CSS attribute "margin". */ public static final Attribute MARGIN = new Attribute("margin", null, false); /** * CSS attribute "margin-bottom". */ public static final Attribute MARGIN_BOTTOM = new Attribute("margin-bottom", "0", false); /** * CSS attribute "margin-left". */ public static final Attribute MARGIN_LEFT = new Attribute("margin-left", "0", false); /** * CSS attribute "margin-right". */ public static final Attribute MARGIN_RIGHT = new Attribute("margin-right", "0", false); /* * made up css attributes to describe orientation depended * margins. used for

, ,