本文整理汇总了Java中javax.swing.text.StyleContext.getDefaultStyleContext方法的典型用法代码示例。如果您正苦于以下问题:Java StyleContext.getDefaultStyleContext方法的具体用法?Java StyleContext.getDefaultStyleContext怎么用?Java StyleContext.getDefaultStyleContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleContext
的用法示例。
在下文中一共展示了StyleContext.getDefaultStyleContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSearchPanel
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private Component createSearchPanel() {
StyleContext styleContent = StyleContext.getDefaultStyleContext();
AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);
AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);
searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
searchPanel.hide();
return searchPanel.getComponent();
}
示例2: appendToPane
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void appendToPane(JTextPane tp, String msg, MessageType t)
{
boolean scrollToBottom = scrollPane.getVerticalScrollBar().getValue() == scrollPane.getVerticalScrollBar().getMaximum();
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = SimpleAttributeSet.EMPTY;
MessageStyle ms = theme.getStyle(t);
aset = sc.addAttribute(aset, StyleConstants.Foreground, ms.getForeground() == null ? tp.getForeground() : ms.getForeground());
aset = sc.addAttribute(aset, StyleConstants.Background, ms.getBackground() == null ? tp.getBackground() : ms.getBackground());
aset = sc.addAttribute(aset, StyleConstants.Bold, ms.isBold());
aset = sc.addAttribute(aset, StyleConstants.Italic, ms.isItalic());
aset = sc.addAttribute(aset, StyleConstants.Underline, ms.isUnderlined());
StyledDocument sd = tp.getStyledDocument();
try
{
sd.insertString(sd.getLength(), msg, aset);
}
catch(BadLocationException e)
{
e.printStackTrace();
}
if(scrollToBottom)
{
scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum());
}
}
示例3: appendToPane
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Appends stylized text to a textpane
*
* @param tp
* Textpane
* @param msg
* Message to append. Will automatically place newline at end.
* @param c
* Color of text.
*/
public static void appendToPane(JTextPane tp, String msg, Color c) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
int len = tp.getDocument().getLength(); // same value as
// getText().length();
tp.setCaretPosition(len); // place caret at the end (with no selection)
StyledDocument doc = tp.getStyledDocument();
try {
doc.insertString(doc.getLength(), msg + "\n", aset);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例4: print
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
protected void print(Color c, float size, String text, boolean bold) {
StyleContext sc = StyleContext.getDefaultStyleContext();
MutableAttributeSet aset = ioText.getInputAttributes();
Font f = ioText.getFont();
StyleConstants.setForeground(aset, c);
//StyleConstants.setFontSize(aset, (int)(f.getSize()*size));
StyleConstants.setBold(aset, bold);
try {
doc.insertString(doc.getLength(), text, null);
ioText.getStyledDocument().setCharacterAttributes(doc.getLength() - text.length(), text.length(), aset, true);
} catch (BadLocationException ex) {
Logger.getLogger(NARControls.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例5: print
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
protected void print(Color c, float size, String text, boolean bold) {
StyleContext sc = StyleContext.getDefaultStyleContext();
MutableAttributeSet aset = ioText.getInputAttributes();
Font f = ioText.getFont();
StyleConstants.setForeground(aset, c);
StyleConstants.setFontSize(aset, (int)(f.getSize()*size));
StyleConstants.setBold(aset, bold);
try {
doc.insertString(doc.getLength(), text, null);
ioText.getStyledDocument().setCharacterAttributes(doc.getLength() - text.length(), text.length(), aset, true);
} catch (BadLocationException ex) {
Logger.getLogger(NARWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例6: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
@Override
public void append(String str, Color c) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Sans");
aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
/*
* int len = area.getDocument().getLength(); area.setCaretPosition(len);
* area.setCharacterAttributes(aset, false); area.replaceSelection(str);
*/
DefaultStyledDocument document = (DefaultStyledDocument) area.getDocument();
try {
if (area.getText().length() < 3)
area.setText("");
// document.insertString(0, str, aset);
// else
document.insertString(document.getEndPosition().getOffset() - 1, str, aset);
} catch (BadLocationException e) {}
}
示例7: setupTabStops
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void setupTabStops() {
// Ugly piece of code; needed because default tab indentation is too
// big.
StyleContext sc = StyleContext.getDefaultStyleContext();
Toolkit t = Toolkit.getDefaultToolkit();
FontMetrics fm = t.getFontMetrics(new Font("Courier", Font.PLAIN, 14));
int cw = fm.stringWidth(" ");
final TabStop[] tabStops = new TabStop[60];
for (int i = 0; i < tabStops.length; i++)
tabStops[i] = new TabStop((i + 1) * cw);
TabSet tabs = new TabSet(tabStops);
AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY,
StyleConstants.TabSet, tabs);
pane.setParagraphAttributes(paraSet, false);
}
示例8: appendToLog
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Appends a message to the logging area.
*
* @param message
* Message to add
* @param color
* Color of the message
*/
private void appendToLog(final String message, final Color color) {
final StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, DEFAULT_FONT);
aset = sc.addAttribute(aset, StyleConstants.Alignment, Integer.valueOf(StyleConstants.ALIGN_JUSTIFIED));
final int len = this.mLogArea.getDocument().getLength();
this.mLogArea.setCaretPosition(len);
this.mLogArea.setCharacterAttributes(aset, false);
this.mLogArea.setEditable(true);
this.mLogArea.replaceSelection(message);
this.mLogArea.setEditable(false);
}
示例9: getDefaultFont
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Returns the default font for text areas.
*
* @return The default font.
*/
public static final Font getDefaultFont() {
// Use StyleContext to get a composite font for better Asian language
// support; see Sun bug S282887.
StyleContext sc = StyleContext.getDefaultStyleContext();
Font font = null;
if (isOSX()) {
// Snow Leopard (1.6) uses Menlo as default monospaced font,
// pre-Snow Leopard used Monaco.
font = sc.getFont("Menlo", Font.PLAIN, 12);
if (!"Menlo".equals(font.getFamily())) {
font = sc.getFont("Monaco", Font.PLAIN, 12);
if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen
font = sc.getFont("Monospaced", Font.PLAIN, 13);
}
}
}
else {
// Consolas added in Vista, used by VS2010+.
font = sc.getFont("Consolas", Font.PLAIN, 13);
if (!"Consolas".equals(font.getFamily())) {
font = sc.getFont("Monospaced", Font.PLAIN, 13);
}
}
//System.out.println(font.getFamily() + ", " + font.getName());
return font;
}
示例10: changeBaseFont
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Changes the "base font" for this syntax scheme. This is called by
* <code>RSyntaxTextArea</code> when its font changes via
* <code>setFont()</code>. This looks for tokens that use a derivative of
* the text area's old font (but bolded and/or italicized) and make them
* use the new font with those stylings instead. This is desirable because
* most programmers prefer a single font to be used in their text editor,
* but might want bold (say for keywords) or italics.
*
* @param old The old font of the text area.
* @param font The new font of the text area.
*/
void changeBaseFont(Font old, Font font) {
for (int i=0; i<styles.length; i++) {
Style style = styles[i];
if (style!=null && style.font!=null) {
if (style.font.getFamily().equals(old.getFamily()) &&
style.font.getSize()==old.getSize()) {
int s = style.font.getStyle(); // Keep bold or italic
StyleContext sc = StyleContext.getDefaultStyleContext();
style.font= sc.getFont(font.getFamily(), s, font.getSize());
}
}
}
}
示例11: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color c, String s) {
if (c == null)
c = defaultColor;
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
try {
getDocument().insertString(getDocument().getLength(), s, as);
} catch (BadLocationException e) {
}
}
示例12: addStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static void addStyle(JTextPane pane, String name, Color foreground,
Color background)
{
StyledDocument doc = pane.getStyledDocument();
StyleContext context = StyleContext.getDefaultStyleContext();
Style defaultStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
Style style = doc.addStyle(name, defaultStyle);
StyleConstants.setForeground(style, foreground);
StyleConstants.setBackground(style, background);
}
示例13: setStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static void setStyle(JTextPane textPane, int start, int length,
String name)
{
StyledDocument doc = textPane.getStyledDocument();
Style style;
if (name == null)
{
StyleContext context = StyleContext.getDefaultStyleContext();
style = context.getStyle(StyleContext.DEFAULT_STYLE);
}
else
style = doc.getStyle(name);
doc.setCharacterAttributes(start, length, style, true);
}
示例14: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color c, String s) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
int len = getDocument().getLength();
setCaretPosition(len);
setCharacterAttributes(aset, false);
replaceSelection(s);
}
示例15: getInitialFontHeight
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Get the height of the font at the beginning of the document.
*
* @return height of font at the start of the document.
*/
public double getInitialFontHeight() {
// Small assumption here that there is one root element - can fix
// for more general support later
final Element rootElement = document.getDefaultRootElement();
final Element curElement = drillDownFromRoot(0, rootElement);
final StyleContext context = StyleContext.getDefaultStyleContext();
final Font font = context.getFont(curElement.getAttributes());
final FontMetrics curFM = context.getFontMetrics(font);
return curFM.getMaxAscent() + curFM.getMaxDescent() + curFM.getLeading();
}