001: /*
002: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java.swing.plaf.motif;
027:
028: import javax.swing.*;
029: import javax.swing.event.*;
030: import javax.swing.plaf.*;
031: import javax.swing.plaf.basic.BasicButtonListener;
032: import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
033:
034: import java.awt.*;
035: import java.awt.event.*;
036:
037: /**
038: * MotifCheckboxMenuItem implementation
039: * <p>
040: *
041: * @version 1.53 05/05/07
042: * @author Georges Saab
043: * @author Rich Schiavi
044: */
045: public class MotifCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
046: protected ChangeListener changeListener;
047:
048: public static ComponentUI createUI(JComponent b) {
049: return new MotifCheckBoxMenuItemUI();
050: }
051:
052: protected void installListeners() {
053: super .installListeners();
054: changeListener = createChangeListener(menuItem);
055: menuItem.addChangeListener(changeListener);
056: }
057:
058: protected void uninstallListeners() {
059: super .uninstallListeners();
060: menuItem.removeChangeListener(changeListener);
061: }
062:
063: protected ChangeListener createChangeListener(JComponent c) {
064: return new ChangeHandler();
065: }
066:
067: protected class ChangeHandler implements ChangeListener {
068: public void stateChanged(ChangeEvent e) {
069: JMenuItem c = (JMenuItem) e.getSource();
070: LookAndFeel
071: .installProperty(c, "borderPainted", c.isArmed());
072: }
073: }
074:
075: protected MouseInputListener createMouseInputListener(JComponent c) {
076: return new MouseInputHandler();
077: }
078:
079: protected class MouseInputHandler implements MouseInputListener {
080: public void mouseClicked(MouseEvent e) {
081: }
082:
083: public void mousePressed(MouseEvent e) {
084: MenuSelectionManager manager = MenuSelectionManager
085: .defaultManager();
086: manager.setSelectedPath(getPath());
087: }
088:
089: public void mouseReleased(MouseEvent e) {
090: MenuSelectionManager manager = MenuSelectionManager
091: .defaultManager();
092: JMenuItem menuItem = (JMenuItem) e.getComponent();
093: Point p = e.getPoint();
094: if (p.x >= 0 && p.x < menuItem.getWidth() && p.y >= 0
095: && p.y < menuItem.getHeight()) {
096: manager.clearSelectedPath();
097: menuItem.doClick(0);
098: } else {
099: manager.processMouseEvent(e);
100: }
101: }
102:
103: public void mouseEntered(MouseEvent e) {
104: }
105:
106: public void mouseExited(MouseEvent e) {
107: }
108:
109: public void mouseDragged(MouseEvent e) {
110: MenuSelectionManager.defaultManager().processMouseEvent(e);
111: }
112:
113: public void mouseMoved(MouseEvent e) {
114: }
115: }
116:
117: }
|