You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by sd...@apache.org on 2003/07/20 17:41:48 UTC

cvs commit: jakarta-log4j/src/java/org/apache/log4j/chainsaw ChainsawToolBarAndMenus.java LogUI.java

sdeboy      2003/07/20 08:41:48

  Modified:    src/java/org/apache/log4j/chainsaw
                        ChainsawToolBarAndMenus.java LogUI.java
  Log:
  New 'show tabs' menu added to the 'View' menu.
  
  When a tab is created, a checkbox menu item is added to the show tabs menu.  
  If the user unchecks the item for a tab, the tab is hidden.
  If the user checks the item, the tab is displayed.  
  If the tab is undocked, the corresponding menu item is checked and disabled until the tab is re-docked.
  
  PR:
  Obtained from:
  Submitted by:	
  Reviewed by:	
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.2       +56 -1     jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
  
  Index: ChainsawToolBarAndMenus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ChainsawToolBarAndMenus.java	25 Jun 2003 04:05:22 -0000	1.1
  +++ ChainsawToolBarAndMenus.java	20 Jul 2003 15:41:48 -0000	1.2
  @@ -73,7 +73,10 @@
   
   import java.util.ArrayList;
   import java.util.Collection;
  +import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Set;
   
   import javax.swing.AbstractAction;
   import javax.swing.Action;
  @@ -149,6 +152,10 @@
     private String lastFind = "";
     private String levelDisplay = ChainsawConstants.LEVEL_DISPLAY_ICONS;
     private final Action[] logPanelSpecificActions;
  +  private final ChangeListener panelListener;
  +  private Map panelMenuMap = new HashMap();
  +  private Map panelEnabledMap = new HashMap();
  +  private JMenuItem showTabs;
   
     ChainsawToolBarAndMenus(final LogUI logui) {
       this.logui = logui;
  @@ -172,7 +179,34 @@
         new JSlider(JSlider.VERTICAL, 0, 5000, logui.handler.getQueueInterval());
       createMenuBar();
       createToolbar();
  -
  +    
  +    panelListener = new ChangeListener() {
  +    	public void stateChanged(ChangeEvent e) {
  +    		Map m = logui.getPanels();
  +    		if (m !=null) {
  +    			Set s = m.entrySet();
  +    			Iterator iter = s.iterator();
  +    			while (iter.hasNext()) {
  +    				Map.Entry entry = (Map.Entry)iter.next();
  +    				if (!panelMenuMap.keySet().contains(entry.getKey())) {
  +    					panelMenuMap.put(entry.getKey(), getDisplayPanelMenuItem(entry.getKey().toString()));
  +    					//default to enabled
  +    					panelEnabledMap.put(entry.getKey(), Boolean.TRUE);
  +    					showTabs.add((JCheckBoxMenuItem)panelMenuMap.get(entry.getKey()));
  +    				}
  +
  +					boolean entryEnabled = ((Boolean)panelEnabledMap.get(entry.getKey())).booleanValue();
  +    				boolean newEnabled = ((Boolean)entry.getValue()).booleanValue();
  +					    				  
  +    				if (entryEnabled != newEnabled) {
  +    					((JCheckBoxMenuItem)panelMenuMap.get(entry.getKey())).getModel().setEnabled(newEnabled);
  +    					panelEnabledMap.put(entry.getKey(), Boolean.valueOf(newEnabled));
  +    				}
  +    			}
  +    		}
  +    	}
  +    };
  +    
       logPanelSpecificActions =
         new Action[] {
           pauseAction, findNextAction, clearAction, fileMenu.getFileSaveAction(),
  @@ -530,6 +564,9 @@
       viewMenu.add(menuUndock);
       viewMenu.add(pause);
   
  +	showTabs = new JMenu("Display tabs");
  +	viewMenu.add(showTabs);    
  +
       JCheckBoxMenuItem toggleDetailMenuItem =
         new JCheckBoxMenuItem(toggleDetailPaneAction);
       toggleDetailMenuItem.setSelected(true);
  @@ -1064,6 +1101,24 @@
           element.setSelected(false);
         }
       }
  +  }
  +  
  +  ChangeListener getPanelListener() {
  +  	return panelListener;
  +  }
  +  
  +  private JCheckBoxMenuItem getDisplayPanelMenuItem(final String panelName) {
  +  	final JCheckBoxMenuItem item = new JCheckBoxMenuItem(panelName, true);
  +  	
  +	final Action action =
  +	  new AbstractAction(panelName) {
  +		public void actionPerformed(ActionEvent e) {
  +		  logui.displayPanel(panelName, item.isSelected());
  +		}
  +	  };
  +	  item.setAction(action);
  +
  +	return item;
     }
   
     private Action setupFindFieldsAndActions() {
  
  
  
  1.5       +30 -51    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LogUI.java	9 Jul 2003 06:10:01 -0000	1.4
  +++ LogUI.java	20 Jul 2003 15:41:48 -0000	1.5
  @@ -209,7 +209,6 @@
     private final List filterableColumns = new ArrayList();
     private final Map entryMap = new HashMap();
     private final Map panelMap = new HashMap();
  -  private final Map lostMap = new HashMap();
     private final Map scrollMap = new HashMap();
     private final Map levelMap = new HashMap();
     ChainsawAppenderHandler handler;
  @@ -290,6 +289,7 @@
       toolbar = tbms.getToolbar();
       setJMenuBar(tbms.getMenubar());
       tabbedPane = new ChainsawTabbedPane();
  +    tabbedPane.addChangeListener(tbms.getPanelListener());
     }
   
     /**
  @@ -518,17 +518,7 @@
                 LogPanel logPanel = getCurrentLogPanel();
   
                 if (logPanel != null) {
  -                if ((e.getModifiers() & InputEvent.CTRL_MASK) > 0) {
  -                  synchronized (tableModelMap) {
  -                    logPanel.clearModel();
  -                    tableModelMap.remove(logPanel.getIdentifier());
  -                    tabbedPane.removeTabAt(tabIndex);
  -
  -                    //          TODO should also tidy up any other references to things... Might need to be able to recover this pane again...
  -                  }
  -                } else {
                     logPanel.undock();
  -                }
                 }
               }
             }
  @@ -705,6 +695,33 @@
       aboutBox.setVisible(true);
     }
   
  +  Map getPanels() {
  +  	Map m = new HashMap();
  +  	Set panelSet = panelMap.entrySet();
  +  	Iterator iter = panelSet.iterator();
  +  	while (iter.hasNext()) {
  +  		Map.Entry entry = (Map.Entry)iter.next();
  +  		m.put(entry.getKey(), Boolean.valueOf(((DockablePanel)entry.getValue()).isDocked()));
  +  	}
  +  	return m;
  +  }
  +  
  +  void displayPanel(String panelName, boolean display) {
  +  	Object o = panelMap.get(panelName);
  +  	if (o instanceof LogPanel) {
  +		LogPanel p = (LogPanel)o;
  +
  +		int index = tabbedPane.indexOfTab(panelName);
  +
  +		if (index == -1 && display) {
  +			tabbedPane.addTab(panelName, p);
  +		}
  +		if (index > -1 && !display) {
  +			tabbedPane.removeTabAt(index);
  +		}
  +  	}
  +  }
  +  		
     /**
      * Shutsdown by ensuring the Appender gets a chance to close.
      */
  @@ -1627,17 +1644,6 @@
         f.getContentPane().add(
           tbms.createDockwindowToolbar(f, this), BorderLayout.NORTH);
   
  -      f.addWindowListener(
  -        new WindowAdapter() {
  -          public void windowClosing(WindowEvent event) {
  -            HashMap m = new HashMap();
  -            m.put(ChainsawConstants.MAIN_PANEL, LogPanel.this);
  -            m.put(ChainsawConstants.UPPER_PANEL, upperPanel);
  -            m.put(ChainsawConstants.LOWER_PANEL, lowerPanel);
  -            lostMap.put(ident, m);
  -          }
  -        });
  -
         dockingAction =
           new AbstractAction("Undock") {
               public void actionPerformed(ActionEvent evt) {
  @@ -1719,33 +1725,6 @@
         menuItemScrollBottom.setIcon(
           new ImageIcon(ChainsawIcons.SCROLL_TO_BOTTOM));
   
  -      JMenuItem menuItemRecoverPanes = new JMenuItem("Recover closed panes");
  -      menuItemRecoverPanes.addActionListener(
  -        new ActionListener() {
  -          public void actionPerformed(ActionEvent evt) {
  -            Set s = lostMap.entrySet();
  -            Iterator iter = s.iterator();
  -
  -            while (iter.hasNext()) {
  -              Map.Entry m = (Map.Entry) iter.next();
  -              String title = (String) m.getKey();
  -              HashMap map = (HashMap) m.getValue();
  -              JSplitPane lower =
  -                (JSplitPane) map.get(ChainsawConstants.LOWER_PANEL);
  -              JPanel upper = (JPanel) map.get(ChainsawConstants.UPPER_PANEL);
  -              DockablePanel thisPanel =
  -                (DockablePanel) map.get(ChainsawConstants.MAIN_PANEL);
  -              thisPanel.add(upper, BorderLayout.NORTH);
  -              thisPanel.add(lower, BorderLayout.CENTER);
  -              panelMap.put(title, thisPanel);
  -              tabbedPane.add(title, thisPanel);
  -              thisPanel.setDocked(true);
  -            }
  -
  -            lostMap.clear();
  -          }
  -        });
  -
         JMenuItem menuItemRemoveColorFilter =
           new JMenuItem("Remove all color filters");
         menuItemRemoveColorFilter.addActionListener(
  @@ -1984,13 +1963,13 @@
        *
        */
       void dock() {
  +	  setDocked(true);
         f.setVisible(false);
         removeAll();
         add(lowerPanel, BorderLayout.CENTER);
         panelMap.put(getIdentifier(), LogPanel.this);
         tabbedPane.addANewTab(getIdentifier(), LogPanel.this, null);
         externalPanel.setDocked(true);
  -      setDocked(true);
         dockingAction.putValue(Action.NAME, "Undock");
         dockingAction.putValue(Action.SMALL_ICON, ChainsawIcons.ICON_UNDOCK);
       }
  @@ -2001,11 +1980,11 @@
        *
        */
       void undock() {
  +	  setDocked(false);
         externalPanel.removeAll();
         externalPanel.add(lowerPanel, BorderLayout.CENTER);
         tabbedPane.remove(LogPanel.this);
         externalPanel.setDocked(false);
  -      setDocked(false);
         panelMap.put(getIdentifier(), externalPanel);
         f.setSize(getSize());
   
  
  
  

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