KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)MotifCheckBoxMenuItemUI.java 1.44 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.BasicButtonListener JavaDoc;
14 import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI JavaDoc;
15
16 import java.awt.*;
17 import java.awt.event.*;
18
19
20 /**
21  * MotifCheckboxMenuItem implementation
22  * <p>
23  *
24  * @version 1.44 12/19/03
25  * @author Georges Saab
26  * @author Rich Schiavi
27  */

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