📄 component.java.svn-base
字号:
scrollY = m.getValue();
if (destScrollY == scrollY) {
destScrollY = -1;
}
return true;
}
//preform the dragging motion if exists
if (draggedMotion != null && !draggedMotion.isFinished()) {
// change the variable directly for efficiency both in removing redundant
// repaints and scroll checks
int dragVal = draggedMotion.getValue();
if (isScrollableY()) {
if (dragVal >= 0 && dragVal <= (getPreferredH() - getHeight())) {
scrollY = dragVal;
return true;
}
} else {
if (dragVal >= 0 && dragVal <= (getPreferredW() - getWidth())) {
scrollX = dragVal;
return true;
}
}
}
if (animateBackground && bgImage instanceof StaticAnimation) {
Rectangle dirty = ((StaticAnimation) bgImage).getDirtyRegion();
if (dirty != null) {
dirty.setX(getAbsoluteX());
dirty.setY(getAbsoluteY() + dirty.getY());
}
setDirtyRegion(dirty);
}
return animateBackground;
}
/**
* Indicates that this component is fixed into place and not affected by
* scrolling of the parent container. This is applicable for components such as
* menus etc...
*
* @return true is this component is fixed into place and not affected by
* scrolling of the parent container; othewise false
*/
boolean isFixedPosition() {
return fixedPosition;
}
/**
* Indicates that this component is fixed into place and not affected by
* scrolling of the parent container. This is applicable for components such as
* menus etc...
*
* @param fixedPosition whether this component is fixed into place and not
* affected by scrolling of the parent container
*/
void setFixedPosition(boolean fixedPosition) {
this.fixedPosition = fixedPosition;
}
/**
* Makes sure the component is visible in the scroll if this container
* is scrollable
*
* @param rect the rectangle that need to be visible
* @param coordinateSpace the component according to whose coordinates
* rect is defined. Rect's x/y are relative to that component
* (they are not absolute).
*/
protected void scrollRectToVisible(Rectangle rect, Component coordinateSpace) {
if (isScrollable()) {
int scrollPosition = getScrollY();
int w = getWidth() - getStyle().getPadding(LEFT) - getStyle().getPadding(RIGHT);
int h = getHeight() - getStyle().getPadding(TOP) - getStyle().getPadding(BOTTOM);
Rectangle view = new Rectangle(getScrollX(), getScrollY(), w, h);
int relativeX = rect.getX();
int relativeY = rect.getY();
// component needs to be in absolute coordinates...
Container parent = null;
if (coordinateSpace != null) {
parent = coordinateSpace.getParent();
}
if (parent == this) {
if (view.contains(rect)) {
return;
}
} else {
while (parent != this) {
// mostly a special case for list
if (parent == null) {
relativeX = rect.getX();
relativeY = rect.getY();
break;
}
relativeX += parent.getX();
relativeY += parent.getY();
parent = parent.getParent();
}
if (view.contains(relativeX, relativeY, rect.getSize().getWidth(), rect.getSize().getHeight())) {
return;
}
}
if (getScrollX() > relativeX) {
setScrollX(relativeX);
}
if (getScrollY() > relativeY) {
scrollPosition = relativeY;
}
int rightX = relativeX + rect.getSize().getWidth();
int bottomY = relativeY + rect.getSize().getHeight();
if (getScrollX() + w < rightX) {
setScrollX(getScrollX() + (rightX - (getScrollX() + w)));
} else {
if (getScrollX() > relativeX) {
setScrollX(relativeX);
}
}
if (getScrollY() + h < bottomY) {
scrollPosition = getScrollY() + (bottomY - (getScrollY() + h));
} else {
if (getScrollY() > relativeY) {
scrollPosition = relativeY;
}
}
if (isSmoothScrolling()) {
initialScrollY = getScrollY();
destScrollY = scrollPosition;
initScrollMotion();
} else {
setScrollY(scrollPosition);
}
repaint();
}
}
/**
* Indicates whether a border should be painted
*
* @param b true would cause the paintBorder method to be invoked false
* allows us to hide the border of the component without deriving the class
* @deprecated use getStyle().setBorder() to null to disable borders or install
* a different border
*/
public void setBorderPainted(boolean b) {
if (!b) {
getStyle().setBorder(null);
} else {
getStyle().setBorder(Border.getDefaultBorder());
}
}
/**
* Indicates whether a border should be painted
*
* @return if the border will be painted
* @deprecated use getStyle().getBorder() != null
*/
public boolean isBorderPainted() {
return getStyle().getBorder() != null;
}
/**
* Draws the component border if such a border exists. The border unlike the content
* of the component will not be affected by scrolling for a scrollable component.
*
* @param g graphics context on which the border is painted
*/
protected void paintBorder(Graphics g) {
Border b = getBorder();
if (b != null) {
if (isFocusPainted() && hasFocus()) {
g.setColor(getStyle().getFgSelectionColor());
} else {
g.setColor(getStyle().getFgColor());
}
b.paint(g, this);
}
}
/**
* Used as an optimization to mark that this component is currently being
* used as a cell renderer
*
* @param cellRenderer indicate whether this component is currently being
* used as a cell renderer
*/
public void setCellRenderer(boolean cellRenderer) {
this.cellRenderer = cellRenderer;
}
/**
* Used as an optimization to mark that this component is currently being
* used as a cell renderer
*
* @return rtue is this component is currently being used as a cell renderer
*/
boolean isCellRenderer() {
return cellRenderer;
}
/**
* Indicate whether this component scroll is visible
*
* @return true is this component scroll is visible; otherwise false
*/
public boolean isScrollVisible() {
return isScrollVisible;
}
/**
* Set whether this component scroll is visible
*
* @param isScrollVisible Indicate whether this component scroll is visible
*/
public void setIsScrollVisible(boolean isScrollVisible) {
this.isScrollVisible = isScrollVisible;
}
/**
* Invoked internally to initialize and bind the component
*/
void initComponentImpl() {
if (!initialized) {
initialized = true;
UIManager.getInstance().getLookAndFeel().bind(this);
checkAnimation();
initComponent();
}
}
/**
* Cleansup the initialization flags in the hierachy, notice that paint calls might
* still occur after deinitilization mostly to perform transitions etc.
* <p>However interactivity, animation and event tracking code can and probably
* should be removed by this method.
*/
void deinitializeImpl() {
if (isInitialized()) {
Form f = getComponentForm();
if (f != null) {
f.deregisterAnimated(this);
}
setInitialized(false);
setDirtyRegion(null);
deinitialize();
}
}
/**
* Invoked to indicate that the component initialization is being reversed
* since the component was detached from the container hierarchy. This allows
* the component to deregister animators and cleanup after itself. This
* method is the opposite of the initComponent() method.
*/
protected void deinitialize() {
}
/**
* Allows subclasses to bind functionality that relies on fully initialized and
* "ready for action" component state
*/
protected void initComponent() {
}
/**
* Indicates if the component is in the initalized state, a component is initialized
* when its initComponent() method was invoked. The initMethod is invoked before showing the
* component to the user.
*
* @return true if the component is in the initalized state
*/
protected boolean isInitialized() {
return initialized;
}
/**
* Indicates if the component is in the initalized state, a component is initialized
* when its initComponent() method was invoked. The initMethod is invoked before showing the
* component to the user.
*
* @param initialized Indicates if the component is in the initalized state
*/
protected void setInitialized(boolean initialized) {
this.initialized = initialized;
}
/**
* @inheritDoc
*/
public void styleChanged(String propertyName, Style source) {
//changing the Font, Padding, Margin may casue the size of the Component to Change
//therefore we turn on the shouldCalcPreferredSize flag
if (!shouldCalcPreferredSize &&
propertyName.equals(Style.FONT) ||
propertyName.equals(Style.MARGIN) ||
propertyName.equals(Style.PADDING)) {
setShouldCalcPreferredSize(true);
Container parent = getParent();
if (parent != null) {
parent.revalidate();
}
}
}
/**
* Allows us to determine which component will receive focus next when travering
* with the down key
*/
public Component getNextFocusDown() {
return nextFocusDown;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the down key
*/
public void setNextFocusDown(Component nextFocusDown) {
this.nextFocusDown = nextFocusDown;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the up key.
*/
public Component getNextFocusUp() {
return nextFocusUp;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the up key, this method doesn't affect the generl focus beavior.
*/
public void setNextFocusUp(Component nextFocusUp) {
this.nextFocusUp = nextFocusUp;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the left key.
*/
public Component getNextFocusLeft() {
return nextFocusLeft;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the left key, this method doesn't affect the generl focus beavior.
*/
public void setNextFocusLeft(Component nextFocusLeft) {
this.nextFocusLeft = nextFocusLeft;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the right key
*/
public Component getNextFocusRight() {
return nextFocusRight;
}
/**
* Allows us to determine which component will receive focus next when travering
* with the right key
*/
public void setNextFocusRight(Component nextFocusRight) {
this.nextFocusRight = nextFocusRight;
}
/**
* Indicates whether component is enabled or disabled thus allowing us to prevent
* a component from receiving input events and indicate so visually
*/
public boolean isEnabled() {
return enabled;
}
/**
* Used to reduce coupling between the TextArea component and display/implementation
* classes thus reduce the size of the hello world MIDlet
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -