JButton moreInfoButton = new JButton("More Info");
moreInfoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
Configuration configuration = getConfiguration();
// FIXME: Customize to the particular code generator.
// Use Thread.currentThread() so that this code will
// work under WebStart.
URL infoURL = Thread.currentThread()
.getContextClassLoader().getResource(
"ptolemy/codegen/README.html");
configuration.openModel(null, infoURL, infoURL
.toExternalForm());
} catch (Exception ex) {
throw new InternalErrorException(codeGenerator, ex,
"Failed to open doc/codegen.htm: ");
}
}
});
caveatsPanel.add(moreInfoButton);
JPanel left = new JPanel();
left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
caveatsPanel.setMaximumSize(new Dimension(500, 100));
left.add(caveatsPanel);
// Panel for push buttons.
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 4));
JButton goButton = new JButton("Generate");
goButton.setToolTipText("Generate code");
buttonPanel.add(goButton);
JButton stopButton = new JButton("Cancel");
stopButton.setToolTipText("Terminate executing processes");
buttonPanel.add(stopButton);
JButton clearButton = new JButton("Clear");
clearButton.setToolTipText("Clear Log");
buttonPanel.add(clearButton);
buttonPanel.setMaximumSize(new Dimension(500, 50));
left.add(buttonPanel);
Configurer configurer = new Configurer(codeGenerator);
JPanel controlPanel = new JPanel();
controlPanel.add(configurer);
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);
// If we execute any commands, print the output in the text area.
codeGenerator.setExecuteCommands(exec);
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);
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 {
exec.updateStatusBar("// Starting " + codeGenerator
+ " code generation.");
StringBuffer code = new StringBuffer();
codeGenerator.generateCode(code);
String codeFileNameWritten = codeGenerator
.getCodeFileName();
if (codeFileNameWritten != null) {
Configuration configuration = getConfiguration();
URL codeURL = new File(codeFileNameWritten).toURI()
.toURL();
// Use Thread.currentThread() so that this code will
// work under WebStart.
configuration.openModel(null, codeURL, codeURL
.toExternalForm());
}
// Don't write the file to the window
//exec.updateStatusBar(code.toString());