本文整理匯總了Java中javax.swing.text.MutableAttributeSet.removeAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableAttributeSet.removeAttributes方法的具體用法?Java MutableAttributeSet.removeAttributes怎麽用?Java MutableAttributeSet.removeAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.MutableAttributeSet
的用法示例。
在下文中一共展示了MutableAttributeSet.removeAttributes方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: convertToHTML
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Convert the give set of attributes to be html for
* the purpose of writing them out. Any keys that
* have been converted will not appear in the resultant
* set. Any keys not converted will appear in the
* resultant set the same as the received set.<p>
* This will put the converted values into <code>to</code>, unless
* it is null in which case a temporary AttributeSet will be returned.
*/
AttributeSet convertToHTML(AttributeSet from, MutableAttributeSet to) {
if (to == null) {
to = convAttr;
}
to.removeAttributes(to);
if (writeCSS) {
convertToHTML40(from, to);
}
else {
convertToHTML32(from, to);
}
return to;
}
示例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: convertToHTML
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Convert the give set of attributes to be html for the purpose of writing
* them out. Any keys that have been converted will not appear in the
* resultant set. Any keys not converted will appear in the resultant set
* the same as the received set.
* <p>
* This will put the converted values into <code>to</code>, unless it is
* null in which case a temporary AttributeSet will be returned.
*/
AttributeSet convertToHTML(AttributeSet from, MutableAttributeSet to) {
if (to == null) {
to = convAttr;
}
to.removeAttributes(to);
if (writeCSS) {
convertToHTML40(from, to);
} else {
convertToHTML32(from, to);
}
return to;
}
示例5: insertIcon
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Inserts an <code>Icon</code> into the text at the current caret position.
*
* @param icon the <code>Icon</code> to be inserted
*/
public void insertIcon(Icon icon)
{
MutableAttributeSet inputAtts = getInputAttributes();
inputAtts.removeAttributes(inputAtts);
StyleConstants.setIcon(inputAtts, icon);
replaceSelection(" ");
inputAtts.removeAttributes(inputAtts);
}
示例6: insertComponent
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Inserts a component into the document as a replacement for the currently
* selected content. If there is no selection the component is effectively
* inserted at the current position of the caret. This is represented in the
* associated document as an attribute of one character of content.
* <p>
* The component given is the actual component used by the JTextPane. Since
* components cannot be a child of more than one container, this method
* should not be used in situations where the model is shared by text
* components.
* <p>
* The component is placed relative to the text baseline according to the
* value returned by <code>Component.getAlignmentY</code>. For Swing
* components this value can be conveniently set using the method
* <code>JComponent.setAlignmentY</code>. For example, setting a value of
* <code>0.75</code> will cause 75 percent of the component to be above the
* baseline, and 25 percent of the component to be below the baseline.
*
* @param c
* the component to insert
*/
public void insertComponent(Component c) {
MutableAttributeSet inputAttributes = getInputAttributes();
inputAttributes.removeAttributes(inputAttributes);
StyleConstants.setComponent(inputAttributes, c);
replaceSelection(" ", false);
inputAttributes.removeAttributes(inputAttributes);
}
示例7: insertIcon
import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
* Inserts an icon into the document as a replacement for the currently
* selected content. If there is no selection the icon is effectively
* inserted at the current position of the caret. This is represented in the
* associated document as an attribute of one character of content.
*
* @param g
* the icon to insert
* @see Icon
*/
public void insertIcon(Icon g) {
MutableAttributeSet inputAttributes = getInputAttributes();
inputAttributes.removeAttributes(inputAttributes);
StyleConstants.setIcon(inputAttributes, g);
replaceSelection(" ", false);
inputAttributes.removeAttributes(inputAttributes);
}
示例8: 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.
}