private WebMenuItem createEntryMenuItem(final JarEntry entry) { WebMenuItem entryItem = new WebMenuItem(entry.getName(), entry.getIcon()); entryItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateClassPath(entry, true); } }); return entryItem; }
/** * Returns newly created menu item. * * @param icon menu item icon, can be either String icon name, ImageIcon, Image, image File or * image URL * @param text menu item text * @param hotkey menu item accelerator * @param enabled whether menu item is enabled or not * @param actionListener menu item action listener * @return newly created menu item */ protected WebMenuItem createItem( final Object icon, final String text, final HotkeyData hotkey, final boolean enabled, final ActionListener actionListener) { final WebMenuItem item = new WebMenuItem(); item.setIcon(getIcon(icon)); item.setLanguage(getLanguageKey(text)); item.setAccelerator(hotkey); item.setEnabled(enabled); item.addActionListener(actionListener); return item; }
final void statusChanged(Control.Status status) { switch (status) { case CONNECTING: mConnectMenuItem.setEnabled(false); break; case CONNECTED: mConnectMenuItem.setEnabled(false); mDisconnectMenuItem.setEnabled(true); break; case DISCONNECTING: mDisconnectMenuItem.setEnabled(false); break; case DISCONNECTED: // fallthrough case FAILED: // fallthrough case ERROR: mConnectMenuItem.setEnabled(true); mDisconnectMenuItem.setEnabled(false); break; } }
/** 初始化List事件等等动作 */ private void initMemberList() { final WebPopupMenu memberPopup = new WebPopupMenu(); WebMenuItem openChatItem = new WebMenuItem("发送消息"); WebMenuItem userDetailsItem = new WebMenuItem("查看资料"); WebMenuItem refreshListItem = new WebMenuItem("刷新列表"); WebMenuItem refreshFaceItem = new WebMenuItem("刷新头像"); memberPopup.add(openChatItem); memberPopup.addSeparator(); memberPopup.add(userDetailsItem); memberPopup.addSeparator(); memberPopup.add(refreshListItem); memberPopup.addSeparator(); memberPopup.add(refreshFaceItem); memberPopup.addSeparator(); memberList.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { checkSendSessionMsg(); } else if (e.isMetaDown()) { memberPopup.show(e.getComponent(), e.getX(), e.getY()); } } }); openChatItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { checkSendSessionMsg(); } }); userDetailsItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WebOptionPane.showMessageDialog(UIGroupMemberModule.this, "No Implements!!!"); } }); refreshListItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (namedObject != null) { updateMembers(namedObject); } } }); refreshFaceItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (namedObject != null) { updateFaces(namedObject); } } }); }
MainFrame( final View view, TableView<?, ?> userList, TableView<?, ?> threadList, Component content, Component searchPanel, Component statusBar) { mView = view; // general view + behaviour this.setTitle("Kontalk Java Client"); this.setSize(mConf.getInt(Config.VIEW_FRAME_WIDTH), mConf.getInt(Config.VIEW_FRAME_HEIGHT)); this.setIconImage(Utils.getImage("kontalk.png")); // closing behaviour this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (mConf.getBoolean(Config.MAIN_TRAY_CLOSE) && SystemTray.getSystemTray().getTrayIcons().length > 0) MainFrame.this.toggleState(); else mView.callShutDown(); } }); // menu WebMenuBar menubar = new WebMenuBar(); this.setJMenuBar(menubar); WebMenu konNetMenu = new WebMenu("KonNet"); konNetMenu.setMnemonic(KeyEvent.VK_K); mConnectMenuItem = new WebMenuItem(Tr.tr("Connect")); mConnectMenuItem.setAccelerator(Hotkey.ALT_C); mConnectMenuItem.setToolTipText(Tr.tr("Connect to Server")); mConnectMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { mView.callConnect(); } }); konNetMenu.add(mConnectMenuItem); mDisconnectMenuItem = new WebMenuItem(Tr.tr("Disconnect")); mDisconnectMenuItem.setAccelerator(Hotkey.ALT_D); mDisconnectMenuItem.setToolTipText(Tr.tr("Disconnect from Server")); mDisconnectMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { mView.callDisconnect(); } }); konNetMenu.add(mDisconnectMenuItem); konNetMenu.addSeparator(); WebMenuItem statusMenuItem = new WebMenuItem(Tr.tr("Set status")); statusMenuItem.setAccelerator(Hotkey.ALT_S); statusMenuItem.setToolTipText(Tr.tr("Set status text send to other user")); statusMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { WebDialog statusDialog = new StatusDialog(); statusDialog.setVisible(true); } }); konNetMenu.add(statusMenuItem); konNetMenu.addSeparator(); WebMenuItem exitMenuItem = new WebMenuItem(Tr.tr("Exit")); exitMenuItem.setAccelerator(Hotkey.ALT_E); exitMenuItem.setToolTipText(Tr.tr("Exit application")); exitMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { mView.callShutDown(); } }); konNetMenu.add(exitMenuItem); menubar.add(konNetMenu); WebMenu optionsMenu = new WebMenu(Tr.tr("Options")); optionsMenu.setMnemonic(KeyEvent.VK_O); WebMenuItem conConfMenuItem = new WebMenuItem(Tr.tr("Preferences")); conConfMenuItem.setAccelerator(Hotkey.ALT_P); conConfMenuItem.setToolTipText(Tr.tr("Set application preferences")); conConfMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { mView.showConfig(); } }); optionsMenu.add(conConfMenuItem); menubar.add(optionsMenu); WebMenu helpMenu = new WebMenu(Tr.tr("Help")); helpMenu.setMnemonic(KeyEvent.VK_H); WebMenuItem aboutMenuItem = new WebMenuItem(Tr.tr("About")); aboutMenuItem.setToolTipText(Tr.tr("About Kontalk")); aboutMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { MainFrame.this.showAboutDialog(); } }); helpMenu.add(aboutMenuItem); menubar.add(helpMenu); // Layout... this.setLayout(new BorderLayout(5, 5)); // ...left... WebPanel sidePanel = new WebPanel(false); sidePanel.add(searchPanel, BorderLayout.NORTH); mTabbedPane = new WebTabbedPane(WebTabbedPane.LEFT); WebButton newThreadButton = new WebButton(Tr.tr("New")); newThreadButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO new thread button } }); // String threadOverlayText = // Tr.t/r("No chats to display. You can create a new chat from your contacts"); WebScrollPane threadPane = createTablePane(threadList, newThreadButton, "threadOverlayText"); mTabbedPane.addTab("", threadPane); mTabbedPane.setTabComponentAt(Tab.THREADS.ordinal(), new WebVerticalLabel(Tr.tr("Chats"))); WebButton newUserButton = new WebButton(Tr.tr("Add")); newUserButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WebDialog addUserDialog = new AddUserDialog(); addUserDialog.setVisible(true); } }); // String userOverlayText = T/r.tr("No contacts to display. You have no friends ;("); WebScrollPane userPane = createTablePane(userList, newUserButton, "userOverlayText"); mTabbedPane.addTab("", userPane); mTabbedPane.setTabComponentAt(Tab.USER.ordinal(), new WebVerticalLabel(Tr.tr("Contacts"))); mTabbedPane.setPreferredSize(new Dimension(250, -1)); mTabbedPane.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { mView.tabPaneChanged(Tab.values()[mTabbedPane.getSelectedIndex()]); } }); sidePanel.add(mTabbedPane, BorderLayout.CENTER); this.add(sidePanel, BorderLayout.WEST); // ...right... this.add(content, BorderLayout.CENTER); // ...bottom this.add(statusBar, BorderLayout.SOUTH); }