Change scrolling policy w/in Savant. Now highlighted text stays in the middle of the window instead of at the bottom.
This commit is contained in:
parent
e8dacead31
commit
59d65bedc3
2 changed files with 18 additions and 5 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue