📄 chatpanel.java
字号:
public JSplitPane getSplitPane() { return container; } /** * Listens for the user to move the divider, and saves it's location * * @author Adam Olsen * @version 1.0 */ private class DividerListener implements PropertyChangeListener { 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()); } } /** * Updates the ConversationArea's font * * @param font * the font to update to */ public void updateStyle(Font font) { conversationArea.loadStyleSheet(font); } /** * 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 synchronized void updateResources() { SwingUtilities.invokeLater(new Runnable() { public void run() { if (selected == null) selected = ""; 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, 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(); Emoticons.getInstance().displayEmoticonChooser(f, emoteButton, textEntryArea); } }); eventButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFrame f = frame; if (f == null) f = BuddyList.getInstance().getTabFrame(); Events events = new Events(); events.setEvents(f, eventButton,buddy); } }); 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(); } }; //for making it so they can select text in the window and not have it // lose focus on them conversationArea.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { conversationArea.grabFocus(); } }); conversationArea.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { //only request focus to the input box if there is no text // selected if (conversationArea.getSelectedText() == null) textEntryArea.requestFocus(); else conversationArea.grabFocus(); } public void focusLost(FocusEvent e) { } }); conversationArea.addMouseListener(new RightClickListener(popMenu)); CopyPasteContextMenu.registerComponent(conversationArea); 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); } 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("<font color='green'>" + getDate(null) + "<b> " + buddy.getName() + " " + resources.getString("signedOff") + "</b></font>"); } }); } /** * Displays a message in the window when a buddy signs on */ public void signedOn() { SwingUtilities.invokeLater(new Runnable() { public void run() { conversationArea.append("<font color='green'>" + getDate(null) + "<b> " + buddy.getName() + " " + resources.getString("signedOn") + "</b></font>"); } }); } /** * Displays a "disconnected" message" */ public void disconnected() { conversationArea.append("<b>" + getDate(null) + " **** " + resources.getString("disconnected") + ""); chats = new Hashtable(); } public void messageEvent(String text) { conversationArea.append("<b>" + getDate(null) + " **** " + text + ""); } /** * 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 */ 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) resourceBox.setSelectedItem(resource); resourceBox.validate(); String newBody = ConversationText .replaceText(body, false, true); String name = buddy.getName(); if (name == null) name = buddy.getUser(); if (decryptedFlag) { URL enc = Standard.getURL("images/encrypted.gif"); extraInfo = extraInfo + (" <img src=\"" + enc.toString() + "\"> "); } if (verifiedFlag) { URL sig = Standard.getURL("images/signed.gif"); extraInfo = extraInfo + (" <img src=\"" + sig.toString() + "\"> "); } if (newBody.startsWith(" /me ")) { newBody = newBody.replaceAll("^ \\/me ", ""); conversationArea.append(getDate(date) + " <b>* " + name + "</font></b>" + extraInfo + " " + newBody); } else { conversationArea.append("<font color='#16569e'>" + getDate(date) + " <b>" + name + "</b></font>" + extraInfo + ": " + newBody); } } }); } /** * Sends the message in the TextEntryArea */ public void sendHandler(String allText) { String areaTextComplete; final String areaText; if (allText != null) { areaTextComplete = allText; } else { areaTextComplete = textEntryArea.getText(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -