gtknativeengine.java
来自「JAVA 所有包」· Java 代码 · 共 487 行 · 第 1/2 页
JAVA
487 行
/* * @(#)GTKNativeEngine.java 1.9 06/11/30 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import javax.swing.plaf.synth.*;import java.awt.*;import java.awt.image.*;import javax.swing.*;import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType;import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;import javax.imageio.*;import java.io.*;import java.util.HashMap;import sun.awt.image.SunWritableRaster;import sun.swing.ImageCache;/** * 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. * * @version 1.9, 11/30/06 * @author Josh Outwater */public class GTKNativeEngine extends GTKEngine { /** Size of the image cache */ private static final int CACHE_SIZE = 50; /** This enum mirrors that in gtk2_interface.h */ static enum WidgetType { ARROW_BUTTON, BUTTON, CHECK_BOX, CHECK_BOX_MENU_ITEM, COLOR_CHOOSER, COMBO_BOX, DESKTOP_ICON, DESKTOP_PANE, EDITOR_PANE, FORMATTED_TEXT_FIELD, HANDLE_BOX, HSCROLL_BAR, HSCROLL_BAR_TRACK, HSCROLL_BAR_THUMB, HSEPARATOR, HSLIDER, HSLIDER_TRACK, HSLIDER_THUMB, HSPLIT_PANE_DIVIDER, INTERNAL_FRAME, INTERNAL_FRAME_TITLE_PANE, IMAGE, LABEL, LIST, MENU, MENU_BAR, MENU_ITEM, MENU_ITEM_ACCELERATOR, OPTION_PANE, PANEL, PASSWORD_FIELD, POPUP_MENU, POPUP_MENU_SEPARATOR, PROGRESS_BAR, RADIO_BUTTON, RADIO_BUTTON_MENU_ITEM, ROOT_PANE, SCROLL_PANE, SPINNER, SPLIT_PANE, TABBED_PANE, TABBED_PANE_TAB_AREA, TABBED_PANE_CONTENT, TABBED_PANE_TAB, TABLE, TABLE_HEADER, TEXT_AREA, TEXT_FIELD, TEXT_PANE, TOGGLE_BUTTON, TOOL_BAR, TOOL_BAR_DRAG_WINDOW, TOOL_BAR_SEPARATOR, TOOL_TIP, TREE, TREE_CELL, VIEWPORT, VSCROLL_BAR, VSCROLL_BAR_TRACK, VSCROLL_BAR_THUMB, VSEPARATOR, VSLIDER, VSLIDER_TRACK, VSLIDER_THUMB, VSPLIT_PANE_DIVIDER } private static HashMap regionToWidgetTypeMap; private ImageCache cache = new ImageCache(CACHE_SIZE); private int x0, y0, w0, h0; private Graphics graphics; private Object[] cacheArgs; private native void native_paint_arrow( int widgetType, int state, int shadowType, String detail, int x, int y, int width, int height, int arrowType); private native void native_paint_box( int widgetType, int state, int shadowType, String detail, int x, int y, int width, int height, int synth_state); private native void native_paint_box_gap( int widgetType, int state, int shadowType, 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, String detail, int x, int y, int width, int height); private native void native_paint_expander( int widgetType, int state, String detail, int x, int y, int width, int height, int expanderStyle); private native void native_paint_extension( int widgetType, int state, int shadowType, 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, String detail, int x, int y, int width, int height, boolean hasFocus); private native void native_paint_focus( int widgetType, int state, String detail, int x, int y, int width, int height); private native void native_paint_handle( int widgetType, int state, int shadowType, String detail, int x, int y, int width, int height, int orientation); private native void native_paint_hline( int widgetType, int state, String detail, int x, int y, int width, int height); private native void native_paint_option( int widgetType, int synthState, String detail, int x, int y, int width, int height); private native void native_paint_shadow( int widgetType, int state, int shadowType, String detail, int x, int y, int width, int height); private native void native_paint_slider( int widgetType, int state, int shadowType, String detail, int x, int y, int width, int height, int orientation); private native void native_paint_vline( int widgetType, int state, String detail, int x, int y, int width, int height); private native void native_paint_background( int widgetType, int state, int x, int y, int width, int height); private native Object native_get_gtk_setting(int property); private native void nativeStartPainting(int w, int h); private native int nativeFinishPainting(int[] buffer, int width, int height); private native void native_switch_theme(); static { // 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, WidgetType.ARROW_BUTTON); 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, WidgetType.FORMATTED_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, WidgetType.LABEL); 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, WidgetType.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); } /** Translate Region and JComponent into WidgetType ordinals */ static WidgetType getWidgetType(JComponent c, Region id) { 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 (c.getParent() instanceof JScrollBar) { JScrollBar sb = (JScrollBar)c.getParent();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?