github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/integrations/intellij/src/main/java/InitDialog.java (about) 1 import javax.swing.*; 2 import java.awt.event.*; 3 4 public class InitDialog extends JDialog { 5 private JPanel contentPane; 6 private JButton buttonOK; 7 private JButton buttonCancel; 8 private JTextField tName; 9 private JTextField tDescription; 10 private JTextArea tMaintainers; 11 private JCheckBox cSingleFile; 12 private boolean validated; 13 14 public class Result { 15 public String name; 16 public String description; 17 public String maintainers; 18 public boolean singleFile; 19 } 20 21 public boolean wasValidated() { return validated;} 22 23 public Result result() { 24 Result r = new Result(); 25 r.name = tName.getText(); 26 r.description = tDescription.getText(); 27 r.maintainers = tMaintainers.getText(); 28 r.singleFile = cSingleFile.isSelected(); 29 return r; 30 } 31 32 public InitDialog() { 33 setContentPane(contentPane); 34 setModal(true); 35 getRootPane().setDefaultButton(buttonOK); 36 37 buttonOK.addActionListener(new ActionListener() { 38 public void actionPerformed(ActionEvent e) { 39 onOK(); 40 } 41 }); 42 43 buttonCancel.addActionListener(new ActionListener() { 44 public void actionPerformed(ActionEvent e) { 45 onCancel(); 46 } 47 }); 48 49 // call onCancel() when cross is clicked 50 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 51 addWindowListener(new WindowAdapter() { 52 public void windowClosing(WindowEvent e) { 53 onCancel(); 54 } 55 }); 56 57 // call onCancel() on ESCAPE 58 contentPane.registerKeyboardAction(new ActionListener() { 59 public void actionPerformed(ActionEvent e) { 60 onCancel(); 61 } 62 }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 63 } 64 65 private void onOK() { 66 // add your code here 67 validated = true; 68 dispose(); 69 } 70 71 private void onCancel() { 72 // add your code here if necessary 73 validated = false; 74 dispose(); 75 } 76 }