📄 component.java
字号:
parent.repaint(x+cx, y+cy, cwidth, cheight); } else { // top level component FireScreen.getScreen().repaintScreen(x+cx,y+cy,cwidth,cheight); } } /** * Returns a int[2] array with the width,height which are preffered by this component. * If set it is used by the LayoutManager to correctly layout this Component inside its Container * @return */ public int[] getPrefSize() { if(prefWidth==-1 || prefHeight==-1) return null; return new int[]{prefWidth,prefHeight}; } /** * @see #getPrefSize() * @param width * @param height */ public void setPrefSize(int width,int height) { if (width < 0 || height < 0) throw new IllegalArgumentException("Dimensions can not be negative: "+width+"/"+height); prefWidth = width; prefHeight = height; valid=false; } protected void pointerDragged(int x, int y) { if(pointerListener!=null) pointerListener.pointerDragged(x, y,this); } protected void pointerPressed(int x, int y) { if(pointerListener!=null) pointerListener.pointerPressed(x, y,this); } protected void pointerReleased(int x, int y) { if(pointerListener!=null) pointerListener.pointerReleased(x, y,this); } protected void keyPressed(int keyCode) { if(keyListener!=null) keyListener.keyPressed(keyCode,this); } protected void keyReleased(int keyCode) { if(keyListener!=null) keyListener.keyReleased(keyCode,this); } protected void keyRepeated(int keyCode) { if(keyListener!=null) keyListener.keyRepeated(keyCode,this); } public Command getLeftSoftKeyCommand() { return leftSoftKeyCommand; } public void setLeftSoftKeyCommand(Command leftSoftKeyCommand) { this.leftSoftKeyCommand = leftSoftKeyCommand; FireScreen.getScreen().componentSoftKeyUpdate(this); } public Command getRightSoftKeyCommand() { return rightSoftKeyCommand; } public void setRightSoftKeyCommand(Command rightSoftKeyCommand) { this.rightSoftKeyCommand = rightSoftKeyCommand; FireScreen.getScreen().componentSoftKeyUpdate(this); } /** * If this component is inside another (i.e. a container) then its parent is that container * If this component is directly added to the FireScreen (i.e. using the FireScreen.addComponent() method) the parent is null * @see FireScreen#addComponent(Component, int) * @return */ public Component getParent() { return parent; } public int getForegroundColor() { return foregroundColor; } public void setForegroundColor(int foregroundColor) { this.foregroundColor = foregroundColor; } public int getBackgroundColor() { return backgroundColor; } public void setBackgroundColor(int backgroundColor) { this.backgroundColor = backgroundColor; } /** * The minSize is used to calculate the layout of the components inside their container by the LayoutManager. * The minSize is only used when the prefSize is not set. * If the prefSize is set it will be used even if the minSize is bigger than prefSize. * * @return the minSize dimensions of this Component. */ public int[] getMinSize() { return new int[]{0,0}; } public Font getFont() { return font; } public void setFont(Font font) { this.font = font; } /** * Returns the layout set to this component. Using the layout the component can * decide how to present its content to the screen. * Possible layouts are combinations of the following * FireScreen.CENTER,FireScreen.LEFT, FireScreen.RIGHT, FireScreen.TOP, FireScreen.BOTTOM , FireScreen.VCENTER * @see FireScreen#CENTER * @return */ public int getLayout() { return layout; } /** * @see #getLayout() * @param layout */ public void setLayout(int layout) { this.layout = layout; } /** * Returns the width of the usefull content of this component (i.e. for a TextComponent the width of the text without borders,etc) * It is used by the LayoutManager and the Browser to determine the best way to display this component * * * @return */ public int getContentWidth(){ return 0; } /** * Returns the height of the usefull content of this component (i.e. for a TextComponent the height of the text without borders,etc) * It is used by the LayoutManager and the Browser to determine the best way to display this component * * @return */ public int getContentHeight() { return 0; } /** * Sets this component to be able to receive key and pointer events * @param focusable */ public void setFocusable(boolean focusable) { this.focusable = focusable; } /** * @see #getId() * @param id */ public void setId(String id) { this.id = id; } /** * Every Fire Component can have an Id string assosiated with it. * * @return */ public String getId() { return id; } public String toString() { return super.toString() + ((id!=null)?" ["+id+"]":""); } /** * Utility method to easily retrieve * the vertical layout information of this component * * @see #setLayout(int) * @return */ public int getValign() { int valign = FireScreen.TOP; if ((layout&FireScreen.VCENTER)==FireScreen.VCENTER) { valign = FireScreen.VCENTER; } else if ((layout&FireScreen.TOP) == FireScreen.TOP) { valign = FireScreen.TOP; } else if ((layout&FireScreen.BOTTOM) == FireScreen.BOTTOM) { valign = FireScreen.BOTTOM; } return valign; } /** * Utility method to easily retrieve * the horizontal layout information of this component * * @see #setLayout(int) * @return */ public int getHalign() { int halign = FireScreen.LEFT; if ((layout&FireScreen.CENTER)==FireScreen.CENTER) // hcenter { halign = FireScreen.CENTER; } else if ((layout&FireScreen.LEFT)==FireScreen.LEFT) { halign = FireScreen.LEFT; } else if ((layout&FireScreen.RIGHT)==FireScreen.RIGHT) { halign = FireScreen.RIGHT; } return halign; } /** * A component can have a border. This method returns true if the border flag is set.<br/> * Note: It is up to the component implementation to support and display borders. * @return */ public boolean isBorder() { return border; } /** * @see #isBorder() * @param border */ public void setBorder(boolean border) { this.border = border; } /** * If a component is visivle (default) then it will be drawn by the firescreen or its parent component * @return */ public boolean isVisible() { return visible; } /** * @see #isVisible() * @param visible */ public void setVisible(boolean visible) { this.visible = visible; } /** * Utility method to easili translate the component inside its parent by (dx,dy) * @see #setPosition(int, int) * @param dx * @param dy */ public void move(int dx, int dy) { repaint(); this.x+=dx; this.y+=dy; } /** * Sets the position of this component relative to its parent top left corner. * If the component does not have a parent (its a top level component of the FireScreen) the * position is relative to the top,left of the FireScreen * * @param x * @param y */ public void setPosition(int x,int y) { repaint(); this.x=x; this.y=y; } /** * This method returns the animation (if any) associated with this component. * A component can have at most one animation. When a component has an animation * it is considered its parent (this==animation.parent && this.animation==animation) * @return */ public Animation getAnimation() { return animation; } /** * @see #setAnimation(Animation) * @param animation */ public void setAnimation(Animation animation) { if(animation.parent!=null) { animation.parent.animation=null; } animation.parent=this; this.animation = animation; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -