KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifRadioButtonMenuItemUI


1 /*
2  * @(#)MotifRadioButtonMenuItemUI.java 1.42 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7  
8 package com.sun.java.swing.plaf.motif;
9
10 import javax.swing.*;
11 import javax.swing.event.*;
12 import javax.swing.plaf.*;
13 import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI JavaDoc;
14
15 import java.awt.*;
16 import java.awt.event.*;
17 import java.io.Serializable JavaDoc;
18
19
20 /**
21  * MotifRadioButtonMenuItem implementation
22  * <p>
23  * <strong>Warning:</strong>
24  * Serialized objects of this class will not be compatible with
25  * future Swing releases. The current serialization support is appropriate
26  * for short term storage or RMI between applications running the same
27  * version of Swing. A future release of Swing will provide support for
28  * long term persistence.
29  *
30  * @version 1.42 12/19/03
31  * @author Georges Saab
32  * @author Rich Schiavi
33  */

34 public class MotifRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI JavaDoc
35 {
36     protected ChangeListener changeListener;
37
38     public static ComponentUI createUI(JComponent b) {
39         return new MotifRadioButtonMenuItemUI();
40     }
41
42     protected void installListeners() {
43     super.installListeners();
44         changeListener = createChangeListener(menuItem);
45         menuItem.addChangeListener(changeListener);
46     }
47     
48     protected void uninstallListeners() {
49     super.uninstallListeners();
50     menuItem.removeChangeListener(changeListener);
51     }
52
53     protected ChangeListener createChangeListener(JComponent c) {
54     return new ChangeHandler();
55     }
56
57     protected class ChangeHandler implements ChangeListener, Serializable JavaDoc {
58     public void stateChanged(ChangeEvent e) {
59         JMenuItem c = (JMenuItem)e.getSource();
60         if (c.isArmed()) {
61         c.setBorderPainted(true);
62         } else {
63         c.setBorderPainted(false);
64         }
65     }
66     }
67
68     public void paint(Graphics g, JComponent c) {
69     MotifGraphicsUtils.paintMenuItem(g, c,
70                      checkIcon,
71                      arrowIcon,
72                      selectionBackground,
73                      selectionForeground,
74                      defaultTextIconGap);
75     }
76
77     protected MouseInputListener createMouseInputListener(JComponent c) {
78     return new MouseInputHandler();
79     }
80
81
82     protected class MouseInputHandler implements MouseInputListener {
83     public void mouseClicked(MouseEvent e) {}
84     public void mousePressed(MouseEvent e) {
85         MenuSelectionManager manager = MenuSelectionManager.defaultManager();
86         manager.setSelectedPath(getPath());
87     }
88     public void mouseReleased(MouseEvent e) {
89         MenuSelectionManager manager =
90         MenuSelectionManager.defaultManager();
91         JMenuItem menuItem = (JMenuItem)e.getComponent();
92         Point p = e.getPoint();
93         if(p.x >= 0 && p.x < menuItem.getWidth() &&
94            p.y >= 0 && p.y < menuItem.getHeight()) {
95                 manager.clearSelectedPath();
96                 menuItem.doClick(0);
97         } else {
98         manager.processMouseEvent(e);
99         }
100     }
101     public void mouseEntered(MouseEvent e) {}
102     public void mouseExited(MouseEvent e) {}
103     public void mouseDragged(MouseEvent e) {
104         MenuSelectionManager.defaultManager().processMouseEvent(e);
105     }
106     public void mouseMoved(MouseEvent e) { }
107     }
108
109 }
110
111
112
113
114
115
116
117
118
Popular Tags