📄 chatpanel.java
字号:
*/ private class DividerListener implements PropertyChangeListener { /** * Description of the Method * *@param e Description of the Parameter */ public void propertyChange(PropertyChangeEvent e) { String modifier = ""; if (Settings.getInstance().getBoolean("useTabbedWindow")) { modifier = "tabbed_"; } if (e.getOldValue().toString().equals("-1")) { return; } Settings.getInstance().setProperty( modifier + "conversationWindowDividerLocation", e.getOldValue().toString()); } } /** * Gets the ComboBox with all the buddy's resources * *@return the ComboBox */ public JComboBox getResourceBox() { return resourceBox; } /** * Updates the JComboBox with the buddy's current resources */ public void updateResources() { SwingUtilities.invokeLater( new Runnable() { public void run() { if (selected == null) { selected = ""; } com.valhalla.Logger.debug("updating resources " + buddy.getUser()); resourceBox.removeAllItems(); resourceBox.addItem(resources.getString("defaultResource")); resourceBox.addItem(resources.getString("allResources")); if (buddy.getUser().indexOf("/") >= 0) { return; } Iterator i = buddy.keySet().iterator(); int count = 2; int sel = 0; while (i.hasNext()) { String key = (String) i.next(); if (!key.equals("N/A")) { resourceBox.addItem(key); if (key.equals(selected)) { sel = count; com.valhalla.Logger.debug("sel" + selected); } count++; } } if (count == 2) { sel = 0; resourceBox.setEnabled(false); } else if (count == 3) { sel = 2; resourceBox.setEnabled(false); } else { resourceBox.setEnabled(true); } if (selected.equals(resources.getString("allResources"))) { sel = 1; } if (sel > 0 && sel <= resourceBox.getItemCount()) { resourceBox.setSelectedIndex(sel); } else { resourceBox.setSelectedIndex(0); } resourceBox.repaint(); } }); } /** * Adds the various event listeners for the components that are a part of * this frame */ private void addListeners() { clearButton.setToolTipText(resources.getString("clear")); emoteButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JFrame f = frame; if (f == null) { f = BuddyList.getInstance().getTabFrame(); } ConversationFormatter.getInstance().displayEmoticonChooser(f, emoteButton, textEntryArea); } }); encryptButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (buddy.isEncrypting()) { buddy.isEncrypting(false); encryptButton.setIcon(Standard.getIcon("images/buttons/ssl_no.png")); } else { buddy.isEncrypting(true); encryptButton.setIcon(Standard.getIcon("images/buttons/ssl_yes.png")); } } }); clearButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { conversationArea.setText(""); } }); //if the press enter, send the message Action sendMessageAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { sendHandler(null); } }; Action shiftEnterAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int pos = textEntryArea.getCaretPosition(); if (pos < 0) { pos = 0; } textEntryArea.insert("\n", pos); try { textEntryArea.setCaretPosition(pos + 1); } catch (IllegalArgumentException ex) { } } }; Action checkCloseAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { checkCloseHandler(); } }; Action closeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { closeHandler(); } }; //set it up so that if there isn't any selected text in the // conversation area //the textentryarea grabs the focus. conversationArea.getTextPane().addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (conversationArea.getSelectedText() == null) { textEntryArea.requestFocus(); } } }); conversationArea.getTextPane().addMouseListener(new RightClickListener(popMenu)); CopyPasteContextMenu.registerComponent(conversationArea.getTextPane()); textEntryArea.getInputMap() .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), sendMessageAction); textEntryArea.getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, java.awt.event.InputEvent.SHIFT_MASK), shiftEnterAction); textEntryArea.getInputMap().put( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), shiftEnterAction); textEntryArea.getInputMap().put( KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), checkCloseAction); textEntryArea.getInputMap().put( KeyStroke.getKeyStroke(KeyEvent.VK_K, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), closeAction); } /** * Gets the textEntryArea attribute of the ChatPanel object * *@return The textEntryArea value */ public JTextComponent getTextEntryArea() { return textEntryArea; } /** * Displays a message in the window when the buddy signs off */ public void signedOff() { SwingUtilities.invokeLater( new Runnable() { public void run() { setIsTyping(false); conversationArea.append(getDate(null) + " " + buddy.getName() + " "+ resources.getString("signedOff") + "\n", ConversationArea.SERVER); } }); } /** * Displays a message in the window when a buddy signs on */ public void signedOn() { SwingUtilities.invokeLater( new Runnable() { public void run() { conversationArea.append(getDate(null) + " " + buddy.getName() + " " + resources.getString("signedOn") + "\n", ConversationArea.SERVER); } }); } /** * Displays a "disconnected" message" */ public void disconnected() { conversationArea.append(getDate(null) + " *** " + resources.getString("disconnected") + "\n", ConversationArea.BLACK, true); chats = new Hashtable(); } /** * Description of the Method * *@param text Description of the Parameter */ public void messageEvent(String text) { conversationArea.append(getDate(null) + " *** " + text + "\n", ConversationArea.BLACK, true); } /** * Receives a message * *@param sbj the message subject *@param body the message body *@param resource the resource the message came from if there is one *@param delayInfo Description of the Parameter *@param date Description of the Parameter *@param decryptedFlag Description of the Parameter *@param verifiedFlag Description of the Parameter */ public void receiveMessage(final String sbj, final String delayInfo, final String body, final String resource, final Date date, final boolean decryptedFlag, final boolean verifiedFlag) { SwingUtilities.invokeLater( new Runnable() { public void run() { String extraInfo = delayInfo; setIsTyping(false); receiveMessage(); JFrame f = frame; if (f == null) { f = BuddyList.getInstance().getTabFrame(); } if (f.isFocused() == true) {// SwingUtilities.invokeLater(new Runnable() {// public void run() { buddy.sendNotDisplayedID();// }// }); } if (resource != null && buddy.getUser().indexOf("/") < 0 && !resource.equals("")) { int c = 0; selected = resource; boolean select = false; for (int i = 0; i < resourceBox.getModel().getSize(); i++) { if (((String) resourceBox.getModel().getElementAt(i)).equals(resource)) { select = true; break; } c++; } if(select) resourceBox.setSelectedIndex(c); } String newBody = body; String name = buddy.getName(); if (name == null) { name = buddy.getUser(); } ImageIcon enc = null; ImageIcon sig = null; if (decryptedFlag) { enc = Standard.getIcon("images/encrypted.gif"); } if (verifiedFlag) { sig = Standard.getIcon("images/signed.gif"); } if (newBody.startsWith("/me ")) { newBody = newBody.replaceAll("^\\/me ", ""); conversationArea.append(getDate(date)); conversationArea.append(" *" + name, ConversationArea.BLACK, true); conversationArea.append(extraInfo, ConversationArea.BLACK); if( sig != null ) conversationArea.appendIcon(sig); if( enc != null ) conversationArea.appendIcon(enc); conversationArea.append(" " + newBody + "\n", ConversationArea.BLACK); } else { conversationArea.append(getDate(date), ConversationArea.SENDER); conversationArea.append(" " + name, ConversationArea.SENDER, true); conversationArea.append(extraInfo, ConversationArea.BLACK); if( sig != null ) conversationArea.appendIcon(sig); if( enc != null ) conversationArea.appendIcon(enc); conversationArea.append(": " + newBody + "\n", ConversationArea.BLACK); } } }); } /** * Sends the message in the TextEntryArea * *@param allText Description of the Parameter */ public void sendHandler(String allText) { String areaTextComplete; final String areaText; if (allText != null) { areaTextComplete = allText; } else { areaTextComplete = textEntryArea.getText(); } if (!areaTextComplete.equals("")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -