|
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; |
|
38 |
| |
|
39 |
| import javax.swing.*; |
|
40 |
| import java.awt.event.*; |
|
41 |
| import java.awt.*; |
|
42 |
| |
|
43 |
| import edu.rice.cs.drjava.model.SingleDisplayModel; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| public abstract class AbortablePanel extends TabbedPanel { |
|
51 |
| protected JPanel _leftPane; |
|
52 |
| protected JScrollPane _scrollPane; |
|
53 |
| |
|
54 |
| protected final SingleDisplayModel _model; |
|
55 |
| protected final MainFrame _frame; |
|
56 |
| |
|
57 |
| protected String _title; |
|
58 |
| protected JPanel _buttonPanel; |
|
59 |
| |
|
60 |
| protected JButton _abortButton; |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
0
| public AbortablePanel(MainFrame frame, String title) {
|
|
68 |
0
| super(frame, title);
|
|
69 |
| |
|
70 |
0
| _title = title;
|
|
71 |
0
| this.setLayout(new BorderLayout());
|
|
72 |
| |
|
73 |
0
| _frame = frame;
|
|
74 |
0
| _model = frame.getModel();
|
|
75 |
| |
|
76 |
0
| this.removeAll();
|
|
77 |
| |
|
78 |
| |
|
79 |
0
| _closePanel = new JPanel(new BorderLayout());
|
|
80 |
0
| _closePanel.add(_closeButton, BorderLayout.NORTH);
|
|
81 |
| |
|
82 |
0
| _leftPane = new JPanel(new BorderLayout());
|
|
83 |
0
| Component leftPanel = makeLeftPanel();
|
|
84 |
0
| _scrollPane = new JScrollPane(leftPanel);
|
|
85 |
0
| _leftPane.add(_scrollPane);
|
|
86 |
0
| _setColors(leftPanel);
|
|
87 |
| |
|
88 |
0
| this.add(_leftPane, BorderLayout.CENTER);
|
|
89 |
| |
|
90 |
0
| _buttonPanel = new JPanel(new BorderLayout());
|
|
91 |
0
| _setupButtonPanel();
|
|
92 |
0
| this.add(_buttonPanel, BorderLayout.EAST);
|
|
93 |
0
| updateButtons();
|
|
94 |
| |
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
0
| protected static void _setColors(Component c) {
|
|
99 |
0
| new ForegroundColorListener(c);
|
|
100 |
0
| new BackgroundColorListener(c);
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
0
| @Override
|
|
105 |
| protected void _close() { |
|
106 |
0
| super._close();
|
|
107 |
0
| abortActionPerformed(null);
|
|
108 |
0
| updateButtons();
|
|
109 |
| } |
|
110 |
| |
|
111 |
| |
|
112 |
| protected abstract Component makeLeftPanel(); |
|
113 |
| |
|
114 |
| |
|
115 |
| protected abstract void abortActionPerformed(ActionEvent e); |
|
116 |
| |
|
117 |
| |
|
118 |
0
| protected void updateButtons() { }
|
|
119 |
| |
|
120 |
| |
|
121 |
0
| protected JComponent[] makeButtons() {
|
|
122 |
0
| return new JComponent[0];
|
|
123 |
| } |
|
124 |
| |
|
125 |
| |
|
126 |
0
| private void _setupButtonPanel() {
|
|
127 |
0
| JPanel mainButtons = new JPanel();
|
|
128 |
0
| JPanel emptyPanel = new JPanel();
|
|
129 |
0
| JPanel closeButtonPanel = new JPanel(new BorderLayout());
|
|
130 |
0
| GridBagLayout gbLayout = new GridBagLayout();
|
|
131 |
0
| GridBagConstraints c = new GridBagConstraints();
|
|
132 |
0
| mainButtons.setLayout(gbLayout);
|
|
133 |
| |
|
134 |
0
| JComponent[] buts = makeButtons();
|
|
135 |
| |
|
136 |
0
| closeButtonPanel.add(_closeButton, BorderLayout.NORTH);
|
|
137 |
0
| mainButtons.add(_abortButton = new JButton("Abort"));
|
|
138 |
0
| _abortButton.addActionListener(new ActionListener() {
|
|
139 |
0
| public void actionPerformed(ActionEvent e) { abortActionPerformed(e); }
|
|
140 |
| }); |
|
141 |
0
| for (JComponent b: buts) { mainButtons.add(b); }
|
|
142 |
0
| mainButtons.add(emptyPanel);
|
|
143 |
| |
|
144 |
0
| c.fill = GridBagConstraints.HORIZONTAL;
|
|
145 |
0
| c.anchor = GridBagConstraints.NORTH;
|
|
146 |
0
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
147 |
0
| c.weightx = 1.0;
|
|
148 |
| |
|
149 |
0
| gbLayout.setConstraints(_abortButton, c);
|
|
150 |
0
| for (JComponent b: buts) { gbLayout.setConstraints(b, c); }
|
|
151 |
| |
|
152 |
0
| c.fill = GridBagConstraints.BOTH;
|
|
153 |
0
| c.anchor = GridBagConstraints.SOUTH;
|
|
154 |
0
| c.gridheight = GridBagConstraints.REMAINDER;
|
|
155 |
0
| c.weighty = 1.0;
|
|
156 |
| |
|
157 |
0
| gbLayout.setConstraints(emptyPanel, c);
|
|
158 |
| |
|
159 |
0
| _buttonPanel.add(mainButtons, BorderLayout.CENTER);
|
|
160 |
0
| _buttonPanel.add(closeButtonPanel, BorderLayout.EAST);
|
|
161 |
| } |
|
162 |
| } |