jcomponent.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 1,065 行 · 第 1/2 页
JAVA
1,065 行
rv.setLocation(getX(),
getY());
return rv;
}
public Dimension getMaximumSize()
{
if (max != null)
{
//System.out.println("HAVE_MAX_SIZE = " + max);
return max;
}
if (ui != null)
{
Dimension s = ui.getMaximumSize(this);
if (s != null)
{
//System.out.println(" UI-MAX = " + s + ", UI = " + ui + ", IM="+this);
return s;
}
}
Dimension p = super.getMaximumSize();
//System.out.println(" MAX = " + p + ", COMP="+this);
return p;
}
public Dimension getMinimumSize()
{
if (min != null)
{
//System.out.println("HAVE_MIN_SIZE = " + min);
return min;
}
if (ui != null)
{
Dimension s = ui.getMinimumSize(this);
if (s != null)
{
// System.out.println(" UI-MIN = " + s + ", UI = " + ui + ", IM="+this);
return s;
}
}
Dimension p = super.getMinimumSize();
// System.out.println(" MIN = " + p + ", COMP="+this);
return p;
}
public Dimension getPreferredSize()
{
if (pref != null)
{
//System.out.println("HAVE_PREF_SIZE = " + pref);
return pref;
}
if (ui != null)
{
Dimension s = ui.getPreferredSize(this);
if (s != null)
{
//System.out.println(" UI-PREF = " + s + ", UI = " + ui + ", IM="+this);
return s;
}
}
Dimension p = super.getPreferredSize();
// System.out.println(" PREF = " + p + ", COMP="+this);
return p;
}
public Component getNextFocusableComponent()
{
// Return the next focusable component or null if the focus manager should choose the next focusable component automatically
return null;
}
public KeyStroke[] getRegisteredKeyStrokes()
{
// Return the KeyStrokes that will initiate registered actions.
return null;
}
public JRootPane getRootPane()
{
JRootPane p = SwingUtilities.getRootPane(this);
System.out.println("root = " + p);
return p;
}
public Dimension getSize(Dimension rv)
{
// System.out.println("JComponent, getsize()");
if (rv == null)
return new Dimension(getWidth(),
getHeight());
else
{
rv.setSize(getWidth(),
getHeight());
return rv;
}
}
/*********************************************************************
*
*
* tooltips:
*
*
**************************************/
public JToolTip createToolTip()
{
if (tooltip == null)
tooltip = new JToolTip(tool_tip_text);
return tooltip;
}
public Point getToolTipLocation(MouseEvent event)
{ return null; }
public void setToolTipText(String text)
{ tool_tip_text = text; }
public String getToolTipText()
{ return tool_tip_text; }
public String getToolTipText(MouseEvent event)
{ return tool_tip_text; }
/*********************************************************************
*
*
* things to do with visibility:
*
*
**************************************/
public Container getTopLevelAncestor()
{
// Returns the top-level ancestor of this component (either the containing Window or Applet), or null if this component has not been added to any container.
System.out.println("JComponent, getTopLevelAncestor()");
return null;
}
public Rectangle getVisibleRect()
{
/// Returns the Component's "visible rectangle" - the intersection of this components visible rectangle:
System.out.println("JComponent, getVisibleRect()");
return null;
}
public void grabFocus()
{
// Set the focus on the receiving component.
}
public boolean hasFocus()
{
// Returns true if this Component has the keyboard focus.
return false;
}
public boolean isDoubleBuffered()
{ return use_double_buffer; }
public boolean isFocusCycleRoot()
{
// Override this method and return true if your component is the root of of a component tree with its own focus cycle.
return false;
}
public boolean isFocusTraversable()
{
// Identifies whether or not this component can receive the focus.
return false;
}
public static boolean isLightweightComponent(Component c)
{
return c.getPeer() instanceof LightweightPeer;
}
public boolean isManagingFocus()
{
// Override this method and return true if your JComponent manages focus.
return false;
}
public boolean isOpaque()
{ return opaque; }
public boolean isOptimizedDrawingEnabled()
{
// Returns true if this component tiles its children,
return true;
}
public boolean isPaintingTile()
{
// Returns true if the receiving component is currently painting a tile.
return false;
}
public boolean isRequestFocusEnabled()
{
// Return whether the receiving component can obtain the focus by calling requestFocus
return false;
}
public boolean isValidateRoot()
{
// If this method returns true, revalidate() calls by descendants of this component will cause the entire tree beginning with this root to be validated.
return false;
}
public void paint(Graphics g)
{
// System.out.println("SWING_PAINT:" + this);
paintBorder(g);
paintComponent(g);
paintChildren(g);
}
protected void paintBorder(Graphics g)
{
// System.out.println("PAINT_BORDER x XXXXXXX x x x x x x x x x x x x:" + getBorder() + ", THIS="+this);
// Paint the component's border.
if (getBorder() != null)
{
//System.out.println("PAINT_BORDER x XXXXXXX x x x x x x x x x x x x:" + getBorder() + ", THIS="+this);
getBorder().paintBorder(this,
g,
0,
0,
getWidth(),
getHeight());
}
}
protected void paintChildren(Graphics g)
{
// Paint this component's children.
//super.paintChildren(g);
}
protected void paintComponent(Graphics g)
{
// If the UI delegate is non-null, call its paint method.
if (ui != null)
{
ui.paint(g, this);
}
}
/**
* Paint the specified region in this component and all of
* its descendants that overlap the region, immediately.
*/
public void paintImmediately(int x, int y, int w, int h)
{
//Ronald: this shoudld probably redirect to the PLAF ....
}
public void paintImmediately(Rectangle r)
{
/// Paint the specified region now.
paintImmediately((int)r.getX(),
(int)r.getY(),
(int)r.getWidth(),
(int)r.getHeight());
}
protected String paramString()
{
// Returns a string representation of this JComponent.
return "JComponent";
}
protected void processComponentKeyEvent(KeyEvent e)
{
// Process any key events that the component itself recognizes.
//System.out.println("COMP_KEY-EVENT: " + e);
}
protected void processFocusEvent(FocusEvent e)
{
// Processes focus events occurring on this component by dispatching them to any registered FocusListener objects.
//System.out.println("FOCUS_EVENT: " + e);
}
protected void processKeyEvent(KeyEvent e)
{
// Override processKeyEvent to process events protected
//System.out.println("KEY-EVENT: " + e);
}
public void processMouseMotionEvent(MouseEvent e)
{
// Processes mouse motion events occurring on this component by dispatching them to any registered MouseMotionListener objects.
//System.out.println("COMP_MOUSE-EVENT: " + e + ", MEMORY = " + Runtime.getRuntime().freeMemory());
}
public void registerKeyboardAction(ActionListener anAction,
KeyStroke aKeyStroke,
int aCondition)
{
registerKeyboardAction(anAction,
null,
aKeyStroke,
aCondition);
}
public void registerKeyboardAction(ActionListener anAction,
String aCommand,
KeyStroke aKeyStroke,
int aCondition)
{
// Register a new keyboard action.
}
public void removeNotify()
{
// Notification to this component that it no longer has a parent component.
}
public void repaint(long tm, int x, int y, int width, int height)
{
// Adds the specified region to the dirty region list if the component is showing.
//System.out.println("JC: repaint");
super.repaint(tm, x,y,width,height);
}
public void repaint(Rectangle r)
{
// Adds the specified region to the dirty region list if the component is showing.
repaint((long)0,
(int)r.getX(),
(int)r.getY(),
(int)r.getWidth(),
(int)r.getHeight());
}
public boolean requestDefaultFocus()
{
// Request the focus for the component that should have the focus by default.
return false;
}
public void requestFocus()
{
// Set focus on the receiving component if isRequestFocusEnabled returns true
super.requestFocus();
}
public void resetKeyboardActions()
{
// Unregister all keyboard actions
}
public void reshape(int x, int y, int w, int h)
{
/// Moves and resizes this component.
super.reshape(x,y,w,h);
}
public void revalidate()
{
// Support for deferred automatic layout.
if (getParent() == null)
invalidate();
}
public void scrollRectToVisible(Rectangle aRect)
{
// Forwards the scrollRectToVisible() message to the JComponent's parent.
}
public void setAlignmentX(float alignmentX)
{
// Set the the vertical alignment.
}
public void setAlignmentY(float alignmentY)
{
// Set the the horizontal alignment.
}
public void setAutoscrolls(boolean autoscrolls)
{
// If true this component will automatically scroll its contents when dragged, if contained in a component that supports scrolling, such as JViewport
}
public void setDebugGraphicsOptions(int debugOptions)
{
// Enables or disables diagnostic information about every graphics operation performed within the component or one of its children.
}
public void setDoubleBuffered(boolean aFlag)
{
use_double_buffer = aFlag;
}
public void setEnabled(boolean enabled)
{
// Sets whether or not this component is enabled.
super.setEnabled(enabled);
repaint();
}
public void setFont(Font font)
{
super.setFont(font);
revalidate();
repaint();
}
public void setBackground(Color bg)
{
super.setBackground(bg);
revalidate();
repaint();
}
public void setForeground(Color fg)
{
super.setForeground(fg);
revalidate();
repaint();
}
public void setMaximumSize(Dimension maximumSize)
{ max = maximumSize; }
public void setMinimumSize(Dimension minimumSize)
{ min = minimumSize; }
public void setPreferredSize(Dimension preferredSize)
{ pref = preferredSize; }
public void setNextFocusableComponent(Component aComponent)
{
// Specifies the next component to get the focus after this one, for example, when the tab key is pressed.
}
public void setOpaque(boolean isOpaque)
{
opaque = isOpaque;
revalidate();
repaint();
}
public void setRequestFocusEnabled(boolean aFlag)
{
}
public void setVisible(boolean aFlag)
{
// Makes the component visible or invisible.
super.setVisible(aFlag);
if (getParent() != null)
{
Rectangle dims = getBounds();
getParent().repaint((int)dims.getX(),
(int)dims.getY(),
(int)dims.getWidth(),
(int)dims.getHeight());
}
}
public void unregisterKeyboardAction(KeyStroke aKeyStroke)
{
// Unregister a keyboard action.
}
public void update(Graphics g)
{
paint(g);
}
/******************************************
*
*
* UI management
*
*
*********/
public String getUIClassID()
{
/// Return the UIDefaults key used to look up the name of the swing.
return "JComponent";
}
protected void setUI(ComponentUI newUI)
{
if (ui != null)
{
ui.uninstallUI(this);
}
// Set the look and feel delegate for this component.
ui = newUI;
if (ui != null)
{
ui.installUI(this);
}
revalidate();
repaint();
}
public void updateUI()
{
// Resets the UI property to a value from the current look and feel.
System.out.println("update UI not overwritten in class: " + this);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?