Fixing ChatRoom scroll issue.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4856 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-08-08 17:58:11 +00:00
committed by derek
parent 8420a4fd03
commit da1687b63c
3 changed files with 78 additions and 9 deletions

View File

@ -34,6 +34,7 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
@ -354,6 +355,9 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
int chatLength = transcriptWindow.getDocument().getLength();
transcriptWindow.setCaretPosition(chatLength);
JScrollBar sb = textScroller.getVerticalScrollBar();
sb.setValue(sb.getMaximum());
}

View File

@ -16,23 +16,22 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.packet.Time;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.borders.PartialLineBorder;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.profile.VCardManager;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
/**
* UI to display VCard Information in Wizards, Dialogs, Chat Rooms and any other container.
*
@ -45,6 +44,7 @@ public class VCardPanel extends JPanel {
/**
* Generate a VCard Panel using the specified jid.
*
* @param jid the jid to use when retrieving the vcard information.
*/
public VCardPanel(final String jid) {
@ -89,6 +89,30 @@ public class VCardPanel extends JPanel {
worker.start();
}
public VCardPanel(VCard vcard, String jid) {
setLayout(new GridBagLayout());
setOpaque(false);
this.jid = jid;
avatarImage = new JLabel();
byte[] bytes = vcard.getAvatar();
if (bytes != null) {
try {
ImageIcon icon = new ImageIcon(bytes);
icon = VCardManager.scale(icon);
if (icon.getIconWidth() > 0) {
avatarImage.setIcon(icon);
avatarImage.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));
}
setupUI(vcard);
}
catch (Exception e) {
Log.error(e);
}
}
}
private void setupUI(VCard vcard) {
add(avatarImage, new GridBagConstraints(0, 0, 1, 4, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

View File

@ -25,6 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.MessageEventManager;
import org.jivesoftware.smackx.MessageEventNotificationListener;
import org.jivesoftware.smackx.MessageEventRequestListener;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.ui.ChatRoomButton;
@ -35,6 +36,7 @@ import org.jivesoftware.spark.ui.RosterDialog;
import org.jivesoftware.spark.ui.VCardPanel;
import org.jivesoftware.spark.ui.status.StatusItem;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.profile.VCardManager;
@ -213,9 +215,48 @@ public class ChatRoomImpl extends ChatRoom {
messageEventRequestListener = new ChatMessageEventRequestListener();
SparkManager.getMessageEventManager().addMessageEventRequestListener(messageEventRequestListener);
// Add VCard Panel
final VCardPanel vcardPanel = new VCardPanel(getParticipantJID());
getToolBar().add(vcardPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
SwingWorker worker = new SwingWorker() {
public Object construct() {
return SparkManager.getVCardManager().getVCard(participantJID);
}
public void finished() {
final VCard vcard = (VCard)get();
if (vcard == null) {
// Do nothing.
return;
}
// Add VCard Panel
final VCardPanel vcardPanel = new VCardPanel(vcard, participantJID);
getToolBar().add(vcardPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
scrollOnTimer();
}
};
worker.start();
}
private void scrollOnTimer() {
SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
e.printStackTrace();
}
return true;
}
public void finished() {
scrollToBottom();
}
};
worker.start();
}
public void closeChatRoom() {