src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java

Print this page




  39 import com.sun.java.swing.plaf.gtk.GTKConstants.TextDirection;
  40 
  41 import sun.awt.image.SunWritableRaster;
  42 import sun.swing.ImageCache;
  43 
  44 /**
  45  * GTKEngine delegates all painting job to native GTK libraries.
  46  *
  47  * Painting with GTKEngine looks like this:
  48  * First, startPainting() is called. It prepares an offscreen buffer of the
  49  *   required size.
  50  * Then, any number of paintXXX() methods can be called. They effectively ignore
  51  *   the Graphics parameter and draw to the offscreen buffer.
  52  * Finally, finishPainting() should be called. It fills the data buffer passed
  53  *   in with the image data.
  54  *
  55  * @author Josh Outwater
  56  */
  57 class GTKEngine {
  58 
  59     final static GTKEngine INSTANCE = new GTKEngine();
  60 
  61     /** Size of the image cache */
  62     private static final int CACHE_SIZE = 50;
  63 
  64     /** This enum mirrors that in gtk2_interface.h */
  65     static enum WidgetType {
  66         BUTTON, CHECK_BOX, CHECK_BOX_MENU_ITEM, COLOR_CHOOSER,
  67         COMBO_BOX, COMBO_BOX_ARROW_BUTTON, COMBO_BOX_TEXT_FIELD,
  68         DESKTOP_ICON, DESKTOP_PANE, EDITOR_PANE, FORMATTED_TEXT_FIELD,
  69         HANDLE_BOX, HPROGRESS_BAR,
  70         HSCROLL_BAR, HSCROLL_BAR_BUTTON_LEFT, HSCROLL_BAR_BUTTON_RIGHT,
  71         HSCROLL_BAR_TRACK, HSCROLL_BAR_THUMB,
  72         HSEPARATOR, HSLIDER, HSLIDER_TRACK, HSLIDER_THUMB, HSPLIT_PANE_DIVIDER,
  73         INTERNAL_FRAME, INTERNAL_FRAME_TITLE_PANE, IMAGE, LABEL, LIST, MENU,
  74         MENU_BAR, MENU_ITEM, MENU_ITEM_ACCELERATOR, OPTION_PANE, PANEL,
  75         PASSWORD_FIELD, POPUP_MENU, POPUP_MENU_SEPARATOR,
  76         RADIO_BUTTON, RADIO_BUTTON_MENU_ITEM, ROOT_PANE, SCROLL_PANE,
  77         SPINNER, SPINNER_ARROW_BUTTON, SPINNER_TEXT_FIELD,
  78         SPLIT_PANE, TABBED_PANE, TABBED_PANE_TAB_AREA, TABBED_PANE_CONTENT,
  79         TABBED_PANE_TAB, TABLE, TABLE_HEADER, TEXT_AREA, TEXT_FIELD, TEXT_PANE,


 506         native_paint_slider(widget, state, shadowType.ordinal(), detail,
 507                             x - x0, y - y0, w, h, orientation.ordinal());
 508     }
 509 
 510     public void paintVline(Graphics g, SynthContext context,
 511             Region id, int state, String detail, int x, int y, int w, int h) {
 512 
 513         state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
 514         int widget = getWidgetType(context.getComponent(), id).ordinal();
 515         native_paint_vline(widget, state, detail, x - x0, y - y0, w, h);
 516     }
 517 
 518     public void paintBackground(Graphics g, SynthContext context,
 519             Region id, int state, Color color, int x, int y, int w, int h) {
 520 
 521         state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
 522         int widget = getWidgetType(context.getComponent(), id).ordinal();
 523         native_paint_background(widget, state, x - x0, y - y0, w, h);
 524     }
 525 
 526     private final static ColorModel[] COLOR_MODELS = {
 527         // Transparency.OPAQUE
 528         new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000),
 529         // Transparency.BITMASK
 530         new DirectColorModel(25, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000),
 531         // Transparency.TRANSLUCENT
 532         ColorModel.getRGBdefault(),
 533     };
 534 
 535     private final static int[][] BAND_OFFSETS = {
 536         { 0x00ff0000, 0x0000ff00, 0x000000ff },             // OPAQUE
 537         { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000 }, // BITMASK
 538         { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }  // TRANSLUCENT
 539     };
 540 
 541 
 542     /**
 543      * Paint a cached image identified by its size and a set of additional
 544      * arguments, if there's one.
 545      *
 546      * @return true if a cached image has been painted, false otherwise
 547      */
 548     public boolean paintCachedImage(Graphics g,
 549             int x, int y, int w, int h, Object... args) {
 550         if (w <= 0 || h <= 0) {
 551             return true;
 552         }
 553 
 554         // look for cached image
 555         Image img = cache.getImage(getClass(), null, w, h, args);




  39 import com.sun.java.swing.plaf.gtk.GTKConstants.TextDirection;
  40 
  41 import sun.awt.image.SunWritableRaster;
  42 import sun.swing.ImageCache;
  43 
  44 /**
  45  * GTKEngine delegates all painting job to native GTK libraries.
  46  *
  47  * Painting with GTKEngine looks like this:
  48  * First, startPainting() is called. It prepares an offscreen buffer of the
  49  *   required size.
  50  * Then, any number of paintXXX() methods can be called. They effectively ignore
  51  *   the Graphics parameter and draw to the offscreen buffer.
  52  * Finally, finishPainting() should be called. It fills the data buffer passed
  53  *   in with the image data.
  54  *
  55  * @author Josh Outwater
  56  */
  57 class GTKEngine {
  58 
  59     static final GTKEngine INSTANCE = new GTKEngine();
  60 
  61     /** Size of the image cache */
  62     private static final int CACHE_SIZE = 50;
  63 
  64     /** This enum mirrors that in gtk2_interface.h */
  65     static enum WidgetType {
  66         BUTTON, CHECK_BOX, CHECK_BOX_MENU_ITEM, COLOR_CHOOSER,
  67         COMBO_BOX, COMBO_BOX_ARROW_BUTTON, COMBO_BOX_TEXT_FIELD,
  68         DESKTOP_ICON, DESKTOP_PANE, EDITOR_PANE, FORMATTED_TEXT_FIELD,
  69         HANDLE_BOX, HPROGRESS_BAR,
  70         HSCROLL_BAR, HSCROLL_BAR_BUTTON_LEFT, HSCROLL_BAR_BUTTON_RIGHT,
  71         HSCROLL_BAR_TRACK, HSCROLL_BAR_THUMB,
  72         HSEPARATOR, HSLIDER, HSLIDER_TRACK, HSLIDER_THUMB, HSPLIT_PANE_DIVIDER,
  73         INTERNAL_FRAME, INTERNAL_FRAME_TITLE_PANE, IMAGE, LABEL, LIST, MENU,
  74         MENU_BAR, MENU_ITEM, MENU_ITEM_ACCELERATOR, OPTION_PANE, PANEL,
  75         PASSWORD_FIELD, POPUP_MENU, POPUP_MENU_SEPARATOR,
  76         RADIO_BUTTON, RADIO_BUTTON_MENU_ITEM, ROOT_PANE, SCROLL_PANE,
  77         SPINNER, SPINNER_ARROW_BUTTON, SPINNER_TEXT_FIELD,
  78         SPLIT_PANE, TABBED_PANE, TABBED_PANE_TAB_AREA, TABBED_PANE_CONTENT,
  79         TABBED_PANE_TAB, TABLE, TABLE_HEADER, TEXT_AREA, TEXT_FIELD, TEXT_PANE,


 506         native_paint_slider(widget, state, shadowType.ordinal(), detail,
 507                             x - x0, y - y0, w, h, orientation.ordinal());
 508     }
 509 
 510     public void paintVline(Graphics g, SynthContext context,
 511             Region id, int state, String detail, int x, int y, int w, int h) {
 512 
 513         state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
 514         int widget = getWidgetType(context.getComponent(), id).ordinal();
 515         native_paint_vline(widget, state, detail, x - x0, y - y0, w, h);
 516     }
 517 
 518     public void paintBackground(Graphics g, SynthContext context,
 519             Region id, int state, Color color, int x, int y, int w, int h) {
 520 
 521         state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
 522         int widget = getWidgetType(context.getComponent(), id).ordinal();
 523         native_paint_background(widget, state, x - x0, y - y0, w, h);
 524     }
 525 
 526     private static final ColorModel[] COLOR_MODELS = {
 527         // Transparency.OPAQUE
 528         new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000),
 529         // Transparency.BITMASK
 530         new DirectColorModel(25, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000),
 531         // Transparency.TRANSLUCENT
 532         ColorModel.getRGBdefault(),
 533     };
 534 
 535     private static final int[][] BAND_OFFSETS = {
 536         { 0x00ff0000, 0x0000ff00, 0x000000ff },             // OPAQUE
 537         { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000 }, // BITMASK
 538         { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }  // TRANSLUCENT
 539     };
 540 
 541 
 542     /**
 543      * Paint a cached image identified by its size and a set of additional
 544      * arguments, if there's one.
 545      *
 546      * @return true if a cached image has been painted, false otherwise
 547      */
 548     public boolean paintCachedImage(Graphics g,
 549             int x, int y, int w, int h, Object... args) {
 550         if (w <= 0 || h <= 0) {
 551             return true;
 552         }
 553 
 554         // look for cached image
 555         Image img = cache.getImage(getClass(), null, w, h, args);