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;