本文整理匯總了Java中javax.swing.text.MutableAttributeSet.addAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableAttributeSet.addAttributes方法的具體用法?Java MutableAttributeSet.addAttributes怎麽用?Java MutableAttributeSet.addAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.MutableAttributeSet
的用法示例。
在下文中一共展示了MutableAttributeSet.addAttributes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setCharacterAttributes
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Sets text attributes for the current selection. If there is no selection
* the text attributes are applied to newly inserted text
*
* @param attribute the text attributes to set
* @param replace if <code>true</code>, the attributes of the current
* selection are overridden, otherwise they are merged
*
* @see #getInputAttributes
*/
public void setCharacterAttributes(AttributeSet attribute,
boolean replace)
{
int dot = getCaret().getDot();
int start = getSelectionStart();
int end = getSelectionEnd();
if (start == dot && end == dot)
// There is no selection, update insertAttributes instead
{
MutableAttributeSet inputAttributes =
getStyledEditorKit().getInputAttributes();
if (replace)
inputAttributes.removeAttributes(inputAttributes);
inputAttributes.addAttributes(attribute);
}
else
getStyledDocument().setCharacterAttributes(start, end - start, attribute,
replace);
}
示例2: merge
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
public static void merge(Context context, int... indexes) throws Exception {
@SuppressWarnings("unchecked")
List<Item> list = (List<Item>) context.getInstance(List.class);
StringBuilder sb = context.logOpBuilder();
if (sb != null) {
sb.append("Merge[");
}
MutableAttributeSet mutableAttributeSet = new SimpleAttributeSet();
AttrSet[] attrSets = new AttrSet[indexes.length];
for (int i = indexes.length - 1; i >= 0; i--) {
int index = indexes[i];
if (sb != null) {
if (i > 0) {
sb.append(',');
}
sb.append(index);
}
Item item = list.get(index);
attrSets[i] = item.attrSet;
mutableAttributeSet.addAttributes(item.expected);
}
AttrSet mergedAttrSet = AttrSet.merge(attrSets);
Item mergedItem = new Item(mutableAttributeSet, mergedAttrSet);
list.add(mergedItem);
if (sb != null) {
sb.append("]\n");
context.logOp(sb);
}
}
示例3: setCharacterAttributes
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Applies the given attributes to character content. If there is a
* selection, the attributes are applied to the selection range. If there is
* no selection, the attributes are applied to the input attribute set which
* defines the attributes for any new text that gets inserted.
*
* @param attr
* the attributes
* @param replace
* if true, then replace the existing attributes first
*/
public void setCharacterAttributes(AttributeSet attr, boolean replace) {
int p0 = getSelectionStart();
int p1 = getSelectionEnd();
if (p0 != p1) {
StyledDocument doc = getStyledDocument();
doc.setCharacterAttributes(p0, p1 - p0, attr, replace);
} else {
MutableAttributeSet inputAttributes = getInputAttributes();
if (replace) {
inputAttributes.removeAttributes(inputAttributes);
}
inputAttributes.addAttributes(attr);
}
}
示例4: createInputAttributes
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Copies the key/values in elements AttributeSet into set.
* This does not copy component, icon, or element names attributes.
* This is called anytime the caret moves over a different location.
*
* @param element - the element to create the input attributes for.
* @param set - the set to copy the values into.
*/
protected void createInputAttributes(Element element,
MutableAttributeSet set)
{
set.removeAttributes(set);
set.addAttributes(element.getAttributes());
// FIXME: Not fully implemented.
}