📄 component.java.svn-base
字号:
*/
public void setPreferredH(int preferredH) {
setPreferredSize(new Dimension(getPreferredW(), preferredH));
}
/**
* Helper method to retrieve the preferred width of the component.
*
* @return preferred width of the component
* @see #getPreferredSize
*/
public int getPreferredW() {
return getPreferredSize().getWidth();
}
/**
* Helper method to retrieve the preferred height of the component.
*
* @return preferred height of the component
* @see #getPreferredSize
*/
public int getPreferredH() {
return getPreferredSize().getHeight();
}
/**
* Sets the Component width, this method is exposed for the purpose of
* external layout managers and should not be invoked directly.<br>
* If a user wishes to effect the component size setPreferredSize should
* be used.
*
* @param width the width of the component
* @see #setPreferredSize
*/
public void setWidth(int width) {
bounds.getSize().setWidth(width);
}
/**
* Sets the Component height, this method is exposed for the purpose of
* external layout managers and should not be invoked directly.<br>
* If a user wishes to effect the component size setPreferredSize should
* be used.
*
* @param height the height of the component
* @see #setPreferredSize
*/
public void setHeight(int height) {
bounds.getSize().setHeight(height);
}
/**
* Sets the Component size, this method is exposed for the purpose of
* external layout managers and should not be invoked directly.<br>
* If a user wishes to effect the component size setPreferredSize should
* be used.
*
* @param d the component dimension
* @see #setPreferredSize
*/
public void setSize(Dimension d) {
Dimension d2 = bounds.getSize();
d2.setWidth(d.getWidth());
d2.setHeight(d.getHeight());
}
/**
* Unique identifier for a component, must be overriden for a component so
* a style can be applied to the component
*
* @return unique string identifying this component for the style sheet
*/
protected String getUIID() {
return null;
}
/**
* Returns the container in which this component is contained
*
* @return the parent container in which this component is contained
*/
public Container getParent() {
return parent;
}
/**
* Sets the Component Parent.
* This method should not be called by the user.
*
* @param parent the parent container
*/
void setParent(Container parent) {
this.parent = parent;
}
/**
* Registers interest in receiving callbacks for focus gained events, a focus event
* is invoked when the component accepts the focus. A special case exists for the
* Form which sends a focus even for every selection within the form.
*
* @param l listener interface implementing the observable pattern
*/
public void addFocusListener(FocusListener l) {
focusListeners.addListener(l);
}
/**
* Deregisters interest in receiving callbacks for focus gained events
*
* @param l listener interface implementing the observable pattern
*/
public void removeFocusListener(FocusListener l) {
focusListeners.removeListener(l);
}
/**
* When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method
* in order to allow 3 button devices to work properly. When overriding this method
* you should also override isSelectableInteraction to indicate that a command is placed
* appropriately on top of the fire key for 3 soft button phones.
*/
protected void fireClicked() {
}
/**
* This method allows a component to indicate that it is interested in an "implicit" select
* command to appear in the "fire" button when 3 softbuttons are defined in a device.
*/
protected boolean isSelectableInteraction() {
return false;
}
/**
* Fired when component gains focus
*/
void fireFocusGained() {
fireFocusGained(this);
}
/**
* Fired when component lost focus
*/
void fireFocusLost() {
fireFocusLost(this);
}
/**
* Fired when component gains focus
*/
void fireFocusGained(Component cmp) {
if (cmp.isCellRenderer()) {
return;
}
focusListeners.fireFocus(cmp);
focusGainedInternal();
if (isSelectableInteraction()) {
Form f = getComponentForm();
if (f != null) {
f.addSelectCommand();
}
}
}
/**
* Fired when component lost focus
*/
void fireFocusLost(Component cmp) {
if (cmp.isCellRenderer()) {
return;
}
if (isSelectableInteraction()) {
Form f = getComponentForm();
if (f != null) {
f.removeSelectCommand();
}
}
focusListeners.fireFocus(cmp);
focusLostInternal();
}
/**
* This method allows us to detect an action event internally without
* implementing the action listener interface.
*/
void fireActionEvent() {
}
/**
* This method is useful since it is not a part of the public API yet
* allows a component within this package to observe focus events
* without implementing a public interface or creating a new class
*/
void focusGainedInternal() {
}
/**
* This method is useful since it is not a part of the public API yet
* allows a component within this package to observe focus events
* without implementing a public interface or creating a new class
*/
void focusLostInternal() {
}
/**
* This method paints all the parents Components Background.
*
* @param g the graphics object
*/
public void paintBackgrounds(Graphics g) {
Rectangle bounds = new Rectangle(getAbsoluteX(), getAbsoluteY(),
getWidth(), getHeight());
drawPainters(g, this.getParent(), this, bounds);
}
/**
* Returns the absolute X location based on the component hierarchy, this method
* calculates a location on the screen for the component rather than a relative
* location as returned by getX()
*
* @return the absolute x location of the component
* @see #getX
*/
public int getAbsoluteX() {
int x = getX() - getScrollX();
Container parent = getParent();
if (parent != null) {
x += parent.getAbsoluteX();
}
return x;
}
/**
* Returns the absolute Y location based on the component hierarchy, this method
* calculates a location on the screen for the component rather than a relative
* location as returned by getX()
*
* @return the absolute y location of the component
* @see #getY
*/
public int getAbsoluteY() {
int y = getY() - getScrollY();
Container parent = getParent();
if (parent != null) {
y += parent.getAbsoluteY();
}
return y;
}
/**
* This method performs the paint of the component internally including drawing
* the scrollbars and scrolling the component. This functionality is hidden
* from developers to prevent errors
*
* @param g the component graphics
*/
final void paintInternal(Graphics g) {
paintInternal(g, true);
}
final void paintInternal(Graphics g, boolean paintIntersects) {
if (!isVisible()) {
return;
}
int oX = g.getClipX();
int oY = g.getClipY();
int oWidth = g.getClipWidth();
int oHeight = g.getClipHeight();
if (bounds.intersects(oX, oY, oWidth, oHeight)) {
g.clipRect(getX(), getY(), getWidth(), getHeight());
paintBackground(g);
if (isScrollable()) {
int scrollX = getScrollX();
int scrollY = getScrollY();
g.translate(-scrollX, -scrollY);
paint(g);
g.translate(scrollX, scrollY);
if (isScrollVisible) {
paintScrollbars(g);
}
} else {
paint(g);
}
if (isBorderPainted()) {
paintBorder(g);
}
//paint all the intersecting Components above the Component
if (paintIntersects && parent != null) {
paintIntersectingComponentsAbove(g);
}
g.setClip(oX, oY, oWidth, oHeight);
}
}
private void paintIntersectingComponentsAbove(Graphics g) {
Container parent = getParent();
Component component = this;
Rectangle bounds = new Rectangle(getAbsoluteX(), getAbsoluteY(),
getWidth(), getHeight());
int tx = g.getTranslateX();
int ty = g.getTranslateY();
g.translate(-tx, -ty);
while (parent != null) {
g.translate(parent.getAbsoluteX() + parent.getScrollX(),
parent.getAbsoluteY() + parent.getScrollY());
parent.paintIntersecting(g, component, bounds, true);
g.translate(-parent.getAbsoluteX() - parent.getScrollX(),
-parent.getAbsoluteY() - parent.getScrollY());
component = parent;
parent = parent.getParent();
}
g.translate(tx, ty);
}
/**
* Paints the UI for the scrollbars on the component, this will be invoked only
* for scrollable components. This method invokes the appropriate X/Y versions
* to do all the work.
*
* @param g the component graphics
*/
protected void paintScrollbars(Graphics g) {
if (isScrollableX()) {
paintScrollbarX(g);
}
if (isScrollableY()) {
paintScrollbarY(g);
}
}
/**
* Paints the UI for the scrollbar on the X axis, this method allows component
* subclasses to customize the look of a scrollbar
*
* @param g the component graphics
*/
protected void paintScrollbarX(Graphics g) {
float offset = ((float) getScrollX()) / ((float) getPreferredW());
float block = ((float) getWidth()) / ((float) getPreferredW());
UIManager.getInstance().getLookAndFeel().drawHorizontalScroll(g, this, offset, block);
}
/**
* Paints the UI for the scrollbar on the Y axis, this method allows component
* subclasses to customize the look of a scrollbar
*
* @param g the component graphics
*/
protected void paintScrollbarY(Graphics g) {
float offset = ((float) getScrollY()) / ((float) getPreferredH());
float block = ((float) getHeight()) / ((float) getPreferredH());
UIManager.getInstance().getLookAndFeel().drawVerticalScroll(g, this, offset, block);
}
/**
* Paints this component as a root by going to all the parent components and
* setting the absolute translation based on coordinates and scroll status.
* Restores translation when the painting is finished.
*
* @param g the graphics to paint this Component on
*/
final public void paintComponent(Graphics g) {
paintComponent(g, true);
}
/**
* Paints this component as a root by going to all the parent components and
* setting the absolute translation based on coordinates and scroll status.
* Restores translation when the painting is finished.
*
* @param g the graphics to paint this Component on
* @param background if true paints all parents background
*/
final public void paintComponent(Graphics g, boolean background) {
int clipX = g.getClipX();
int clipY = g.getClipX();
int clipW = g.getClipWidth();
int clipH = g.getClipHeight();
Container parent = getParent();
int translateX = 0;
int translateY = 0;
if (!isFixedPosition()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -