KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)MotifMenuItemUI.java 1.50 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
11 import javax.swing.*;
12 import javax.swing.event.*;
13 import java.awt.*;
14 import java.awt.event.*;
15
16 import javax.swing.plaf.*;
17 import javax.swing.plaf.basic.BasicMenuItemUI JavaDoc;
18
19
20 /**
21  * MotifMenuItem implementation
22  * <p>
23  *
24  * @author Rich Schiavi
25  * @author Georges Saab
26  */

27 public class MotifMenuItemUI extends BasicMenuItemUI JavaDoc
28 {
29     protected ChangeListener changeListener;
30
31     public static ComponentUI createUI(JComponent c)
32     {
33     return new MotifMenuItemUI();
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 MouseInputListener createMouseInputListener(JComponent c) {
52     return new MouseInputHandler();
53     }
54
55     public void paint(Graphics g, JComponent c) {
56     MotifGraphicsUtils.paintMenuItem(g, c, checkIcon,arrowIcon,
57                      selectionBackground, selectionForeground,
58                      defaultTextIconGap);
59     }
60
61     protected class ChangeHandler implements ChangeListener {
62
63     public void stateChanged(ChangeEvent e) {
64         JMenuItem c = (JMenuItem)e.getSource();
65             LookAndFeel.installProperty(c, "borderPainted",
66                         Boolean.valueOf(c.isArmed() || c.isSelected()));
67     }
68     }
69
70     protected class MouseInputHandler implements MouseInputListener {
71     public void mouseClicked(MouseEvent e) {}
72     public void mousePressed(MouseEvent e) {
73         MenuSelectionManager manager = MenuSelectionManager.defaultManager();
74         manager.setSelectedPath(getPath());
75     }
76     public void mouseReleased(MouseEvent e) {
77         MenuSelectionManager manager =
78         MenuSelectionManager.defaultManager();
79         JMenuItem menuItem = (JMenuItem)e.getComponent();
80         Point p = e.getPoint();
81         if(p.x >= 0 && p.x < menuItem.getWidth() &&
82            p.y >= 0 && p.y < menuItem.getHeight()) {
83                 manager.clearSelectedPath();
84                 menuItem.doClick(0);
85         } else {
86         manager.processMouseEvent(e);
87         }
88     }
89     public void mouseEntered(MouseEvent e) {}
90     public void mouseExited(MouseEvent e) {}
91     public void mouseDragged(MouseEvent e) {
92         MenuSelectionManager.defaultManager().processMouseEvent(e);
93     }
94     public void mouseMoved(MouseEvent e) { }
95     }
96   
97 }
98
99
100
101
102
103
104
105
Popular Tags