本文整理匯總了Java中javax.swing.text.StyledDocument.addStyle方法的典型用法代碼示例。如果您正苦於以下問題:Java StyledDocument.addStyle方法的具體用法?Java StyledDocument.addStyle怎麽用?Java StyledDocument.addStyle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.StyledDocument
的用法示例。
在下文中一共展示了StyledDocument.addStyle方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertString
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
if(style == null) {
style = authorStyle;
}
sd.insertString(sd.getLength(), author, style);
String iconStyleName = AUTHOR_ICON_STYLE + author;
Style iconStyle = sd.getStyle(iconStyleName);
if(iconStyle == null) {
iconStyle = sd.addStyle(iconStyleName, null);
StyleConstants.setIcon(iconStyle, kenaiUser.getIcon());
}
sd.insertString(sd.getLength(), " ", style);
sd.insertString(sd.getLength(), " ", iconStyle);
}
示例2: logDivider
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
/** Write a horizontal separator into the log window. */
public void logDivider() {
if (log == null)
return;
clearError();
StyledDocument doc = log.getStyledDocument();
Style dividerStyle = doc.addStyle("bar", styleRegular);
JPanel jpanel = new JPanel();
jpanel.setBackground(Color.LIGHT_GRAY);
jpanel.setPreferredSize(new Dimension(300, 1)); // 300 is arbitrary,
// since it will
// auto-stretch
StyleConstants.setComponent(dividerStyle, jpanel);
reallyLog(".", dividerStyle); // Any character would do; "." will be
// replaced by the JPanel
reallyLog("\n\n", styleRegular);
log.setCaretPosition(doc.getLength());
lastSize = doc.getLength();
}
示例3: setFontName
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
/** Set the font name. */
public void setFontName(String fontName) {
if (log == null)
return;
this.fontName = fontName;
log.setFont(new Font(fontName, Font.PLAIN, fontSize));
StyleConstants.setFontFamily(styleRegular, fontName);
StyleConstants.setFontFamily(styleBold, fontName);
StyleConstants.setFontFamily(styleRed, fontName);
StyleConstants.setFontSize(styleRegular, fontSize);
StyleConstants.setFontSize(styleBold, fontSize);
StyleConstants.setFontSize(styleRed, fontSize);
// Changes all existing text
StyledDocument doc = log.getStyledDocument();
Style temp = doc.addStyle("temp", null);
StyleConstants.setFontFamily(temp, fontName);
StyleConstants.setFontSize(temp, fontSize);
doc.setCharacterAttributes(0, doc.getLength(), temp, false);
// Changes all existing hyperlinks
Font newFont = new Font(fontName, Font.BOLD, fontSize);
for (JLabel link : links) {
link.setFont(newFont);
}
}
示例4: setFontName
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
/** Set the font name. */
public void setFontName(String fontName) {
if (log==null) return;
this.fontName = fontName;
log.setFont(new Font(fontName, Font.PLAIN, fontSize));
StyleConstants.setFontFamily(styleRegular, fontName);
StyleConstants.setFontFamily(styleBold, fontName);
StyleConstants.setFontFamily(styleRed, fontName);
StyleConstants.setFontSize(styleRegular, fontSize);
StyleConstants.setFontSize(styleBold, fontSize);
StyleConstants.setFontSize(styleRed, fontSize);
// Changes all existing text
StyledDocument doc=log.getStyledDocument();
Style temp=doc.addStyle("temp", null);
StyleConstants.setFontFamily(temp, fontName);
StyleConstants.setFontSize(temp, fontSize);
doc.setCharacterAttributes(0, doc.getLength(), temp, false);
// Changes all existing hyperlinks
Font newFont = new Font(fontName, Font.BOLD, fontSize);
for(JLabel link: links) { link.setFont(newFont); }
}
示例5: DocumentHandler
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
/**
* Constructor
*
* @param textPane
*/
public DocumentHandler(JTextPane textPane) {
this.textPane = textPane;
setFormatter(new RecordFormatter());
StyledDocument document = (StyledDocument) this.textPane.getDocument();
infoStyle = document.addStyle("INFO", null);
StyleConstants.setFontFamily(infoStyle, "Monospaced");
StyleConstants.setBackground(infoStyle, Color.white);
StyleConstants.setForeground(infoStyle, Color.blue);
severStyle = document.addStyle("SEVER", null);
StyleConstants.setFontFamily(severStyle, "Monospaced");
StyleConstants.setBackground(severStyle, Color.white);
StyleConstants.setForeground(severStyle, Color.red);
}
示例6: underlineStacktraces
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
private static void underlineStacktraces(StyledDocument doc, JTextPane textPane, List<StackTracePosition> stacktraces, String comment) {
Style defStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style hlStyle = doc.addStyle("regularBlue-stacktrace", defStyle); // NOI18N
hlStyle.addAttribute(HyperlinkSupport.STACKTRACE_ATTRIBUTE, new StackTraceAction());
StyleConstants.setForeground(hlStyle, UIUtils.getLinkColor());
StyleConstants.setUnderline(hlStyle, true);
int last = 0;
textPane.setText(""); // NOI18N
for (StackTraceSupport.StackTracePosition stp : stacktraces) {
int start = stp.getStartOffset();
int end = stp.getEndOffset();
if (last < start) {
insertString(doc, comment, last, start, defStyle);
}
last = start;
// for each line skip leading whitespaces (look bad underlined)
boolean inStackTrace = (comment.charAt(start) > ' ');
for (int i = start; i < end; i++) {
char ch = comment.charAt(i);
if ((inStackTrace && ch == '\n') || (!inStackTrace && ch > ' ')) {
insertString(doc, comment, last, i, inStackTrace ? hlStyle : defStyle);
inStackTrace = !inStackTrace;
last = i;
}
}
if (last < end) {
insertString(doc, comment, last, end, inStackTrace ? hlStyle : defStyle);
}
last = end;
}
try {
doc.insertString(doc.getLength(), comment.substring(last), defStyle);
} catch (BadLocationException ex) {
Support.LOG.log(Level.SEVERE, null, ex);
}
}
示例7: showDescription
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
private void showDescription() {
StyledDocument doc = descValue.getStyledDocument();
final Boolean matchCase = matchCaseValue.isSelected();
try {
doc.remove(0, doc.getLength());
ModuleDependency[] deps = getSelectedDependencies();
if (deps.length != 1) {
return;
}
String longDesc = deps[0].getModuleEntry().getLongDescription();
if (longDesc != null) {
doc.insertString(0, longDesc, null);
}
String filterText = filterValue.getText().trim();
if (filterText.length() != 0 && !FILTER_DESCRIPTION.equals(filterText)) {
doc.insertString(doc.getLength(), "\n\n", null); // NOI18N
Style bold = doc.addStyle(null, null);
bold.addAttribute(StyleConstants.Bold, Boolean.TRUE);
doc.insertString(doc.getLength(), getMessage("TEXT_matching_filter_contents"), bold);
doc.insertString(doc.getLength(), "\n", null); // NOI18N
if (filterText.length() > 0) {
String filterTextLC = matchCase?filterText:filterText.toLowerCase(Locale.US);
Style match = doc.addStyle(null, null);
match.addAttribute(StyleConstants.Background, UIManager.get("selection.highlight")!=null?
UIManager.get("selection.highlight"):new Color(246, 248, 139));
boolean isEven = false;
Style even = doc.addStyle(null, null);
even.addAttribute(StyleConstants.Background, UIManager.get("Panel.background"));
if (filterer == null) {
return; // #101776
}
for (String hit : filterer.getMatchesFor(filterText, deps[0])) {
int loc = doc.getLength();
doc.insertString(loc, hit, (isEven ? even : null));
int start = (matchCase?hit:hit.toLowerCase(Locale.US)).indexOf(filterTextLC);
while (start != -1) {
doc.setCharacterAttributes(loc + start, filterTextLC.length(), match, true);
start = hit.toLowerCase(Locale.US).indexOf(filterTextLC, start + 1);
}
doc.insertString(doc.getLength(), "\n", (isEven ? even : null)); // NOI18N
isEven ^= true;
}
} else {
Style italics = doc.addStyle(null, null);
italics.addAttribute(StyleConstants.Italic, Boolean.TRUE);
doc.insertString(doc.getLength(), getMessage("TEXT_no_filter_specified"), italics);
}
}
descValue.setCaretPosition(0);
} catch (BadLocationException e) {
Util.err.notify(ErrorManager.INFORMATIONAL, e);
}
}
示例8: logDivider
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
/** Write a horizontal separator into the log window. */
public void logDivider() {
if (log==null) return;
clearError();
StyledDocument doc = log.getStyledDocument();
Style dividerStyle = doc.addStyle("bar", styleRegular);
JPanel jpanel = new JPanel();
jpanel.setBackground(Color.LIGHT_GRAY);
jpanel.setPreferredSize(new Dimension(300,1)); // 300 is arbitrary, since it will auto-stretch
StyleConstants.setComponent(dividerStyle, jpanel);
reallyLog(".", dividerStyle); // Any character would do; "." will be replaced by the JPanel
reallyLog("\n\n", styleRegular);
log.setCaretPosition(doc.getLength());
lastSize = doc.getLength();
}
示例9: addToConsole
import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
private void addToConsole(LogEntry logentry, boolean update) {
StyledDocument doc = console.textpane.getStyledDocument();
Style style = doc.addStyle("Style", null);
if(update) {
updateLogEntry(logentry);
}
boolean doesLog = true;
switch(logentry.getLevel()) {
case LogEntry.LEVELERROR:
doesLog = showError;
StyleConstants.setBackground(style, Color.WHITE);
StyleConstants.setForeground(style, Color.red);
break;
case LogEntry.LEVELINPUT:
doesLog = showInput;
StyleConstants.setBackground(style, Color.WHITE);
StyleConstants.setForeground(style, Color.BLUE);
break;
case LogEntry.LEVELLOW:
doesLog = showLow;
StyleConstants.setBackground(style, Color.WHITE);
StyleConstants.setForeground(style, Color.GRAY);
break;
case LogEntry.LEVELNORMAL:
doesLog = showNormal;
StyleConstants.setBackground(style, Color.WHITE);
StyleConstants.setForeground(style, Color.BLACK);
break;
case LogEntry.LEVELCOMMAND:
doesLog = showCommand;
StyleConstants.setBackground(style, Color.BLACK);
StyleConstants.setForeground(style, Color.YELLOW);
break;
}
if(doesLog) {
try {
doc.insertString(doc.getLength(), logentry.toString() + "\n", style);
} catch (Exception ex) {
logErr(String.format(lang.getProperty("error_while_adding_to_the_console", "Error while adding to the console: %s"), ex));
}
console.textpane.setCaretPosition(doc.getLength());
}
}