GTKNativeEnginepublic class GTKNativeEngine extends GTKEngine GTKNativeEngine delegates all painting job to native GTK libraries.
Painting with GTKNativeEngine looks like this:
First, startPainting() is called. It prepares an offscreen buffer of the
required size.
Then, any number of paintXXX() methods can be called. They effectively ignore
the Graphics parameter and draw to the offscreen buffer.
Finally, finishPainting() should be called. It fills the data buffer passed
in with the image data. |
Fields Summary |
---|
private static final int | CACHE_SIZESize of the image cache | private static HashMap | regionToWidgetTypeMap | private ImageCache | cache | private int | x0 | private int | y0 | private int | w0 | private int | h0 | private Graphics | graphics | private Object[] | cacheArgs | private static final ColorModel[] | COLOR_MODELS | private static final int[] | BAND_OFFSETS |
Methods Summary |
---|
public void | finishPainting()Called to indicate that painting is finished. We create a new
BufferedImage from the offscreen buffer, cache it, and paint it.
int[] data = new int[w0 * h0];
int transparency = nativeFinishPainting(data, w0, h0);
int[] bands = BAND_OFFSETS[transparency - 1];
DataBuffer dataBuffer = new DataBufferInt(data, data.length);
WritableRaster raster = Raster.createPackedRaster(
dataBuffer, w0, h0, w0, bands, null);
// Raster created this way is not accelerated.
// We re-enable acceleration here.
if (raster instanceof SunWritableRaster) {
((SunWritableRaster)raster).setStolen(false);
}
ColorModel cm = COLOR_MODELS[transparency - 1];
Image img = new BufferedImage(cm, raster, false, null);
cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
graphics.drawImage(img, x0, y0, null);
| public java.lang.Object | getSetting(Settings property)
synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
return native_get_gtk_setting(property.ordinal());
}
| private static int | getTextDirection(javax.swing.plaf.synth.SynthContext context)
TextDirection dir = TextDirection.NONE;
JComponent comp = context.getComponent();
if (comp != null) {
ComponentOrientation co = comp.getComponentOrientation();
if (co != null) {
dir = co.isLeftToRight() ?
TextDirection.LTR : TextDirection.RTL;
}
}
return dir.ordinal();
| static com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType | getWidgetType(javax.swing.JComponent c, javax.swing.plaf.synth.Region id)Translate Region and JComponent into WidgetType ordinals
// Make sure the awt toolkit is loaded so we have access to native
// methods.
Toolkit.getDefaultToolkit();
// Initialize regionToWidgetTypeMap
regionToWidgetTypeMap = new HashMap(50);
regionToWidgetTypeMap.put(Region.ARROW_BUTTON, new WidgetType[] {
WidgetType.SPINNER_ARROW_BUTTON,
WidgetType.COMBO_BOX_ARROW_BUTTON,
WidgetType.HSCROLL_BAR_BUTTON_LEFT,
WidgetType.HSCROLL_BAR_BUTTON_RIGHT,
WidgetType.VSCROLL_BAR_BUTTON_UP,
WidgetType.VSCROLL_BAR_BUTTON_DOWN});
regionToWidgetTypeMap.put(Region.BUTTON, WidgetType.BUTTON);
regionToWidgetTypeMap.put(Region.CHECK_BOX, WidgetType.CHECK_BOX);
regionToWidgetTypeMap.put(Region.CHECK_BOX_MENU_ITEM,
WidgetType.CHECK_BOX_MENU_ITEM);
regionToWidgetTypeMap.put(Region.COLOR_CHOOSER, WidgetType.COLOR_CHOOSER);
regionToWidgetTypeMap.put(Region.FILE_CHOOSER, WidgetType.OPTION_PANE);
regionToWidgetTypeMap.put(Region.COMBO_BOX, WidgetType.COMBO_BOX);
regionToWidgetTypeMap.put(Region.DESKTOP_ICON, WidgetType.DESKTOP_ICON);
regionToWidgetTypeMap.put(Region.DESKTOP_PANE, WidgetType.DESKTOP_PANE);
regionToWidgetTypeMap.put(Region.EDITOR_PANE, WidgetType.EDITOR_PANE);
regionToWidgetTypeMap.put(Region.FORMATTED_TEXT_FIELD, new WidgetType[] {
WidgetType.FORMATTED_TEXT_FIELD, WidgetType.SPINNER_TEXT_FIELD});
regionToWidgetTypeMap.put(GTKRegion.HANDLE_BOX, WidgetType.HANDLE_BOX);
regionToWidgetTypeMap.put(Region.INTERNAL_FRAME,
WidgetType.INTERNAL_FRAME);
regionToWidgetTypeMap.put(Region.INTERNAL_FRAME_TITLE_PANE,
WidgetType.INTERNAL_FRAME_TITLE_PANE);
regionToWidgetTypeMap.put(Region.LABEL, new WidgetType[] {
WidgetType.LABEL, WidgetType.COMBO_BOX_TEXT_FIELD});
regionToWidgetTypeMap.put(Region.LIST, WidgetType.LIST);
regionToWidgetTypeMap.put(Region.MENU, WidgetType.MENU);
regionToWidgetTypeMap.put(Region.MENU_BAR, WidgetType.MENU_BAR);
regionToWidgetTypeMap.put(Region.MENU_ITEM, WidgetType.MENU_ITEM);
regionToWidgetTypeMap.put(Region.MENU_ITEM_ACCELERATOR,
WidgetType.MENU_ITEM_ACCELERATOR);
regionToWidgetTypeMap.put(Region.OPTION_PANE, WidgetType.OPTION_PANE);
regionToWidgetTypeMap.put(Region.PANEL, WidgetType.PANEL);
regionToWidgetTypeMap.put(Region.PASSWORD_FIELD,
WidgetType.PASSWORD_FIELD);
regionToWidgetTypeMap.put(Region.POPUP_MENU, WidgetType.POPUP_MENU);
regionToWidgetTypeMap.put(Region.POPUP_MENU_SEPARATOR,
WidgetType.POPUP_MENU_SEPARATOR);
regionToWidgetTypeMap.put(Region.PROGRESS_BAR, WidgetType.PROGRESS_BAR);
regionToWidgetTypeMap.put(Region.RADIO_BUTTON, WidgetType.RADIO_BUTTON);
regionToWidgetTypeMap.put(Region.RADIO_BUTTON_MENU_ITEM,
WidgetType.RADIO_BUTTON_MENU_ITEM);
regionToWidgetTypeMap.put(Region.ROOT_PANE, WidgetType.ROOT_PANE);
regionToWidgetTypeMap.put(Region.SCROLL_BAR, new WidgetType[] {
WidgetType.HSCROLL_BAR, WidgetType.VSCROLL_BAR});
regionToWidgetTypeMap.put(Region.SCROLL_BAR_THUMB, new WidgetType[] {
WidgetType.HSCROLL_BAR_THUMB, WidgetType.VSCROLL_BAR_THUMB});
regionToWidgetTypeMap.put(Region.SCROLL_BAR_TRACK, new WidgetType[] {
WidgetType.HSCROLL_BAR_TRACK, WidgetType.VSCROLL_BAR_TRACK});
regionToWidgetTypeMap.put(Region.SCROLL_PANE, WidgetType.SCROLL_PANE);
regionToWidgetTypeMap.put(Region.SEPARATOR, new WidgetType[] {
WidgetType.HSEPARATOR, WidgetType.VSEPARATOR});
regionToWidgetTypeMap.put(Region.SLIDER, new WidgetType[] {
WidgetType.HSLIDER, WidgetType.VSLIDER});
regionToWidgetTypeMap.put(Region.SLIDER_THUMB, new WidgetType[] {
WidgetType.HSLIDER_THUMB, WidgetType.VSLIDER_THUMB});
regionToWidgetTypeMap.put(Region.SLIDER_TRACK, new WidgetType[] {
WidgetType.HSLIDER_TRACK, WidgetType.VSLIDER_TRACK});
regionToWidgetTypeMap.put(Region.SPINNER, WidgetType.SPINNER);
regionToWidgetTypeMap.put(Region.SPLIT_PANE, WidgetType.SPLIT_PANE);
regionToWidgetTypeMap.put(Region.SPLIT_PANE_DIVIDER, new WidgetType[] {
WidgetType.HSPLIT_PANE_DIVIDER, WidgetType.VSPLIT_PANE_DIVIDER});
regionToWidgetTypeMap.put(Region.TABBED_PANE, WidgetType.TABBED_PANE);
regionToWidgetTypeMap.put(Region.TABBED_PANE_CONTENT,
WidgetType.TABBED_PANE_CONTENT);
regionToWidgetTypeMap.put(Region.TABBED_PANE_TAB,
WidgetType.TABBED_PANE_TAB);
regionToWidgetTypeMap.put(Region.TABBED_PANE_TAB_AREA,
WidgetType.TABBED_PANE_TAB_AREA);
regionToWidgetTypeMap.put(Region.TABLE, WidgetType.TABLE);
regionToWidgetTypeMap.put(Region.TABLE_HEADER, WidgetType.TABLE_HEADER);
regionToWidgetTypeMap.put(Region.TEXT_AREA, WidgetType.TEXT_AREA);
regionToWidgetTypeMap.put(Region.TEXT_FIELD, new WidgetType[] {
WidgetType.TEXT_FIELD, WidgetType.COMBO_BOX_TEXT_FIELD});
regionToWidgetTypeMap.put(Region.TEXT_PANE, WidgetType.TEXT_PANE);
regionToWidgetTypeMap.put(Region.TOGGLE_BUTTON, WidgetType.TOGGLE_BUTTON);
regionToWidgetTypeMap.put(Region.TOOL_BAR, WidgetType.TOOL_BAR);
regionToWidgetTypeMap.put(Region.TOOL_BAR_CONTENT, WidgetType.TOOL_BAR);
regionToWidgetTypeMap.put(Region.TOOL_BAR_DRAG_WINDOW,
WidgetType.TOOL_BAR_DRAG_WINDOW);
regionToWidgetTypeMap.put(Region.TOOL_BAR_SEPARATOR,
WidgetType.TOOL_BAR_SEPARATOR);
regionToWidgetTypeMap.put(Region.TOOL_TIP, WidgetType.TOOL_TIP);
regionToWidgetTypeMap.put(Region.TREE, WidgetType.TREE);
regionToWidgetTypeMap.put(Region.TREE_CELL, WidgetType.TREE_CELL);
regionToWidgetTypeMap.put(Region.VIEWPORT, WidgetType.VIEWPORT);
Object value = regionToWidgetTypeMap.get(id);
if (value instanceof WidgetType) {
return (WidgetType)value;
}
WidgetType[] widgets = (WidgetType[])value;
if (c == null ) {
return widgets[0];
}
if (c instanceof JScrollBar) {
return (((JScrollBar)c).getOrientation() == JScrollBar.HORIZONTAL) ?
widgets[0] : widgets[1];
} else if (c instanceof JSeparator) {
JSeparator separator = (JSeparator)c;
/* We should return correct WidgetType if the separator is inserted
* in Menu/PopupMenu/ToolBar. BugID: 6465603
*/
if (separator.getParent() instanceof JPopupMenu) {
return WidgetType.POPUP_MENU_SEPARATOR;
} else if (separator.getParent() instanceof JToolBar) {
return WidgetType.TOOL_BAR_SEPARATOR;
}
return (separator.getOrientation() == JSeparator.HORIZONTAL) ?
widgets[0] : widgets[1];
} else if (c instanceof JSlider) {
return (((JSlider)c).getOrientation() == JSlider.HORIZONTAL) ?
widgets[0] : widgets[1];
} else if (c instanceof JSplitPane) {
return (((JSplitPane)c).getOrientation() == JSplitPane.HORIZONTAL_SPLIT) ?
widgets[1] : widgets[0];
} else if (id == Region.LABEL || id == Region.TEXT_FIELD) {
String name = c.getName();
if (name != null && name.startsWith("ComboBox")) {
return widgets[1];
} else {
return widgets[0];
}
} else if (id == Region.FORMATTED_TEXT_FIELD) {
String name = c.getName();
if (name != null && name.startsWith("Spinner")) {
return widgets[1];
} else {
return widgets[0];
}
} else if (id == Region.ARROW_BUTTON) {
if (c.getParent() instanceof JScrollBar) {
Integer prop = (Integer)c.getClientProperty("__arrow_direction__");
int dir = (prop != null) ?
prop.intValue() : SwingConstants.WEST;
switch (dir) {
case SwingConstants.WEST:
return WidgetType.HSCROLL_BAR_BUTTON_LEFT;
case SwingConstants.EAST:
return WidgetType.HSCROLL_BAR_BUTTON_RIGHT;
case SwingConstants.NORTH:
return WidgetType.VSCROLL_BAR_BUTTON_UP;
case SwingConstants.SOUTH:
return WidgetType.VSCROLL_BAR_BUTTON_DOWN;
default:
return null;
}
} else if (c.getParent() instanceof JComboBox) {
return WidgetType.COMBO_BOX_ARROW_BUTTON;
} else {
return WidgetType.SPINNER_ARROW_BUTTON;
}
}
return null;
| private native int | nativeFinishPainting(int[] buffer, int width, int height)
| private native void | nativeStartPainting(int w, int h)
| private native java.lang.Object | native_get_gtk_setting(int property)
| private native void | native_paint_arrow(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int arrowType)
| private native void | native_paint_background(int widgetType, int state, int x, int y, int width, int height)
| private native void | native_paint_box(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int synth_state, int dir)
| private native void | native_paint_box_gap(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int gapSide, int gapX, int gapWidth)
| private native void | native_paint_check(int widgetType, int synthState, java.lang.String detail, int x, int y, int width, int height)
| private native void | native_paint_expander(int widgetType, int state, java.lang.String detail, int x, int y, int width, int height, int expanderStyle)
| private native void | native_paint_extension(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int placement)
| private native void | native_paint_flat_box(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, boolean hasFocus)
| private native void | native_paint_focus(int widgetType, int state, java.lang.String detail, int x, int y, int width, int height)
| private native void | native_paint_handle(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int orientation)
| private native void | native_paint_hline(int widgetType, int state, java.lang.String detail, int x, int y, int width, int height)
| private native void | native_paint_option(int widgetType, int synthState, java.lang.String detail, int x, int y, int width, int height)
| private native void | native_paint_shadow(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int synthState, int dir)
| private native void | native_paint_slider(int widgetType, int state, int shadowType, java.lang.String detail, int x, int y, int width, int height, int orientation)
| private native void | native_paint_vline(int widgetType, int state, java.lang.String detail, int x, int y, int width, int height)
| private native void | native_switch_theme()
| public void | paintArrow(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType direction, java.lang.String detail, int x, int y, int w, int h)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_arrow(widget, state, shadowType.ordinal(),
detail, x - x0, y - y0, w, h, direction.ordinal());
| public void | paintBackground(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, java.awt.Color color, int x, int y, int w, int h)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_background(widget, state, x - x0, y - y0, w, h);
| public void | paintBox(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h)
int gtkState =
GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int synthState = context.getComponentState();
int dir = getTextDirection(context);
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_box(widget, gtkState, shadowType.ordinal(),
detail, x - x0, y - y0, w, h, synthState, dir);
| public void | paintBoxGap(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h, com.sun.java.swing.plaf.gtk.GTKConstants.PositionType boxGapType, int tabBegin, int size)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_box_gap(widget, state, shadowType.ordinal(), detail,
x - x0, y - y0, w, h, boxGapType.ordinal(), tabBegin, size);
| public boolean | paintCachedImage(java.awt.Graphics g, int x, int y, int w, int h, java.lang.Object args)Paint a cached image identified by its size and a set of additional
arguments, if there's one.
if (w <= 0 || h <= 0) {
return true;
}
// look for cached image
Image img = cache.getImage(getClass(), null, w, h, args);
if (img != null) {
g.drawImage(img, x, y, null);
return true;
}
return false;
| public void | paintCheck(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h)
int synthState = context.getComponentState();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_check(widget, synthState, detail, x - x0, y - y0, w, h);
| public void | paintExpander(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle expanderStyle, java.lang.String detail, int x, int y, int w, int h)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_expander(widget, state, detail, x - x0, y - y0, w, h,
expanderStyle.ordinal());
| public void | paintExtension(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h, com.sun.java.swing.plaf.gtk.GTKConstants.PositionType placement, int tabIndex)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_extension(widget, state, shadowType.ordinal(), detail,
x - x0, y - y0, w, h, placement.ordinal());
| public void | paintFlatBox(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h, javax.swing.plaf.synth.ColorType colorType)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_flat_box(widget, state, shadowType.ordinal(), detail,
x - x0, y - y0, w, h,
context.getComponent().hasFocus());
| public void | paintFocus(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, java.lang.String detail, int x, int y, int w, int h)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_focus(widget, state, detail, x - x0, y - y0, w, h);
| public void | paintHandle(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h, com.sun.java.swing.plaf.gtk.GTKConstants.Orientation orientation)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_handle(widget, state, shadowType.ordinal(), detail,
x - x0, y - y0, w, h, orientation.ordinal());
| public void | paintHline(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, java.lang.String detail, int x, int y, int w, int h)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_hline(widget, state, detail, x - x0, y - y0, w, h);
| public void | paintOption(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h)
int synthState = context.getComponentState();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_option(widget, synthState, detail, x - x0, y - y0, w, h);
| public void | paintShadow(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h)
int gtkState =
GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int synthState = context.getComponentState();
int dir = getTextDirection(context);
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_shadow(widget, gtkState, shadowType.ordinal(), detail,
x - x0, y - y0, w, h, synthState, dir);
| public void | paintSlider(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType shadowType, java.lang.String detail, int x, int y, int w, int h, com.sun.java.swing.plaf.gtk.GTKConstants.Orientation orientation)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_slider(widget, state, shadowType.ordinal(), detail,
x - x0, y - y0, w, h, orientation.ordinal());
| public void | paintVline(java.awt.Graphics g, javax.swing.plaf.synth.SynthContext context, javax.swing.plaf.synth.Region id, int state, java.lang.String detail, int x, int y, int w, int h)
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_vline(widget, state, detail, x - x0, y - y0, w, h);
| public void | startPainting(java.awt.Graphics g, int x, int y, int w, int h, java.lang.Object args)
nativeStartPainting(w, h);
x0 = x;
y0 = y;
w0 = w;
h0 = h;
graphics = g;
cacheArgs = args;
| public void | themeChanged()Notify native layer of theme change, and flush cache
synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
native_switch_theme();
}
cache.flush();
|
|