Text editor source file (Java language)

zhaozj2021-02-11  178

/ Copyright 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, cazcel;

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, "Palette", TRUE;

THIS.MP = MP;

Colors = new color [strlen];

Colors1 = new color [strlen];

Colors2 = new color [strlen];

For (int i = 0; i

{

Float H = ((Float) i) / (Float Strlen);

Colors [I] = New Color (Color.hsbtorgb (h, 1.0f, 1.0f));

}

For (int i = 0; i

{

Float H = ((Float) i) / (Float Strlen);

Colors1 [i] = new color (color.hsbtorgb (1.0f, h, 1.0f));

}

For (int i = 0; i

{

Float H = ((Float) i) / (Float Strlen);

Color (color.hsbtorgb (1.0f, 1.0f, h));

}

setLayout (null);

OK = New Button ("OK");

Cancel = New Button ("Cancel");

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

{

G.SetColor (Colors [i]);

g.fillRect (0, Y, 100, 1);

Y = 1;

}

y = 0;

For (int i = 0; i

{

G.SetColor (Colors1 [i]);

G.FillRect (100, y, 100, 1);

Y = 1;

}

y = 0;

For (int i = 0; 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 (bat ,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 (est.target == ok)

{

Mp.SetColor (CURRENT);

Dispose ();

Return True;

}

IF (est.target == ca Zancel)

{

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.ble);

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.ble);

// 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.getHHEight ();

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.ble);

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

{

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.ble);

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.ble);

g.setfont (ff.bf);

g.drawstring (TEST, 20, SZ.HEIGHT-21);

}

}

Class D_Font Extends Dialog

{

Public Font BF;

Private button ok, cazcel;

Private label L1, L2, L3;

Private string items1 [] = {"Helvetica", "Courier", "Timeesroman", "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", "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.ital;

}

Public D_Font (Frame Fr, I_Method QM, INT X, INT Y)

{

Super (Fr, "Font", True;

INIT ();

SetFont (New Font ("Timeesroman", 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 ("Font:", 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 ("Font Style:", 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 ("Size:", 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 ("OK");

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 ("Cancel");

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

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

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

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 (est.target == ok)

{

IF (ll1.getSelected "== - 1)

Ll1.select (0);

IF (ll3.getSelectedIndex () == - 1)

ll3.select (0);

IF (ll2.getSelectedIndex () == - 1)

Ll2.select (0);

INT size = integer.parseint (items3 [ll3.getSelected ");

BF = new font (items1 [ll1.getSelected "], style [ll2.getSelected";

Im.setfont (bf);

Dispose ();

Return True;

}

IF (est.target == ca Zancel)

{

Dispose ();

Return True;

}

}

IF (Evt.Target InstanceOf List)

{

IF (ll1.getSelected "== - 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.getSelected ");

BF = new font (items1 [ll1.getSelected "], style [ll2.getSelected";

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 Text Compiler);

//setbackground(chor.lightgray);

SetFont (New Font ("Timeesroman", Font.Bold, 16));

IM = qm;

OK = New Button ("OK");

Cancel = New Button ("Cancel");

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 (est.target == ok)

{

im.setquit ();

Dispose ();

Return True;

Else

IF (est.target == ca Zancel)

{

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 tent [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; // Current cursor coordinates

Public int index; // Current cursor corresponding to offset

Public int linex, liney; // Layer number first address is 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.ble);

G. Drawline (Cusorx, Cusory, Cusorx, Cusory-H 2);

Oldx = CUSORX;

Oldy = CUSORY;

}

}

Class Select

{

Public char [] SELS;

Public int count; // Select the number of characters

Public int index; // Current cursor corresponding to offset

Public int linex, liney;

Public select ()

{

LINEX = liney = count = 0;

Sels = New char [1000];

}

}

// The horizontal start is 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; // Used to write characters

Public int = 0; // Total number of characters

Private int lcount = 0;

Public Boolean Border = true; // Whether the cursor is on the boundary

// private boolean scroll = false;

Public boolean select = false;

Public boolean selold = false; // Select the back and redraw screen

Public Boolean bfind = false;

Private string findtext = null;

Private int [] FindIndex;

Private int foccount = 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.ble);

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);

}

// Open an existing file

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] = '/ n';

// Totle ;

// sc.Length [lcount] = line.length () 1;

// lcount ;

Repaint ();

}

Public string getText ()

{

CHAR [] RET = New Char [TOTLE];

For (INT i = 0; 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.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.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 == '/ n')

{

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

Text [i] = text [i 1];

Keycusor (-1,0);

}

IF (de> 0)

For (int i = cus.index; 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

Text [i] = text [i end 2];

}

IF (SEL.COUNT> 0)

{

INT end = SEL.INDEX 1;

For (int I = end; 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.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

{

IF (Text [i] == '/ n') {

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 = 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 = 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.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.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 Color

{

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; // Used to record starti

INT C1 = 0; // Number of records

INT C2 = 0; // Record the number of bytes per line

INT C3 = 0; // Maximum number

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

{

IF (Text [i] == '/ n')

{

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

{

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)

{

Fr.SetCursor (2);

Return True;

}

Public Boolean MouseExit (Event EVT, INT X, INT Y)

{

Fr.SetCursor (0);

Return True;

}

Public Void Find (String Find, Int Dire)

{

bfind = true;

Findcount = 0;

String SSS = FindText;

For (int i = 0; i <100; i )

FindIndex [i] = 0;

INT j = 0;

While (True)

{

IF (SSS.INDEXOF (Find) == - 1)

Break;

FindIndex [J] = sss.lastIndexof (Find);

SSS = sss.substring (0, FindIndex [J]);

J ;

Findcount ;

}

Repaint ();

SELOLD = TRUE;

}

}

Public Class Mainf Extends Frame IMPLEMENTS I_METHOD

{

Private w_quick lshow;

PRIVATE FILEDIALOG OPENDIALOG;

PRIVATE FILEDIALOG SAVEDIALOG;

Public scrollbar horz, vert;

Private menubar menubar;

Private Panel file_panel, back_p;

Private Panel back_panels [];

Private int screenw, screenh;

Private color fcolor = color.black;

Private font ffont = new font ("Timeesroman", Font.Plain, 14);

Private Int fwidth, Fheight;

Private int [] bookmarks = new int =

// ***************

Public P_area Current_t;

Private Int I1;

Private INT III = 0;

Private boolean insert = false;

Boolean begin = false; // 开始 用 是 标 是 选 选 选

Boolean end = false;

Private Int SEL1 = 0;

Private Int SEL2 = 0;

Menuitem EITEM;

Menuitem EITEM1;

Menuitem EITEM2;

Public MenuItem EITEM3;

Mainf (String Title)

{

Super (title);

Font Font = New Font ("Timeesroman", Font.Bold, 20);

SetFont (font);

SetBackground (color.lightgray); horz = new scrollbar (scrollbar.horizontal, 0, 0, 0);

Vert = new scrollbar (scrollbar.vertical, 0, 0, 0);

// show ();

AddMenu ();

INIT ();

LSHOW = New W_quick (this, this, 0,0);

OpenDialog = New FileDialog (this, "open file ...", filedialog.load);

Savedialog = New FileDialog (this, "Save File ...", FileDialog.save;

}

Private void init ()

{

SetLayout (New BorderLayout ());

File_Panel = New Panel ();

File_Panel.SetBackground (color.lightgray);

Panel pp = new panel ();

PP.setLayout (New BorderLayout);

Current_t = new p_area (this, ffont, fcolor, "aa", "aa");

PP.Add ("center", current_t);

PP.Add ("South", HORZ);

PP.Add ("EAST", VERT);

Add ("South", File_Panel;

Add ("Center", PP);

Dimension Screen_Size = Toolkit.getDefaultToolkit (). GetScreensize ();

Screenw = screen_size.width;

Screenh = Screen_Size.Height-16;

Reshape (16, 16, Screen_Size.width-32, Screen_Size.Height-32);

SHOW ();

}

Private void addmenu ()

{

Menubar = new menubar ();

setmenubar;

Menu Menu = New Menu ("File");

Menu Menu1 = New Menu ("Edit");

Menu Menu2 = New Menu ("Option");

MenuBar.Add (Menu);

MenuBar.Add (Menu1);

MenuBar.Add (Menu2);

Menuitem Fitem = New Menuitem ("New");

Menu.add (fitem);

MenuItem Fitem1 = New Menuitem ("Open");

Menu.add (fitem1);

Menuitem Fitem2 = New Menuitem ("Close");

Menu.add (fitem2);

Menu.addseparator ();

Menuitem Fitem3 = New Menuitem ("Save");

Menu.Add (FiteM3);

Menuitem Fitem4 = New Menuitem ("Save AS");

Menu.Add (Fitem4);

Menu.addseparator ();

Menuitem fitem5 = new menuItem ("quit");

Menu.add (FiteM5); Menu1.Add (New Menuitem ("undo");

Menu1.Add (New Menuitem ("REDO");

Menu1.addseparator ();

EITEM = New MenuItem ("CUT");

Menu1.add (EITEM);

EItem.enable (FALSE);

EITEM1 = New Menuitem ("Copy");

EITEM1.ENABLE (FALSE);

Menu1.add (EITEM1);

EITEM2 = New Menuitem ("Paste");

Menu1.add (EITEM2);

EItem2.enable (false);

Menu1.addseparator ();

EITEM3 = New Menuitem ("delete");

Menu1.Add (EITEM3);

EItem3.enable (false);

Menuitem EITEM6 = New Menuitem ("Bookmark");

Menu1.add (EITEM6);

Menu1.addseparator ();

Menuitem EITEM4 = New Menuitem ("Find");

Menu1.Add (EITEM4);

MenuItem EITEM5 = New Menuitem ("Repace");

Menu1.Add (EITEM5);

MenuItem OITEM = New Menuitem ("Color");

Menu2.Add (OITEM);

Menuitem OITEM1 = New Menuitem ("font");

Menu2.Add (OITEM1);

}

Public void setquit ()

{

this.dispose ();

System.exit (0);

}

Public void setFont (Font F)

{

Ffont = f;

Current_t.setfont (f);

Repaint ();

}

Public Void SetColor (Color C)

{

Fcolor = C;

Current_t.setcolor (c);

Repaint ();

}

Public void Paint (Graphics G)

{

IF (ffont! = null)

g.setfont (ffont);

}

Public void read (String FN, String FD)

{

Current_t.setname (FN, FD);

String line = NULL;

String infut = null;

File s = new file (fd, fn);

FileInputStream in = NULL;

DataInputStream DataIn = NULL;

Try

{

IN = New fileInputstream (s);

Datain = New DataInputStream (in);

} catch (Exception E)

{

System.out.Println ("Unable to open file");

Return;

}

Try {

While ((line = datain.readline ())! = NULL)

{

LINE = "/ n";

IF (Input == Null)

INPUT = line;

Else

INPUT = line;

}

} catch (ioException e) {system.out.println ("Error In Reading File");

}

Current_t.open (input);

Try {

In.Close ();

} catch (ioexception e) {

System.out.println ("e");

}

}

Public Void Write (String FN, String FD)

{

FileOutputStream out = null;

File s = new file (fd, fn);

Try {

OUT = New FileOutputStream (s);

} catch (Exception E)

{

System.out.Println ("Unable to open file");

Return;

}

PRINTSTREAM PSOUT = New PrintStream (OUT);

PSout.print (current_t.gettext ()); ///

Try {

Out.close ();

} catch (ioexception e) {

System.out.println ("e");

}

}

Public Boolean KeyDown (Event EVT, INT Key)

{

System.out.println (Key);

Switch (key)

{

Case 1004: // Up

Current_t.keycusor (0, -1);

Return True;

Case 1005: // down

Current_t.keycusor (0, 1);

Return True;

Case 1006:

Current_t.keycusor (-1,0);

Return True;

Case 1007:

Current_t.keycusor (1,0);

Return True;

Case 8:

Current_t.del (-1);

Return True;

Case 127:

Current_t.del (1);

Return True;

Case 1001: // end

Current_t.end ();

Return True;

Case 1000: // Home

Current_t.home ();

Return True;

Case 1002:

CURRENT_T.PAGEUP ();

Return True;

Case 1003:

Current_t.pagedown ();

Return True;

}

// if (! Current_t.border)

// current_t.addchar ((char) evt.key);

// else

Current_t.add ((char) evt.key);

Return True;

}

Public Boolean MouseDown (Event EVT, INT X, INT Y)

{

// **** Click Right click ****************** incomplete

EItem.enable (FALSE);

EITEM1.ENABLE (FALSE);

EItem3.enable (false);

Current_t.bfind = false;

IF ((est.modifiers & evenett.meta_mask)> 0)

{

Lshow.show (est.x, evt.y);

Return False;

Else

{

Lshow.hide ();

Begin = True;

Current_t.movecusor (est.x, evt.y);

IF (current_t.selold)

{

Current_t.selold = false;

Current_t.selrep ();

}

}

IF (end)

{

// current_t.rep ();

// current_t.paint = true;

End = false;

}

Return False;

}

Public Boolean MouseDrag (Event EVT, INT X, INT Y)

{

EItem.enable (TRUE);

EITEM1.enable (TRUE);

EITEM3.enable;

Current_t.drag (EVT.X, EVT.Y);

//}

Return True;

}

Public Boolean Handleevent (EVENT EVT)

{

IF (Evt.id == Event.Window_Destroy)

{

W_quit aa = new w_quit (this, this);

aa.show ();

Return True;

}

Switch (evt.id)

{

Case 601:

Case 602:

Case 603:

Case 604:

Case 605:

//current_t.offsety= (VERT.GETVALUE ());

// current_t.offsetx = (HORZ.GETVALUE ());

// current_t.paint = true;

// current_t.rep ();

Current_t.scrollpaint (Horz.getValue (), VERT.GetValue ());

Vert.setValue (current_t.sc.offsety);

HORZ.SETVALUE (current_t.sc.offsetx);

Return True;

}

Return super.handleevent (evt);

}

Public Boolean Action (EVENT EVT, Object Arg)

{

String filename;

IF (EVT.TARGET InstanceOf MenuItem)

{

IF (est.arg.equals ("new")))

{

Return True;

}

IF (evt.arg.equals ("open")))

{

OpenDialog.show ();

String fn = Opendialog.getFile ();

String filedir = Opendialog.getdirectory ();

Read (FN, Filedir);

Return True;

}

IF (Evt.Arg.equals ("Save")))

{

Write (current_t.filename, current_t.filedir);

Return True;

}

IF (Evt.arg.Equals ("Save AS")))

{

Savedialog.show ();

Filename = savedialog.getfile ();

String filedir = Opendialog.getdirectory ();

Write (filename, filedir);

Return True;

}

IF (Evt.arg.Equals ("quit"))

{

System.exit (0);

}

IF (Evt.arg.Equals ("CUT"))

{

Current_t.dels ();

EItem.enable (FALSE);

EITEM1.ENABLE (FALSE);

EItem3.enable (false);

EITEM2.enable (TRUE);

Return True;

}

IF (Evt.arg.Equals ("Paste"))

{

Current_t.adds (); EITEM2.enable (false);

EItem.enable (FALSE);

EITEM1.ENABLE (FALSE);

EItem3.enable (false);

Return True;

}

IF (evt.arg.equals ("copy"))

{

EItem.enable (FALSE);

EITEM1.ENABLE (FALSE);

EItem3.enable (false);

EITEM2.enable (TRUE);

Return True;

}

IF (Evt.arg.Equals ("delete"))))

{

Current_t.dels ();

EItem3.enable (false);

EItem.enable (FALSE);

EITEM1.ENABLE (FALSE);

EItem2.enable (false);

Return True;

}

IF (Evt.Arg.equals ("close")))

{

CURRENT_T.TOTLE = 0;

CURRENT_T.REP ();

Return True;

}

IF (Evt.arg.Equals ("Find"))

{

New Outpanel (this);

Return True;

}

IF (Evt.Arg.equals ("font")))

{

New D_Font (this, this, screenw, screenh);

Return True;

}

IF (Evt.arg.Equals ("color")))

{

New D_Color (this, this, screenw, screenh);

Return True;

}

}

/ * Else if (Evt.Target InstanceOf Button)

{

} * /

Return False;

}

Public Void Find (String Find, Int Dire)

{

Current_t.find (Find, DIRE);

System.out.println (find);

}

Public static void main (string [] args)

{

Mainf ff = new mainf ("Text Compiler");

}

}

Class Outpanel Extends Dialog

{

Mainf FR;

Label lbname; // name label

Textfield TFName; // Entry Field

OutlinePanel Psex; // Two Outlined Panels]

CheckboxGroup CBSEX;

Checkbox Up, Down, Boxc; // 2 Radios

Button OK, Cancel; // Two Pushbuttons

Gridbagconstraints GBC;

GridbagLayout GBL;

INT DIRE = 1;

Public Outpanel (Mainf FR)

{

Super (Fr, Find ", TRUE;

THIS.FR = fr;

SetFont (New Font ("Helvetica", Font.Plain, 12));

SetBackground (color.lightgray);

GBL = New gridbagLayout ();

GBC = New gridbagconstraints ();

SetLayout (GBL);

GBC.IPADX = 5; // Make Buttons Wider

GBC.IPADY = 3; // Make Buttons Higher

Gbc.insets.Left = 6;

GBC.Insets.right = 6; gbc.insets.bottom = 4;

Gbc.insets.top = 4;

Gbc.weightx = 1;

gbc.weighty = 1;

LBNAME = New Label ("Find Target:"); // Label

Add_component (lbname, 0, 0, 1, 1);

TFNAME = New TextField (20); // text Entry Field

Add_component (TFNAME, 1, 0, 3, 1);

// Panel with Two Buttons for SEX

Boxc = New Checkbox ("Case Size");

Add_component (BoxC, 0, 2, 1, 1);

PSEX = new OutlinePanel (); //first Panel

Add_component (PSEX, 1, 1, 3, 2); // Insert in Layout

// Put Two Radio Buttons in Panel

Up = psex.addcheckbox ("Up", False);

Down = psex.addcheckbox ("Down", TRUE);

PSEX.Resize (148, 53);

// add two command buttons to bottom

OK = New Button ("find one"); // Buttons At Bottom

Cancel = New Button ("Cancel");

Add_component (OK, 4, 0, 1, 1);

Add_component (Cancel, 4, 2, 1, 1);

Reshape (100, 100, 380, 146);

SHOW ();

}

// --------------------------------------

Private Void Add_component (Component C, Int x, Int Y, INT W, INT H)

{

gbc.gridx = x;

GBC.Gridy = Y;

GBC.GridWidth = W;

Gbc.gridheight = h;

Add (c);

GBL.SETCONSTRAINTS (C, GBC);

}

// --------------------------------------

Public Boolean Action (EVENT EVT, Object Arg)

{

IF (est.target == ok)

{

String ss = tfname.getText ();

IF (Boxc.getState ())

{

SS.TOLOWERCASE ();

Fr.Find (SS, DIRE);

Else

Fr.Find (SS, DIRE);

}

IF (est.target == ca Zancel)

{

Dispose ();

Return True;

}

IF (est.target == UP)

{

DIRE = -1;

}

IF (est.target == down)

{

Dire = 1;

}

IF (est.target == Boxc)

{

}

Return Super.Action (EVT, ARG);

}

}

// * / // =============================================== Class OutlinePanel Extends Panel

{

Checkboxgroup CBG;

Int Yposn;

Vector CBList;

// --------------------------------------

Public OUTLINEPANEL ()

{

Super ();

CBG = New CheckboxGroup (); // for radio buttons

setLayout (null);

Yposn = 3;

CBList = new vector ();

}

// --------------------------------------

Public void Reshape (int X, int y, int w, int h)

{

Super.reshape (X, Y, W, H);

For (int i = 0; i

{

Component C = (Component) CBList.Elementat (i);

C.reshape (C.Location (). x, c.Location (). Y, W-6, C.Size (). HEIGHT);

}

}

// --------------------------------------

Public Component Add (Component C)

{

Super.Add (c);

Return C;

}

// --------------------------------------

Public Checkbox AddCheckBox (String S, Boolean Checked)

{

Checkbox CB = New Checkbox (S, CBG, Checked);

Add (CB);

CBList.Addelement (CB);

Cb.reshape (3, Yposn, 50, 12);

Yposn = 15;

Return CB;

}

// --------------------------------------

Public void Paint (Graphics G)

{

Dimension SZ = Size ();

Point pt = location ();

G.SetColor (color.darkgray); // graw rectangle

g.drawRect (0, 0, Sz.width-2, Sz.Height-2);

// Outline Gray Rectangle with 2 White Inner Lines

g.setcolor (color.white);

g.drawline (1, 1, sz.width-3, 1);

g.drawline (1, 1, 1, sz.height-3);

// and two white outer lines

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

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

}

// --------------------------------------

}

转载请注明原文地址:https://www.9cbs.com/read-4821.html

New Post(0)