abstractbutton.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 759 行 · 第 1/2 页

JAVA
759
字号
/* AbstractButton.java -- Provides basic button functionality.
   Copyright (C) 2002 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath 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 for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package javax.swing;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.ItemSelectable;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeListener;

import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleIcon;
import javax.accessibility.AccessibleRelationSet;
import javax.accessibility.AccessibleStateSet;
import javax.accessibility.AccessibleText;
import javax.accessibility.AccessibleValue;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ButtonUI;
import javax.swing.text.AttributeSet;

/**
 * Provides basic button functionality
 *
 * @author Ronald Veldema (rveldema@cs.vu.nl)
 */
public abstract class AbstractButton extends JComponent implements ItemSelectable, SwingConstants {
	Icon default_icon, pressed_button, disabled_button, selected_button, disabled_selected_button, current_icon;
	String text;

	int vert_align = CENTER;
	int hori_align = CENTER;
	int hori_text_pos = CENTER;
	int vert_text_pos = CENTER;

	boolean paint_border = true, paint_focus;
	Action action_taken;
	ButtonModel model;
	Insets margin;

	public static final String FOCUS_PAINTED_CHANGED_PROPERTY = "focusPainted";

	/**
	 * AccessibleAbstractButton
	 */
	protected abstract class AccessibleAbstractButton extends AccessibleJComponent implements AccessibleAction, AccessibleValue, AccessibleText {

		//-------------------------------------------------------------
		// Initialization ---------------------------------------------
		//-------------------------------------------------------------

		/**
		 * Constructor AccessibleAbstractButton
		 * @param component TODO
		 */
		protected AccessibleAbstractButton(AbstractButton component) {
			super(component);
			// TODO
		} // AccessibleAbstractButton()

		//-------------------------------------------------------------
		// Methods ----------------------------------------------------
		//-------------------------------------------------------------

		/**
		 * getAccessibleStateSet
		 * @returns AccessibleStateSet
		 */
		public AccessibleStateSet getAccessibleStateSet() {
			return null; // TODO
		} // getAccessibleStateSet()

		/**
		 * getAccessibleName
		 * @returns String
		 */
		public String getAccessibleName() {
			return null; // TODO
		} // getAccessibleName()

		/**
		 * getAccessibleIcon
		 * @returns AccessibleIcon[]
		 */
		public AccessibleIcon[] getAccessibleIcon() {
			return null; // TODO
		} // getAccessibleIcon()

		/**
		 * getAccessibleRelationSet
		 * @returns AccessibleRelationSet
		 */
		public AccessibleRelationSet getAccessibleRelationSet() {
			return null; // TODO
		} // getAccessibleRelationSet()

		/**
		 * getAccessibleAction
		 * @returns AccessibleAction
		 */
		public AccessibleAction getAccessibleAction() {
			return null; // TODO
		} // getAccessibleAction()

		/**
		 * getAccessibleValue
		 * @returns AccessibleValue
		 */
		public AccessibleValue getAccessibleValue() {
			return null; // TODO
		} // getAccessibleValue()

		/**
		 * getAccessibleActionCount
		 * @returns int
		 */
		public int getAccessibleActionCount() {
			return 0; // TODO
		} // getAccessibleActionCount()

		/**
		 * getAccessibleActionDescription
		 * @param value0 TODO
		 * @returns String
		 */
		public String getAccessibleActionDescription(int value0) {
			return null; // TODO
		} // getAccessibleActionDescription()

		/**
		 * doAccessibleAction
		 * @param value0 TODO
		 * @returns boolean
		 */
		public boolean doAccessibleAction(int value0) {
			return false; // TODO
		} // doAccessibleAction()

		/**
		 * getCurrentAccessibleValue
		 * @returns Number
		 */
		public Number getCurrentAccessibleValue() {
			return null; // TODO
		} // getCurrentAccessibleValue()

		/**
		 * setCurrentAccessibleValue
		 * @param value0 TODO
		 * @returns boolean
		 */
		public boolean setCurrentAccessibleValue(Number value0) {
			return false; // TODO
		} // setCurrentAccessibleValue()

		/**
		 * getMinimumAccessibleValue
		 * @returns Number
		 */
		public Number getMinimumAccessibleValue() {
			return null; // TODO
		} // getMinimumAccessibleValue()

		/**
		 * getMaximumAccessibleValue
		 * @returns Number
		 */
		public Number getMaximumAccessibleValue() {
			return null; // TODO
		} // getMaximumAccessibleValue()

		/**
		 * getAccessibleText
		 * @returns AccessibleText
		 */
		public AccessibleText getAccessibleText() {
			return null; // TODO
		} // getAccessibleText()

		/**
		 * getIndexAtPoint
		 * @param value0 TODO
		 * @returns int
		 */
		public int getIndexAtPoint(Point value0) {
			return 0; // TODO
		} // getIndexAtPoint()

		/**
		 * getCharacterBounds
		 * @param value0 TODO
		 * @returns Rectangle
		 */
		public Rectangle getCharacterBounds(int value0) {
			return null; // TODO
		} // getCharacterBounds()

		/**
		 * getCharCount
		 * @returns int
		 */
		public int getCharCount() {
			return 0; // TODO
		} // getCharCount()

		/**
		 * getCaretPosition
		 * @returns int
		 */
		public int getCaretPosition() {
			return 0; // TODO
		} // getCaretPosition()

		/**
		 * getAtIndex
		 * @param value0 TODO
		 * @param value1 TODO
		 * @returns String
		 */
		public String getAtIndex(int value0, int value1) {
			return null; // TODO
		} // getAtIndex()

		/**
		 * getAfterIndex
		 * @param value0 TODO
		 * @param value1 TODO
		 * @returns String
		 */
		public String getAfterIndex(int value0, int value1) {
			return null; // TODO
		} // getAfterIndex()

		/**
		 * getBeforeIndex
		 * @param value0 TODO
		 * @param value1 TODO
		 * @returns String
		 */
		public String getBeforeIndex(int value0, int value1) {
			return null; // TODO
		} // getBeforeIndex()

		/**
		 * getCharacterAttribute
		 * @param value0 TODO
		 * @returns AttributeSet
		 */
		public AttributeSet getCharacterAttribute(int value0) {
			return null; // TODO
		} // getCharacterAttribute()

		/**
		 * getSelectionStart
		 * @returns int
		 */
		public int getSelectionStart() {
			return 0; // TODO
		} // getSelectionStart()

		/**
		 * getSelectionEnd
		 * @returns int
		 */
		public int getSelectionEnd() {
			return 0; // TODO
		} // getSelectionEnd()

		/**
		 * getSelectedText
		 * @returns String
		 */
		public String getSelectedText() {
			return null; // TODO
		} // getSelectedText()

		/**
		 * getTextRectangle
		 * @returns Rectangle
		 */
		private Rectangle getTextRectangle() {
			return null; // TODO
		} // getTextRectangle()

	} // AccessibleAbstractButton

	static private class JFocusListener implements FocusListener {
		AbstractButton c;

		JFocusListener(AbstractButton c) {
			this.c = c;
		}

		public void focusLost(FocusEvent event) {
			c.getModel().setArmed(false);

			System.out.println("LOST FOCUS");
			if (c.isFocusPainted()) {
				c.repaint();
			}
		}
		public void focusGained(FocusEvent event) {
			System.out.println("GAIN FOCUS");
		}
	}

	/**********************************************
	 *
	 * 
	 *       Constructors
	 *
	 *
	 ****************/

	AbstractButton() {
		this("", null);
	}

	AbstractButton(String text, Icon icon) {
		this.text = text;
		setIcon(icon);

		setAlignmentX(LEFT_ALIGNMENT);
		setAlignmentY(CENTER_ALIGNMENT);

		addFocusListener(new JFocusListener(this));

		setModel(new DefaultButtonModel(this));

		updateUI(); // get a proper ui
	}

	/**********************************************
	 *
	 * 
	 *       Actions etc

⌨️ 快捷键说明

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