test/javax/swing/ToolTipManager/7123767/bug7123767.java

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25    @bug 7123767
  26    @summary Wrong tooltip location in Multi-Monitor configurations
  27    @author Vladislav Karnaukhov
  28    @run main bug7123767
  29 */
  30 
  31 import sun.awt.SunToolkit;
  32 
  33 import javax.swing.*;
  34 import javax.swing.plaf.metal.MetalLookAndFeel;
  35 import java.awt.*;
  36 import java.awt.event.MouseEvent;
  37 import java.lang.reflect.InvocationTargetException;
  38 
  39 public class bug7123767 extends JFrame {
  40 
  41     private static class TestFactory extends PopupFactory {
  42 
  43         private static TestFactory newFactory = new TestFactory();
  44         private static PopupFactory oldFactory;
  45 
  46         private TestFactory() {
  47             super();
  48         }
  49 
  50         public static void install() {
  51             if (oldFactory == null) {
  52                 oldFactory = getSharedInstance();


 143                 Rectangle localRect = config.getBounds();
 144                 adjustInsets(localRect, localInsets);
 145                 rect.add(localRect);
 146             }
 147         }
 148         setBounds(rect);
 149     }
 150 
 151     private static void setUp() throws InterruptedException, InvocationTargetException {
 152         SwingUtilities.invokeAndWait(new Runnable() {
 153             @Override
 154             public void run() {
 155                 frame = new bug7123767();
 156                 frame.setVisible(true);
 157             }
 158         });
 159     }
 160 
 161     // Moves mouse pointer to the corners of every GraphicsConfiguration
 162     private static void testToolTip() throws AWTException {
 163         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
 164         toolkit.realSync();


 165 
 166         GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
 167         GraphicsDevice[] devices = environment.getScreenDevices();
 168         for (GraphicsDevice device : devices) {
 169             GraphicsConfiguration[] configs = device.getConfigurations();
 170             for (GraphicsConfiguration config : configs) {
 171                 Rectangle rect = config.getBounds();
 172                 Insets insets = toolkit.getScreenInsets(config);
 173                 adjustInsets(rect, insets);
 174 
 175                 // Upper left
 176                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 177                         rect.x + MARGIN, rect.y + MARGIN);
 178                 toolkit.realSync();
 179 
 180                 // Lower left
 181                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 182                         rect.x + MARGIN, rect.y + rect.height - MARGIN);
 183                 toolkit.realSync();
 184 
 185                 // Upper right
 186                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 187                         rect.x + rect.width - MARGIN, rect.y + MARGIN);
 188                 toolkit.realSync();
 189 
 190                 // Lower right
 191                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 192                         rect.x + rect.width - MARGIN, rect.y + rect.height - MARGIN);
 193                 toolkit.realSync();
 194             }
 195         }
 196     }
 197 
 198     private static void glide(int x0, int y0, int x1, int y1) throws AWTException {
 199         if (robot == null) {
 200             robot = new Robot();
 201             robot.setAutoDelay(20);
 202         }
 203 
 204         float dmax = (float) Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0));
 205         float dx = (x1 - x0) / dmax;
 206         float dy = (y1 - y0) / dmax;
 207 
 208         robot.mouseMove(x0, y0);
 209         for (int i = 1; i <= dmax; i += 10) {
 210             robot.mouseMove((int) (x0 + dx * i), (int) (y0 + dy * i));
 211         }
 212     }
 213 


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25    @bug 7123767
  26    @summary Wrong tooltip location in Multi-Monitor configurations
  27    @author Vladislav Karnaukhov
  28    @run main bug7123767
  29 */
  30 


  31 import javax.swing.*;
  32 import javax.swing.plaf.metal.MetalLookAndFeel;
  33 import java.awt.*;
  34 import java.awt.event.MouseEvent;
  35 import java.lang.reflect.InvocationTargetException;
  36 
  37 public class bug7123767 extends JFrame {
  38 
  39     private static class TestFactory extends PopupFactory {
  40 
  41         private static TestFactory newFactory = new TestFactory();
  42         private static PopupFactory oldFactory;
  43 
  44         private TestFactory() {
  45             super();
  46         }
  47 
  48         public static void install() {
  49             if (oldFactory == null) {
  50                 oldFactory = getSharedInstance();


 141                 Rectangle localRect = config.getBounds();
 142                 adjustInsets(localRect, localInsets);
 143                 rect.add(localRect);
 144             }
 145         }
 146         setBounds(rect);
 147     }
 148 
 149     private static void setUp() throws InterruptedException, InvocationTargetException {
 150         SwingUtilities.invokeAndWait(new Runnable() {
 151             @Override
 152             public void run() {
 153                 frame = new bug7123767();
 154                 frame.setVisible(true);
 155             }
 156         });
 157     }
 158 
 159     // Moves mouse pointer to the corners of every GraphicsConfiguration
 160     private static void testToolTip() throws AWTException {
 161 
 162         robot = new Robot();
 163         robot.setAutoDelay(20);
 164         robot.waitForIdle();
 165 
 166         GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
 167         GraphicsDevice[] devices = environment.getScreenDevices();
 168         for (GraphicsDevice device : devices) {
 169             GraphicsConfiguration[] configs = device.getConfigurations();
 170             for (GraphicsConfiguration config : configs) {
 171                 Rectangle rect = config.getBounds();
 172                 Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
 173                 adjustInsets(rect, insets);
 174 
 175                 // Upper left
 176                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 177                         rect.x + MARGIN, rect.y + MARGIN);
 178                 robot.waitForIdle();
 179 
 180                 // Lower left
 181                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 182                         rect.x + MARGIN, rect.y + rect.height - MARGIN);
 183                 robot.waitForIdle();
 184 
 185                 // Upper right
 186                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 187                         rect.x + rect.width - MARGIN, rect.y + MARGIN);
 188                 robot.waitForIdle();
 189 
 190                 // Lower right
 191                 glide(rect.x + rect.width / 2, rect.y + rect.height / 2,
 192                         rect.x + rect.width - MARGIN, rect.y + rect.height - MARGIN);
 193                 robot.waitForIdle();
 194             }
 195         }
 196     }
 197 
 198     private static void glide(int x0, int y0, int x1, int y1) throws AWTException {
 199         if (robot == null) {
 200             robot = new Robot();
 201             robot.setAutoDelay(20);
 202         }
 203 
 204         float dmax = (float) Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0));
 205         float dx = (x1 - x0) / dmax;
 206         float dy = (y1 - y0) / dmax;
 207 
 208         robot.mouseMove(x0, y0);
 209         for (int i = 1; i <= dmax; i += 10) {
 210             robot.mouseMove((int) (x0 + dx * i), (int) (y0 + dy * i));
 211         }
 212     }
 213