当前位置: 首页>>代码示例>>Java>>正文


Java Style类代码示例

本文整理汇总了Java中javax.swing.text.Style的典型用法代码示例。如果您正苦于以下问题:Java Style类的具体用法?Java Style怎么用?Java Style使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Style类属于javax.swing.text包,在下文中一共展示了Style类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCodeArea

import javax.swing.text.Style; //导入依赖的package包/类
private JTextPane getCodeArea(){
    final StyleContext sc = new StyleContext();
    final DefaultStyledDocument doc = new DefaultStyledDocument(sc);

    final JTextPane codeArea = new JTextPane(doc);
    codeArea.setBackground(new Color(0x25401C));
    codeArea.setCaretColor(new Color(0xD1E8CE));

    final Style bodyStyle = sc.addStyle("body", null);
    bodyStyle.addAttribute(StyleConstants.Foreground, new Color(0x789C6C));
    bodyStyle.addAttribute(StyleConstants.FontSize, 13);
    bodyStyle.addAttribute(StyleConstants.FontFamily, "monospaced");
    bodyStyle.addAttribute(StyleConstants.Bold, true);

    doc.setLogicalStyle(0, bodyStyle);

    return codeArea;
}
 
开发者ID:rossdrew,项目名称:emuRox,代码行数:19,代码来源:DebuggerWindow.java

示例2: addStylesToDocument

import javax.swing.text.Style; //导入依赖的package包/类
/**
 * Add styles to the document.
 * 
 * @param doc the StyledDocument to add styles to
 */
protected void addStylesToDocument(final StyledDocument doc)
{
  //Initialize some styles.
  Style def = StyleContext.getDefaultStyleContext().
                  getStyle(StyleContext.DEFAULT_STYLE);

  Style regular = doc.addStyle("regular", def);
  StyleConstants.setFontFamily(def, "SansSerif");
  StyleConstants.setFontSize(def, 12);
  StyleConstants.setLineSpacing(def, 2.0f);

  Style s = doc.addStyle("italic", regular);
  StyleConstants.setItalic(s, true);

  s = doc.addStyle("bold", regular);
  StyleConstants.setBold(s, true);

  s = doc.addStyle("small", regular);
  StyleConstants.setFontSize(s, 10);

  s = doc.addStyle("large", regular);
  StyleConstants.setFontSize(s, 14);
}
 
开发者ID:argonium,项目名称:jarman,代码行数:29,代码来源:ExploreFileDlg.java

示例3: create

import javax.swing.text.Style; //导入依赖的package包/类
public static IssueLinker create(VCSHyperlinkProvider hp, Style issueHyperlinkStyle, File root, StyledDocument sd, String text) {
    int[] spans = hp.getSpans(text);
    if (spans == null) {
        return null;
    }
    if(spans.length % 2 != 0) {
        // XXX more info and log only _ONCE_
        LOG.warning("Hyperlink provider " + hp.getClass().getName() + " returns wrong spans");
        return null;
    }
    if(spans.length > 0) {
        IssueLinker l = new IssueLinker(hp, issueHyperlinkStyle, root, sd, text, spans);
        return l;
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:VCSHyperlinkSupport.java

示例4: insertString

import javax.swing.text.Style; //导入依赖的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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:VCSHyperlinkSupport.java

示例5: addDate

import javax.swing.text.Style; //导入依赖的package包/类
private void addDate (JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {

            LogEntry entry = item.getUserData();
            StyledDocument sd = pane.getStyledDocument();
            // clear document
            clearSD(pane, sd);

            Style selectedStyle = createSelectedStyle(pane);
            Style normalStyle = createNormalStyle(pane);
            Style style;
            if (selected) {
                style = selectedStyle;
            } else {
                style = normalStyle;
            }

            // add date
            sd.insertString(sd.getLength(), entry.getDate(), style);
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SummaryCellRenderer.java

示例6: clearSD

import javax.swing.text.Style; //导入依赖的package包/类
private void clearSD (JTextPane pane, StyledDocument sd) {
    try {
        Style noindentStyle = createNoindentStyle(pane);
        sd.remove(0, sd.getLength());
        sd.setParagraphAttributes(0, sd.getLength(), noindentStyle, false);
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:SummaryCellRenderer.java

示例7: logDivider

import javax.swing.text.Style; //导入依赖的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();
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:20,代码来源:SwingLogPanel.java

示例8: reallyLog

import javax.swing.text.Style; //导入依赖的package包/类
private void reallyLog(String text, Style style) {
	if (log == null || text.length() == 0)
		return;
	int i = text.lastIndexOf('\n'), j = text.lastIndexOf('\r');
	if (i >= 0 && i < j) {
		i = j;
	}
	StyledDocument doc = log.getStyledDocument();
	try {
		if (i < 0) {
			doc.insertString(doc.getLength(), text, style);
		} else {
			// Performs intelligent caret positioning
			doc.insertString(doc.getLength(), text.substring(0, i + 1), style);
			log.setCaretPosition(doc.getLength());
			if (i < text.length() - 1) {
				doc.insertString(doc.getLength(), text.substring(i + 1), style);
			}
		}
	} catch (BadLocationException e) {
		// Harmless
	}
	if (style != styleRed) {
		lastSize = doc.getLength();
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:27,代码来源:SwingLogPanel.java

示例9: setFontName

import javax.swing.text.Style; //导入依赖的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);
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:25,代码来源:SwingLogPanel.java

示例10: handleBadLocationException

import javax.swing.text.Style; //导入依赖的package包/类
/**
 * Try and recover from a BadLocationException thrown when inserting a string
 * into the log area. This method must only be called on the AWT event
 * handling thread.
 */
private void handleBadLocationException(BadLocationException e,
    String textToInsert, Style style) {
  originalErr.println("BadLocationException encountered when writing to "
      + "the log area: " + e);
  originalErr.println("trying to recover...");

  Document newDocument = new DefaultStyledDocument();
  try {
    StringBuilder sb = new StringBuilder();
    sb.append("An error occurred when trying to write a message to the log area.  The log\n");
    sb.append("has been cleared to try and recover from this problem.\n\n");
    sb.append(textToInsert);

    newDocument.insertString(0, sb.toString(), style);
  } catch(BadLocationException e2) {
    // oh dear, all bets are off now...
    e2.printStackTrace(originalErr);
    return;
  }
  // replace the log area's document with the new one
  setDocument(newDocument);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:28,代码来源:LogArea.java

示例11: reallyLog

import javax.swing.text.Style; //导入依赖的package包/类
private void reallyLog(String text, Style style) {
    if (log==null || text.length()==0) return;
    int i=text.lastIndexOf('\n'), j=text.lastIndexOf('\r');
    if (i>=0 && i<j) { i=j; }
    StyledDocument doc=log.getStyledDocument();
    try {
        if (i<0) {
            doc.insertString(doc.getLength(), text, style);
        } else {
            // Performs intelligent caret positioning
            doc.insertString(doc.getLength(), text.substring(0,i+1), style);
            log.setCaretPosition(doc.getLength());
            if (i<text.length()-1) {
                doc.insertString(doc.getLength(), text.substring(i+1), style);
            }
        }
    } catch (BadLocationException e) {
        // Harmless
    }
    if (style!=styleRed) { lastSize=doc.getLength(); }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:SwingLogPanel.java

示例12: setFontName

import javax.swing.text.Style; //导入依赖的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); }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:SwingLogPanel.java

示例13: addParagraph

import javax.swing.text.Style; //导入依赖的package包/类
static void addParagraph(Paragraph p) {
    try {
        Style s = null;
        for (int i = 0; i < p.data.length; i++) {
            AttributedContent run = p.data[i];
            s = contentAttributes.get(run.attr);
            doc.insertString(doc.getLength(), run.content, s);
        }

        Style ls = styles.getStyle(p.logical);
        doc.setLogicalStyle(doc.getLength() - 1, ls);
        doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JViewPortBackingStoreImageTest.java

示例14: appendToConsole

import javax.swing.text.Style; //导入依赖的package包/类
private void appendToConsole(String message, Style style)
{
    StyledDocument paneDocument = txtServerConsole.getStyledDocument();
    Integer documentLength = paneDocument.getLength();

    try
    {
        paneDocument.insertString(documentLength, message, style);
    }
    catch (BadLocationException ex)
    {
        // The system will attempt to update the log
        // if it fails to update the log, I sense an
        // infinite loop somewhere...
        System.out.println("[SERVER-WARNING] Failed to update log.\r\n\tError: " + ex.getMessage());
    }
}
 
开发者ID:ldawkes,项目名称:LiveBeans,代码行数:18,代码来源:ServerGUI.java

示例15: makeStyles

import javax.swing.text.Style; //导入依赖的package包/类
private void makeStyles(StyledDocument doc) {
    Style s1 = doc.addStyle("regular", regStyle);
    StyleConstants.setFontFamily(s1, "SansSerif");
    Style s2 = doc.addStyle("bold", s1);       
    StyleConstants.setBold(s2, true);
    Style icon = doc.addStyle("input", s1);
    StyleConstants.setAlignment(icon, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(icon, 8);
    StyleConstants.setIcon(icon, Icons.in);
    Style icon2 = doc.addStyle("output", s1);
    StyleConstants.setAlignment(icon2, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(icon2, 8);
    StyleConstants.setIcon(icon2, Icons.out);


}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:17,代码来源:DocFormatter.java


注:本文中的javax.swing.text.Style类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。