⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skinsimplebuttonindexmodel.java

📁 XP Look And Feel
💻 JAVA
字号:
// Beta
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*   XP Look and Feel                                                       *
*                                                                              *
*  (C) Copyright 2002, by Stefan Krause                                        *
*                                                                              *
*                                                                              *
*   This library is free software; you can redistribute it and/or modify it    *
*   under the terms of the GNU Lesser General Public License as published by   *
*   the Free Software Foundation; either version 2.1 of the License, or (at    *
*   your option) any later version.                                            *
*                                                                              *
*   This library 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 Lesser General Public License for more details.                *
*                                                                              *
*   You should have received a copy of the GNU General Public License along    *
*   with this program; if not, write to the Free Software Foundation, Inc.,    *
*   59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.                    *
*                                                                              *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package com.stefankrause.xplookandfeel.skin;

import javax.swing.AbstractButton;

/**
 * A Simple Index Model for a button. Use it to calculate which of the subimages
 * of a skin should be used.
 * 
 * The order of evaluation of the states is:
 * 1. Test if button is disabled
 * 2. Test if button is pressed
 * 3. Test if button is in rollover state
 * 4. Button must be in normal state then.
 * 
 * The first test that evaluates to true determines the index for the skin to
 * be used.
 * 
 * If the component is not a subclass of AbstractButton one can explicitly
 * pass the relevant states to getIndexForState but use the same logic.
 */
public class SkinSimpleButtonIndexModel  {
	private AbstractButton button;
	
    private int normal,rollover,pressed,disabled;
	
	/**
	 * Creates a SkinIndexModel for the button with the indices normal=0,
	 * rollover=1, pushed=2 and disabled=3
	 * @param button
	 */
	public SkinSimpleButtonIndexModel()
	{
		this.normal=0;
		this.rollover=1;
		this.pressed=2;
		this.disabled=3;
	}
    
    /**
     * Creates a SkinIndexModel for the button with the given states.
     * 
     * @param normal the index of the normal image
     * @param rollover the index of the rollover image
     * @param pressed the index of the pressed image
     * @param disabled the index of the disabled image
     */	
	public SkinSimpleButtonIndexModel(int normal,int rollover,int pressed,int disabled)
	{
		this.normal=normal;
		this.rollover=rollover;
		this.pressed=pressed;
		this.disabled=disabled;
	}

    /**
     * Returns the index of the image of the skin to be used for rendering.
     * The button must be set before calling <code>getIndexForState</code>.
     * @see setButton
     * @return int the index of the image that should be used for rendering due to the state of the button
     */
	public int getIndexForState() {
		
		if (!button.isEnabled())
			return disabled;
		if (button.getModel().isPressed() ) 		// Do we need to check for armed ??
			return pressed;
		if (button.getModel().isRollover())
			return rollover;
	
		return normal;
	}
	
	/**
	 * This methode can be used for other Components than AbstractButtons. The states are passed
	 * directly, but the logic to decide which index to use is the same as in <code>getIndexForState</code>
     * so that consistency is preserved. 
	 * @param isEnabled
	 * @param isPressed
	 * @param isRollover
	 * @return int
	 */
	public int getIndexForState(boolean isEnabled, boolean isRollover, boolean isPressed)
	{
		if (!isEnabled)
			return disabled;
		if (isPressed ) 		// Do we need to check for armed ??
			return pressed;
		if (isRollover)
			return rollover;

		return normal;		
	}
	
	/**
	 * Returns the button.
	 * @return AbstractButton
	 */
	public AbstractButton getButton() {
		return button;
	}

	/**
	 * Sets the button.
	 * @param button The button to set
	 */
	public void setButton(AbstractButton button) {
		this.button = button;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -