📄 jdictraygui.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.vpn.client;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import org.jdesktop.jdic.tray.SystemTray;
import org.jdesktop.jdic.tray.TrayIcon;
public class JDICTrayGUI implements VPNClientGUI {
final int IDLE_ICON = 0;
final int TX_ICON = 1;
final int RX_ICON = 2;
final int TXRX_ICON = 3;
final int DISCONNECTED_ICON = 4;
Icon[] icons;
Icon currentIcon;
TrayIcon systemTrayIcon;
JPopupMenu systemTrayMenu;
VPNClientGUIListener listener;
String currentToolTip;
public JDICTrayGUI() {
}
public void init(VPNClientGUIListener listener) {
icons = new Icon[5];
URL url = getClass().getResource("/images/idle.gif");
icons[IDLE_ICON] = new ImageIcon(url);
url = getClass().getResource("/images/tx.gif");
icons[TX_ICON] = new ImageIcon(url);
url = getClass().getResource("/images/rx.gif");
icons[RX_ICON] = new ImageIcon(url);
url = getClass().getResource("/images/txrx.gif");
icons[TXRX_ICON] = new ImageIcon(url);
url = getClass().getResource("/images/disconnected.gif");
icons[DISCONNECTED_ICON] = new ImageIcon(url);
this.listener = listener;
JMenuItem exit = new JMenuItem("Exit");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JDICTrayGUI.this.listener.exit();
}
});
JMenuItem open = new JMenuItem("Open Browser");
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JDICTrayGUI.this.listener.open();
}
});
// #ifdef DEBUG
JMenuItem console = new JMenuItem("Debug Console");
console.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JDICTrayGUI.this.listener.console();
}
});
// #endif
JMenuItem ports = new JMenuItem("Tunnel Monitor");
ports.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JDICTrayGUI.this.listener.ports();
}
});
systemTrayMenu = new JPopupMenu("Agent");
systemTrayMenu.add(exit);
systemTrayMenu.addSeparator();
systemTrayMenu.add(open);
systemTrayMenu.add(ports);
/* DEBUG */systemTrayMenu.add(console);
systemTrayIcon = new TrayIcon(icons[IDLE_ICON], "Agent", systemTrayMenu);
SystemTray tray = SystemTray.getDefaultSystemTray();
tray.addTrayIcon(systemTrayIcon);
}
public void addMenuItem(final AgentAction action) {
JMenuItem item = new JMenuItem(action.getAction());
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
action.actionPerformed();
}
});
systemTrayMenu.add(item);
}
synchronized void setIcon(Icon icon) {
if(icon != currentIcon) {
systemTrayIcon.setIcon(icon);
this.currentIcon = icon;
}
}
public void showIdle() {
setIcon(icons[IDLE_ICON]);
}
public void showDisconnected() {
setIcon(icons[DISCONNECTED_ICON]);
}
public void showTx() {
setIcon(icons[TX_ICON]);
}
public void showRx() {
setIcon(icons[RX_ICON]);
}
public void showTxRx() {
setIcon(icons[TXRX_ICON]);
}
public synchronized void setInfo(String info) {
if(!info.equals(currentToolTip)) {
systemTrayIcon.setToolTip(info);
currentToolTip = info;
}
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.vpn.client.VPNClientGUI#getGUIComponent()
*/
public Component getGUIComponent() {
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -