View Javadoc

1   package org.lsst.ccs.plugin.jas3.tutorial;
2   
3   import java.io.IOException;
4   import javax.swing.ImageIcon;
5   import javax.swing.JOptionPane;
6   import org.freehep.application.studio.Studio;
7   import org.freehep.util.commanddispatcher.BooleanCommandState;
8   import org.freehep.util.commanddispatcher.CommandProcessor;
9   import org.freehep.util.commanddispatcher.CommandState;
10  
11  /**
12   * A command processor makes it easy to have methods called when user selects
13   * menu or toolbar items. It also provides facilities for enabling/disabling
14   * menu or toolbar items, and handling checkboxes or toggle buttons.
15   *
16   * @author tonyj
17   */
18  public class TutorialCommands extends CommandProcessor {
19  
20      private Studio studio;
21      private TutorialConsole tutorialConsole;
22      private boolean chooseMeEnabled = true;
23      
24      public TutorialCommands(Studio studio) {
25          this.studio = studio;
26          this.tutorialConsole = new TutorialConsole(studio);
27      }
28  
29      /*
30       * Methods of the form onXXX will be called when the XXX command is activated, 
31       * typically by selecting a menu item defined in a ".menus" file with command="XXX".
32       */
33      public void onChooseMe() {
34          JOptionPane.showMessageDialog(studio, "Choose Me was activated");
35      }
36      /*
37       * onXXX commands can be optionally paired with enableXXX methods which can 
38       * be used to enable or disable the XXX command.
39       */
40      public void enableChooseMe(CommandState state) {
41          state.setEnabled(chooseMeEnabled);
42      }
43      /*
44       * An example illustrating how a checkbox can be used in a toolbar or menu.
45       * In this case the button is used to control the enabled/disabled state of
46       * the ChooseMe button.
47       */
48      public void onEnableChooseMe(boolean onOff) {
49          chooseMeEnabled = onOff;
50          // Whenever the enabled/disabled state of an item is changed, setChanged()
51          // must be called to update the menus.
52          setChanged();
53      }
54      /*
55       * In the case of a checkbox or toggle button, the enable method is used both
56       * to enable/disable the corresponding menu item, and to set the state of its
57       * toggle.
58       */
59      public void enableEnableChooseMe(BooleanCommandState state) {
60          // Not really necessary since this is the default anyway
61          state.setEnabled(true);
62          state.setSelected(chooseMeEnabled);
63      }
64  
65      public void onOpenTutorialPage() {
66          ImageIcon icon = new ImageIcon(getClass().getResource("Letter T.png"));
67          studio.getPageManager().openPage(new TutorialPage(), "Tutorial", icon);
68      }
69  
70      public void onOpenAdvancedTutorialPage() {
71          
72          ImageIcon icon = new ImageIcon(getClass().getResource("Letter A.png"));
73          studio.getPageManager().openPage(new AdvancedTutorialPage(), "Advanced", icon);
74      }
75      
76      public void onCreateDemoOutputConsole() throws IOException {
77          tutorialConsole.createOutputConsole();
78      }
79  
80      public void onCreateDemoInputConsole() throws IOException {
81          tutorialConsole.createInputConsole();
82      }
83  
84      public void onCreateDemoInputOutputConsole() throws IOException {
85          tutorialConsole.createInputOutputConsole();
86      }
87  }