jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaComboBoxPopup.java
changeset 32857 3e91092d2a15
parent 30917 511aae7fee1a
child 37714 7a0b1c7e7054
equal deleted inserted replaced
32682:6f1200d8999d 32857:3e91092d2a15
    24  */
    24  */
    25 
    25 
    26 package com.apple.laf;
    26 package com.apple.laf;
    27 
    27 
    28 import java.awt.*;
    28 import java.awt.*;
       
    29 import java.awt.Insets;
       
    30 import java.awt.Rectangle;
    29 import java.awt.event.*;
    31 import java.awt.event.*;
    30 
    32 
    31 import javax.swing.*;
    33 import javax.swing.*;
    32 import javax.swing.plaf.basic.BasicComboPopup;
    34 import javax.swing.plaf.basic.BasicComboPopup;
    33 
    35 
   193         //System.err.println("GetBestScreenBounds p: "+ p.x + ", " + p.y);
   195         //System.err.println("GetBestScreenBounds p: "+ p.x + ", " + p.y);
   194         final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   196         final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   195         final GraphicsDevice[] gs = ge.getScreenDevices();
   197         final GraphicsDevice[] gs = ge.getScreenDevices();
   196         //System.err.println("  gs.length = " + gs.length);
   198         //System.err.println("  gs.length = " + gs.length);
   197         final Rectangle comboBoxBounds = comboBox.getBounds();
   199         final Rectangle comboBoxBounds = comboBox.getBounds();
   198         if (gs.length == 1) {
       
   199             final Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
       
   200 
       
   201             //System.err.println("  scrSize: "+ scrSize);
       
   202 
       
   203             // If the combo box is totally off screen, don't show a popup
       
   204             if ((p.x + comboBoxBounds.width < 0) || (p.y + comboBoxBounds.height < 0) || (p.x > scrSize.width) || (p.y > scrSize.height)) {
       
   205                 return null;
       
   206             }
       
   207             Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(comboBox.getGraphicsConfiguration());
       
   208             return new Rectangle(0, insets.top, scrSize.width, scrSize.height - insets.top - insets.bottom);
       
   209         }
       
   210 
   200 
   211         for (final GraphicsDevice gd : gs) {
   201         for (final GraphicsDevice gd : gs) {
   212             final GraphicsConfiguration[] gc = gd.getConfigurations();
   202             final GraphicsConfiguration[] gc = gd.getConfigurations();
   213             for (final GraphicsConfiguration element0 : gc) {
   203             for (final GraphicsConfiguration element0 : gc) {
   214                 final Rectangle gcBounds = element0.getBounds();
   204                 final Rectangle gcBounds = element0.getBounds();
   215                 if (gcBounds.contains(p)) return gcBounds;
   205                 if (gcBounds.contains(p)) {
       
   206                     return getAvailableScreenArea(gcBounds, element0);
       
   207                 }
   216             }
   208             }
   217         }
   209         }
   218 
   210 
   219         // Hmm.  Origin's off screen, but is any part on?
   211         // Hmm.  Origin's off screen, but is any part on?
   220         comboBoxBounds.setLocation(p);
   212         comboBoxBounds.setLocation(p);
   221         for (final GraphicsDevice gd : gs) {
   213         for (final GraphicsDevice gd : gs) {
   222             final GraphicsConfiguration[] gc = gd.getConfigurations();
   214             final GraphicsConfiguration[] gc = gd.getConfigurations();
   223             for (final GraphicsConfiguration element0 : gc) {
   215             for (final GraphicsConfiguration element0 : gc) {
   224                 final Rectangle gcBounds = element0.getBounds();
   216                 final Rectangle gcBounds = element0.getBounds();
   225                 if (gcBounds.intersects(comboBoxBounds)) return gcBounds;
   217                 if (gcBounds.intersects(comboBoxBounds)) {
       
   218                     if (gcBounds.contains(p)) {
       
   219                         return getAvailableScreenArea(gcBounds, element0);
       
   220                     }
       
   221                 }
   226             }
   222             }
   227         }
   223         }
   228 
   224 
   229         return null;
   225         return null;
       
   226     }
       
   227 
       
   228     private Rectangle getAvailableScreenArea(Rectangle bounds,
       
   229                                              GraphicsConfiguration gc) {
       
   230         Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
       
   231         return new Rectangle(0, insets.top, bounds.width,
       
   232                 bounds.height - insets.top);
   230     }
   233     }
   231 
   234 
   232     @Override
   235     @Override
   233     protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
   236     protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
   234         final int itemCount = comboBox.getModel().getSize();
   237         final int itemCount = comboBox.getModel().getSize();