Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

TextItem.java

Go to the documentation of this file.
00001 // -*-Java-*-
00002 
00012 
00013 package pkgView;
00014 
00016 public class TextItem {
00017    private boolean selected, mayEdit;
00018 
00019    private int defaultColor, activeColor, colorFlag;
00020    private int yPos, xPos;
00021    private int fieldWidth = 0;
00022    private StringBuffer txtMsg;
00023    private ScreenKit sk = ScreenKit.getSingleton();
00024    private int charIndex;
00025 
00026    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00034    public TextItem( String msg, int len){
00035       selected = false;
00036       mayEdit = false;
00037       colorFlag = 0;
00038       yPos = xPos = 0;
00039       this.fieldWidth = len;
00040       charIndex = 0;            // akin to cursor position offset
00041       setText(msg);
00042    }
00043 
00044    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00050    public void setText( String msg ){
00051       if( fieldWidth < 1 ) return;
00052       try {
00053          txtMsg = new StringBuffer(msg);
00054          charIndex = txtMsg.length();
00055          while( txtMsg.length() < fieldWidth ){
00056             txtMsg.append(" ");
00057          }
00058       }
00059       catch( Exception e ) {
00060          System.err.println( e.getMessage() );
00061       }
00062 
00063    }
00064 
00065    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00067    public void moveRight(){
00068       if( ++charIndex >= fieldWidth ){
00069          charIndex = 0;
00070       }
00071    }
00072 
00073    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00075    public void moveLeft(){
00076       if( --charIndex <= 0 ){
00077          charIndex = 0;
00078       }
00079    }
00080 
00081    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00083    public void putChar( char ch ){
00084       try {
00085          if( charIndex < txtMsg.length() ){
00086             txtMsg.setCharAt(charIndex++,ch);
00087          }
00088       }
00089       catch( Exception e ) {
00090          System.err.println( e.getMessage() );
00091       }
00092    }
00093       
00094 
00095    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00097    public void eraseLine( ){
00098       for( int i=0; i < txtMsg.length(); i++ ){
00099          txtMsg.setCharAt( i, ' ' );
00100       }
00101       charIndex = 0;
00102    }
00103       
00104 
00105    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00110    public String getText(){
00111       return txtMsg.toString();
00112    }
00113 
00114    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00120    public void setSelected( boolean bFlag){
00121          selected = bFlag;
00122    } // setSelected
00123 
00124 
00125    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00130    public void redraw(){
00131       if( fieldWidth < 1 ) return;
00132       String jstr = txtMsg.toString();
00133       int len = jstr.length();
00134       if( selected ){
00135          sk.ttyMvAddStr(yPos,xPos,jstr,len,colorFlag,activeColor);
00136       }
00137       else{
00138          sk.ttyMvAddStr(yPos,xPos,jstr,len,colorFlag,defaultColor);
00139       }
00140    }
00141 
00142    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00147    public void setAttribute( int value ){
00148       colorFlag = value;
00149    }
00150 
00151    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00155    public boolean isSelected(){
00156       // usually used for menu traversal
00157       return selected;
00158    }
00159 
00160    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00166    public void setColors( int color1, int color2 ){
00167       defaultColor = color1;
00168       activeColor = color2;
00169    }
00170 
00171    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00177    public void setPosition( int y, int x ){
00178       yPos = y;
00179       xPos = x;
00180    }
00181 
00182    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00187    public int getRow(){
00188       return yPos;
00189    }
00190 
00191    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00195    public void enableEdit( boolean bFlag){
00196       mayEdit = bFlag;
00197    }
00198 } // end class TextItem
00199 

SourceForge.net Logo