JScrollPane scrollPane = new JScrollPane(controlPanel);
left.add(scrollPane, BorderLayout.CENTER);
// Create a JTextAreaExec without Start and Cancel buttons.
final JTextAreaExec exec = new JTextAreaExec(
"Code Generator Commands", false);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
left, exec);
splitPane.setOneTouchExpandable(true);
// Adjust the divider so that the control panel does not
// have a horizontal scrollbar.
Dimension preferred = left.getPreferredSize();
splitPane.setDividerLocation(preferred.width + 20);
getContentPane().add(splitPane, BorderLayout.CENTER);
// ActionListeners for the buttons
parametersButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
options.sanityCheckAndUpdateParameters(null);
} catch (Exception ex) {
exec.appendJTextArea(ex.toString());
}
exec.appendJTextArea(options.toString());
}
});
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exec.cancel();
}
});
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exec.clear();
}
});
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
// The code generator to run. The value of this
// parameter should name a subdirectory of
// ptolemy/copernicus such as "java" or "shallow".
String codeGenerator = options
.getParameter("codeGenerator");
String targetPath = options.getParameter("targetPath");
String ptIIUserDirectory = options
.getParameter("ptIIUserDirectory");
// Check that we will be able to write
File directory = new File(ptIIUserDirectory, targetPath);
if (!directory.isDirectory()) {
throw new IllegalActionException(model,
"Not a directory: " + ptIIUserDirectory
+ "/" + targetPath
+ "\n.Try hitting the "
+ "Parameters button to "
+ "create the directory.");
}
if (!directory.canWrite()) {
throw new IllegalActionException(model,
"Can't write: " + ptIIUserDirectory + "/"
+ targetPath);
}
exec.updateStatusBar("Starting " + codeGenerator
+ " code generation.");
// Run the code generator in a separate process
try {
List commands = _generateCodeGeneratorCommands(
model, options, codeGenerator);
exec.setCommands(commands);
exec.start();
} catch (Exception ex) {
throw new IllegalActionException(model, ex, null);
}
// FIXME: Above is asynchronous: Do in listener?
exec.updateStatusBar("Code generation " + "complete.");
} catch (Exception ex) {
MessageHandler.error("Code generation failed.", ex);
}
}
});