LWButtonPeer.java revision 4632
5598N/A/*
5598N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
5598N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5598N/A *
5598N/A * This code is free software; you can redistribute it and/or modify it
5598N/A * under the terms of the GNU General Public License version 2 only, as
5598N/A * published by the Free Software Foundation. Oracle designates this
5598N/A * particular file as subject to the "Classpath" exception as provided
5598N/A * by Oracle in the LICENSE file that accompanied this code.
5598N/A *
5598N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5598N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5598N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5598N/A * version 2 for more details (a copy is included in the LICENSE file that
5598N/A * accompanied this code).
5598N/A *
5598N/A * You should have received a copy of the GNU General Public License version
5598N/A * 2 along with this work; if not, write to the Free Software Foundation,
5598N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5598N/A *
5598N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5598N/A * or visit www.oracle.com if you need additional information or have any
5598N/A * questions.
5598N/A */
5598N/A
5598N/A
5598N/Apackage sun.lwawt;
5598N/A
5598N/Aimport java.awt.Button;
5598N/Aimport java.awt.Color;
5598N/Aimport java.awt.event.ActionEvent;
5598N/Aimport java.awt.event.ActionListener;
5598N/Aimport java.awt.peer.ButtonPeer;
5598N/A
5598N/Aimport javax.swing.JButton;
5598N/A
5598N/Afinal class LWButtonPeer extends LWComponentPeer<Button, JButton>
5598N/A implements ButtonPeer, ActionListener {
5598N/A
5598N/A // We don't support background and foreground colors for button
5598N/A // since AquaButtonUI doesn't do it
5598N/A private Color background, foreground;
5598N/A
5598N/A LWButtonPeer(final Button target,
5598N/A final PlatformComponent platformComponent) {
5598N/A super(target, platformComponent);
5598N/A }
5598N/A
5598N/A @Override
5598N/A protected JButton createDelegate() {
5598N/A return new JButtonDelegate();
5598N/A }
5598N/A
5598N/A @Override
5598N/A public void initialize() {
5598N/A super.initialize();
5598N/A setLabel(getTarget().getLabel());
5598N/A synchronized (getDelegateLock()) {
5598N/A getDelegate().addActionListener(this);
5598N/A }
5598N/A }
5598N/A
5598N/A public Color getBackground() {
5598N/A return background;
5598N/A }
5598N/A
5598N/A public void setBackground(Color background) {
5598N/A this.background = background;
5598N/A }
5598N/A
5598N/A public Color getForeground() {
5598N/A return foreground;
5598N/A }
5598N/A
5598N/A public void setForeground(Color foreground) {
5598N/A this.foreground = foreground;
5598N/A }
5598N/A
5598N/A @Override
5598N/A public void actionPerformed(final ActionEvent e) {
5598N/A postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
5598N/A getTarget().getActionCommand(), e.getWhen(),
5598N/A e.getModifiers()));
5598N/A }
5598N/A
5598N/A @Override
5598N/A public void setLabel(final String label) {
5598N/A synchronized (getDelegateLock()) {
5598N/A getDelegate().setText(label);
5598N/A }
5598N/A }
5598N/A
5598N/A @Override
5598N/A public boolean isFocusable() {
5598N/A return true;
5598N/A }
5598N/A
5598N/A private final class JButtonDelegate extends JButton {
5598N/A
5598N/A // Empty non private constructor was added because access to this
5598N/A // class shouldn't be emulated by a synthetic accessor method.
5598N/A JButtonDelegate() {
5598N/A super();
5598N/A }
5598N/A
@Override
public boolean hasFocus() {
return getTarget().hasFocus();
}
}
}