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 |
Action action = new ActionsTest.TestActionWithTooltip(); |
250 |
JButton button = new JButton(); |
251 |
|
252 |
Actions.connect(button, action); |
253 |
|
254 |
JFrame f = new JFrame(); |
255 |
|
256 |
f.getContentPane().add(button); |
257 |
f.setVisible(true); |
258 |
|
259 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
260 |
|
261 |
action.putValue(Action.NAME, "new-name"); |
262 |
|
263 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
264 |
|
265 |
action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a')); |
266 |
|
267 |
assertTrue(button.getToolTipText().indexOf(TestActionWithTooltip.TOOLTIP) != (-1)); |
268 |
|
269 |
f.setVisible(false); |
270 |
} |
271 |
|
272 |
/** |
273 |
* Tests if the tooltip is made out of the NAME if there is not tooltip set for an action. |
274 |
* See also #57974. |
275 |
*/ |
276 |
public void testTooltipsIsBuiltFromNameIfNoTooltip() throws Exception { |
277 |
Action action = new ActionsTest.TestAction(); |
278 |
JButton button = new JButton(); |
279 |
|
280 |
Actions.connect(button, action); |
281 |
|
282 |
JFrame f = new JFrame(); |
283 |
|
284 |
f.getContentPane().add(button); |
285 |
f.setVisible(true); |
286 |
|
287 |
assertTrue(button.getToolTipText().equals("test")); |
288 |
|
289 |
action.putValue(Action.NAME, "new-name"); |
290 |
|
291 |
assertTrue(button.getToolTipText().equals("new-name")); |
292 |
|
293 |
action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a')); |
294 |
|
295 |
assertTrue(button.getToolTipText().indexOf("new-name") != (-1)); |
296 |
|
297 |
f.setVisible(false); |
298 |
} |
299 |
|
300 |
/** |
301 |
* Tests if the accelerator key is shown in the button's tooltip for actions with |
302 |
* custom tooltips. |
303 |
*/ |
304 |
public void testTooltipsContainAccelerator() throws Exception { |
305 |
Action action = new ActionsTest.TestActionWithTooltip(); |
306 |
JButton button = new JButton(); |
307 |
|
308 |
Actions.connect(button, action); |
309 |
|
310 |
JFrame f = new JFrame(); |
311 |
|
312 |
f.getContentPane().add(button); |
313 |
f.setVisible(true); |
314 |
|
315 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
316 |
|
317 |
action.putValue(Action.NAME, "new-name"); |
318 |
|
319 |
assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); |
320 |
|
321 |
action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)); |
322 |
|
323 |
assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1)); |
324 |
|
325 |
action.putValue(Action.SHORT_DESCRIPTION, null); |
326 |
|
327 |
assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1)); |
328 |
|
329 |
f.setVisible(false); |
330 |
} |
331 |
|
332 |
protected boolean runInEQ() { |
333 |
return true; |
334 |
} |
335 |
|
243 |
private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) { |
336 |
private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) { |
244 |
checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon); |
337 |
checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon); |
245 |
checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon); |
338 |
checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon); |
Lines 305-310
Link Here
|
305 |
} |
398 |
} |
306 |
|
399 |
|
307 |
} |
400 |
} |
|
|
401 |
|
402 |
private static final class TestActionWithTooltip extends AbstractAction { |
403 |
|
404 |
private static String TOOLTIP = "tooltip"; |
405 |
|
406 |
public TestActionWithTooltip() { |
407 |
putValue(NAME, "name"); |
408 |
putValue(SHORT_DESCRIPTION, TOOLTIP); |
409 |
} |
410 |
|
411 |
public void actionPerformed(ActionEvent e) { |
412 |
} |
413 |
|
414 |
} |
308 |
|
415 |
|
309 |
public static final class Lkp extends AbstractLookup { |
416 |
public static final class Lkp extends AbstractLookup { |
310 |
public Lkp () { |
417 |
public Lkp () { |