Lines 12-31
Link Here
|
12 |
|
12 |
|
13 |
package org.openide.awt; |
13 |
package org.openide.awt; |
14 |
|
14 |
|
|
|
15 |
import java.awt.event.ActionEvent; |
16 |
import java.awt.event.KeyEvent; |
15 |
import java.awt.image.BufferedImage; |
17 |
import java.awt.image.BufferedImage; |
16 |
import java.util.HashMap; |
18 |
import java.util.HashMap; |
17 |
import java.util.Map; |
19 |
import java.util.Map; |
18 |
import java.util.Observable; |
20 |
import java.util.Observable; |
19 |
import javax.swing.AbstractButton; |
|
|
20 |
import javax.swing.AbstractAction; |
21 |
import javax.swing.AbstractAction; |
21 |
import javax.swing.Action; |
22 |
import javax.swing.Action; |
22 |
import javax.swing.JButton; |
23 |
import javax.swing.JButton; |
23 |
import javax.swing.Icon; |
24 |
import javax.swing.Icon; |
24 |
import javax.swing.ImageIcon; |
25 |
import javax.swing.JFrame; |
25 |
import javax.swing.JMenuItem; |
26 |
import javax.swing.JMenuItem; |
26 |
import javax.swing.KeyStroke; |
27 |
import javax.swing.KeyStroke; |
|
|
28 |
import javax.swing.SwingUtilities; |
27 |
import javax.swing.text.Keymap; |
29 |
import javax.swing.text.Keymap; |
28 |
import org.openide.util.Utilities; |
|
|
29 |
|
30 |
|
30 |
import org.openide.util.actions.SystemAction; |
31 |
import org.openide.util.actions.SystemAction; |
31 |
|
32 |
|
Lines 240-245
Link Here
|
240 |
assertGC ("action can dissappear", ref); |
241 |
assertGC ("action can dissappear", ref); |
241 |
} |
242 |
} |
242 |
|
243 |
|
|
|
244 |
/** |
245 |
* Tests if changes in accelerator key or name of the action does not change the tooltip |
246 |
* of the button if the action has a custom tooltip. See first part of #57974. |
247 |
*/ |
248 |
public void testTooltipsArePersistent() throws Exception { |
249 |
if (!SwingUtilities.isEventDispatchThread()) { |
250 |
SwingUtilities.invokeAndWait(new Runnable() { |
251 |
public void run() { |
252 |
try { |
253 |
testTooltipsArePersistent(); |
254 |
} catch (Exception e) { |
255 |
IllegalStateException exc = new IllegalStateException(e.getMessage()); |
256 |
|
257 |
exc.initCause(e); |
258 |
throw exc; |
259 |
} |
260 |
} |
261 |
}); |
262 |
return ; |
263 |
} |
264 |
|
265 |
Action action = new ActionsTest.TestActionWithTooltip(); |
266 |
JButton button = new JButton(); |
267 |
|
268 |
Actions.connect(button, action); |
269 |
|
270 |
JFrame f = new JFrame(); |
271 |
|
272 |
f.getContentPane().add(button); |
273 |
f.setVisible(true); |
274 |
|
275 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
276 |
|
277 |
action.putValue(Action.NAME, "new-name"); |
278 |
|
279 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
280 |
|
281 |
action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a')); |
282 |
|
283 |
assertTrue(button.getToolTipText().indexOf(TestActionWithTooltip.TOOLTIP) != (-1)); |
284 |
|
285 |
f.setVisible(false); |
286 |
} |
287 |
|
288 |
/** |
289 |
* Tests if the tooltip is made out of the NAME if there is not tooltip set for an action. |
290 |
* See also #57974. |
291 |
*/ |
292 |
public void testTooltipsIsBuiltFromNameIfNoTooltip() throws Exception { |
293 |
if (!SwingUtilities.isEventDispatchThread()) { |
294 |
SwingUtilities.invokeAndWait(new Runnable() { |
295 |
public void run() { |
296 |
try { |
297 |
testTooltipsIsBuiltFromNameIfNoTooltip(); |
298 |
} catch (Exception e) { |
299 |
IllegalStateException exc = new IllegalStateException(e.getMessage()); |
300 |
|
301 |
exc.initCause(e); |
302 |
throw exc; |
303 |
} |
304 |
} |
305 |
}); |
306 |
return ; |
307 |
} |
308 |
|
309 |
Action action = new ActionsTest.TestAction(); |
310 |
JButton button = new JButton(); |
311 |
|
312 |
Actions.connect(button, action); |
313 |
|
314 |
JFrame f = new JFrame(); |
315 |
|
316 |
f.getContentPane().add(button); |
317 |
f.setVisible(true); |
318 |
|
319 |
assertTrue(button.getToolTipText().equals("test")); |
320 |
|
321 |
action.putValue(Action.NAME, "new-name"); |
322 |
|
323 |
assertTrue(button.getToolTipText().equals("new-name")); |
324 |
|
325 |
action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a')); |
326 |
|
327 |
assertTrue(button.getToolTipText().indexOf("new-name") != (-1)); |
328 |
|
329 |
f.setVisible(false); |
330 |
} |
331 |
|
332 |
/** |
333 |
* Tests if the accelerator key is shown in the button's tooltip for actions with |
334 |
* custom tooltips. |
335 |
*/ |
336 |
public void testTooltipsContainAccelerator() throws Exception { |
337 |
if (!SwingUtilities.isEventDispatchThread()) { |
338 |
SwingUtilities.invokeAndWait(new Runnable() { |
339 |
public void run() { |
340 |
try { |
341 |
testTooltipsContainAccelerator(); |
342 |
} catch (Exception e) { |
343 |
IllegalStateException exc = new IllegalStateException(e.getMessage()); |
344 |
|
345 |
exc.initCause(e); |
346 |
throw exc; |
347 |
} |
348 |
} |
349 |
}); |
350 |
return ; |
351 |
} |
352 |
|
353 |
Action action = new ActionsTest.TestActionWithTooltip(); |
354 |
JButton button = new JButton(); |
355 |
|
356 |
Actions.connect(button, action); |
357 |
|
358 |
JFrame f = new JFrame(); |
359 |
|
360 |
f.getContentPane().add(button); |
361 |
f.setVisible(true); |
362 |
|
363 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
364 |
|
365 |
action.putValue(Action.NAME, "new-name"); |
366 |
|
367 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
368 |
|
369 |
action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)); |
370 |
|
371 |
assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1)); |
372 |
|
373 |
action.putValue(Action.SHORT_DESCRIPTION, null); |
374 |
|
375 |
assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1)); |
376 |
|
377 |
f.setVisible(false); |
378 |
} |
379 |
|
243 |
private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) { |
380 |
private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) { |
244 |
checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon); |
381 |
checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon); |
245 |
checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon); |
382 |
checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon); |
Lines 305-310
Link Here
|
305 |
} |
442 |
} |
306 |
|
443 |
|
307 |
} |
444 |
} |
|
|
445 |
|
446 |
private static final class TestActionWithTooltip extends AbstractAction { |
447 |
|
448 |
private static String TOOLTIP = "tooltip"; |
449 |
|
450 |
public TestActionWithTooltip() { |
451 |
putValue(NAME, "name"); |
452 |
putValue(SHORT_DESCRIPTION, TOOLTIP); |
453 |
} |
454 |
|
455 |
public void actionPerformed(ActionEvent e) { |
456 |
} |
457 |
|
458 |
} |
308 |
|
459 |
|
309 |
public static final class Lkp extends AbstractLookup { |
460 |
public static final class Lkp extends AbstractLookup { |
310 |
public Lkp () { |
461 |
public Lkp () { |