Created
May 17, 2012 08:31
-
-
Save asimihsan/2717392 to your computer and use it in GitHub Desktop.
Disable Spark automatic scroll on activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/java/org/jivesoftware/spark/ui/ChatArea.java | |
=================================================================== | |
--- src/java/org/jivesoftware/spark/ui/ChatArea.java (revision 13060) | |
+++ src/java/org/jivesoftware/spark/ui/ChatArea.java (working copy) | |
@@ -298,7 +298,7 @@ | |
final Document doc = getDocument(); | |
styles.removeAttribute("link"); | |
doc.insertString(doc.getLength(), text, styles); | |
- setCaretPosition(doc.getLength()); | |
+ //setCaretPosition(doc.getLength()); | |
} | |
/** | |
@@ -312,7 +312,7 @@ | |
final Document doc = getDocument(); | |
StyleConstants.setForeground(styles, color); | |
doc.insertString(doc.getLength(), text, styles); | |
- setCaretPosition(doc.getLength()); | |
+ //setCaretPosition(doc.getLength()); | |
} | |
/** | |
@@ -332,7 +332,7 @@ | |
StyleConstants.setForeground(styles, (Color)UIManager.get("TextPane.foreground")); | |
styles.removeAttribute("link"); | |
setCharacterAttributes(styles, false); | |
- setCaretPosition(doc.getLength()); | |
+ //setCaretPosition(doc.getLength()); | |
} | |
@@ -353,7 +353,7 @@ | |
StyleConstants.setForeground(styles, (Color)UIManager.get("TextPane.foreground")); | |
styles.removeAttribute("link"); | |
setCharacterAttributes(styles, false); | |
- setCaretPosition(doc.getLength()); | |
+ //setCaretPosition(doc.getLength()); | |
} | |
@@ -376,7 +376,7 @@ | |
select(doc.getLength(), doc.getLength()); | |
insertIcon(emotion); | |
- setCaretPosition(doc.getLength()); | |
+ //setCaretPosition(doc.getLength()); | |
return true; | |
} | |
Index: src/java/org/jivesoftware/spark/ui/ChatRoom.java | |
=================================================================== | |
--- src/java/org/jivesoftware/spark/ui/ChatRoom.java (revision 13060) | |
+++ src/java/org/jivesoftware/spark/ui/ChatRoom.java (working copy) | |
@@ -63,6 +63,7 @@ | |
import javax.swing.event.DocumentListener; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.Document; | |
+import javax.swing.text.DefaultCaret; | |
import org.jivesoftware.resource.Res; | |
import org.jivesoftware.resource.SparkRes; | |
@@ -132,6 +133,8 @@ | |
protected ChatRoom() { | |
chatPanel = new JPanel(new GridBagLayout()); | |
transcriptWindow = UIComponentRegistry.createTranscriptWindow(); | |
+ DefaultCaret caret = (DefaultCaret)transcriptWindow.getCaret(); | |
+ caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); | |
splitPane = new JSplitPane(); | |
packetIDList = new ArrayList<String>(); | |
notificationLabel = new JLabel(); | |
@@ -245,6 +248,7 @@ | |
// For the first 5*150ms we wait for transcript to load and move | |
// scrollpane to max postion if size of scrollpane changed | |
+ /* | |
textScroller.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { | |
private boolean scrollAtStart = false; | |
@@ -284,8 +288,8 @@ | |
} | |
} | |
}); | |
+ */ | |
- | |
// Speed up scrolling. It was way too slow. | |
textScroller.getVerticalScrollBar().setBlockIncrement(200); | |
textScroller.getVerticalScrollBar().setUnitIncrement(20); | |
@@ -569,6 +573,7 @@ | |
newMessage.setProperty("date", new Date()); | |
transcript.add(newMessage); | |
+ //transcriptWindow.setCaretPosition(0); | |
// Add current date if this is the current agent | |
if (updateDate && transcriptWindow.getLastUpdated() != null) { | |
@@ -594,7 +599,7 @@ | |
newMessage.setFrom(from); | |
newMessage.setBody(body); | |
newMessage.setProperty("date", date); | |
- transcript.add(newMessage); | |
+ transcript.add(newMessage); | |
} | |
/** | |
@@ -605,16 +610,29 @@ | |
return; | |
} | |
+ //final JScrollBar scrollBar = textScroller.getVerticalScrollBar(); | |
+ //int maxValue = scrollBar.getMaximum(); | |
+ //int currentValue = scrollBar.getValue(); | |
int lengthOfChat = transcriptWindow.getDocument().getLength(); | |
- transcriptWindow.setCaretPosition(lengthOfChat); | |
+ /* | |
+ if ((maxValue - currentValue) <= 100) { | |
+ transcriptWindow.setCaretPosition(lengthOfChat); | |
+ } | |
+ */ | |
try { | |
final JScrollBar scrollBar = textScroller.getVerticalScrollBar(); | |
EventQueue.invokeLater(new Runnable() { | |
@Override | |
- public void run() { | |
- scrollBar.setValue(scrollBar.getMaximum()); | |
+ public void run() { | |
+ int maxValue = scrollBar.getMaximum(); | |
+ int currentValue = scrollBar.getValue(); | |
+ /* | |
+ if ((maxValue - currentValue) <= 100) { | |
+ scrollBar.setValue(maxValue); | |
+ } | |
+ */ | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment