Path: blob/master/src/java.desktop/macosx/classes/sun/lwawt/LWButtonPeer.java
41153 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526package sun.lwawt;2728import java.awt.Button;29import java.awt.event.ActionEvent;30import java.awt.event.ActionListener;31import java.awt.peer.ButtonPeer;3233import javax.swing.JButton;3435/**36* Lightweight implementation of {@link ButtonPeer}. Delegates most of the work37* to the {@link JButton}.38*/39final class LWButtonPeer extends LWComponentPeer<Button, JButton>40implements ButtonPeer, ActionListener {4142LWButtonPeer(final Button target,43final PlatformComponent platformComponent) {44super(target, platformComponent);45}4647@Override48JButton createDelegate() {49return new JButtonDelegate();50}5152@Override53void initializeImpl() {54super.initializeImpl();55setLabel(getTarget().getLabel());56synchronized (getDelegateLock()) {57getDelegate().addActionListener(this);58}59}6061@Override62public void actionPerformed(final ActionEvent e) {63postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,64getTarget().getActionCommand(), e.getWhen(),65e.getModifiers()));66}6768@Override69public void setLabel(final String label) {70synchronized (getDelegateLock()) {71getDelegate().setText(label);72}73}7475@Override76public boolean isFocusable() {77return true;78}7980@SuppressWarnings("serial")// Safe: outer class is non-serializable.81private final class JButtonDelegate extends JButton {8283@Override84public boolean hasFocus() {85return getTarget().hasFocus();86}87}88}899091