The updated version of the applicationConfigurable sample plugin.
[idea/community.git] / samples / applicationConfigurable / src / fontConfigurable / IDEDialog.java
1 package fontConfigurable;
2
3 import com.intellij.ide.ui.UISettings;
4 import com.intellij.util.ui.UIUtil;
5
6 import javax.swing.*;
7 import java.awt.event.*;
8
9 public class IDEDialog extends JDialog {
10     private JPanel contentPane;
11     public JPanel name;
12     public JComboBox myFontCombo;
13     public JComboBox myFontSize;
14     public JLabel menuFontSettingsLabel;
15     public JButton buttonRestoreDefaultFont;
16
17
18     public IDEDialog() {
19         setContentPane(contentPane);
20         setModal(true);
21         UISettings settings = UISettings.getInstance();
22         myFontCombo.setModel(new DefaultComboBoxModel(UIUtil.getValidFontNames(false)));
23         myFontSize.setModel(new DefaultComboBoxModel(UIUtil.getStandardFontSizes()));
24         myFontCombo.setSelectedItem(settings.FONT_FACE);
25         myFontSize.setSelectedItem(String.valueOf(settings.FONT_SIZE));
26
27 // Configure the Set Default Font myButton listener.
28
29         MyButtonListener actionListener = new MyButtonListener();
30         actionListener.myButton = buttonRestoreDefaultFont;
31         actionListener.myFontCombo = myFontCombo;
32         actionListener.myFontSize = myFontSize;
33         buttonRestoreDefaultFont.addActionListener(actionListener);
34
35
36 // call onCancel() when cross is clicked
37         setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
38         addWindowListener(new WindowAdapter() {
39             public void windowClosing(WindowEvent e) {
40                 onCancel();
41             }
42         });
43
44 // call onCancel() on ESCAPE
45         contentPane.registerKeyboardAction(new ActionListener() {
46             public void actionPerformed(ActionEvent e) {
47                 onCancel();
48             }
49         }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
50     }
51
52     private void onOK() {
53 // add your code here
54
55
56         dispose();
57     }
58
59
60     private void onCancel() {
61 // add your code here if necessary
62         dispose();
63     }
64
65
66 }