FileDocCategorySizeDatePackage
GTKNativeStyle.javaAPI DocJava SE 6 API7793Tue Jun 10 00:21:56 BST 2008com.sun.java.swing.plaf.gtk

GTKNativeStyle

public class GTKNativeStyle extends GTKStyle
version
1.7, 03/15/07
author
Kirill Kirichenko

Fields Summary
private final int
widgetType
Type of the GTK widget that has this kind of style. I.e. it is responsible for the style.
private final int
xThickness
private final int
yThickness
private final Font
pangoFont
private Object[]
images
Background images for this style. They are uploaded by demand.
private static final Object
EMPTY_IMAGE_TAG
Constructors Summary
GTKNativeStyle(Font font, com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType widgetType)

    
        
        super(font);
        this.widgetType = widgetType.ordinal();

        String pangoFontName = null;
        synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
            xThickness = native_get_xthickness(this.widgetType);
            yThickness = native_get_ythickness(this.widgetType);
            pangoFontName = native_get_pango_font_name(this.widgetType);
        }
        pangoFont = (pangoFontName != null) ?
            PangoFonts.lookupFont(pangoFontName) : null;
    
Methods Summary
booleanfillBackground(javax.swing.plaf.synth.SynthContext context, int state)
Returns true if the style should fill in the background of the specified context for the specified state.

        Object image = getBackgroundImage(state);
        return image == EMPTY_IMAGE_TAG;
    
java.awt.ImagegetBackgroundImage(javax.swing.plaf.synth.SynthContext context, int state)
Returns the Icon to fill the background in with for the specified context and state.

        Object image = getBackgroundImage(state);
        return (image == EMPTY_IMAGE_TAG) ? null : (Image)image;
    
private java.lang.ObjectgetBackgroundImage(int state)

        state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
        
        if (images[state] != null) {
            return images[state];
        }
        
        Dimension size = null;
        
        synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
            size = native_get_image_dimension(widgetType, state);
        }
        
        if (size != null) {
            BufferedImage image = new BufferedImage(size.width, size.height, 
                                                    BufferedImage.TYPE_INT_RGB);

            // Getting the DataBuffer for an image (as it's done below) defeats
            // possible future acceleration.
            // Calling setLocalAccelerationEnabled on that image's surface
            // manager re-enables it.
            boolean accelerated = false;
            CachingSurfaceManager csm = null;
            SurfaceManager sm = SurfaceManager.getManager(image);
            if (sm instanceof CachingSurfaceManager) {
                csm = (CachingSurfaceManager)sm;
                accelerated = csm.isLocalAccelerationEnabled();
            }

            DataBufferInt data = (DataBufferInt)image.getRaster().getDataBuffer();
            synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
                native_get_image(data.getData(), size.width, size.height,
                                 widgetType, state);
            }
            
            if (csm != null && accelerated != csm.isLocalAccelerationEnabled()) {
                csm.setLocalAccelerationEnabled(accelerated);
                csm.rasterChanged();
            }
            
            return images[state] = image;
        }
        
        return images[state] = EMPTY_IMAGE_TAG;
    
java.lang.ObjectgetClassSpecificValue(javax.swing.plaf.synth.Region region, java.lang.String key)
Returns the value for a class specific property. A class specific value is a value that will be picked up based on class hierarchy.

param
context SynthContext indentifying requestor
param
key Key identifying class specific value
return
Value, or null if one has not been defined.

        synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
            return native_get_class_value(widgetType, key);
        }
    
java.lang.ObjectgetClassSpecificValue(com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType wt, java.lang.String key)
Returns the value for a class specific property for a particular WidgetType. This method is useful in those cases where we need to fetch a value for a Region that is not associated with the component currently in use (e.g. we need to figure out the insets for a SCROLL_BAR, but certain values can only be extracted from a SCROLL_PANE region).

param
wt WidgetType for which to fetch the value
param
key Key identifying class specific value
return
Value, or null if one has not been defined

        synchronized (UNIXToolkit.GTK_LOCK) {
            return native_get_class_value(wt.ordinal(), key);
        }
    
protected java.awt.FontgetFontForState(javax.swing.JComponent c, javax.swing.plaf.synth.Region id, int state)
Returns the font for the specified state.

param
c JComponent the style is associated with
param
id Region identifier
param
state State of the region.
return
Font to render with

        if (pangoFont != null) {
            return pangoFont;
        } else {
            return super.getFontForState(c, id, state);
        }
    
java.lang.StringgetFontNameForWidgetType(com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType wt)
Returns fontname specific for the given WidgetType

param
wt WidgetType to return fontname for
return
fontname

        synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
            return native_get_pango_font_name(wt.ordinal());
        }
    
java.awt.ColorgetStyleSpecificColor(javax.swing.plaf.synth.SynthContext context, int state, javax.swing.plaf.synth.ColorType type)

        state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
        synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
            int rgb = native_get_color_for_state(widgetType, state, type.getID());
            return new ColorUIResource(rgb);
        }
    
javax.swing.IcongetStyleSpecificIcon(java.lang.String key, TextDirection direction, int type)

        Image img = ((UNIXToolkit)Toolkit.getDefaultToolkit()).
                getStockIcon(widgetType, key, type, direction.ordinal(), null);
        
         return (img != null) ? new ImageIcon(img) : null;
    
intgetXThickness()
Returns the X thickness to use for this GTKStyle.

return
x thickness.

        return xThickness;
    
intgetYThickness()
Returns the Y thickness to use for this GTKStyle.

return
x thickness.

        return yThickness;
    
private native java.lang.Objectnative_get_class_value(int widgetType, java.lang.String key)

private native intnative_get_color_for_state(int widgetType, int state, int typeID)

private native voidnative_get_image(int[] buffer, int width, int height, int widgetType, int state)

private native java.awt.Dimensionnative_get_image_dimension(int widgetType, int state)

private native java.lang.Stringnative_get_pango_font_name(int widgetType)

private native intnative_get_xthickness(int widgetType)

private native intnative_get_ythickness(int widgetType)