public class StyleSheet extends StyleContext
toString
方法。
HTML视图的实现得到他们的属性的主要切入点是getViewAttributes
方法。应实现这一要求,以建立用于将属性与视图关联的所需的策略。每个HTMLEditorKit执行(即因此每个相关的jeditorpane)可以有它自己的样式,但是默认的一张,将所有的HTMLEditorKit执行实例共享。这情况也可以有一个样式表,保存文档特定的CSS规范。
为了减少状态,因此视图存储更轻,样式表可以作为一个画家,处理一些工厂的渲染任务。这允许实现,以确定他们要缓存的是什么,并有可能在一个选择器是常见的多个视图的水平上共享。由于样式表可以由多个文件的看法和一般的HTML属性不影响选择器的使用,共享的潜力巨大。
该规则被存储为命名样式,并且存储其他信息以将元素的上下文快速转换为规则的上下文。下面的代码片段将显示指定的样式,因此CSS规则中。
import java.util.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
public class ShowStyles {
public static void main(String[] args) {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
StyleSheet styles = doc.getStyleSheet();
Enumeration rules = styles.getStyleNames();
while (rules.hasMoreElements()) {
String name = (String) rules.nextElement();
Style rule = styles.getStyle(name);
System.out.println(rule.toString());
}
System.exit(0);
}
}
语义时,CSS样式应该覆盖的视觉属性的元素定义不明确。例如,HTML <body bgcolor=red>
使身体有一个红色的背景。但如果HTML文件也包含CSS规则body { background: blue }
变得较不清楚身体的背景应该是什么颜色的。当前的实现给出了在元素中定义的视觉属性的最高优先级,也就是说它们总是在任何样式之前检查过的。因此,在前面的示例中,背景将有一个红色的,因为身体元素定义了红色的背景颜色。
正如已经提到的这个支持CSS。我们不支持完整的CSS规范引用的CSS类Javadoc看什么性质我们支持。两大CSS解析相关的概念,我们目前不支持伪选择器,如A:link { color: red }
,和important
修饰符。
注:此实现目前是不完整的。它可以替换为完整的替代实现。这一类的未来版本将提供更好的CSS支持。
Modifier and Type | Class and Description |
---|---|
static class |
StyleSheet.BoxPainter
班级开展一些CSS格式化的职责。
|
static class |
StyleSheet.ListPainter
班级开展一些职责的CSS列表格式。
|
StyleContext.NamedStyle, StyleContext.SmallAttributeSet
DEFAULT_STYLE
Constructor and Description |
---|
StyleSheet()
构造样式
|
addChangeListener, addStyle, getChangeListeners, getCompressionThreshold, getDefaultStyleContext, getEmptySet, getFont, getFontMetrics, getStaticAttribute, getStaticAttributeKey, getStyle, getStyleNames, readAttributes, readAttributeSet, reclaim, registerStaticAttributeKey, removeChangeListener, toString, writeAttributes, writeAttributeSet
public Style getRule(HTML.Tag t, Element e)
t
型转化的视觉属性
e
代表标签的元素;元素可以用来确定嵌套的情况下,将不同的属性,如果嵌套在其他元素
public Style getRule(String selector)
selector
是一个空间的元素名称分隔的字符串。例如,
selector
可能是“主体”
返回的样式的属性将更改为规则添加和删除。也就是说,如果你要求一个规则与一个选择器“表P”和一个新的规则添加一个选择器的“P”返回的样式将包括新的属性从规则“P”。
TR TDpublic void addRule(String rule)
public AttributeSet getDeclaration(String decl)
public void loadRules(Reader in, URL ref) throws IOException
in
-流来读取CSS语法
ref
-参考网址。此值表示流的位置,并可能为空。在流中指定的所有相关的网址都将基于此参数。
IOException
public AttributeSet getViewAttributes(View v)
public void removeStyle(String nm)
removeStyle
方法重写,继承类
StyleContext
nm
-风格的名字删除
public void addStyleSheet(StyleSheet ss)
ss
规则的接受者。
ss's
规则将覆盖任何以前添加的样式表规则。一个额外的样式表将不会覆盖接收的样式表规则。
public void removeStyleSheet(StyleSheet ss)
ss
。
public StyleSheet[] getStyleSheets()
public void importStyleSheet(URL url)
url
样式表。将得到的规则直接添加到接收器。如果你不想规则成为接收机部分,创建一个新的样式表,使用addstylesheet挂靠在。
public void setBase(URL base)
base
。
public URL getBase()
public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key, String value)
public boolean addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key, String value)
public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
htmlAttrSet
包含HTML attributeset属性。
public AttributeSet addAttribute(AttributeSet old, Object key, Object value)
addAttribute
接口
AbstractDocument.AttributeContext
addAttribute
方法重写,继承类
StyleContext
old
-旧的属性设置
key
-非空属性的关键
value
-属性值
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
addAttributes
接口
AbstractDocument.AttributeContext
addAttributes
方法重写,继承类
StyleContext
old
-旧的属性设置
attr
-添加属性
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
public AttributeSet removeAttribute(AttributeSet old, Object key)
removeAttribute
接口
AbstractDocument.AttributeContext
removeAttribute
方法重写,继承类
StyleContext
old
-老集的属性
key
-非空属性名称
MutableAttributeSet.removeAttribute(java.lang.Object)
public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)
removeAttributes
接口
AbstractDocument.AttributeContext
removeAttributes
方法重写,继承类
StyleContext
old
-旧的属性设置
names
-属性名称
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
removeAttributes
接口
AbstractDocument.AttributeContext
removeAttributes
方法重写,继承类
StyleContext
old
-旧的属性设置
attrs
-属性
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
createSmallAttributeSet
方法重写,继承类
StyleContext
a
-属性在紧凑的形式表示的集合。
protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
createLargeAttributeSet
方法重写,继承类
StyleContext
a
-属性在较大的形式表示的集合。
public Font getFont(AttributeSet a)
getFont
方法重写,继承类
StyleContext
a
-属性设置
public Color getForeground(AttributeSet a)
getForeground
方法重写,继承类
StyleContext
a
-属性设置
public Color getBackground(AttributeSet a)
getBackground
方法重写,继承类
StyleContext
a
-属性设置
public StyleSheet.BoxPainter getBoxPainter(AttributeSet a)
public StyleSheet.ListPainter getListPainter(AttributeSet a)
public void setBaseFontSize(int sz)
public void setBaseFontSize(String size)
public static int getIndexOfSize(float pt)
public float getPointSize(int index)
public float getPointSize(String size)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.