absolutePath = f.getAbsoluteFile().getCanonicalPath();
} catch (IOException e) {
logger.fatal("Cannot load testcase source", e);
return null;
}
NonWrappingTextPane textPane = activateSourceIfAlreadyLoaded(absolutePath, isTestScript);
if (!force & textPane != null) {
return textPane;
}
if (f.exists() && f.canRead()) {
StringBuffer contents = new StringBuffer();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(f));
while (in.ready()) {
contents.append(in.readLine()).append("\n");
}
boolean newTab = textPane == null;
if (textPane == null) {
textPane = new NonWrappingTextPane(isTestScript);
}
if (newTab) {
JScrollPane sp = new JScrollPane(textPane);
if (absolutePath.endsWith(".py")) {
textPane.init("text/python");
} else if (absolutePath.endsWith(".xml")) {
textPane.init("text/xml");
} else if (absolutePath.endsWith(".sh")) {
textPane.init("text/bash");
} else if (absolutePath.endsWith(".bat") || absolutePath.endsWith(".cmd")) {
textPane.init("text/dosbatch");
} else {
textPane.init("text/plain");
}
textPane.setFileName(absolutePath);
if (isTestScript) {
tcSourceTextPane = textPane;
}
textPane.setTestCasePane(this);
editorTabbedPane.addTab(f.getName(), null, sp, absolutePath);
editorTabbedPane.setSelectedIndex(editorTabbedPane.getTabCount() - 1);
textPane.addDocumentListener();
textPane.addPropertyChangeListener("isModified", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getNewValue().equals(true)) {
String currentTitle = editorTabbedPane.getTitleAt(editorTabbedPane.getSelectedIndex());
if (!currentTitle.contains("*")) {
currentTitle += " *";
editorTabbedPane.setTitleAt(editorTabbedPane.getSelectedIndex(), currentTitle);
}
} else {
String currentTitle = editorTabbedPane.getTitleAt(editorTabbedPane.getSelectedIndex());
if (currentTitle.contains(" *")) {
currentTitle = currentTitle.replace(" *", "");
editorTabbedPane.setTitleAt(editorTabbedPane.getSelectedIndex(), currentTitle);
}
}
}
});
}
setTestCaseSource(textPane, absolutePath, contents.toString(), isTestScript);
textPane.setModified(false);
textPane.clearUndos();
if (absolutePath.endsWith(".py")) {
new DebuggerShortcuts(this); // TO MOVE TO NONWRAPPINGTEXTPANE
}
new GenericShortcuts(this); // TO MOVE TO NONWRAPPINGTEXTPANE