1 /* 2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt.X11; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import java.awt.peer.TrayIconPeer; 31 import sun.awt.*; 32 33 import java.awt.image.*; 34 import java.text.BreakIterator; 35 import java.util.concurrent.ArrayBlockingQueue; 36 import java.security.AccessController; 37 import java.security.PrivilegedAction; 38 import java.lang.reflect.InvocationTargetException; 39 40 /** 41 * An utility window class. This is a base class for Tooltip and Balloon. 42 */ 43 @SuppressWarnings("serial") // JDK-implementation class 44 public abstract class InfoWindow extends Window { 45 private Container container; 46 private Closer closer; 47 48 protected InfoWindow(Frame parent, Color borderColor) { 49 super(parent); 50 setType(Window.Type.POPUP); 51 container = new Container() { 52 @Override 53 public Insets getInsets() { 54 return new Insets(1, 1, 1, 1); 55 } 56 }; 57 setLayout(new BorderLayout()); 58 setBackground(borderColor); 64 65 public Component add(Component c) { 66 container.add(c, BorderLayout.CENTER); 67 return c; 68 } 69 70 protected void setCloser(Runnable action, int time) { 71 closer.set(action, time); 72 } 73 74 // Must be executed on EDT. 75 @SuppressWarnings("deprecation") 76 protected void show(Point corner, int indent) { 77 assert SunToolkit.isDispatchThreadForAppContext(this); 78 79 pack(); 80 81 Dimension size = getSize(); 82 Rectangle scrSize = getGraphicsConfiguration().getBounds(); 83 84 if (corner.x < scrSize.width/2 && corner.y < scrSize.height/2) { // 1st square 85 setLocation(corner.x + indent, corner.y + indent); 86 87 } else if (corner.x >= scrSize.width/2 && corner.y < scrSize.height/2) { // 2nd square 88 setLocation(corner.x - indent - size.width, corner.y + indent); 89 90 } else if (corner.x < scrSize.width/2 && corner.y >= scrSize.height/2) { // 3rd square 91 setLocation(corner.x + indent, corner.y - indent - size.height); 92 93 } else if (corner.x >= scrSize.width/2 && corner.y >= scrSize.height/2) { // 4th square 94 setLocation(corner.x - indent - size.width, corner.y - indent - size.height); 95 } 96 97 super.show(); 98 closer.schedule(); 99 } 100 101 @SuppressWarnings("deprecation") 102 public void hide() { 103 closer.close(); 104 } 105 106 private class Closer implements Runnable { 107 Runnable action; 108 int time; 109 110 public void run() { 111 doClose(); 112 } 113 | 1 /* 2 * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt.X11; 27 28 import java.awt.BorderLayout; 29 import java.awt.Button; 30 import java.awt.Color; 31 import java.awt.Component; 32 import java.awt.Container; 33 import java.awt.Dimension; 34 import java.awt.Font; 35 import java.awt.Frame; 36 import java.awt.GridLayout; 37 import java.awt.Image; 38 import java.awt.Insets; 39 import java.awt.Label; 40 import java.awt.MouseInfo; 41 import java.awt.Panel; 42 import java.awt.Point; 43 import java.awt.Rectangle; 44 import java.awt.Toolkit; 45 import java.awt.Window; 46 import java.awt.event.ActionEvent; 47 import java.awt.event.ActionListener; 48 import java.awt.event.MouseAdapter; 49 import java.awt.event.MouseEvent; 50 import java.security.AccessController; 51 import java.security.PrivilegedAction; 52 import java.text.BreakIterator; 53 import java.util.concurrent.ArrayBlockingQueue; 54 55 import sun.awt.SunToolkit; 56 57 /** 58 * An utility window class. This is a base class for Tooltip and Balloon. 59 */ 60 @SuppressWarnings("serial") // JDK-implementation class 61 public abstract class InfoWindow extends Window { 62 private Container container; 63 private Closer closer; 64 65 protected InfoWindow(Frame parent, Color borderColor) { 66 super(parent); 67 setType(Window.Type.POPUP); 68 container = new Container() { 69 @Override 70 public Insets getInsets() { 71 return new Insets(1, 1, 1, 1); 72 } 73 }; 74 setLayout(new BorderLayout()); 75 setBackground(borderColor); 81 82 public Component add(Component c) { 83 container.add(c, BorderLayout.CENTER); 84 return c; 85 } 86 87 protected void setCloser(Runnable action, int time) { 88 closer.set(action, time); 89 } 90 91 // Must be executed on EDT. 92 @SuppressWarnings("deprecation") 93 protected void show(Point corner, int indent) { 94 assert SunToolkit.isDispatchThreadForAppContext(this); 95 96 pack(); 97 98 Dimension size = getSize(); 99 Rectangle scrSize = getGraphicsConfiguration().getBounds(); 100 101 if (corner.x < scrSize.x + scrSize.width/2 && corner.y < scrSize.y + scrSize.height/2) { // 1st square 102 setLocation(corner.x + indent, corner.y + indent); 103 104 } else if (corner.x >= scrSize.x + scrSize.width/2 && corner.y < scrSize.y + scrSize.height/2) { // 2nd square 105 setLocation(corner.x - indent - size.width, corner.y + indent); 106 107 } else if (corner.x < scrSize.x + scrSize.width/2 && corner.y >= scrSize.y + scrSize.height/2) { // 3rd square 108 setLocation(corner.x + indent, corner.y - indent - size.height); 109 110 } else if (corner.x >= scrSize.x +scrSize.width/2 && corner.y >= scrSize.y +scrSize.height/2) { // 4th square 111 setLocation(corner.x - indent - size.width, corner.y - indent - size.height); 112 } 113 114 super.show(); 115 closer.schedule(); 116 } 117 118 @SuppressWarnings("deprecation") 119 public void hide() { 120 closer.close(); 121 } 122 123 private class Closer implements Runnable { 124 Runnable action; 125 int time; 126 127 public void run() { 128 doClose(); 129 } 130 |