1
2
3
4
5 package spellcast.ui;
6
7 import java.awt.*;
8 import javax.swing.*;
9 import javax.swing.plaf.basic.BasicMenuItemUI;
10
11 /***
12 * This is the UI delegate that handles the displaying of the
13 * <code>GestureChoicesMenuItem</code>. It restricts the menu item
14 * to only display the icon with no border. Unfortunately this means
15 * that the menu items dont display which menu item is armed.
16 *
17 * @author Barrie Treloar
18 */
19 public class GestureMenuItemUI extends BasicMenuItemUI
20 {
21 /***
22 * Override the property to use for UI defaults to be GestureChoicesMenuItem.
23 */
24 protected String getPropertyPrefix() {
25 return "GestureMenuItem";
26 }
27
28 /***
29 * Override the minimum size to be the preferred size.
30 */
31 public Dimension getMinimumSize( JComponent c )
32 {
33 return getPreferredSize( c );
34 }
35
36 /***
37 * Override the maximum size to be the preferred size.
38 */
39 public Dimension getMaximumSize( JComponent c )
40 {
41 return getPreferredSize( c );
42 }
43
44 public Dimension getPreferredSize( JComponent c )
45 {
46 JMenuItem b = (JMenuItem) c;
47 Icon icon = (Icon) b.getIcon();
48 Dimension result = new Dimension();
49 result.width = icon.getIconWidth();
50 result.height = icon.getIconHeight();
51 return result;
52 }
53
54 /***
55 * Override painting to just paint the icon with no borders or embellishments.
56 */
57 public void paint(Graphics g, JComponent c)
58 {
59 JMenuItem b = (JMenuItem) c;
60 ButtonModel model = b.getModel();
61 Icon icon = (Icon) b.getIcon();
62 if ( icon != null )
63 {
64 icon.paintIcon(c, g, 0, 0);
65 }
66 }
67 }
68