package com.topthinking.exingim; import java.awt.EventQueue; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedList; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.SwingConstants; import javax.swing.UIManager; import org.jdesktop.jdic.tray.SystemTray; import org.jdesktop.jdic.tray.TrayIcon; import org.jvnet.substance.SubstanceImageCreator; import org.jvnet.substance.SubstanceLookAndFeel; import org.jvnet.substance.skin.SubstanceModerateLookAndFeel; import org.jvnet.substance.theme.SubstanceTheme; import org.jvnet.substance.title.TitleButtonCallback; import org.jvnet.substance.title.TitleButtonInfo; import com.swtdesigner.SwingResourceManager; public class AliWangWangUI { private JFrame frame; private JPopupMenu menuBar; /** * Launch the application * @param args */ public static void main(String args[]) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel(new SubstanceModerateLookAndFeel()); } catch (Exception e) { System.out.println("Substance Raven Graphite failed to initialize"); } EventQueue.invokeLater(new Runnable() { public void run() { try { AliWangWangUI window = new AliWangWangUI(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application */ public AliWangWangUI() { createContents(); } /** * Initialize the contents of the frame */ private void createContents() { frame = new JFrame(); frame.getContentPane().setLayout(new GridBagLayout()); frame.setIconImage(SwingResourceManager.getImage(AliWangWangUI.class, "/com/topthinking/pic/al-logo.png")); frame.setTitle("易行 IM"); frame.setBounds(400, 40, 334, 648); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TopPanel topPanel = new TopPanel(); final GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.insets = new Insets(0, 4, 0, 0); gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 20; frame.getContentPane().add(topPanel, gridBagConstraints); BodyPanel bodyPanel = new BodyPanel(frame); final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints(); gridBagConstraints_1.insets = new Insets(0, 0, 8, 0); gridBagConstraints_1.fill = GridBagConstraints.BOTH; gridBagConstraints_1.weighty = 1; gridBagConstraints_1.weightx = 1; gridBagConstraints_1.gridx = 0; gridBagConstraints_1.gridy = 1; gridBagConstraints_1.ipadx = -35; gridBagConstraints_1.ipady = -25; frame.getContentPane().add(bodyPanel, gridBagConstraints_1); FootPanel footPanel = new FootPanel(); final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints(); gridBagConstraints_2.weightx = 1; gridBagConstraints_2.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_2.anchor = GridBagConstraints.WEST; gridBagConstraints_2.gridx = 0; gridBagConstraints_2.gridy = 2; gridBagConstraints_2.ipadx = 47; frame.getContentPane().add(footPanel, gridBagConstraints_2); menuBar = new JPopupMenu(); menuBar.setPopupSize(180, 400); final JMenu personMenu = new JMenu(); personMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/person.png")); personMenu.setText("个人资料"); menuBar.add(personMenu); final JMenu onlineStateMenu = new JMenu(); onlineStateMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/state.png")); onlineStateMenu.setText("在线状态"); menuBar.add(onlineStateMenu); final JMenuItem freeStateItem = new JMenuItem(); freeStateItem.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/tick.png")); freeStateItem.setText("我有空"); onlineStateMenu.add(freeStateItem); onlineStateMenu.addSeparator(); final JMenuItem busyStateItem = new JMenuItem(); busyStateItem.setText("忙碌中"); onlineStateMenu.add(busyStateItem); final JMenuItem notHereStateItem = new JMenuItem(); notHereStateItem.setText("不在电脑旁"); onlineStateMenu.add(notHereStateItem); final JMenuItem phoneStateItem = new JMenuItem(); phoneStateItem.setText("接听电话中"); onlineStateMenu.add(phoneStateItem); final JMenuItem dinnerStateItem = new JMenuItem(); dinnerStateItem.setText("外出就餐"); onlineStateMenu.add(dinnerStateItem); onlineStateMenu.addSeparator(); final JMenuItem hideStateItem = new JMenuItem(); hideStateItem.setText("隐身"); onlineStateMenu.add(hideStateItem); final JMenu signMenu = new JMenu(); signMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/sign.png")); signMenu.setText("个性签名"); menuBar.add(signMenu); menuBar.addSeparator(); final JMenuItem sendItem = new JMenuItem(); sendItem.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/send.png")); sendItem.setText("指定发送"); menuBar.add(sendItem); final JMenu recordMenu = new JMenu(); recordMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/record.png")); recordMenu.setText("聊天记录"); menuBar.add(recordMenu); menuBar.addSeparator(); final JMenu optionMenu = new JMenu(); optionMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/option.png")); optionMenu.setText("显示选项"); menuBar.add(optionMenu); final JMenu systemMenu = new JMenu(); systemMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/system.png")); systemMenu.setText("系统设置"); menuBar.add(systemMenu); final JMenu mobileMenu = new JMenu(); mobileMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/mobile.png")); mobileMenu.setText("移动旺旺"); menuBar.add(mobileMenu); menuBar.addSeparator(); final JMenuItem pluginItem = new JMenuItem(); pluginItem.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/plagin.png")); pluginItem.setText("插件"); menuBar.add(pluginItem); menuBar.addSeparator(); final JMenu helpMenu = new JMenu(); helpMenu.setIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/help.png")); helpMenu.setText("帮助"); menuBar.add(helpMenu); //-------------------- 添加窗口标题栏的右边按钮 --------------------------- TitleButtonInfo tbInfo1 = new TitleButtonInfo(); tbInfo1.setActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuBar.show(frame, frame.getWidth()-16*5, 27); } }); tbInfo1.setTooltipText("Tooltip for custom button 1"); tbInfo1.setButtonCallback(new TitleButtonCallback() { public Icon getTitleButtonIcon(SubstanceTheme currSubstanceTheme, int iconMaxWidth, int iconMaxHeight) { return new ImageIcon(SubstanceImageCreator .overlayEcho(SubstanceImageCreator .getArrow(8, 8, SwingConstants.SOUTH, currSubstanceTheme ), 1, 1)); } }); java.util.List<TitleButtonInfo> tbInfoList = new LinkedList<TitleButtonInfo>(); tbInfoList.add(tbInfo1); SubstanceLookAndFeel.setRootPaneCustomTitleButtons( frame.getRootPane(), tbInfoList); //加入系统托盘 // tray(); } /** * 添加系统托盘 */ public void tray() { final SystemTray tray = SystemTray.getDefaultSystemTray(); //获得操作系统托盘实例 final TrayIcon trayIcon = new TrayIcon(SwingResourceManager.getIcon(AliWangWangUI.class, "/com/topthinking/pic/al-logo.png"), "易行IM", menuBar); trayIcon.setIconAutoSize(true); tray.addTrayIcon(trayIcon); } }