本文整理汇总了Java中javax.swing.text.html.CSS类的典型用法代码示例。如果您正苦于以下问题:Java CSS类的具体用法?Java CSS怎么用?Java CSS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSS类属于javax.swing.text.html包,在下文中一共展示了CSS类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToHTML40
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Copies the given AttributeSet to a new set, converting
* any CSS attributes found to arguments of an HTML style
* attribute.
*/
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
Enumeration keys = from.getAttributeNames();
String value = "";
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof CSS.Attribute) {
value = value + " " + key + "=" + from.getAttribute(key) + ";";
}
else {
to.addAttribute(key, from.getAttribute(key));
}
}
if (value.length() > 0) {
to.addAttribute(HTML.Attribute.STYLE, value);
}
}
示例2: createFontAttribute
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Create/update an HTML <font> tag attribute. The
* value of the attribute should be a MutableAttributeSet so
* that the attributes can be updated as they are discovered.
*/
private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {
MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);
if (fontAttr == null) {
fontAttr = new SimpleAttributeSet();
to.addAttribute(HTML.Tag.FONT, fontAttr);
}
// edit the parameters to the font tag
String htmlValue = from.getAttribute(a).toString();
if (a == CSS.Attribute.FONT_FAMILY) {
fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
}
else if (a == CSS.Attribute.FONT_SIZE) {
fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
}
else if (a == CSS.Attribute.COLOR) {
fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
}
}
示例3: createFontAttribute
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Create/update an HTML <font> tag attribute. The value of the
* attribute should be a MutableAttributeSet so that the attributes can be
* updated as they are discovered.
*/
private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {
MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);
if (fontAttr == null) {
fontAttr = new SimpleAttributeSet();
to.addAttribute(HTML.Tag.FONT, fontAttr);
}
// edit the parameters to the font tag
String htmlValue = from.getAttribute(a).toString();
if (a == CSS.Attribute.FONT_FAMILY) {
fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
} else if (a == CSS.Attribute.FONT_SIZE) {
fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
} else if (a == CSS.Attribute.COLOR) {
fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
}
}
示例4: convertToHTML40
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Copies the given AttributeSet to a new set, converting any CSS attributes
* found to arguments of an HTML style attribute.
*/
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
Enumeration keys = from.getAttributeNames();
String value = "";
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof CSS.Attribute) {
value = value + " " + key + "=" + from.getAttribute(key) + ";";
} else {
to.addAttribute(key, from.getAttribute(key));
}
}
if (value.length() > 0) {
to.addAttribute(HTML.Attribute.STYLE, value);
}
}
示例5: getFontScaleFactor
import javax.swing.text.html.CSS; //导入依赖的package包/类
private float getFontScaleFactor(AttributeSet a) {
final Object attribute = a.getAttribute(CSS.Attribute.FONT_SIZE);
if(attribute == null)
return ScaledEditorKit.getFontScaleFactor();
final String fontSize = attribute.toString();
final int fsLength = fontSize.length();
if(fsLength <= 1
|| Character.isDigit(fontSize.charAt(fsLength-1))
|| fontSize.endsWith("pt"))
return ScaledEditorKit.getFontScaleFactor();
if(fontSize.endsWith("px"))
return 1/1.3f;
if(fontSize.endsWith("%") || fontSize.endsWith("em") || fontSize.endsWith("ex")
|| fontSize.endsWith("er"))
return getFontScaleFactor(a);
return ScaledEditorKit.getFontScaleFactor();
}
示例6: createFontAttribute
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Create/update an HTML <font> tag attribute. The
* value of the attribute should be a MutableAttributeSet so
* that the attributes can be updated as they are discovered.
*/
private static void createFontAttribute(CSS.Attribute a, AttributeSet from,
MutableAttributeSet to) {
MutableAttributeSet fontAttr = (MutableAttributeSet)
to.getAttribute(HTML.Tag.FONT);
if (fontAttr == null) {
fontAttr = new SimpleAttributeSet();
to.addAttribute(HTML.Tag.FONT, fontAttr);
}
// edit the parameters to the font tag
String htmlValue = from.getAttribute(a).toString();
if (a == CSS.Attribute.FONT_FAMILY) {
fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
} else if (a == CSS.Attribute.FONT_SIZE) {
fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
} else if (a == CSS.Attribute.COLOR) {
fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
}
}
示例7: convertToHTML
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Create an older style of HTML attributes. This will convert character
* level attributes that have a StyleConstants mapping over to an HTML
* tag/attribute. Other CSS attributes will be placed in an HTML style
* attribute.
*/
private static void convertToHTML(AttributeSet from, MutableAttributeSet to) {
if (from == null) {
return;
}
Enumeration keys = from.getAttributeNames();
String value = "";
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof CSS.Attribute) {
// default is to store in a HTML style attribute
if (value.length() > 0) {
value = value + "; ";
}
value = value + key + ": " + from.getAttribute(key);
} else {
to.addAttribute(key, from.getAttribute(key));
}
}
if (value.length() > 0) {
to.addAttribute(HTML.Attribute.STYLE, value);
}
}
示例8: getFontFamily
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Gets the font family name at the {@link JEditorPane}'s current caret position
*
* @param editor
* @return The font family name, or null if no font is set
*/
public static String getFontFamily(JEditorPane editor)
{
AttributeSet attr = getCharacterAttributes(editor);
if(attr != null)
{
Object val = attr.getAttribute(StyleConstants.FontFamily);
if(val != null)
return val.toString();
val = attr.getAttribute(CSS.Attribute.FONT_FAMILY);
if(val != null)
return val.toString();
val = attr.getAttribute(HTML.Tag.FONT);
if(val != null && val instanceof AttributeSet)
{
AttributeSet set = (AttributeSet)val;
val = set.getAttribute(HTML.Attribute.FACE);
if(val != null)
return val.toString();
}
}
return null; //no font family was defined
}
示例9: corrigePImplied
import javax.swing.text.html.CSS; //导入依赖的package包/类
public static void corrigePImplied(ExtendedHTMLDocument doc) {
List<Element> tds = findElementByTag(doc, Tag.TD);
for(Element td: tds) {
if(td.getElementCount() > 0) {
Element p = td.getElement(0);
AttributeSet attrs = p.getAttributes();
if(attrs.containsAttribute(StyleConstants.NameAttribute, Tag.IMPLIED) &&
attrs.isDefined(CSS.Attribute.TEXT_ALIGN)) {
SimpleAttributeSet s = new SimpleAttributeSet();
s.addAttribute(StyleConstants.NameAttribute, Tag.P);
doc.setParagraphAttributes(p.getStartOffset(), p.getEndOffset(),
s, false);
}
}
}
}
示例10: writeStyle
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Outputs the named style. <code>outputStyle</code> indicates
* whether or not a style has been output yet. This will return
* true if a style is written.
*/
boolean writeStyle(String name, Style style, boolean outputStyle) throws IOException {
boolean didOutputStyle = false;
Enumeration attributes = style.getAttributeNames();
if (attributes != null) {
while (attributes.hasMoreElements()) {
Object attribute = attributes.nextElement();
if (attribute instanceof CSS.Attribute) {
String value = style.getAttribute(attribute).toString();
if (value != null) {
if (!outputStyle) {
writeStyleStartTag();
outputStyle = true;
}
if (!didOutputStyle) {
didOutputStyle = true;
indent();
write(name);
write(" {");
}
else {
write(";");
}
write(' ');
write(attribute.toString());
write(": ");
write(value);
}
}
}
}
if (didOutputStyle) {
write(" }");
writeLineSeparator();
}
return didOutputStyle;
}
示例11: writeStyle
import javax.swing.text.html.CSS; //导入依赖的package包/类
/**
* Outputs the named style. <code>outputStyle</code> indicates whether or
* not a style has been output yet. This will return true if a style is
* written.
*/
boolean writeStyle(String name, Style style, boolean outputStyle) throws IOException {
boolean didOutputStyle = false;
Enumeration attributes = style.getAttributeNames();
if (attributes != null) {
while (attributes.hasMoreElements()) {
Object attribute = attributes.nextElement();
if (attribute instanceof CSS.Attribute) {
String value = style.getAttribute(attribute).toString();
if (value != null) {
if (!outputStyle) {
writeStyleStartTag();
outputStyle = true;
}
if (!didOutputStyle) {
didOutputStyle = true;
indent();
write(name);
write(" {");
} else {
write(";");
}
write(' ');
write(attribute.toString());
write(": ");
write(value);
}
}
}
}
if (didOutputStyle) {
write(" }");
writeLineSeparator();
}
return didOutputStyle;
}
示例12: decouperTexteEnLignes_String
import javax.swing.text.html.CSS; //导入依赖的package包/类
private void decouperTexteEnLignes_String(Element element) {
if (!element.isLeaf()) {
Object display = trouverProprieteCSSHeritage(CSS.Attribute.DISPLAY,
element);
if (display != null)
display = display.toString().toLowerCase();
else {
HTML.Tag tag = HTML.getTag(element.getName());
if (tag == null)
display = "";
else if (tag.isBlock())
display = "block";
else
display = "inline";
}
if (display.equals("block")) {
decoupe += "<<" + element.getName() + ">>";
}
int elementCount = element.getElementCount();
for (int i = 0; i < elementCount; i++) {
Element elem = element.getElement(i);
decouperTexteEnLignes_String(elem);
}
if (display.equals("block")) {
decoupe += "<<" + element.getName() + ">>";
}
} else {
int beg = element.getStartOffset();
int end = element.getEndOffset();
String text = null;
try {
text = getText(beg, end - beg);
text = text.replaceAll("\\s+", " ");
decoupe += text;
} catch (BadLocationException e) {
}
}
}
示例13: trouverFontFamily
import javax.swing.text.html.CSS; //导入依赖的package包/类
public String[] trouverFontFamily(Element element) {
AttributeSet as;
String family = null;
as = element.getAttributes();
// Vérifier si l'élément de texte contient directement un
// attribut "font-family". NOTE: Normalement, il ne devrait pas
// le contenir car notre lecteur HTML a été modifié par rapport
// au HTMLDocument.HTMLReader original qui, lui, convertit certains
// éléments HTML affectant le texte en attributs qu'il ajoute à
// l'élément de texte (par exemple, <FONT face=verdana> devient
// un attribut font-family=verdana ajouté au texte qui suit.)
// if (as.isDefined(CSS.Attribute.FONT_FAMILY))
// Essayer l'attribut css font-family
Object familyObject = as.getAttribute(CSS.Attribute.FONT_FAMILY);
if (familyObject == null)
family = null;
else
family = familyObject.toString();
// Sinon, essay l'attribut css font
// if (family == null) {
// String font = (String)as.getAttribute(CSS.Attribute.FONT);
// family = parseFontForFamily(font);
// }
if (family == null) {
Element parent = element.getParentElement();
// fontFamily =
// transInuk.trouverFontFamilyHerit(parent,doc);
if (parent != null) {
String[] families = trouverFontFamilyHerit(parent);
return families;
} else
return null;
} else {
return (String[]) new String[] { family };
}
}
示例14: caretUpdate
import javax.swing.text.html.CSS; //导入依赖的package包/类
@Override
public void caretUpdate(CaretEvent e) {
int referentCharacter = e.getDot();
try {
if(referentCharacter>0 && !editeur.getText(referentCharacter-1, 1).equals("\n")) {referentCharacter--;}
} catch (BadLocationException ex) {
Logger.getLogger(JMathTextPane.class.getName()).log(Level.SEVERE, null, ex);
}
AttributeSet ast = editeur.getHTMLdoc().getCharacterElement(referentCharacter).getAttributes();
Object textDecorationValue = ast.getAttribute(CSS.Attribute.TEXT_DECORATION);
editeur.getEditeurKit().getBoutonStrike().setSelected(textDecorationValue!=null && textDecorationValue.toString().equals("line-through"));
}