From tchemit@users.nuiton.org Sat Mar  9 15:02:50 2013
From: tchemit@users.nuiton.org
To: jaxx-commits@list.nuiton.org
Subject: [Jaxx-commits] r2603 -
	trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help
Date: Sat, 09 Mar 2013 15:02:50 +0100
Message-ID: <20130309140250.668DC15A1F@nuiton.codelutin.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============5495776912971014032=="

--===============5495776912971014032==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Author: tchemit
Date: 2013-03-09 15:02:50 +0100 (Sat, 09 Mar 2013)
New Revision: 2603

Url: http://nuiton.org/projects/jaxx/repository/revisions/2603

Log:
fixes #2579: Improve JAXXHelpBroker

Modified:
   trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.ja=
va

Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBr=
oker.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.j=
ava	2013-03-09 07:21:41 UTC (rev 2602)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.j=
ava	2013-03-09 14:02:50 UTC (rev 2603)
@@ -24,6 +24,7 @@
  */
 package jaxx.runtime.swing.help;
=20
+import com.google.common.base.Preconditions;
 import jaxx.runtime.JAXXContext;
 import jaxx.runtime.JAXXObject;
 import jaxx.runtime.SwingUtil;
@@ -33,6 +34,7 @@
 import javax.help.CSH;
 import javax.help.HelpBroker;
 import javax.help.HelpSet;
+import javax.help.plaf.basic.BasicCursorFactory;
 import javax.swing.AbstractButton;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
@@ -53,6 +55,7 @@
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
 import java.net.URL;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -230,15 +233,20 @@
=20
             // prepare cursor
             onItemCursor =3D (Cursor) UIManager.get("HelpOnItemCursor");
+
+            if (onItemCursor =3D=3D null) {
+                onItemCursor =3D BasicCursorFactory.getOnItemCursor();
+                UIManager.put("HelpOnItemCursor", onItemCursor);
+            }
+            Preconditions.checkNotNull(onItemCursor, "A cursor is missing (a=
dd HelpOnItemCursor cursor in UIManager).");
             Vector<?> topComponents =3D null;
             cursors =3D null;
=20
             if (onItemCursor !=3D null) {
                 cursors =3D new Hashtable<Component, Cursor>();
                 topComponents =3D getTopContainers(source);
-                Enumeration<?> enums =3D topComponents.elements();
-                while (enums.hasMoreElements()) {
-                    setAndStoreCursors((Container) enums.nextElement(), onIt=
emCursor);
+                for (Object topComponent : topComponents) {
+                    setAndStoreCursors((Container) topComponent, onItemCurso=
r);
                 }
             }
=20
@@ -261,9 +269,8 @@
             } finally {
                 // restore the old cursors
                 if (topComponents !=3D null) {
-                    Enumeration<?> containers =3D topComponents.elements();
-                    while (containers.hasMoreElements()) {
-                        resetAndRestoreCursors((Container) containers.nextEl=
ement());
+                    for (Object topComponent : topComponents) {
+                        resetAndRestoreCursors((Container) topComponent);
                     }
                 }
                 cursors =3D null;
@@ -356,14 +363,12 @@
             }
         }
         Frame frames[] =3D Frame.getFrames();
-        for (int i =3D 0; i < frames.length; i++) {
-            Window[] windows =3D frames[i].getOwnedWindows();
-            for (int j =3D 0; j < windows.length; j++) {
-                containers.add(windows[j]);
+        for (Frame frame : frames) {
+            Window[] windows =3D frame.getOwnedWindows();
+            Collections.addAll(containers, windows);
+            if (!containers.contains(frame)) {
+                containers.add(frame);
             }
-            if (!containers.contains(frames[i])) {
-                containers.add(frames[i]);
-            }
         }
         return containers;
     }
@@ -401,16 +406,21 @@
         if (comp =3D=3D null) {
             return;
         }
-        Cursor compCursor =3D comp.getCursor();
-        if (compCursor !=3D cursor) {
-            cursors.put(comp, compCursor);
-            log.debug("set cursor on " + comp);
-            comp.setCursor(cursor);
+        if (cache.containsKey(comp)) {
+            Cursor compCursor =3D comp.getCursor();
+            if (compCursor !=3D cursor) {
+                cursors.put(comp, compCursor);
+                if (log.isDebugEnabled()) {
+                    log.debug("set cursor on " + comp);
+                }
+                comp.setCursor(cursor);
+            }
         }
+
         if (comp instanceof Container) {
             Component component[] =3D ((Container) comp).getComponents();
-            for (int i =3D 0; i < component.length; i++) {
-                setAndStoreCursors(component[i], cursor);
+            for (Component aComponent : component) {
+                setAndStoreCursors(aComponent, cursor);
             }
         }
     }
@@ -430,8 +440,8 @@
         }
         if (comp instanceof Container) {
             Component component[] =3D ((Container) comp).getComponents();
-            for (int i =3D 0; i < component.length; i++) {
-                resetAndRestoreCursors(component[i]);
+            for (Component aComponent : component) {
+                resetAndRestoreCursors(aComponent);
             }
         }
     }


--===============5495776912971014032==--


