📄 chatroompanel.java
字号:
checkPop(e); } public void checkPop(MouseEvent e) { // look for the popup trigger.. usually a right click if (e.isPopupTrigger()) { if (conversationArea.getSelectedText() == null) { popMenu.show(e.getComponent(), e.getX(), e.getY()); } } } } /** * Add the various menu items to the popup menu */ private void setUpPopMenu() { MenuItemListener listener = new MenuItemListener(); conversationArea.getTextPane().addMouseListener(new RightClickListener()); CopyPasteContextMenu.registerComponent(conversationArea.getTextPane()); popMenu.add(nickItem); popMenu.add(newItem); popMenu.add(logItem); popMenu.addSeparator(); popMenu.add(viewAdmins); popMenu.add(viewModerators); popMenu.add(viewMembers); popMenu.add(viewParticipants); popMenu.add(viewOwners); popMenu.add(viewOutcasts); popMenu.add(invite); popMenu.add(registerItem); popMenu.add(destroyRoom); popMenu.addSeparator(); popMenu.add(leaveItem); logItem.addActionListener(listener); newItem.addActionListener(listener); leaveItem.addActionListener(listener); nickItem.addActionListener(listener); registerItem.addActionListener(listener); viewAdmins.addActionListener(listener); viewOutcasts.addActionListener(listener); viewMembers.addActionListener(listener); invite.addActionListener(listener); viewParticipants.addActionListener(listener); viewOwners.addActionListener(listener); viewModerators.addActionListener(listener); destroyRoom.addActionListener(listener); } /** * Listens for items to be selected in the menu * * @author Adam Olsen * @version 1.0 */ private class MenuItemListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == nickItem) changeNickHandler(); else if (e.getSource() == leaveItem) { BuddyList.getInstance().getTabFrame().removePanel(ChatRoomPanel.this); BuddyList.getInstance().stopTabFrame(); } else if (e.getSource() == newItem) { GroupChatBookmarks gc = new GroupChatBookmarks(BuddyList .getInstance().getTabFrame()); gc.load(); gc.setVisible(true); gc.toFront(); } else if (e.getSource() == logItem) new LogViewerDialog(ChatRoomPanel.this, getRoomName()); else if (e.getSource() == registerItem) configurationHandler("registerFor"); else if (e.getSource() == viewAdmins) new ListViewDialog(ChatRoomPanel.this, ListViewDialog.TYPE_ADMIN); else if (e.getSource() == viewOutcasts) new ListViewDialog(ChatRoomPanel.this, ListViewDialog.TYPE_OUTCASTS); else if (e.getSource() == viewMembers) new ListViewDialog(ChatRoomPanel.this, ListViewDialog.TYPE_MEMBERS); else if (e.getSource() == viewParticipants) new ListViewDialog(ChatRoomPanel.this, ListViewDialog.TYPE_PARTICIPANTS); else if (e.getSource() == viewOwners) new ListViewDialog(ChatRoomPanel.this, ListViewDialog.TYPE_OWNERS); else if (e.getSource() == invite) { UserChooser chooser = new UserChooser(BuddyList.getInstance().getTabFrame(), resources.getString("inviteUser")); chooser.addListener(ChatRoomPanel.this); chooser.setVisible(true); } else if (e.getSource() == viewModerators) new ListViewDialog(ChatRoomPanel.this, ListViewDialog.TYPE_MODERATORS); else if (e.getSource() == destroyRoom) destroyHandler(); } } public void usersChosen(UserChooser.Item[] items) { usersChosen((Object[])items); } /** * Description of the Method * * @param array Description of the Parameter */ public void usersChosen(Object[] us) { String result = (String) JOptionPane.showInputDialog(BuddyList.getInstance().getTabFrame(), resources .getString("enterReasonForInvite"), resources .getString("inviteUser"), JOptionPane.QUESTION_MESSAGE, null, null, "Come join us!"); if(result == null || result.equals("")) return; if(us[0] instanceof String) { inviteUsers(new String[] {(String)us[0]}, result); return; } ArrayList u = new ArrayList(); for(int i = 0; i < us.length; i++) { UserChooser.Item item = (UserChooser.Item)us[i]; u.add(item.getJID()); } inviteUsers((String[])u.toArray(new String[u.size()]), result); } protected void inviteUsers(final String[] users, final String reason) { Thread thread = new Thread(new Runnable() { public void run() { for(int i = 0; i < users.length; i++) { chat.invite(users[i], reason); } } }); thread.start(); } private void destroyHandler() { final int r = JOptionPane.showConfirmDialog(BuddyList.getInstance() .getTabFrame(), resources.getString("sureDestroyRoom"), resources.getString("destroyRoom"), JOptionPane.YES_NO_OPTION); if (r == JOptionPane.YES_OPTION) { final String reason = (String) JOptionPane.showInputDialog( BuddyList.getInstance().getTabFrame(), resources .getString("enterReasonForDestroy"), resources .getString("destroyRoom"), JOptionPane.QUESTION_MESSAGE, null, null, "Room has been moved"); if (reason == null) return; final String result = (String) JOptionPane.showInputDialog( BuddyList.getInstance().getTabFrame(), resources .getString("enterAlternate"), resources .getString("destroyRoom"), JOptionPane.QUESTION_MESSAGE, null, null, ""); if (result == null) return; new Thread(new DestroyThread(reason, result)).start(); } } class DestroyThread implements Runnable { String reason, result; public DestroyThread(String reason, String result) { this.reason = reason; this.result = result; } public void run() { String error = null; try { chat.destroy(reason, result); } catch (XMPPException ex) { error = ex.getMessage(); } final String e = error; SwingUtilities.invokeLater(new Runnable() { public void run() { if (e != null) { serverErrorMessage(e); } else { serverErrorMessage("Room has been destroyed"); } } }); } } /** * Collects a Data Form to be filled out * * @param type * the type of form. Either "configure" or "registerFor" */ public void configurationHandler(String type) { Thread thread = new Thread(new ConfigThread(type)); thread.start(); } /** * Collects the data form and displays it. * * @author Adam Olsen */ private class ConfigThread implements Runnable { private String type = "configure"; /** * @param type * the type of form to collect. */ public ConfigThread(String type) { this.type = type; } /** * Called by the enclosing thread */ public void run() { try { Form temp; // get the form if (type.equals("configure")) { temp = chat.getConfigurationForm(); } else { temp = chat.getRegistrationForm(); } if (temp == null) { serverErrorMessage(resources .getString("couldNotCollectForm")); return; } final Form form = temp; final JBDataForm f = new JBDataForm(BuddyList.getInstance().getTabFrame(), form); f.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // if the cancel button is pressed, close the form if (e.getActionCommand().equals("cancel")) { SwingUtilities.invokeLater(new Runnable() { public void run() { f.dispose(); } }); } // else submit the form else if (e.getActionCommand().equals("ok")) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (submitConfigurationForm(f, type)) { f.setVisible(false); } } }); } } }); // show the form SwingUtilities.invokeLater(new Runnable() { public void run() { f.setVisible(true); } }); } // if there was an error collecting the form catch (XMPPException ex) { String message = ex.getMessage(); if (ex.getXMPPError() != null) { message = resources.getString("xmppError" + ex.getXMPPError().getCode()); } serverErrorMessage(resources.getString(type + "Room") + ": " + message); } } } /** * Submits the form * * @param form * the form to submit * @param type * the type of form, either "configure" or "registerFor" * @return false if the required fields have not been filled out */ private boolean submitConfigurationForm(JBDataForm form, final String type) { final Form answer = form.getAnswerForm(); if (answer == null) return false; Thread thread = new Thread(new Runnable() { public void run() { try { if (type.equals("configure")) { chat.sendConfigurationForm(answer); } else { chat.sendRegistrationForm(answer); } } catch (XMPPException ex) { } SwingUtilities.invokeLater(new Runnable() { public void run() { if (type.equals("configure")) { serverNoticeMessage(resources .getString("configureSubmitted")); } else { serverNoticeMessage(resources .getString("registerSubmitted")); } } }); } }); thread.start(); return true; } /** * Opens the log window for this chat room */ public void openLogWindow() { new LogViewerDialog(this, getRoomName()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -