1 /* 2 * Copyright (c) 2011, 2017, 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.apple.laf; 27 28 import java.beans.PropertyChangeEvent; 29 import java.beans.PropertyChangeListener; 30 import java.io.Serializable; 31 32 import javax.accessibility.AccessibleContext; 33 import javax.accessibility.AccessibleState; 34 import javax.swing.AbstractButton; 35 import javax.swing.Icon; 36 import javax.swing.JComponent; 37 import javax.swing.JMenuItem; 38 import javax.swing.KeyStroke; 39 40 class ScreenMenuPropertyListener implements PropertyChangeListener, Serializable { 41 private static final long serialVersionUID = -3236277050952156113L; 42 43 ScreenMenuPropertyHandler fMenu; 44 45 ScreenMenuPropertyListener(final ScreenMenuPropertyHandler mc) { 46 fMenu = mc; 47 } 48 49 /** 50 * This method gets called when a bound property is changed. 51 * @param e A PropertyChangeEvent object describing the event source 52 * and the property that has changed. 53 */ 54 public void propertyChange(final PropertyChangeEvent e) { 55 final String propertyName = e.getPropertyName(); 56 57 if ("enabled".equals(propertyName)) { 58 fMenu.setEnabled(((Boolean)e.getNewValue()).booleanValue()); 59 return; 60 } 61 62 if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(propertyName)) { 63 // rdar://Problem/3553843 64 // When an ACCESSIBLE_STATE_PROPERTY changes, it's always newValue == null and oldValue == state turned off 65 // or newValue == state turned on and oldValue == null. We only care about changes in the ENABLED 66 // state, so only change the menu's enabled state when the value is AccessibleState.ENABLED 67 if (e.getNewValue() == AccessibleState.ENABLED || e.getOldValue() == AccessibleState.ENABLED) { 68 final Object newValue = e.getNewValue(); 69 fMenu.setEnabled(newValue == AccessibleState.ENABLED); 70 } 71 return; 72 } 73 74 if ("accelerator".equals(propertyName)) { 75 fMenu.setAccelerator((KeyStroke)e.getNewValue()); 76 return; 77 } 78 79 if (AbstractButton.TEXT_CHANGED_PROPERTY.equals(propertyName)) { 80 fMenu.setLabel((String)e.getNewValue()); 81 return; 82 } 83 84 if (AbstractButton.ICON_CHANGED_PROPERTY.equals(propertyName)) { 85 fMenu.setIcon((Icon)e.getNewValue()); 86 return; 87 } 88 89 if (JComponent.TOOL_TIP_TEXT_KEY.equals(propertyName)) { 90 fMenu.setToolTipText((String)e.getNewValue()); 91 return; 92 } 93 94 if (AquaMenuItemUI.IndeterminateListener.CLIENT_PROPERTY_KEY.equals(propertyName)) { 95 fMenu.setIndeterminate(AquaMenuItemUI.IndeterminateListener.isIndeterminate((JMenuItem)e.getSource())); 96 return; 97 } 98 } 99 }