本文整理汇总了Java中javax.swing.text.DefaultStyledDocument.ElementSpec方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultStyledDocument.ElementSpec方法的具体用法?Java DefaultStyledDocument.ElementSpec怎么用?Java DefaultStyledDocument.ElementSpec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.DefaultStyledDocument
的用法示例。
在下文中一共展示了DefaultStyledDocument.ElementSpec方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blockOpen
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Instructs the parse buffer to create a block element with the given
* attributes.
*
* @param t the tag that requires opening a new block
* @param attr the attribute set for the new block
*/
protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
{
if (inImpliedParagraph())
blockClose(HTML.Tag.IMPLIED);
// Push the new tag on top of the stack.
parseStack.push(t);
DefaultStyledDocument.ElementSpec element;
AbstractDocument.AttributeContext ctx = getAttributeContext();
AttributeSet copy = attr.copyAttributes();
copy = ctx.addAttribute(copy, StyleConstants.NameAttribute, t);
element = new DefaultStyledDocument.ElementSpec(copy,
DefaultStyledDocument.ElementSpec.StartTagType);
parseBuffer.addElement(element);
}
示例2: addSpecialElement
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Adds content that is specified in the attribute set.
*
* @param t the HTML.Tag
* @param a the attribute set specifying the special content
*/
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
{
if (t != HTML.Tag.FRAME && ! inParagraph())
{
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
}
a.addAttribute(StyleConstants.NameAttribute, t);
// The two spaces are required because some special elements like HR
// must be broken. At least two characters are needed to break into the
// two parts.
DefaultStyledDocument.ElementSpec spec =
new DefaultStyledDocument.ElementSpec(a.copyAttributes(),
DefaultStyledDocument.ElementSpec.ContentType,
new char[] {' '}, 0, 1 );
parseBuffer.add(spec);
}
示例3: blockOpen
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Instructs the parse buffer to create a block element with the given
* attributes.
*
* @param t the tag that requires opening a new block
* @param attr the attribute set for the new block
*/
protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
{
if (inImpliedParagraph())
blockClose(HTML.Tag.IMPLIED);
// Push the new tag on top of the stack.
parseStack.push(t);
DefaultStyledDocument.ElementSpec element;
AbstractDocument.AttributeContext ctx = getAttributeContext();
AttributeSet copy = attr.copyAttributes();
copy = ctx.addAttribute(copy, StyleConstants.NameAttribute, t);
element = new DefaultStyledDocument.ElementSpec(copy,
DefaultStyledDocument.ElementSpec.StartTagType);
parseBuffer.addElement(element);
}
示例4: addSpecialElement
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Adds content that is specified in the attribute set.
*
* @param t the HTML.Tag
* @param a the attribute set specifying the special content
*/
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
{
if (t != HTML.Tag.FRAME && ! inParagraph())
{
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
}
a.addAttribute(StyleConstants.NameAttribute, t);
// The two spaces are required because some special elements like HR
// must be broken. At least two characters are needed to break into the
// two parts.
DefaultStyledDocument.ElementSpec spec =
new DefaultStyledDocument.ElementSpec(a.copyAttributes(),
DefaultStyledDocument.ElementSpec.ContentType,
new char[] {' '}, 0, 1 );
parseBuffer.add(spec);
}
示例5: checkSpecType
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
private void checkSpecType(final String specsDescr, int i, final DefaultStyledDocument.ElementSpec spec) {
final char typeChar = specsDescr.charAt(i*2);
short specType = 0;
if (typeChar == 's') {
specType = ElementSpec.StartTagType;
} else if (typeChar == 'c') {
specType = ElementSpec.ContentType;
} else if (typeChar == 'e') {
specType = ElementSpec.EndTagType;
}
final char dirChar = specsDescr.charAt(i*2 + 1);
short specDir = 0;
if (dirChar == 'n') {
specDir = ElementSpec.JoinNextDirection;
} else if (dirChar == 'p') {
specDir = ElementSpec.JoinPreviousDirection;
} else if (dirChar == 'o') {
specDir = ElementSpec.OriginateDirection;
}
assertEquals("spec direction", specDir, spec.getDirection());
assertEquals("spec type", specType, spec.getType());
}
示例6: blockClose
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Instructs the parse buffer to close the block element associated with
* the given HTML.Tag
*
* @param t the HTML.Tag that is closing its block
*/
protected void blockClose(HTML.Tag t)
{
DefaultStyledDocument.ElementSpec element;
if (inImpliedParagraph() && t != HTML.Tag.IMPLIED)
blockClose(HTML.Tag.IMPLIED);
// Pull the token from the stack.
if (! parseStack.isEmpty()) // Just to be sure.
parseStack.pop();
// If the previous tag is a start tag then we insert a synthetic
// content tag.
DefaultStyledDocument.ElementSpec prev;
prev = parseBuffer.size() > 0 ? (DefaultStyledDocument.ElementSpec)
parseBuffer.get(parseBuffer.size() - 1) : null;
if (prev != null &&
prev.getType() == DefaultStyledDocument.ElementSpec.StartTagType)
{
addContent(new char[]{' '}, 0, 1);
}
element = new DefaultStyledDocument.ElementSpec(null,
DefaultStyledDocument.ElementSpec.EndTagType);
parseBuffer.addElement(element);
}
示例7: blockClose
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Instructs the parse buffer to close the block element associated with
* the given HTML.Tag
*
* @param t the HTML.Tag that is closing its block
*/
protected void blockClose(HTML.Tag t)
{
DefaultStyledDocument.ElementSpec element;
if (inImpliedParagraph() && t != HTML.Tag.IMPLIED)
blockClose(HTML.Tag.IMPLIED);
// Pull the token from the stack.
if (! parseStack.isEmpty()) // Just to be sure.
parseStack.pop();
// If the previous tag is a start tag then we insert a synthetic
// content tag.
DefaultStyledDocument.ElementSpec prev;
prev = parseBuffer.size() > 0 ? (DefaultStyledDocument.ElementSpec)
parseBuffer.get(parseBuffer.size() - 1) : null;
if (prev != null &&
prev.getType() == DefaultStyledDocument.ElementSpec.StartTagType)
{
addContent(new char[]{' '}, 0, 1);
}
element = new DefaultStyledDocument.ElementSpec(null,
DefaultStyledDocument.ElementSpec.EndTagType);
parseBuffer.addElement(element);
}
示例8: addContent
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Adds text to the appropriate context using the current character
* attribute set, and possibly generating an IMPLIED Tag if necessary.
*
* @param data the text to add
* @param offs the offset at which to add it
* @param length the length of the text to add
* @param generateImpliedPIfNecessary whether or not we should generate
* an HTML.Tag.IMPLIED tag if necessary
*/
protected void addContent(char[] data, int offs, int length,
boolean generateImpliedPIfNecessary)
{
if (generateImpliedPIfNecessary && ! inParagraph())
{
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
}
AbstractDocument.AttributeContext ctx = getAttributeContext();
DefaultStyledDocument.ElementSpec element;
AttributeSet attributes = null;
// Copy the attribute set, don't use the same object because
// it may change
if (charAttr != null)
attributes = charAttr.copyAttributes();
else
attributes = ctx.getEmptySet();
attributes = ctx.addAttribute(attributes, StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
element = new DefaultStyledDocument.ElementSpec(attributes,
DefaultStyledDocument.ElementSpec.ContentType,
data, offs, length);
// Add the element to the buffer
parseBuffer.addElement(element);
if (parseBuffer.size() > threshold)
{
if (threshold <= MAX_THRESHOLD)
threshold *= GROW_THRESHOLD;
try
{
flushImpl();
}
catch (BadLocationException ble)
{
// TODO: what to do here?
}
}
}
示例9: addContent
import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
* Adds text to the appropriate context using the current character
* attribute set, and possibly generating an IMPLIED Tag if necessary.
*
* @param data the text to add
* @param offs the offset at which to add it
* @param length the length of the text to add
* @param generateImpliedPIfNecessary whether or not we should generate
* an HTML.Tag.IMPLIED tag if necessary
*/
protected void addContent(char[] data, int offs, int length,
boolean generateImpliedPIfNecessary)
{
if (generateImpliedPIfNecessary && ! inParagraph())
{
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
}
AbstractDocument.AttributeContext ctx = getAttributeContext();
DefaultStyledDocument.ElementSpec element;
AttributeSet attributes = null;
// Copy the attribute set, don't use the same object because
// it may change
if (charAttr != null)
attributes = charAttr.copyAttributes();
else
attributes = ctx.getEmptySet();
attributes = ctx.addAttribute(attributes, StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
element = new DefaultStyledDocument.ElementSpec(attributes,
DefaultStyledDocument.ElementSpec.ContentType,
data, offs, length);
// Add the element to the buffer
parseBuffer.addElement(element);
if (parseBuffer.size() > threshold)
{
if (threshold <= MAX_THRESHOLD)
threshold *= GROW_THRESHOLD;
try
{
flushImpl();
}
catch (BadLocationException ble)
{
// TODO: what to do here?
}
}
}