&& applicationPreferenceModel.isShowNoReceiverWarning()) {
showNoReceiversWarningPanel();
}
Container container = tutorialFrame.getContentPane();
final JEditorPane tutorialArea = new JEditorPane();
tutorialArea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
tutorialArea.setEditable(false);
container.setLayout(new BorderLayout());
try {
tutorialArea.setPage(ChainsawConstants.TUTORIAL_URL);
container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER);
} catch (Exception e) {
MessageCenter.getInstance().getLogger().error(
"Error occurred loading the Tutorial", e);
}
tutorialFrame.setIconImage(new ImageIcon(ChainsawIcons.HELP).getImage());
tutorialFrame.setSize(new Dimension(640, 480));
final Action startTutorial =
new AbstractAction(
"Start Tutorial", new ImageIcon(ChainsawIcons.ICON_RESUME_RECEIVER)) {
public void actionPerformed(ActionEvent e) {
if (
JOptionPane.showConfirmDialog(
null,
"This will start 3 \"Generator\" receivers for use in the Tutorial. Is that ok?",
"Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
new Thread(new Tutorial()).start();
putValue("TutorialStarted", Boolean.TRUE);
} else {
putValue("TutorialStarted", Boolean.FALSE);
}
}
};
final Action stopTutorial =
new AbstractAction(
"Stop Tutorial", new ImageIcon(ChainsawIcons.ICON_STOP_RECEIVER)) {
public void actionPerformed(ActionEvent e) {
if (
JOptionPane.showConfirmDialog(
null,
"This will stop all of the \"Generator\" receivers used in the Tutorial, but leave any other Receiver untouched. Is that ok?",
"Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
new Thread(
new Runnable() {
public void run() {
PluginRegistry pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();
List list = pluginRegistry.getPlugins(Generator.class);
for (Iterator iter = list.iterator(); iter.hasNext();) {
Plugin plugin = (Plugin) iter.next();
pluginRegistry.stopPlugin(plugin.getName());
}
}
}).start();
setEnabled(false);
startTutorial.putValue("TutorialStarted", Boolean.FALSE);
}
}
};
stopTutorial.putValue(
Action.SHORT_DESCRIPTION,
"Removes all of the Tutorials Generator Receivers, leaving all other Receivers untouched");
startTutorial.putValue(
Action.SHORT_DESCRIPTION,
"Begins the Tutorial, starting up some Generator Receivers so you can see Chainsaw in action");
stopTutorial.setEnabled(false);
final SmallToggleButton startButton = new SmallToggleButton(startTutorial);
PropertyChangeListener pcl =
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
stopTutorial.setEnabled(
((Boolean) startTutorial.getValue("TutorialStarted")).equals(
Boolean.TRUE));
startButton.setSelected(stopTutorial.isEnabled());
}
};
startTutorial.addPropertyChangeListener(pcl);
stopTutorial.addPropertyChangeListener(pcl);
pluginRegistry.addPluginListener(
new PluginListener() {
public void pluginStarted(PluginEvent e) {
}
public void pluginStopped(PluginEvent e) {
List list = pluginRegistry.getPlugins(Generator.class);
if (list.size() == 0) {
startTutorial.putValue("TutorialStarted", Boolean.FALSE);
}
}
});
final SmallButton stopButton = new SmallButton(stopTutorial);
final JToolBar tutorialToolbar = new JToolBar();
tutorialToolbar.setFloatable(false);
tutorialToolbar.add(startButton);
tutorialToolbar.add(stopButton);
container.add(tutorialToolbar, BorderLayout.NORTH);
tutorialArea.addHyperlinkListener(
new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (e.getDescription().equals("StartTutorial")) {
startTutorial.actionPerformed(null);
} else if (e.getDescription().equals("StopTutorial")) {
stopTutorial.actionPerformed(null);
} else {
try {
tutorialArea.setPage(e.getURL());
} catch (IOException e1) {
MessageCenter.getInstance().getLogger().error(
"Failed to change the URL for the Tutorial", e1);
}
}