logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw WelcomePanel.java
Date Thu, 19 Jun 2003 03:38:59 GMT
psmith      2003/06/18 20:38:59

  Modified:    src/java/org/apache/log4j/chainsaw WelcomePanel.java
  Log:
  Changed Welcome Panel into nearly a fully fledged browser.
  
  Added Home, and back button support.  You can now click on links in 
  the browser and they actually go somewhere!.
  
  This was a lot easier than I thought!
  
  Revision  Changes    Path
  1.6       +129 -13   jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/WelcomePanel.java
  
  Index: WelcomePanel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/WelcomePanel.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WelcomePanel.java	17 Jun 2003 20:06:51 -0000	1.5
  +++ WelcomePanel.java	19 Jun 2003 03:38:59 -0000	1.6
  @@ -49,15 +49,34 @@
   
   package org.apache.log4j.chainsaw;
   
  +import org.apache.log4j.chainsaw.icons.ChainsawIcons;
  +
  +import java.awt.BorderLayout;
   import java.awt.Color;
   import java.awt.Dimension;
  +import java.awt.FlowLayout;
  +import java.awt.GridBagConstraints;
  +import java.awt.GridBagLayout;
  +import java.awt.event.ActionEvent;
  +
  +import java.io.IOException;
  +
   import java.net.URL;
   
  +import java.util.Stack;
  +
  +import javax.swing.AbstractAction;
  +import javax.swing.Action;
   import javax.swing.BorderFactory;
   import javax.swing.BoxLayout;
  +import javax.swing.ImageIcon;
  +import javax.swing.JButton;
   import javax.swing.JEditorPane;
   import javax.swing.JPanel;
   import javax.swing.JScrollPane;
  +import javax.swing.SwingUtilities;
  +import javax.swing.event.HyperlinkEvent;
  +import javax.swing.event.HyperlinkListener;
   
   
   /**
  @@ -69,26 +88,123 @@
    * @author Scott Deboy <sdeboy@apache.org>
    */
   public class WelcomePanel extends JPanel {
  +  private Stack urlStack = new Stack();
  +  private final JEditorPane textInfo = new JEditorPane();
  +  private final URLToolbar urlToolbar =  new URLToolbar();
  +  private final URL helpURL;
  +  
     public WelcomePanel() {
  -    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  +    setLayout(new BorderLayout());
       setBackground(Color.white);
  +    add(urlToolbar, BorderLayout.NORTH);
   
  -    final URL helpURL =
  +     helpURL =
         getClass().getClassLoader().getResource(
           "org/apache/log4j/chainsaw/WelcomePanel.html");
   
       if (helpURL != null) {
  -        final JEditorPane textInfo = new JEditorPane();
  -        textInfo.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  -        textInfo.setEditable(false);
  -        textInfo.setPreferredSize(new Dimension(320, 240));
  -
  -        JScrollPane pane = new JScrollPane(textInfo);
  -        pane.setBorder(null);
  -        add(pane);
  -        try {
  -			textInfo.setPage(helpURL);
  -		} catch (Exception e) {e.printStackTrace();}
  +      textInfo.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  +      textInfo.setEditable(false);
  +      textInfo.setPreferredSize(new Dimension(320, 240));
  +
  +      JScrollPane pane = new JScrollPane(textInfo);
  +      pane.setBorder(null);
  +      add(pane, BorderLayout.CENTER);
  +
  +      try {
  +        textInfo.setPage(helpURL);
  +        textInfo.addHyperlinkListener(
  +          new HyperlinkListener() {
  +            public void hyperlinkUpdate(HyperlinkEvent e) {
  +              if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
  +                urlStack.add(textInfo.getPage());
  +
  +                try {
  +                  textInfo.setPage(e.getURL());
  +                  urlToolbar.updateToolbar();
  +                } catch (IOException e1) {
  +                  e1.printStackTrace();
  +                }
  +              }
  +            }
  +          });
  +      } catch (Exception e) {
  +        e.printStackTrace();
  +      }
  +    }
  +  }
  +  
  +  void setURL(final URL url) {
  +    SwingUtilities.invokeLater(
  +      new Runnable() {
  +        public void run() {
  +          try {
  +            textInfo.setPage(url);
  +            urlToolbar.updateToolbar();
  +          } catch (IOException e) {
  +            e.printStackTrace();
  +          }
  +        }
  +      });
  +    
  +  }
  +
  +  private class URLToolbar extends JPanel {
  +    private final Action previousAction =
  +      new AbstractAction(null, new ImageIcon(ChainsawIcons.ICON_BACK)) {
  +        public void actionPerformed(ActionEvent e) {
  +          if (urlStack.isEmpty()) {
  +            return;
  +          }
  +          setURL((URL)urlStack.pop());
  +
  +        }
  +      };
  +      
  +    private final Action homeAction =
  +      new AbstractAction(null, new ImageIcon(ChainsawIcons.ICON_HOME)) {
  +        public void actionPerformed(ActionEvent e) {
  +          if (urlStack.isEmpty()) {
  +            return;
  +          }
  +          setURL(helpURL);
  +          urlStack.clear();
  +        }
  +      };
  +
  +    private URLToolbar() {
  +      setLayout(new GridBagLayout());
  +      updateToolbar();
  +      previousAction.putValue(Action.SHORT_DESCRIPTION, "Back");
  +      homeAction.putValue(Action.SHORT_DESCRIPTION, "Home");
  +
  +      GridBagConstraints c = new GridBagConstraints();
  +      c.weightx = 0.0;
  +      c.weighty = 0.0;
  +      c.ipadx = 1;
  +      c.ipady = 1;
  +      c.gridx = 0;
  +      c.gridy = 0;
  +      
  +      c.fill = GridBagConstraints.NONE;
  +      c.anchor = GridBagConstraints.WEST;
  +      
  +      JButton home = new SmallButton(homeAction);
  +      add(home, c);
  +      
  +      c.gridx = 1;
  +      JButton previous = new SmallButton(previousAction);
  +      previous.setEnabled(false);
  +      add(previous, c);
  +
  +      c.gridx = 2;
  +      c.weightx = 1;
  +      JPanel p = new JPanel();
  +      add(p, c);
  +    }
  +
  +    void updateToolbar() {
  +      previousAction.setEnabled(!urlStack.isEmpty());
       }
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Mime
View raw message