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 ChainsawToolBarAndMenus.java LogUI.java
Date Sat, 03 May 2003 06:53:13 GMT
psmith      2003/05/02 23:53:13

  Modified:    src/java/org/apache/log4j/chainsaw LogUI.java
  Added:       src/java/org/apache/log4j/chainsaw
                        ChainsawToolBarAndMenus.java
  Log:
  Added new class ChainsawToolbarAndMenus to encapsulate all the
  Actions and the Menu's and Toolbar buttons they can belong to.
  
  Still Work In Progress.
  
  Revision  Changes    Path
  1.19      +46 -169   jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- LogUI.java	2 May 2003 16:50:35 -0000	1.18
  +++ LogUI.java	3 May 2003 06:53:13 -0000	1.19
  @@ -50,11 +50,11 @@
   package org.apache.log4j.chainsaw;
   
   import java.awt.BorderLayout;
  +import java.awt.Component;
   import java.awt.Dimension;
   import java.awt.Font;
   import java.awt.GridBagConstraints;
   import java.awt.GridBagLayout;
  -import java.awt.Insets;
   import java.awt.Point;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
  @@ -84,7 +84,6 @@
   import javax.swing.Action;
   import javax.swing.BorderFactory;
   import javax.swing.ButtonGroup;
  -import javax.swing.ImageIcon;
   import javax.swing.JButton;
   import javax.swing.JCheckBox;
   import javax.swing.JCheckBoxMenuItem;
  @@ -94,7 +93,6 @@
   import javax.swing.JFrame;
   import javax.swing.JLabel;
   import javax.swing.JMenu;
  -import javax.swing.JMenuBar;
   import javax.swing.JMenuItem;
   import javax.swing.JPanel;
   import javax.swing.JPopupMenu;
  @@ -105,7 +103,6 @@
   import javax.swing.JTabbedPane;
   import javax.swing.JTable;
   import javax.swing.JTextField;
  -import javax.swing.JToggleButton;
   import javax.swing.JToolBar;
   import javax.swing.KeyStroke;
   import javax.swing.ListSelectionModel;
  @@ -119,7 +116,6 @@
   import javax.swing.table.TableModel;
   
   import org.apache.log4j.LogManager;
  -import org.apache.log4j.chainsaw.icons.ChainsawIcons;
   
   
   /**
  @@ -140,7 +136,7 @@
     private final Map tableModelMap = new HashMap();
     private final Map tableMap = new HashMap();
     private final List names = new ArrayList();
  -  private final List pausedList = new Vector();
  +  final List pausedList = new Vector();
     private final List levelList = new ArrayList();
     private final List filterableColumns = new ArrayList();
     private final Map entryMap = new HashMap();
  @@ -156,133 +152,9 @@
      */
     public LogUI() {
       super("Log Viewer");
  -    initGUI();
     }
   
     /**
  -   * Initialises the menu's and toolbars, but does not actually
  -   * create any of the main panel components.
  -   *
  -   */
  -  private void initGUI() {
  -    JMenuBar menuBar = new JMenuBar();
  -
  -    /**
  -     * The menus
  -     */    
  -    FileMenu fileMenu = new FileMenu(this);
  -    JMenu viewMenu = new JMenu("View");
  -    JMenu activeTabMenu = new JMenu("Current tab");
  -
  -    createToolbar(fileMenu);
  -    
  -    JMenuItem menuItemUseRightMouse =
  -      new JMenuItem("Other options available via panel's right mouse button popup menu");
  -    menuItemUseRightMouse.setEnabled(false);
  -    activeTabMenu.add(menuItemUseRightMouse);
  -
  -    viewMenu.setMnemonic('V');
  -    
  -    /**
  -     * -== Begin of Show/Hide toolbar action
  -     */
  -    final JComponent removeToolbarComponent = toolbar;
  -    Action toggleToolbarAction = new AbstractAction("Show Toolbar") {
  -      private boolean hide = false;
  -      public void actionPerformed(ActionEvent e) {
  -         hide = !hide;
  -         Runnable runnable = null;
  -         if (hide) {
  -          runnable = new Runnable() {
  -            public void run() {
  -              getContentPane().remove(removeToolbarComponent);
  -              getRootPane().repaint();
  -              getRootPane().revalidate();
  -            }
  -          };
  -        } else {
  -          runnable = new Runnable() {
  -            public void run() {
  -              getContentPane().add(removeToolbarComponent, BorderLayout.NORTH);
  -              getRootPane().repaint();
  -              getRootPane().revalidate();
  -            }
  -          };
  -        }
  -        SwingUtilities.invokeLater(runnable);
  -      }
  -    };
  -    toggleToolbarAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T,
InputEvent.ALT_MASK));
  -    
  -    JCheckBoxMenuItem showToolbarCheck = new JCheckBoxMenuItem(toggleToolbarAction);
  -    showToolbarCheck.setSelected(true);
  -    
  -    final JToolBar theToolbar = toolbar;
  -    Action lockToolbarAction = new AbstractAction("Lock Toolbar") {
  -      private boolean lock = true;
  -      public void actionPerformed(ActionEvent e) {
  -        lock = !lock;
  -        final boolean isLocked = lock;
  -         Runnable runnable = null;
  -          runnable = new Runnable() {
  -            public void run() {
  -              toolbar.setFloatable(!isLocked);
  -              toolbar.repaint();
  -            }
  -          };
  -        SwingUtilities.invokeLater(runnable);
  -      }
  -    };    
  -    JCheckBoxMenuItem lockToolbarCheck = new JCheckBoxMenuItem(lockToolbarAction);
  -    lockToolbarCheck.setSelected(true);
  -    
  -    viewMenu.add(showToolbarCheck);
  -    viewMenu.add(lockToolbarCheck);
  -    
  -    /**
  -     * -== End of Show/Hide toolbar
  -     */
  -    
  -    /**
  -     * Finally, add all the Menu's to the Menu bar, and set the Menu
  -     * bar for this frame
  -     */
  -    menuBar.add(fileMenu);
  -    menuBar.add(viewMenu);
  -    menuBar.add(activeTabMenu);
  -    setJMenuBar(menuBar);
  -
  -  }
  -
  -  /**
  -   * Builds up the Toolbar
  -   * @param fileMenu need the filemenu to extract the Open/Save actions
  -   */
  -  private void createToolbar(FileMenu fileMenu) {
  -    toolbar = new JToolBar(JToolBar.HORIZONTAL);
  -    toolbar.setFloatable(false);
  -    toolbar.setRollover(true);
  -    
  -    Insets buttonMargins = new Insets(1,1,1,1);
  -    
  -    JButton fileOpenButton = new JButton(fileMenu.getFileOpenAction());
  -    fileOpenButton.setMargin(buttonMargins);
  -
  -    JButton fileSaveButton = new JButton(fileMenu.getFileSaveAction());
  -    fileSaveButton.setMargin(buttonMargins);
  -    
  -    fileOpenButton.setText("");
  -    fileSaveButton.setText("");
  -    
  -    toolbar.add(fileOpenButton);      
  -    toolbar.add(fileSaveButton);
  -//    toolbar.addSeparator();
  -    
  -    toolbar.setMargin(buttonMargins);
  -
  -  }
  -  
  -  /**
      * Starts Chainsaw by attaching a new instance to the Log4J
      * main root Logger via a ChainsawAppender, and activates itself
      * @param args
  @@ -299,13 +171,17 @@
       activateViewer();
     }
   
  -  public String getActiveTabName() {
  -  	int index=tabbedPane.getSelectedIndex();
  -  	if (index==-1) {
  -  		return null;
  -  	} else {
  -		return tabbedPane.getTitleAt(index);
  -  	}
  +
  +  
  +  /**
  +   * Initialises the menu's and toolbars, but does not actually
  +   * create any of the main panel components.
  +   *
  +   */
  +  private void initGUI() {
  +	ChainsawToolBarAndMenus tbms = new ChainsawToolBarAndMenus(this);
  +	toolbar = tbms.getToolbar();
  +	setJMenuBar(tbms.getMenubar());
     }
     
     /**
  @@ -314,6 +190,7 @@
      * layout, table columns, and sets itself viewable.
      */
     public void activateViewer() {
  +	initGUI();
       setSize(new Dimension(500, 500));
       setLocation(500, 150);
   
  @@ -380,6 +257,29 @@
     }
   
     /**
  +   * Returns the currently selected LogPanel, if there is one, otherwise null
  +   * @return
  +   */
  +  LogPanel getCurrentLogPanel() {
  +  	Component selectedTab = tabbedPane.getSelectedComponent();
  +  	if(selectedTab instanceof LogPanel) {
  +  		return (LogPanel)selectedTab;
  +  	}else {
  +//  		System.out.println(selectedTab);
  +  	}
  +  	return null;
  +  }
  +  
  +  public String getActiveTabName() {
  +	int index=tabbedPane.getSelectedIndex();
  +	if (index==-1) {
  +		return null;
  +	} else {
  +		return tabbedPane.getTitleAt(index);
  +	}
  +  }
  +  
  +  /**
      * Determines an appropriate title for the Tab for the Tab Pane
      * by locating a the log4jmachinename property
      * @param v
  @@ -543,7 +443,8 @@
         table = new JSortTable(tableModel);
         scrollToBottom = new ScrollToBottom(true);
         LogPanel thisPanel=new LogPanel(ident, tableModel, table, scrollToBottom, map);
  -      tabbedPane.add(ident, thisPanel);
  +//      tabbedPane.add(ident, thisPanel);
  +	  tabbedPane.insertTab(ident, null, thisPanel, null, 0);
         System.out.println("Creating tab " + ident);
       }
   
  @@ -630,6 +531,7 @@
       final ColorFilter colorFilter = new ColorFilter();
       final DisplayFilter displayFilter;
       boolean isDocked = true;
  +    String identifier;
       final Map columnDisplayMap = new HashMap();
       final Map colorDisplayMap = new HashMap();
       final Set loggerSet = new HashSet();
  @@ -650,6 +552,8 @@
         final String ident, final DefaultSortTableModel tableModel,
         final JSortTable table, final ScrollToBottom scrollToBottom,
         final Map map) {
  +      	
  +      identifier = ident;
         map.put(ChainsawConstants.LEVEL_COL_NAME, levelSet);
         levelSet.addAll(levelList);
   
  @@ -831,35 +735,6 @@
         final DetailThread detailThread = new DetailThread(detail, tableModel);
         detailThread.start();
   
  -      Action pauseAction = new AbstractAction("Pause") {
  -          boolean paused = false;
  -
  -          public void actionPerformed(ActionEvent evt) {
  -            paused = !paused;
  -            if (paused) {
  -              if (!pausedList.contains(ident)) {
  -                pausedList.add(ident);
  -              }
  -            } else {
  -              if (pausedList.contains(ident)) {
  -                pausedList.remove(ident);
  -              }
  -            }
  -          }
  -        };
  -      pauseAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
  -      pauseAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F12"));
  -      pauseAction.putValue(Action.SHORT_DESCRIPTION, "Halts the display, while still allowing
events to stream in the background");
  -      pauseAction.putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.PAUSE));
  -
  -      final JToggleButton pauseButton = new JToggleButton(pauseAction);
  -      pauseButton.setText("");
  -      
  -      pauseButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F12"),pauseAction.getValue(Action.NAME)
);
  -      pauseButton.getActionMap().put(pauseAction.getValue(Action.NAME), pauseAction);
  -      Dimension d=new Dimension(24,24);
  -      pauseButton.setPreferredSize(d);
  -      pauseButton.setMaximumSize(d);
         
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints gbc = new GridBagConstraints();
  @@ -870,8 +745,6 @@
         gbc.gridx = 0;
         gbc.gridy = 0;
         gbc.weightx = 0;
  -      gridbag.setConstraints(pauseButton, gbc);
  -      upperPanel.add(pauseButton);
   
         final JLabel filterLabel = new JLabel("Filter: ");
         gbc.gridx = 1;
  @@ -1383,6 +1256,10 @@
         entryMap.put(ident, map);
   
         tableModel.setEventCountListener(new EventCountListenerImpl(ident));
  +    }
  +    
  +    String getIdentifier() { 
  +    	return identifier;
       }
     }
   
  
  
  
  1.1                  jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
  
  Index: ChainsawToolBarAndMenus.java
  ===================================================================
  /*
   * Created on May 3, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.log4j.chainsaw;
  
  import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.Insets;
  import java.awt.event.ActionEvent;
  import java.awt.event.InputEvent;
  import java.awt.event.KeyEvent;
  
  import javax.swing.AbstractAction;
  import javax.swing.Action;
  import javax.swing.ImageIcon;
  import javax.swing.JButton;
  import javax.swing.JCheckBoxMenuItem;
  import javax.swing.JComponent;
  import javax.swing.JMenu;
  import javax.swing.JMenuBar;
  import javax.swing.JMenuItem;
  import javax.swing.JToggleButton;
  import javax.swing.JToolBar;
  import javax.swing.KeyStroke;
  import javax.swing.SwingUtilities;
  
  import org.apache.log4j.chainsaw.icons.ChainsawIcons;
  
  /**
   * Encapsulates the full Toolbar, and menus and all the actions that can be performed from
it.
   * @author Paul Smith <psmith@apache.org>
   *
   */
  class ChainsawToolBarAndMenus {
  
  	ChainsawToolBarAndMenus(final LogUI logui) {
  		this.logui = logui;
  		toolbar = new JToolBar(JToolBar.HORIZONTAL);
  		menuBar = new JMenuBar();
  		fileMenu = new FileMenu(logui);
  		
  		lockToolbarAction = createLockableToolbarAction();
  		toggleToolbarAction = createToggleToolbarAction();
  		pauseAction = createPauseAction();
  		
  		createMenuBar();
  		createToolbar();
  	}
  	
  	JToolBar getToolbar() {
  		return toolbar;
  	}
  	
  	JMenuBar getMenubar() {
  		return menuBar;
  	}
  	
  	private Action createToggleToolbarAction() {
  		/**
  		 * -== Begin of Show/Hide toolbar action
  		 */
  		final Action toggleToolbarAction = new AbstractAction("Show Toolbar") {
  		  private boolean hide = false;
  		  public void actionPerformed(ActionEvent e) {
  			 hide = !hide;
  			 Runnable runnable = null;
  			 if (hide) {
  			  runnable = new Runnable() {
  				public void run() {
  				  logui.getContentPane().remove(toolbar);
  				  logui.getRootPane().repaint();
  				  logui.getRootPane().revalidate();
  				}
  			  };
  			} else {
  			  runnable = new Runnable() {
  				public void run() {
  				  logui.getContentPane().add(toolbar, BorderLayout.NORTH);
  				  logui.getRootPane().repaint();
  				  logui.getRootPane().revalidate();
  				}
  			  };
  			}
  			SwingUtilities.invokeLater(runnable);
  		  }
  		};
  		toggleToolbarAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T,
InputEvent.ALT_MASK));
  		
  		return toggleToolbarAction;
  	}
  	
  	private Action createLockableToolbarAction() {
  		final Action lockToolbarAction = new AbstractAction("Lock Toolbar") {
  		  private boolean lock = true;
  		  public void actionPerformed(ActionEvent e) {
  			lock = !lock;
  			final boolean isLocked = lock;
  			 Runnable runnable = null;
  			  runnable = new Runnable() {
  				public void run() {
  				  toolbar.setFloatable(!isLocked);
  				  toolbar.repaint();
  				}
  			  };
  			SwingUtilities.invokeLater(runnable);
  		  }
  		}; 
  		return lockToolbarAction;   
  	}
  	
  	private Action createPauseAction() {
  		final Action pauseAction = new AbstractAction("Pause") {
  			boolean paused = false;
  
  			public void actionPerformed(ActionEvent evt) {
  			  paused = !paused;
  			  LogUI.LogPanel logPanel = logui.getCurrentLogPanel();
  			  if(logPanel == null) return;
  			  String ident = logPanel.getIdentifier();
  			  System.out.println("trying to pause '" + ident + "'");
  			  if (paused) {
  				if (!logui.pausedList.contains(ident)) {
  				  logui.pausedList.add(ident);
  				}
  			  } else {
  				if (logui.pausedList.contains(ident)) {
  				  logui.pausedList.remove(ident);
  				}
  			  }
  			}
  		  };
  		pauseAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
  		pauseAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F12"));
  		pauseAction.putValue(Action.SHORT_DESCRIPTION, "Halts the display, while still allowing
events to stream in the background");
  		pauseAction.putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.PAUSE));
  
  		return pauseAction;
  
  	}
  	
  	private void createToolbar() {
  		
  		Insets buttonMargins = new Insets(1, 1, 1, 1);
  
  		FileMenu fileMenu = (FileMenu)menuBar.getMenu(0);
  		
  		JButton fileOpenButton = new JButton(fileMenu.getFileOpenAction());
  		fileOpenButton.setMargin(buttonMargins);
  
  		JButton fileSaveButton = new JButton(fileMenu.getFileSaveAction());
  		fileSaveButton.setMargin(buttonMargins);
  
  		fileOpenButton.setText("");
  		fileSaveButton.setText("");
  
  		toolbar.add(fileOpenButton);
  		toolbar.add(fileSaveButton);
  		toolbar.addSeparator();
  		
  		final JToggleButton pauseButton = new JToggleButton(pauseAction);
  		pauseButton.setText("");
        
  //		pauseButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F12"),pauseAction.getValue(Action.NAME)
);
  		pauseButton.getActionMap().put(pauseAction.getValue(Action.NAME), pauseAction);
  		Dimension d=new Dimension(24,24);
  		pauseButton.setPreferredSize(d);
  		pauseButton.setMaximumSize(d);
  
  		toolbar.add(pauseButton);
  		
  		toolbar.setMargin(buttonMargins);
  		toolbar.setFloatable(false);
  	}
  	
  	private void createMenuBar() {
  		JMenu viewMenu = new JMenu("View");
  		JMenu activeTabMenu = new JMenu("Current tab");
  
  		JMenuItem menuItemUseRightMouse =
  		  new JMenuItem("Other options available via panel's right mouse button popup menu");
  		menuItemUseRightMouse.setEnabled(false);
  		activeTabMenu.add(menuItemUseRightMouse);
  
  		viewMenu.setMnemonic('V');
  		
  		JCheckBoxMenuItem lockToolbarCheck = new JCheckBoxMenuItem(lockToolbarAction);
  		lockToolbarCheck.setSelected(true);
  
  		JCheckBoxMenuItem showToolbarCheck = new JCheckBoxMenuItem(toggleToolbarAction);
  		showToolbarCheck.setSelected(true);
      
  		JCheckBoxMenuItem pause = new JCheckBoxMenuItem(pauseAction);
      
  		viewMenu.add(showToolbarCheck);
  		viewMenu.add(lockToolbarCheck);
  		viewMenu.addSeparator();
  		viewMenu.add(pause);
  
  		menuBar.add(fileMenu);
  		menuBar.add(viewMenu);
  		menuBar.add(activeTabMenu);
  	}
  	
  	private LogUI logui;
  	private final JToolBar toolbar; 
  	private final JMenuBar menuBar;
  	
  	private final Action lockToolbarAction;
  	private final Action toggleToolbarAction;
  	
  	private final Action pauseAction;
  	
  	private final FileMenu fileMenu;
  	
  
  	
  }
  
  

---------------------------------------------------------------------
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