本文整理匯總了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?
}
}
}