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