1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.awt.BorderLayout; |
24 |
|
import java.awt.Color; |
25 |
|
import java.awt.Component; |
26 |
|
import java.awt.Font; |
27 |
|
import java.awt.GridLayout; |
28 |
|
import java.awt.Rectangle; |
29 |
|
import java.awt.event.ActionListener; |
30 |
|
import java.awt.event.MouseAdapter; |
31 |
|
import java.awt.event.MouseEvent; |
32 |
|
import java.util.List; |
33 |
|
import java.util.Objects; |
34 |
|
|
35 |
|
import javax.swing.AbstractButton; |
36 |
|
import javax.swing.BorderFactory; |
37 |
|
import javax.swing.JButton; |
38 |
|
import javax.swing.JComboBox; |
39 |
|
import javax.swing.JComponent; |
40 |
|
import javax.swing.JLabel; |
41 |
|
import javax.swing.JMenu; |
42 |
|
import javax.swing.JMenuItem; |
43 |
|
import javax.swing.JPanel; |
44 |
|
import javax.swing.JScrollBar; |
45 |
|
import javax.swing.SwingConstants; |
46 |
|
import javax.swing.border.Border; |
47 |
|
import javax.swing.border.TitledBorder; |
48 |
|
|
49 |
|
import jalview.util.MessageManager; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@author |
55 |
|
|
56 |
|
|
|
|
| 0% |
Uncovered Elements: 147 (147) |
Complexity: 41 |
Complexity Density: 0.45 |
|
57 |
|
public final class JvSwingUtils |
58 |
|
{ |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
@return |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 7 |
Complexity Density: 0.54 |
|
69 |
0 |
public static String wrapTooltip(boolean enclose, String ttext)... |
70 |
|
{ |
71 |
0 |
Objects.requireNonNull(ttext, |
72 |
|
"Tootip text to format must not be null!"); |
73 |
0 |
ttext = ttext.trim(); |
74 |
0 |
boolean maxLengthExceeded = false; |
75 |
|
|
76 |
0 |
if (ttext.contains("<br>")) |
77 |
|
{ |
78 |
0 |
String[] htmllines = ttext.split("<br>"); |
79 |
0 |
for (String line : htmllines) |
80 |
|
{ |
81 |
0 |
maxLengthExceeded = line.length() > 60; |
82 |
0 |
if (maxLengthExceeded) |
83 |
|
{ |
84 |
0 |
break; |
85 |
|
} |
86 |
|
} |
87 |
|
} |
88 |
|
else |
89 |
|
{ |
90 |
0 |
maxLengthExceeded = ttext.length() > 60; |
91 |
|
} |
92 |
|
|
93 |
0 |
if (!maxLengthExceeded) |
94 |
|
{ |
95 |
0 |
return enclose ? "<html>" + ttext + "</html>" : ttext; |
96 |
|
} |
97 |
|
|
98 |
0 |
return (enclose ? "<html>" : "") |
99 |
|
|
100 |
|
+ "<style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style><div class=\"ttip\">" |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
+ ttext + " </div>" |
105 |
|
|
106 |
0 |
+ ((enclose ? "</html>" : "")); |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
109 |
0 |
public static JButton makeButton(String label, String tooltip,... |
110 |
|
ActionListener action) |
111 |
|
{ |
112 |
0 |
JButton button = new JButton(); |
113 |
0 |
button.setText(label); |
114 |
|
|
115 |
0 |
button.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); |
116 |
0 |
button.setForeground(Color.black); |
117 |
0 |
button.setHorizontalAlignment(SwingConstants.CENTER); |
118 |
0 |
button.setToolTipText(tooltip); |
119 |
0 |
button.addActionListener(action); |
120 |
0 |
return button; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
@param |
128 |
|
@return |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
130 |
0 |
public static JMenu findOrCreateMenu(JMenu menu, String submenu)... |
131 |
|
{ |
132 |
0 |
JMenu submenuinstance = null; |
133 |
0 |
for (int i = 0, iSize = menu.getMenuComponentCount(); i < iSize; i++) |
134 |
|
{ |
135 |
0 |
if (menu.getMenuComponent(i) instanceof JMenu |
136 |
|
&& ((JMenu) menu.getMenuComponent(i)).getText() |
137 |
|
.equals(submenu)) |
138 |
|
{ |
139 |
0 |
submenuinstance = (JMenu) menu.getMenuComponent(i); |
140 |
|
} |
141 |
|
} |
142 |
0 |
if (submenuinstance == null) |
143 |
|
{ |
144 |
0 |
submenuinstance = new JMenu(submenu); |
145 |
0 |
menu.add(submenuinstance); |
146 |
|
} |
147 |
0 |
return submenuinstance; |
148 |
|
|
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@param |
155 |
|
@param |
156 |
|
@param |
157 |
|
@return |
158 |
|
|
159 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
160 |
0 |
public static JPanel addtoLayout(JPanel panel, String tooltip,... |
161 |
|
JComponent label, JComponent valBox) |
162 |
|
{ |
163 |
0 |
JPanel laypanel = new JPanel(new GridLayout(1, 2)); |
164 |
0 |
JPanel labPanel = new JPanel(new BorderLayout()); |
165 |
0 |
JPanel valPanel = new JPanel(); |
166 |
0 |
labPanel.setBounds(new Rectangle(7, 7, 158, 23)); |
167 |
0 |
valPanel.setBounds(new Rectangle(172, 7, 270, 23)); |
168 |
0 |
labPanel.add(label, BorderLayout.WEST); |
169 |
0 |
valPanel.add(valBox); |
170 |
0 |
laypanel.add(labPanel); |
171 |
0 |
laypanel.add(valPanel); |
172 |
0 |
valPanel.setToolTipText(tooltip); |
173 |
0 |
labPanel.setToolTipText(tooltip); |
174 |
0 |
valBox.setToolTipText(tooltip); |
175 |
0 |
panel.add(laypanel); |
176 |
0 |
panel.validate(); |
177 |
0 |
return laypanel; |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
public static void mgAddtoLayout(JPanel cpanel, String tooltip,... |
181 |
|
JLabel jLabel, JComponent name) |
182 |
|
{ |
183 |
0 |
mgAddtoLayout(cpanel, tooltip, jLabel, name, null); |
184 |
|
} |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
186 |
0 |
public static void mgAddtoLayout(JPanel cpanel, String tooltip,... |
187 |
|
JLabel jLabel, JComponent name, String params) |
188 |
|
{ |
189 |
0 |
cpanel.add(jLabel); |
190 |
0 |
if (params == null) |
191 |
|
{ |
192 |
0 |
cpanel.add(name); |
193 |
|
} |
194 |
|
else |
195 |
|
{ |
196 |
0 |
cpanel.add(name, params); |
197 |
|
} |
198 |
0 |
name.setToolTipText(tooltip); |
199 |
0 |
jLabel.setToolTipText(tooltip); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
@return |
206 |
|
|
207 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
0 |
public static Font getLabelFont()... |
209 |
|
{ |
210 |
0 |
return getLabelFont(false, false); |
211 |
|
} |
212 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 5 |
Complexity Density: 5 |
|
213 |
0 |
public static Font getLabelFont(boolean bold, boolean italic)... |
214 |
|
{ |
215 |
0 |
return new java.awt.Font("Verdana", |
216 |
0 |
(!bold && !italic) ? Font.PLAIN |
217 |
0 |
: (bold ? Font.BOLD : 0) + (italic ? Font.ITALIC : 0), |
218 |
|
11); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@return |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0 |
public static Font getTextAreaFont()... |
227 |
|
{ |
228 |
0 |
return getLabelFont(false, false); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
@param |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
237 |
0 |
public static void cleanMenu(JMenu webService)... |
238 |
|
{ |
239 |
0 |
for (int i = 0; i < webService.getItemCount();) |
240 |
|
{ |
241 |
0 |
JMenuItem item = webService.getItem(i); |
242 |
0 |
if (item instanceof JMenu && ((JMenu) item).getItemCount() == 0) |
243 |
|
{ |
244 |
0 |
webService.remove(i); |
245 |
|
} |
246 |
|
else |
247 |
|
{ |
248 |
0 |
i++; |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
@see |
259 |
|
|
260 |
|
@param |
261 |
|
@return |
262 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
263 |
0 |
public static float getScrollBarProportion(JScrollBar scroll)... |
264 |
|
{ |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
0 |
int possibleRange = scroll.getMaximum() - scroll.getMinimum() |
270 |
|
- scroll.getModel().getExtent(); |
271 |
0 |
float valueInRange = scroll.getValue() |
272 |
|
- (scroll.getModel().getExtent() / 2f); |
273 |
0 |
float proportion = valueInRange / possibleRange; |
274 |
0 |
return proportion; |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
@param |
283 |
|
@param |
284 |
|
@return |
285 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
286 |
0 |
public static int getScrollValueForProportion(JScrollBar scrollbar,... |
287 |
|
float proportion) |
288 |
|
{ |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
0 |
float fraction = proportion |
294 |
|
* (scrollbar.getMaximum() - scrollbar.getMinimum() |
295 |
|
- scrollbar.getModel().getExtent()) |
296 |
|
+ (scrollbar.getModel().getExtent() / 2f); |
297 |
0 |
return Math.min(Math.round(fraction), scrollbar.getMaximum()); |
298 |
|
} |
299 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
300 |
0 |
public static void jvInitComponent(AbstractButton comp, String i18nString)... |
301 |
|
{ |
302 |
0 |
setColorAndFont(comp); |
303 |
0 |
if (i18nString != null && !i18nString.isEmpty()) |
304 |
|
{ |
305 |
0 |
comp.setText(MessageManager.getString(i18nString)); |
306 |
|
} |
307 |
|
} |
308 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
309 |
0 |
public static void jvInitComponent(JComponent comp)... |
310 |
|
{ |
311 |
0 |
setColorAndFont(comp); |
312 |
|
} |
313 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
314 |
0 |
private static void setColorAndFont(JComponent comp)... |
315 |
|
{ |
316 |
0 |
comp.setBackground(Color.white); |
317 |
0 |
comp.setFont(JvSwingUtils.getLabelFont()); |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
@param |
325 |
|
@param |
326 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
327 |
0 |
public static JComboBox<Object> buildComboWithTooltips(... |
328 |
|
List<Object> entries, List<String> tooltips) |
329 |
|
{ |
330 |
0 |
JComboBox<Object> combo = new JComboBox<>(); |
331 |
0 |
final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer(); |
332 |
0 |
combo.setRenderer(renderer); |
333 |
0 |
for (Object attName : entries) |
334 |
|
{ |
335 |
0 |
combo.addItem(attName); |
336 |
|
} |
337 |
0 |
renderer.setTooltips(tooltips); |
338 |
0 |
final MouseAdapter mouseListener = new MouseAdapter() |
339 |
|
{ |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
340 |
0 |
@Override... |
341 |
|
public void mouseEntered(MouseEvent e) |
342 |
|
{ |
343 |
0 |
int j = combo.getSelectedIndex(); |
344 |
0 |
if (j > -1) |
345 |
|
{ |
346 |
0 |
combo.setToolTipText(tooltips.get(j)); |
347 |
|
} |
348 |
|
} |
349 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
0 |
@Override... |
351 |
|
public void mouseExited(MouseEvent e) |
352 |
|
{ |
353 |
0 |
combo.setToolTipText(null); |
354 |
|
} |
355 |
|
}; |
356 |
0 |
for (Component c : combo.getComponents()) |
357 |
|
{ |
358 |
0 |
c.addMouseListener(mouseListener); |
359 |
|
} |
360 |
0 |
return combo; |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
@param |
368 |
|
@param |
369 |
|
@param |
370 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
371 |
0 |
public static TitledBorder createTitledBorder(JComponent comp,... |
372 |
|
String title, boolean italic) |
373 |
|
{ |
374 |
0 |
Font font = comp.getFont(); |
375 |
0 |
if (italic) |
376 |
|
{ |
377 |
0 |
font = new Font(font.getName(), Font.ITALIC, font.getSize()); |
378 |
|
} |
379 |
0 |
Border border = BorderFactory.createTitledBorder(""); |
380 |
0 |
TitledBorder titledBorder = BorderFactory.createTitledBorder(border, |
381 |
|
title, TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, |
382 |
|
font); |
383 |
0 |
comp.setBorder(titledBorder); |
384 |
|
|
385 |
0 |
return titledBorder; |
386 |
|
} |
387 |
|
|
388 |
|
} |