Java Code Examples for javax.swing.text.StyleContext

The following examples show how to use javax.swing.text.StyleContext. These examples are extracted from open source projects. 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
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
 
Example 2
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
 
Example 3
Source Project: Spade   Source File: AboutDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void addStylesToDocument(StyledDocument doc)
{
	//Initialize some styles.
	Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
	
	Style regular = doc.addStyle("regular", def);
	StyleConstants.setFontFamily(def, "SansSerif");
	
	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, 16);
	StyleConstants.setBold(s, true);
}
 
Example 4
Source Project: Bytecoder   Source File: CSS.java    License: Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException
{
    ObjectInputStream.GetField f = s.readFields();
    int newBaseFontSize = f.get("baseFontSize", 0);
    setBaseFontSize(newBaseFontSize);

    // Reconstruct the hashtable.
    int numValues = s.readInt();
    valueConvertor = new Hashtable<>();
    while (numValues-- > 0) {
        Object key = s.readObject();
        Object value = s.readObject();
        Object staticKey = StyleContext.getStaticAttribute(key);
        if (staticKey != null) {
            key = staticKey;
        }
        Object staticValue = StyleContext.getStaticAttribute(value);
        if (staticValue != null) {
            value = staticValue;
        }
        if (key != null && value != null) {
            valueConvertor.put(key, value);
        }
    }
}
 
Example 5
private void showPacket(final AbstractPacketPoint point) {
	SwingUtilities4.invokeInEDT(() -> {
		final String[] lines = point.getPayload().split("\n");
		int max = 0;
		for (final String line1 : lines) {
			max = Math.max(max, line1.length());
		}
		max += 5;
		for (final String line2 : lines) {
			final Color color = colorForLine(line2);
			final StyleContext sc = StyleContext.getDefaultStyleContext();
			AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLACK);

			aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
			aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
			aset = sc.addAttribute(aset, StyleConstants.Bold, false);
			aset = sc.addAttribute(aset, StyleConstants.Background, color);
			final int len = _details.getDocument().getLength();
			_details.setCaretPosition(len);
			_details.setCharacterAttributes(aset, false);
			_details.replaceSelection(line2 + StringUtils.repeat(" ", max - line2.length()) + "\n");
		}
		_details.setCaretPosition(0);
	});
}
 
Example 6
Source Project: groovy   Source File: ConsoleSupport.java    License: 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 7
public MemoryStatusGadget() {
  if ( MacOSXIntegration.MAC_OS_X ) {
    setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 10 ),
      BorderFactory.createLineBorder( SystemColor.controlShadow ) ) );
  } else {
    setBorder( BorderFactory.createLineBorder( SystemColor.controlShadow ) );
  }
  setFont(
    StyleContext.getDefaultStyleContext().getFont( getFont().getName(), Font.PLAIN, getFont().getSize() - 2 ) );
  setHorizontalAlignment( JLabel.CENTER );

  timer = new Timer( 500, new MemoryStatusUpdateAction() );
  timer.setRepeats( true );
  timer.start();

  addMouseListener( new GarbageCollectorAction() );
}
 
Example 8
public Component getTableCellRendererComponent( final JTable table, final Object value, final boolean isSelected,
                                                final boolean hasFocus, final int row, final int column ) {

  final JLabel label =
    (JLabel) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
  if ( value == null ) {
    return label;
  }
  label.setBackground( Color.GRAY );
  label.setForeground( Color.WHITE );
  if ( column >= 1 ) {
    label.setText( "" ); //$NON-NLS-1$
    label.setIcon( null );
  } else {
    final Font font = StyleContext.getDefaultStyleContext().getFont( label.getFont().getName(), Font.BOLD,
      label.getFont().getSize() );
    label.setFont( font );
    final GroupingHeader groupingHeader = (GroupingHeader) value;
    final boolean isCollapsed = groupingHeader.isCollapsed();
    if ( table.getModel() instanceof GroupedTableModel ) {
      label.setIcon( isCollapsed ? expandImage : collapseImage );
    }
  }
  return label;
}
 
Example 9
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
 
Example 10
Source Project: otroslogviewer   Source File: StackTraceColorizer.java    License: Apache License 2.0 6 votes vote down vote up
protected void initStyles() {
  styleContext = new StyleContext();
  Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
  StyleConstants.setFontFamily(defaultStyle, "courier");
  styleStackTrace = styleContext.addStyle("stackTrace", defaultStyle);

  StyleConstants.setBackground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_BACKGROUND));
  StyleConstants.setForeground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FOREGROUND));
  stylePackage = styleContext.addStyle("stylePackage", styleStackTrace);
  styleClass = styleContext.addStyle("styleClass", stylePackage);
  StyleConstants.setForeground(styleClass, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_CLASS));
  StyleConstants.setBold(styleClass, true);
  styleMethod = styleContext.addStyle("styleMethod", styleStackTrace);
  StyleConstants.setForeground(styleMethod, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_METHOD));
  StyleConstants.setItalic(styleMethod, true);
  StyleConstants.setBold(styleMethod, true);
  styleFile = styleContext.addStyle("styleFile", styleStackTrace);
  StyleConstants.setForeground(styleFile, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FLE));
  StyleConstants.setUnderline(styleFile, true);

  styleCodeComment = styleContext.addStyle("styleCodeComment", defaultStyle);
  StyleConstants.setForeground(styleCodeComment, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_COMMENT));
  StyleConstants.setItalic(styleCodeComment, true);
}
 
Example 11
public ImageToggleButton( final ImageIcon icon,
                          final String text,
                          final GlobalPane.Alignment alignment ) {
  super();
  this.imageIcon = icon;
  this.text = text;

  setMargin( new Insets( 0, 0, 0, 0 ) );
  setContentAreaFilled( false );
  setBorderPainted( false );
  setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) );
  setFont( StyleContext.getDefaultStyleContext().getFont( getFont().getName(), Font.PLAIN, 10 ) );
  setAlignmentX( alignment );

  setFocusable( false );
}
 
Example 12
Source Project: otroslogviewer   Source File: MessageColorizerEditor.java    License: Apache License 2.0 6 votes vote down vote up
private void refreshView() {
  LOGGER.info("refreshing view");
  Style defaultStyle = textPane.getStyle(StyleContext.DEFAULT_STYLE);
  String text = textPane.getText();
  textPane.getStyledDocument().setCharacterAttributes(0, text.length(), defaultStyle, true);
  try {
    PropertyPatternMessageColorizer propertyPatternMessageColorize = createMessageColorizer();
    if (propertyPatternMessageColorize.colorizingNeeded(text)) {
      Collection<MessageFragmentStyle> colorize = propertyPatternMessageColorize.colorize(text);
      for (MessageFragmentStyle mfs : colorize) {
        textPane.getStyledDocument().setCharacterAttributes(mfs.getOffset(), mfs.getLength(), mfs.getStyle(), mfs.isReplace());
      }
    }
  } catch (Exception e) {
    LOGGER.error(String.format("Can't init PropertyPatternMessageColorizer:%s", e.getMessage()));
    statusObserver.updateStatus(String.format("Error: %s", e.getMessage()), StatusObserver.LEVEL_ERROR);
  }

}
 
Example 13
Source Project: jadx   Source File: FontUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Font loadByStr(String fontDesc) {
	String[] parts = fontDesc.split("-");
	if (parts.length != 3) {
		throw new JadxRuntimeException("Unsupported font description format: " + fontDesc);
	}
	String name = parts[0];
	int style = parseFontStyle(parts[1]);
	int size = Integer.parseInt(parts[2]);

	StyleContext sc = StyleContext.getDefaultStyleContext();
	Font font = sc.getFont(name, style, size);
	if (font == null) {
		throw new JadxRuntimeException("Font not found: " + fontDesc);
	}
	return font;
}
 
Example 14
Source Project: java-swing-tips   Source File: MainPanel.java    License: 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 15
Source Project: FlatLaf   Source File: DemoFrame.java    License: Apache License 2.0 5 votes vote down vote up
private void fontFamilyChanged( ActionEvent e ) {
	String fontFamily = e.getActionCommand();

	Font font = UIManager.getFont( "defaultFont" );
	Font newFont = StyleContext.getDefaultStyleContext().getFont( fontFamily, font.getStyle(), font.getSize() );
	UIManager.put( "defaultFont", newFont );

	FlatLaf.updateUI();
}
 
Example 16
Source Project: FlatLaf   Source File: FlatLaf.java    License: Apache License 2.0 5 votes vote down vote up
static FontUIResource createCompositeFont( String family, int style, int size ) {
	// using StyleContext.getFont() here because it uses
	// sun.font.FontUtilities.getCompositeFontUIResource()
	// and creates a composite font that is able to display all Unicode characters
	Font font = StyleContext.getDefaultStyleContext().getFont( family, style, size );
	return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
}
 
Example 17
Source Project: dragonwell8_jdk   Source File: bug7189299.java    License: 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 18
Source Project: TencentKona-8   Source File: bug7189299.java    License: 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 19
Source Project: jdk8u60   Source File: bug7189299.java    License: 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 20
Source Project: FancyBing   Source File: GuiUtil.java    License: 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 21
Source Project: FancyBing   Source File: GuiUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void addStyle(JTextPane textPane, String name,
                            Color foreground, Color background,
                            boolean bold)
{
    StyledDocument doc = textPane.getStyledDocument();
    StyleContext context = StyleContext.getDefaultStyleContext();
    Style def = context.getStyle(StyleContext.DEFAULT_STYLE);
    Style style = doc.addStyle(name, def);
    if (foreground != null)
        StyleConstants.setForeground(style, foreground);
    if (background != null)
        StyleConstants.setBackground(style, background);
    StyleConstants.setBold(style, bold);
}
 
Example 22
Source Project: openjdk-jdk8u   Source File: bug7189299.java    License: 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 23
Source Project: netbeans   Source File: StackTraceSupport.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 24
Source Project: netbeans   Source File: GuardedDocument.java    License: Apache License 2.0 5 votes vote down vote up
private void init(StyleContext styles) {
    this.styles = styles;
    guardedBlockChain = new MarkBlockChain(this) {
        protected @Override Mark createBlockStartMark() {
            MarkFactory.ContextMark startMark = new MarkFactory.ContextMark(Position.Bias.Forward, false);
            return startMark;
        }

        protected @Override Mark createBlockEndMark() {
            MarkFactory.ContextMark endMark = new MarkFactory.ContextMark(Position.Bias.Backward, false);
            return endMark;
        }
    };
}
 
Example 25
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 26
Source Project: freecol   Source File: Utility.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void initStyleContext(Font font) {
    Style defaultStyle = StyleContext.getDefaultStyleContext()
        .getStyle(StyleContext.DEFAULT_STYLE);

    STYLE_CONTEXT = new StyleContext();
    Style regular = STYLE_CONTEXT.addStyle("regular", defaultStyle);
    StyleConstants.setFontFamily(regular, font.getFamily());
    StyleConstants.setFontSize(regular, font.getSize());

    Style buttonStyle = STYLE_CONTEXT.addStyle("button", regular);
    StyleConstants.setForeground(buttonStyle, LINK_COLOR);

    Style right = STYLE_CONTEXT.addStyle("right", regular);
    StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
}
 
Example 27
Source Project: Bytecoder   Source File: CSS.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(java.io.ObjectOutputStream s)
    throws IOException
{
    s.defaultWriteObject();

    // Determine what values in valueConvertor need to be written out.
    Enumeration<?> keys = valueConvertor.keys();
    s.writeInt(valueConvertor.size());
    if (keys != null) {
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = valueConvertor.get(key);
            if (!(key instanceof Serializable) &&
                (key = StyleContext.getStaticAttributeKey(key)) == null) {
                // Should we throw an exception here?
                key = null;
                value = null;
            }
            else if (!(value instanceof Serializable) &&
                (value = StyleContext.getStaticAttributeKey(value)) == null){
                // Should we throw an exception here?
                key = null;
                value = null;
            }
            s.writeObject(key);
            s.writeObject(value);
        }
    }
}
 
Example 28
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 29
Source Project: openjdk-jdk9   Source File: bug7189299.java    License: 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 Project: jdk8u-jdk   Source File: bug7189299.java    License: 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.");
    }
}