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.awt.*;
29 import java.awt.event.*;
30 import java.awt.peer.MenuComponentPeer;
31
32 import javax.swing.*;
33 import javax.swing.plaf.ButtonUI;
34
35 import com.apple.laf.AquaMenuItemUI.IndeterminateListener;
36
37 import sun.lwawt.macosx.*;
38
39 class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener {
40 JMenuItem fMenuItem;
41 MenuContainer fParent;
42
43 ScreenMenuItemCheckbox(final JCheckBoxMenuItem mi) {
44 super(mi.getText(), mi.getState());
45 init(mi);
46 }
47
48 ScreenMenuItemCheckbox(final JRadioButtonMenuItem mi) {
49 super(mi.getText(), mi.getModel().isSelected());
50 init(mi);
51 }
52
53 public void init(final JMenuItem mi) {
54 fMenuItem = mi;
55 setEnabled(fMenuItem.isEnabled());
56 }
57
58 ScreenMenuPropertyListener fPropertyListener;
59 public void addNotify() {
93 }
94
95 if (fMenuItem instanceof JCheckBoxMenuItem) {
96 setState(((JCheckBoxMenuItem)fMenuItem).isSelected());
97 } else {
98 setState(fMenuItem.getModel().isSelected());
99 }
100 }
101
102 public void removeNotify() {
103 fMenuItem.removeComponentListener(this);
104 fMenuItem.removePropertyChangeListener(fPropertyListener);
105 fPropertyListener = null;
106 removeActionListener(this);
107 removeItemListener(this);
108 fMenuItem.removeItemListener(this);
109
110 super.removeNotify();
111 }
112
113 public void setAccelerator(final KeyStroke ks) {
114 if (ks == null) {
115 setShortcut(null);
116 return;
117 }
118
119 final MenuComponentPeer peer = getPeer();
120 if (peer instanceof CMenuItem) {
121 final CMenuItem ourPeer = (CMenuItem)peer;
122 ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers());
123 } else {
124 setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0));
125 }
126 }
127
128 public void actionPerformed(final ActionEvent e) {
129 fMenuItem.doClick(0); // This takes care of all the different events
130 }
131
132 /**
133 * Invoked when the component's size changes.
134 */
135 public void componentResized(final ComponentEvent e) {}
136
137 /**
138 * Invoked when the component's position changes.
139 */
140 public void componentMoved(final ComponentEvent e) {}
141
142 /**
143 * Invoked when the component has been made visible.
144 * See componentHidden - we should still have a MenuItem
145 * it just isn't inserted
|
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.awt.*;
29 import java.awt.event.*;
30 import java.awt.peer.MenuComponentPeer;
31
32 import javax.swing.*;
33 import javax.swing.plaf.ButtonUI;
34
35 import com.apple.laf.AquaMenuItemUI.IndeterminateListener;
36
37 import sun.lwawt.macosx.*;
38
39 final class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener {
40 JMenuItem fMenuItem;
41 MenuContainer fParent;
42
43 ScreenMenuItemCheckbox(final JCheckBoxMenuItem mi) {
44 super(mi.getText(), mi.getState());
45 init(mi);
46 }
47
48 ScreenMenuItemCheckbox(final JRadioButtonMenuItem mi) {
49 super(mi.getText(), mi.getModel().isSelected());
50 init(mi);
51 }
52
53 public void init(final JMenuItem mi) {
54 fMenuItem = mi;
55 setEnabled(fMenuItem.isEnabled());
56 }
57
58 ScreenMenuPropertyListener fPropertyListener;
59 public void addNotify() {
93 }
94
95 if (fMenuItem instanceof JCheckBoxMenuItem) {
96 setState(((JCheckBoxMenuItem)fMenuItem).isSelected());
97 } else {
98 setState(fMenuItem.getModel().isSelected());
99 }
100 }
101
102 public void removeNotify() {
103 fMenuItem.removeComponentListener(this);
104 fMenuItem.removePropertyChangeListener(fPropertyListener);
105 fPropertyListener = null;
106 removeActionListener(this);
107 removeItemListener(this);
108 fMenuItem.removeItemListener(this);
109
110 super.removeNotify();
111 }
112
113 @Override
114 public synchronized void setLabel(final String label) {
115 ScreenMenuItem.syncLabelAndKS(this, label, fMenuItem.getAccelerator());
116 }
117
118 @Override
119 public void setAccelerator(final KeyStroke ks) {
120 // We call CMenuItem.setLabel(..,..,..) directly and does not initialize
121 // shortcut property. So shortcut property should not be used from the
122 // peers code directly or indirectly.
123 ScreenMenuItem.syncLabelAndKS(this, fMenuItem.getText(), ks);
124 }
125
126 public void actionPerformed(final ActionEvent e) {
127 fMenuItem.doClick(0); // This takes care of all the different events
128 }
129
130 /**
131 * Invoked when the component's size changes.
132 */
133 public void componentResized(final ComponentEvent e) {}
134
135 /**
136 * Invoked when the component's position changes.
137 */
138 public void componentMoved(final ComponentEvent e) {}
139
140 /**
141 * Invoked when the component has been made visible.
142 * See componentHidden - we should still have a MenuItem
143 * it just isn't inserted
|