當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。