|
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 edu.rice.cs.drjava.DrJava; |
|
40 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
41 |
| import edu.rice.cs.drjava.config.OptionEvent; |
|
42 |
| import edu.rice.cs.drjava.config.OptionListener; |
|
43 |
| import edu.rice.cs.drjava.model.SingleDisplayModel; |
|
44 |
| import edu.rice.cs.drjava.model.compiler.CompilerModel; |
|
45 |
| import edu.rice.cs.drjava.model.compiler.CompilerErrorModel; |
|
46 |
| import edu.rice.cs.drjava.model.compiler.CompilerInterface; |
|
47 |
| import edu.rice.cs.util.UnexpectedException; |
|
48 |
| import edu.rice.cs.util.text.SwingDocument; |
|
49 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
50 |
| |
|
51 |
| import javax.swing.*; |
|
52 |
| import javax.swing.text.BadLocationException; |
|
53 |
| import javax.swing.text.Position; |
|
54 |
| import java.awt.*; |
|
55 |
| import java.awt.event.ItemEvent; |
|
56 |
| import java.awt.event.ItemListener; |
|
57 |
| import java.io.File; |
|
58 |
| import java.util.Vector; |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| public class CompilerErrorPanel extends ErrorPanel { |
|
66 |
| |
|
67 |
| |
|
68 |
| private boolean _compileHasOccurred; |
|
69 |
| private CompilerErrorListPane _errorListPane; |
|
70 |
| private final JComboBox _compilerChoiceBox; |
|
71 |
| |
|
72 |
| |
|
73 |
| private File[] _excludedFiles = new File[0]; |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
38
| public CompilerErrorPanel(SingleDisplayModel model, MainFrame frame) {
|
|
80 |
38
| super(model, frame, "Compiler Output", "Compiler");
|
|
81 |
38
| _compileHasOccurred = false;
|
|
82 |
38
| _numErrors = 0;
|
|
83 |
| |
|
84 |
38
| _errorListPane = new CompilerErrorListPane();
|
|
85 |
38
| setErrorListPane(_errorListPane);
|
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
38
| final CompilerModel compilerModel = getModel().getCompilerModel();
|
|
95 |
38
| Iterable<CompilerInterface> iter = getModel().getCompilerModel().getAvailableCompilers();
|
|
96 |
38
| _compilerChoiceBox = new JComboBox(IterUtil.toArray(iter, CompilerInterface.class));
|
|
97 |
38
| _compilerChoiceBox.setEditable(false);
|
|
98 |
38
| _compilerChoiceBox.setSelectedItem(compilerModel.getActiveCompiler());
|
|
99 |
38
| _compilerChoiceBox.addItemListener(new ItemListener() {
|
|
100 |
0
| public void itemStateChanged(ItemEvent e) {
|
|
101 |
0
| if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
102 |
0
| final CompilerInterface compiler = (CompilerInterface) _compilerChoiceBox.getSelectedItem();
|
|
103 |
0
| compilerModel.resetCompilerErrors();
|
|
104 |
0
| _compileHasOccurred = false;
|
|
105 |
| |
|
106 |
| |
|
107 |
0
| new Thread(new Runnable() {
|
|
108 |
0
| public void run() {
|
|
109 |
0
| compilerModel.setActiveCompiler(compiler);
|
|
110 |
0
| reset();
|
|
111 |
| } |
|
112 |
| }).start(); |
|
113 |
| } |
|
114 |
| } |
|
115 |
| }); |
|
116 |
| |
|
117 |
38
| customPanel.add(_compilerChoiceBox, BorderLayout.NORTH);
|
|
118 |
| |
|
119 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.JAVAC_LOCATION, new CompilerLocationOptionListener<File>());
|
|
120 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.EXTRA_COMPILERS, new CompilerLocationOptionListener<Vector<String>>());
|
|
121 |
| } |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| private class CompilerLocationOptionListener<T> implements OptionListener<T> { |
|
126 |
| |
|
127 |
0
| public void optionChanged(OptionEvent<T> oce) {
|
|
128 |
0
| _compilerChoiceBox.removeAllItems();
|
|
129 |
0
| for (CompilerInterface c : getModel().getCompilerModel().getAvailableCompilers()) {
|
|
130 |
0
| _compilerChoiceBox.addItem(c);
|
|
131 |
| } |
|
132 |
| } |
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
84
| public CompilerErrorListPane getErrorListPane() { return _errorListPane; }
|
|
137 |
| |
|
138 |
| |
|
139 |
1
| public void setCompilationInProgress() {
|
|
140 |
1
| _errorListPane.setCompilationInProgress();
|
|
141 |
| } |
|
142 |
| |
|
143 |
17
| public CompilerErrorModel getErrorModel() { return getModel().getCompilerModel().getCompilerErrorModel(); }
|
|
144 |
| |
|
145 |
| |
|
146 |
4
| @Override
|
|
147 |
| protected void _close() { |
|
148 |
4
| super._close();
|
|
149 |
4
| getModel().getCompilerModel().resetCompilerErrors();
|
|
150 |
4
| reset();
|
|
151 |
| } |
|
152 |
| |
|
153 |
| |
|
154 |
1
| public void reset(File[] excludedFiles) {
|
|
155 |
1
| _excludedFiles = excludedFiles;
|
|
156 |
1
| reset();
|
|
157 |
| } |
|
158 |
| |
|
159 |
| |
|
160 |
43
| public void reset() {
|
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
43
| _numErrors = getModel().getCompilerModel().getNumErrors();
|
|
165 |
| |
|
166 |
43
| _errorListPane.updateListPane(true);
|
|
167 |
| |
|
168 |
| |
|
169 |
| } |
|
170 |
| |
|
171 |
| class CompilerErrorListPane extends ErrorPanel.ErrorListPane { |
|
172 |
| |
|
173 |
1
| protected void _updateWithErrors() throws BadLocationException {
|
|
174 |
1
| SwingDocument doc = new SwingDocument();
|
|
175 |
1
| if (_excludedFiles.length != 0) {
|
|
176 |
0
| final StringBuilder msgBuffer =
|
|
177 |
| new StringBuilder("Compilation completed. The following files were not compiled:\n"); |
|
178 |
0
| for (File f: _excludedFiles) {
|
|
179 |
0
| if (f != null) { msgBuffer.append(" ").append(f).append('\n'); }
|
|
180 |
| } |
|
181 |
0
| doc.append(msgBuffer.toString(), NORMAL_ATTRIBUTES);
|
|
182 |
| } |
|
183 |
| |
|
184 |
1
| String failureName = "error";
|
|
185 |
0
| if (getErrorModel().hasOnlyWarnings()) failureName = "warning";
|
|
186 |
| |
|
187 |
1
| _updateWithErrors(failureName, "found", doc);
|
|
188 |
| } |
|
189 |
| |
|
190 |
| |
|
191 |
1
| public void setCompilationInProgress() {
|
|
192 |
1
| _errorListPositions = new Position[0];
|
|
193 |
1
| _compileHasOccurred = true;
|
|
194 |
| |
|
195 |
1
| SwingDocument doc = new SwingDocument();
|
|
196 |
| |
|
197 |
1
| try { doc.insertString(0, "Compilation in progress, please wait...", NORMAL_ATTRIBUTES); }
|
|
198 |
0
| catch (BadLocationException ble) { throw new UnexpectedException(ble); }
|
|
199 |
| |
|
200 |
1
| setDocument(doc);
|
|
201 |
1
| selectNothing();
|
|
202 |
| } |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
42
| protected void _updateNoErrors(boolean done) throws BadLocationException {
|
|
208 |
42
| SwingDocument doc = new SwingDocument();
|
|
209 |
42
| String message;
|
|
210 |
42
| if (_compileHasOccurred) {
|
|
211 |
0
| if (_excludedFiles.length == 0) message = "Compilation completed.";
|
|
212 |
| else { |
|
213 |
0
| final StringBuilder msgBuffer =
|
|
214 |
| new StringBuilder("Compilation completed. The following files were not compiled:\n"); |
|
215 |
0
| for (File f: _excludedFiles) {
|
|
216 |
0
| if (f != null) { msgBuffer.append(" ").append(f).append('\n'); }
|
|
217 |
| } |
|
218 |
0
| message = msgBuffer.toString();
|
|
219 |
| } |
|
220 |
| } |
|
221 |
42
| else if (!getModel().getCompilerModel().getActiveCompiler().isAvailable())
|
|
222 |
0
| message = "No compiler available.";
|
|
223 |
| else |
|
224 |
42
| message = "Compiler ready: " + getModel().getCompilerModel().getActiveCompiler().getDescription() + ".";
|
|
225 |
| |
|
226 |
42
| doc.insertString(0, message, NORMAL_ATTRIBUTES);
|
|
227 |
42
| setDocument(doc);
|
|
228 |
42
| _updateScrollButtons();
|
|
229 |
42
| selectNothing();
|
|
230 |
| } |
|
231 |
| } |
|
232 |
| } |