javax.swing.text.StyleConstants Java Examples

The following examples show how to use javax.swing.text.StyleConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayArea.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
@Override
public void displaySharkey() {
    displayDataState = DisplayDataState.SHARKEY;
    clearText();
    style = jTextPane.addStyle("STYLE", null);
    Document doc = jTextPane.getStyledDocument();

    try {
        StyleConstants.setForeground(style, theme.getIdentifiersColor());
        StyleConstants.setFontSize(style, 15);
        StyleConstants.setFontFamily(style, "Monospaced");

        doc.insertString(doc.getLength(), Doodle.get(), style);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }

    jTextPane.setDocument(doc);
}
 
Example #2
Source File: ViewFactoryImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new LabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return null;
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new DocumentView(elem);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }
    }
    return null;
}
 
Example #3
Source File: ColorsManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Map getCurrentColors(Language l) {
    // current colors
    FontColorSettingsFactory fcsf = EditorSettings.getDefault().
            getFontColorSettings(new String[] {l.getMimeType()});
    Collection<AttributeSet> colors = fcsf.getAllFontColors("NetBeans");
    Map<String,AttributeSet> colorsMap = new HashMap<String,AttributeSet> ();
    Iterator<AttributeSet> it = colors.iterator();
    while (it.hasNext()) {
        AttributeSet as = it.next();
        colorsMap.put(
                (String) as.getAttribute(StyleConstants.NameAttribute),
                as
                );
    }
    return colorsMap;
}
 
Example #4
Source File: KTextEdit.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
@Override
public View create(Element elem) {
	String kind = elem.getName();
	if (kind != null) {
		if (kind.equals(AbstractDocument.ContentElementName)) {
			return new WrapLabelView(elem);
		} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
			return new ParagraphView(elem);
		} else if (kind.equals(AbstractDocument.SectionElementName)) {
			return new BoxView(elem, View.Y_AXIS);
		} else if (kind.equals(StyleConstants.ComponentElementName)) {
			return new ComponentView(elem);
		} else if (kind.equals(StyleConstants.IconElementName)) {
			return new IconView(elem);
		}
	}

	// default to text display
	return new LabelView(elem);
}
 
Example #5
Source File: JTextPaneUtils.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
public static void appendIconAndText(JTextPane textPane, Image image, String message) {
	StyledDocument document = (StyledDocument)textPane.getDocument();
	image = StatusMessageImageConverter.convertImage(image);
	
       try {
		JLabel jl  = JLabelFactory.createJLabel("<html>" + message + "</html>", image);
		jl.setHorizontalAlignment(SwingConstants.LEFT);

		String styleName = "style"+message;
		Style textStyle = document.addStyle(styleName, null);
	    StyleConstants.setComponent(textStyle, jl);

	    document.insertString(document.getLength(), " ", document.getStyle(styleName));
	} catch (BadLocationException e) {
		throw new IllegalStateException(e);
	}
}
 
Example #6
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private MainPanel() {
  super(new GridLayout(3, 1));

  JTextPane label1 = new JTextPane();
  // MutableAttributeSet attr = new SimpleAttributeSet();
  Style attr = label1.getStyle(StyleContext.DEFAULT_STYLE);
  StyleConstants.setLineSpacing(attr, -.2f);
  label1.setParagraphAttributes(attr, true);
  label1.setText("JTextPane\n" + DUMMY_TEXT);
  // [XP Style Icons - Download](https://xp-style-icons.en.softonic.com/)
  ImageIcon icon = new ImageIcon(getClass().getResource("wi0124-32.png"));
  add(makeLeftIcon(label1, icon));

  JTextArea label2 = new JTextArea("JTextArea\n" + DUMMY_TEXT);
  add(makeLeftIcon(label2, icon));

  JLabel label3 = new JLabel("<html>JLabel+html<br>" + DUMMY_TEXT);
  label3.setIcon(icon);
  add(label3);

  setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
  setPreferredSize(new Dimension(320, 240));
}
 
Example #7
Source File: JTextPaneUtils.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
public static void appendTextUsingLabel(JTextPane textPane, String message) {
	StyledDocument document = (StyledDocument)textPane.getDocument();
	
       try {
		JLabel jl  = JLabelFactory.createJLabel(message);
		jl.setHorizontalAlignment(SwingConstants.LEFT);

		String styleName = "style"+message;
		Style textStyle = document.addStyle(styleName, null);
	    StyleConstants.setComponent(textStyle, jl);

	    document.insertString(document.getLength(), " ", document.getStyle(styleName));
	} catch (BadLocationException e) {
		throw new IllegalStateException(e);
	}
}
 
Example #8
Source File: PythonIndentation.java    From SikuliX1 with MIT License 6 votes vote down vote up
@Override
public String getLeadingWhitespace(StyledDocument doc, int head, int len) throws BadLocationException {
  String ret = "";
  int pos = head;
  while (pos < head + len) {
    Element e = doc.getCharacterElement(pos);
    if (e.getName().equals(StyleConstants.ComponentElementName)) {
      break;
    }
    int eStart = e.getStartOffset();
    int eEnd = e.getEndOffset();
    String space = getLeadingWhitespace(doc.getText(eStart, eEnd - eStart));
    ret += space;
    if (space.length() < eEnd - eStart) {
      break;
    }
    pos = eEnd;
  }
  return ret;
}
 
Example #9
Source File: AnnotationDisplayCustomizationFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
  Style style = AnnotationDisplayCustomizationFrame.this.styleMap
      .get(AnnotationDisplayCustomizationFrame.this.currentTypeName);
  if (style == null) {
    style = AnnotationDisplayCustomizationFrame.this.textPane.addStyle(
        AnnotationDisplayCustomizationFrame.this.currentTypeName,
        AnnotationDisplayCustomizationFrame.this.styleMap.get(CAS.TYPE_NAME_ANNOTATION));
  }
  StyleConstants.setForeground(style, StyleConstants
      .getForeground(AnnotationDisplayCustomizationFrame.this.currentStyle));
  StyleConstants.setBackground(style, StyleConstants
      .getBackground(AnnotationDisplayCustomizationFrame.this.currentStyle));
  AnnotationDisplayCustomizationFrame.this.styleMap.put(
      AnnotationDisplayCustomizationFrame.this.currentTypeName, style);
  enableButtons(false);
  AnnotationDisplayCustomizationFrame.this.repaint();
}
 
Example #10
Source File: WrapEditorKit.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public View create( Element elem ) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new WrapLabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return new ParagraphView(elem);
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new BoxView(elem, View.Y_AXIS);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }
    }

    // default to text display
    return new LabelView(elem);
}
 
Example #11
Source File: ConsoleSupport.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected void addStylesToDocument(JTextPane outputArea) {
    StyledDocument doc = outputArea.getStyledDocument();

    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "Monospaced");

    promptStyle = doc.addStyle("prompt", regular);
    StyleConstants.setForeground(promptStyle, Color.BLUE);

    commandStyle = doc.addStyle("command", regular);
    StyleConstants.setForeground(commandStyle, Color.MAGENTA);

    outputStyle = doc.addStyle("output", regular);
    StyleConstants.setBold(outputStyle, true);
}
 
Example #12
Source File: SyntaxColoringPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Collection<AttributeSet> invertCategory (Collection<AttributeSet> c, AttributeSet category) {
    if (category == null) return c;
    ArrayList<AttributeSet> result = new ArrayList<AttributeSet> (c);
    int i = result.indexOf (category);
    SimpleAttributeSet as = new SimpleAttributeSet (category);
    Color highlight = (Color) getValue (currentLanguage, category, StyleConstants.Background);
    if (highlight == null) return result;
    Color newColor = new Color (
        255 - highlight.getRed (),
        255 - highlight.getGreen (),
        255 - highlight.getBlue ()
    );
    as.addAttribute (
        StyleConstants.Underline,
        newColor
    );
    result.set (i, as);
    return result;
}
 
Example #13
Source File: MessageList.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
@Override
public javax.swing.text.View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        switch (kind) {
            case AbstractDocument.ContentElementName:
                return new WrapLabelView(elem);
            case AbstractDocument.ParagraphElementName:
                return new ParagraphView(elem);
            case AbstractDocument.SectionElementName:
                return new BoxView(elem, javax.swing.text.View.Y_AXIS);
            case StyleConstants.ComponentElementName:
                return new ComponentView(elem);
            case StyleConstants.IconElementName:
                return new IconView(elem);
        }
    }
    // default to text display
    return new LabelView(elem);
}
 
Example #14
Source File: QueryBuilderSqlTextArea.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public QueryBuilderSqlTextArea(QueryBuilder queryBuilder) {
        super();
        _queryBuilder = queryBuilder;
        createSqlTextPopup();
        // Get Netbeans-registered EditorKit for SQL content
	setEditorKit(CloneableEditorSupport.getEditorKit("text/x-sql"));
        if ( SYNTAX_HIGHLIGHT ) {
            addKeyListener(this);
        }
        
        // set the bold attribute
        // colors chosen from :
        // http://ui.netbeans.org/docs/hi/annotations/index2.html
        StyleConstants.setForeground(keyword,new Color(0,0,153));
        StyleConstants.setForeground(schema, new Color(0,111,0));
        StyleConstants.setForeground(column,new Color(120,0,0));
          
        // Add support for code completion (comment out, breaks syntax highlighting)
//        QueryBuilderSqlCompletion doc = new QueryBuilderSqlCompletion( this, sqlReservedWords);
//        this.setDocument(doc);
    }
 
Example #15
Source File: OurConsole.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, boolean italic, boolean strike, Color color, int leftIndent) {


        fontName = AlloyGraphics.matchBestFontName(fontName);

        MutableAttributeSet s = new SimpleAttributeSet();
        StyleConstants.setFontFamily(s, fontName);
        StyleConstants.setFontSize(s, fontSize);
        StyleConstants.setLineSpacing(s, -0.2f);
        StyleConstants.setBold(s, boldness);
        StyleConstants.setItalic(s, italic);
        StyleConstants.setForeground(s, color);
        StyleConstants.setLeftIndent(s, leftIndent);
        StyleConstants.setStrikeThrough(s, strike);
        return s;
    }
 
Example #16
Source File: LogRecordEntry.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new {@link LogRecordEntry} which automatically formats the given {@link LogRecord}
 * with the RapidMiner Studio log styling and default logging format.
 *
 * @param logRecord
 */
public LogRecordEntry(LogRecord logRecord) {

	logLevel = logRecord.getLevel();
	initialString = logRecord.getMessage();

	simpleAttributeSet = new SimpleAttributeSet();
	if (logRecord.getLevel().intValue() >= Level.SEVERE.intValue()) {
		StyleConstants.setForeground(simpleAttributeSet, COLOR_ERROR);
		StyleConstants.setBold(simpleAttributeSet, true);
	} else if (logRecord.getLevel().intValue() >= Level.WARNING.intValue()) {
		StyleConstants.setForeground(simpleAttributeSet, COLOR_WARNING);
		StyleConstants.setBold(simpleAttributeSet, true);
	} else if (logRecord.getLevel().intValue() >= Level.INFO.intValue()) {
		StyleConstants.setForeground(simpleAttributeSet, COLOR_INFO);
		StyleConstants.setBold(simpleAttributeSet, false);
	} else {
		StyleConstants.setForeground(simpleAttributeSet, COLOR_DEFAULT);
		StyleConstants.setBold(simpleAttributeSet, false);
	}

	formattedString = formatter.format(logRecord);
}
 
Example #17
Source File: LogDataFormatter.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
private Style getStyleForMarkerColor(MarkerColors markerColors) {
  String styleName = "MarkerColor" + markerColors.name();
  Style style = sc.getStyle(styleName);
  if (style == null) {
    style = sc.addStyle(styleName, mainStyle);
    StyleConstants.setForeground(style, markerColors.getForeground());
    StyleConstants.setBackground(style, markerColors.getBackground());
  }
  return style;
}
 
Example #18
Source File: EditableNotificationMessageElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void updateStyle(@Nonnull JEditorPane editorPane, @javax.annotation.Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
  super.updateStyle(editorPane, tree, value, selected, hasFocus);

  final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
  final Style linkStyle = htmlDocument.getStyleSheet().getStyle(LINK_STYLE);
  StyleConstants.setForeground(linkStyle, IdeTooltipManager.getInstance().getLinkForeground(false));
  StyleConstants.setItalic(linkStyle, true);
  HTMLDocument.Iterator iterator = htmlDocument.getIterator(HTML.Tag.A);
  while (iterator.isValid()) {
    boolean disabledLink = false;
    final AttributeSet attributes = iterator.getAttributes();
    if (attributes instanceof SimpleAttributeSet) {
      final Object attribute = attributes.getAttribute(HTML.Attribute.HREF);
      if (attribute instanceof String && disabledLinks.containsKey(attribute)) {
        disabledLink = true;
        //TODO [Vlad] add support for disabled link text update
        ////final String linkText = disabledLinks.get(attribute);
        //if (linkText != null) {
        //}
        ((SimpleAttributeSet)attributes).removeAttribute(HTML.Attribute.HREF);
      }
      if (attribute == null) {
        disabledLink = true;
      }
    }
    if (!disabledLink) {
      htmlDocument.setCharacterAttributes(
              iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset(), linkStyle, false);
    }
    iterator.next();
  }
}
 
Example #19
Source File: JViewPortBackingStoreImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void createStyles() {
    styles = new StyleContext();
    doc = new DefaultStyledDocument(styles);
    contentAttributes = new HashMap<>();

    // no attributes defined
    Style s = styles.addStyle(null, null);
    contentAttributes.put("none", s);

    Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);

    Style heading = styles.addStyle("heading", def);
    StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);
}
 
Example #20
Source File: bug7189299.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example #21
Source File: HyperlinkListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static AttributeSet getHyperlinkAS () {
    if (hyperlinkAS == null) {
        SimpleAttributeSet as = new SimpleAttributeSet ();
        as.addAttribute (StyleConstants.Foreground, Color.blue);
        as.addAttribute (StyleConstants.Underline, Color.blue);
        hyperlinkAS = as;
    }
    return hyperlinkAS;
}
 
Example #22
Source File: EditorContextImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Color getHighlight(String name, int defaultRGB) {
    FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
    AttributeSet as = (fcs != null) ? fcs.getFontColors(name) : null;
    if (as != null) {
        return (Color) as.getAttribute(StyleConstants.Background);
    } else {
        return new Color(defaultRGB);
    }
}
 
Example #23
Source File: RefactoringUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String color(String string, AttributeSet set) {
    if (set == null) {
        return string;
    }
    if (string.trim().length() == 0) {
        return string.replace(" ", "&nbsp;").replace("\n", "<br>"); //NOI18N

    }
    StringBuilder buf = new StringBuilder(string);
    if (StyleConstants.isBold(set)) {
        buf.insert(0, "<b>"); //NOI18N

        buf.append("</b>"); //NOI18N

    }
    if (StyleConstants.isItalic(set)) {
        buf.insert(0, "<i>"); //NOI18N

        buf.append("</i>"); //NOI18N

    }
    if (StyleConstants.isStrikeThrough(set)) {
        buf.insert(0, "<s>"); // NOI18N

        buf.append("</s>"); // NOI18N

    }
    buf.insert(0, "<font color=" + getHTMLColor(StyleConstants.getForeground(set)) + ">"); //NOI18N

    buf.append("</font>"); //NOI18N

    return buf.toString();
}
 
Example #24
Source File: GtpConsoleDialog.java    From mylizzie with GNU General Public License v3.0 5 votes vote down vote up
public GtpConsoleDialog(Window owner) {
    super(owner);
    initComponents();

    textLineManager = new TextLineManager(textPaneGtpConsole.getStyledDocument(), 10000);
    grayText = new SimpleAttributeSet();
    StyleConstants.setForeground(grayText, Color.GRAY);
    commandConsumer = command -> {
        SwingUtilities.invokeLater(() -> textLineManager.appendBoldLine("GTP> " + command));

        enableStdoutDisplay = !isAnalysisCommand(command);
        enableStderrDisplay = !isClassicAnalysisCommand(command);
    };
    stdoutConsumer = line -> {
        if (enableStdoutDisplay) {
            SwingUtilities.invokeLater(() -> textLineManager.appendNormalLine(line));
        }
    };
    stderrConsumer = line -> {
        if (enableStderrDisplay && !isStderrLineFiltered(line)) {
            SwingUtilities.invokeLater(() -> textLineManager.appendLine(line, grayText));
        }
    };
    exitObserver = exitCode -> unlinkGtpClient();
    gtpClient = null;
    enableStdoutDisplay = true;
    enableStderrDisplay = true;

    getRootPane().registerKeyboardAction(e -> {
                if (!textFieldGtpCommandInput.isFocusOwner()) {
                    setVisible(!isVisible());
                }
            },
            KeyStroke.getKeyStroke(KeyEvent.VK_E, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW
    );
}
 
Example #25
Source File: SyntaxDocument.java    From binnavi with Apache License 2.0 5 votes vote down vote up
public SyntaxDocument(final boolean addBraces) {
  doc = this;

  m_addBraces = addBraces;

  rootElement = doc.getDefaultRootElement();
  putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n");

  StyleConstants.setForeground(normal, Color.black);
  StyleConstants.setFontSize(normal, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(comment, Color.gray);
  StyleConstants.setItalic(comment, true);
  StyleConstants.setFontSize(comment, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(keyword, Color.blue.darker());
  StyleConstants.setFontSize(keyword, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(quote, Color.red);
  StyleConstants.setFontSize(quote, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(type, Color.PINK.darker());
  StyleConstants.setFontSize(type, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(number, Color.green.darker());
  StyleConstants.setFontSize(number, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(constant, Color.red.darker().darker());
  StyleConstants.setFontSize(constant, DEFAULT_FONT_SIZE);
}
 
Example #26
Source File: GuiUtil.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #27
Source File: PythonIndentation.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Override
public int atEndOfLine(StyledDocument doc, int cpos, int start, String s, int sLen) {
  for (int i = cpos - start; i < sLen; i++) {
    if (doc.getCharacterElement(cpos).getName().equals(StyleConstants.ComponentElementName) || !isWhitespace(s.charAt(i))) {
      return i + start;
    }
    cpos++;
  }
  return -1;
}
 
Example #28
Source File: EmbeddingHighlightsContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
EmbeddingHighlightsContainer(Document document) {
    this.document = document;

    //try load the background from tpl settings
    FontColorSettings fcs = MimeLookup.getLookup(TplDataLoader.MIME_TYPE).lookup(FontColorSettings.class);
    Color tplBG = null;
    if (fcs != null) {
        tplBG = getColoring(fcs, TPL_BACKGROUND_TOKEN_NAME);
    }

    tplBackground = tplBG == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable(
        StyleConstants.Background, tplBG, ATTR_EXTENDS_EOL, Boolean.TRUE);
}
 
Example #29
Source File: bug7189299.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example #30
Source File: JViewPortBackingStoreImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void createStyles() {
    styles = new StyleContext();
    doc = new DefaultStyledDocument(styles);
    contentAttributes = new HashMap<>();

    // no attributes defined
    Style s = styles.addStyle(null, null);
    contentAttributes.put("none", s);

    Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);

    Style heading = styles.addStyle("heading", def);
    StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);
}