文本编辑器源文件(java语言)

来源:互联网 发布:js如何实现文件上传 编辑:程序博客网 时间:2024/05/13 04:16
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
/版权所有helj
import java.awt.*;
import java.io.*;
import java.util.*;
//W_color;C_str;C_file;C_back;W_find;W_fond

interface I_Method
{
    public void setQuit();
    public void setfont(Font f);
    public void setcolor(Color c);
    public void Find(String find,int dire);
}



class D_color extends Dialog
{
    private Button OK,Cancel;
    private I_Method mp;
    private Rectangle test;

    private Color current= Color.black;
    private Color []colors;
    private Color []colors1;
    private Color []colors2;
    private int strlen= 250;

    public D_color(Frame fr,I_Method mp,int x,int y)
    {
        super(fr,"调色板",true);
        this.mp= mp;
        colors= new Color[strlen];
        colors1= new Color[strlen];
        colors2= new Color[strlen];
        for (int i = 0; i < strlen; i++)
        {
            float h = ((float)i)/((float)strlen);
colors[i] = new Color(Color.HSBtoRGB(h,1.0f,1.0f));
        }
        for (int i = 0; i < strlen; i++)
        {
            float h = ((float)i)/((float)strlen);
colors1[i] = new Color(Color.HSBtoRGB(1.0f,h,1.0f));
        }
        for (int i = 0; i < strlen; i++)
        {
            float h = ((float)i)/((float)strlen);
colors2[i] = new Color(Color.HSBtoRGB(1.0f,1.0f,h));
        }
       
        setLayout(null);
        OK= new Button("确定");
        Cancel= new Button("取消");
        OK.reshape(320,100,80,30);
        add(OK);
        Cancel.reshape(320,150,80,30);
        add(Cancel);        
        test= new Rectangle(0,0,300,250);
        reshape(x/2-210,y/2-140,420,280);
        show();
    }

    public void update(Graphics g)
    {
        int y= 0;
        for (int i = 0; i < strlen; i++)
        {
            g.setColor(colors[i]);
            g.fillRect(0,y,100,1);
            y+=1;
        }
        y= 0;
        for (int i = 0; i < strlen; i++)
        {
            g.setColor(colors1[i]);
            g.fillRect(100,y,100,1);
            y+=1;
        }
        y= 0;
        for (int i = 0; i < strlen; i++)
        {
            g.setColor(colors2[i]);
            g.fillRect(200,y,100,1);
            y+=1;
        }
        g.setColor(current);
        g.fillRect(330,30,60,60);
    }
   
    public void paint(Graphics g)
    {
        update(g);
    }

    public boolean mouseMove(Event evt,int x,int y)
    {
        if(test.inside(x,y))
        {
            Graphics g1= getGraphics();
            //g1.drawImage(back,oldx,oldy);
            //g1.clipRect(x-3,y-3,6,6);
            g1.setColor(Color.white);
            g1.drawArc(x-3,y-3,6,6,60,360);
            g1.drawLine(x-3,y,x+3,y);
            g1.drawLine(x,y-3,x,y+3);
            repaint();
            //oldx= x-3;
            //oldy= y-3;
            return true;
        }
        return false;
    }


    public boolean mouseDown(Event evt,int x,int y)
    {
        if((x>=0)&&(x<=100))
        {
            current= colors[y];
            System.out.println(y);
            getGraphics().setColor(current);
        getGraphics().fillRect(330,30,60,60);
            return true;
        }
        if((x>100)&&(x<=200))
        {
            current= colors1[y];
            getGraphics().setColor(current);
            getGraphics().fillRect(330,30,60,60);
            return true;
        }
        if((x>200)&&(x<=300))
        {
            current= colors2[y];
            getGraphics().setColor(current);
            getGraphics().fillRect(330,30,60,60);
            return true;
        }
        return false;
    }

    public boolean action(Event evt,Object arg)
    {
        if(evt.target instanceof Button)
        {
            if(evt.target== OK)
            {
                mp.setcolor(current);
                dispose();
                return true;
            }
            if(evt.target== Cancel)
            {
                dispose();
                return true;
            }
        }
        return super.action(evt,arg);
    }
}

class W_quick extends Window
{
    MainF fr;
    private Dimension sz;
    private int w,h;
    private int fw,fh;
    private FontMetrics fm;
    private int index=0;

    public W_quick(MainF fr,I_Method qm,int x,int y)
    {
        super(fr);
        this.fr= fr;
        setBackground(Color.lightGray);
       
    }

    public void show(int x,int y)
    {
        repaint();
        reshape(x,y,100,160);
        show();
    }

    private void draw_uplines(Graphics g,int x,int y,int w1,int h1)
{
    g.setColor(Color.white);
        g.drawLine(x,y,x+w1-1,x);
        g.drawLine(x,y,x,y+h1-1);

        g.setColor(Color.black);
        g.drawLine(x+w1-1,y-1,x+w1-1,y+h1-1);
        g.drawLine(x+w1-2,y+1,x+w1-2,y+h1-2);
        g.drawLine(x+1,y+h-2,x+w1-2,y+h1-2);
    //    g.drawLine(x,y+h1-1,x+w1-1,y+h1-1);
    //    g.setColor(Color.black);
    //    g.drawLine(x,y+h1-1,x+w1-1,y+h1-1);
       
}
   
    public void paint(Graphics g)
    {
        sz= size();
        w= sz.width;
        h= sz.height;   
    //    g.setFont(Ffont);
        fm= g.getFontMetrics();
        fh=fm.getHeight();
        fw= fm.charWidth('C');
        g.setColor(Color.gray);
        g.drawRect(10,(index-1)*fh+6,w-20,fh);
    //    g.setColor(Color.lightGray);
    //    g.drawRect(0,0,w,h);
        draw_uplines(g,1,1,w-1,h-1);
        g.setColor(Color.black);
        g.drawString("Cut",13,fh);
        g.drawString("Copy",13,2*fh);
        g.drawString("Paste",13,3*fh);
        g.drawString("Delete",13,4*fh);
    }

    public boolean mouseMove(Event evt,int x,int y)
    {
        for(int i=1;i<=4;i++)
            if((y>(i-1)*fh)&&(y<(i*fh)))
        {
            index= i;
            repaint();
        }
        return super.mouseMove(evt,x,y);
    }

    public boolean mouseDown(Event evt,int x,int y)
    {
        if(y>0&&y<fh)
        {
            fr.current_t.dels();
            fr.eitem.enable(false);
            fr.eitem1.enable(false);
            fr.eitem3.enable(false);
            fr.eitem2.enable(true);
            hide();
            return true;
        }
        if(y>fh&&(y<(2*fh)))
        {
            fr.eitem.enable(false);
            fr.eitem1.enable(false);
            fr.eitem3.enable(false);
            fr.eitem2.enable(true);
            hide();
            return true;
        }
        if((y>(2*fh))&&(y<(3*fh)))
        {
            fr.current_t.adds();
            fr.eitem2.enable(false);
            fr.eitem.enable(false);
            fr.eitem1.enable(false);
            fr.eitem3.enable(false);
            hide();
            return true;
        }
        if((y>(3*fh))&&(y<(4*fh)))
        {
            fr.current_t.dels();
            fr.eitem3.enable(false);
            fr.eitem.enable(false);
            fr.eitem1.enable(false);
            fr.eitem2.enable(false);
            hide();
            return true;
        }
        return super.mouseDown(evt,x,y);
    }
}

class ptest extends Panel
{
    String test= "ABCDabcd";
    D_font ff;

    public ptest(D_font ff)
    {
        this.ff= ff;
        repaint();
    }

    private void draw_downlines(Graphics g,int x,int y,int w,int h)
{
        g.setColor(Color.white);
        g.drawLine(x+1,y+h-1,x+w-1,y+h-1);
        g.drawLine(x+w-1,y+h-1,x+w-1,y+1);
       
        g.setColor(Color.black);
        g.drawLine(x,y,x,y+h);
        g.drawLine(x+1,y+1,x+1,y+h-1);
        g.drawLine(x,y,x+w,y);
        g.drawLine(x+1,y+1,x+w-1,y+1);
}

    public void rep()
    {
        repaint();
    }
   
    public void paint(Graphics g)
    {
        Dimension sz= size();
        Point pt= location();
g.setColor(Color.darkGray);
g.drawRect(0,0,sz.width-2,sz.height-2);

g.setColor(Color.white);
g.drawLine(1,1,1,sz.height-3);
g.drawLine(1,1,sz.width-3,1);

g.drawLine(0,sz.height-1,sz.width-1,sz.height-1);
g.drawLine(sz.width-1,0,sz.width-1,sz.height-1);

        draw_downlines(g,15,10,sz.width-30,sz.height-20);
        g.clipRect(16,11,sz.width-31,sz.height-21);
        g.setColor(Color.black);
        g.setFont(ff.bf);
        g.drawString(test,20,sz.height-21);
    }
}



class D_font extends Dialog
{
    public Font bf;
    private Button OK,Cancel;
    private Label l1,l2,l3;
    private String items1[]={"Helvetica","Courier","TimesRoman","Dialog"};
    private String items2[]={"PLAIN","BOLD","PLAIN+BOLD","ITALIC","BOLD+ITALIC"};
    private int[] style= new int[5];
    private String items3[]={"8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"};
    private TextField f1,f2,f3;
    private List ll1,ll2,ll3;
    private ptest test;
    private I_Method im;

    public void init()
    {
        style[0]= Font.PLAIN;
        style[1]= Font.BOLD;
        style[2]= Font.PLAIN+Font.BOLD;
        style[3]= Font.ITALIC;
        style[4]= Font.BOLD+Font.ITALIC;
    }

    public D_font(Frame fr,I_Method qm,int x,int y)
    {
        super(fr,"字体",true);
        init();
        setFont(new Font("TimesRoman",Font.PLAIN,14));
        im= qm;
       
        GridBagLayout gridBag= new GridBagLayout();
        GridBagConstraints c= new GridBagConstraints();
        setLayout(gridBag);
        c.insets.left= 4;
        c.insets.right= 4;
        c.insets.bottom= 1;
        c.insets.top= 1;
       
        l1= new Label("字体:",Label.LEFT);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=0;
        c.gridy=0;
        c.gridwidth=2;
        c.gridheight =1;
        gridBag.setConstraints(l1,c);
        add(l1);

        l2= new Label("字体样式:",Label.LEFT);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=2;
        c.gridy=0;
        c.gridwidth=1;
        c.gridheight =1;
        gridBag.setConstraints(l2,c);
        add(l2);

        l3= new Label("大小:",Label.LEFT);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=3;
        c.gridy=0;
        c.gridwidth=1;
        c.gridheight =1;
        gridBag.setConstraints(l3,c);
        add(l3);

        OK= new Button("确定");
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=4;
        c.gridy=1;
        c.gridwidth=1;
        c.gridheight =1;
        gridBag.setConstraints(OK,c);
        add(OK);

        f1= new TextField();
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=0;
        c.gridy=1;
        c.gridwidth=2;
        c.gridheight =1;
        gridBag.setConstraints(f1,c);
        add(f1);

        f2= new TextField();
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=2;
        c.gridy=1;
        c.gridwidth=1;
        c.gridheight =1;
        gridBag.setConstraints(f2,c);
        add(f2);

        f3= new TextField();
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=3;
        c.gridy=1;
        c.gridwidth=1;
        c.gridheight =1;
        gridBag.setConstraints(f3,c);
        add(f3);

        Cancel= new Button("取消");
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=4;
        c.gridy=2;
        c.gridwidth=1;
        c.gridheight =1;
        gridBag.setConstraints(Cancel,c);
        add(Cancel);

        ll1= new List();
        for(int i=0;i<items1.length;i++)
            ll1.addItem(items1[i]);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 1.0;
        c.weighty= 1.0;
        c.gridx=0;
        c.gridy=2;
        c.gridwidth=2;
        c.gridheight =7;
        gridBag.setConstraints(ll1,c);
        add(ll1);

        ll2= new List();
        for(int i1=0;i1<items2.length;i1++)
            ll2.addItem(items2[i1]);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=2;
        c.gridy=2;
        c.gridwidth=1;
        c.gridheight =7;
        gridBag.setConstraints(ll2,c);
        add(ll2);

        ll3= new List();
        for(int i2=0;i2<items3.length;i2++)
            ll3.addItem(items3[i2]);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 0.0;
        c.weighty= 0.0;
        c.gridx=3;
        c.gridy=2;
        c.gridwidth=1;
        c.gridheight =7;
        gridBag.setConstraints(ll3,c);
        add(ll3);

        test= new ptest(this);
        c.gridwidth= GridBagConstraints.REMAINDER;
        c.fill= GridBagConstraints.BOTH;
        c.weightx= 1.0;
        c.weighty= 1.0;
        c.gridx=0;
        c.gridy=9;
        c.gridwidth=5;
        c.gridheight =4;
        gridBag.setConstraints(test,c);
        add(test);

        reshape(x/2-210,y/2-140,420,280);
        show();
    }

    public boolean action(Event evt,Object arg)
    {
        if(evt.target instanceof Button)
        {
            if(evt.target== OK)
            {
                if(ll1.getSelectedIndex()==-1)
                    ll1.select(0);
                if(ll3.getSelectedIndex()==-1)
                    ll3.select(0);
                if(ll2.getSelectedIndex()==-1)
                    ll2.select(0);
                int size= Integer.parseInt(items3[ll3.getSelectedIndex()]);
                bf=new Font(items1[ll1.getSelectedIndex()],style[ll2.getSelectedIndex()],size);
                im.setfont(bf);
                dispose();
                return true;
            }
            if(evt.target== Cancel)
            {
                dispose();
                return true;
            }
        }

        if(evt.target instanceof List)
        {
            if(ll1.getSelectedIndex()==-1)
                    ll1.select(0);
            if(ll3.getSelectedIndex()==-1)
                    ll3.select(0);
            if(ll2.getSelectedIndex()==-1)
                    ll2.select(0);
            f1.setText(ll1.getSelectedItem());
            f2.setText(ll2.getSelectedItem());
            f3.setText(ll3.getSelectedItem());
           
            int size= Integer.parseInt(items3[ll3.getSelectedIndex()]);
            bf=new Font(items1[ll1.getSelectedIndex()],style[ll2.getSelectedIndex()],size);
            test.rep();
            return true;
        }
        return super.action(evt,arg);
    }
}


class W_quit extends Dialog
{
    Button OK,Cancel;
    I_Method im;

    public W_quit(Frame fr,I_Method qm)
    {
        super(fr,"java文本编译器");
        //setBackground(Color.lightGray);
        setFont(new Font("TimesRoman",Font.BOLD,16));
        im= qm;
        OK= new Button("确定");
        Cancel= new Button("取消");

        Panel pp= new Panel();
        pp.add(OK);
        pp.add(Cancel);
        add("South",pp);
        add("Center",new Label("Ready to Quit",1));
        reshape(100,100,200,100);
    }

    public boolean action(Event evt,Object arg)
    {
        if(evt.target== OK)
        {
            im.setQuit();
            dispose();
            return true;
        }else
            if(evt.target== Cancel)
        {
            dispose();
            return true;
        }else
            return super.action(evt,arg);
    }
}

class screen
{
    public int[] length;
    public int left,right,up,down;
    public int offsetx=0,offsety=0;
    public int w=0,h=0;
    public int maxline;

    public screen()
    {
        length= new int[300];
        for(int i=0;i<300;i++)
        {
            length[i]= 0;
        }
        left= 0;
        up= 0;
    }

    public void setmax(int x,int y)
    {
        down= y;
        right= x;
    }
}

class cusor
{
    public int cusorx,cusory;//当前光标的坐标
    public int index;//当前光标对应的偏移
    public int linex,liney;//行列号首地址为1,1linex
    public int oldx,oldy;
    public int w,h;

    public cusor(int y)
    {
        index= 0;
        cusorx= 3;
        cusory= y;
        linex= liney= 0;
    }

    public void paint(Graphics g)
    {
        g.setColor(Color.white);
        g.drawLine(oldx,oldy,oldx,oldy-h+2);        
        g.setColor(Color.black);
        g.drawLine(cusorx,cusory,cusorx,cusory-h+2);
        oldx= cusorx;
        oldy= cusory;
    }
}

class select
{
    public char[] sels;
    public int count;// 选中字符的个数
    public int index;//当前光标对应的偏移
    public int linex,liney;

    public select()
    {
        linex= liney= count= 0;
        sels= new char[1000];
    }
}

//横坐标起始为3
class P_area extends Canvas
{
    public screen sc;
    public cusor cus;
    public select sel;
    private MainF fr;
    public String filename,filedir;
    private Font Ffont= null;
    private Color Bcolor= Color.black;
    private FontMetrics fm;
    private Dimension sz;
   
    private int fh,fw;
    private int paint_x,paint_y;//用于写字符   
    public int totle= 0;//字符总数
    private int lcount=0;

    public boolean border= true;//光标是否在边界
//    private boolean scroll= false;
    public boolean select= false;
    public boolean selold= false;//选中后重画屏幕
    public boolean bfind= false;

    private String findtext= null;   
    private int[] findindex;
    private int findcount=0;
    private char[] text;
   
    public P_area(MainF fr,Font cuf,Color cuc,String fn,String fd)
    {
        this.fr= fr;
        setBackground(Color.white);
        sz= size();        
        Ffont= cuf;
        setFont(cuf);
        cus= new cusor(sz.height);
        sc= new screen();
        sel= new select();
        Bcolor= cuc;
        filename= fn;
        filedir= fd;
        text= new char[5000];
        findindex= new int[100];
        repaint();
    }

    private void draw_downlines(Graphics g,int x,int y,int w,int h)
{
        g.setColor(Color.white);
        g.drawLine(x+1,y+h-1,x+w-1,y+h-1);
        g.drawLine(x+w-1,y+h-1,x+w-1,y+1);
       
        g.setColor(Color.black);
        g.drawLine(x,y,x,y+h);
        g.drawLine(x+1,y+1,x+1,y+h-1);
        g.drawLine(x,y,x+w,y);
        g.drawLine(x+1,y+1,x+w-1,y+1);
}

    //打开已存在的文件
    public void setname(String fn,String fd)
    {
        filename= fn;
        filedir= fd;
    }

    public void open(String line)
    {
        //findtext= line;
        line.getChars(0,line.length()-1,text,totle);
        totle+= line.length();
    //    text[totle]= '';
    //    totle++;
    //    sc.length[lcount]= line.length()+1;
    //    lcount++;
        repaint();
    }

    public String getText()
    {
        char[] ret= new char[totle];
        for(int i=0;i<totle;i++)
            ret[i]= text[i];
        return (new String(ret));
    }

    public void movecusor(int x,int y)
    {
        cus.linex= (int)((x-3)/cus.w);
        cus.liney= (int)((y-3*fh)/cus.h)+1;
        int i=0;
        cus.index=0;
        for(;i< cus.liney+sc.offsety-1;i++)
            cus.index+= sc.length[i];
        cus.index+=cus.linex-1+sc.offsetx;
        cus.cusorx= (cus.linex-1)*cus.w+3;
        cus.cusory= cus.liney*cus.h;
        cus.paint(getGraphics());
    }
   
    public void keycusor(int x,int y)
    {
        cus.linex+= x;
        cus.liney+= y;
        cus.cusorx+= x*cus.w;
        cus.cusory+= y*cus.h;
        int i=0;
        cus.index=0;
        for(;i<cus.liney+sc.offsety-1;i++)
            cus.index+= sc.length[i];
        cus.index+=cus.linex-1+sc.offsetx;
        cus.paint(getGraphics());
    }

    public void add(char ch)
    {
        if(totle==0)
            totle= 1;
        for(int i= totle;i>=cus.index;i--)
            text[i]= text[i-1];
        text[cus.index]= ch;
        totle++;
        sc.length[cus.liney]+= 1;
       
        repaint();
        if(ch=='')
        {
            cus.linex= 1;
            cus.liney+= 1;
            cus.cusorx= 3;
            cus.cusory= cus.liney*cus.h;
            cus.index++;
        }else
            keycusor(1,0);
    }

    public void adds()
    {
        totle+= sel.count;
        int i;
        for(i= totle-1;i>(cus.index+sel.count);i--)
            text[i]= text[i-sel.count];
        for(int j= sel.count;j>0;j--,i--)
            text[i]= sel.sels[j-1];
        sel.count= 0;
        repaint();
    }
   
    public void del(int de)
    {
        if(de<0)
        {
            for(int i= cus.index-1;i<totle;i++)
                text[i]= text[i+1];
            keycusor(-1,0);
        }
        if(de>0)
            for(int i= cus.index;i<totle;i++)
            text[i]= text[i+1];
        totle--;
        repaint();
    }

    public void dels()
    {
        if(sel.count<0)
        {
            int end= -sel.count;
            for(int i= sel.index;i<totle;i++)
                text[i]= text[i+end+2];
        }
        if(sel.count>0)
        {
            int end= sel.index+1;
            for(int i= end;i<totle;i++)
                text[i-sel.count]= text[i];
        }
        totle-= sel.count;
        //sel.count= 0;
        repaint();
    }

    public void selrep()
    {
        draw(getGraphics());
    }

    public void drag(int x,int y)
    {
        sel.linex= (int)((x-3)/cus.w);
        sel.liney= (int)((y-3*fh)/cus.h)+1;
        int i=0;
        sel.index=0;
        for(;i< sel.liney+sc.offsety-1;i++)
            sel.index+= sc.length[i];
        sel.index+=sel.linex-1+sc.offsetx;
        sel.count= sel.index- cus.index+1;
        if(sel.index!= cus.index)
        {
            select= true;
            selold= true;
            repaint();
        }
    }

    private void drawselect(Graphics g)
    {
        int ji= 0;
        paint_x= 3-(int)(sc.offsetx*cus.w);
        paint_y= fh-(int)(sc.offsety*fh);
        for(int i=0;i< totle;i++)
        {
            if(text[i]=='')
            {
                paint_x = 3-(int)(sc.offsetx*cus.w);
                paint_y+=cus.h;
                i++;
            }
            fw= fm.charWidth(text[i]);
            if(sel.index>cus.index)
            {
                if((i< totle)&&(i<=sel.index)&&(i>=cus.index))
                {
                    sel.sels[ji]= text[i];
                    ji++;
                    g.setColor(Color.blue);
                    g.fillRect(paint_x,paint_y-fh,fw+1,fh);
                    g.setColor(Color.white);
                    g.drawChars(text,i,1,paint_x,paint_y);
                }
            }else
                if((i< totle)&&(i>=sel.index)&&(i<=cus.index))
                {
                sel.sels[ji]= text[i];
                ji++;
                g.setColor(Color.blue);
                    g.fillRect(paint_x,paint_y-fh,fw+1,fh);
                    g.setColor(Color.white);
                    g.drawChars(text,i,1,paint_x,paint_y);
                }

            paint_x+= fw;
        }
    }

    public void home()
    {
        cus.linex= 1;
        int i=0;
        cus.index=0;
        for(;i< cus.liney+sc.offsety-1;i++)
            cus.index+= sc.length[i];
        cus.index+=cus.linex-1+sc.offsetx;
        cus.cusorx= 3;
        cus.paint(getGraphics());
    }

    public void end()
    {
        cus.linex= sc.length[cus.liney-1]-1;
        int i=0;
        cus.index=0;
        for(;i< cus.liney+sc.offsety-1;i++)
            cus.index+= sc.length[i];
        cus.index+=cus.linex-1+sc.offsetx;
        cus.cusorx= (cus.linex-1)*cus.w+3;
        cus.paint(getGraphics());
    }

    public void pagedown()
    {
        if(sc.maxline>2*sc.h)
        {
            sc.offsety+= sc.h;
            fr.vert.setValue(sc.offsety);
            draw(getGraphics());
            fr.vert.setValue(sc.offsety);
        }
    }

    public void pageup()
    {
        if((sc.offsety-sc.h)>=0)
        {
            sc.offsety-=sc.h;
            draw(getGraphics());
            fr.vert.setValue(sc.offsety);
        }
    }

    public void scrollpaint(int x1,int x2)
    {
        sc.offsetx= x1;
        sc.offsety= x2;
    //    getGraphics().translate(-x1,-x2);
        draw(getGraphics());
    }
    public void setFont(Font cuf)
    {
        Ffont= cuf;
        //paint= true;
        repaint();
    }

    public void setColor(Color col)
    {
        Bcolor= col;
    //    paint= true;
        repaint();
    }

    public void rep()
    {
        repaint();
    }
   
    private void draw(Graphics g)
    {
        findtext= new String(text,0,totle);
        int findi= findcount;
        int aa= 0;//用于记录starti
        int c1= 0;//记录行的数目
        int c2= 0;//记录每行的字节数
        int c3= 0; //最大列数
        g.setFont(Ffont);
        g.setColor(Color.white);
        g.fillRect(3,2,sz.width,sz.height);
        g.setColor(Bcolor);
       
        paint_x= 3-(int)(sc.offsetx*cus.w);
        paint_y= fh-(int)(sc.offsety*fh);
        for(int i=0;i< totle;i++)
        {
            if(text[i]=='')
            {
                paint_x = 3-(int)(sc.offsetx*cus.w);
                paint_y+=cus.h;
                //i++;
                sc.length[c1]= c2+1;
                c1++;
                if(c2>c3)
                    c3= c2;
                c2= 0;
            }else            
            if(i< totle)
            {
                fw= fm.charWidth(text[i]);
                g.setColor(Bcolor);
                g.drawChars(text,i,1,paint_x,paint_y);
                if(i== findindex[findi]&&bfind)
                {
                    if(findi>0)
                        findi--;
                    g.setColor(Color.blue);        
                    g.fillRect(paint_x,paint_y-fh+2,fw+1,fh);
                    g.setColor(Color.white);
                    g.drawChars(text,i,1,paint_x,paint_y);
               
                }
               
                paint_x+= fw;
                c2++;
            }
        }
        c1+= 1;
        sc.maxline= c1;
        cus.paint(g);
        if(c3> sc.w)
            fr.horz.setValues(0,sc.w,0,c3-sc.w);
        if(c1> sc.h)
            fr.vert.setValues(0,sc.h,0,c1-sc.h);
    }

    public void update(Graphics g)
    {
        sz= size();
        g.setColor(Bcolor);
        g.setFont(Ffont);
        fm= g.getFontMetrics();
        cus.h= fh= fm.getHeight();
        cus.w= fw= fm.charWidth('A');
        sc.h= (int)((sz.height-3)/fh)+1;
        sc.w= (int)((sz.width-3)/fw)+1;

        draw_downlines(g,0,0,sz.width,sz.height);
        //g.clipRect(3,2,sz.width,sz.height);
        if(select)
        {
            drawselect(g);
            select= false;
        }else
            draw(g);
    }

    public void paint(Graphics g)
    {
        update(g);
    }

    public boolean mouseEnter(Event evt,int x,int y)
    {
      &<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>