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.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java 2013-03-09 07:21:41 UTC (rev 2602) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java 2013-03-09 14:02:50 UTC (rev 2603) @@ -24,6 +24,7 @@ */ package jaxx.runtime.swing.help; +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 @@ // prepare cursor onItemCursor = (Cursor) UIManager.get("HelpOnItemCursor"); + + if (onItemCursor == null) { + onItemCursor = BasicCursorFactory.getOnItemCursor(); + UIManager.put("HelpOnItemCursor", onItemCursor); + } + Preconditions.checkNotNull(onItemCursor, "A cursor is missing (add HelpOnItemCursor cursor in UIManager)."); Vector<?> topComponents = null; cursors = null; if (onItemCursor != null) { cursors = new Hashtable<Component, Cursor>(); topComponents = getTopContainers(source); - Enumeration<?> enums = topComponents.elements(); - while (enums.hasMoreElements()) { - setAndStoreCursors((Container) enums.nextElement(), onItemCursor); + for (Object topComponent : topComponents) { + setAndStoreCursors((Container) topComponent, onItemCursor); } } @@ -261,9 +269,8 @@ } finally { // restore the old cursors if (topComponents != null) { - Enumeration<?> containers = topComponents.elements(); - while (containers.hasMoreElements()) { - resetAndRestoreCursors((Container) containers.nextElement()); + for (Object topComponent : topComponents) { + resetAndRestoreCursors((Container) topComponent); } } cursors = null; @@ -356,14 +363,12 @@ } } Frame frames[] = Frame.getFrames(); - for (int i = 0; i < frames.length; i++) { - Window[] windows = frames[i].getOwnedWindows(); - for (int j = 0; j < windows.length; j++) { - containers.add(windows[j]); + for (Frame frame : frames) { + Window[] windows = 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 == null) { return; } - Cursor compCursor = comp.getCursor(); - if (compCursor != cursor) { - cursors.put(comp, compCursor); - log.debug("set cursor on " + comp); - comp.setCursor(cursor); + if (cache.containsKey(comp)) { + Cursor compCursor = comp.getCursor(); + if (compCursor != cursor) { + cursors.put(comp, compCursor); + if (log.isDebugEnabled()) { + log.debug("set cursor on " + comp); + } + comp.setCursor(cursor); + } } + if (comp instanceof Container) { Component component[] = ((Container) comp).getComponents(); - for (int i = 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[] = ((Container) comp).getComponents(); - for (int i = 0; i < component.length; i++) { - resetAndRestoreCursors(component[i]); + for (Component aComponent : component) { + resetAndRestoreCursors(aComponent); } } }
participants (1)
-
tchemit@users.nuiton.org