📄 abstractbuttonstylesupport.java
字号:
/* * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */package com.sun.stylesheet.styleable;import java.awt.*;import java.beans.*;import java.lang.reflect.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;import com.sun.stylesheet.*;import com.sun.stylesheet.types.*;/** * Implements <code>Styleable</code> support for {@link AbstractButton * AbstractButtons}. In addition to the basic support provided by its * superclass, <code>AbstractButtonStyleSupport</code> adds support for the * <code>text-decoration</code> synthetic property. * *@author Ethan Nicholas */public class AbstractButtonStyleSupport extends ComponentStyleSupport { private Map<PseudoclassListener, ChangeListener> armedListeners; /** * Creates a new <code>AbstractButtonStyleSupport</code> for the specified * class. * *@param cls the specific button class to support */ public AbstractButtonStyleSupport(Class cls) { super(cls); } protected void init() throws IntrospectionException { super.init(); properties.put("text-decoration", new TextDecorationHandler(this)); } protected void createPropertyHandler(PropertyDescriptor descriptor) { String name = descriptor.getName(); if (name.equals("text")) properties.put(name, new TextHandler(this, descriptor)); else super.createPropertyHandler(descriptor); } private synchronized ChangeListener getArmedListener( final PseudoclassListener listener, final PseudoclassEvent event, final boolean inverse) { if (armedListeners == null) armedListeners = new HashMap<PseudoclassListener, ChangeListener>(); ChangeListener result = armedListeners.get(listener); if (result == null) { result = new ChangeListener() { public void stateChanged(ChangeEvent e) { AbstractButton button = (AbstractButton) e.getSource(); if (inverse != button.getModel().isArmed()) listener.pseudoclassAdded(event); else listener.pseudoclassRemoved(event); } }; armedListeners.put(listener, result); } return result; } public void addPseudoclassListener(DefaultStyleable styleable, String pseudoclass, final PseudoclassListener listener) throws StylesheetException { final PseudoclassEvent event = new PseudoclassEvent(styleable, pseudoclass); if (pseudoclass.equals("armed") || pseudoclass.equals("unarmed")) { boolean inverse = pseudoclass.equals("unarmed"); AbstractButton button = (AbstractButton) styleable.getBaseObject(); if (button.getModel().isArmed() != inverse) listener.pseudoclassAdded(event); button.addChangeListener(getArmedListener(listener, event, inverse)); } else super.addPseudoclassListener(styleable, pseudoclass, listener); } public void removePseudoclassListener(DefaultStyleable styleable, String pseudoclass, final PseudoclassListener listener) throws StylesheetException { if (pseudoclass.equals("armed") || pseudoclass.equals("unarmed")) { boolean inverse = pseudoclass.equals("unarmed"); AbstractButton button = (AbstractButton) styleable.getBaseObject(); button.removeChangeListener(getArmedListener(listener, null, inverse)); } else super.removePseudoclassListener(styleable, pseudoclass, listener); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -