1 package fr.ifremer.reefdb.ui.swing;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import fr.ifremer.quadrige3.core.dao.technical.Assert;
27 import jaxx.runtime.JAXXObject;
28 import jaxx.runtime.SwingUtil;
29 import jaxx.runtime.awt.visitor.BuildTreeVisitor;
30 import jaxx.runtime.awt.visitor.ComponentTreeNode;
31 import jaxx.runtime.awt.visitor.GetCompopentAtPointVisitor;
32 import jaxx.runtime.swing.help.JAXXHelpBroker;
33 import jaxx.runtime.swing.help.JAXXHelpUI;
34 import jaxx.runtime.swing.help.JAXXHelpUIHandler;
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 import javax.swing.AbstractButton;
39 import java.awt.Component;
40 import java.awt.Point;
41 import java.awt.event.ActionListener;
42 import java.awt.event.MouseEvent;
43
44
45
46
47
48
49 public class ReefDbHelpBroker extends JAXXHelpBroker {
50
51
52
53
54 private static final Log LOG = LogFactory.getLog(ReefDbHelpBroker.class);
55
56
57
58
59
60
61 public ReefDbHelpBroker(String defaultID) {
62 super("reefdb", "help",
63 defaultID,
64 (JAXXHelpUIHandler) ReefDbUIContext.getInstance());
65 }
66
67
68 @Override
69 public void prepareUI(JAXXObject c) {
70
71 Assert.notNull(c, "parameter c can not be null!");
72
73
74 AbstractButton help = getShowHelpButton(c);
75
76 if (help != null) {
77
78
79 if (LOG.isDebugEnabled()) {
80 LOG.debug("attach context to showhelp button " + c);
81 }
82 help.putClientProperty(JAXX_CONTEXT_ENTRY, c);
83
84
85 ActionListener listener = getShowHelpAction();
86 if (LOG.isDebugEnabled()) {
87 LOG.debug("adding tracking action " + listener);
88 }
89 help.addActionListener(listener);
90
91 if (LOG.isDebugEnabled()) {
92 LOG.debug("done for " + c);
93 }
94 }
95 }
96
97
98 @Override
99 public String findHelpId(Component comp) {
100
101 if (comp == null) {
102 comp = ReefDbUIContext.getInstance().getMainUI();
103 }
104 JAXXHelpUI<?> parentContainer = SwingUtil.getParent(comp, JAXXHelpUI.class);
105
106 String result;
107 if (parentContainer != null && this != parentContainer.getBroker()) {
108
109 JAXXHelpBroker broker = parentContainer.getBroker();
110 result = broker.findHelpId(comp);
111 } else {
112 result = super.findHelpId(comp);
113 }
114
115 if (result == null) {
116 result = "reefdb.index.help";
117 }
118
119 return result;
120 }
121
122
123 @Override
124 public Component getDeppestComponent(Component mouseComponent, MouseEvent event) {
125 ComponentTreeNode tree = BuildTreeVisitor.buildTree(mouseComponent);
126
127 Point point = event.getPoint();
128
129 Component component = GetCompopentAtPointVisitor.get(tree, point);
130 if (LOG.isDebugEnabled()) {
131 LOG.debug("Component at (" + point + "): " + component);
132 }
133 return component;
134 }
135
136 }