unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
  ExtCtrls, Buttons, SynHighlighterJava, SynEdit, SynCompletion,
  SynHighlighterAny, SynHighlighterCpp, SynExportHTML, LCLType, LConvEncoding,
  UTF8Process, Crt, Process, LazUTF8, PrintersDlgs, Clipbrd, ComCtrls, Printers,
  PReport;

type

  { TForm1 }

  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn5: TBitBtn;
    ImageList1: TImageList;
    ImageList3: TImageList;
    ImageList2: TImageList;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    Memo1: TMemo;
    MenuItem1: TMenuItem;
    MenuItem10: TMenuItem;
    MenuItem11: TMenuItem;
    MenuItem12: TMenuItem;
    MenuItem13: TMenuItem;
    MenuItem14: TMenuItem;
    MenuItem15: TMenuItem;
    MenuItem16: TMenuItem;
    MenuItem17: TMenuItem;
    MenuItem18: TMenuItem;
    MenuItem19: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem20: TMenuItem;
    MenuItem21: TMenuItem;
    MenuItem22: TMenuItem;
    MenuItem23: TMenuItem;
    MenuItem24: TMenuItem;
    MenuItem25: TMenuItem;
    MenuItem26: TMenuItem;
    MenuItem27: TMenuItem;
    MenuItem28: TMenuItem;
    MenuItem29: TMenuItem;
    MenuItem3: TMenuItem;
    MenuItem30: TMenuItem;
    MenuItem31: TMenuItem;
    MenuItem32: TMenuItem;
    MenuItem33: TMenuItem;
    MenuItem34: TMenuItem;
    MenuItem35: TMenuItem;
    MenuItem36: TMenuItem;
    MenuItem37: TMenuItem;
    MenuItem38: TMenuItem;
    MenuItem39: TMenuItem;
    MenuItem4: TMenuItem;
    MenuItem40: TMenuItem;
    MenuItem41: TMenuItem;
    MenuItem42: TMenuItem;
    MenuItem43: TMenuItem;
    MenuItem44: TMenuItem;
    MenuItem45: TMenuItem;
    MenuItem48: TMenuItem;
    MenuItem49: TMenuItem;
    MenuItem5: TMenuItem;
    MenuItem50: TMenuItem;
    MenuItem51: TMenuItem;
    MenuItem52: TMenuItem;
    MenuItem53: TMenuItem;
    MenuItem54: TMenuItem;
    MenuItem55: TMenuItem;
    MenuItem56: TMenuItem;
    MenuItem57: TMenuItem;
    MenuItem58: TMenuItem;
    MenuItem59: TMenuItem;
    MenuItem6: TMenuItem;
    MenuItem60: TMenuItem;
    MenuItem61: TMenuItem;
    MenuItem62: TMenuItem;
    MenuItem63: TMenuItem;
    MenuItem64: TMenuItem;
    MenuItem65: TMenuItem;
    MenuItem66: TMenuItem;
    MenuItem67: TMenuItem;
    MenuItem68: TMenuItem;
    MenuItem69: TMenuItem;
    MenuItem7: TMenuItem;
    MenuItem70: TMenuItem;
    MenuItem71: TMenuItem;
    MenuItem72: TMenuItem;
    MenuItem73: TMenuItem;
    MenuItem74: TMenuItem;
    MenuItem75: TMenuItem;
    MenuItem76: TMenuItem;
    MenuItem77: TMenuItem;
    MenuItem78: TMenuItem;
    MenuItem79: TMenuItem;
    MenuItem8: TMenuItem;
    MenuItem80: TMenuItem;
    MenuItem81: TMenuItem;
    MenuItem82: TMenuItem;
    MenuItem83: TMenuItem;
    MenuItem84: TMenuItem;
    MenuItem85: TMenuItem;
    MenuItem86: TMenuItem;
    MenuItem9: TMenuItem;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    PopupMenu1: TPopupMenu;
    PrintDialog1: TPrintDialog;
    ProcessUTF8_1: TProcessUTF8;
    ProcessUTF8_2: TProcessUTF8;
    ProcessUTF8_3: TProcessUTF8;
    ProcessUTF8_4: TProcessUTF8;
    SaveDialog1: TSaveDialog;
    SaveDialog_html: TSaveDialog;
    SelectDirectoryDialog1: TSelectDirectoryDialog;
    Separator1: TMenuItem;
    Separator10: TMenuItem;
    Separator11: TMenuItem;
    Separator12: TMenuItem;
    Separator2: TMenuItem;
    Separator3: TMenuItem;
    Separator4: TMenuItem;
    Separator5: TMenuItem;
    Separator6: TMenuItem;
    Separator7: TMenuItem;
    Separator8: TMenuItem;
    Separator9: TMenuItem;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton19: TSpeedButton;
    SpeedButton20: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    Splitter1: TSplitter;
    Splitter2: TSplitter;
    SynCompletion1: TSynCompletion;
    SynEdit1: TSynEdit;
    SynExporterHTML1: TSynExporterHTML;
    SynJavaSyn1: TSynJavaSyn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MenuItem10Click(Sender: TObject);
    procedure MenuItem11Click(Sender: TObject);
    procedure MenuItem17Click(Sender: TObject);
    procedure MenuItem19Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem21Click(Sender: TObject);
    procedure MenuItem26Click(Sender: TObject);
    procedure MenuItem27Click(Sender: TObject);
    procedure MenuItem29Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem30Click(Sender: TObject);
    procedure MenuItem31Click(Sender: TObject);
    procedure MenuItem32Click(Sender: TObject);
    procedure MenuItem35Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure MenuItem41Click(Sender: TObject);
    procedure MenuItem43Click(Sender: TObject);
    procedure MenuItem44Click(Sender: TObject);
    procedure MenuItem45Click(Sender: TObject);
    procedure MenuItem47Click(Sender: TObject);
    procedure MenuItem48Click(Sender: TObject);
    procedure MenuItem49Click(Sender: TObject);
    procedure MenuItem50Click(Sender: TObject);
    procedure MenuItem51Click(Sender: TObject);
    procedure MenuItem52Click(Sender: TObject);
    procedure MenuItem61Click(Sender: TObject);
    procedure MenuItem62Click(Sender: TObject);
    procedure MenuItem63Click(Sender: TObject);
    procedure MenuItem65Click(Sender: TObject);
    procedure MenuItem68Click(Sender: TObject);
    procedure MenuItem69Click(Sender: TObject);
    procedure MenuItem74Click(Sender: TObject);
    procedure MenuItem75Click(Sender: TObject);
    procedure MenuItem76Click(Sender: TObject);
    procedure MenuItem77Click(Sender: TObject);
    procedure MenuItem78Click(Sender: TObject);
    procedure MenuItem79Click(Sender: TObject);
    procedure MenuItem80Click(Sender: TObject);
    procedure MenuItem81Click(Sender: TObject);
    procedure MenuItem82Click(Sender: TObject);
    procedure MenuItem83Click(Sender: TObject);
    procedure MenuItem9Click(Sender: TObject);
    procedure SpeedButton10Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure SpeedButton14Click(Sender: TObject);
    procedure SpeedButton15Click(Sender: TObject);
    procedure SpeedButton16Click(Sender: TObject);
    procedure SpeedButton18Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure Stop();
    procedure Convertcp1251toutf8();
    procedure PrintStrings(Strings: TStrings);
  private

  public
   var DirJDK, jdk_str: String;
       class_name: String;
  end;

var
  Form1: TForm1;
  st_lib, compil_prog, java_exe, java_exe_gui, pak_name, pak_dir, pak, fullFileName, FileName, Dirpro, pr_path: String;
  jshell, st_p, st_bin, jw, file_con_fx, file_con, Dirfile, os, vers, file_con_exe, file_con_exe_fx: String;
  list: TStringList;


implementation
 uses Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, fun_1;
{$R *.lfm}

{ TForm1 }

procedure TForm1.PrintStrings(Strings: TStrings);
var
Y, X, i : Integer;
begin

 if PrintDialog1.Execute then
  begin
   X := 100;
   Y := 100;
   Printer.Canvas.Font.Name := SynEdit1.Font.Name;
   Printer.Canvas.Font.Size := SynEdit1.Font.Size;
   Printer.Canvas.Font.Color := SynEdit1.Font.Color;
   Printer.BeginDoc;
   for i:=0 to Strings.Count-1 do begin
      Printer.Canvas.TextOut(X, Y, Strings[i]);
      Y := Y + Printer.Canvas.GetTextHeight(Strings[0]);
      if Y >= Printer.PageHeight then
            begin
              Y := 100;
              Printer.NewPage;
            end;
        end;
   Printer.EndDoc;
  end;

end;


procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
  SpeedButton2Click(Sender);
end;

procedure TForm1.MenuItem1Click(Sender: TObject);
begin
  SynEdit1.CutToClipboard;
end;

procedure TForm1.MenuItem21Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' for (int i = 0; i < 5; i++) {');
  SynEdit1.Lines.Insert(cur+1,'   System.out.println(i);');
  SynEdit1.Lines.Insert(cur+2,'  }');
end;

procedure TForm1.MenuItem26Click(Sender: TObject);
begin
  Form5.ShowModal;
end;

procedure TForm1.MenuItem27Click(Sender: TObject);
begin
  Form6.ShowModal;
end;

procedure TForm1.MenuItem29Click(Sender: TObject);
begin
  Stop();
end;

procedure TForm1.MenuItem2Click(Sender: TObject);
begin
  SynEdit1.CopyToClipboard;
end;

procedure TForm1.MenuItem30Click(Sender: TObject);
begin
  Convertcp1251toutf8();
end;

procedure TForm1.MenuItem31Click(Sender: TObject);
begin
   Stop();
end;

procedure TForm1.MenuItem32Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' int i = 0;');
  SynEdit1.Lines.Insert(cur+1,' while (i < 5) {');
  SynEdit1.Lines.Insert(cur+2,'   System.out.println(i);');
  SynEdit1.Lines.Insert(cur+3,'   i++;');
  SynEdit1.Lines.Insert(cur+4,' }');
end;

procedure TForm1.MenuItem35Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' int i = 0;');
  SynEdit1.Lines.Insert(cur+1,' do {');
  SynEdit1.Lines.Insert(cur+2,'   System.out.println(i);');
  SynEdit1.Lines.Insert(cur+3,'   i++;');
  SynEdit1.Lines.Insert(cur+4,' }');
  SynEdit1.Lines.Insert(cur+5,' while (i < 5);');
end;


procedure TForm1.MenuItem3Click(Sender: TObject);
begin
  SynEdit1.PasteFromClipboard;
end;

procedure TForm1.MenuItem41Click(Sender: TObject);
begin
  Form4.ShowModal();
end;

procedure TForm1.MenuItem43Click(Sender: TObject);
begin
  if (MenuItem43.Checked = true) then Panel2.Visible:=true
  else Panel2.Visible:=false;
end;

procedure TForm1.MenuItem44Click(Sender: TObject);
begin
  PrintStrings(SynEdit1.Lines);
end;


procedure TForm1.MenuItem45Click(Sender: TObject);
begin
  fun_1.shablon_fx();
end;



procedure TForm1.MenuItem47Click(Sender: TObject);
begin
 fun_1.shablon_applet();
end;

procedure TForm1.MenuItem48Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};');
  SynEdit1.Lines.Insert(cur+1,' for (String i : cars) {');
  SynEdit1.Lines.Insert(cur+2,'   System.out.println(i);');
  SynEdit1.Lines.Insert(cur+3,' }');
end;

procedure TForm1.MenuItem49Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' }try {');
  SynEdit1.Lines.Insert(cur+1,'          ');
  SynEdit1.Lines.Insert(cur+2,' } catch (Exception exc) {');
  SynEdit1.Lines.Insert(cur+3,'     exc.printStackTrace();');
  SynEdit1.Lines.Insert(cur+4,' }');
end;

procedure TForm1.MenuItem50Click(Sender: TObject);
var  javastr :String;
begin
  javastr:='';
  if os = 'linux' then javastr :=DirJDK+ st_bin + './' + jshell;
  if os = 'win' then
  begin
    if DirJDK = '' then javastr :=jshell
    else javastr :=DirJDK+ st_bin + jshell;
  end;
  Memo1.Clear;
  Memo1.Text:= javastr;
  ProcessUTF8_2.Executable:=javastr;
  ProcessUTF8_2.Execute;
end;

procedure TForm1.MenuItem51Click(Sender: TObject);
begin
  SynEdit1.Undo;
end;

procedure TForm1.MenuItem52Click(Sender: TObject);
begin
  SynEdit1.Redo;
end;

procedure TForm1.MenuItem61Click(Sender: TObject);
begin
 SynEdit1.ClearSelection;
end;

procedure TForm1.MenuItem62Click(Sender: TObject);
begin
  SynEdit1.SelectAll;
end;

procedure TForm1.MenuItem63Click(Sender: TObject);
begin
  Form7.ShowModal;
end;

procedure TForm1.MenuItem65Click(Sender: TObject);
var str: String;
begin
  ChDir(ExtractFileDir(fullFileName));
  list:=TStringList.Create();
  list.Add('Windows Registry Editor Version 5.00');
  list.Add('');
  list.Add('[HKEY_CLASSES_ROOT\.jar]');
  list.Add('@="jarfile"');
  list.Add('');
  list.Add('[HKEY_CLASSES_ROOT\jarfile]');
  list.Add('@="Executable Jar File"');
  list.Add('');
  list.Add('[HKEY_CLASSES_ROOT\jarfile\shell]');
  list.Add('');
  list.Add('[HKEY_CLASSES_ROOT\jarfile\shell\open]');
  list.Add('');
  list.Add('[HKEY_CLASSES_ROOT\jarfile\shell\open\command]');
  str:='@="\"' + fun_1.rep(DirJDK) + '\\bin\\javaw.exe\" -jar \"%1\" %*"';
  list.Add(str);
  list.SaveToFile('vav_jar_fix_0.reg');
  list.Destroy();
end;

procedure TForm1.MenuItem68Click(Sender: TObject);
var javastr, FileName  :String;
begin
 ChDir(Dirpro);
 ProcessUTF8_1.Parameters.Clear;
 FileName := 'SceneBuilder.exe';
 if FileExists(Dirpro + FileName) then
    begin
            javastr:=FileName;
            ProcessUTF8_1.Executable:='SceneBuilder.exe';
            Memo1.Clear;
            Memo1.Text:=javastr;
            ProcessUTF8_1.Execute;
     end
 else exit;

end;

procedure TForm1.MenuItem69Click(Sender: TObject);
var f_name:String;
begin
  SynExporterHTML1.Title:='File_export_html';
  SynExporterHTML1.ExportAll(SynEdit1.Lines);
  SaveDialog_html.InitialDir:=Dirfile;
  if (SaveDialog_html.Execute) then begin
    f_name:=SaveDialog_html.FileName;
  end;
  try
    SynExporterHTML1.SaveToFile(f_name);
  except
    ShowMessage('Ошибка при сохранении файла');
  end;

end;

procedure TForm1.MenuItem74Click(Sender: TObject);
var str: String;
    cur: Integer;
begin
  SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  str:='public class MyClass {';
  SynEdit1.Lines.Insert(cur,str);
  SynEdit1.Lines.Insert(cur+1,' ');
  SynEdit1.Lines.Insert(cur+2,' ');
  str:='  }';
  SynEdit1.Lines.Insert(cur+3,str);
end;

procedure TForm1.MenuItem75Click(Sender: TObject);
var str: String;
    cur: Integer;
begin
  SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  str:='public interface MyInterface {';
  SynEdit1.Lines.Insert(cur,str);
  SynEdit1.Lines.Insert(cur+1,' ');
  SynEdit1.Lines.Insert(cur+2,' ');
  str:='  }';
  SynEdit1.Lines.Insert(cur+3,str);
end;

procedure TForm1.MenuItem76Click(Sender: TObject);
var cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' public static void main(String args[]){');
  SynEdit1.Lines.Insert(cur+1,' ');
  SynEdit1.Lines.Insert(cur+2,' }');
end;

procedure TForm1.MenuItem77Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' if (x > y) {');
  SynEdit1.Lines.Insert(cur+1,'  System.out.println("x больше y");');
  SynEdit1.Lines.Insert(cur+2,' }');
end;

procedure TForm1.MenuItem78Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' int time = 20;');
  SynEdit1.Lines.Insert(cur+1,' if (time < 18) {');
  SynEdit1.Lines.Insert(cur+2,'  System.out.println("Хорошего дня.");');
  SynEdit1.Lines.Insert(cur+3,'  } else {');
  SynEdit1.Lines.Insert(cur+4,'  System.out.println("Хорошего вечера.");');
  SynEdit1.Lines.Insert(cur+5,' }');
end;

procedure TForm1.MenuItem79Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' int day = 4;');
  SynEdit1.Lines.Insert(cur+1,' switch (day) {');
  SynEdit1.Lines.Insert(cur+2,'  case 1:');
  SynEdit1.Lines.Insert(cur+3,'   System.out.println("Вторник");');
  SynEdit1.Lines.Insert(cur+4,'   break;');
  SynEdit1.Lines.Insert(cur+5,'  default:');
  SynEdit1.Lines.Insert(cur+6,'   System.out.println("День недели");');
  SynEdit1.Lines.Insert(cur+7,' }');
end;

procedure TForm1.MenuItem80Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.Strings[cur-1]:= SynEdit1.Lines.Strings[cur-1] + '{}';
end;

procedure TForm1.MenuItem81Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.Strings[cur-1]:= SynEdit1.Lines.Strings[cur-1] + '[]';
end;

procedure TForm1.MenuItem82Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.Strings[cur-1]:= SynEdit1.Lines.Strings[cur-1] + '()';
end;

procedure TForm1.MenuItem83Click(Sender: TObject);
var  cur: Integer;
begin
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(cur,' System.out.println();');
end;


procedure TForm1.MenuItem9Click(Sender: TObject);
begin
  close();
end;

procedure TForm1.SpeedButton10Click(Sender: TObject);
begin
  SpeedButton1Click(Sender);
  Delay(1000);
  SpeedButton12Click(Sender);

end;

procedure TForm1.SpeedButton11Click(Sender: TObject);
begin
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin

end;

procedure TForm1.SpeedButton13Click(Sender: TObject);
var  javastr :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ChDir(ExtractFileDir(fullFileName));
  FileName := ExtractFileName(fullFileName);
  ProcessUTF8_4.Parameters.Clear;
  javastr :=Form1.DirJDK+ st_bin + 'appletviewer';
  Form1.Caption:=javastr;
  ProcessUTF8_4.Executable:=javastr;
  ProcessUTF8_4.Parameters.Add(FileName);
  ProcessUTF8_4.Execute;
  Memo1.Clear;
  //memo1.Lines.LoadFromStream(ProcessUTF8_2.Output);
end;

procedure TForm1.SpeedButton14Click(Sender: TObject);
var javastr :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  SynEdit1.Lines.SaveToFile(fullFileName);
  ChDir(ExtractFileDir(fullFileName));
  FileName := ExtractFileName(fullFileName);
  ProcessUTF8_1.Parameters.Clear;
  javastr:=Form1.DirJDK+ st_bin + 'javac';
  Form1.Caption:=javastr;
  ProcessUTF8_1.Executable:=javastr;
  ProcessUTF8_1.Parameters.Add('-encoding');
  ProcessUTF8_1.Parameters.Add('utf8');
  ProcessUTF8_1.Parameters.Add(FileName);
  ProcessUTF8_1.Execute;
  Memo1.Clear;
  memo1.Lines.LoadFromStream(ProcessUTF8_1.Output);
end;

procedure TForm1.SpeedButton15Click(Sender: TObject);
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_2.Parameters.Clear;
  if os = 'win' then
  begin
   fun_1.console_cr_win_exe();
   //delay(1000);
   ProcessUTF8_2.Executable:=file_con_exe;
   ProcessUTF8_2.Execute;
  end;
end;

procedure TForm1.SpeedButton16Click(Sender: TObject);
begin
     if Form1.SynEdit1.Lines.Text = '' then exit;
     //ProcessUTF8_2.CommandLine:='';
     ProcessUTF8_2.Parameters.Clear;
     if os = 'win' then
        begin
             console_cr_win_fx_exe();
             //delay(1000);
             ProcessUTF8_2.Executable:=file_con_exe_fx;
             ProcessUTF8_2.Execute;
        end;
end;

procedure TForm1.SpeedButton18Click(Sender: TObject);
var str: String;
begin
   list := TStringList.Create;
                        memo1.Clear;
                    if FileExists(ExtractFileDir(pr_path) + st_p + 'first.java') then
                    begin
                       fullFileName := ExtractFileDir(pr_path) + st_p + 'first.java';
                        Dirfile:= ExtractFileDir(fullFileName) + st_p;
                        SynEdit1.Clear;
                        SynEdit1.Lines.LoadFromFile(fullFileName);
                    end
                  else
                  begin
                      ChDir(Dirpro);
                      list.Clear;
                        Form1.SynEdit1.Lines.Clear;
  str:='//Шаблон ';
  list.add(str);
  str:='import java.util.Scanner; ';
  list.add(str);
  str:='public class first {';
  list.add(str);
  str:='   public static void main(String[] args){';
  list.add(str);
  list.add('');
  str:='      //Ваш код ';
  list.add(str);
  list.add('      System.out.println("Шаблон программы!");');
  str:='      //Остановка закрытия окна ';
  list.add(str);
  str:='      Scanner s = new Scanner(System.in);';
  list.add(str);
  str:='      s.nextLine();';
  list.add(str);
  str:='   } ';
  list.add(str);
  str:='}';
  list.add(str);
  list.add('');
                      list.SaveToFile('first.java');
                      SynEdit1.Clear;
                      SynEdit1.Lines.LoadFromFile('first.java');
                      fullFileName := Dirpro  + st_p + 'first.java';
                      Dirfile:=Dirpro;
                   end;
                  memo1.Text:=FileName;
  list.Destroy;
  Form2.Caption:=fullFileName;
  Memo1.Text:=fullFileName;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
var javastr, FileExeName  :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_1.Parameters.Clear;
  ChDir(ExtractFileDir(fullFileName));
  FileName := ExtractFileName(fullFileName);
  FileExeName:=Copy(FileName,1,Length(FileName)-5);
  pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
      if pak <> '' then
         begin
              if  Form1.DirJDK<>'' then
                 begin
                  javastr:=Form1.DirJDK + st_bin + java_exe + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + pak + '.' + FileExeName;
                  ProcessUTF8_1.Executable:=Form1.DirJDK + st_bin + java_exe;
                 end
              else
              begin
                  javastr:=java_exe + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + pak + '.' + FileExeName;
                  ProcessUTF8_1.Executable:=java_exe;
              end;
              ProcessUTF8_1.Parameters.Add('-cp');
              ProcessUTF8_1.Parameters.Add(ExtractFileDir(fullFileName));
              ProcessUTF8_1.Parameters.Add(pak + '.' + FileExeName);
              Form1.Caption:=pak + '.' + FileExeName;
              Memo1.Clear;
              Memo1.Text:=javastr;
              ProcessUTF8_1.Execute;
         end
      else
          begin
            if  Form1.DirJDK<>'' then
               begin
                 javastr:=DirJDK + st_bin + java_exe + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + FileExeName;
                 ProcessUTF8_1.Executable:=Form1.DirJDK + st_bin + java_exe;
               end
            else
              begin
                 javastr:=java_exe + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + FileExeName;
                 ProcessUTF8_1.Executable:=java_exe;
              end;
             ProcessUTF8_1.Parameters.Add('-cp');
             ProcessUTF8_1.Parameters.Add(ExtractFileDir(fullFileName));
             ProcessUTF8_1.Parameters.Add(FileExeName);
             Memo1.Clear;
             Memo1.Text:=javastr;
             ProcessUTF8_1.Execute;
          end;

end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
var javastr :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  SynEdit1.Lines.SaveToFile(fullFileName);
  ChDir(ExtractFileDir(fullFileName));
  //FileName := ExtractFileName(fullFileName);
  ProcessUTF8_1.Parameters.Clear;
  Form1.Caption:=fullFileName;
  pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
  if pak <> '' then
   begin
      javastr:=DirJDK + st_bin + compil_prog + ' -d ./ -encoding utf8 ' + fullFileName;
      ProcessUTF8_1.Executable:=DirJDK + st_bin + compil_prog;
      ProcessUTF8_1.Parameters.Add('-d');
      ProcessUTF8_1.Parameters.Add('./');
      ProcessUTF8_1.Parameters.Add('-encoding');
      ProcessUTF8_1.Parameters.Add('utf8');
      ProcessUTF8_1.Parameters.Add(fullFileName);
      //ProcessUTF8_1.CommandLine:=javastr;
      Memo1.Clear;
      Memo1.Text:=javastr;
      ProcessUTF8_1.Execute;

   end
  else
   begin
      javastr:=DirJDK+ st_bin + compil_prog + ' -encoding utf8 ' + fullFileName;
      ProcessUTF8_1.Executable:=DirJDK + st_bin + compil_prog;
      ProcessUTF8_1.Parameters.Add('-encoding');
      ProcessUTF8_1.Parameters.Add('utf8');
      ProcessUTF8_1.Parameters.Add(fullFileName);
     //ProcessUTF8_1.CommandLine:=javastr;
      Memo1.Clear;
      Memo1.Text:=javastr;
      ProcessUTF8_1.Execute;
   end;
   ProcessUTF8_1.WaitOnExit;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  if os = 'win' then fun_1.jar_win();
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
   fullFileName := OpenDialog1.FileName;
   Form1.Caption:=fullFileName;
   SynEdit1.Lines.LoadFromFile(fullFileName);
  end;
  Dirfile:= ExtractFileDir(fullFileName) + st_p;
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
var sss, javastr :String;
    i:  integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ChDir(ExtractFileDir(fullFileName));
  FileName := ExtractFileName(fullFileName);
  //ProcessUTF8_4.CommandLine:='';
  ProcessUTF8_4.Parameters.Clear;
  i:= Length(FileName);
  sss:=Copy(FileName,1,i-5);
  if  Form1.DirJDK <> '' then
  begin
      javastr :=Form1.DirJDK+ st_bin + jw + ' -jar ' + ExtractFileDir(fullFileName) + '\' + sss +'.jar';
      Form1.Caption:=sss +'.jar';
      Memo1.Clear;
      Memo1.Text:= javastr;
      ProcessUTF8_4.Executable:=Form1.DirJDK+ st_bin + jw;
  end
  else
  begin
      javastr :=jw + ' -jar ' + ExtractFileDir(fullFileName) + '\' + sss +'.jar';
      Form1.Caption:=sss +'.jar';
      Memo1.Clear;
      Memo1.Text:= javastr;
      ProcessUTF8_4.Executable:=jw;
  end;

  ProcessUTF8_4.Parameters.Add('-jar');
  ProcessUTF8_4.Parameters.Add(ExtractFileDir(fullFileName) + '\' + sss +'.jar');
  ProcessUTF8_4.Execute;
end;

procedure TForm1.SpeedButton6Click(Sender: TObject);
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  SpeedButton2Click(Self);
  SpeedButton1Click(Self);
end;

procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
  if fullFileName='' then
  begin
   if SaveDialog1.Execute then fullFileName:=SaveDialog1.FileName;
  end;
 if fullFileName <>'' then
 begin
    class_name:= ReadClassName(SynEdit1);
 if class_name<>'' then
     begin
      SaveDialog1.FileName:= class_name + '.java';
       Form1.Caption:=class_name;
     end;
  if SaveDialog1.Execute then
   begin
      fullFileName:=SaveDialog1.FileName;
      SynEdit1.Lines.SaveToFile(fullFileName);
   end;
 end;
 Memo1.Text:=fullFileName;
 Form2.Caption:=fullFileName;
end;

procedure TForm1.SpeedButton8Click(Sender: TObject);
begin
 Form3.ShowModal;
end;


procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Form2.ShowModal;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_2.Parameters.Clear;
  //ProcessUTF8_2.CommandLine:='';
if os = 'win' then
  begin
   fun_1.console_cr_win();
   //delay(1000);
   ProcessUTF8_2.Executable:=file_con;
   ProcessUTF8_2.Execute;
  end;




end;




procedure TForm1.Stop();
var str: String;
    cur: Integer;
begin
  str:='import java.util.Scanner;';
  SynEdit1.Lines.add('');
  SynEdit1.Lines.Insert(0,str);
  cur := SynEdit1.CaretY;
  str:='    //остановка закрытия окна';
  SynEdit1.Lines.Insert(cur+1,str);
  str:='    Scanner s = new Scanner(System.in);';
  SynEdit1.Lines.Insert(cur+2,str);
  str:='    s.nextLine();';
  SynEdit1.Lines.Insert(cur+3,str);
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
if Form1.SynEdit1.Lines.Text = '' then exit;
ProcessUTF8_2.Parameters.Clear;
//ProcessUTF8_2.CommandLine:='';
if os = 'win' then
  begin
   fun_1.console_cr_fx_win();
   //delay(1000);
   ProcessUTF8_2.Executable:=file_con_fx;
   ProcessUTF8_2.Execute;
  end;
end;

procedure TForm1.Convertcp1251toutf8();
begin
     SynEdit1.Text := CP1251ToUTF8(SynEdit1.Text);
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
  class_name:= ReadClassName(SynEdit1);
 if class_name<>'' then
     begin
      SaveDialog1.FileName:= class_name + '.java';
       Form1.Caption:=class_name;
     end;
  if SaveDialog1.Execute then
   begin
      fullFileName:=SaveDialog1.FileName;
      SynEdit1.Lines.SaveToFile(fullFileName);
   end;
end;

procedure TForm1.BitBtn6Click(Sender: TObject);
var javastr, FileExeName  :String;
begin
 if Form1.SynEdit1.Lines.Text = '' then exit;
 ChDir(ExtractFileDir(fullFileName));
 ProcessUTF8_1.Parameters.Clear;
 FileName := ExtractFileName(fullFileName);
 FileExeName:=Copy(FileName,1,Length(FileName)-5);
 pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
     if pak <> '' then
        begin
               if DirJDK <> '' then
               begin
                 javastr:=DirJDK + st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + pak + '.' + FileExeName;
                 ProcessUTF8_1.Executable:=Form1.DirJDK + st_bin + java_exe_gui;
               end
               else
               begin
                 javastr:=java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + pak + '.' + FileExeName;
                 ProcessUTF8_1.Executable:=java_exe_gui;
               end;
              ProcessUTF8_1.Parameters.Add('-cp');
              ProcessUTF8_1.Parameters.Add(ExtractFileDir(fullFileName));
             ProcessUTF8_1.Parameters.Add(pak + '.' + FileExeName);
             Form1.Caption:=pak + '.' + FileExeName;
             Memo1.Clear;
             Memo1.Text:=javastr;
             ProcessUTF8_1.Execute;
        end
     else
         begin
            if DirJDK <> '' then
               begin
                javastr:=DirJDK + st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + FileExeName;
                ProcessUTF8_1.Executable:=Form1.DirJDK + st_bin + java_exe_gui;
               end
            else
             begin
                javastr:=java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + FileExeName;
                ProcessUTF8_1.Executable:=java_exe_gui;
             end;
            ProcessUTF8_1.Parameters.Add('-cp');
            ProcessUTF8_1.Parameters.Add(ExtractFileDir(fullFileName));
            ProcessUTF8_1.Parameters.Add(FileExeName);
            Memo1.Clear;
            Memo1.Text:=javastr;
            ProcessUTF8_1.Execute;
         end;
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
var pak, javastr,FileExeName :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  SynEdit1.Lines.SaveToFile(fullFileName);
  ChDir(ExtractFileDir(fullFileName));
  ProcessUTF8_1.Parameters.Clear;
  FileName := ExtractFileName(fullFileName);
  FileExeName:=Copy(FileName,1,Length(FileName)-5);
  Form1.Caption:=FileExeName;
  pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
  if pak <> '' then
   begin
        javastr:=DirJDK+ st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' --module-path ' + Form1.DirJDK + st_lib + ' --add-modules ' + 'javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web ' + ' ' + pak + '.' + FileExeName;
        ProcessUTF8_1.Executable:=Form1.DirJDK+ st_bin + java_exe_gui;
        ProcessUTF8_1.Parameters.Add('-cp');
        ProcessUTF8_1.Parameters.Add(ExtractFileDir(fullFileName));;
        ProcessUTF8_1.Parameters.Add('--module-path');
        ProcessUTF8_1.Parameters.Add(Form1.DirJDK + st_lib);
        ProcessUTF8_1.Parameters.Add('--add-modules');
        ProcessUTF8_1.Parameters.Add('javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web');
        ProcessUTF8_1.Parameters.Add(pak + '.' + FileExeName);
        ProcessUTF8_1.Execute;
        Memo1.Clear;
        memo1.Text:= javastr;
   end
    else
   begin
        javastr:=Form1.DirJDK+ st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' --module-path ' + Form1.DirJDK + st_lib + ' --add-modules ' + 'javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web ' + ' ' + FileExeName;
        ProcessUTF8_1.Executable:=Form1.DirJDK+ st_bin + java_exe_gui;
        ProcessUTF8_1.Parameters.Add('-cp');
        ProcessUTF8_1.Parameters.Add(ExtractFileDir(fullFileName));;
        ProcessUTF8_1.Parameters.Add('--module-path');
        ProcessUTF8_1.Parameters.Add(Form1.DirJDK + st_lib);
        ProcessUTF8_1.Parameters.Add('--add-modules');
        ProcessUTF8_1.Parameters.Add('javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web');
        ProcessUTF8_1.Parameters.Add(FileExeName);
        ProcessUTF8_1.Execute;
        Memo1.Clear;
        memo1.Text:= javastr;
   end;

end;

procedure TForm1.BitBtn8Click(Sender: TObject);
var pak, javastr :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  SynEdit1.Lines.SaveToFile(fullFileName);
  ChDir(ExtractFileDir(fullFileName));
  ProcessUTF8_1.Parameters.Clear;
  FileName := ExtractFileName(fullFileName);
  Form1.Caption:=fullFileName;
  pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
  if pak <> '' then
   begin
        javastr:=DirJDK+ st_bin + compil_prog + ' -d ./ -encoding utf8  --module-path ' + Form1.DirJDK + st_lib + ' --add-modules ' + 'javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web ' + fullFileName;
        ProcessUTF8_1.Executable:=DirJDK+ st_bin + compil_prog;
        ProcessUTF8_1.Parameters.Add('-d');
        ProcessUTF8_1.Parameters.Add('./');
        ProcessUTF8_1.Parameters.Add('-encoding');
        ProcessUTF8_1.Parameters.Add('utf8');
        ProcessUTF8_1.Parameters.Add('--module-path');
        ProcessUTF8_1.Parameters.Add(Form1.DirJDK + st_lib);
        ProcessUTF8_1.Parameters.Add('--add-modules');
        ProcessUTF8_1.Parameters.Add('javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web');
        ProcessUTF8_1.Parameters.Add(fullFileName);
        ProcessUTF8_1.Execute;
        Memo1.Clear;
        memo1.Text:= javastr;
   end
    else
   begin
        javastr:=Form1.DirJDK+ st_bin + compil_prog + ' -encoding utf8  --module-path ' + Form1.DirJDK + st_lib + ' --add-modules ' + 'javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web ' + fullFileName;
        ProcessUTF8_1.Executable:=DirJDK+ st_bin + compil_prog;
        ProcessUTF8_1.Parameters.Add('-encoding');
        ProcessUTF8_1.Parameters.Add('utf8');
        ProcessUTF8_1.Parameters.Add('--module-path');
        ProcessUTF8_1.Parameters.Add(Form1.DirJDK + st_lib);
        ProcessUTF8_1.Parameters.Add('--add-modules');
        ProcessUTF8_1.Parameters.Add('javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web');
        ProcessUTF8_1.Parameters.Add(fullFileName);

        Form1.Caption:=ProcessUTF8_1.Parameters.Text;

        ProcessUTF8_1.Execute;
        Memo1.Clear;
        memo1.Text:= javastr;
   end;
   ProcessUTF8_1.WaitOnExit;
end;




procedure TForm1.Button2Click(Sender: TObject);
begin
  SynEdit1.Font.Size:=SynEdit1.Font.Size + 1;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
   SynEdit1.Font.Size:=SynEdit1.Font.Size - 1;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Form1.FocusControl(SynEdit1);
end;






procedure TForm1.FormCreate(Sender: TObject);
begin

  os := 'win';

  if os = 'linux' then st_p   := '/';
  if os = 'win' then st_p   := '\';

  if os = 'linux' then st_bin := '/bin/';
  if os = 'win' then st_bin := '\bin\';

  if os = 'linux' then st_lib := '/lib';
  if os = 'win' then st_lib := '\lib';

  if os = 'linux' then jw := 'java ';
  if os = 'win' then jw := 'javaw ';

  if os = 'linux' then file_con_fx := '0_compile_run_fx.sh';
  if os = 'win' then file_con_fx := '0_compile_run_fx.bat';

  if os = 'linux' then file_con  := '0_compile_run.sh';
  if os = 'win' then file_con  := '0_compile_run.bat';

  if os = 'linux' then file_con_exe  := '0_run.sh';
  if os = 'win' then file_con_exe  := '0_run.bat';

  if os = 'linux' then file_con_exe_fx  := '0_run_fx.sh';
  if os = 'win' then file_con_exe_fx  := '0_run_fx.bat';


  if os = 'linux' then jshell  := 'jshell';
  if os = 'win' then jshell  := 'jshell.exe';

  compil_prog:= 'javac';
  pak_name:= '';
  pak_dir:= '';
  java_exe:='java';
  java_exe_gui:='javaw';
  jdk_str:='';
  list := TStringList.Create;

                  pr_path:= ParamStr(0);
                  fullFileName:=ParamStr(1);
                  Dirpro:= ExtractFileDir(pr_path) + st_p;
                  Dirfile:= ExtractFileDir(fullFileName) + st_p;

                  SynEdit1.Clear;
                  if fullFileName<> '' then SynEdit1.Lines.LoadFromFile(fullFileName);



		  if FileExists(Dirpro + 'jdk.ini') then
                  begin
					list.LoadFromFile(Dirpro + 'jdk.ini');
                                        jdk_str := list.Strings[0];
                                        if jdk_str = '' then DirJDK := ''
                                        else
                                          if jdk_str = 'runtime' then DirJDK := ExtractFileDir(pr_path) + st_p + 'runtime'
                                          else DirJDK := jdk_str;

		 end
		 else   DirJDK := '';



 if FileExists(Dirpro + 'key_java.ini') then SynCompletion1.ItemList.LoadFromFile(Dirpro + st_p + 'key_java.ini');
 vers :='Версия редактора : 1.9.76-p-win-mini-fx  ';
 Label1.Caption :=  vers;
 SynEdit1.TabWidth:=4;
 Form1.Caption:= Dirpro;
 list.Destroy;
end;

procedure TForm1.MenuItem10Click(Sender: TObject);
begin
 fun_1.shablon_console();
end;

procedure TForm1.MenuItem11Click(Sender: TObject);
begin
  fun_1.shablon_swing();
end;

procedure TForm1.MenuItem17Click(Sender: TObject);
begin

end;

procedure TForm1.MenuItem19Click(Sender: TObject);
begin
  Convertcp1251toutf8();
end;

end.

