mwomack     2003/03/12 22:19:22

  Modified:    src/java/org/apache/log4j/chainsaw ChainsawAppender.java
                        Main.java Start.java
  Added:       src/java/org/apache/log4j/chainsaw ChainsawViewer.java
                        DefaultViewer.java
  Log:
  Changes to support generic gui viewers in ChainsawAppender.  ChainsawAppender 
compatible viewers must implement the ChainsawViewer interface.
  Moved gui related code from Main.java into DefaultViewer.java, and added 
implementation of ChainsawViewer interface.
  Start.java creates a default ChainsawAppender if no configuration file is specified.
  
  Revision  Changes    Path
  1.5       +42 -0     
jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawAppender.java
  
  Index: ChainsawAppender.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawAppender.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ChainsawAppender.java     13 Mar 2003 06:00:01 -0000      1.4
  +++ ChainsawAppender.java     13 Mar 2003 06:19:21 -0000      1.5
  @@ -53,6 +53,7 @@
   
   import org.apache.log4j.AppenderSkeleton;
   import org.apache.log4j.spi.LoggingEvent;
  +import org.apache.log4j.helpers.OptionConverter;
   
   
   /**
  @@ -87,6 +88,11 @@
     private static ChainsawAppender sSharedAppender = null;
   
     /**
  +   * The classname of the viewer to create to view the events.
  +   */
  +  private String viewerClassname;
  +
  +  /**
      * Constructor, initialises the singleton instance of the appender
      */
     public ChainsawAppender() {
  @@ -163,12 +169,48 @@
       }
     }
   
  +  /**
  +   * Instantiates and activates an instance of a ChainsawViewer
  +   * to view the contents of this appender.
  +   */
  +  public void activateOptions() {
  +    if (viewerClassname == null) {
  +      viewerClassname = DefaultViewer.class.getName();
  +    }
  +      
  +    ChainsawViewer viewer = 
  +      (ChainsawViewer) OptionConverter.instantiateByClassName(viewerClassname, 
  +        ChainsawViewer.class, null);
  +        
  +    if (viewer != null) {
  +      viewer.activateViewer(this);
  +    }
  +  }
   
     /**
      * Close does nothing
      */
     public void close() {
       /** @todo  perhaps it should clear the internal TableModel */
  +  }
  +
  +  /**
  +   * Sets the viewer class to use to view the events.  The class must
  +   * implement the ChainsawViewer interface.
  +   *
  +   * @param classname The class name of the viewer class.
  +   */
  +  public void setViewerClass(String classname) {
  +    viewerClassname = classname;
  +  }
  +
  +  /**
  +   * Gets the viewer class to use to view the events.
  +   *
  +   * @return The class name of the viewer class.
  +   */
  +  public String getViewerClass() {
  +    return viewerClassname;
     }
   
     // ==========================================================================
  
  
  
  1.8       +4 -214    jakarta-log4j/src/java/org/apache/log4j/chainsaw/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/Main.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Main.java 11 Mar 2003 05:22:49 -0000      1.7
  +++ Main.java 13 Mar 2003 06:19:21 -0000      1.8
  @@ -49,228 +49,18 @@
   
   package org.apache.log4j.chainsaw;
   
  -import java.awt.BorderLayout;
  -import java.awt.Dimension;
  -import java.awt.event.ActionEvent;
  -import java.awt.event.ActionListener;
  -import java.awt.event.WindowAdapter;
  -import java.awt.event.WindowEvent;
  -
  -import javax.swing.BorderFactory;
  -import javax.swing.JFrame;
  -import javax.swing.JMenu;
  -import javax.swing.JMenuBar;
  -import javax.swing.JMenuItem;
  -import javax.swing.JOptionPane;
  -import javax.swing.JPanel;
  -import javax.swing.JScrollPane;
  -import javax.swing.JSplitPane;
  -import javax.swing.JTable;
  -import javax.swing.ListSelectionModel;
  -import javax.swing.table.TableColumnModel;
  -import javax.swing.table.TableModel;
  -
  -
   /**
    * The main application.
    *
  + * @deprecated, should be started from the Start class
    * @author <a href="mailto:[EMAIL PROTECTED]">Oliver Burn</a>
    */
  -public class Main extends JFrame {
  -  /** Window x-position property */
  -  public static final String X_POSITION_PROPERTY =
  -    Preferences.PROP_PREFIX + ".x";
  -
  -  /** Window y-position property */
  -  public static final String Y_POSITION_PROPERTY =
  -    Preferences.PROP_PREFIX + ".y";
  -
  -  /** Window width property */
  -  public static final String WIDTH_PROPERTY =
  -    Preferences.PROP_PREFIX + ".width";
  -
  -  /** Window height property */
  -  public static final String HEIGHT_PROPERTY =
  -    Preferences.PROP_PREFIX + ".height";
  -
  -  /** Details/table separator position property */
  -  public static final String DETAILS_SEPARATOR_PROPERTY =
  -    Preferences.PROP_PREFIX + ".details.separator";
  -  private static final Preferences PREFS = Preferences.getInstance();
  -  private JSplitPane mDetailsDivider;
  -  private final MyTableColumnModel mColumnModel;
  -
  -  /**
  - * Creates a new <code>Main</code> instance.
  - */
  -  public Main() {
  -    super("CHAINSAW - Log4J Log Viewer");
  -
  -    ExitAction.INSTANCE.addShutdownHook(new Thread(new Shutdown()));
  -
  -    // create the all important models
  -    final ChainsawAppender model = ChainsawAppender.getInstance();
  -    mColumnModel = new MyTableColumnModel(model);
  -
  -    buildMenus(model);
  -    buildComponents(model);
  -
  -    addWindowListener(
  -      new WindowAdapter() {
  -        public void windowClosing(WindowEvent aEvent) {
  -          ExitAction.INSTANCE.actionPerformed(null);
  -        }
  -      });
  -
  -    loadGuiPrefs();
  -    setVisible(true);
  -  }
  -
  +public class Main {
     /**
  -   * Constructs the JTable used for displaying the Events logs
  -   * @param tableModel
  -   * @param tableColumnModel
  -   * @return
  +   * @deprecated, should be started from the Start class
  +   * @param args
      */
  -  private JTable buildTable(
  -    TableModel tableModel, TableColumnModel tableColumnModel) {
  -    final JTable table = new JTable(tableModel, mColumnModel);
  -    table.setAutoCreateColumnsFromModel(true);
  -    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  -
  -    return table;
  -  }
  -
  -  /**
  - * Constructs all the components required for this frame
  - * and attaches the ChainsawAppender to components that require it
  - * @param model
  - */
  -  private void buildComponents(ChainsawAppender model) {
  -    // Add control panel
  -    final ControlPanel cp = new ControlPanel(model.getWrappedModel());
  -    getContentPane().add(cp, BorderLayout.NORTH);
  -
  -    // Create the table
  -    final JTable table = buildTable(model, mColumnModel);
  -    final JScrollPane scrollPane = new JScrollPane(table);
  -    scrollPane.setBorder(BorderFactory.createTitledBorder("Events: "));
  -    scrollPane.setPreferredSize(new Dimension(900, 300));
  -
  -    // Create the details
  -    final JPanel details = new DetailPanel(table, model.getWrappedModel());
  -    details.setPreferredSize(new Dimension(900, 100));
  -
  -    // Add the table and stack trace into a splitter
  -    mDetailsDivider =
  -      new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, details);
  -    getContentPane().add(mDetailsDivider, BorderLayout.CENTER);
  -  }
  -
  -  /**
  - * Initialises the Menu bar for this frame, and bind
  - * actions
  - * @param eventSink
  - */
  -  private void buildMenus(EventDetailSink eventSink) {
  -    //Create the menu bar.
  -    final JMenuBar menuBar = new JMenuBar();
  -    setJMenuBar(menuBar);
  -
  -    final JMenu menu = new JMenu("File");
  -    menu.setMnemonic('F');
  -    menuBar.add(menu);
  -
  -    try {
  -      final LoadXMLAction lxa = new LoadXMLAction(this, eventSink);
  -      final JMenuItem loadMenuItem = new JMenuItem("Load file...");
  -      loadMenuItem.setMnemonic('L');
  -      menu.add(loadMenuItem);
  -      loadMenuItem.addActionListener(lxa);
  -    } catch (NoClassDefFoundError e) {
  -      System.err.println("Missing classes for XML parser :" + e);
  -      JOptionPane.showMessageDialog(
  -        this, "XML parser not in classpath - unable to load XML events.",
  -        "CHAINSAW", JOptionPane.ERROR_MESSAGE);
  -    } catch (Exception e) {
  -      System.err.println(
  -        "Unable to create the action to load XML files:" + e.getMessage());
  -      JOptionPane.showMessageDialog(
  -        this, "Unable to create a XML parser - unable to load XML events.",
  -        "CHAINSAW", JOptionPane.ERROR_MESSAGE);
  -    }
  -
  -    final RecentFilesMenu recent = new RecentFilesMenu(eventSink);
  -    recent.setMnemonic('R');
  -    menu.add(recent);
  -    PREFS.setRecentFilesMenu(recent);
  -    recent.rebuild();
  -
  -    final JMenuItem prefsMenuItem = new JMenuItem("Preferences");
  -    prefsMenuItem.setMnemonic('P');
  -    menu.add(prefsMenuItem);
  -    prefsMenuItem.addActionListener(
  -      new ActionListener() {
  -        public void actionPerformed(ActionEvent ae) {
  -          new PreferencesDialog(Main.this, mColumnModel).show();
  -        }
  -      });
  -
  -    final JMenuItem exitMenuItem = new JMenuItem("Exit");
  -    exitMenuItem.setMnemonic('x');
  -    menu.add(exitMenuItem);
  -    exitMenuItem.addActionListener(ExitAction.INSTANCE);
  -  }
  -
  -  private void loadGuiPrefs() {
  -    // table prefs
  -    mColumnModel.loadPrefs();
  -
  -    final int divider = PREFS.getInteger(DETAILS_SEPARATOR_PROPERTY, -1);
  -
  -    if (divider > 0) {
  -      mDetailsDivider.setDividerLocation(divider);
  -    }
  -
  -    final int x = PREFS.getInteger(X_POSITION_PROPERTY, 0);
  -    final int y = PREFS.getInteger(Y_POSITION_PROPERTY, 0);
  -    setLocation(x, y);
  -
  -    final int width = PREFS.getInteger(WIDTH_PROPERTY, 0);
  -    final int height = PREFS.getInteger(HEIGHT_PROPERTY, 0);
  -
  -    if ((width > 0) && (height > 0)) {
  -      setSize(width, height);
  -    } else {
  -      pack();
  -    }
  -  }
  -
  -  private void saveGuiPrefs() {
  -    mColumnModel.savePrefs();
  -
  -    PREFS.setInteger(
  -      DETAILS_SEPARATOR_PROPERTY, mDetailsDivider.getDividerLocation());
  -    PREFS.setInteger(X_POSITION_PROPERTY, getX());
  -    PREFS.setInteger(Y_POSITION_PROPERTY, getY());
  -    PREFS.setInteger(WIDTH_PROPERTY, getWidth());
  -    PREFS.setInteger(HEIGHT_PROPERTY, getHeight());
  -  }
  -
  -  /**
  - * @deprecated, should be started from the Start class
  - * @param args
  - */
     public static void main(String[] args) {
       Start.main(args);
  -  }
  -
  -  ////////////////////////////////////////////////////////////////////////////
  -  // static methods
  -  ////////////////////////////////////////////////////////////////////////////
  -  private class Shutdown implements Runnable {
  -    public void run() {
  -      saveGuiPrefs();
  -    }
     }
   }
  
  
  
  1.4       +14 -4     jakarta-log4j/src/java/org/apache/log4j/chainsaw/Start.java
  
  Index: Start.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/Start.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Start.java        11 Mar 2003 04:18:34 -0000      1.3
  +++ Start.java        13 Mar 2003 06:19:21 -0000      1.4
  @@ -49,6 +49,8 @@
   
   package org.apache.log4j.chainsaw;
   
  +import org.apache.log4j.LogManager;
  +import org.apache.log4j.Level;
   import org.apache.log4j.xml.DOMConfigurator;
   
   import java.io.File;
  @@ -74,14 +76,23 @@
   
     public static void main(String[] args) {
       initLog4J();
  -    new Main();
     }
   
     private static void initLog4J() {
       /** initialise log4j **/
       final FinderStrategies strategies = new FinderStrategies();
       final URL url = strategies.findConfiguration();
  -    DOMConfigurator.configure(url);
  +    
  +    // if a configuration file is specified, use it.
  +    if (url != null) {
  +      DOMConfigurator.configure(url);
  +    // else no configuration specified, create an instance to use
  +    } else {
  +      LogManager.getLogger("org.apache.log4j.chainsaw").setLevel(Level.INFO);
  +      ChainsawAppender appender = new ChainsawAppender();
  +      LogManager.getRootLogger().addAppender(appender);
  +      appender.activateOptions();
  +    }
     }
   
     private static class FinderStrategies implements Log4JConfigurationFinder {
  @@ -106,8 +117,7 @@
           }
         }
   
  -      throw new RuntimeException(
  -        "Failed to locate a Log4J configuration" + " via any means");
  +      return null;
       }
     }
   
  
  
  
  1.1                  
jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawViewer.java
  
  Index: ChainsawViewer.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
   
  package org.apache.log4j.chainsaw;
  
  /**
    Chainsaw compatible gui viewers must implement this interface
    in order to be opened and configured by the ChainsawAppender class.
    
    @author Mark Womack
  */
  public interface ChainsawViewer {
    
    /**
      Called when the viewer should activate.
      
      @param model The ChainsawAppender model instance the viewer should use. */
    void activateViewer(ChainsawAppender model);
  }
  
  
  1.1                  
jakarta-log4j/src/java/org/apache/log4j/chainsaw/DefaultViewer.java
  
  Index: DefaultViewer.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.chainsaw;
  
  import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  
  import javax.swing.BorderFactory;
  import javax.swing.JFrame;
  import javax.swing.JMenu;
  import javax.swing.JMenuBar;
  import javax.swing.JMenuItem;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JSplitPane;
  import javax.swing.JTable;
  import javax.swing.ListSelectionModel;
  import javax.swing.table.TableColumnModel;
  import javax.swing.table.TableModel;
  
  
  /**
   * The default viewer.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Oliver Burn</a>
   */
  public class DefaultViewer extends JFrame implements ChainsawViewer {
    /** Window x-position property */
    public static final String X_POSITION_PROPERTY =
      Preferences.PROP_PREFIX + ".x";
  
    /** Window y-position property */
    public static final String Y_POSITION_PROPERTY =
      Preferences.PROP_PREFIX + ".y";
  
    /** Window width property */
    public static final String WIDTH_PROPERTY =
      Preferences.PROP_PREFIX + ".width";
  
    /** Window height property */
    public static final String HEIGHT_PROPERTY =
      Preferences.PROP_PREFIX + ".height";
  
    /** Details/table separator position property */
    public static final String DETAILS_SEPARATOR_PROPERTY =
      Preferences.PROP_PREFIX + ".details.separator";
    private static final Preferences PREFS = Preferences.getInstance();
    private JSplitPane aDetailsDivider;
    private MyTableColumnModel mColumnModel;
  
    /**
     * Creates a new <code>Main</code> instance.
     */
    public DefaultViewer() {
      super("CHAINSAW - Log4J Log Viewer");
    }
  
    public void activateViewer(ChainsawAppender model) {
      ExitAction.INSTANCE.addShutdownHook(new Thread(new Shutdown()));
  
      // create the all important models
      mColumnModel = new MyTableColumnModel(model);
  
      buildMenus(model);
      buildComponents(model);
  
      addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent aEvent) {
            ExitAction.INSTANCE.actionPerformed(null);
          }
        });
  
      loadGuiPrefs();
      setVisible(true);
    }
    /**
     * Constructs the JTable used for displaying the Events logs
     * @param tableModel
     * @param tableColumnModel
     * @return
     */
    private JTable buildTable(
      TableModel tableModel, TableColumnModel tableColumnModel) {
      final JTable table = new JTable(tableModel, mColumnModel);
      table.setAutoCreateColumnsFromModel(true);
      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  
      return table;
    }
  
    /**
     * Constructs all the components required for this frame
     * and attaches the ChainsawAppender to components that require it
     * @param model
     */
    private void buildComponents(ChainsawAppender model) {
      // Add control panel
      final ControlPanel cp = new ControlPanel(model.getWrappedModel());
      getContentPane().add(cp, BorderLayout.NORTH);
  
      // Create the table
      final JTable table = buildTable(model, mColumnModel);
      final JScrollPane scrollPane = new JScrollPane(table);
      scrollPane.setBorder(BorderFactory.createTitledBorder("Events: "));
      scrollPane.setPreferredSize(new Dimension(900, 300));
  
      // Create the details
      final JPanel details = new DetailPanel(table, model.getWrappedModel());
      details.setPreferredSize(new Dimension(900, 100));
  
      // Add the table and stack trace into a splitter
      aDetailsDivider =
        new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, details);
      getContentPane().add(aDetailsDivider, BorderLayout.CENTER);
    }
  
    /**
     * Initialises the Menu bar for this frame, and bind
     * actions
     * @param eventSink
     */
    private void buildMenus(EventDetailSink eventSink) {
      //Create the menu bar.
      final JMenuBar menuBar = new JMenuBar();
      setJMenuBar(menuBar);
  
      final JMenu menu = new JMenu("File");
      menu.setMnemonic('F');
      menuBar.add(menu);
  
      try {
        final LoadXMLAction lxa = new LoadXMLAction(this, eventSink);
        final JMenuItem loadMenuItem = new JMenuItem("Load file...");
        loadMenuItem.setMnemonic('L');
        menu.add(loadMenuItem);
        loadMenuItem.addActionListener(lxa);
      } catch (NoClassDefFoundError e) {
        System.err.println("Missing classes for XML parser :" + e);
        JOptionPane.showMessageDialog(
          this, "XML parser not in classpath - unable to load XML events.",
          "CHAINSAW", JOptionPane.ERROR_MESSAGE);
      } catch (Exception e) {
        System.err.println(
          "Unable to create the action to load XML files:" + e.getMessage());
        JOptionPane.showMessageDialog(
          this, "Unable to create a XML parser - unable to load XML events.",
          "CHAINSAW", JOptionPane.ERROR_MESSAGE);
      }
  
      final RecentFilesMenu recent = new RecentFilesMenu(eventSink);
      recent.setMnemonic('R');
      menu.add(recent);
      PREFS.setRecentFilesMenu(recent);
      recent.rebuild();
  
      final JMenuItem prefsMenuItem = new JMenuItem("Preferences");
      prefsMenuItem.setMnemonic('P');
      menu.add(prefsMenuItem);
      prefsMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            new PreferencesDialog(DefaultViewer.this, mColumnModel).show();
          }
        });
  
      final JMenuItem exitMenuItem = new JMenuItem("Exit");
      exitMenuItem.setMnemonic('x');
      menu.add(exitMenuItem);
      exitMenuItem.addActionListener(ExitAction.INSTANCE);
    }
  
    private void loadGuiPrefs() {
      // table prefs
      mColumnModel.loadPrefs();
  
      final int divider = PREFS.getInteger(DETAILS_SEPARATOR_PROPERTY, -1);
  
      if (divider > 0) {
        aDetailsDivider.setDividerLocation(divider);
      }
  
      final int x = PREFS.getInteger(X_POSITION_PROPERTY, 0);
      final int y = PREFS.getInteger(Y_POSITION_PROPERTY, 0);
      setLocation(x, y);
  
      final int width = PREFS.getInteger(WIDTH_PROPERTY, 0);
      final int height = PREFS.getInteger(HEIGHT_PROPERTY, 0);
  
      if ((width > 0) && (height > 0)) {
        setSize(width, height);
      } else {
        pack();
      }
    }
  
    private void saveGuiPrefs() {
      mColumnModel.savePrefs();
  
      PREFS.setInteger(
        DETAILS_SEPARATOR_PROPERTY, aDetailsDivider.getDividerLocation());
      PREFS.setInteger(X_POSITION_PROPERTY, getX());
      PREFS.setInteger(Y_POSITION_PROPERTY, getY());
      PREFS.setInteger(WIDTH_PROPERTY, getWidth());
      PREFS.setInteger(HEIGHT_PROPERTY, getHeight());
    }
  
    ////////////////////////////////////////////////////////////////////////////
    // static methods
    ////////////////////////////////////////////////////////////////////////////
    private class Shutdown implements Runnable {
      public void run() {
        saveGuiPrefs();
      }
    }
  }
  
  
  

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

Reply via email to