From 59d65bedc3972094a87b2ddf7c496c2255f0a04e Mon Sep 17 00:00:00 2001 From: eg3p Date: Sat, 2 Nov 2002 20:10:05 +0000 Subject: [PATCH] Change scrolling policy w/in Savant. Now highlighted text stays in the middle of the window instead of at the bottom. --- .../org/thdl/savant/TextHighlightPlayer.java | 18 +++++++++++++++--- source/org/thdl/savant/TwoWayTextPlayer.java | 5 +++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/source/org/thdl/savant/TextHighlightPlayer.java b/source/org/thdl/savant/TextHighlightPlayer.java index 87c0452..9e6dcfd 100644 --- a/source/org/thdl/savant/TextHighlightPlayer.java +++ b/source/org/thdl/savant/TextHighlightPlayer.java @@ -23,6 +23,7 @@ import java.util.*; import javax.swing.*; import javax.swing.text.*; import java.awt.event.MouseListener; +import java.awt.event.ComponentAdapter; import org.thdl.util.ThdlDebug; @@ -32,6 +33,7 @@ public class TextHighlightPlayer extends JPanel implements AnnotationPlayer protected Hashtable hashStart, hashEnd, highlights; protected Highlighter highlighter; protected Highlighter.HighlightPainter highlightPainter; + protected JViewport viewport; public TextHighlightPlayer(TranscriptView view, Color highlightcolor) { @@ -100,12 +102,22 @@ public class TextHighlightPlayer extends JPanel implements AnnotationPlayer int end = endInt.intValue(); Object tag = highlighter.addHighlight(start, end, highlightPainter); highlights.put(id, tag); - try - { + + // scrolls highlighted text to middle of viewport + JViewport viewport = (JViewport)SwingUtilities.getAncestorOfClass(JViewport.class, text); + int halfViewHeight = viewport.getExtentSize().height / 2; + Rectangle textRectangle = text.modelToView(end); + int yFactor = textRectangle.y - halfViewHeight; + if (yFactor > 0) { + viewport.setViewPosition(new Point(0, yFactor)); + text.repaint(); + } + +/* this does scrolling at the bottom of the text window Rectangle rect = text.modelToView(end); text.scrollRectToVisible(rect); text.repaint(); - } catch (BadLocationException ble) {} +*/ } catch (BadLocationException ble) { diff --git a/source/org/thdl/savant/TwoWayTextPlayer.java b/source/org/thdl/savant/TwoWayTextPlayer.java index f73cc18..440ccc6 100644 --- a/source/org/thdl/savant/TwoWayTextPlayer.java +++ b/source/org/thdl/savant/TwoWayTextPlayer.java @@ -30,17 +30,18 @@ import java.util.Enumeration; import java.util.NoSuchElementException; import javax.swing.text.JTextComponent; +import org.thdl.media.SmartMoviePanel; import org.thdl.util.ThdlDebug; public class TwoWayTextPlayer extends TextHighlightPlayer { protected TreeMap orderedOffsets = null; - protected SoundPanel sound = null; + protected SmartMoviePanel sound = null; protected long doubleClickDelay = 300L; protected long lastClickTime; protected Point lastClickPoint = null; - public TwoWayTextPlayer(SoundPanel sp, TranscriptView view, Color highlightColor) + public TwoWayTextPlayer(SmartMoviePanel sp, TranscriptView view, Color highlightColor) { super(view, highlightColor); sound = sp;