本文整理汇总了Java中javax.swing.text.StyledEditorKit.getInputAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java StyledEditorKit.getInputAttributes方法的具体用法?Java StyledEditorKit.getInputAttributes怎么用?Java StyledEditorKit.getInputAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyledEditorKit
的用法示例。
在下文中一共展示了StyledEditorKit.getInputAttributes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void action()
{
// FIX bold word if no selection! (only if chars on both sides are letters or digits)
// nn|nn -> BB|BB
// nn|. -> nn|.
// <sp>|<sp> -> <sp>|<sp>
// BBB|nnn -> nnn|nnn
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
if(k != null)
{
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isBold(as);
SimpleAttributeSet newAttrs = new SimpleAttributeSet();
StyleConstants.setBold(newAttrs, !on);
setCharacterAttributes(ed, newAttrs, false);
}
}
}
示例2: actionPerformed
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e){
JEditorPane editor = getEditor(e);
if (editor != null) {
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean strike = (StyleConstants.isStrikeThrough(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setStrikeThrough(sas, strike);
setCharacterAttributes(editor, sas, false);
}
}
示例3: highlight
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void highlight(ActionEvent e){
JEditorPane editor = getEditor(e);
if(editor != null){
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
javax.swing.text.DefaultHighlighter.DefaultHighlightPainter highlightPainter =
new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
try {
last = editor.getHighlighter().addHighlight(editor.getSelectionStart(), editor.getSelectionEnd(), highlightPainter);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
示例4: action
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isItalic(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setItalic(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例5: action
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isStrikeThrough(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setStrikeThrough(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例6: action
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isSubscript(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setSubscript(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例7: action
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isUnderline(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setUnderline(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例8: action
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isSuperscript(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setSuperscript(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例9: setCharacterAttributes
import javax.swing.text.StyledEditorKit; //导入方法依赖的package包/类
protected void setCharacterAttributes(JEditorPane ed, AttributeSet as, boolean replace)
{
int start = ed.getSelectionStart();
int end = ed.getSelectionEnd();
// word selection logic a-la MS Word
if(start == end)
{
int ws = getWordStart(ed, start);
if(ws >= 0)
{
int we = getWordEnd(ed, end);
if(we >= 0)
{
start = ws;
end = we;
}
}
}
if(start != end)
{
getStyledDocument(ed).setCharacterAttributes(start, end - start, as, replace);
}
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet a = k.getInputAttributes();
if(replace)
{
a.removeAttributes(a);
}
a.addAttributes(as);
}