From da1687b63c06d7dd9fe93840d507e6d48e13de11 Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Tue, 8 Aug 2006 17:58:11 +0000 Subject: [PATCH] Fixing ChatRoom scroll issue. git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4856 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/spark/ui/ChatRoom.java | 4 ++ .../org/jivesoftware/spark/ui/VCardPanel.java | 36 +++++++++++--- .../spark/ui/rooms/ChatRoomImpl.java | 47 +++++++++++++++++-- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/java/org/jivesoftware/spark/ui/ChatRoom.java b/src/java/org/jivesoftware/spark/ui/ChatRoom.java index c3b2c28ff..d2b5bbe0d 100644 --- a/src/java/org/jivesoftware/spark/ui/ChatRoom.java +++ b/src/java/org/jivesoftware/spark/ui/ChatRoom.java @@ -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()); } diff --git a/src/java/org/jivesoftware/spark/ui/VCardPanel.java b/src/java/org/jivesoftware/spark/ui/VCardPanel.java index df2a0c1d2..e6cae650f 100644 --- a/src/java/org/jivesoftware/spark/ui/VCardPanel.java +++ b/src/java/org/jivesoftware/spark/ui/VCardPanel.java @@ -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)); diff --git a/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java b/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java index 2cb519aa4..9c2698092 100644 --- a/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java +++ b/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java @@ -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() {