unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,fileutil,
  ExtCtrls, Buttons, SynHighlighterJava, SynEdit,
  SynCompletion, SynHighlighterAny, SynHighlighterCpp, SynExportHTML, LCLType,
  LConvEncoding, UTF8Process, Crt, Process, LazUTF8, ComCtrls, {$ifdef LINUX}gtk2, gdk2, Clipbrd{$endif};

type

  { TForm1 }

  TForm1 = class(TForm)
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    Button2: TButton;
    Button3: TButton;
    ImageList1: TImageList;
    ImageList3: TImageList;
    ImageList2: TImageList;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    MenuItem1: TMenuItem;
    MenuItem10: TMenuItem;
    MenuItem100: 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;
    MenuItem46: TMenuItem;
    MenuItem47: 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;
    MenuItem87: TMenuItem;
    MenuItem88: TMenuItem;
    MenuItem89: TMenuItem;
    MenuItem9: TMenuItem;
    MenuItem90: TMenuItem;
    MenuItem91: TMenuItem;
    MenuItem92: TMenuItem;
    MenuItem93: TMenuItem;
    MenuItem94: TMenuItem;
    MenuItem95: TMenuItem;
    MenuItem96: TMenuItem;
    MenuItem97: TMenuItem;
    MenuItem98: TMenuItem;
    MenuItem99: TMenuItem;
    OpenDialog1: TOpenDialog;
    PageControl1: TPageControl;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    PopupMenu1: TPopupMenu;
    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;
    Separator2: TMenuItem;
    Separator3: TMenuItem;
    Separator4: TMenuItem;
    Separator5: TMenuItem;
    Separator6: TMenuItem;
    Separator7: TMenuItem;
    Separator8: TMenuItem;
    Separator9: TMenuItem;
    SpeedButton1: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton19: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    Splitter1: TSplitter;
    Splitter2: TSplitter;
    SynCompletion1: TSynCompletion;
    SynEdit1: TSynEdit;
    SynExporterHTML1: TSynExporterHTML;
    SynJavaSyn1: TSynJavaSyn;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(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 FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure MenuItem100Click(Sender: TObject);
    procedure MenuItem10Click(Sender: TObject);
    procedure MenuItem11Click(Sender: TObject);
    procedure MenuItem17Click(Sender: TObject);
    procedure MenuItem19Click(Sender: TObject);
    procedure MenuItem1Click(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 MenuItem38Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure MenuItem41Click(Sender: TObject);
    procedure MenuItem43Click(Sender: TObject);
    procedure MenuItem44Click(Sender: TObject);
    procedure MenuItem45Click(Sender: TObject);
    procedure MenuItem46Click(Sender: TObject);
    procedure MenuItem47Click(Sender: TObject);
    procedure MenuItem4Click(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 MenuItem74Click(Sender: TObject);
    procedure MenuItem75Click(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 MenuItem84Click(Sender: TObject);
    procedure MenuItem85Click(Sender: TObject);
    procedure MenuItem86Click(Sender: TObject);
    procedure MenuItem87Click(Sender: TObject);
    procedure MenuItem88Click(Sender: TObject);
    procedure MenuItem89Click(Sender: TObject);
    procedure MenuItem90Click(Sender: TObject);
    procedure MenuItem91Click(Sender: TObject);
    procedure MenuItem92Click(Sender: TObject);
    procedure MenuItem93Click(Sender: TObject);
    procedure MenuItem94Click(Sender: TObject);
    procedure MenuItem95Click(Sender: TObject);
    procedure MenuItem96Click(Sender: TObject);
    procedure MenuItem97Click(Sender: TObject);
    procedure MenuItem98Click(Sender: TObject);
    procedure MenuItem99Click(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 SpeedButton17Click(Sender: TObject);
    procedure SpeedButton18Click(Sender: TObject);
    procedure SpeedButton19Click(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 console_cr_fx();
  private

  public

  end;

var
  Form1: TForm1;
  pak, file_run, jshell, fullFileName, FileName, Dirpro, DirJDK, DirJDK8, DirFX, pr_path: String;
  param, file_run_fx, st_p, st_bin, st_lib, jw, file_con_fx, file_con, Dirfile, os, vers: String;
  compil_prog, pak_name, pak_dir, java_exe, java_exe_gui: String;
  list: TStringList;
  file_con_run, terminal:String;

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

{ TForm1 }



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

procedure TForm1.MenuItem1Click(Sender: TObject);
begin
  SynEdit1.CutToClipboard;
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.MenuItem38Click(Sender: TObject);
begin

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
  if (MenuItem44.Checked = true) then Panel4.Visible:=true
  else Panel4.Visible:=false;
  SpeedButton12Click(Sender);
end;

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

procedure TForm1.MenuItem46Click(Sender: TObject);
begin
  shablon.input_output();
  Panel4.Visible:=true;
  MenuItem44.Checked:=true;
end;

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

procedure TForm1.MenuItem4Click(Sender: TObject);
begin

end;

procedure TForm1.MenuItem50Click(Sender: TObject);
var  javastr :String;
begin

  if os = 'linux' then javastr :=DirJDK+ st_bin + './' + jshell;
  if os = 'win' then javastr :=DirJDK+ st_bin + jshell;

  Form1.Caption:=javastr;
  ProcessUTF8_2.CommandLine:=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.MenuItem74Click(Sender: TObject);
var str: String;
begin
   list := TStringList.Create;
                        memo1.Clear;
                    if FileExists(ExtractFileDir(pr_path) + st_p + 'PJ-mini.desktop') then
                    begin
                       Exit;
                    end
                  else
                  begin
                      ChDir(Dirpro);
                      list.Clear;
                        Form1.SynEdit1.Lines.Clear;


str:='[Desktop Entry]';
list.add(str);
str:='Name=PJ-mini';
list.add(str);
str:='Name[ru]=PJ-mini';
list.add(str);
str:='Type=Application';
list.add(str);
str:='NoDisplay=false';
list.add(str);
str:='Exec=' + ExtractFileDir(pr_path) + st_p + 'PJ-mini';
list.add(str);
str:='Icon=' + ExtractFileDir(pr_path) + st_p + 'PJ.png';
list.add(str);
str:='Icon[ru]=' + ExtractFileDir(pr_path) + st_p + 'PJ.png';
list.add(str);
str:='Hidden=false';
list.add(str);
str:='Path=' + ExtractFileDir(pr_path) + st_p;
list.add(str);
str:='Terminal=false';
list.add(str);
str:='StartupNotify=false';
list.add(str);
str:='Categories=Application;Development';
list.add(str);

                      list.SaveToFile('PJ-mini.desktop');
                   end;
  list.Destroy;


end;

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

procedure TForm1.MenuItem77Click(Sender: TObject);
var str, main_class: String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
   list := TStringList.Create;
   ChDir(ExtractFileDir(fullFileName));
   list.Clear;
   FileName := ExtractFileName(fullFileName);
   main_class:=Copy(FileName,1,Length(FileName)-5);
  str:=DirJDK;
  list.add(str);
  pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
  if pak <> '' then
      begin
          str := pak + '.' + main_class;
      end
   else
       begin
          str := main_class;

   end;
  list.add(str);
  list.add('');
  list.add('');
  list.add('');
  list.add('#################################################');
  list.add('');
  list.add('1 - path jdk/jre');
  list.add('2 - main class');
  list.add('');
  list.add('################################################# ');
  list.SaveToFile('init.ini');
  list.Destroy;

end;

procedure TForm1.MenuItem78Click(Sender: TObject);
var fn_1, fn_2 : String;
    ok: boolean;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  fn_1:= Dirpro + '/Запуск0';
  fn_2:= ExtractFileDir(fullFileName) + '/Запуск';
  CopyFile(fn_1,fn_2);
  ChDir(ExtractFileDir(fullFileName));
  Form1.ProcessUTF8_4.Parameters.Clear;
  Form1.ProcessUTF8_4.CommandLine:='';
  Form1.ProcessUTF8_4.CommandLine:='chmod 777 Запуск';
  Form1.ProcessUTF8_4.Execute;
end;

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

procedure TForm1.MenuItem80Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := 0;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'import java.util.Scanner;');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');
end;

procedure TForm1.MenuItem81Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'    Scanner s = new Scanner(System.in);');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem82Click(Sender: TObject);
var cur: Integer;
begin
    if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'public class first{  }');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem83Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'    System.out.println("Шаблон программы!");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem84Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'// Сумма двух целых чисел ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'  ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'import java.util.Scanner;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'public class Sum {');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    public static void main(String[] args) {');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'        Scanner in = new Scanner(System.in);');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'        int a = in.nextInt(); ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'        int b = in.nextInt();');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'        System.out.println("" + (a+b));');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    }');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'}');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
end;

procedure TForm1.MenuItem85Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int num1 = 6;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int num2 = 4;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'if(num1>num2){');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("Первое число больше второго");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'}');
end;

procedure TForm1.MenuItem86Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int num1 = 6;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int num2 = 4;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'if(num1>num2){');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("Первое число больше второго");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'}');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'else{ ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("Первое число меньше второго");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'} ');
end;

procedure TForm1.MenuItem87Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int num1 = 6;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int num2 = 8;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'if(num1>num2){');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("Первое число больше второго");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'}');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'else if(num1<num2){ ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("Первое число меньше второго");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'} ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'else{  ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("Числа равны"); ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'} ');
end;

procedure TForm1.MenuItem88Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int num = 8;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int num2 = 8;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'switch(num){');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'case 1: ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("число равно 1"); ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    break;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'case 8:');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("число равно 8");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    num++; ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    break; ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'case 9: ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("число равно 9");');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    break; ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'default: ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println("число не равно 1, 8, 9"); ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'} ');





end;

procedure TForm1.MenuItem89Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int num = 8;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'for (int i = 1; i < 9; i++){ ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.printf("Квадрат числа %d равен %d \n", i, i * i); ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'} ');
end;

procedure TForm1.MenuItem90Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int j = 7;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'while (j > 0){ ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,' ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println(j);');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    j--; ');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'} ');
end;

procedure TForm1.MenuItem91Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
    cur := SynEdit1.CaretY;
    SynEdit1.Lines.add('');
    SynEdit1.Lines.Insert(cur,'int j = 7;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'do{');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    System.out.println(j);');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'    j--;');
    cur:= cur + 1; SynEdit1.Lines.Insert(cur,'}while (j > 0);');
end;

procedure TForm1.MenuItem92Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int[] nums2 = new int[5];   // массив из 5 чисел');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem93Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int[] nums = new int[] { 1, 2, 3, 5 }; ');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem94Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'int[][][] nums3 = new int[2][3][4]; //Объявление трехмерного массива ');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem95Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := 0;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'import java.util.ArrayList;');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');

end;

procedure TForm1.MenuItem96Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'ArrayList<String> people = new ArrayList<String>();');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'  // добавим в список ряд элементов');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'  people.add("Tom");');

end;

procedure TForm1.MenuItem97Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'StringBuffer strBuffer = new StringBuffer("hello");');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'  // Метод append() добавляет подстроку в конец StringBuffer');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'  strBuffer.append(" world");');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'  System.out.println(strBuffer.toString()); // hello world');

end;

procedure TForm1.MenuItem98Click(Sender: TObject);
var str: String;
begin

  if FileExists(ExtractFileDir(pr_path) + st_p + 'Java-CheatSheet_Edureka1.pdf') then
    begin
      str:='Java-CheatSheet_Edureka1.pdf';
      ChDir(ExtractFileDir(pr_path));
      ProcessUTF8_4.CommandLine:='';
      ProcessUTF8_4.Parameters.Clear;
      ProcessUTF8_4.Executable:='chromium-browser';
      ProcessUTF8_4.Parameters.Add(str);
      Memo1.Clear;
      Memo1.Text:= str;
      ProcessUTF8_4.Execute;
    end;
end;

procedure TForm1.MenuItem99Click(Sender: TObject);
var cur: Integer;
begin
  if Form1.SynEdit1.Lines.Text = '' then SynEdit1.Lines.add('');
  cur := SynEdit1.CaretY;
  SynEdit1.Lines.add('');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'/*');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'   ');
  cur:= cur + 1; SynEdit1.Lines.Insert(cur,'*/');
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
  Memo2.Lines.SaveToFile(Dirfile + 'input.txt');
  Memo3.Lines.SaveToFile(Dirfile + 'output.txt');
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
    Memo3.Lines.Clear;
    Memo2.Lines.Clear;
    if FileExists(Dirfile + 'output.txt') then Memo3.Lines.LoadFromFile(Dirfile + 'output.txt');
    if FileExists(Dirfile + 'input.txt') then Memo2.Lines.LoadFromFile(Dirfile + 'input.txt');
end;

procedure TForm1.SpeedButton13Click(Sender: TObject);
var  javastr :String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ChDir(ExtractFileDir(fullFileName));
  FileName := ExtractFileName(fullFileName);
  javastr :=DirJDK+ st_bin + 'appletviewer ' + FileName;
  //Form1.Caption:=javastr;
  ProcessUTF8_4.CommandLine:=javastr;
  ProcessUTF8_4.Execute;
  Memo1.Clear;
  Memo1.Text:= javastr;
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);

  javastr:=DirJDK8+ st_bin + 'javac -encoding utf8 ' + FileName;
  Form1.Caption:=javastr;
  ProcessUTF8_1.CommandLine:=javastr;
  ProcessUTF8_1.Execute;
  Memo1.Clear;
  memo1.Lines.LoadFromStream(ProcessUTF8_1.Output);
end;

procedure TForm1.SpeedButton15Click(Sender: TObject);
var comand, sss, FileExeName: String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_4.Parameters.Clear;
  ProcessUTF8_2.CommandLine:='';

if os = 'linux' then
  begin


    Form1.SynEdit1.Lines.SaveToFile(fullFileName);
    ChDir(ExtractFileDir(fullFileName));
    FileName := ExtractFileName(fullFileName);
    FileExeName:=Copy(FileName,1,Length(FileName)-5);

    pak:= Name_Package(Form1.SynEdit1.Lines.Strings[Find_Package(Form1.SynEdit1)]);
       param :='';
       if pak <> '' then
          begin
               FileExeName:=pak + '.' + FileExeName;
               param :='-d ./';
          end
       else
           begin
                FileExeName:= FileExeName;
           end;



    fun_lin.console_cr_run_linux(FileExeName);
    Memo1.Clear;
    Memo1.Text:=FileExeName;
    Form1.ProcessUTF8_4.CommandLine:='chmod 777 ' + file_run;
    Form1.ProcessUTF8_4.Execute;
    Form1.ProcessUTF8_4.WaitOnExit;
    sss:=GetCurrentDir();
    comand:= '"' + sss + '"' + '/' + file_run;
    Memo1.Text:= comand;
   ProcessUTF8_2.CommandLine:=comand;
   ProcessUTF8_2.Execute;
  end;

end;

procedure TForm1.SpeedButton16Click(Sender: TObject);
var comand, sss: String;
begin
if Form1.SynEdit1.Lines.Text = '' then exit;
ProcessUTF8_4.Parameters.Clear;
ProcessUTF8_2.CommandLine:='';
if os = 'linux' then
 begin
  fun_lin.console_run_fx_linux();
   Form1.ProcessUTF8_4.CommandLine:='chmod 777 ' + file_run_fx;
   Form1.ProcessUTF8_4.Execute;
   Form1.ProcessUTF8_4.WaitOnExit;
   sss:=GetCurrentDir();
    comand:= '"' + sss + '"' + '/' + file_run_fx;
    Memo1.Text:= comand;
  ProcessUTF8_2.CommandLine:=comand;
  ProcessUTF8_2.Execute;
 end;

if os = 'win' then
 begin
 end
end;

procedure TForm1.SpeedButton17Click(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;

end;

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

procedure TForm1.SpeedButton19Click(Sender: TObject);
var str, main_class: String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
   list := TStringList.Create;
   ChDir(ExtractFileDir(fullFileName));
   list.Clear;
   FileName := ExtractFileName(fullFileName);
   main_class:=Copy(FileName,1,Length(FileName)-5);
  str:='Manifest-Version: 1.0';
  list.add(str);
  pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
  if pak <> '' then
      begin
          str:='main-class: ' + pak + '.' + main_class;
      end
   else
       begin
          str:='main-class: ' + main_class;

   end;
  list.add(str);
  CreateDir('META-INF');
  ChDir('META-INF');
  list.SaveToFile('MANIFEST.MF');
  list.Destroy;

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
              javastr:=DirJDK + st_bin + java_exe + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + pak + '.' + FileExeName;
              ProcessUTF8_1.Executable:=DirJDK + st_bin + java_exe;
              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
             javastr:=DirJDK + st_bin + java_exe + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + FileExeName;
             ProcessUTF8_1.Executable:=DirJDK + st_bin + java_exe;
             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 = 'linux' then fun_lin.jar_linux();
  if os = 'win' then fun_win.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);
  javastr :=DirJDK+ st_bin + java_exe_gui + ' -jar ' + ExtractFileDir(fullFileName) + st_p + sss +'.jar';
  Form1.Caption:=sss +'.jar';
  Memo1.Clear;
  Memo1.Text:= javastr;
  ProcessUTF8_4.Executable:=DirJDK+ st_bin + java_exe_gui;
  ProcessUTF8_4.Parameters.Add('-jar');
  ProcessUTF8_4.Parameters.Add(ExtractFileDir(fullFileName) + st_p + 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;
 SynEdit1.Lines.SaveToFile(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);
var comand, sss, FileExeName: String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_4.Parameters.Clear;
  ProcessUTF8_2.CommandLine:='';

if os = 'linux' then
  begin


    Form1.SynEdit1.Lines.SaveToFile(fullFileName);
    ChDir(ExtractFileDir(fullFileName));
    FileName := ExtractFileName(fullFileName);
    FileExeName:=Copy(FileName,1,Length(FileName)-5);

    pak:= Name_Package(Form1.SynEdit1.Lines.Strings[Find_Package(Form1.SynEdit1)]);
       param :='';
       if pak <> '' then
          begin
               FileExeName:=pak + '.' + FileExeName;
               param :='-d ./';
          end
       else
           begin
                FileExeName:= FileExeName;
           end;



    fun_lin.console_cr_linux(FileName, FileExeName, param);
    Memo1.Clear;
    Memo1.Text:=FileExeName;
    Form1.ProcessUTF8_4.CommandLine:='chmod 777 ' + file_con;
    Form1.ProcessUTF8_4.Execute;
    Form1.ProcessUTF8_4.WaitOnExit;
    sss:=GetCurrentDir();
    comand:= '"' + sss + '"' + '/' + file_con;
    Memo1.Text:= comand;
   ProcessUTF8_2.CommandLine:=comand;
   ProcessUTF8_2.Execute;
  end;

end;



procedure TForm1.console_cr_fx();
begin

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);
var sss, comand: String;
begin
 if Form1.SynEdit1.Lines.Text = '' then exit;
 ProcessUTF8_4.Parameters.Clear;
 ProcessUTF8_2.CommandLine:='';
if os = 'linux' then
  begin
   fun_lin.console_cr_fx_linux();
   Form1.ProcessUTF8_4.CommandLine:='chmod 777 ' + file_con_fx;
    Form1.ProcessUTF8_4.Execute;
    Form1.ProcessUTF8_4.WaitOnExit;
    sss:=GetCurrentDir();
    comand:= '"' + sss + '"' + '/' + file_con_fx;
    Memo1.Text:= comand;
   ProcessUTF8_2.CommandLine:=comand;
   ProcessUTF8_2.Execute;
  end;
if os = 'win' then
  begin
  end;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
var comand, sss, FileExeName: String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_4.Parameters.Clear;
  ProcessUTF8_2.CommandLine:='';

if os = 'linux' then
  begin


    Form1.SynEdit1.Lines.SaveToFile(fullFileName);
    ChDir(ExtractFileDir(fullFileName));
    FileName := ExtractFileName(fullFileName);
    FileExeName:=Copy(FileName,1,Length(FileName)-5);

    pak:= Name_Package(Form1.SynEdit1.Lines.Strings[Find_Package(Form1.SynEdit1)]);
       param :='';
       if pak <> '' then
          begin
               FileExeName:=pak + '.' + FileExeName;
               param :='-d ./';
          end
       else
           begin
                FileExeName:= FileExeName;
           end;



    //fun_lin.console_cr_linux8(FileName, FileExeName, param);
    Memo1.Clear;
    Memo1.Text:=FileExeName;
    Form1.ProcessUTF8_4.CommandLine:='chmod 777 ' + file_con;
    Form1.ProcessUTF8_4.Execute;
    Form1.ProcessUTF8_4.WaitOnExit;
    sss:=GetCurrentDir();
    comand:= '"' + sss + '"' + '/' + file_con;
    Memo1.Text:= comand;
   ProcessUTF8_2.CommandLine:=comand;
   ProcessUTF8_2.Execute;
  end;

if os = 'win' then
   begin

  end;



end;

procedure TForm1.Convertcp1251toutf8();
var
  MyAnsi: ansistring;
  MyUtf16:widestring;
begin
     MyAnsi:= SynEdit1.Text;
     MyUtf16 := CP1251ToUTF8(MyAnsi);
     SynEdit1.Text :=MyUtf16;
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
var fn_1: String;
begin
  if fullFileName = '' then
       begin
         fullFileName:=SynEdit1.SelText;
         SaveDialog1.FileName:=fullFileName + '.java';
       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_4.Parameters.Clear;
 ProcessUTF8_4.CommandLine:='';
 FileName := ExtractFileName(fullFileName);
 FileExeName:=Copy(FileName,1,Length(FileName)-5);
 pak:= Name_Package(SynEdit1.Lines.Strings[Find_Package(SynEdit1)]);
     if pak <> '' then
        begin
             javastr:=DirJDK + st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + pak + '.' + FileExeName;
             ProcessUTF8_4.Executable:=DirJDK + st_bin + java_exe_gui;
             ProcessUTF8_4.Parameters.Add('-cp');
             ProcessUTF8_4.Parameters.Add(ExtractFileDir(fullFileName));
             ProcessUTF8_4.Parameters.Add(pak + '.' + FileExeName);
             Form1.Caption:=pak + '.' + FileExeName;
             Memo1.Clear;
             Memo1.Text:=javastr;
             ProcessUTF8_4.Execute;
        end
     else
         begin
            javastr:=DirJDK + st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' ' + FileExeName;
            ProcessUTF8_4.Executable:=DirJDK + st_bin + java_exe_gui;
            ProcessUTF8_4.Parameters.Add('-cp');
            ProcessUTF8_4.Parameters.Add(ExtractFileDir(fullFileName));
            ProcessUTF8_4.Parameters.Add(FileExeName);
            Memo1.Clear;
            Memo1.Text:=javastr;
            ProcessUTF8_4.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 ' + DirFX + st_lib + ' --add-modules ' + 'javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web ' + ' ' + pak + '.' + FileExeName;
        ProcessUTF8_1.Executable:=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(DirFX + 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:=DirJDK+ st_bin + java_exe_gui + ' -cp ' + ExtractFileDir(fullFileName) + ' --module-path ' + DirFX + st_lib + ' --add-modules ' + 'javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web ' + ' ' + FileExeName;
        ProcessUTF8_1.Executable:=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(DirFX + 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 ' + DirFX + 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(DirFX + 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:=DirJDK+ st_bin + compil_prog + ' -encoding utf8  --module-path ' + DirFX + 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(DirFX + 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.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
c: PGtkClipboard;
t: string;
begin
   {$ifdef LINUX}
   c := gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
   t := Clipboard.AsText;
   gtk_clipboard_set_text(c, PChar(t), Length(t));
   gtk_clipboard_store(c);
   {$endif}
end;






procedure TForm1.FormCreate(Sender: TObject);
begin
  SynEdit1.PasteFromClipboard;
  os := 'linux';
  terminal:='';
  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_run  := '0_file_run.sh';
  if os = 'win' then file_run  := '0_file_run.bat';

  if os = 'linux' then file_run_fx  := '0_file_run_fx.sh';
  if os = 'win' then file_run_fx  := '0_file_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:='java';



  try
                  pr_path:= ParamStr(0);
                  fullFileName:=ParamStr(1);
                  Dirpro:= ExtractFileDir(pr_path) + st_p;
                  Dirfile:= ExtractFileDir(fullFileName) + st_p;
                  list := TStringList.Create;
                  if FileExists(ExtractFileDir(pr_path) + st_p + 'jdk.ini') then
                     begin
                          list.LoadFromFile(ExtractFileDir(pr_path) + st_p + 'jdk.ini');
                          DirJDK := list.Strings[0];
                          terminal := list.Strings[1];
                          //DirFX := list.Strings[1];
                          //DirJDK8 := list.Strings[2];
                     end
                  else
                  begin
                          if DirectoryExists(ExtractFileDir(pr_path) + st_p + 'jdk') then
                              DirJDK := Dirpro + 'jdk'
                          else begin
                                DirJDK := '';
                               end;
                          //DirFX := Dirpro + 'jdk';
                          //DirJDK8 := Dirpro + 'jdk';
                          //st_bin:='';
                  end;
                  list.Destroy;

                  SynEdit1.Clear;
                  SynEdit1.Lines.LoadFromFile(fullFileName);
                  Form1.Caption:= fullFileName;
        except
            //ShowMessage('Ошибка: нет файла настроек jdk.ini');
        end;
 if FileExists(ExtractFileDir(pr_path) + st_p + 'key_java.ini') then
    SynCompletion1.ItemList.LoadFromFile(ExtractFileDir(pr_path) + st_p + 'key_java.ini');


      ProcessUTF8_2.XTermProgram:=terminal;



    vers :='Версия: 1.9.99 ';
    Label1.Caption :=  vers;
end;

procedure TForm1.MenuItem100Click(Sender: TObject);
var comand, sss, str, str_f, main_class, pak_dir, pak_dir1: String;
begin
  if Form1.SynEdit1.Lines.Text = '' then exit;
  ProcessUTF8_4.Parameters.Clear;
  ProcessUTF8_2.CommandLine:='';
   list := TStringList.Create;
   ChDir(ExtractFileDir(fullFileName));
   list.Clear;
   FileName := ExtractFileName(fullFileName);
   main_class:=Copy(FileName,1,Length(FileName)-5);
  str:='#!/bin/bash';
  list.add(str);

  pak_dir:= Name_Package(Form1.SynEdit1.Lines.Strings[Find_Package(Form1.SynEdit1)]);
  pak_dir1 := stringreplace(phone, '.', '/', [rfReplaceAll]);
  if pak_dir <> '' then
      begin
          str_f := pak_dir1 + '/' + main_class + '.class';
      end
   else
       begin
          str_f := main_class + '.class';
   end;


   str := 'echo " "';
   list.add(str);
   str := 'echo "------------------------jdeps-----------------------------"';
   list.add(str);
   str := 'echo " "';
   list.add(str);
   str := DirJDK + st_bin + 'jdeps ' + str_f;
   list.add(str);
   str := 'echo " "';
   list.add(str);
   str := 'echo "----------------------------------------------------------"';
   list.add(str);
   str := 'read p';
   list.add(str);

  list.SaveToFile('0_jdeps.sh');
  list.Destroy;

    Form1.ProcessUTF8_4.CommandLine:='chmod 777 ' + '0_jdeps.sh';
    Form1.ProcessUTF8_4.Execute;
    Form1.ProcessUTF8_4.WaitOnExit;
    sss:=GetCurrentDir();
    comand:= '"' + sss + '"' + '/' + '0_jdeps.sh';
    Memo1.Text:= comand;
   ProcessUTF8_2.CommandLine:=comand;
   ProcessUTF8_2.Execute;


end;

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

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

procedure TForm1.MenuItem17Click(Sender: TObject);
begin

end;

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

end.

