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 
  26 package com.sun.java.swing.plaf.motif;
  27 
  28 import javax.swing.*;
  29 import javax.swing.event.*;
  30 import javax.swing.plaf.*;
  31 import javax.swing.plaf.basic.BasicButtonListener;
  32 import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
  33 
  34 import java.awt.*;
  35 import java.awt.event.*;
  36 
  37 
  38 /**
  39  * MotifCheckboxMenuItem implementation
  40  * <p>
  41  *
  42  * @author Georges Saab
  43  * @author Rich Schiavi
  44  */
  45 public 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                 manager.clearSelectedPath();
  94                 menuItem.doClick(0);
  95             } else {
  96                 manager.processMouseEvent(e);
  97             }
  98         }
  99         public void mouseEntered(MouseEvent e) {}
 100         public void mouseExited(MouseEvent e) {}
 101         public void mouseDragged(MouseEvent e) {
 102             MenuSelectionManager.defaultManager().processMouseEvent(e);
 103         }
 104         public void mouseMoved(MouseEvent e) { }
 105     }
 106 
 107 }