package com.github.shiraji.permissionsdispatcherplugin.views;

import javax.swing.*;
import java.awt.event.*;

public class GeneratePMCodeDialog extends JDialog {
    JPanel contentPane;
    JButton buttonOK;
    JButton buttonCancel;
    private JCheckBox readCalendar;
    private JCheckBox writeCalendar;
    private JCheckBox camera;
    private JCheckBox readContacts;
    private JCheckBox writeContacts;
    private JCheckBox getAccounts;
    private JCheckBox accessFineLocation;
    private JCheckBox accessCoarseLocation;
    private JCheckBox recordAudio;
    private JCheckBox readPhoneState;
    private JCheckBox callPhone;
    private JCheckBox readCallLog;
    private JCheckBox writeCallLog;
    private JCheckBox addVoicemail;
    private JCheckBox useSip;
    private JCheckBox processOutgoingCall;
    private JCheckBox bodySensors;
    private JCheckBox sendSms;
    private JCheckBox receiveSms;
    private JCheckBox readSms;
    private JCheckBox receiveWapPush;
    private JCheckBox receiveMms;
    private JCheckBox readExternalStorage;
    private JCheckBox writeExternalStorage;
    private JCheckBox systemAlertWindow;
    private JCheckBox writeSettings;

    public boolean isOk = false;

    public GeneratePMCodeDialog() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

// call onCancel() when cross is clicked
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

// call onCancel() on ESCAPE
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
// add your code here
        isOk = true;
        setVisible(false);
    }

    private void onCancel() {
// add your code here if necessary
        setVisible(false);
    }

    public static void main(String[] args) {
        GeneratePMCodeDialog dialog = new GeneratePMCodeDialog();
        dialog.pack();
        dialog.setVisible(true);
        if (dialog.isOk) {
            System.out.println("ok!");
        }
        System.exit(0);
    }
}

@@ -81,33 +81,8 @@
 g.*;
-%0Aimport java.awt.event.*;
 %0A%0Apu
@@ -203,27 +203,20 @@
 Cancel;%0A
- 
+%0A
    
-private
  JCheckB
@@ -232,32 +232,24 @@
 lendar;%0A    
-private 
 JCheckBox wr
@@ -261,32 +261,24 @@
 lendar;%0A    
-private 
 JCheckBox ca
@@ -283,32 +283,24 @@
 camera;%0A    
-private 
 JCheckBox re
@@ -311,32 +311,24 @@
 ntacts;%0A    
-private 
 JCheckBox wr
@@ -340,32 +340,24 @@
 ntacts;%0A    
-private 
 JCheckBox ge
@@ -367,32 +367,24 @@
 counts;%0A    
-private 
 JCheckBox ac
@@ -401,32 +401,24 @@
 cation;%0A    
-private 
 JCheckBox ac
@@ -437,32 +437,24 @@
 cation;%0A    
-private 
 JCheckBox re
@@ -464,32 +464,24 @@
 dAudio;%0A    
-private 
 JCheckBox re
@@ -494,32 +494,24 @@
 eState;%0A    
-private 
 JCheckBox ca
@@ -519,32 +519,24 @@
 lPhone;%0A    
-private 
 JCheckBox re
@@ -546,32 +546,24 @@
 allLog;%0A    
-private 
 JCheckBox wr
@@ -574,32 +574,24 @@
 allLog;%0A    
-private 
 JCheckBox ad
@@ -602,32 +602,24 @@
 cemail;%0A    
-private 
 JCheckBox us
@@ -624,32 +624,24 @@
 useSip;%0A    
-private 
 JCheckBox pr
@@ -659,32 +659,24 @@
 ngCall;%0A    
-private 
 JCheckBox bo
@@ -686,32 +686,24 @@
 ensors;%0A    
-private 
 JCheckBox se
@@ -709,32 +709,24 @@
 endSms;%0A    
-private 
 JCheckBox re
@@ -735,32 +735,24 @@
 iveSms;%0A    
-private 
 JCheckBox re
@@ -758,32 +758,24 @@
 eadSms;%0A    
-private 
 JCheckBox re
@@ -788,32 +788,24 @@
 apPush;%0A    
-private 
 JCheckBox re
@@ -814,32 +814,24 @@
 iveMms;%0A    
-private 
 JCheckBox re
@@ -849,32 +849,24 @@
 torage;%0A    
-private 
 JCheckBox wr
@@ -885,28 +885,21 @@
 torage;%0A
+%0A
     
-private 
 JCheckBo
@@ -923,24 +923,16 @@
 ow;%0A    
-private 
 JCheckBo
@@ -1031,1205 +1031,58 @@
     
-setContentPane(contentPane);%0A        setModal(true);%0A        getRootPane().setDefaultButton(buttonOK);%0A%0A        buttonOK.addActionListener(new ActionListener() %7B%0A            public void actionPerformed(ActionEvent e) %7B%0A                onOK();%0A            %7D%0A        %7D);%0A%0A        buttonCancel.addActionListener(new ActionListener() %7B%0A            public void actionPerformed(ActionEvent e) %7B%0A                onCancel();%0A            %7D%0A        %7D);%0A%0A// call onCancel() when cross is clicked%0A        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);%0A        addWindowListener(new WindowAdapter() %7B%0A            public void windowClosing(WindowEvent e) %7B%0A                onCancel();%0A            %7D%0A        %7D);%0A%0A// call onCancel() on ESCAPE%0A        contentPane.registerKeyboardAction(new ActionListener() %7B%0A            public void actionPerformed(ActionEvent e) %7B%0A                onCancel();%0A            %7D%0A        %7D, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);%0A    %7D%0A%0A    private void onOK() %7B%0A// add your code here%0A        isOk = true;%0A        setVisible(false);%0A    %7D%0A%0A    private void onCancel() %7B%0A// add your code here if necessary%0A        setVisible(false
+new GeneratePMCodeDialogDelegate(this).initDialog(
 );%0A 

Move most code to Kotlin