logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r777023 - in /logging/chainsaw/trunk/src/main: java/org/apache/log4j/chainsaw/LogPanel.java java/org/apache/log4j/chainsaw/LogUI.java java/org/apache/log4j/chainsaw/color/ColorPanel.java resources/org/apache/log4j/chainsaw/WelcomePanel.html
Date Thu, 21 May 2009 08:58:45 GMT
Author: sdeboy
Date: Thu May 21 08:58:44 2009
New Revision: 777023

URL: http://svn.apache.org/viewvc?rev=777023&view=rev
Log:
Add support for copying color rules from one tab to another (from color panel)
Also added Ctrl-G goto-line info to Welcome tab

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java
    logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java?rev=777023&r1=777022&r2=777023&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java Thu May 21
08:58:44 2009
@@ -200,6 +200,7 @@
   private final String identifier;
   private final ChainsawStatusBar statusBar;
   private final JFrame preferencesFrame = new JFrame();
+  private ColorPanel colorPanel;
   private final JFrame colorFrame = new JFrame();
   private final JFrame undockedFrame;
   private final DockablePanel externalPanel;
@@ -243,14 +244,14 @@
   private final Vector filterExpressionVector;
   private static final Color INVALID_EXPRESSION_BACKGROUND = new Color(251, 186, 186);
 
-  /**
+    /**
    * Creates a new LogPanel object.  If a LogPanel with this identifier has
    * been loaded previously, reload settings saved on last exit.
    *
    * @param statusBar shared status bar, provided by main application
    * @param identifier used to load and save settings
    */
-  public LogPanel(final ChainsawStatusBar statusBar, final String identifier, int cyclicBufferSize)
{
+  public LogPanel(final ChainsawStatusBar statusBar, final String identifier, int cyclicBufferSize,
Map allColorizers) {
     this.identifier = identifier;
     this.statusBar = statusBar;
     logger.debug("creating logpanel for " + identifier);
@@ -647,7 +648,8 @@
     colorFrame.setIconImage(
       ((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage());
 
-    final ColorPanel colorPanel = new ColorPanel(colorizer, filterModel);
+    allColorizers.put(identifier, colorizer);
+    colorPanel = new ColorPanel(colorizer, filterModel, allColorizers);
 
     colorFrame.getContentPane().add(colorPanel);
 
@@ -1678,6 +1680,7 @@
    * Display the color rule frame
    */
   void showColorPreferences() {
+    colorPanel.loadLogPanelColorizers();
     colorFrame.pack();
     colorFrame.setVisible(true);
   }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java?rev=777023&r1=777022&r2=777023&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java Thu May 21 08:58:44
2009
@@ -107,10 +107,8 @@
 import org.apache.log4j.chainsaw.prefs.SettingsManager;
 import org.apache.log4j.chainsaw.receivers.ReceiversPanel;
 import org.apache.log4j.chainsaw.version.VersionManager;
-import org.apache.log4j.helpers.Constants;
 import org.apache.log4j.net.SocketNodeEventListener;
 import org.apache.log4j.plugins.Plugin;
-import org.apache.log4j.xml.DOMConfigurator;
 import org.apache.log4j.plugins.PluginEvent;
 import org.apache.log4j.plugins.PluginListener;
 import org.apache.log4j.plugins.PluginRegistry;
@@ -124,6 +122,7 @@
 import org.apache.log4j.spi.LoggerRepositoryEx;
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.log4j.spi.RepositorySelector;
+import org.apache.log4j.xml.DOMConfigurator;
 import org.apache.log4j.xml.XMLDecoder;
 
 
@@ -202,8 +201,10 @@
   private static final LoggerRepositoryExImpl repositoryExImpl = new LoggerRepositoryExImpl(LogManager.getLoggerRepository());
   
   private PluginRegistry pluginRegistry;
+  //map of tab names to rulecolorizers
+  private Map allColorizers = new HashMap();
 
-  /**
+    /**
    * Constructor which builds up all the visual elements of the frame including
    * the Menu bar
    */
@@ -1918,7 +1919,8 @@
   private void buildLogPanel(
       boolean customExpression, final String ident, final List events)
       throws IllegalArgumentException {
-      final LogPanel thisPanel = new LogPanel(getStatusBar(), ident, cyclicBufferSize);
+      final LogPanel thisPanel = new LogPanel(getStatusBar(), ident, cyclicBufferSize, allColorizers);
+
 
       /**
                * Now add the panel as a batch listener so it can handle it's own

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java?rev=777023&r1=777022&r2=777023&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java Thu
May 21 08:58:44 2009
@@ -38,11 +38,12 @@
 import java.util.Vector;
 
 import javax.swing.AbstractAction;
+import javax.swing.Action;
 import javax.swing.BorderFactory;
 import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.DefaultCellEditor;
-import javax.swing.DefaultListModel;
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JColorChooser;
@@ -82,8 +83,10 @@
  * @author Scott Deboy <sdeboy@apache.org>
  */
 public class ColorPanel extends JPanel {
+  private static final String DEFAULT_STATUS = "<html>Double click a rule field to
edit the rule</html>";
+  private final String currentRuleSet = "Default";
+
   private RuleColorizer colorizer;
-  private JPanel ruleSetsPanel;
   private JPanel rulesPanel;
   private FilterModel filterModel;
   private DefaultTableModel tableModel;
@@ -92,17 +95,20 @@
   private ActionListener closeListener;
   private JLabel statusBar;
   private Vector columns;
-  private String currentRuleSet = "Default";
-  private DefaultListModel ruleSetListModel;
+  private final String currentTabString = "Current tab";
+  private DefaultComboBoxModel logPanelColorizersModel;
+  private Map allLogPanelColorizers;
+  private RuleColorizer currentLogPanelColorizer;
 
-  public ColorPanel(
-    final RuleColorizer colorizer, final FilterModel filterModel) {
+    public ColorPanel(final RuleColorizer currentLogPanelColorizer, final FilterModel filterModel,
final Map allLogPanelColorizers) {
     super(new BorderLayout());
 
-    this.colorizer = colorizer;
+    this.currentLogPanelColorizer = currentLogPanelColorizer;
+    this.colorizer = currentLogPanelColorizer;
     this.filterModel = filterModel;
-    
-    colorizer.addPropertyChangeListener(
+    this.allLogPanelColorizers = allLogPanelColorizers;
+
+    currentLogPanelColorizer.addPropertyChangeListener(
     	      "colorrule",
     	      new PropertyChangeListener() {
     	        public void propertyChange(PropertyChangeEvent evt) {
@@ -113,14 +119,12 @@
     tableModel = new DefaultTableModel();
     table = new JTable(tableModel);
 
-    ruleSetListModel = new DefaultListModel();
-    
     columns = new Vector();
     columns.add("Expression");
     columns.add("Background");
     columns.add("Foreground");
 
-    table.setPreferredScrollableViewportSize(new Dimension(400, 200));
+    table.setPreferredScrollableViewportSize(new Dimension(525, 200));
     tableScrollPane = new JScrollPane(table);
 
     Vector data = getColorizerVector();    
@@ -134,10 +138,7 @@
 
     configureTable();
 
-    statusBar = new JLabel("Ruleset support not yet implemented");
-
-    ruleSetsPanel = buildRuleSetsPanel();
-    ruleSetsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+    statusBar = new JLabel(DEFAULT_STATUS);
 
     rulesPanel = buildRulesPanel();
     rulesPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
@@ -164,18 +165,87 @@
     rightPanel.add(southPanel, BorderLayout.SOUTH);
     rightOuterPanel.add(rightPanel);
 
-    add(ruleSetsPanel, BorderLayout.WEST);
+    JPanel topPanel = new JPanel();
+    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
+
+    JLabel selectText = new JLabel("Apply a tab's colors");
+    topPanel.add(selectText);
+    topPanel.add(Box.createHorizontalStrut(5));
+
+    logPanelColorizersModel = new DefaultComboBoxModel();
+    final JComboBox loadPanelColorizersComboBox = new JComboBox(logPanelColorizersModel);
+    loadLogPanelColorizers();
+
+    topPanel.add(loadPanelColorizersComboBox);
+
+    topPanel.add(Box.createHorizontalStrut(5));
+    final Action copyRulesAction = new AbstractAction() {
+        public void actionPerformed(ActionEvent e)
+          {
+              tableModel.getDataVector().clear();
+              RuleColorizer sourceColorizer = (RuleColorizer) allLogPanelColorizers.get(loadPanelColorizersComboBox.getSelectedItem().toString());
+              colorizer.setRules(sourceColorizer.getRules());
+              updateColors();
+          }
+      };
+        
+      loadPanelColorizersComboBox.addActionListener(new ActionListener() {
+          public void actionPerformed(ActionEvent e) {
+              String selectedColorizerName = loadPanelColorizersComboBox.getSelectedItem().toString();
+              copyRulesAction.setEnabled(!(currentTabString.equals(selectedColorizerName)));
+          }
+      });
+
+    copyRulesAction.putValue(Action.NAME, "Copy color rules");
+    copyRulesAction.setEnabled(!(currentTabString.equals(loadPanelColorizersComboBox.getSelectedItem())));
+
+    JButton copyRulesButton = new JButton(copyRulesAction);
+    topPanel.add(copyRulesButton);
+
+    add(topPanel, BorderLayout.NORTH);
     add(rightOuterPanel, BorderLayout.CENTER);
     if (table.getRowCount() > 0) {
         table.getSelectionModel().setSelectionInterval(0, 0);
     }
   }
 
+  public void loadLogPanelColorizers() {
+      if (logPanelColorizersModel.getIndexOf(currentTabString) == -1) {
+        logPanelColorizersModel.addElement(currentTabString);
+      }
+      for (Iterator iter = allLogPanelColorizers.entrySet().iterator();iter.hasNext();) {
+          Map.Entry entry = (Map.Entry)iter.next();
+          if (!entry.getValue().equals(currentLogPanelColorizer)) {
+              if (logPanelColorizersModel.getIndexOf(entry.getKey()) == -1) {
+                logPanelColorizersModel.addElement(entry.getKey());
+              }
+          }
+      }
+  }
+
   public static void main(String[] args) {
     FilterModel filterModel = new FilterModel();
     RuleColorizer colorizer = new RuleColorizer();
 
-    ColorPanel p = new ColorPanel(colorizer, filterModel);
+    Map otherColorizers = new HashMap();
+
+    RuleColorizer panel1Colorizer = new RuleColorizer();
+    HashMap entry1 = new HashMap();
+    List list1 = new ArrayList();
+    list1.add(new ColorRule("logger == test1", ExpressionRule.getRule("logger == test1"),
Color.YELLOW, Color.BLACK));
+    entry1.put("Default", list1);
+    panel1Colorizer.setRules(entry1);
+    otherColorizers.put("test1", panel1Colorizer);
+
+    RuleColorizer panel2Colorizer = new RuleColorizer();
+    HashMap entry2 = new HashMap();
+    List list2 = new ArrayList();
+    list2.add(new ColorRule("logger == test2", ExpressionRule.getRule("logger == test2"),
Color.YELLOW, Color.BLACK));
+    entry2.put("Default", list2);
+    panel2Colorizer.setRules(entry2);
+    otherColorizers.put("test2", panel2Colorizer);
+
+    ColorPanel p = new ColorPanel(colorizer, filterModel, otherColorizers);
     final JFrame f = new JFrame();
 
     p.setCloseActionListener(
@@ -186,7 +256,7 @@
       });
 
 //    Following does not compile on JDK 1.3.1
-//    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     f.getContentPane().add(p);
     f.pack();
     f.setVisible(true);
@@ -195,20 +265,19 @@
   public void updateColors() {
     tableModel.getDataVector().clear();
     tableModel.getDataVector().addAll(getColorizerVector());
+    tableModel.fireTableDataChanged();
   }
   
   private Vector getColorizerVector() {
       Vector data = new Vector();
       Map map = colorizer.getRules();
       Iterator iter = map.entrySet().iterator();
-      ruleSetListModel.removeAllElements();
       while (iter.hasNext()) {
         Map.Entry entry = (Map.Entry)iter.next();
         //update ruleset list
-        ruleSetListModel.addElement(entry.getKey());
         if (entry.getKey().equals(currentRuleSet)) {
             Iterator iter2 = ((List)entry.getValue()).iterator();
-      
+
             while (iter2.hasNext()) {
                 ColorRule rule = (ColorRule)iter2.next();
                 Vector v = new Vector();
@@ -340,7 +409,7 @@
     if (result.toString().equals("")) {
       ((ExpressionTableCellRenderer) table.getColumnModel().getColumn(0).getCellRenderer())
       .setToolTipText("Double click to edit");
-      statusBar.setText("");
+      statusBar.setText(DEFAULT_STATUS);
 
       //only update rules if there were no errors
       Map map = new HashMap();
@@ -472,53 +541,11 @@
     return panel;
   }
 
-  JPanel buildRuleSetsPanel() {
-    JPanel panel = new JPanel(new BorderLayout());
-
-    JLabel ruleSetLabel = new JLabel("RuleSets:");
-    panel.add(ruleSetLabel, BorderLayout.NORTH);
-
-    final JList list = new JList(ruleSetListModel);
-    JScrollPane scrollPane = new JScrollPane(list);
-    list.setEnabled(false);
-
-    panel.add(scrollPane, BorderLayout.CENTER);
-
-    JPanel buttonPanel = new JPanel(new GridLayout(0, 2));
-
-    JPanel newPanel = new JPanel();
-    JButton newButton = new JButton("New");
-    newButton.setEnabled(false);
-    newPanel.add(newButton);
-
-    JPanel deletePanel = new JPanel();
-    JButton deleteButton = new JButton("Delete");
-    deleteButton.setEnabled(false);
-    deletePanel.add(deleteButton);
-
-    buttonPanel.add(newPanel);
-    buttonPanel.add(deletePanel);
-
-    panel.add(buttonPanel, BorderLayout.SOUTH);
-
-    return panel;
-  }
-
   JPanel buildRulesPanel() {
     JPanel listPanel = new JPanel(new BorderLayout());
     JPanel panel = new JPanel();
     panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 
-    JLabel ruleSetLabel = new JLabel("RuleSet Name:");
-    panel.add(ruleSetLabel);
-
-    JTextField ruleSetTextField = new JTextField(20);
-    ruleSetTextField.setText(currentRuleSet);
-    ruleSetTextField.setAlignmentX(Component.LEFT_ALIGNMENT);
-    ruleSetTextField.setEnabled(false);
-
-    panel.add(ruleSetTextField);
-
     panel.add(Box.createVerticalStrut(10));
 
     JLabel rulesLabel = new JLabel("Rules:");
@@ -607,7 +634,7 @@
     return listPanel;
   }
 
-  class ColorListCellRenderer extends JLabel implements ListCellRenderer {
+    class ColorListCellRenderer extends JLabel implements ListCellRenderer {
     ColorListCellRenderer() {
       setOpaque(true);
     }

Modified: logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html?rev=777023&r1=777022&r2=777023&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html
(original)
+++ logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html
Thu May 21 08:58:44 2009
@@ -76,10 +76,13 @@
 	<td width="50" align="center">-</td>
 	<td colspan="1">Find previous</td>
 </tr>
-<tr valign="top">
+<tr valign="top" bgcolor="#EEEEEE">
 	<td nowrap class="HotKey">ALT-X</td>
 	<td width="50" align="center">-</td>
-	<td colspan="4">Exits the Application</td>
+	<td colspan="1">Exits the Application</td>
+    <td nowrap class="HotKey">CTRL-G</td>
+    <td width="50" align="center">-</td>
+    <td colspan="1">Go to line</td>
 </tr>
 </table></P>
 <!--<p><a href="#TheTop">Back to top</a></p>-->



Mime
View raw message