1/*
2 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.java.swing.plaf.motif;
27
28import javax.swing.*;
29import javax.swing.event.*;
30import javax.swing.plaf.*;
31import javax.swing.plaf.basic.BasicButtonListener;
32import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
33
34import java.awt.*;
35import java.awt.event.*;
36import sun.swing.SwingUtilities2;
37
38
39/**
40 * MotifCheckboxMenuItem implementation
41 *
42 * @author Georges Saab
43 * @author Rich Schiavi
44 */
45public class MotifCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI
46{
47    protected ChangeListener changeListener;
48
49    public static ComponentUI createUI(JComponent b) {
50        return new MotifCheckBoxMenuItemUI();
51    }
52
53    protected void installListeners() {
54        super.installListeners();
55        changeListener = createChangeListener(menuItem);
56        menuItem.addChangeListener(changeListener);
57    }
58
59    protected void uninstallListeners() {
60        super.uninstallListeners();
61        menuItem.removeChangeListener(changeListener);
62    }
63
64    protected ChangeListener createChangeListener(JComponent c) {
65        return new ChangeHandler();
66    }
67
68    protected class ChangeHandler implements ChangeListener {
69        public void stateChanged(ChangeEvent e) {
70            JMenuItem c = (JMenuItem)e.getSource();
71            LookAndFeel.installProperty(c, "borderPainted", c.isArmed());
72        }
73    }
74
75    protected MouseInputListener createMouseInputListener(JComponent c) {
76        return new MouseInputHandler();
77    }
78
79
80    protected class MouseInputHandler implements MouseInputListener {
81        public void mouseClicked(MouseEvent e) {}
82        public void mousePressed(MouseEvent e) {
83            MenuSelectionManager manager = MenuSelectionManager.defaultManager();
84            manager.setSelectedPath(getPath());
85        }
86        public void mouseReleased(MouseEvent e) {
87            MenuSelectionManager manager =
88                MenuSelectionManager.defaultManager();
89            JMenuItem menuItem = (JMenuItem)e.getComponent();
90            Point p = e.getPoint();
91            if(p.x >= 0 && p.x < menuItem.getWidth() &&
92               p.y >= 0 && p.y < menuItem.getHeight()) {
93                String property = "CheckBoxMenuItem.doNotCloseOnMouseClick";
94                if (!SwingUtilities2.getBoolean(menuItem, property)) {
95                    manager.clearSelectedPath();
96                }
97                menuItem.doClick(0);
98            } else {
99                manager.processMouseEvent(e);
100            }
101        }
102        public void mouseEntered(MouseEvent e) {}
103        public void mouseExited(MouseEvent e) {}
104        public void mouseDragged(MouseEvent e) {
105            MenuSelectionManager.defaultManager().processMouseEvent(e);
106        }
107        public void mouseMoved(MouseEvent e) { }
108    }
109
110}
111