protected void assembleSystemMenu() { systemMenu = new JPopupMenu(); JMenuItem mi = (JMenuItem) systemMenu.add(new JMenuItem(restoreAction)); mi.setMnemonic('R'); mi = (JMenuItem) systemMenu.add(new JMenuItem(moveAction)); mi.setMnemonic('M'); mi = (JMenuItem) systemMenu.add(new JMenuItem(sizeAction)); mi.setMnemonic('S'); mi = (JMenuItem) systemMenu.add(new JMenuItem(iconifyAction)); mi.setMnemonic('n'); mi = (JMenuItem) systemMenu.add(new JMenuItem(maximizeAction)); mi.setMnemonic('x'); systemMenu.add(new JSeparator()); mi = (JMenuItem) systemMenu.add(new JMenuItem(closeAction)); mi.setMnemonic('C'); systemButton = new SystemButton(); systemButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { systemMenu.show(systemButton, 0, BUTTON_SIZE); } }); systemButton.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent evt) { try { frame.setSelected(true); } catch (PropertyVetoException pve) { } if ((evt.getClickCount() == 2)) { closeAction.actionPerformed( new ActionEvent( evt.getSource(), ActionEvent.ACTION_PERFORMED, null, evt.getWhen(), 0)); systemMenu.setVisible(false); } } }); }
public void layoutContainer(Container c) { int w = getWidth(); systemButton.setBounds(0, 0, BUTTON_SIZE, BUTTON_SIZE); int x = w - BUTTON_SIZE; if (frame.isMaximizable()) { maximizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE); x -= BUTTON_SIZE; } else if (maximizeButton.getParent() != null) { maximizeButton.getParent().remove(maximizeButton); } if (frame.isIconifiable()) { minimizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE); x -= BUTTON_SIZE; } else if (minimizeButton.getParent() != null) { minimizeButton.getParent().remove(minimizeButton); } title.setBounds(BUTTON_SIZE, 0, x, BUTTON_SIZE); }
private Composite createWinTitle(Composite composite) { Composite winTitle = new Composite(composite, SWT.NONE); winTitle.setLayoutData(new RowData(850, 25)); SystemButton menuBtn = new SystemButton( winTitle, SWT.NONE, "/res/sysbtn_menu.png", 4, "菜单", this, new Listener() { @Override public void handleEvent(Event e) { int x = e.getBounds().x; int y = e.getBounds().y; if (x < 0 || y < 0) return; ((Composite) (e.widget)).getMenu().setVisible(true); } }); menuBtn.setLocation(769, 0); Menu menu = new Menu(menuBtn); menuBtn.setMenu(menu); MenuItem mntmCaidan = new MenuItem(menu, SWT.NONE); mntmCaidan.setText("设置"); MenuItem menuItem = new MenuItem(menu, SWT.NONE); menuItem.setText("\u65B0\u7248\u529F\u80FD"); MenuItem menuItem_1 = new MenuItem(menu, SWT.NONE); menuItem_1.setText("\u5B98\u65B9\u5FAE\u535A"); MenuItem menuItem_2 = new MenuItem(menu, SWT.NONE); menuItem_2.setText("\u95EE\u9898\u53CD\u9988\u4E0E\u5EFA\u8BAE"); MenuItem menuItem_3 = new MenuItem(menu, SWT.NONE); menuItem_3.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) {} }); menuItem_3.setText("\u7528\u6237\u9690\u79C1\u4FDD\u62A4\u653F\u7B56"); MenuItem menuItem_4 = new MenuItem(menu, SWT.NONE); menuItem_4.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { MessageBox mb = new MessageBox(shell, SWT.ABORT); mb.setMessage("开源中国 @xwalker QQ:909854136"); mb.setText("关于"); mb.open(); } }); menuItem_4.setText("\u5173\u4E8E\u6211\u4EEC"); SystemButton minBtn = new SystemButton( winTitle, SWT.NONE, "/res/sysbtn_min.png", 4, "最小化", this, new Listener() { @Override public void handleEvent(Event event) { shell.setMinimized(true); } }); minBtn.setLocation(796, 0); SystemButton closeBtn = new SystemButton( winTitle, SWT.NONE, "/res/sysbtn_close.png", 4, "关闭", this, new Listener() { @Override public void handleEvent(Event event) { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.CANCEL); mb.setMessage("确定退出?"); mb.setText("确定"); if (mb.open() == SWT.OK) { shell.close(); shell.dispose(); } } }); closeBtn.setLocation(823, 0); CLabel lblJava = new CLabel(winTitle, SWT.NONE); lblJava.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); lblJava.setForeground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); lblJava.setBounds(5, 0, 309, 23); lblJava.setText("Java\u684C\u9762\u7A0B\u5E8F \u4EFF360\u8F6F\u4EF6\u7BA1\u5BB6 QQ:909854136"); return winTitle; }