1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.appletgui; |
22 |
|
|
23 |
|
import jalview.util.Platform; |
24 |
|
|
25 |
|
import java.awt.BorderLayout; |
26 |
|
import java.awt.Color; |
27 |
|
import java.awt.FlowLayout; |
28 |
|
import java.awt.Font; |
29 |
|
import java.awt.Frame; |
30 |
|
import java.awt.HeadlessException; |
31 |
|
import java.awt.Label; |
32 |
|
import java.awt.Menu; |
33 |
|
import java.awt.MenuBar; |
34 |
|
import java.awt.Panel; |
35 |
|
import java.awt.PopupMenu; |
36 |
|
import java.awt.event.MouseEvent; |
37 |
|
import java.awt.event.MouseListener; |
38 |
|
import java.util.HashMap; |
39 |
|
import java.util.Map; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@author |
52 |
|
|
53 |
|
|
|
|
| 0% |
Uncovered Elements: 97 (97) |
Complexity: 25 |
Complexity Density: 0.42 |
|
54 |
|
public class EmbmenuFrame extends Frame |
55 |
|
implements MouseListener, AutoCloseable |
56 |
|
{ |
57 |
|
protected static final Font FONT_ARIAL_PLAIN_11 = new Font("Arial", |
58 |
|
Font.PLAIN, 11); |
59 |
|
|
60 |
|
public static final Font DEFAULT_MENU_FONT = FONT_ARIAL_PLAIN_11; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
protected Map<Label, PopupMenu> embeddedPopup = new HashMap<>(); |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
protected Panel embeddedMenu; |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0 |
public EmbmenuFrame() throws HeadlessException... |
75 |
|
{ |
76 |
0 |
super(); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
public EmbmenuFrame(String title) throws HeadlessException... |
80 |
|
{ |
81 |
0 |
super(title); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@param |
89 |
|
|
90 |
|
|
91 |
|
@return |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
93 |
0 |
protected boolean embedMenuIfNeeded(Panel tobeAdjusted)... |
94 |
|
{ |
95 |
0 |
MenuBar topMenuBar = getMenuBar(); |
96 |
0 |
if (topMenuBar == null) |
97 |
|
{ |
98 |
0 |
return false; |
99 |
|
} |
100 |
|
|
101 |
0 |
if (Platform.isAMacAndNotJS()) |
102 |
|
{ |
103 |
|
|
104 |
0 |
embeddedMenu = makeEmbeddedPopupMenu(topMenuBar, true, false); |
105 |
0 |
setMenuBar(null); |
106 |
|
|
107 |
0 |
add(embeddedMenu, BorderLayout.NORTH); |
108 |
0 |
tobeAdjusted.setSize(getSize().width, |
109 |
|
getSize().height - embeddedMenu.getHeight()); |
110 |
0 |
return true; |
111 |
|
} |
112 |
0 |
return false; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
@param |
122 |
|
@param |
123 |
|
|
124 |
|
|
125 |
|
@return |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
127 |
0 |
protected Panel makeEmbeddedPopupMenu(MenuBar menuBar,... |
128 |
|
boolean overrideFonts, boolean append) |
129 |
|
{ |
130 |
0 |
if (!append) |
131 |
|
{ |
132 |
0 |
embeddedPopup.clear(); |
133 |
0 |
if (embeddedMenu != null) |
134 |
|
{ |
135 |
0 |
embeddedMenu.removeAll(); |
136 |
|
} |
137 |
|
} |
138 |
0 |
embeddedMenu = makeEmbeddedPopupMenu(menuBar, DEFAULT_MENU_FONT, |
139 |
|
overrideFonts, new Panel(), this); |
140 |
0 |
return embeddedMenu; |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
@param |
151 |
|
|
152 |
|
@param |
153 |
|
@param |
154 |
|
@param |
155 |
|
|
156 |
|
@param |
157 |
|
|
158 |
|
|
159 |
|
@return |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 6 |
Complexity Density: 0.23 |
|
161 |
0 |
protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, Font font,... |
162 |
|
boolean overrideFonts, Panel embeddedMenu, |
163 |
|
MouseListener clickHandler) |
164 |
|
{ |
165 |
0 |
if (overrideFonts) |
166 |
|
{ |
167 |
0 |
Font mbf = menuBar.getFont(); |
168 |
0 |
if (mbf != null) |
169 |
|
{ |
170 |
0 |
font = mbf; |
171 |
|
} |
172 |
|
} |
173 |
0 |
if (embeddedMenu == null) |
174 |
|
{ |
175 |
0 |
embeddedMenu = new Panel(); |
176 |
|
} |
177 |
0 |
FlowLayout flowLayout1 = new FlowLayout(); |
178 |
0 |
embeddedMenu.setBackground(Color.lightGray); |
179 |
0 |
embeddedMenu.setLayout(flowLayout1); |
180 |
|
|
181 |
0 |
for (int mbi = 0, nMbi = menuBar.getMenuCount(); mbi < nMbi; mbi++) |
182 |
|
{ |
183 |
0 |
Menu mi = menuBar.getMenu(mbi); |
184 |
0 |
Label elab = new Label(mi.getLabel()); |
185 |
0 |
elab.setFont(font); |
186 |
|
|
187 |
0 |
PopupMenu popup = new PopupMenu(); |
188 |
0 |
int m, mSize = mi.getItemCount(); |
189 |
0 |
for (m = 0; m < mSize; m++) |
190 |
|
{ |
191 |
0 |
popup.add(mi.getItem(m)); |
192 |
0 |
mSize--; |
193 |
0 |
m--; |
194 |
|
} |
195 |
0 |
embeddedPopup.put(elab, popup); |
196 |
0 |
embeddedMenu.add(elab); |
197 |
0 |
elab.addMouseListener(clickHandler); |
198 |
|
} |
199 |
0 |
flowLayout1.setAlignment(FlowLayout.LEFT); |
200 |
0 |
flowLayout1.setHgap(2); |
201 |
0 |
flowLayout1.setVgap(0); |
202 |
0 |
return embeddedMenu; |
203 |
|
} |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
205 |
0 |
@Override... |
206 |
|
public void mousePressed(MouseEvent evt) |
207 |
|
{ |
208 |
0 |
PopupMenu popup = null; |
209 |
0 |
Label source = (Label) evt.getSource(); |
210 |
0 |
popup = getPopupMenu(source); |
211 |
0 |
if (popup != null) |
212 |
|
{ |
213 |
0 |
embeddedMenu.add(popup); |
214 |
0 |
popup.show(embeddedMenu, source.getBounds().x, |
215 |
|
source.getBounds().y + source.getBounds().getSize().height); |
216 |
|
} |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
@param |
223 |
|
|
224 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
225 |
0 |
PopupMenu getPopupMenu(Label source)... |
226 |
|
{ |
227 |
0 |
return embeddedPopup.get(source); |
228 |
|
} |
229 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
230 |
0 |
@Override... |
231 |
|
public void mouseClicked(MouseEvent evt) |
232 |
|
{ |
233 |
|
} |
234 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
235 |
0 |
@Override... |
236 |
|
public void mouseReleased(MouseEvent evt) |
237 |
|
{ |
238 |
|
} |
239 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
240 |
0 |
@Override... |
241 |
|
public void mouseEntered(MouseEvent evt) |
242 |
|
{ |
243 |
|
} |
244 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
245 |
0 |
@Override... |
246 |
|
public void mouseExited(MouseEvent evt) |
247 |
|
{ |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
254 |
0 |
public void destroyMenus()... |
255 |
|
{ |
256 |
0 |
if (embeddedPopup != null) |
257 |
|
{ |
258 |
0 |
for (Label lb : embeddedPopup.keySet()) |
259 |
|
{ |
260 |
0 |
lb.removeMouseListener(this); |
261 |
|
} |
262 |
0 |
embeddedPopup.clear(); |
263 |
|
} |
264 |
0 |
if (embeddedMenu != null) |
265 |
|
{ |
266 |
0 |
embeddedMenu.removeAll(); |
267 |
|
} |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
273 |
0 |
@Override... |
274 |
|
public void close() |
275 |
|
{ |
276 |
0 |
destroyMenus(); |
277 |
0 |
embeddedPopup = null; |
278 |
0 |
embeddedMenu = null; |
279 |
|
} |
280 |
|
} |