8160160: The menu displayed nothing with the option"-server -d64 -Xmixed -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
authorssadetsky
Tue, 27 Sep 2016 09:55:45 +0300
changeset 41399 367e803499c1
parent 41398 1f7d85a74c12
child 41400 71893f19fd7f
8160160: The menu displayed nothing with the option"-server -d64 -Xmixed -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel". Reviewed-by: alexsch, serb
jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java
jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java	Mon Sep 26 13:15:37 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java	Tue Sep 27 09:55:45 2016 +0300
@@ -586,8 +586,8 @@
      * Convenience method that delegates to finishPainting() with
      * caching enabled.
      */
-    public void finishPainting() {
-        finishPainting(true);
+    public BufferedImage finishPainting() {
+        return finishPainting(true);
     }
 
     /**
@@ -595,7 +595,7 @@
      * BufferedImage from the offscreen buffer, (optionally) cache it,
      * and paint it.
      */
-    public void finishPainting(boolean useCache) {
+    public BufferedImage finishPainting(boolean useCache) {
         DataBufferInt dataBuffer = new DataBufferInt(w0 * h0);
         // Note that stealData() requires a markDirty() afterwards
         // since we modify the data in it.
@@ -609,11 +609,12 @@
                 dataBuffer, w0, h0, w0, bands, null);
 
         ColorModel cm = COLOR_MODELS[transparency - 1];
-        Image img = new BufferedImage(cm, raster, false, null);
+        BufferedImage img = new BufferedImage(cm, raster, false, null);
         if (useCache) {
             cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
         }
         graphics.drawImage(img, x0, y0, null);
+        return img;
     }
 
     /**
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Mon Sep 26 13:15:37 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Tue Sep 27 09:55:45 2016 +0300
@@ -24,6 +24,8 @@
  */
 package com.sun.java.swing.plaf.gtk;
 
+import sun.awt.ModalExclude;
+import sun.awt.SunToolkit;
 import sun.awt.UNIXToolkit;
 
 import javax.swing.plaf.synth.*;
@@ -36,6 +38,7 @@
 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 java.awt.image.BufferedImage;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
@@ -567,8 +570,10 @@
         Region id = context.getRegion();
         int gtkState = GTKLookAndFeel.synthStateToGTKState(
                 id, context.getComponentState());
+        boolean isHW = SunToolkit.getHeavyweightComponent(
+                context.getComponent()) instanceof ModalExclude;
         synchronized (UNIXToolkit.GTK_LOCK) {
-            if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
+            if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, isHW)) {
                 return;
             }
             ENGINE.startPainting(g, x, y, w, h, id, gtkState);
@@ -581,7 +586,25 @@
                 style.getGTKColor(context, gtkState, GTKColorType.BACKGROUND),
                 x + insets.left, y + insets.top, w - insets.left - insets.right,
                 h - insets.top - insets.bottom);
-            ENGINE.finishPainting();
+            BufferedImage img = ENGINE.finishPainting();
+            if(!isHW) {
+                int border = img.getRGB(0, h / 2);
+                if (img != null && border == img.getRGB(w / 2, h / 2)) {
+                    // fix no menu borders in Adwaita theme
+                    Graphics g2 = img.getGraphics();
+                    Color c = new Color(border);
+                    g2.setColor(new Color(Math.max((int) (c.getRed() * 0.8), 0),
+                            Math.max((int) (c.getGreen() * 0.8), 0),
+                            Math.max((int) (c.getBlue() * 0.8), 0)));
+                    g2.drawLine(0, 0, w - 1, 0);
+                    g2.drawLine(w - 1, 0, w - 1, h - 1);
+                    g2.drawLine(0, h - 1, 0, 1);
+                    g2.setColor(c.darker());
+                    g2.drawLine(w - 1, h - 1, 0, h - 1);
+                    g2.dispose();
+                    g.drawImage(img, x, y, null);
+                }
+            }
         }
     }