(Component contents)
| 61 | } |
| 62 | |
| 63 | protected void init(Component contents){ |
| 64 | MainFrame.getGuiRoots().add(this); |
| 65 | |
| 66 | getContentPane().setLayout(new BorderLayout()); |
| 67 | |
| 68 | // //fill in the contents |
| 69 | // JPanel vBox = new JPanel(); |
| 70 | // vBox.setLayout(new BoxLayout(vBox, BoxLayout.Y_AXIS)); |
| 71 | // |
| 72 | // JPanel contentsPanel = new JPanel(); |
| 73 | // contentsPanel.add(contents); |
| 74 | // contentsPanel.setAlignmentX(Component.CENTER_ALIGNMENT); |
| 75 | // |
| 76 | // vBox.add(contentsPanel); |
| 77 | |
| 78 | getContentPane().add(contents, BorderLayout.CENTER); |
| 79 | |
| 80 | JPanel buttonsBox = new JPanel(); |
| 81 | buttonsBox.setLayout(new BoxLayout(buttonsBox, BoxLayout.X_AXIS)); |
| 82 | buttonsBox.setAlignmentX(Component.CENTER_ALIGNMENT); |
| 83 | okButton = new JButton("OK"); |
| 84 | cancelButton = new JButton("Cancel"); |
| 85 | buttonsBox.add(Box.createHorizontalGlue()); |
| 86 | buttonsBox.add(okButton); |
| 87 | buttonsBox.add(Box.createHorizontalStrut(20)); |
| 88 | buttonsBox.add(cancelButton); |
| 89 | buttonsBox.add(Box.createHorizontalGlue()); |
| 90 | |
| 91 | Box vBox = Box.createVerticalBox(); |
| 92 | vBox.add(Box.createVerticalStrut(10)); |
| 93 | vBox.add(buttonsBox); |
| 94 | vBox.add(Box.createVerticalStrut(10)); |
| 95 | |
| 96 | getContentPane().add(vBox, BorderLayout.SOUTH); |
| 97 | |
| 98 | Action applyAction = new AbstractAction() { |
| 99 | @Override |
| 100 | public void actionPerformed(ActionEvent e) { |
| 101 | userHasPressedOK = true; |
| 102 | setVisible(false); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | Action cancelAction = new AbstractAction() { |
| 107 | @Override |
| 108 | public void actionPerformed(ActionEvent e) { |
| 109 | userHasPressedCancel = true; |
| 110 | setVisible(false); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | // define keystrokes action bindings at the level of the main window |
| 115 | InputMap inputMap = ((JComponent)this.getContentPane()). |
| 116 | getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); |
| 117 | ActionMap actionMap = |
| 118 | ((JComponent)this.getContentPane()).getActionMap(); |
| 119 | inputMap.put(KeyStroke.getKeyStroke("ENTER"), "Apply"); |
| 120 | actionMap.put("Apply", applyAction); |
no test coverage detected