FileDocCategorySizeDatePackage
SynthTextPaneUI.javaAPI DocJava SE 5 API4751Fri Aug 26 14:58:14 BST 2005javax.swing.plaf.synth

SynthTextPaneUI

public class SynthTextPaneUI extends SynthEditorPaneUI
Provides the look and feel for a styled text editor in the Synth look and feel.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

author
Shannon Hickey
version
1.8 12/19/03

Fields Summary
Constructors Summary
Methods Summary
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)
Creates a UI for the JTextPane.

param
c the JTextPane object
return
the UI

        return new SynthTextPaneUI();
    
protected java.lang.StringgetPropertyPrefix()
Fetches the name used as a key to lookup properties through the UIManager. This is used as a prefix to all the standard text properties.

return
the name ("TextPane")

        return "TextPane";
    
public voidinstallUI(javax.swing.JComponent c)

        super.installUI(c);
        updateForeground(c.getForeground());
        updateFont(c.getFont());
    
voidpaintBackground(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g, javax.swing.JComponent c)

        context.getPainter().paintTextPaneBackground(context, g, 0, 0,
                                                  c.getWidth(), c.getHeight());
    
public voidpaintBorder(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g, int x, int y, int w, int h)

        context.getPainter().paintTextPaneBorder(context, g, x, y, w, h);
    
protected voidpropertyChange(java.beans.PropertyChangeEvent evt)
This method gets called when a bound property is changed on the associated JTextComponent. This is a hook which UI implementations may change to reflect how the UI displays bound properties of JTextComponent subclasses. If the font, foreground or document has changed, the the appropriate property is set in the default style of the document.

param
evt the property change event

        super.propertyChange(evt);

        String name = evt.getPropertyName();

        if (name.equals("foreground")) {
            updateForeground((Color)evt.getNewValue());
        } else if (name.equals("font")) {
            updateFont((Font)evt.getNewValue());
        } else if (name.equals("document")) {
            JComponent comp = getComponent();
            updateForeground(comp.getForeground());
            updateFont(comp.getFont());
        }
    
private voidupdateFont(java.awt.Font font)
Update the font in the default style of the document.

param
font the new font to use or null to remove the font attribute from the document's style

        StyledDocument doc = (StyledDocument)getComponent().getDocument();
        Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

        if (style == null) {
            return;
        }

        if (font == null) {
            style.removeAttribute(StyleConstants.FontFamily);
            style.removeAttribute(StyleConstants.FontSize);
            style.removeAttribute(StyleConstants.Bold);
            style.removeAttribute(StyleConstants.Italic);
        } else {
            StyleConstants.setFontFamily(style, font.getName());
            StyleConstants.setFontSize(style, font.getSize());
            StyleConstants.setBold(style, font.isBold());
            StyleConstants.setItalic(style, font.isItalic());
        }
    
private voidupdateForeground(java.awt.Color color)
Update the color in the default style of the document.

param
color the new color to use or null to remove the color attribute from the document's style

        StyledDocument doc = (StyledDocument)getComponent().getDocument();
        Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

        if (style == null) {
            return;
        }

        if (color == null) {
            style.removeAttribute(StyleConstants.Foreground);
        } else {
            StyleConstants.setForeground(style, color);
        }