View Javadoc
1   package fr.ifremer.tutti.ui.swing;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.base.Preconditions;
26  import jaxx.runtime.JAXXObject;
27  import jaxx.runtime.SwingUtil;
28  import jaxx.runtime.awt.visitor.BuildTreeVisitor;
29  import jaxx.runtime.awt.visitor.ComponentTreeNode;
30  import jaxx.runtime.awt.visitor.GetCompopentAtPointVisitor;
31  import jaxx.runtime.swing.help.JAXXHelpBroker;
32  import jaxx.runtime.swing.help.JAXXHelpUI;
33  import org.apache.commons.logging.Log;
34  import org.apache.commons.logging.LogFactory;
35  
36  import javax.swing.AbstractButton;
37  import java.awt.Component;
38  import java.awt.Point;
39  import java.awt.event.ActionListener;
40  import java.awt.event.MouseEvent;
41  
42  /**
43   * Help broker.
44   *
45   * @author Tony Chemit - chemit@codelutin.com
46   * @since 1.1
47   */
48  public class TuttiHelpBroker extends JAXXHelpBroker {
49  
50      /** Logger */
51      private static final Log log = LogFactory.getLog(TuttiHelpBroker.class);
52  
53      public TuttiHelpBroker(String defaultID) {
54          super("tutti", "help",
55                defaultID,
56                TuttiUIContext.getApplicationContext());
57      }
58  
59      @Override
60      public void prepareUI(JAXXObject c) {
61  
62          Preconditions.checkNotNull(c, "parameter c can not be null!");
63  
64          // l'ui doit avoir un boutton showHelp
65          AbstractButton help = getShowHelpButton(c);
66  
67          if (help != null) {
68  
69              // attach context to button
70              if (log.isDebugEnabled()) {
71                  log.debug("attach context to showhelp button " + c);
72              }
73              help.putClientProperty(JAXX_CONTEXT_ENTRY, c);
74  
75              // add tracking action
76              ActionListener listener = getShowHelpAction();
77              if (log.isDebugEnabled()) {
78                  log.debug("adding tracking action " + listener);
79              }
80              help.addActionListener(listener);
81  
82              if (log.isDebugEnabled()) {
83                  log.debug("done for " + c);
84              }
85          }
86      }
87  
88      @Override
89      public String findHelpId(Component comp) {
90  
91          if (comp == null) {
92              comp = TuttiUIContext.getApplicationContext().getMainUI();
93          }
94          JAXXHelpUI parentContainer = SwingUtil.getParent(comp, JAXXHelpUI.class);
95  
96          String result;
97          if (parentContainer != null && this != parentContainer.getBroker()) {
98  
99              JAXXHelpBroker broker = parentContainer.getBroker();
100             result = broker.findHelpId(comp);
101         } else {
102             result = super.findHelpId(comp);
103         }
104 
105         if (result == null) {
106             result = "tutti.index.help";
107         }
108 
109         return result;
110     }
111 
112 }