jcomponent.java

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

JAVA
1,065
字号
/* JComponent.java -- Every component in swing inherits from this class.
   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.*;
import java.awt.peer.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.plaf.*;

import java.util.*;
import java.beans.*;

import javax.accessibility.*;

/**
 * Every component in swing inherits from this class (JLabel, JButton, etc).
 * It contains generic methods to manage events, properties and sizes.
 * Actual drawing of the component is channeled to a look-and-feel class
 * that is implemented elsewhere.
 *
 * @author Ronald Veldema (rveldema@cs.vu.nl)
 */
public abstract class JComponent extends Container implements Serializable
{
  static final long serialVersionUID = -5242478962609715464L;
        /**
         * accessibleContext
         */
        protected AccessibleContext accessibleContext;

	Dimension pref,min,max;
	Border border;
	JToolTip tooltip;
	String tool_tip_text;
	boolean use_double_buffer, opaque;
	protected ComponentUI ui;

	Vector ancestor_list;
	Vector veto_list;
	Vector change_list;
	Hashtable prop_hash;

	/**
	 * AccessibleJComponent
	 */
	public abstract class AccessibleJComponent 
		extends AccessibleAWTContainer {

		//-------------------------------------------------------------
		// Classes ----------------------------------------------------
		//-------------------------------------------------------------

		/**
		 * AccessibleFocusHandler
		 */
		protected class AccessibleFocusHandler implements FocusListener {

			//-------------------------------------------------------------
			// Variables --------------------------------------------------
			//-------------------------------------------------------------


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

			/**
			 * Constructor AccessibleFocusHandler
			 * @param component TODO
			 */
			protected AccessibleFocusHandler(AccessibleJComponent component) {
				// TODO
			} // AccessibleFocusHandler()


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

			/**
			 * focusGained
			 * @param event TODO
			 */
			public void focusGained(FocusEvent event) {
				// TODO
			} // focusGained()

			/**
			 * focusLost
			 * @param event TODO
			 */
			public void focusLost(FocusEvent valevent) {
				// TODO
			} // focusLost()


		} // AccessibleFocusHandler

		/**
		 * AccessibleContainerHandler
		 */
		protected class AccessibleContainerHandler implements ContainerListener {

			//-------------------------------------------------------------
			// Variables --------------------------------------------------
			//-------------------------------------------------------------


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

			/**
			 * Constructor AccessibleContainerHandler
			 * @param component TODO
			 */
			protected AccessibleContainerHandler(AccessibleJComponent component) {
				// TODO
			} // AccessibleContainerHandler()


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

			/**
			 * componentAdded
			 * @param event TODO
			 */
			public void componentAdded(ContainerEvent event) {
				// TODO
			} // componentAdded()

			/**
			 * componentRemoved
			 * @param event TODO
			 */
			public void componentRemoved(ContainerEvent valevent) {
				// TODO
			} // componentRemoved()


		} // AccessibleContainerHandler


		//-------------------------------------------------------------
		// Variables --------------------------------------------------
		//-------------------------------------------------------------

		/**
		 * accessibleContainerHandler
		 */
		protected ContainerListener accessibleContainerHandler;

		/**
		 * accessibleFocusHandler
		 */
		protected FocusListener accessibleFocusHandler;


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

		/**
		 * Constructor AccessibleJComponent
		 * @param component TODO
		 */
		protected AccessibleJComponent(JComponent component) {
//			super((Container)component);
			// TODO
		} // AccessibleJComponent()


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

		/**
		 * addPropertyChangeListener
		 * @param listener TODO
		 */
		public void addPropertyChangeListener(PropertyChangeListener listener) {
			// TODO
		} // addPropertyChangeListener()

		/**
		 * removePropertyChangeListener
		 * @param listener TODO
		 */
		public void removePropertyChangeListener(PropertyChangeListener listener) {
			// TODO
		} // removePropertyChangeListener()

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

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

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

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

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

		/**
		 * getAccessibleRole
		 * @returns AccessibleRole
		 */
		public AccessibleRole getAccessibleRole() {
			return null; // TODO
		} // getAccessibleRole()

		/**
		 * getBorderTitle
		 * @param value0 TODO
		 * @returns String
		 */
		protected String getBorderTitle(Border value0) {
			return null; // TODO
		} // getBorderTitle()


	} // AccessibleJComponent


        public JComponent()
	{
		super();
		super.setLayout(new FlowLayout());
		
		//eventMask |= AWTEvent.COMP_KEY_EVENT_MASK;
		enableEvents( AWTEvent.KEY_EVENT_MASK );

		//updateUI(); // get a proper ui
	}


	// protected EventListenerList listenerList
	public boolean contains(int x, int y)
	{
		//return dims.contains(x,y);
		return super.contains(x,y);
	}


	public  void addNotify()
	{
		//Notification to this component that it now has a parent component.
		super.addNotify();
	}


	Hashtable get_prop_hash()
	{
		if (prop_hash == null)
			prop_hash = new Hashtable();
		return prop_hash;
	}
	public Vector get_veto_list()
	{
		if (veto_list == null)
			veto_list = new Vector();
		return veto_list;
	}
	public Vector get_change_list()
	{
		if (change_list == null)
			change_list = new Vector();
		return change_list;
	}
	public Vector get_ancestor_list()
	{
		if (ancestor_list == null)
			ancestor_list = new Vector();
		return ancestor_list;
	}

	public Object getClientProperty(Object key)
        {	return get_prop_hash().get(key);    }

	public void putClientProperty(Object key, Object value)
	{    get_prop_hash().put(key, value);   }


	public void removeAncestorListener(AncestorListener listener)
	{  get_ancestor_list().removeElement(listener);  }

        public void removePropertyChangeListener(PropertyChangeListener listener)
	{  get_change_list().removeElement(listener);   }

	public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
	{  /* FIXME */   get_change_list().removeElement(listener);   }

	public void removeVetoableChangeListener(VetoableChangeListener listener)
	{  get_veto_list().removeElement(listener);   }

	public void addAncestorListener(AncestorListener listener)
	{   get_ancestor_list().addElement(listener);  }

	public void addPropertyChangeListener(PropertyChangeListener listener)
	{  get_change_list().addElement(listener);   }

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
	{ /* FIXME */ get_change_list().addElement(listener);   }

	public void addVetoableChangeListener(VetoableChangeListener listener)
	{  get_veto_list().addElement(listener);    }

	public void computeVisibleRect(Rectangle rect)
	{
		//Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors.
		//super.computeVisibleRect(rect);
	}


	public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
	{
		//Reports a bound property change.
	}
	public void firePropertyChange(String propertyName, byte oldValue, byte newValue)
	{
		//    Reports a bound property change.
	}
	public void firePropertyChange(String propertyName, char oldValue, char newValue)
	{
		//Reports a bound property change.
	}

	public void firePropertyChange(String propertyName, double oldValue, double newValue)
	{
		//Reports a bound property change.
	}

	public void firePropertyChange(String propertyName, float oldValue, float newValue)
	{
		//       Reports a bound property change.
	}
	public void firePropertyChange(String propertyName, int oldValue, int newValue)
	{
		//       Reports a bound property change.
	}
	public void firePropertyChange(String propertyName, long oldValue, long newValue)
	{
		//Reports a bound property change. protected
	}

  protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
	{
		//       Support for reporting bound property changes.
	}
	public void firePropertyChange(String propertyName, short oldValue, short newValue)
	{
		//       Reports a bound property change.
	}


	protected  void fireVetoableChange(String propertyName, Object oldValue, Object newValue)
	{
		//       Support for reporting constrained property changes.
	}

        public AccessibleContext getAccessibleContext()
	{
		//       Get the AccessibleContext associated with this JComponent
		return null;
	}
	
        public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
	{
		//Return the object that will perform the action registered for a given keystroke.
		return null;
	}
	public float getAlignmentX()
	{
		//    Overrides Container.getAlignmentX to return the vertical alignment.
		return 0;
	}

	public float getAlignmentY()
	{
		//       Overrides Container.getAlignmentY to return the horizontal alignment.
		return 0;
	}
	public boolean getAutoscrolls()
	{
		//Returns true if this component automatically scrolls its contents when dragged, (when contained in a component that supports scrolling, like JViewport
		return false;
	}

	public void setBorder(Border border)
	{
		//System.out.println("set border called !, new border = " + border);
		this.border = border;
		revalidate();
		repaint();
	}

	public Border getBorder()
	{	return border;    }


        public Rectangle getBounds(Rectangle rv)
	{
		if (rv == null)
			return new Rectangle(getX(),getY(),getWidth(),getHeight());
		else
		{
			rv.setBounds(getX(),getY(),getWidth(),getHeight());
			return rv;
		}
	}

	protected  Graphics getComponentGraphics(Graphics g)
	{      return g;       }

	public int getConditionForKeyStroke(KeyStroke aKeyStroke)
	{
		//Return the condition that determines whether a registered action occurs in response to the specified keystroke.
		return 0;
	}
	public int getDebugGraphicsOptions()
	{
		return 0;
	}

	public Graphics getGraphics()
	{	return super.getGraphics();    }


	//    static MantaNative void DebugMe(Border b);

	public Insets getInsets()
	{
		//	System.out.println("watch this border");
		//	DebugMe(border);
		//	System.out.println("border = " + border);

		if (border == null)
		{
			//System.out.println("compares to null !");
			return super.getInsets();
		}
		//	System.out.println("compare failed !");
		return getBorder().getBorderInsets(this);
	}

	public Insets getInsets(Insets insets)
	{
	    Insets t = getInsets();

	    if (insets == null)
		return t;
	    
	    
	    return new Insets(t.top, t.left, t.bottom, t.right);
	}
	public Point getLocation(Point rv)
	{
		//Store the x,y origin of this component into "return value" rv and return rv.

		if (rv == null)
			return new Point(getX(),
					 getY());

⌨️ 快捷键说明

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