74 |
* Controls the blinking of the caret. |
* Controls the blinking of the caret. |
75 |
* |
* |
76 |
* @author Roman Kennke (kennke@aicas.com) |
* @author Roman Kennke (kennke@aicas.com) |
77 |
|
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
78 |
*/ |
*/ |
79 |
private class BlinkTimerListener implements ActionListener |
private class BlinkTimerListener implements ActionListener |
80 |
{ |
{ |
81 |
/** |
/** |
82 |
|
* Forces the next event to be ignored. The next event should be ignored |
83 |
|
* if we force the caret to appear. We do not know how long will it take |
84 |
|
* to fire the comming event; this may be near immediately. Better to leave |
85 |
|
* the caret visible one iteration longer. |
86 |
|
*/ |
87 |
|
boolean ignoreNextEvent; |
88 |
|
|
89 |
|
/** |
90 |
* Receives notification when the blink timer fires and updates the visible |
* Receives notification when the blink timer fires and updates the visible |
91 |
* state of the caret. |
* state of the caret. |
92 |
* |
* |
93 |
* @param event the action event |
* @param event the action event |
94 |
*/ |
*/ |
95 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
96 |
{ |
{ |
97 |
visible = !visible; |
if (ignoreNextEvent) |
98 |
repaint(); |
ignoreNextEvent = false; |
99 |
|
else |
100 |
|
{ |
101 |
|
visible = !visible; |
102 |
|
repaint(); |
103 |
|
} |
104 |
} |
} |
105 |
} |
} |
106 |
|
|
288 |
private Object highlightEntry; |
private Object highlightEntry; |
289 |
|
|
290 |
private Timer blinkTimer; |
private Timer blinkTimer; |
291 |
|
|
292 |
|
private BlinkTimerListener blinkListener; |
293 |
|
|
294 |
/** |
/** |
295 |
* Creates a new <code>DefaultCaret</code> instance. |
* Creates a new <code>DefaultCaret</code> instance. |
784 |
this.dot = dot; |
this.dot = dot; |
785 |
handleHighlight(); |
handleHighlight(); |
786 |
adjustVisibility(this); |
adjustVisibility(this); |
787 |
repaint(); |
appear(); |
788 |
} |
} |
789 |
|
|
790 |
/** |
/** |
802 |
this.mark = dot; |
this.mark = dot; |
803 |
handleHighlight(); |
handleHighlight(); |
804 |
adjustVisibility(this); |
adjustVisibility(this); |
805 |
repaint(); |
appear(); |
806 |
} |
} |
807 |
|
|
808 |
|
/** |
809 |
|
* Show the caret (may be hidden due blinking) and adjust the timer not to |
810 |
|
* hide it (possibly immediately). |
811 |
|
* |
812 |
|
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
813 |
|
*/ |
814 |
|
void appear() |
815 |
|
{ |
816 |
|
// All machinery is only required if the carret is blinking. |
817 |
|
if (blinkListener != null) |
818 |
|
{ |
819 |
|
blinkListener.ignoreNextEvent = true; |
820 |
|
|
821 |
|
// If the caret is visible, erase the current position by repainting |
822 |
|
// over. |
823 |
|
if (visible) |
824 |
|
repaint(); |
825 |
|
|
826 |
|
// Draw the caret in the new position. |
827 |
|
visible = true; |
828 |
|
|
829 |
|
Rectangle area = null; |
830 |
|
try |
831 |
|
{ |
832 |
|
area = getComponent().modelToView(getDot()); |
833 |
|
} |
834 |
|
catch (BadLocationException ex) |
835 |
|
{ |
836 |
|
assert false : "Unexpected bad caret location: " + getDot(); |
837 |
|
} |
838 |
|
if (area != null) |
839 |
|
damage(area); |
840 |
|
} |
841 |
|
repaint(); |
842 |
|
} |
843 |
|
|
844 |
/** |
/** |
845 |
* Returns <code>true</code> if this <code>Caret</code> is currently visible, |
* Returns <code>true</code> if this <code>Caret</code> is currently visible, |
940 |
private void initBlinkTimer() |
private void initBlinkTimer() |
941 |
{ |
{ |
942 |
// Setup the blink timer. |
// Setup the blink timer. |
943 |
blinkTimer = new Timer(getBlinkRate(), new BlinkTimerListener()); |
blinkListener = new BlinkTimerListener(); |
944 |
|
blinkTimer = new Timer(getBlinkRate(), blinkListener); |
945 |
blinkTimer.setRepeats(true); |
blinkTimer.setRepeats(true); |
946 |
} |
} |
947 |
} |
} |