component.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 2,221 行 · 第 1/5 页
JAVA
2,221 行
* Describes all registered PropertyChangeListeners.
*
* @see #addPropertyChangeListener(PropertyChangeListener)
* @see #removePropertyChangeListener(PropertyChangeListener)
* @see #firePropertyChange(String, Object, Object)
* @serial the property change listeners
* @since 1.2
*/
PropertyChangeSupport changeSupport;
/**
* True if the component has been packed (layed out).
*
* @serial true if this is packed
*/
boolean isPacked;
/**
* The serialization version for this class. Currently at version 4.
*
* XXX How do we handle prior versions?
*
* @serial the serialization version
*/
int componentSerializedDataVersion = 4;
/**
* The accessible context associated with this component. This is only set
* by subclasses.
*
* @see #getAccessibleContext()
* @serial the accessibility context
* @since 1.2
*/
AccessibleContext accessibleContext;
// Guess what - listeners are special cased in serialization. See
// readObject and writeObject.
/** Component listener chain. */
transient ComponentListener componentListener;
/** Focus listener chain. */
transient FocusListener focusListener;
/** Key listener chain. */
transient KeyListener keyListener;
/** Mouse listener chain. */
transient MouseListener mouseListener;
/** Mouse motion listener chain. */
transient MouseMotionListener mouseMotionListener;
/**
* Mouse wheel listener chain.
*
* @since 1.4
*/
transient MouseWheelListener mouseWheelListener;
/**
* Input method listener chain.
*
* @since 1.2
*/
transient InputMethodListener inputMethodListener;
/**
* Hierarcy listener chain.
*
* @since 1.3
*/
transient HierarchyListener hierarchyListener;
/**
* Hierarcy bounds listener chain.
*
* @since 1.3
*/
transient HierarchyBoundsListener hierarchyBoundsListener;
// Anything else is non-serializable, and should be declared "transient".
/** The parent. */
transient Container parent;
/** The associated native peer. */
transient ComponentPeer peer;
/** The preferred component orientation. */
transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN;
/**
* The associated graphics configuration.
*
* @since 1.4
*/
transient GraphicsConfiguration graphicsConfig;
/**
* The buffer strategy for repainting.
*
* @since 1.4
*/
transient BufferStrategy bufferStrategy;
// Public and protected API.
/**
* Default constructor for subclasses. When Component is extended directly,
* it forms a lightweight component that must be hosted in an opaque native
* container higher in the tree.
*/
protected Component() {
}
/**
* Returns the name of this component.
*
* @return the name of this component
* @see #setName(String)
* @since 1.1
*/
public String getName() {
if (name == null && !nameExplicitlySet)
name = generateName();
return name;
}
/**
* Sets the name of this component to the specified name.
*
* @param name the new name of this component
* @see #getName()
* @since 1.1
*/
public void setName(String name) {
nameExplicitlySet = true;
this.name = name;
}
/**
* Returns the parent of this component.
*
* @return the parent of this component
*/
public Container getParent() {
return parent;
}
/**
* Returns the native windowing system peer for this component. Only the
* platform specific implementation code should call this method.
*
* @return the peer for this component
* @deprecated user programs should not directly manipulate peers; use
* {@link #isDisplayable()} instead
*/
// Classpath's Gtk peers rely on this.
public ComponentPeer getPeer() {
return peer;
}
/**
* Returns the native windowing system peer for this component. Only the
* JNode specific implementation code should call this method.
*
* @return the peer for this component
*/
public ComponentPeer getJNodePeer() {
return peer;
}
/**
* Set the associated drag-and-drop target, which receives events when this
* is enabled.
*
* @param dt the new drop target
* @see #isEnabled()
*/
public void setDropTarget(DropTarget dt) {
this.dropTarget = dt;
}
/**
* Gets the associated drag-and-drop target, if there is one.
*
* @return the drop target
*/
public DropTarget getDropTarget() {
return dropTarget;
}
/**
* Returns the graphics configuration of this component, if there is one.
* If it has not been set, it is inherited from the parent.
*
* @return the graphics configuration, or null
* @since 1.3
*/
public GraphicsConfiguration getGraphicsConfiguration() {
return getGraphicsConfigurationImpl();
}
/**
* Returns the object used for synchronization locks on this component
* when performing tree and layout functions.
*
* @return the synchronization lock for this component
*/
public final Object getTreeLock() {
return treeLock;
}
/**
* Returns the toolkit in use for this component. The toolkit is associated
* with the frame this component belongs to.
*
* @return the toolkit for this component
*/
public Toolkit getToolkit() {
if (peer != null) {
Toolkit tk = peer.getToolkit();
if (tk != null)
return tk;
}
if (parent != null)
return parent.getToolkit();
return Toolkit.getDefaultToolkit();
}
/**
* Tests whether or not this component is valid. A invalid component needs
* to have its layout redone.
*
* @return true if this component is valid
* @see #validate()
* @see #invalidate()
*/
public boolean isValid() {
return valid;
}
/**
* Tests if the component is displayable. It must be connected to a native
* screen resource, and all its ancestors must be displayable. A containment
* hierarchy is made displayable when a window is packed or made visible.
*
* @return true if the component is displayable
* @see Container#add(Component)
* @see Container#remove(Component)
* @see Window#pack()
* @see Window#show()
* @see Window#dispose()
* @since 1.2
*/
public boolean isDisplayable() {
if (parent != null)
return parent.isDisplayable();
return false;
}
/**
* Tests whether or not this component is visible. Except for top-level
* frames, components are initially visible.
*
* @return true if the component is visible
* @see #setVisible(boolean)
*/
public boolean isVisible() {
return visible;
}
/**
* Tests whether or not this component is actually being shown on
* the screen. This will be true if and only if it this component is
* visible and its parent components are all visible.
*
* @return true if the component is showing on the screen
* @see #setVisible(boolean)
*/
public boolean isShowing() {
if (!visible || peer == null)
return false;
return parent == null ? true : parent.isShowing();
}
/**
* Tests whether or not this component is enabled. Components are enabled
* by default, and must be enabled to receive user input or generate events.
*
* @return true if the component is enabled
* @see #setEnabled(boolean)
*/
public boolean isEnabled() {
return enabled;
}
/**
* Enables or disables this component. The component must be enabled to
* receive events (except that lightweight components always receive mouse
* events).
*
* @param enabled true to enable this component
* @see #isEnabled()
* @see #isLightweight()
* @since 1.1
*/
public void setEnabled(boolean b) {
this.enabled = b;
if (peer != null)
peer.setEnabled(b);
}
/**
* Enables this component.
*
* @deprecated use {@link #setEnabled(boolean)} instead
*/
public void enable() {
setEnabled(true);
}
/**
* Enables or disables this component.
*
* @param enabled true to enable this component
* @deprecated use {@link #setEnabled(boolean)} instead
*/
public void enable(boolean b) {
setEnabled(b);
}
/**
* Disables this component.
*
* @deprecated use {@link #setEnabled(boolean)} instead
*/
public void disable() {
setEnabled(false);
}
/**
* Checks if this image is painted to an offscreen image buffer that is
* later copied to screen (double buffering reduces flicker). This version
* returns false, so subclasses must override it if they provide double
* buffering.
*
* @return true if this is double buffered; defaults to false
*/
public boolean isDoubleBuffered() {
return false;
}
/**
* Enables or disables input method support for this component. By default,
* components have this enabled. Input methods are given the opportunity
* to process key events before this component and its listeners.
*
* @param enable true to enable input method processing
* @see #processKeyEvent(KeyEvent)
* @since 1.2
*/
public void enableInputMethods(boolean enable) {
// XXX Implement.
throw new Error("not implemented");
}
/**
* Makes this component visible or invisible. Note that it wtill might
* not show the component, if a parent is invisible.
*
* @param visible true to make this component visible
* @see #isVisible()
* @since 1.1
*/
public void setVisible(boolean b) {
// Inspection by subclassing shows that Sun's implementation calls
// show(boolean) which then calls show() or hide(). It is the show()
// method that is overriden in subclasses like Window.
if (peer != null)
peer.setVisible(b);
this.visible = b;
}
/**
* Makes this component visible on the screen.
*
* @deprecated use {@link #setVisible(boolean)} instead
*/
public void show() {
setVisible(true);
}
/**
* Makes this component visible or invisible.
*
* @param visible true to make this component visible
* @deprecated use {@link #setVisible(boolean)} instead
*/
public void show(boolean b) {
setVisible(b);
}
/**
* Hides this component so that it is no longer shown on the screen.
*
* @deprecated use {@link #setVisible(boolean)} instead
*/
public void hide() {
setVisible(false);
}
/**
* Returns this component's foreground color. If not set, this is inherited
* from the parent.
*
* @return this component's foreground color, or null
* @see #setForeground(Color)
*/
public Color getForeground() {
if (foreground != null)
return foreground;
return parent == null ? null : parent.getForeground();
}
/**
* Sets this component's foreground color to the specified color. This is a
* bound property.
*
* @param c the new foreground color
* @see #getForeground()
*/
public void setForeground(Color c) {
firePropertyChange("foreground", foreground, c);
if (peer != null)
peer.setForeground(c);
foreground = c;
}
/**
* Tests if the foreground was explicitly set, or just inherited from the
* parent.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?