Author: mes
Date: 2010-09-28 10:00:38 -0700 (Tue, 28 Sep 2010)
New Revision: 22084

Modified:
   
cytoscape/trunk/application/src/main/java/cytoscape/actions/HelpContentsAction.java
   cytoscape/trunk/application/src/main/java/cytoscape/view/CyHelpBroker.java
   cytoscape/trunk/application/src/main/java/cytoscape/view/CyMenus.java
   
cytoscape/trunk/application/src/main/java/cytoscape/view/CytoscapeDesktop.java
Log:
cleaned up help

Modified: 
cytoscape/trunk/application/src/main/java/cytoscape/actions/HelpContentsAction.java
===================================================================
--- 
cytoscape/trunk/application/src/main/java/cytoscape/actions/HelpContentsAction.java
 2010-09-28 01:43:53 UTC (rev 22083)
+++ 
cytoscape/trunk/application/src/main/java/cytoscape/actions/HelpContentsAction.java
 2010-09-28 17:00:38 UTC (rev 22084)
@@ -38,20 +38,19 @@
 
 import cytoscape.util.CytoscapeAction;
 
-import cytoscape.view.CyHelpBroker;
-
+import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import javax.swing.JOptionPane;
 
-import javax.help.CSH;
+import cytoscape.view.CyHelpBroker; 
 
 /**
  * Really just a wrapper for the CSH.DisplayHelpFromSource action.
  */
 public class HelpContentsAction extends CytoscapeAction {
 
-       private CSH.DisplayHelpFromSource csh; 
+       private final ActionListener helpActionListener = 
CyHelpBroker.getHelpActionListener();
 
        /**
         * Creates a new HelpContentsAction object.
@@ -68,18 +67,6 @@
         * @param e The triggering event - passed to 
CSH.DisplayHelpFromSource.actionPerformed(e)  
         */
        public void actionPerformed(ActionEvent e) {
-               if ( csh == null ) {
-                       try {
-                       csh = new 
CSH.DisplayHelpFromSource(CyHelpBroker.getHelpBroker());
-                       } catch (Exception ex) {
-                               JOptionPane.showMessageDialog(
-                                       null,
-                                       "Help cannot be started. Please see the 
manual on the Cytoscape website instead: http://cytoscape.org.";,
-                                       "ERROR",
-                                       JOptionPane.ERROR_MESSAGE);
-                               return;
-                       }
-               }
-               csh.actionPerformed(e);
+               helpActionListener.actionPerformed(e);
        }
 }

Modified: 
cytoscape/trunk/application/src/main/java/cytoscape/view/CyHelpBroker.java
===================================================================
--- cytoscape/trunk/application/src/main/java/cytoscape/view/CyHelpBroker.java  
2010-09-28 01:43:53 UTC (rev 22083)
+++ cytoscape/trunk/application/src/main/java/cytoscape/view/CyHelpBroker.java  
2010-09-28 17:00:38 UTC (rev 22084)
@@ -31,6 +31,7 @@
 
 
 import cytoscape.logger.CyLogger;
+import cytoscape.Cytoscape;
 
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -42,7 +43,14 @@
 import javax.help.HelpBroker;
 import javax.help.HelpSet;
 
+import java.awt.Component;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import javax.swing.JOptionPane;
 
+import javax.help.CSH; 
+
+
 /**
  * This class creates the Cytoscape Help Broker for managing the JavaHelp 
system
  * and help set access
@@ -50,31 +58,29 @@
 public class CyHelpBroker {
        private static HelpBroker hb;
        private static HelpSet masterHelpSet;
+       private static CSH.DisplayHelpFromFocus csh;
+       private static ActionListener actionListener;
        private static final String HELP_RESOURCE = 
"/cytoscape/help/jhelpset.hs";
+       private static final CyLogger logger = 
CyLogger.getLogger(CyHelpBroker.class);
 
        static {
-               new CyHelpBroker();
-       }
-
-       /**
-        * Creates a new CyHelpBroker object.
-        */
-       private CyHelpBroker() {
-               hb = null;
-               masterHelpSet = null;
-
-               URL hsURL = getClass().getResource(HELP_RESOURCE);
                try {
-                       masterHelpSet = new HelpSet(null, hsURL);
+                       masterHelpSet = new HelpSet(null, 
CyHelpBroker.class.getResource(HELP_RESOURCE));
                        hb = masterHelpSet.createHelpBroker();
-                       hb.setCurrentID("d0e1");
+                       hb.setCurrentID("Cytoscape User Manual");
+                       csh = new CSH.DisplayHelpFromFocus(hb);
+                       actionListener = new SensibleActionListener();
                } catch (Exception e) {
-                       CyLogger.getLogger().info("HelpSet " + e.getMessage());
-                       CyLogger.getLogger().info("HelpSet " + masterHelpSet + 
" not found.");
+                       logger.warning("HelpSet " + HELP_RESOURCE + " not 
loaded.", e);
                }
        }
 
        /**
+        * Creates a new CyHelpBroker object.
+        */
+       private CyHelpBroker() { }
+
+       /**
         * Returns the HelpBroker. 
         *
         * @return the HelpBroker. 
@@ -112,4 +118,42 @@
        public static boolean removeHelpSet(final HelpSet hs) {
                return masterHelpSet.remove(hs);
        }
+
+
+       /**
+        * Provides access to an ActionListener that pops up a help dialog. To 
enable,
+        * for example, a help button, you would simple add the available 
action as a
+        * ActionListener to the button.
+        * <br/>
+        * <pre>
+        * JButton helpButton = new JButton("Help");
+        * helpButton.addActionListener( CyHelpBroker.getHelpActionListener() );
+        * </pre>
+        */
+       public static ActionListener getHelpActionListener() {
+               return actionListener;
+       }
+
+       /**
+        * An ActionListener that wraps the available CSH ActionListener and 
tries
+        * to gracefully handle exceptions. 
+        */
+       private static class SensibleActionListener implements ActionListener {
+               public void actionPerformed(ActionEvent ae) {
+                       try {
+                               csh.actionPerformed(ae);
+                       } catch (Exception e) {
+                               logger.warn("Couldn't display help for event: " 
+ ae.toString(), e);
+                               // Try again with a fake action with a 
different source, a source
+                               // that has help defined for it.
+                               try {
+                                       csh.actionPerformed( new ActionEvent( 
Cytoscape.getDesktop(), 
+                                                                              
ae.getID(), ae.getActionCommand(), 
+                                                                              
ae.getWhen(), ae.getModifiers() ) );
+                               } catch (Exception ex) {
+                                       logger.error("REALLY Couldn't display 
help for previous event", ex);
+                               }
+                       }
+               }
+       }
 }

Modified: cytoscape/trunk/application/src/main/java/cytoscape/view/CyMenus.java
===================================================================
--- cytoscape/trunk/application/src/main/java/cytoscape/view/CyMenus.java       
2010-09-28 01:43:53 UTC (rev 22083)
+++ cytoscape/trunk/application/src/main/java/cytoscape/view/CyMenus.java       
2010-09-28 17:00:38 UTC (rev 22084)
@@ -43,7 +43,6 @@
 import java.beans.PropertyChangeListener;
 import java.net.URL;
 import java.util.List;
-import javax.help.CSH;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JMenu;
@@ -621,20 +620,7 @@
                toolBar.addSeparator();
 
                helpButton = new JButton();
-               helpButton.addActionListener( new ActionListener() {
-                       private CSH.DisplayHelpFromSource csh;
-                       public void actionPerformed(ActionEvent e) {
-                               if ( csh == null ) {
-                                       try {
-                                       csh = new 
CSH.DisplayHelpFromSource(CyHelpBroker.getHelpBroker());
-                                       } catch (Exception ex) {
-                                               
JOptionPane.showMessageDialog(null, "Help cannot be started. Please see the 
manual on the Cytoscape website instead: http://cytoscape.org.";, "ERROR", 
JOptionPane.ERROR_MESSAGE);
-                                               return;
-                                       }
-                               }
-                               csh.actionPerformed(e);
-                       }
-               });
+               helpButton.addActionListener( 
CyHelpBroker.getHelpActionListener() );
                helpButton.setIcon(new 
ImageIcon(Cytoscape.class.getResource("images/ximian/stock_help.png")));
                helpButton.setToolTipText("Help");
                helpButton.setBorderPainted(false);

Modified: 
cytoscape/trunk/application/src/main/java/cytoscape/view/CytoscapeDesktop.java
===================================================================
--- 
cytoscape/trunk/application/src/main/java/cytoscape/view/CytoscapeDesktop.java  
    2010-09-28 01:43:53 UTC (rev 22083)
+++ 
cytoscape/trunk/application/src/main/java/cytoscape/view/CytoscapeDesktop.java  
    2010-09-28 17:00:38 UTC (rev 22084)
@@ -46,8 +46,7 @@
 import java.util.List;
 import java.util.Properties;
 
-import javax.help.HelpBroker;
-import javax.help.HelpSet;
+import javax.help.CSH;
 import javax.swing.ImageIcon;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -340,6 +339,9 @@
                // show the Desktop
                setVisible(true);
                toFront();
+
+               // sets the top level identifier for java help
+               CSH.setHelpIDString(this,"Cytoscape User Manual");
        }
        
        
@@ -409,38 +411,6 @@
        }
 
        /**
-        * @deprecated Will be removed April 2008. Use 
CyHelpBroker.getHelpBroker() instead.
-        */
-       public HelpBroker getHelpBroker() {
-               return CyHelpBroker.getHelpBroker();
-       }
-
-       /**
-        * @deprecated Will be removed April 2008. Use 
CyHelpBroker.getHelpSet() instead.
-        */
-       public HelpSet getHelpSet() {
-               return CyHelpBroker.getHelpSet();
-       }
-
-       /**
-        * Don't use this!
-        *
-        * @param edit An undoable edit.
-        * @deprecated Use CyUndo.getUndoableEditSupport().postEdit(edit) 
instead. Will be removed March 2008.
-        */
-       public void addEdit(javax.swing.undo.UndoableEdit edit) {
-               CyUndo.getUndoableEditSupport().postEdit(edit);
-       }
-
-       /**
-        * Return the view type for this CytoscapeDesktop
-        * @deprecated View type is no longer used, so just don't use this 
method. Will be gone August 2008.
-        */
-       public int getViewType() {
-               return 1; // what was internal
-       }
-
-       /**
         *  DOCUMENT ME!
         *
         * @return  DOCUMENT ME!

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to