private void copyForeground(Style style, Color defaultColor, Map<String, Color> overriden) { Color newColor = StyleConstants.getForeground(style); if (!newColor.equals(defaultColor)) { overriden.put(style.getName(), newColor); } }
public void init(DrawContext ctx) { foreColor = StyleConstants.getForeground(style); backColor = StyleConstants.getBackground(style); }
public void init(DrawContext ctx) { foreColor = StyleConstants.getForeground(style); backColor = StyleConstants.getBackground(style); }
private String getColor(Level p) { Color c = StyleConstants.getForeground(attributes.get(p)); return c == null ? null : colorToString(c); }
/** This method applies an AttributeSet to a Graphics context * * @param g The graphic context * @param attribute The attribute to apply */ protected void applyAttribute(Graphics g, AttributeSet attribute) { if(attribute == null) { g.setColor(Color.black); g.setFont(DEFAULT_FONT); return; } g.setFont(getFontForAttribute(attribute)); final Color c = StyleConstants.getForeground(attribute); if(c == null) g.setColor(Color.black); else g.setColor(c); }
/** * Save color preferences. * * @param file the file * @throws IOException Signals that an I/O exception has occurred. */ public void saveColorPreferences(File file) throws IOException { Properties prefs1 = new Properties(); Iterator<String> it = this.styleMap.keySet().iterator(); String type; Style style; Color fg, bg; while (it.hasNext()) { type = it.next(); style = this.styleMap.get(type); fg = StyleConstants.getForeground(style); bg = StyleConstants.getBackground(style); prefs1.setProperty(type, Integer.toString(fg.getRGB()) + "+" + Integer.toString(bg.getRGB())); } FileOutputStream out = new FileOutputStream(file); prefs1.store(out, "Color preferences for annotation viewer."); }
private static String color(String string, AttributeSet set) { if (set==null) { return string; } if (string.trim().length() == 0) { return string.replace(" ", " ").replace("\n", "<br>"); //NOI18N } StringBuffer buf = new StringBuffer(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(); }
private void setForeground(Style style, Color defaultColor, Map<String, Color> overriden) { Color foreground = overriden.get(style.getName()); if (foreground == null) { foreground = defaultColor; } StyleConstants.setForeground(style, foreground == null ? StyleConstants.getForeground( doc.getStyle(StyleContext.DEFAULT_STYLE)) : foreground); }
cssMap.put("color", colorToHex(StyleConstants.getForeground(style)));
@Override public void actionPerformed(ActionEvent event) { Style style = AnnotationDisplayCustomizationFrame.this.styleMap .get(AnnotationDisplayCustomizationFrame.this.currentTypeName); if (style == null) { style = AnnotationDisplayCustomizationFrame.this.styleMap.get(CAS.TYPE_NAME_ANNOTATION); } // assert(style != null); AnnotationDisplayCustomizationFrame.this.fgColor = StyleConstants.getForeground(style); AnnotationDisplayCustomizationFrame.this.fgIcon .setColor(AnnotationDisplayCustomizationFrame.this.fgColor); AnnotationDisplayCustomizationFrame.this.bgColor = StyleConstants.getBackground(style); AnnotationDisplayCustomizationFrame.this.bgIcon .setColor(AnnotationDisplayCustomizationFrame.this.bgColor); setCurrentStyle(style); setTextPane(); enableButtons(false); AnnotationDisplayCustomizationFrame.this.repaint(); }
@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(); }
/** * Sets the current style. * * @param style the new current style */ private void setCurrentStyle(Style style) { // Copy style. this.currentStyle = this.textPane.addStyle(currentStyleName, style); StyleConstants.setForeground(this.currentStyle, StyleConstants.getForeground(style)); StyleConstants.setBackground(this.currentStyle, StyleConstants.getBackground(style)); }
if (highlightMatchesEnabled && getAttributes().containsAttribute(Attribute.HIGHLIGHT_WORD, true)) { Color c = StyleConstants.getForeground(getAttributes()); Color c2; Color c3;
this.textPane.addStyle(defaultStyleName, defaultStyle); setCurrentStyle(style); this.fgColor = StyleConstants.getForeground(this.currentStyle); this.bgColor = StyleConstants.getBackground(this.currentStyle); this.fgIcon = new ColorIcon(this.fgColor);
protected Collection<MessageFragmentStyle> colorizeStackTraceRegex(final Style style, String text, Pattern regex, int group) { ArrayList<MessageFragmentStyle> list = new ArrayList<>(); Matcher matcher = regex.matcher(text); Style styleToUse = style; while (matcher.find()) { LocationInfo locationInfo = LocationInfo.parse(matcher.group(0)); if (locationInfo != null) { String name = styleToUse.getName(); Style newStyle = styleContext.addStyle(name + "-" + locationInfo.toString(), styleToUse); newStyle.addAttribute(STYLE_ATTRIBUTE_LOCATION_INFO, locationInfo); StyleConstants.setForeground(newStyle, StyleConstants.getForeground(styleToUse)); StyleConstants.setBold(newStyle, StyleConstants.isBold(styleToUse)); StyleConstants.setItalic(newStyle, StyleConstants.isItalic(styleToUse)); styleToUse = newStyle; } int start = matcher.start(group); int end = matcher.end(group); if (end - start > 0) { MessageFragmentStyle messageFragmentStyle = new MessageFragmentStyle(start, end - start, styleToUse, false); list.add(messageFragmentStyle); } } return list; }
/** * Sets the customization panel. * * @param typeName the new customization panel */ private void setCustomizationPanel(String typeName) { this.currentTypeName = typeName; Style defaultAnnotStyle = this.styleMap.get(CAS.TYPE_NAME_ANNOTATION); Style style = this.styleMap.get(typeName); if (style == null) { style = defaultAnnotStyle; } // Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( // StyleContext.DEFAULT_STYLE); setCurrentStyle(style); this.fgColor = StyleConstants.getForeground(this.currentStyle); this.bgColor = StyleConstants.getBackground(this.currentStyle); this.fgIcon.setColor(this.fgColor); this.bgIcon.setColor(this.bgColor); setTextPane(); enableButtons(false); this.repaint(); }
break; case 39: StyleConstants.setForeground(ANSI, StyleConstants.getForeground(defaultStyle)); break; case 40:
@Override public void mouseClicked(MouseEvent e) { int pos = previewText.viewToModel(e.getPoint()); Style style = getStyleAtPoint(previewText, e.getPoint()); Color color = StyleConstants.getForeground(style); try { int rowStart = getStyleStart(previewText, pos, style); int rowEnd = getStyleEnd(previewText, pos, style); colorPreview_.setText(previewText.getStyledDocument() .getText(rowStart, rowEnd - rowStart)); } catch (BadLocationException e1) { LOGGER_.error("Error creating message preview", e1); } JOptionPane op = new JOptionPane(colorChooser_, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dlg = op.createDialog(previewText, "Choose Text Color"); dlg.setLocationRelativeTo(previewText); colorChooser_.setColor(color); dlg.setVisible(true); if (op.getValue() != null) { color = colorChooser_.getColor(); StyleConstants.setForeground(style, color); refreshPreview(); } } });
@Test public void testColorize() throws BadLocationException { String message = "a55(a)a"; Collection<MessageFragmentStyle> colorize = colorizer.colorize(message); assertEquals(2, colorize.size()); ArrayList<MessageFragmentStyle> list = new ArrayList<>(colorize); MessageFragmentStyle messageFragmentStyle = list.get(0); MessageFragmentStyle messageFragmentStyle1 = list.get(1); assertEquals(messageFragmentStyle.isReplace(), false); assertEquals(messageFragmentStyle.getOffset(), 0); assertEquals(messageFragmentStyle.getLength(), message.length()); Style style = messageFragmentStyle.getStyle(); assertEquals(StyleConstants.getBackground(style), new Color(0, 255, 255)); assertEquals(StyleConstants.getForeground(style), new Color(255, 255, 0)); assertEquals((Boolean) StyleConstants.isBold(style), Boolean.FALSE); assertEquals((Boolean) StyleConstants.isItalic(style), Boolean.TRUE); assertEquals(messageFragmentStyle1.isReplace(), false); assertEquals(messageFragmentStyle1.getOffset(), 1); assertEquals(messageFragmentStyle1.getLength(), 5); Style style1 = messageFragmentStyle1.getStyle(); assertEquals(StyleConstants.getBackground(style1), new Color(0, 0, 255)); assertEquals(StyleConstants.getForeground(style1), new Color(255, 0, 0)); assertEquals((Boolean) StyleConstants.isBold(style1), Boolean.TRUE); assertEquals((Boolean) StyleConstants.isItalic(style1), Boolean.FALSE); } }
boolean highlighted = message.highlighted; if (message.whisper && message.action) { color = StyleConstants.getForeground(styles.info()); highlighted = true;