|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.ui.config; |
|
38 |
| |
|
39 |
| import javax.swing.*; |
|
40 |
| import javax.swing.border.EmptyBorder; |
|
41 |
| import java.awt.event.*; |
|
42 |
| import java.awt.*; |
|
43 |
| |
|
44 |
| |
|
45 |
| import java.util.Vector; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public class ConfigPanel extends JPanel { |
|
52 |
| |
|
53 |
| protected final String _title; |
|
54 |
| protected final Vector<OptionComponent<?,?>> _components; |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
608
| public ConfigPanel(String title) {
|
|
60 |
| |
|
61 |
608
| _title = title;
|
|
62 |
608
| _components = new Vector<OptionComponent<?,?>>();
|
|
63 |
| } |
|
64 |
| |
|
65 |
0
| public String getTitle() { return _title; }
|
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
18244
| public void addComponent(OptionComponent<?,?> oc) { _components.add(oc); }
|
|
71 |
| |
|
72 |
570
| public void displayComponents() {
|
|
73 |
570
| this.setLayout(new BorderLayout());
|
|
74 |
| |
|
75 |
570
| JPanel panel = new JPanel();
|
|
76 |
570
| panel.setLayout(new BorderLayout());
|
|
77 |
570
| JPanel panel2 = new JPanel();
|
|
78 |
570
| panel.add(panel2, BorderLayout.NORTH);
|
|
79 |
| |
|
80 |
570
| JScrollPane scroll =
|
|
81 |
| new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
82 |
570
| scroll.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), _title));
|
|
83 |
| |
|
84 |
| |
|
85 |
570
| JScrollBar bar = scroll.getVerticalScrollBar();
|
|
86 |
570
| bar.setUnitIncrement(25);
|
|
87 |
570
| bar.setBlockIncrement(400);
|
|
88 |
| |
|
89 |
570
| GridBagLayout gridbag = new GridBagLayout();
|
|
90 |
570
| GridBagConstraints c = new GridBagConstraints();
|
|
91 |
570
| panel2.setLayout(gridbag);
|
|
92 |
570
| c.fill = GridBagConstraints.HORIZONTAL;
|
|
93 |
570
| Insets labelInsets = new Insets(0, 10, 0, 10);
|
|
94 |
570
| Insets compInsets = new Insets(0, 0, 0, 0);
|
|
95 |
570
| for (int i = 0; i < _components.size(); i++) {
|
|
96 |
18244
| OptionComponent<?,?> comp = _components.get(i);
|
|
97 |
| |
|
98 |
18244
| if (!comp.useEntireColumn()) {
|
|
99 |
16648
| c.anchor = GridBagConstraints.CENTER;
|
|
100 |
16648
| c.weightx = 0.0;
|
|
101 |
16648
| c.gridwidth = 1;
|
|
102 |
16648
| c.insets = labelInsets;
|
|
103 |
| |
|
104 |
16648
| JLabel label= comp.getLabel();
|
|
105 |
16648
| gridbag.setConstraints(label, c);
|
|
106 |
16648
| panel2.add(label);
|
|
107 |
| |
|
108 |
16648
| c.weightx = 1.0;
|
|
109 |
16648
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
110 |
16648
| c.insets = compInsets;
|
|
111 |
| |
|
112 |
16648
| JComponent otherC = comp.getComponent();
|
|
113 |
16648
| gridbag.setConstraints(otherC, c);
|
|
114 |
16648
| panel2.add(otherC);
|
|
115 |
| } |
|
116 |
| else { |
|
117 |
1596
| c.anchor = GridBagConstraints.NORTH;
|
|
118 |
1596
| c.weightx = 0.0;
|
|
119 |
1596
| c.gridwidth = 2;
|
|
120 |
1596
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
121 |
1596
| c.insets = compInsets;
|
|
122 |
| |
|
123 |
1596
| JComponent otherC = comp.getComponent();
|
|
124 |
1596
| gridbag.setConstraints(otherC, c);
|
|
125 |
1596
| panel2.add(otherC);
|
|
126 |
| } |
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
570
| JButton _resetToDefaultButton = new JButton("Reset to Defaults");
|
|
131 |
570
| _resetToDefaultButton.addActionListener(new ActionListener() {
|
|
132 |
0
| public void actionPerformed(ActionEvent e) { resetToDefault(); }
|
|
133 |
| }); |
|
134 |
570
| JPanel resetPanel = new JPanel();
|
|
135 |
570
| resetPanel.setLayout(new FlowLayout());
|
|
136 |
570
| resetPanel.setBorder(new EmptyBorder(5,5,5,5));
|
|
137 |
570
| resetPanel.add(_resetToDefaultButton);
|
|
138 |
570
| panel.add(resetPanel, BorderLayout.SOUTH);
|
|
139 |
| |
|
140 |
570
| this.add(scroll, BorderLayout.CENTER);
|
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
0
| public boolean update() {
|
|
147 |
| |
|
148 |
0
| for (int i = 0; i < _components.size(); i++) {
|
|
149 |
0
| boolean isValidUpdate = _components.get(i).updateConfig();
|
|
150 |
0
| if (! isValidUpdate) return false;
|
|
151 |
| } |
|
152 |
0
| return true;
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
0
| public void resetToCurrent() {
|
|
157 |
0
| for (int i = 0; i < _components.size(); i++) {
|
|
158 |
0
| _components.get(i).resetToCurrent();
|
|
159 |
0
| if (_components.get(i) instanceof VectorOptionComponent<?>)
|
|
160 |
0
| ((VectorOptionComponent<?>)_components.get(i)).resizeTable();
|
|
161 |
| } |
|
162 |
| } |
|
163 |
| |
|
164 |
| |
|
165 |
0
| public void resetToDefault() {
|
|
166 |
0
| for (int i = 0; i < _components.size(); i++) {
|
|
167 |
0
| _components.get(i).resetToDefault();
|
|
168 |
0
| if (_components.get(i) instanceof VectorOptionComponent<?>)
|
|
169 |
0
| ((VectorOptionComponent<?>)_components.get(i)).resizeTable();
|
|
170 |
| } |
|
171 |
| |
|
172 |
0
| VectorKeyStrokeOptionComponent.resetCurrentKeyStrokeMap();
|
|
173 |
| } |
|
174 |
| } |