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