當前位置: 首頁>>代碼示例>>Java>>正文


Java MutableAttributeSet.addAttributes方法代碼示例

本文整理匯總了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);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:30,代碼來源:JTextPane.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:AttrSetTesting.java

示例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);
	}
}
 
開發者ID:javalovercn,項目名稱:j2se_for_android,代碼行數:26,代碼來源:JTextPane.java

示例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.
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:16,代碼來源:HTMLEditorKit.java


注:本文中的javax.swing.text.MutableAttributeSet.addAttributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。