/[classpath]/classpath/javax/swing/text/DefaultCaret.java
ViewVC logotype

Diff of /classpath/javax/swing/text/DefaultCaret.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22 by rabbit78, Thu Nov 3 23:19:34 2005 UTC revision 1.23 by audriusa, Tue Nov 8 23:42:56 2005 UTC
# Line 74  public class DefaultCaret extends Rectan Line 74  public class DefaultCaret extends Rectan
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    
# Line 274  public class DefaultCaret extends Rectan Line 288  public class DefaultCaret extends Rectan
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.
# Line 768  public class DefaultCaret extends Rectan Line 784  public class DefaultCaret extends Rectan
784      this.dot = dot;      this.dot = dot;
785      handleHighlight();      handleHighlight();
786      adjustVisibility(this);      adjustVisibility(this);
787      repaint();      appear();
788    }    }
789    
790    /**    /**
# Line 786  public class DefaultCaret extends Rectan Line 802  public class DefaultCaret extends Rectan
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,
# Line 888  public class DefaultCaret extends Rectan Line 940  public class DefaultCaret extends Rectan
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  }  }

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26