开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from Stefan/Java8Source
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
develop
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (2)
master
develop
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
develop
Java8Source
/
src
/
java
/
awt
/
TrayIcon.java
Java8Source
/
src
/
java
/
awt
/
TrayIcon.java
TrayIcon.java 26.26 KB
一键复制 编辑 原始数据 按行查看 历史
Stefan 提交于 2020年08月11日 23:17 +08:00 . 初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.awt;
import java.awt.event.*;
import java.awt.peer.TrayIconPeer;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import sun.awt.AWTAccessor;
import sun.awt.HeadlessToolkit;
import java.util.EventObject;
import java.security.AccessControlContext;
import java.security.AccessController;
/**
* A <code>TrayIcon</code> object represents a tray icon that can be
* added to the {@link SystemTray system tray}. A
* <code>TrayIcon</code> can have a tooltip (text), an image, a popup
* menu, and a set of listeners associated with it.
*
* <p>A <code>TrayIcon</code> can generate various {@link MouseEvent
* MouseEvents} and supports adding corresponding listeners to receive
* notification of these events. <code>TrayIcon</code> processes some
* of the events by itself. For example, by default, when the
* right-mouse click is performed on the <code>TrayIcon</code> it
* displays the specified popup menu. When the mouse hovers
* over the <code>TrayIcon</code> the tooltip is displayed.
*
* <p><strong>Note:</strong> When the <code>MouseEvent</code> is
* dispatched to its registered listeners its <code>component</code>
* property will be set to <code>null</code>. (See {@link
* java.awt.event.ComponentEvent#getComponent}) The
* <code>source</code> property will be set to this
* <code>TrayIcon</code>. (See {@link
* java.util.EventObject#getSource})
*
* <p><b>Note:</b> A well-behaved {@link TrayIcon} implementation
* will assign different gestures to showing a popup menu and
* selecting a tray icon.
*
* <p>A <code>TrayIcon</code> can generate an {@link ActionEvent
* ActionEvent}. On some platforms, this occurs when the user selects
* the tray icon using either the mouse or keyboard.
*
* <p>If a SecurityManager is installed, the AWTPermission
* {@code accessSystemTray} must be granted in order to create
* a {@code TrayIcon}. Otherwise the constructor will throw a
* SecurityException.
*
* <p> See the {@link SystemTray} class overview for an example on how
* to use the <code>TrayIcon</code> API.
*
* @since 1.6
* @see SystemTray#add
* @see java.awt.event.ComponentEvent#getComponent
* @see java.util.EventObject#getSource
*
* @author Bino George
* @author Denis Mikhalkin
* @author Sharon Zakhour
* @author Anton Tarasov
*/
public class TrayIcon {
private Image image;
private String tooltip;
private PopupMenu popup;
private boolean autosize;
private int id;
private String actionCommand;
transient private TrayIconPeer peer;
transient MouseListener mouseListener;
transient MouseMotionListener mouseMotionListener;
transient ActionListener actionListener;
/*
* The tray icon's AccessControlContext.
*
* Unlike the acc in Component, this field is made final
* because TrayIcon is not serializable.
*/
private final AccessControlContext acc = AccessController.getContext();
/*
* Returns the acc this tray icon was constructed with.
*/
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException("TrayIcon is missing AccessControlContext");
}
return acc;
}
static {
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
AWTAccessor.setTrayIconAccessor(
new AWTAccessor.TrayIconAccessor() {
public void addNotify(TrayIcon trayIcon) throws AWTException {
trayIcon.addNotify();
}
public void removeNotify(TrayIcon trayIcon) {
trayIcon.removeNotify();
}
});
}
private TrayIcon()
throws UnsupportedOperationException, HeadlessException, SecurityException
{
SystemTray.checkSystemTrayAllowed();
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
if (!SystemTray.isSupported()) {
throw new UnsupportedOperationException();
}
SunToolkit.insertTargetMapping(this, AppContext.getAppContext());
}
/**
* Creates a <code>TrayIcon</code> with the specified image.
*
* @param image the <code>Image</code> to be used
* @throws IllegalArgumentException if <code>image</code> is
* <code>null</code>
* @throws UnsupportedOperationException if the system tray isn't
* supported by the current platform
* @throws HeadlessException if
* {@code GraphicsEnvironment.isHeadless()} returns {@code true}
* @throws SecurityException if {@code accessSystemTray} permission
* is not granted
* @see SystemTray#add(TrayIcon)
* @see TrayIcon#TrayIcon(Image, String, PopupMenu)
* @see TrayIcon#TrayIcon(Image, String)
* @see SecurityManager#checkPermission
* @see AWTPermission
*/
public TrayIcon(Image image) {
this();
if (image == null) {
throw new IllegalArgumentException("creating TrayIcon with null Image");
}
setImage(image);
}
/**
* Creates a <code>TrayIcon</code> with the specified image and
* tooltip text.
*
* @param image the <code>Image</code> to be used
* @param tooltip the string to be used as tooltip text; if the
* value is <code>null</code> no tooltip is shown
* @throws IllegalArgumentException if <code>image</code> is
* <code>null</code>
* @throws UnsupportedOperationException if the system tray isn't
* supported by the current platform
* @throws HeadlessException if
* {@code GraphicsEnvironment.isHeadless()} returns {@code true}
* @throws SecurityException if {@code accessSystemTray} permission
* is not granted
* @see SystemTray#add(TrayIcon)
* @see TrayIcon#TrayIcon(Image)
* @see TrayIcon#TrayIcon(Image, String, PopupMenu)
* @see SecurityManager#checkPermission
* @see AWTPermission
*/
public TrayIcon(Image image, String tooltip) {
this(image);
setToolTip(tooltip);
}
/**
* Creates a <code>TrayIcon</code> with the specified image,
* tooltip and popup menu.
*
* @param image the <code>Image</code> to be used
* @param tooltip the string to be used as tooltip text; if the
* value is <code>null</code> no tooltip is shown
* @param popup the menu to be used for the tray icon's popup
* menu; if the value is <code>null</code> no popup menu is shown
* @throws IllegalArgumentException if <code>image</code> is <code>null</code>
* @throws UnsupportedOperationException if the system tray isn't
* supported by the current platform
* @throws HeadlessException if
* {@code GraphicsEnvironment.isHeadless()} returns {@code true}
* @throws SecurityException if {@code accessSystemTray} permission
* is not granted
* @see SystemTray#add(TrayIcon)
* @see TrayIcon#TrayIcon(Image, String)
* @see TrayIcon#TrayIcon(Image)
* @see PopupMenu
* @see MouseListener
* @see #addMouseListener(MouseListener)
* @see SecurityManager#checkPermission
* @see AWTPermission
*/
public TrayIcon(Image image, String tooltip, PopupMenu popup) {
this(image, tooltip);
setPopupMenu(popup);
}
/**
* Sets the image for this <code>TrayIcon</code>. The previous
* tray icon image is discarded without calling the {@link
* java.awt.Image#flush} method &#151; you will need to call it
* manually.
*
* <p> If the image represents an animated image, it will be
* animated automatically.
*
* <p> See the {@link #setImageAutoSize(boolean)} property for
* details on the size of the displayed image.
*
* <p> Calling this method with the same image that is currently
* being used has no effect.
*
* @throws NullPointerException if <code>image</code> is <code>null</code>
* @param image the non-null <code>Image</code> to be used
* @see #getImage
* @see Image
* @see SystemTray#add(TrayIcon)
* @see TrayIcon#TrayIcon(Image, String)
*/
public void setImage(Image image) {
if (image == null) {
throw new NullPointerException("setting null Image");
}
this.image = image;
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.updateImage();
}
}
/**
* Returns the current image used for this <code>TrayIcon</code>.
*
* @return the image
* @see #setImage(Image)
* @see Image
*/
public Image getImage() {
return image;
}
/**
* Sets the popup menu for this <code>TrayIcon</code>. If
* <code>popup</code> is <code>null</code>, no popup menu will be
* associated with this <code>TrayIcon</code>.
*
* <p>Note that this <code>popup</code> must not be added to any
* parent before or after it is set on the tray icon. If you add
* it to some parent, the <code>popup</code> may be removed from
* that parent.
*
* <p>The {@code popup} can be set on one {@code TrayIcon} only.
* Setting the same popup on multiple {@code TrayIcon}s will cause
* an {@code IllegalArgumentException}.
*
* <p><strong>Note:</strong> Some platforms may not support
* showing the user-specified popup menu component when the user
* right-clicks the tray icon. In this situation, either no menu
* will be displayed or, on some systems, a native version of the
* menu may be displayed.
*
* @throws IllegalArgumentException if the {@code popup} is already
* set for another {@code TrayIcon}
* @param popup a <code>PopupMenu</code> or <code>null</code> to
* remove any popup menu
* @see #getPopupMenu
*/
public void setPopupMenu(PopupMenu popup) {
if (popup == this.popup) {
return;
}
synchronized (TrayIcon.class) {
if (popup != null) {
if (popup.isTrayIconPopup) {
throw new IllegalArgumentException("the PopupMenu is already set for another TrayIcon");
}
popup.isTrayIconPopup = true;
}
if (this.popup != null) {
this.popup.isTrayIconPopup = false;
}
this.popup = popup;
}
}
/**
* Returns the popup menu associated with this <code>TrayIcon</code>.
*
* @return the popup menu or <code>null</code> if none exists
* @see #setPopupMenu(PopupMenu)
*/
public PopupMenu getPopupMenu() {
return popup;
}
/**
* Sets the tooltip string for this <code>TrayIcon</code>. The
* tooltip is displayed automatically when the mouse hovers over
* the icon. Setting the tooltip to <code>null</code> removes any
* tooltip text.
*
* When displayed, the tooltip string may be truncated on some platforms;
* the number of characters that may be displayed is platform-dependent.
*
* @param tooltip the string for the tooltip; if the value is
* <code>null</code> no tooltip is shown
* @see #getToolTip
*/
public void setToolTip(String tooltip) {
this.tooltip = tooltip;
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.setToolTip(tooltip);
}
}
/**
* Returns the tooltip string associated with this
* <code>TrayIcon</code>.
*
* @return the tooltip string or <code>null</code> if none exists
* @see #setToolTip(String)
*/
public String getToolTip() {
return tooltip;
}
/**
* Sets the auto-size property. Auto-size determines whether the
* tray image is automatically sized to fit the space allocated
* for the image on the tray. By default, the auto-size property
* is set to <code>false</code>.
*
* <p> If auto-size is <code>false</code>, and the image size
* doesn't match the tray icon space, the image is painted as-is
* inside that space &#151; if larger than the allocated space, it will
* be cropped.
*
* <p> If auto-size is <code>true</code>, the image is stretched or shrunk to
* fit the tray icon space.
*
* @param autosize <code>true</code> to auto-size the image,
* <code>false</code> otherwise
* @see #isImageAutoSize
*/
public void setImageAutoSize(boolean autosize) {
this.autosize = autosize;
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.updateImage();
}
}
/**
* Returns the value of the auto-size property.
*
* @return <code>true</code> if the image will be auto-sized,
* <code>false</code> otherwise
* @see #setImageAutoSize(boolean)
*/
public boolean isImageAutoSize() {
return autosize;
}
/**
* Adds the specified mouse listener to receive mouse events from
* this <code>TrayIcon</code>. Calling this method with a
* <code>null</code> value has no effect.
*
* <p><b>Note</b>: The {@code MouseEvent}'s coordinates (received
* from the {@code TrayIcon}) are relative to the screen, not the
* {@code TrayIcon}.
*
* <p> <b>Note: </b>The <code>MOUSE_ENTERED</code> and
* <code>MOUSE_EXITED</code> mouse events are not supported.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param listener the mouse listener
* @see java.awt.event.MouseEvent
* @see java.awt.event.MouseListener
* @see #removeMouseListener(MouseListener)
* @see #getMouseListeners
*/
public synchronized void addMouseListener(MouseListener listener) {
if (listener == null) {
return;
}
mouseListener = AWTEventMulticaster.add(mouseListener, listener);
}
/**
* Removes the specified mouse listener. Calling this method with
* <code>null</code> or an invalid value has no effect.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param listener the mouse listener
* @see java.awt.event.MouseEvent
* @see java.awt.event.MouseListener
* @see #addMouseListener(MouseListener)
* @see #getMouseListeners
*/
public synchronized void removeMouseListener(MouseListener listener) {
if (listener == null) {
return;
}
mouseListener = AWTEventMulticaster.remove(mouseListener, listener);
}
/**
* Returns an array of all the mouse listeners
* registered on this <code>TrayIcon</code>.
*
* @return all of the <code>MouseListeners</code> registered on
* this <code>TrayIcon</code> or an empty array if no mouse
* listeners are currently registered
*
* @see #addMouseListener(MouseListener)
* @see #removeMouseListener(MouseListener)
* @see java.awt.event.MouseListener
*/
public synchronized MouseListener[] getMouseListeners() {
return AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
}
/**
* Adds the specified mouse listener to receive mouse-motion
* events from this <code>TrayIcon</code>. Calling this method
* with a <code>null</code> value has no effect.
*
* <p><b>Note</b>: The {@code MouseEvent}'s coordinates (received
* from the {@code TrayIcon}) are relative to the screen, not the
* {@code TrayIcon}.
*
* <p> <b>Note: </b>The <code>MOUSE_DRAGGED</code> mouse event is not supported.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param listener the mouse listener
* @see java.awt.event.MouseEvent
* @see java.awt.event.MouseMotionListener
* @see #removeMouseMotionListener(MouseMotionListener)
* @see #getMouseMotionListeners
*/
public synchronized void addMouseMotionListener(MouseMotionListener listener) {
if (listener == null) {
return;
}
mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener);
}
/**
* Removes the specified mouse-motion listener. Calling this method with
* <code>null</code> or an invalid value has no effect.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param listener the mouse listener
* @see java.awt.event.MouseEvent
* @see java.awt.event.MouseMotionListener
* @see #addMouseMotionListener(MouseMotionListener)
* @see #getMouseMotionListeners
*/
public synchronized void removeMouseMotionListener(MouseMotionListener listener) {
if (listener == null) {
return;
}
mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener);
}
/**
* Returns an array of all the mouse-motion listeners
* registered on this <code>TrayIcon</code>.
*
* @return all of the <code>MouseInputListeners</code> registered on
* this <code>TrayIcon</code> or an empty array if no mouse
* listeners are currently registered
*
* @see #addMouseMotionListener(MouseMotionListener)
* @see #removeMouseMotionListener(MouseMotionListener)
* @see java.awt.event.MouseMotionListener
*/
public synchronized MouseMotionListener[] getMouseMotionListeners() {
return AWTEventMulticaster.getListeners(mouseMotionListener, MouseMotionListener.class);
}
/**
* Returns the command name of the action event fired by this tray icon.
*
* @return the action command name, or <code>null</code> if none exists
* @see #addActionListener(ActionListener)
* @see #setActionCommand(String)
*/
public String getActionCommand() {
return actionCommand;
}
/**
* Sets the command name for the action event fired by this tray
* icon. By default, this action command is set to
* <code>null</code>.
*
* @param command a string used to set the tray icon's
* action command.
* @see java.awt.event.ActionEvent
* @see #addActionListener(ActionListener)
* @see #getActionCommand
*/
public void setActionCommand(String command) {
actionCommand = command;
}
/**
* Adds the specified action listener to receive
* <code>ActionEvent</code>s from this <code>TrayIcon</code>.
* Action events usually occur when a user selects the tray icon,
* using either the mouse or keyboard. The conditions in which
* action events are generated are platform-dependent.
*
* <p>Calling this method with a <code>null</code> value has no
* effect.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param listener the action listener
* @see #removeActionListener
* @see #getActionListeners
* @see java.awt.event.ActionListener
* @see #setActionCommand(String)
*/
public synchronized void addActionListener(ActionListener listener) {
if (listener == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, listener);
}
/**
* Removes the specified action listener. Calling this method with
* <code>null</code> or an invalid value has no effect.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param listener the action listener
* @see java.awt.event.ActionEvent
* @see java.awt.event.ActionListener
* @see #addActionListener(ActionListener)
* @see #getActionListeners
* @see #setActionCommand(String)
*/
public synchronized void removeActionListener(ActionListener listener) {
if (listener == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, listener);
}
/**
* Returns an array of all the action listeners
* registered on this <code>TrayIcon</code>.
*
* @return all of the <code>ActionListeners</code> registered on
* this <code>TrayIcon</code> or an empty array if no action
* listeners are currently registered
*
* @see #addActionListener(ActionListener)
* @see #removeActionListener(ActionListener)
* @see java.awt.event.ActionListener
*/
public synchronized ActionListener[] getActionListeners() {
return AWTEventMulticaster.getListeners(actionListener, ActionListener.class);
}
/**
* The message type determines which icon will be displayed in the
* caption of the message, and a possible system sound a message
* may generate upon showing.
*
* @see TrayIcon
* @see TrayIcon#displayMessage(String, String, MessageType)
* @since 1.6
*/
public enum MessageType {
/** An error message */
ERROR,
/** A warning message */
WARNING,
/** An information message */
INFO,
/** Simple message */
NONE
};
/**
* Displays a popup message near the tray icon. The message will
* disappear after a time or if the user clicks on it. Clicking
* on the message may trigger an {@code ActionEvent}.
*
* <p>Either the caption or the text may be <code>null</code>, but an
* <code>NullPointerException</code> is thrown if both are
* <code>null</code>.
*
* When displayed, the caption or text strings may be truncated on
* some platforms; the number of characters that may be displayed is
* platform-dependent.
*
* <p><strong>Note:</strong> Some platforms may not support
* showing a message.
*
* @param caption the caption displayed above the text, usually in
* bold; may be <code>null</code>
* @param text the text displayed for the particular message; may be
* <code>null</code>
* @param messageType an enum indicating the message type
* @throws NullPointerException if both <code>caption</code>
* and <code>text</code> are <code>null</code>
*/
public void displayMessage(String caption, String text, MessageType messageType) {
if (caption == null && text == null) {
throw new NullPointerException("displaying the message with both caption and text being null");
}
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.displayMessage(caption, text, messageType.name());
}
}
/**
* Returns the size, in pixels, of the space that the tray icon
* occupies in the system tray. For the tray icon that is not yet
* added to the system tray, the returned size is equal to the
* result of the {@link SystemTray#getTrayIconSize}.
*
* @return the size of the tray icon, in pixels
* @see TrayIcon#setImageAutoSize(boolean)
* @see java.awt.Image
* @see TrayIcon#getSize()
*/
public Dimension getSize() {
return SystemTray.getSystemTray().getTrayIconSize();
}
// ****************************************************************
// ****************************************************************
void addNotify()
throws AWTException
{
synchronized (this) {
if (peer == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof SunToolkit) {
peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
} else if (toolkit instanceof HeadlessToolkit) {
peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
}
}
}
peer.setToolTip(tooltip);
}
void removeNotify() {
TrayIconPeer p = null;
synchronized (this) {
p = peer;
peer = null;
}
if (p != null) {
p.dispose();
}
}
void setID(int id) {
this.id = id;
}
int getID(){
return id;
}
void dispatchEvent(AWTEvent e) {
EventQueue.setCurrentEventAndMostRecentTime(e);
Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
processEvent(e);
}
void processEvent(AWTEvent e) {
if (e instanceof MouseEvent) {
switch(e.getID()) {
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
case MouseEvent.MOUSE_CLICKED:
processMouseEvent((MouseEvent)e);
break;
case MouseEvent.MOUSE_MOVED:
processMouseMotionEvent((MouseEvent)e);
break;
default:
return;
}
} else if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
}
}
void processMouseEvent(MouseEvent e) {
MouseListener listener = mouseListener;
if (listener != null) {
int id = e.getID();
switch(id) {
case MouseEvent.MOUSE_PRESSED:
listener.mousePressed(e);
break;
case MouseEvent.MOUSE_RELEASED:
listener.mouseReleased(e);
break;
case MouseEvent.MOUSE_CLICKED:
listener.mouseClicked(e);
break;
default:
return;
}
}
}
void processMouseMotionEvent(MouseEvent e) {
MouseMotionListener listener = mouseMotionListener;
if (listener != null &&
e.getID() == MouseEvent.MOUSE_MOVED)
{
listener.mouseMoved(e);
}
}
void processActionEvent(ActionEvent e) {
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(e);
}
}
private static native void initIDs();
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/x_bao/Java8Source.git
git@gitee.com:x_bao/Java8Source.git
x_bao
Java8Source
Java8Source
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /