📄 bschatwindow.java
字号:
else
chatTextPane.append("<" + nick + ">", BSAutoScrollTextPane.MY_NICK_STYLE);
if (timeStamp != null)
chatTextPane.append(" [" + timeStamp + "]", BSAutoScrollTextPane.TIME_STAMP_STYLE);
if (body != null)
chatTextPane.append(" " + body, BSAutoScrollTextPane.REGULAR_STYLE);
if (oobDesc != null && (body == null || -1 == body.indexOf(oobDesc)))
chatTextPane.append(" " + oobDesc + " ", BSAutoScrollTextPane.URL_DESC_STYLE);
if (oobURL != null)
chatTextPane.append(oobURL, BSAutoScrollTextPane.URL_STYLE);
chatTextPane.append("\n", BSAutoScrollTextPane.REGULAR_STYLE);
}
}
/** Adds received message body into chat window */
/*public void addReceivedMessage(String body) {
chatTextPane.append("<" + nick + "> ", BSAutoScrollTextPane.BUDDY_NICK_STYLE);
chatTextPane.append(body + "\n", BSAutoScrollTextPane.REGULAR_STYLE);
// stores msg to history
History.storeMessage(new JID(BSMainFrame.username, BSMainFrame.server, null),
jid, nick, null, body);
}*/
/** Adds received message packet into chat window */
public void addReceivedMessage(Message msg) {
if (msg == null) return;
handleMessageEvents(msg);
addMessageIntoChatPane(msg, nick, true);
// stores msg to history
History.storeIncomingMessage(msg, nick);
}
/** Handles message events extension, if present */
public void handleMessageEvents(Message msg) {
if (msg == null) return;
XEvent event = null;
Enumeration exts = msg.Extensions();
while (exts.hasMoreElements()) {
Extension e = (Extension) exts.nextElement();
if (e instanceof XEvent) {
event = (XEvent)e;
}
}
// if no event or request
if (event == null || (event != null && event.getID() == null)) {
// a message from buddy cancels his composing
typingLabel.setIcon(emptyIcon);
typingLabel.setToolTipText("buddy cancelled composing of message");
sendComposingEvents = false;
stopComposing();
}
// if request for sending of message events
if (event != null && event.getID() == null) {
if (event.isDisplayed())
sendDisplayedEvent(msg);
if (event.isComposing()) {
sendComposingEvents = true;
id = msg.getIdentifier();
}
}
}
protected void sendDisplayedEvent(Message displayedMsg) {
if (displayedMsg == null) return;
try {
XEventBuilder eb = new XEventBuilder();
eb.setIsDisplayed(true);
eb.setID(displayedMsg.getIdentifier());
MessageBuilder mb = new MessageBuilder();
mb.setToAddress(displayedMsg.getFromAddress());
mb.addExtension(eb.build());
mb.setType(displayedMsg.getType());
if (winMan != null)
((BSChatWinManager)winMan).sendMessage((Message)mb.build());
} catch (InstantiationException e) { }
}
/** Sends composing cancelled event */
protected void sendComposingCancelled() {
try {
XEventBuilder eb = new XEventBuilder();
eb.setID(id);
MessageBuilder mb = new MessageBuilder();
mb.setToAddress(jid);
mb.addExtension(eb.build());
if (winMan != null)
((BSChatWinManager)winMan).sendMessage((Message)mb.build());
} catch (InstantiationException e) { }
}
/** Sends composing event */
protected void sendComposing() {
try {
XEventBuilder eb = new XEventBuilder();
eb.setIsComposing(true);
if (id != null) eb.setID(id);
else eb.setID("an-id");
MessageBuilder mb = new MessageBuilder();
mb.setToAddress(jid);
mb.addExtension(eb.build());
if (winMan != null)
((BSChatWinManager)winMan).sendMessage((Message)mb.build());
} catch (InstantiationException e) { }
}
/** Stops composing = stops timer and sends composing cancelled event */
synchronized protected void stopComposing() {
if (composingTimer != null)
composingTimer.stop();
composingTimer = null;
if (sendComposingEvents) sendComposingCancelled();
}
/** Sets composing = (re)starts timer and sends composing cancelled event
* if necessary */
synchronized protected void setComposing() {
if (!sendComposingEvents) return;
if (composingTimer == null) {
composingTimer = new javax.swing.Timer(COMPOSING_TIME_OUT, new ActionListener() {
public void actionPerformed(ActionEvent e) {
stopComposing();
}
});
composingTimer.setInitialDelay(COMPOSING_TIME_OUT);
sendComposing();
}
composingTimer.restart();
}
/** Removes itself from listening */
public void cancelListening() {
if (composingTimer != null)
stopComposing();
((BSChatWinManager)winMan).updateNewMessageFlags(this, false);
if (videoBean != null)
videoBean.removeVideoConferenceListener(this);
}
/** Displays change of presence in chat window */
public void presenceChanged(BSPresenceInfo pi) {
String timeStamp = History.getCurrentTimeStamp();
if (pi == null)
chatTextPane.append("[" + timeStamp + "] " + nick + " is now " +
BSPresenceInfo.FRIENDLY_SHOW_OFFLINE + "\n",
BSAutoScrollTextPane.PRESENCE_STYLE);
else {
String status = pi.getStatus();
if (status == null) status = "";
chatTextPane.append("[" + timeStamp + "] " + nick + " is now " +
pi.getFriendlyShow() + " (" + status + ")\n",
BSAutoScrollTextPane.PRESENCE_STYLE);
}
// when not online
if (pi == null || !pi.isOnline()) {
// obviously cannot be composing...
typingLabel.setIcon(emptyIcon);
typingLabel.setToolTipText("buddy cancelled composing of message");
sendComposingEvents = false;
stopComposing();
}
}
/** Handles actions from buttons */
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == closeButton) {
if (winMan != null) {
winMan.closeWindow(this);
}
}
else if (evt.getSource() == sendButton) {
sendMessage();
focusToWriteArea();
}
else if (evt.getSource() == historyButton) {
loadHistory();
focusToWriteArea();
}
else if (evt.getSource() == enterSendsCheckBox) {
enterSends = enterSendsCheckBox.isSelected();
focusToWriteArea();
}
else if (evt.getSource() == dockButton) {
if (winMan != null) {
winMan.setWindowDocked(this, !docked);
Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
"images/dock.gif" : "images/float.gif"));
dockButton.setIcon(icon);
dockButton.setToolTipText(docked? "Float" : "Dock");
winMan.selectWindow(this);
}
focusToWriteArea();
}
else if (evt.getSource() == urlButton) {
BSSendURLDialog dlg = new BSSendURLDialog(docked?
((BSChatWinManager)winMan).mainFrame : frame);
dlg.setVisible(true);
if (dlg.url != null && dlg.desc != null) {
sendURL(dlg.url, dlg.desc);
}
}
else if (evt.getSource() == videoButton) {
if (winMan != null) {
videoBean.requestLaunch(this);
}
}
}
public void sendURL(String url, String desc)
{
if (winMan == null) return;
Message msg = ((BSChatWinManager)winMan).sendURL(jid, thread, url, desc);
// stores msg to history
History.storeMessage(new JID(BSMainFrame.username, BSMainFrame.server, null),
jid, local, msg, false);
addMessageIntoChatPane(msg, local, false);
}
/** Handles key strokes - sends on ENTER */
public void keyTyped(KeyEvent evt) {
if (newMsg) {
setNewMsg(false);
((BSChatWinManager)winMan).updateNewMessageFlags(this, false);
}
if (enterSends) {
if (evt.getKeyChar() == '\n') {
String msg = writeTextArea.getText();
if (msg.charAt(writeTextArea.getCaretPosition()-1) == '\n')
msg = msg.substring(0, writeTextArea.getCaretPosition()-1)
+ msg.substring(writeTextArea.getCaretPosition());
writeTextArea.setText(msg);
sendMessage();
}
}
}
/** Updates the composing event status */
public void keyPressed(KeyEvent evt) {
setComposing();
}
/** Empty implementation */
public void keyReleased(KeyEvent keyEvent) { }
public void itemStateChanged(ItemEvent evt) {
if (evt.getStateChange() == ItemEvent.SELECTED &&
smiliesCombo.getSelectedIndex() != 0) {
String smileyStr = ((ImageIcon)evt.getItem()).getDescription();
if (smileyStr != null) {
writeTextArea.append(" " + smileyStr + " ");
}
smiliesCombo.setSelectedIndex(0);
focusToWriteArea();
}
}
public void booking(String url, String info)
{
if (url == null) return;
videoBean.open(url);
String msg = "[New FlashMeeting created]\n" + url +
"\nClick on the FlashMeeting button to join the meeting or enter URL in browser.";
addMessageToWindow(msg);
availability(url, info);
videoBean.notifyAvailability(jid, msg, getBookingID());
//sendURL(url, "");
}
public void launch(String url, String info)
{
if (url == null)
{
videoBean.requestBooking(this);
return;
}
videoBean.open(url);
sendMessage("[Joined FlashMeeting]\n" + url, false);
//sendURL(url, "");
}
public void availability(String url, String info)
{
if (url != null)
{
Icon videoIcon = new ImageIcon(ClassLoader.getSystemResource("images/flashmeeting-active.gif"));
videoButton.setIcon(videoIcon);
}
}
public void authorization(Boolean canCreateBooking)
{
if (Boolean.TRUE.equals(canCreateBooking))
{
Icon videoIcon = new ImageIcon(ClassLoader.getSystemResource(
"images/flashmeeting-normal.gif"));
videoButton.setIcon(videoIcon);
}
videoBean.requestAvailability(this);
}
public String [] getBookingPeople()
{
String him = jid.toSimpleString().toLowerCase();
String me = getBookingJID();
return new String[] { me, him };
}
public String getBookingID()
{
String him = jid.toSimpleString().toLowerCase();
String me = getBookingJID();
String bid;
// make a unique booking id for this pair of users
if (him.compareTo(me) > 0)
{
bid = me + "-" + him;
} else {
bid = him + "-" + me;
}
return bid;
}
public String getBookingJID()
{
String jid = BSMainFrame.username + "@" + BSMainFrame.server;
return jid.toLowerCase();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -