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 import java.awt.image.*;
33 import java.text.BreakIterator;
34 import java.util.concurrent.ArrayBlockingQueue;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import java.lang.reflect.InvocationTargetException;
38
39 /**
40 * An utility window class. This is a base class for Tooltip and Balloon.
41 */
42 public abstract class InfoWindow extends Window {
43 private Container container;
44 private Closer closer;
45
46 protected InfoWindow(Frame parent, Color borderColor) {
47 super(parent);
48 setType(Window.Type.POPUP);
49 container = new Container() {
50 @Override
51 public Insets getInsets() {
52 return new Insets(1, 1, 1, 1);
53 }
54 };
55 setLayout(new BorderLayout());
56 setBackground(borderColor);
57 add(container, BorderLayout.CENTER);
58 container.setLayout(new BorderLayout());
59
60 closer = new Closer();
61 }
129 public void run() {
130 InfoWindow.super.hide();
131 invalidate();
132 if (action != null) {
133 action.run();
134 }
135 }
136 });
137 }
138 }
139
140
141 private interface LiveArguments {
142 /** Whether the target of the InfoWindow is disposed. */
143 boolean isDisposed();
144
145 /** The bounds of the target of the InfoWindow. */
146 Rectangle getBounds();
147 }
148
149 public static class Tooltip extends InfoWindow {
150
151 public interface LiveArguments extends InfoWindow.LiveArguments {
152 /** The tooltip to be displayed. */
153 String getTooltipString();
154 }
155
156 private final Object target;
157 private final LiveArguments liveArguments;
158
159 private final Label textLabel = new Label("");
160 private final Runnable starter = new Runnable() {
161 public void run() {
162 display();
163 }};
164
165 private final static int TOOLTIP_SHOW_TIME = 10000;
166 private final static int TOOLTIP_START_DELAY_TIME = 1000;
167 private final static int TOOLTIP_MAX_LENGTH = 64;
168 private final static int TOOLTIP_MOUSE_CURSOR_INDENT = 5;
222 }
223
224 public void enter() {
225 XToolkit.schedule(starter, TOOLTIP_START_DELAY_TIME);
226 }
227
228 public void exit() {
229 XToolkit.remove(starter);
230 if (isVisible()) {
231 hide();
232 }
233 }
234
235 private boolean isPointerOverTrayIcon(Rectangle trayRect) {
236 Point p = MouseInfo.getPointerInfo().getLocation();
237 return !(p.x < trayRect.x || p.x > (trayRect.x + trayRect.width) ||
238 p.y < trayRect.y || p.y > (trayRect.y + trayRect.height));
239 }
240 }
241
242 public static class Balloon extends InfoWindow {
243
244 public interface LiveArguments extends InfoWindow.LiveArguments {
245 /** The action to be performed upon clicking the baloon. */
246 String getActionCommand();
247 }
248
249 private final LiveArguments liveArguments;
250 private final Object target;
251
252 private final static int BALLOON_SHOW_TIME = 10000;
253 private final static int BALLOON_TEXT_MAX_LENGTH = 256;
254 private final static int BALLOON_WORD_LINE_MAX_LENGTH = 16;
255 private final static int BALLOON_WORD_LINE_MAX_COUNT = 4;
256 private final static int BALLOON_ICON_WIDTH = 32;
257 private final static int BALLOON_ICON_HEIGHT = 32;
258 private final static int BALLOON_TRAY_ICON_INDENT = 0;
259 private final static Color BALLOON_CAPTION_BACKGROUND_COLOR = new Color(200, 200 ,255);
260 private final static Font BALLOON_CAPTION_FONT = new Font(Font.DIALOG, Font.BOLD, 12);
261
|
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 import java.awt.image.*;
33 import java.text.BreakIterator;
34 import java.util.concurrent.ArrayBlockingQueue;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import java.lang.reflect.InvocationTargetException;
38
39 /**
40 * An utility window class. This is a base class for Tooltip and Balloon.
41 */
42 @SuppressWarnings("serial") // JDK-implementation class
43 public abstract class InfoWindow extends Window {
44 private Container container;
45 private Closer closer;
46
47 protected InfoWindow(Frame parent, Color borderColor) {
48 super(parent);
49 setType(Window.Type.POPUP);
50 container = new Container() {
51 @Override
52 public Insets getInsets() {
53 return new Insets(1, 1, 1, 1);
54 }
55 };
56 setLayout(new BorderLayout());
57 setBackground(borderColor);
58 add(container, BorderLayout.CENTER);
59 container.setLayout(new BorderLayout());
60
61 closer = new Closer();
62 }
130 public void run() {
131 InfoWindow.super.hide();
132 invalidate();
133 if (action != null) {
134 action.run();
135 }
136 }
137 });
138 }
139 }
140
141
142 private interface LiveArguments {
143 /** Whether the target of the InfoWindow is disposed. */
144 boolean isDisposed();
145
146 /** The bounds of the target of the InfoWindow. */
147 Rectangle getBounds();
148 }
149
150 @SuppressWarnings("serial") // JDK-implementation class
151 public static class Tooltip extends InfoWindow {
152
153 public interface LiveArguments extends InfoWindow.LiveArguments {
154 /** The tooltip to be displayed. */
155 String getTooltipString();
156 }
157
158 private final Object target;
159 private final LiveArguments liveArguments;
160
161 private final Label textLabel = new Label("");
162 private final Runnable starter = new Runnable() {
163 public void run() {
164 display();
165 }};
166
167 private final static int TOOLTIP_SHOW_TIME = 10000;
168 private final static int TOOLTIP_START_DELAY_TIME = 1000;
169 private final static int TOOLTIP_MAX_LENGTH = 64;
170 private final static int TOOLTIP_MOUSE_CURSOR_INDENT = 5;
224 }
225
226 public void enter() {
227 XToolkit.schedule(starter, TOOLTIP_START_DELAY_TIME);
228 }
229
230 public void exit() {
231 XToolkit.remove(starter);
232 if (isVisible()) {
233 hide();
234 }
235 }
236
237 private boolean isPointerOverTrayIcon(Rectangle trayRect) {
238 Point p = MouseInfo.getPointerInfo().getLocation();
239 return !(p.x < trayRect.x || p.x > (trayRect.x + trayRect.width) ||
240 p.y < trayRect.y || p.y > (trayRect.y + trayRect.height));
241 }
242 }
243
244 @SuppressWarnings("serial") // JDK-implementation class
245 public static class Balloon extends InfoWindow {
246
247 public interface LiveArguments extends InfoWindow.LiveArguments {
248 /** The action to be performed upon clicking the baloon. */
249 String getActionCommand();
250 }
251
252 private final LiveArguments liveArguments;
253 private final Object target;
254
255 private final static int BALLOON_SHOW_TIME = 10000;
256 private final static int BALLOON_TEXT_MAX_LENGTH = 256;
257 private final static int BALLOON_WORD_LINE_MAX_LENGTH = 16;
258 private final static int BALLOON_WORD_LINE_MAX_COUNT = 4;
259 private final static int BALLOON_ICON_WIDTH = 32;
260 private final static int BALLOON_ICON_HEIGHT = 32;
261 private final static int BALLOON_TRAY_ICON_INDENT = 0;
262 private final static Color BALLOON_CAPTION_BACKGROUND_COLOR = new Color(200, 200 ,255);
263 private final static Font BALLOON_CAPTION_FONT = new Font(Font.DIALOG, Font.BOLD, 12);
264
|