📄 component.java.svn-base
字号:
while (parent != null) {
translateX += parent.getX();
translateY += parent.getY();
//if (parent.isScrollable()) {
if (parent.isScrollableX()) {
translateX -= parent.getScrollX();
}
if (parent.isScrollableY()) {
translateY -= parent.getScrollY();
}
// since scrollability can translate everything... we should clip based on the
// current scroll
g.clipRect(parent.getAbsoluteX() + parent.getScrollX(), parent.getAbsoluteY() + parent.getScrollY(), parent.getWidth(), parent.getHeight());
//}
// restore the position for fixed components
if (parent.isFixedPosition()) {
translateX = parent.getX();
translateY = parent.getY();
g.clipRect(parent.getX(), parent.getY(), parent.getWidth(), parent.getHeight());
break;
}
parent = parent.getParent();
}
}
g.clipRect(translateX + getX(), translateY + getY(), getWidth(), getHeight());
if (background) {
paintBackgrounds(g);
}
g.translate(translateX, translateY);
paintInternal(g);
g.translate(-translateX, -translateY);
Form parentForm = getComponentForm();
if (parentForm != null) {
Painter glass = parentForm.getGlassPane();
if (glass != null) {
glass.paint(g, parentForm.getBounds());
}
}
g.setClip(clipX, clipY, clipW, clipH);
}
private void drawPainters(com.sun.lwuit.Graphics g, Component par, Component c,
Rectangle bounds) {
if (par == null) {
return;
} else {
if (par.getStyle().getBgTransparency() != ((byte) 0xFF)) {
drawPainters(g, par.getParent(), par, bounds);
}
}
int transX = par.getAbsoluteX() + par.getScrollX();
int transY = par.getAbsoluteY() + par.getScrollY();
g.translate(transX, transY);
((Container) par).paintIntersecting(g, c, bounds, false);
if (par.isBorderPainted()) {
Border b = par.getBorder();
if (b != null && b.isBackgroundPainter()) {
g.translate(-par.getX(), -par.getY());
b.paintBorderBackground(g, par);
b.paint(g, par);
g.translate(par.getX() - transX, par.getY() - transY);
}
} else {
Painter p = par.getStyle().getBgPainter();
if (p != null) {
p.paint(g, new Rectangle(0, 0, par.getWidth(), par.getHeight()));
}
g.translate(-transX, -transY);
}
}
/**
* Normally returns getStyle().getBorder() but some subclasses might use this
* to programmatically replace the border in runtime e.g. for a pressed border effect
*
* @return the borde that is drawn according to the current component state
*/
protected Border getBorder() {
Border b = getStyle().getBorder();
if (hasFocus()) {
if (b != null) {
return b.getFocusedInstance();
}
return b;
} else {
return b;
}
}
/**
* Paints the background of the component, invoked with the clipping region
* and appropriate scroll translation.
*
* @param g the component graphics
*/
protected void paintBackground(Graphics g) {
if (isBorderPainted()) {
Border b = getBorder();
if (b != null && b.isBackgroundPainter()) {
b.paintBorderBackground(g, this);
return;
}
}
if (getStyle().getBgPainter() != null) {
getStyle().getBgPainter().paint(g, new Rectangle(getX(), getY(), getWidth(), getHeight()));
}
}
/**
* This method paints the Component on the screen, it should be overriden
* by subclasses to perform custom drawing or invoke the UI API's to let
* the PLAF perform the rendering.
*
* @param g the component graphics
*/
public void paint(Graphics g) {
}
/**
* Indicates whether the component should/could scroll by default a component
* is not scrollable.
*
* @return whether the component is scrollable
*/
protected boolean isScrollable() {
return isScrollableX() || isScrollableY();
}
/**
* Indicates whether the component should/could scroll on the X axis
*
* @return whether the component is scrollable on the X axis
*/
public boolean isScrollableX() {
return false;
}
/**
* Indicates whether the component should/could scroll on the Y axis
*
* @return whether the component is scrollable on the X axis
*/
public boolean isScrollableY() {
return false;
}
/**
* Indicates the X position of the scrolling, this number is relative to the
* component position and so a position of 0 would indicate the x position
* of the component.
*
* @return the X position of the scrolling
*/
public int getScrollX() {
return scrollX;
}
/**
* Indicates the Y position of the scrolling, this number is relative to the
* component position and so a position of 0 would indicate the x position
* of the component.
*
* @return the Y position of the scrolling
*/
public int getScrollY() {
return scrollY;
}
/**
* Indicates the X position of the scrolling, this number is relative to the
* component position and so a position of 0 would indicate the x position
* of the component.
*
* @param scrollX the X position of the scrolling
*/
protected void setScrollX(int scrollX) {
if (isScrollableX()) {
this.scrollX = scrollX;
repaint();
}
}
/**
* Indicates the X position of the scrolling, this number is relative to the
* component position and so a position of 0 would indicate the x position
* of the component.
*
* @param scrollY the Y position of the scrolling
*/
protected void setScrollY(int scrollY) {
if (isScrollableY()) {
this.scrollY = scrollY;
repaint();
}
}
/**
* Returns the gap to be left for the bottom scrollbar on the X axis. This
* method is used by layout managers to determine the room they should
* leave for the scrollbar
*
* @return the gap to be left for the bottom scrollbar on the X axis
*/
public int getBottomGap() {
if (isScrollableX()) {
return UIManager.getInstance().getLookAndFeel().getHorizontalScrollHeight();
}
return 0;
}
/**
* Returns the gap to be left for the side scrollbar on the Y axis. This
* method is used by layout managers to determine the room they should
* leave for the scrollbar. (note: side scrollbar rather than left scrollbar
* is used for a future version that would support bidi).
*
* @return the gap to be left for the side scrollbar on the Y axis
*/
public int getSideGap() {
if (isScrollableY()) {
return UIManager.getInstance().getLookAndFeel().getVerticalScrollWidth();
}
return 0;
}
/**
* Retuns true if the given absolute cordinate is contained in the Component
*
* @param x the given absolute x cordinate
* @param y the given absolute y cordinate
* @return true if the given absolute cordinate is contained in the
* Component; otherwise false
*/
public boolean contains(int x, int y) {
int absX = getAbsoluteX() + getScrollX();
int absY = getAbsoluteY() + getScrollY();
return (x >= absX && x < absX + getWidth() && y >= absY && y < absY + getHeight());
}
/**
* Calculates the preferred size based on component content. This method is
* invoked lazily by getPreferred size.
*
* @return the calculated preferred size based on component content
*/
protected Dimension calcPreferredSize() {
Dimension d = new Dimension(0, 0);
return d;
}
private boolean sizeRequestedByUser = false;
private Dimension preferredSize() {
if (!sizeRequestedByUser && (shouldCalcPreferredSize || preferredSize == null)) {
shouldCalcPreferredSize = false;
preferredSize = calcPreferredSize();
}
return preferredSize;
}
/**
* Returns the component bounds which is sometimes more convenient than invoking
* getX/Y/Width/Height. Bounds are relative to parent container.<br>
* Changing values within the bounds can lead to unpredicted behavior.
*
* @see #getX
* @see #getY
* @return the component bounds
*/
protected Rectangle getBounds() {
return bounds;
}
/**
* Returns true if this component can receive focus and is enabled
*
* @return true if this component can receive focus; otherwise false
*/
public boolean isFocusable() {
return focusable && enabled && isVisible();
}
/**
* A simple setter to determine if this Component can get focused
*
* @param focusable indicate whether this component can get focused
*/
public void setFocusable(boolean focusable) {
this.focusable = focusable;
Form p = getComponentForm();
if (p != null) {
p.clearFocusVectors();
}
}
/**
* Indicates the values within the component have changed and preferred
* size should be recalculated
*
* @param shouldCalcPreferredSize indicate whether this component need to
* recalculate his preferred size
*/
protected void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize) {
if (shouldCalcPreferredSize != this.shouldCalcPreferredSize) {
this.shouldCalcPreferredSize = shouldCalcPreferredSize;
if (shouldCalcPreferredSize && getParent() != null) {
this.shouldCalcPreferredSize = shouldCalcPreferredSize;
getParent().setShouldCalcPreferredSize(shouldCalcPreferredSize);
}
}
}
/**
* Indicates whether focus should be drawn around the component or whether
* it will handle its own focus painting
*
* @return true if focus should be drawn around the component
* ; otherwise false
*/
public boolean isFocusPainted() {
return focusPainted;
}
/**
* Indicates whether focus should be drawn around the component or whether
* it will handle its own focus painting
*
* @param focusPainted indicates whether focus should be drawn around the
* component
*/
public void setFocusPainted(boolean focusPainted) {
this.focusPainted = focusPainted;
}
/**
* Prevents key events from being grabbed for focus traversal. E.g. a list component
* might use the arrow keys for internal navigation so it will switch this flag to
* true in order to prevent the focus manager from moving to the next component.
*
* @return true if key events are being used for focus traversal
* ; otherwise false
*/
public boolean handlesInput() {
return handlesInput;
}
/**
* Prevents key events from being grabbed for focus traversal. E.g. a list component
* might use the arrow keys for internal navigation so it will switch this flag to
* true in order to prevent the focus manager from moving to the next component.
*
* @param handlesInput indicates whether key events can be grabbed for
* focus traversal
*/
public void setHandlesInput(boolean handlesInput) {
this.handlesInput = handlesInput;
}
/**
* Returns true if the componet has focus
*
* @return true if the componet has focus; otherwise false
* @see #setFocus
*/
public boolean hasFocus() {
return focused;
}
/**
* This flag doesn't really give focus, its a state that determines
* what colors from the Style should be used when painting the component.
* Actual focus is determined by the parent form
*
* @param focused sets the state that determines what colors from the
* Style should be used when painting a focused component
*
* @see #requestFocus
*/
public void setFocus(boolean focused) {
this.focused = focused;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -