|
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.util.swing.Utilities; |
|
40 |
| import edu.rice.cs.drjava.model.DrJavaFileUtils; |
|
41 |
| import edu.rice.cs.drjava.project.MalformedProjectFileException; |
|
42 |
| import edu.rice.cs.drjava.model.debug.DebugException; |
|
43 |
| import edu.rice.cs.util.UnexpectedException; |
|
44 |
| import edu.rice.cs.util.StringOps; |
|
45 |
| |
|
46 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
47 |
| |
|
48 |
| import javax.swing.*; |
|
49 |
| import java.awt.*; |
|
50 |
| import java.io.*; |
|
51 |
| import java.net.URL; |
|
52 |
| |
|
53 |
| import static edu.rice.cs.plt.object.ObjectUtil.hash; |
|
54 |
| |
|
55 |
| |
|
56 |
| public class MainFrameStatics { |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
1
| public static File proposeToChangeExtension(Component parent, File input,
|
|
68 |
| String title, |
|
69 |
| String message, |
|
70 |
| String changeButton, |
|
71 |
| String keepButton, |
|
72 |
| String newExt) { |
|
73 |
1
| Object[] options = {changeButton, keepButton};
|
|
74 |
1
| int rc = 1;
|
|
75 |
1
| if (!Utilities.TEST_MODE) {
|
|
76 |
0
| rc = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.YES_NO_OPTION,
|
|
77 |
| JOptionPane.QUESTION_MESSAGE, null, options, options[0]); |
|
78 |
| } |
|
79 |
1
| if (rc == 0) {
|
|
80 |
0
| try {
|
|
81 |
0
| String fileName = DrJavaFileUtils.removeExtension(input.getCanonicalPath()) + newExt;
|
|
82 |
0
| File file = new File(fileName);
|
|
83 |
0
| return file;
|
|
84 |
| } |
|
85 |
0
| catch(IOException ioe) { showIOError(parent, ioe); }
|
|
86 |
| } |
|
87 |
1
| return input;
|
|
88 |
| } |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
0
| public static boolean verifyOverwrite(Component parent, File f) {
|
|
95 |
0
| Object[] options = {"Yes","No"};
|
|
96 |
0
| int n = JOptionPane.showOptionDialog(parent,
|
|
97 |
| "<html>This file already exists. Do you wish to overwrite the file?<br>"+ |
|
98 |
| f.getPath()+"<html>", |
|
99 |
| "Confirm Overwrite", |
|
100 |
| JOptionPane.YES_NO_OPTION, |
|
101 |
| JOptionPane.QUESTION_MESSAGE, |
|
102 |
| null, |
|
103 |
| options, |
|
104 |
| options[1]); |
|
105 |
0
| return (n == JOptionPane.YES_OPTION);
|
|
106 |
| } |
|
107 |
| |
|
108 |
0
| public static void showProjectFileParseError(Component parent, MalformedProjectFileException mpfe) {
|
|
109 |
0
| showError(parent, "Invalid Project File", "DrJava could not read the given project file.");
|
|
110 |
| } |
|
111 |
| |
|
112 |
0
| public static void showFileNotFoundError(Component parent, FileNotFoundException fnf) {
|
|
113 |
0
| showErrorWithMessageIfAvailable(parent, fnf, "File Not Found",
|
|
114 |
| "The specified file was not found on disk."); |
|
115 |
| } |
|
116 |
| |
|
117 |
0
| public static void showIOError(Component parent, IOException ioe) {
|
|
118 |
0
| showErrorWithMessageIfAvailable(parent, ioe, "Input/output error",
|
|
119 |
| "An I/O exception occurred during the last operation."); |
|
120 |
| } |
|
121 |
| |
|
122 |
0
| public static void showErrorWithMessageIfAvailable(Component parent, Throwable e, String title, String message) {
|
|
123 |
0
| if ((null != e.getMessage()) && (e.getMessage().length() > 0)) {
|
|
124 |
0
| showError(parent, title, message+"\n"+e.getMessage());
|
|
125 |
| } |
|
126 |
| else { |
|
127 |
0
| showError(parent, e, title, message);
|
|
128 |
| } |
|
129 |
| } |
|
130 |
| |
|
131 |
0
| public static void showClassNotFoundError(Component parent, ClassNotFoundException cnfe) {
|
|
132 |
0
| showError(parent, cnfe, "Class Not Found",
|
|
133 |
| "A ClassNotFound exception occurred during the last operation.\n" + |
|
134 |
| "Please check that your classpath includes all relevant directories.\n\n"); |
|
135 |
| } |
|
136 |
| |
|
137 |
0
| public static void showNoClassDefError(Component parent, NoClassDefFoundError ncde) {
|
|
138 |
0
| showError(parent, ncde, "No Class Def",
|
|
139 |
| "A NoClassDefFoundError occurred during the last operation.\n" + |
|
140 |
| "Please check that your classpath includes all relevant paths.\n\n"); |
|
141 |
| } |
|
142 |
| |
|
143 |
0
| public static void showDebugError(Component parent, DebugException de) {
|
|
144 |
0
| showError(parent, de, "Debug Error", "A Debugger error occurred in the last operation.\n\n");
|
|
145 |
| } |
|
146 |
| |
|
147 |
0
| public static void showJUnitInterrupted(Component parent, UnexpectedException e) {
|
|
148 |
0
| showWarning(parent, e.getCause(), "JUnit Testing Interrupted",
|
|
149 |
| "The slave JVM has thrown a RemoteException probably indicating that it has been reset.\n\n"); |
|
150 |
| } |
|
151 |
| |
|
152 |
0
| public static void showJUnitInterrupted(Component parent, String message) {
|
|
153 |
0
| JOptionPane.showMessageDialog(parent, message, "JUnit Testing Interrupted", JOptionPane.WARNING_MESSAGE);
|
|
154 |
| } |
|
155 |
| |
|
156 |
0
| public static void showError(Component parent, Throwable e, String title, String message) {
|
|
157 |
0
| JOptionPane.showMessageDialog(parent, message + "\n" + e + "\n"+ StringOps.getStackTrace(e),
|
|
158 |
| title, JOptionPane.ERROR_MESSAGE); |
|
159 |
| } |
|
160 |
| |
|
161 |
0
| public static void showError(Component parent, String title, String message) {
|
|
162 |
0
| JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
|
|
163 |
| } |
|
164 |
| |
|
165 |
0
| public static void showWarning(Component parent, Throwable e, String title, String message) {
|
|
166 |
0
| JOptionPane.showMessageDialog(parent, message + "\n" + e, title, JOptionPane.WARNING_MESSAGE);
|
|
167 |
| } |
|
168 |
| |
|
169 |
| public static abstract class AutoCompletePopupEntry implements Comparable<AutoCompletePopupEntry> { |
|
170 |
| |
|
171 |
| public abstract String getClassName(); |
|
172 |
| |
|
173 |
| public abstract String getFullPackage(); |
|
174 |
| |
|
175 |
| public abstract OpenDefinitionsDocument getOpenDefinitionsDocument(); |
|
176 |
| |
|
177 |
6
| public int compareTo(AutoCompletePopupEntry other) {
|
|
178 |
6
| int res = getClassName().toLowerCase().compareTo(other.getClassName().toLowerCase());
|
|
179 |
6
| if (res != 0) { return res; }
|
|
180 |
0
| return getFullPackage().toLowerCase().compareTo(other.getFullPackage().toLowerCase());
|
|
181 |
| } |
|
182 |
| |
|
183 |
32
| public boolean equals(Object other) {
|
|
184 |
16
| if (other == null || ! (other instanceof AutoCompletePopupEntry)) return false;
|
|
185 |
16
| AutoCompletePopupEntry o = (AutoCompletePopupEntry) other;
|
|
186 |
16
| return (getClassName().equals(o.getClassName()) && getFullPackage().equals(o.getFullPackage()));
|
|
187 |
| } |
|
188 |
3279
| public int hashCode() { return hash(getClassName(), getFullPackage()); }
|
|
189 |
| } |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| public static class GoToFileListEntry extends AutoCompletePopupEntry { |
|
196 |
| private final OpenDefinitionsDocument doc; |
|
197 |
| private String fullPackage = null; |
|
198 |
| private final String str; |
|
199 |
13
| public GoToFileListEntry(OpenDefinitionsDocument d, String s) {
|
|
200 |
13
| doc = d;
|
|
201 |
13
| str = s;
|
|
202 |
| } |
|
203 |
32
| public String getFullPackage() {
|
|
204 |
28
| if (fullPackage != null) { return fullPackage; }
|
|
205 |
4
| fullPackage = "";
|
|
206 |
4
| if (doc != null) {
|
|
207 |
1
| try {
|
|
208 |
1
| fullPackage = doc.getPackageName();
|
|
209 |
0
| if (fullPackage.length() > 0) { fullPackage += '.'; }
|
|
210 |
| } |
|
211 |
0
| catch(Exception e) { fullPackage = ""; }
|
|
212 |
| } |
|
213 |
4
| return fullPackage;
|
|
214 |
| } |
|
215 |
44
| public String getClassName() { return str; }
|
|
216 |
1311
| public String toString() { return str; }
|
|
217 |
68
| public OpenDefinitionsDocument getOpenDefinitionsDocument() { return doc; }
|
|
218 |
| } |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| public static class JavaAPIListEntry extends AutoCompletePopupEntry { |
|
224 |
| private final String str, fullStr; |
|
225 |
| private final URL url; |
|
226 |
3279
| public JavaAPIListEntry(String s, String full, URL u) {
|
|
227 |
3279
| str = s;
|
|
228 |
3279
| fullStr = full;
|
|
229 |
3279
| url = u;
|
|
230 |
| } |
|
231 |
0
| public String toString() { return str; }
|
|
232 |
0
| public String getFullString() { return fullStr; }
|
|
233 |
0
| public URL getURL() { return url; }
|
|
234 |
3279
| public String getClassName() { return str; }
|
|
235 |
3279
| public String getFullPackage() {
|
|
236 |
3279
| int pos = fullStr.lastIndexOf('.');
|
|
237 |
3279
| if (pos>=0) { return fullStr.substring(0,pos+1); }
|
|
238 |
0
| return "";
|
|
239 |
| } |
|
240 |
0
| public OpenDefinitionsDocument getOpenDefinitionsDocument() { return null; }
|
|
241 |
| } |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
| |
|
247 |
| |
|
248 |
152
| public static JMenuItem newCheckBoxMenuItem(Action action) {
|
|
249 |
152
| String RADIO_ICON_KEY = "RadioButtonMenuItem.checkIcon";
|
|
250 |
152
| String CHECK_ICON_KEY = "CheckBoxMenuItem.checkIcon";
|
|
251 |
| |
|
252 |
| |
|
253 |
152
| Object radioIcon = UIManager.get(RADIO_ICON_KEY);
|
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
152
| UIManager.put(RADIO_ICON_KEY, UIManager.get(CHECK_ICON_KEY));
|
|
258 |
152
| JRadioButtonMenuItem pseudoCheckBox = new JRadioButtonMenuItem(action);
|
|
259 |
| |
|
260 |
| |
|
261 |
152
| UIManager.put(RADIO_ICON_KEY, radioIcon);
|
|
262 |
| |
|
263 |
152
| return pseudoCheckBox;
|
|
264 |
| } |
|
265 |
| } |