psmith      2003/09/23 16:13:14

  Modified:    src/java/org/apache/log4j/chainsaw/help tutorial.html
                        Tutorial.java
               src/java/org/apache/log4j/chainsaw LogUI.java
  Log:
  Tutorial dialog now has a toolbar to start/stop the tutorial.
  
  These actions are now encapsulated as proper Swing actions, with
  the buttons tracking their state correctly.
  
  Revision  Changes    Path
  1.4       +2 -2      
jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/tutorial.html
  
  Index: tutorial.html
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/tutorial.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- tutorial.html     23 Sep 2003 04:10:01 -0000      1.3
  +++ tutorial.html     23 Sep 2003 23:13:14 -0000      1.4
  @@ -21,7 +21,7 @@
   <li><img src="../icons/TipOfTheDay16.gif" alt="Interesting...">If you would like to 
read more about Receivers first, then click here. <font 
color="red"><b>(TODO)</b></font></li>
   </ul>
   <hr>
  -<p><b>When you are ready to begin the tutorial, <a href="StartTutorial">click 
here</a>.</b></p>
  +<p><b>When you are ready to begin the tutorial, <a href="StartTutorial">click 
here</a>, or click the "Start Tutorial" button in this dialog's toolbar.</b></p>
   <hr>
   <h2>Receivers</h2>
   <p>After you have said yes to the confirmation dialog, you should see 3 new tabs 
appear 
  @@ -112,7 +112,7 @@
   <ul>
   <li><img src="../icons/Help16.gif" alt="Try this...">Show the Receivers panel () 
and shutdown each of the Generator Receivers by using the <img 
src="../icons/Stop16.gif" alt="Stop"> icon.</li>
   </ul>
  -<p>For convenience you can simply <a href="StopTutorial">click here</a>, and 
Chainsaw will stop all the tutorial generators for you (If you created any other 
non-Generator Receivers, they will be left untouched).</p>
  +<p>For convenience you can simply <a href="StopTutorial">click here</a> or click on 
the Stop Tutorial button in this dialogs toolbar, and Chainsaw will stop all the 
tutorial generators for you (If you created any other non-Generator Receivers, they 
will be left untouched).</p>
   </p>
   <hr>
   <PRE>Transmission Ends</PRE>
  
  
  
  1.3       +0 -8      
jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/Tutorial.java
  
  Index: Tutorial.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/Tutorial.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Tutorial.java     22 Sep 2003 06:55:27 -0000      1.2
  +++ Tutorial.java     23 Sep 2003 23:13:14 -0000      1.3
  @@ -53,8 +53,6 @@
   import org.apache.log4j.plugins.Plugin;
   import org.apache.log4j.plugins.PluginRegistry;
   
  -import javax.swing.JOptionPane;
  -
   
   /**
    * A runnable element that installs into the Log4j environment some fake Receivers
  @@ -67,17 +65,11 @@
      * @see java.lang.Runnable#run()
      */
     public void run() {
  -    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) {
         Plugin p1 = new Generator("Generator 1");
         Plugin p2 = new Generator("Generator 2");
         Plugin p3 = new Generator("Generator 3");
         PluginRegistry.startPlugin(p1);
         PluginRegistry.startPlugin(p2);
         PluginRegistry.startPlugin(p3);
  -    }
     }
   }
  
  
  
  1.35      +85 -15    jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- LogUI.java        23 Sep 2003 04:09:13 -0000      1.34
  +++ LogUI.java        23 Sep 2003 23:13:14 -0000      1.35
  @@ -631,36 +631,98 @@
       final JEditorPane tutorialArea = new JEditorPane();
       tutorialArea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
       tutorialArea.setEditable(false);
  +    container.setLayout(new BorderLayout());
   
       try {
         tutorialArea.setPage(getWelcomePanel().getTutorialURL());
  -      container.add(new JScrollPane(tutorialArea));
  +      container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER);
       } catch (Exception e) {
         LogLog.error("Error occurred loading the Tutorial", e);
       }
   
       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() {
  +                  List list =
  +                    PluginRegistry.getPlugins(
  +                      LogManager.getLoggerRepository(), Generator.class);
  +
  +                  for (Iterator iter = list.iterator(); iter.hasNext();) {
  +                    Plugin plugin = (Plugin) iter.next();
  +                    PluginRegistry.stopPlugin(plugin);
  +                  }
  +                }
  +              }).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")) == Boolean.TRUE);
  +          startButton.setSelected(stopTutorial.isEnabled());
  +        }
  +      };
  +
  +    startTutorial.addPropertyChangeListener(pcl);
  +    stopTutorial.addPropertyChangeListener(pcl);
  +
  +    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")) {
  -              new Thread(new Tutorial()).start();
  +              startTutorial.actionPerformed(null);
               } else if (e.getDescription().equals("StopTutorial")) {
  -              new Thread(
  -                new Runnable() {
  -                  public void run() {
  -                    List list =
  -                      PluginRegistry.getPlugins(
  -                        LogManager.getLoggerRepository(), Generator.class);
  -
  -                    for (Iterator iter = list.iterator(); iter.hasNext();) {
  -                      Plugin plugin = (Plugin) iter.next();
  -                      PluginRegistry.stopPlugin(plugin);
  -                    }
  -                  }
  -                }).start();
  +              stopTutorial.actionPerformed(null);
               } else {
                 try {
                   tutorialArea.setPage(e.getURL());
  @@ -1100,6 +1162,14 @@
      * @param string The FQN of the LookANdFeel
      */
     private void applyLookAndFeel(String lookAndFeelClassName) {
  +    if (
  +      UIManager.getLookAndFeel().getClass().getName().equals(
  +          lookAndFeelClassName)) {
  +      LogLog.debug("No need to change L&F, already the same");
  +
  +      return;
  +    }
  +
       LogLog.debug("Setting L&F -> " + lookAndFeelClassName);
   
       try {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to