Fixes a problem with automatic scrolling to the last received message when a new chat tab is open.

cusax-fix
Yana Stamcheva 17 years ago
parent df7dc66cb5
commit eafedb3be4

@ -442,7 +442,7 @@ public void appendMessageToEnd(String chatString)
this.ensureDocumentSize();
// Scroll to the last inserted text in the document.
this.setCarretToEnd();
this.scrollToBottom();
}
/**
@ -472,7 +472,7 @@ public void insertMessageAfterStart(String chatString)
this.ensureDocumentSize();
// Scroll to the last inserted text in the document.
this.setCarretToEnd();
this.scrollToBottom();
}
/**
@ -550,11 +550,13 @@ private void ensureDocumentSize()
* Highlights keywords searched in the history.
*
* @param message the source message
* @param contentType the content type
* @param keyword the searched keyword
* @return the formatted message
*/
private String processKeyword(String message, String contentType,
String keyword)
private String processKeyword( String message,
String contentType,
String keyword)
{
String startPlainTextTag;
String endPlainTextTag;
@ -710,8 +712,9 @@ private String processNewLines(String message)
/**
* Formats message smileys.
*
* @param message The source message string.
* @return The message string with properly formated smileys.
* @param message the source message string
* @param contentType the content type
* @return the message string with properly formated smileys
*/
private String processSmileys(String message, String contentType)
{
@ -866,12 +869,16 @@ public long getLastIncomingMsgTimestamp()
/**
* Moves the caret to the end of the editor pane.
*/
public void setCarretToEnd()
public void scrollToBottom()
{
int documentLength = document.getLength();
if (chatTextPane.getDocument().getLength() == documentLength)
chatTextPane.setCaretPosition(documentLength);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
getVerticalScrollBar()
.setValue(getVerticalScrollBar().getMaximum());
}
});
}
/**
@ -931,25 +938,15 @@ private void openContextMenu(Point p)
rightButtonMenu.setVisible(true);
}
public void mousePressed(MouseEvent e)
{
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e)
{
}
public void mouseExited(MouseEvent e) {}
public void lostOwnership(Clipboard clipboard, Transferable contents)
{
}
public void lostOwnership(Clipboard clipboard, Transferable contents) {}
/**
* Returns the chat container.
@ -1169,7 +1166,7 @@ private String processImgTags(String message)
}
/**
* Extend Editor pane to add url tooltips.
* Extend Editor pane to add URL tooltips.
*/
private class MyTextPane
extends JTextPane
@ -1177,6 +1174,7 @@ private class MyTextPane
/**
* Returns the string to be used as the tooltip for <i>event</i>.
*
* @param event the <tt>MouseEvent</tt>
* @return the string to be used as the tooltip for <i>event</i>.
*/
public String getToolTipText(MouseEvent event)
@ -1231,7 +1229,7 @@ public void addComponent(ChatConversationComponent component)
logger.error("Insert in the HTMLDocument failed.", e);
}
this.setCarretToEnd();
this.scrollToBottom();
}
/**

@ -89,6 +89,9 @@ public class ChatPanel
*/
public static final int TYPING_NOTIFICATION_SEND_FAILED = 0;
/**
* The number of messages shown per page.
*/
protected static final int MESSAGES_PER_PAGE = 20;
private boolean isShown = false;
@ -155,6 +158,10 @@ public ChatPanel(ChatWindow chatWindow)
this.addComponentListener(new TabSelectionComponentListener());
}
/**
* Sets the chat session to associate to this chat panel.
* @param chatSession the chat session to associate to this chat panel
*/
public void setChatSession(ChatSession chatSession)
{
this.chatSession = chatSession;
@ -282,15 +289,20 @@ else if (chatSession instanceof ConferenceChatSession)
sendSmsCheckBox.setEnabled(false);
}
/**
* Returns the chat session associated with this chat panel.
* @return the chat session associated with this chat panel
*/
public ChatSession getChatSession()
{
return chatSession;
}
/**
* Shows or hides the Stylebar depending on the value of parameter b.
*
* @param b if true, makes the Stylebar visible, otherwise hides the Stylebar
* @param b if true, makes the Stylebar visible, otherwise hides the
* Stylebar
*/
public void setStylebarVisible(boolean b)
{
@ -399,7 +411,7 @@ public void componentShown(ComponentEvent evt)
}
/**
* Moves the caret to the end of the conversation panel, contained in the
* Scrolls to the bottom of the conversation panel, contained in the
* given chat panel.
*
* Workaround for the following problem:
@ -410,10 +422,10 @@ public void componentShown(ComponentEvent evt)
* conversation area is slightly resized and is made smaller,
* which moves the scrollbar up.
*/
public void setCaretToEnd()
public void scrollConversationToBottom()
{
//Scroll to the last inserted text in the document.
getChatConversationPanel().setCarretToEnd();
getChatConversationPanel().scrollToBottom();
}
/**
@ -650,7 +662,8 @@ public void addErrorMessage(String contactName,
/**
* Adds the given error message to the chat window conversation area.
*
* @param contactName the name of the contact, for which the error occured
* @param contactName the name of the contact, for which the error occurred
* @param title the title of the error
* @param message the error message
*/
public void addErrorMessage(String contactName,
@ -725,6 +738,7 @@ public void addTextInWriteArea(String text){
/**
* Returns the text contained in the write area editor.
* @param mimeType the mime type
* @return The text contained in the write area editor.
*/
public String getTextFromWriteArea(String mimeType)
@ -1529,6 +1543,7 @@ public void setSelectedChatTransport(ChatTransport chatTransport)
/**
* Updates the status of the given chat transport in the send via selector
* box and notifies the user for the status change.
* @param chatTransport the <tt>chatTransport</tt> to update
*/
public void updateChatTransportStatus(ChatTransport chatTransport)
{
@ -1679,8 +1694,13 @@ public void removeChatContact(ChatContact chatContact)
chatContactListPanel.removeContact(chatContact);
}
/**
* Updates the contact status.
* @param chatContact the chat contact to update
* @param statusMessage the status message to show
*/
public void updateChatContactStatus(ChatContact chatContact,
String statusMessage)
String statusMessage)
{
this.addMessage(
chatContact.getName(),
@ -1690,6 +1710,10 @@ public void updateChatContactStatus(ChatContact chatContact,
ChatConversationPanel.TEXT_CONTENT_TYPE);
}
/**
* Sets the given <tt>subject</tt> to this chat.
* @param subject the subject to set
*/
public void setChatSubject(String subject)
{
if (subjectPanel != null)
@ -1712,6 +1736,7 @@ public void setChatSubject(String subject)
* Adds the given <tt>IncomingFileTransferRequest</tt> to the conversation
* panel in order to notify the user of the incoming file.
*
* @param fileTransferOpSet the file transfer operation set
* @param request the request to display in the conversation panel
* @param date the date on which the request has been received
*/
@ -1849,6 +1874,12 @@ public ChatTransport findInviteChatTransport()
return null;
}
/**
* Invites the given <tt>chatContacts</tt> to this chat.
* @param inviteChatTransport the chat transport to use to send the invite
* @param chatContacts the contacts to invite
* @param reason the reason of the invite
*/
public void inviteContacts( ChatTransport inviteChatTransport,
Collection<String> chatContacts,
String reason)
@ -1940,6 +1971,8 @@ public void fireChatFocusEvent(int eventID)
/**
* Handles file transfer status changed in order to remove completed file
* transfers from the list of active transfers.
* @param event the file transfer status change event the notified us for
* the change
*/
public void statusChanged(FileTransferStatusChangeEvent event)
{
@ -2043,6 +2076,7 @@ else if (incomingEvent instanceof ChatConversationComponent)
* transfers.
*
* @param id the identifier of the file transfer to add
* @param descriptor the descriptor of the file transfer
*/
public void addActiveFileTransfer(String id, Object descriptor)
{

@ -233,11 +233,8 @@ public void setStylebarVisible(boolean b)
}
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.impl.gui.customcontrols.SIPCommFrame#dispose()
/**
* @see SIPCommFrame#dispose()
*/
public void dispose()
{
@ -333,7 +330,7 @@ else if (getChatTabCount() == 0)
// is added to the tabbed pane. Then the scrollpane in the
// conversation area is slightly resized and is made smaller,
// which moves the scrollbar up.
currentChatPanel.setCaretToEnd();
currentChatPanel.scrollConversationToBottom();
//add the chatTabbedPane to the window
this.mainPanel.add(chatTabbedPane, BorderLayout.CENTER);
@ -659,6 +656,7 @@ public void actionPerformed(ActionEvent e)
/**
* Returns the time of the last received message.
*
* @param chatPanel the chat panel for which w're getting the timestamp
* @return The time of the last received message.
*/
public long getLastIncomingMsgTimestamp(ChatPanel chatPanel)
@ -687,6 +685,8 @@ public void windowDeiconified(WindowEvent e)
/**
* Implements the <tt>SIPCommFrame</tt> close method. We check for an open
* menu and if there's one we close it, otherwise we close the current chat.
* @param isEscaped indicates if this window was closed by pressing the esc
* button
*/
protected void close(boolean isEscaped)
{
@ -728,7 +728,8 @@ else if ((menuBar.getSelectedMenu() != null)
/**
* Implements the <tt>ExportedWindow.getIdentifier()</tt> method.
* Returns the identifier of this window, which will
* @return the identifier of this window, used as plugin container
* identifier.
*/
public WindowID getIdentifier()
{
@ -825,6 +826,11 @@ private void initPluginComponents()
GuiActivator.getUIService().addPluginComponentListener(this);
}
/**
* Adds a plugin component to this container.
* @param event the <tt>PluginComponentEvent</tt> that notified us of the
* add
*/
public void pluginComponentAdded(PluginComponentEvent event)
{
PluginComponent c = event.getPluginComponent();
@ -841,6 +847,11 @@ public void pluginComponentAdded(PluginComponentEvent event)
}
}
/**
* Removes a plugin component from this container.
* @param event the <tt>PluginComponentEvent</tt> that notified us of the
* remove
*/
public void pluginComponentRemoved(PluginComponentEvent event)
{
PluginComponent c = event.getPluginComponent();
@ -878,6 +889,10 @@ public int getChatCount()
return chatCount;
}
/**
* Adds the given <tt>ChatChangeListener</tt>.
* @param listener the listener to add
*/
public void addChatChangeListener(ChatChangeListener listener)
{
synchronized (chatChangeListeners)
@ -887,6 +902,10 @@ public void addChatChangeListener(ChatChangeListener listener)
}
}
/**
* Removes the given <tt>ChatChangeListener</tt>.
* @param listener the listener to remove
*/
public void removeChatChangeListener(ChatChangeListener listener)
{
synchronized (chatChangeListeners)
@ -900,6 +919,7 @@ public void removeChatChangeListener(ChatChangeListener listener)
* given constraints.
*
* @param c the component to add
* @param container the plugin container
* @param constraints the constraints determining the container
*/
private void addPluginComponent(Component c,
@ -942,6 +962,7 @@ else if (container.equals(Container.CONTAINER_CHAT_STATUS_BAR))
* constraints.
*
* @param c the component to remove
* @param container the plugin container
* @param constraints the constraints determining the container
*/
private void removePluginComponent( Component c,
@ -1094,7 +1115,8 @@ public void setChatSession(ChatSession chatSession)
}
/**
* Create tooltip.
* Creates a tooltip.
* @return the created tool tip
*/
public JToolTip createToolTip()
{
@ -1137,6 +1159,7 @@ public JToolTip createToolTip()
* each time in order to make the TooltipManager change the tooltip over
* the different cells in the JList.
*
* @param event the <tt>MouseEvent</tt>
* @return the string to be used as the tooltip for <i>event</i>.
*/
public String getToolTipText(MouseEvent event)
@ -1152,14 +1175,14 @@ public void setParams(Object[] windowParams) {}
/**
* Handles <tt>WindowEvent</tt>s triggered when the window has gained focus.
* @param evt the <tt>WindowEvent</tt>
*/
public void windowGainedFocus(WindowEvent evt)
{
this.removeNonReadChatState();
}
public void windowLostFocus(WindowEvent arg0)
{}
public void windowLostFocus(WindowEvent arg0) {}
/**
* Removes the non read state of the currently selected chat session. This
@ -1232,15 +1255,20 @@ public void paintComponent(Graphics g)
}
/**
*
* Sends all files from the given directory when it's dropped in the chat
* window.
* @param dir the directory to send
* @param point the point, where the directory was dropped
*/
public void directoryDropped(File file, Point point)
public void directoryDropped(File dir, Point point)
{
//TODO: Implement send directory
}
/**
*
* Sends the given file when dropped to the chat window.
* @param file the file to send
* @param point the point, where the file was dropped
*/
public void fileDropped(File file, Point point)
{

@ -94,7 +94,7 @@ else if(!chatWindow.getCurrentChatPanel().equals(chatPanel)
{
chatWindow.highlightTab(chatPanel);
chatPanel.setCaretToEnd();
chatPanel.scrollConversationToBottom();
}
}
else
@ -102,7 +102,7 @@ else if(!chatWindow.getCurrentChatPanel().equals(chatPanel)
chatWindow.setVisible(true);
chatWindow.setCurrentChatPanel(chatPanel);
chatPanel.setCaretToEnd();
chatPanel.scrollConversationToBottom();
}
}
}

Loading…
Cancel
Save