类java.awt.TrayIcon源码实例Demo

下面列出了怎么用java.awt.TrayIcon的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码2 项目: TencentKona-8   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码3 项目: TencentKona-8   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码4 项目: neembuu-uploader   文件: NeembuuUploader.java
private void setUpTrayIcon() {
    if (SystemTray.isSupported()) {
        //trayIcon.setImageAutoSize(true); It renders the icon very poorly.
        //So we render the icon ourselves with smooth settings.
        {
            Dimension d = SystemTray.getSystemTray().getTrayIconSize();
            trayIcon = new TrayIcon(getIconImage().getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH));
        }
        //trayIcon = new TrayIcon(getIconImage());
        //trayIcon.setImageAutoSize(true);
        trayIcon.setToolTip(Translation.T().trayIconToolTip());
        trayIcon.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                NULogger.getLogger().info("System tray double clicked");

                setExtendedState(JFrame.NORMAL);
                setVisible(true);
                repaint();
                SystemTray.getSystemTray().remove(trayIcon);
            }
        });
    }
}
 
源代码5 项目: openjdk-jdk8u   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码6 项目: openjdk-jdk8u   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码7 项目: proxyee-down   文件: DownApplication.java
private void initTray() throws AWTException {
  if (SystemTray.isSupported()) {
    // 获得系统托盘对象
    SystemTray systemTray = SystemTray.getSystemTray();
    // 获取图片所在的URL
    URL url = Thread.currentThread().getContextClassLoader().getResource(ICON_PATH);
    // 为系统托盘加托盘图标
    Image trayImage = Toolkit.getDefaultToolkit().getImage(url);
    Dimension trayIconSize = systemTray.getTrayIconSize();
    trayImage = trayImage.getScaledInstance(trayIconSize.width, trayIconSize.height, Image.SCALE_SMOOTH);
    trayIcon = new TrayIcon(trayImage, "Proxyee Down");
    systemTray.add(trayIcon);
    loadPopupMenu();
    //双击事件监听
    trayIcon.addActionListener(event -> Platform.runLater(() -> loadUri(null, true)));
  }
}
 
源代码8 项目: runelite   文件: Notifier.java
private void sendNotification(
	final String title,
	final String message,
	final TrayIcon.MessageType type)
{
	final String escapedTitle = SHELL_ESCAPE.escape(title);
	final String escapedMessage = SHELL_ESCAPE.escape(message);

	switch (OSType.getOSType())
	{
		case Linux:
			sendLinuxNotification(escapedTitle, escapedMessage, type);
			break;
		case MacOS:
			sendMacNotification(escapedTitle, escapedMessage);
			break;
		default:
			sendTrayNotification(title, message, type);
	}
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码11 项目: openjdk-jdk9   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, () -> {
        PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
        if (popup != newPopup) {
            if (popup != null) {
                popupParent.remove(popup);
            }
            if (newPopup != null) {
                popupParent.add(newPopup);
            }
            popup = newPopup;
        }
        if (popup != null) {
            WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
                                             .getPeer(popup);
            peer.show(popupParent, new Point(x, y));
        }
    });
}
 
源代码12 项目: openjdk-8   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码13 项目: jdk8u-jdk   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码14 项目: jdk8u-jdk   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码15 项目: jdk8u_jdk   文件: WTrayIconPeer.java
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码16 项目: hottub   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码17 项目: jdk8u-dev-jdk   文件: WTrayIconPeer.java
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
源代码18 项目: openjdk-8-source   文件: WTrayIconPeer.java
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
源代码19 项目: visualvm   文件: SysTray.java
private TrayIcon createTrayIcon() {
    Image image = createTrayImage();
    String tooltip = createTrayTooltip();
    trayPopup = createTrayPopup();
    TrayIcon icon = new TrayIcon(image, tooltip, trayPopup);
    icon.setImageAutoSize(true);

    icon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    if (trayPopup.isEnabled()) toggleWindowVisibility();
                }
            });
        }
    });

    return icon;
}
 
源代码20 项目: plugins   文件: IdleNotifierPlugin.java
@Subscribe
private void onPlayerSpawned(PlayerSpawned event)
{
	final Player p = event.getPlayer();
	if (config.notifyPkers() && p != null && p != client.getLocalPlayer()
		&& PvPUtil.isAttackable(client, p) && !client.isFriended(p.getName(), false)
		&& !friendChatManager.isMember(p.getName()))
	{
		String playerName = p.getName();
		int combat = p.getCombatLevel();
		notifier.notify("PK'er warning! A level " + combat + " player named " + playerName +
			" appeared!", TrayIcon.MessageType.WARNING);
	}
}
 
源代码21 项目: dragonwell8_jdk   文件: WTrayIconPeer.java
@Override
public void updateImage() {
    Image image = ((TrayIcon)target).getImage();
    if (image != null) {
        updateNativeImage(image);
    }
}
 
源代码22 项目: runelite   文件: Notifier.java
private void sendTrayNotification(
	final String title,
	final String message,
	final TrayIcon.MessageType type)
{
	if (clientUI.getTrayIcon() != null)
	{
		clientUI.getTrayIcon().displayMessage(title, message, type);
	}
}
 
源代码23 项目: dragonwell8_jdk   文件: WTrayIconPeer.java
@Override
public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) {
    if (image != ((TrayIcon)target).getImage() || // if the image has been changed
        isDisposed())
    {
        return false;
    }
    if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS |
                  ImageObserver.WIDTH | ImageObserver.HEIGHT)) != 0)
    {
        updateNativeImage(image);
    }
    return (flags & ImageObserver.ALLBITS) == 0;
}
 
源代码24 项目: Spark   文件: WindowsNotification.java
public static void sendNotification(String title, String bodyText) {

        TrayIcon[] trayIcon = SystemTray.getSystemTray().getTrayIcons();
        if (trayIcon.length == 1) {
            trayIcon[0].displayMessage(title, bodyText, TrayIcon.MessageType.INFO);
        }

    }
 
源代码25 项目: jdk8u60   文件: WTrayIconPeer.java
@Override
public void updateImage() {
    Image image = ((TrayIcon)target).getImage();
    if (image != null) {
        updateNativeImage(image);
    }
}
 
源代码26 项目: PeerWasp   文件: JSystemTray.java
private TrayIcon create(Image image) throws IOException {
	TrayIcon trayIcon = new java.awt.TrayIcon(image);
	trayIcon.setImageAutoSize(true);
	trayIcon.setToolTip(tooltip);
	trayIcon.setPopupMenu(createMenu(false));
	return trayIcon;
}
 
源代码27 项目: jdk8u-dev-jdk   文件: WTrayIconPeer.java
@Override
public void updateImage() {
    Image image = ((TrayIcon)target).getImage();
    if (image != null) {
        updateNativeImage(image);
    }
}
 
源代码28 项目: jdk8u60   文件: WTrayIconPeer.java
@Override
public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) {
    if (image != ((TrayIcon)target).getImage() || // if the image has been changed
        isDisposed())
    {
        return false;
    }
    if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS |
                  ImageObserver.WIDTH | ImageObserver.HEIGHT)) != 0)
    {
        updateNativeImage(image);
    }
    return (flags & ImageObserver.ALLBITS) == 0;
}
 
源代码29 项目: winthing   文件: WindowGui.java
public void setIcon(boolean color) {
    SystemTray tray = SystemTray.getSystemTray();
    TrayIcon[] icons = tray.getTrayIcons();
    if (icons.length > 0) {
        String name = color ? "favicon-green.png" : "favicon-red.png";

        URL url = getClass().getClassLoader().getResource(name);
        Image image = Toolkit.getDefaultToolkit().getImage(url);

        int trayWidth = tray.getTrayIconSize().width;
        int trayHeight = tray.getTrayIconSize().height;
        Image scaled = image.getScaledInstance(trayWidth, trayHeight, Image.SCALE_SMOOTH);
        icons[0].setImage(scaled);
    }
}
 
源代码30 项目: openjdk-jdk8u   文件: WTrayIconPeer.java
@Override
public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) {
    if (image != ((TrayIcon)target).getImage() || // if the image has been changed
        isDisposed())
    {
        return false;
    }
    if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS |
                  ImageObserver.WIDTH | ImageObserver.HEIGHT)) != 0)
    {
        updateNativeImage(image);
    }
    return (flags & ImageObserver.ALLBITS) == 0;
}
 
 类所在包
 同包方法