classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Stopping the DefaultCaret timer when the component loo


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Stopping the DefaultCaret timer when the component looses the focus.
Date: Tue, 22 Nov 2005 10:57:23 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

This should fix the resource leak, stopping the caret blinking timer when the caret looses the focus.

2005-11-22  Audrius Meskauskas  <address@hidden>

       * javax/swing/text/DefaultCaret.java (focusGained):
       Update timer status. (focusLost): Stop the timer
       (unless the event is temporary).
       (updateTimerStatus): New method.
       (setVisible): Delegate timer management to the updateTimerStatus.


Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.24
diff -u -r1.24 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java  17 Nov 2005 20:45:14 -0000      1.24
+++ javax/swing/text/DefaultCaret.java  22 Nov 2005 09:55:22 -0000
@@ -430,18 +430,45 @@
    */
   public void focusGained(FocusEvent event)
   {
-    setVisible(true);
+    setVisible(true);    
+    updateTimerStatus();
   }
 
   /**
    * Sets the caret to <code>invisible</code>.
-   *
+   * 
    * @param event the <code>FocusEvent</code>
    */
   public void focusLost(FocusEvent event)
   {
     if (event.isTemporary() == false)
-      setVisible(false);
+      {
+        setVisible(false);
+        // Stop the blinker, if running.
+        if (blinkTimer != null && blinkTimer.isRunning())
+          blinkTimer.stop();
+      }
+  }
+  
+  /**
+   * Install (if not present) and start the timer, if the caret must blink. The
+   * caret does not blink if it is invisible, or the component is disabled or
+   * not editable.
+   */
+  private void updateTimerStatus()
+  {
+    if (visible && textComponent.isEnabled() && textComponent.isEditable())
+      {
+        if (blinkTimer == null)
+          initBlinkTimer();
+        if (!blinkTimer.isRunning())
+          blinkTimer.start();
+      }
+    else
+      {
+        if (blinkTimer != null)
+          blinkTimer.stop();
+      }
   }
 
   /**
@@ -870,18 +897,7 @@
     if (v != visible)
       {
         visible = v;
-        if (visible)
-          if (textComponent.isEnabled() && textComponent.isEditable())
-            {
-              if (blinkTimer == null)
-                initBlinkTimer();
-              blinkTimer.start();
-            }
-        else
-          {
-            if (blinkTimer != null)
-              blinkTimer.stop();
-          }
+        updateTimerStatus();
         Rectangle area = null;
         try
           {            

reply via email to

[Prev in Thread] Current Thread [Next in Thread]