Action dumpAction = new AbstractAction(getResourceString("DumpReferenceFrequencies")) {
private static final long serialVersionUID = -3222695625267056652L;
public void actionPerformed(ActionEvent evt) {
SourceMetrics workspaceSourceMetrics = perspective.getWorkspace().getSourceMetrics();
DumpOptionChooser chooser = new DumpOptionChooser();
int fileResponse = chooser.showSaveDialog(GemCutter.this);
// If the user closed the dialog or hit cancel, do nothing
// If they didn't, then remember their option selections for next time.
if (fileResponse == JFileChooser.CANCEL_OPTION || fileResponse == JFileChooser.ERROR_OPTION) {
return;
}
chooser.savePreferences();
ModuleFilter moduleFilter;
if (chooser.shouldFilterTestModules()) {
moduleFilter = new ExcludeTestModulesFilter(getWorkspace());
} else {
moduleFilter = new AcceptAllModulesFilter();
}
QualifiedNameFilter functionFilter;
if (chooser.shouldExcludeFunctionsByRegexp()) {
functionFilter = new RegExpBasedUnqualifiedNameFilter(chooser.getExcludeFunctionsRegexp(), true);
} else {
functionFilter = new AcceptAllQualifiedNamesFilter();
}
try {
FileOutputStream fos = new FileOutputStream(chooser.getSelectedFile());
PrintStream ps = new PrintStream(fos);
ps.print(workspaceSourceMetrics.dumpReferenceFrequencies(moduleFilter, functionFilter, true));
ps.close();
fos.close();
} catch(FileNotFoundException e) {
String errTitle = getResourceString("DumpFrequenciesErrorDialogTitle");
String errMessage = GemCutterMessages.getString("DumpFrequenciesErrorDialogMessage", chooser.getSelectedFile().toString());