1 9 10 package com.sun.java.swing.plaf.gtk; 11 12 import java.awt.*; 13 import java.awt.image.*; 14 import javax.swing.*; 15 import javax.swing.plaf.*; 16 import javax.swing.plaf.synth.*; 17 18 import com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType; 19 import com.sun.java.swing.plaf.gtk.GTKConstants.StateType; 20 import sun.awt.image.CachingSurfaceManager; 21 import sun.awt.image.SurfaceManager; 22 import sun.awt.UNIXToolkit; 23 24 29 class GTKNativeStyle extends GTKStyle { 30 31 private native int native_get_xthickness(int widgetType); 32 private native int native_get_ythickness(int widgetType); 33 private native int native_get_color_for_state(int widgetType, 34 int state, int typeID); 35 private native Object native_get_class_value(int widgetType, String key); 36 private native String native_get_pango_font_name(int widgetType); 37 private native Dimension native_get_image_dimension(int widgetType, int state); 38 private native void native_get_image(int[] buffer, int width, int height, 39 int widgetType, int state); 40 41 45 private final int widgetType; 46 47 private final int xThickness, yThickness; 48 private final Font pangoFont; 49 50 54 private Object [] images = new Object [5]; 55 56 private static final Object EMPTY_IMAGE_TAG = "<none>"; 57 58 GTKNativeStyle(Font font, WidgetType widgetType) { 59 super(font); 60 this.widgetType = widgetType.ordinal(); 61 62 String pangoFontName = null; 63 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) { 64 xThickness = native_get_xthickness(this.widgetType); 65 yThickness = native_get_ythickness(this.widgetType); 66 pangoFontName = native_get_pango_font_name(this.widgetType); 67 } 68 pangoFont = (pangoFontName != null) ? 69 PangoFonts.lookupFont(pangoFontName) : null; 70 } 71 72 Color getStyleSpecificColor(SynthContext context, int state, ColorType type) { 73 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal(); 74 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) { 75 int rgb = native_get_color_for_state(widgetType, state, type.getID()); 76 return new ColorUIResource(rgb); 77 } 78 } 79 80 88 protected Font getFontForState(JComponent c, Region id, int state) { 89 if (pangoFont != null) { 90 return pangoFont; 91 } else { 92 return super.getFontForState(c, id, state); 93 } 94 } 95 96 101 int getXThickness() { 102 return xThickness; 103 } 104 105 110 int getYThickness() { 111 return yThickness; 112 } 113 114 122 Object getClassSpecificValue(Region region, String key) { 123 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) { 124 return native_get_class_value(widgetType, key); 125 } 126 } 127 128 140 Object getClassSpecificValue(WidgetType wt, String key) { 141 synchronized (UNIXToolkit.GTK_LOCK) { 142 return native_get_class_value(wt.ordinal(), key); 143 } 144 } 145 146 150 boolean fillBackground(SynthContext context, int state) { 151 Object image = getBackgroundImage(state); 152 return image == EMPTY_IMAGE_TAG; 153 } 154 155 161 String getFontNameForWidgetType(WidgetType wt) { 162 synchronized (sun.awt.UNIXToolkit.GTK_LOCK) { 163 return native_get_pango_font_name(wt.ordinal()); 164 } 165 } 166 167 171 Image getBackgroundImage(SynthContext context, int state) { 172 Object image = getBackgroundImage(state); 173 return (image == EMPTY_IMAGE_TAG) ? null : (Image)image; 174 } 175 176 private Object getBackgroundImage(int state) { 177 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal(); 178 179 if (images[state] != null) { 180 return images[state]; 181 } 182 183 Dimension size = null; 184 185 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) { 186 size = native_get_image_dimension(widgetType, state); 187 } 188 189 if (size != null) { 190 BufferedImage image = new BufferedImage(size.width, size.height, 191 BufferedImage.TYPE_INT_RGB); 192 193 boolean accelerated = false; 198 CachingSurfaceManager csm = null; 199 SurfaceManager sm = SurfaceManager.getManager(image); 200 if (sm instanceof CachingSurfaceManager) { 201 csm = (CachingSurfaceManager)sm; 202 accelerated = csm.isLocalAccelerationEnabled(); 203 } 204 205 DataBufferInt data = (DataBufferInt)image.getRaster().getDataBuffer(); 206 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) { 207 native_get_image(data.getData(), size.width, size.height, 208 widgetType, state); 209 } 210 211 if (csm != null && accelerated != csm.isLocalAccelerationEnabled()) { 212 csm.setLocalAccelerationEnabled(accelerated); 213 csm.rasterChanged(); 214 } 215 216 return images[state] = image; 217 } 218 219 return images[state] = EMPTY_IMAGE_TAG; 220 } 221 222 Icon getStyleSpecificIcon(String key, TextDirection direction, int type) { 223 Image img = ((UNIXToolkit)Toolkit.getDefaultToolkit()). 224 getStockIcon(widgetType, key, type, direction.ordinal(), null); 225 226 return (img != null) ? new ImageIcon(img) : null; 227 } 228 } 229 | Popular Tags |