logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject cvs commit: logging-log4j/src/java/org/apache/log4j/chainsaw/color DefaultColorizer.java
Date Sun, 18 Jan 2004 05:03:08 GMT
sdeboy      2004/01/17 21:03:08

  Modified:    src/java/org/apache/log4j/chainsaw LogPanel.java
  Removed:     src/java/org/apache/log4j/chainsaw/color
                        DefaultColorizer.java
  Log:
  - Added 'best fit column' feature, accessible via context menu
  - Removed unused defaultcolorizer
  
  Revision  Changes    Path
  1.50      +29 -1     logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java
  
  Index: LogPanel.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- LogPanel.java	16 Jan 2004 23:49:03 -0000	1.49
  +++ LogPanel.java	18 Jan 2004 05:03:08 -0000	1.50
  @@ -55,10 +55,12 @@
   package org.apache.log4j.chainsaw;
   
   import java.awt.BorderLayout;
  +import java.awt.Component;
   import java.awt.Container;
   import java.awt.Dimension;
   import java.awt.FlowLayout;
   import java.awt.Font;
  +import java.awt.FontMetrics;
   import java.awt.Point;
   import java.awt.Toolkit;
   import java.awt.event.ActionEvent;
  @@ -779,7 +781,18 @@
                       }
                   }
               });
  -
  +            
  +        final JMenuItem menuItemBestFit = new JMenuItem("Best fit column");
  +        menuItemBestFit.addActionListener(new ActionListener() {
  +                public void actionPerformed(ActionEvent evt) {
  +                    if (currentPoint != null) {
  +                        int column = table.columnAtPoint(currentPoint);
  +                        int maxWidth = getMaxColumnWidth(column);
  +                        table.getColumnModel().getColumn(column).setPreferredWidth(maxWidth);
  +                    }
  +                }
  +        });
  +        
           final JMenuItem menuItemToggleDock = new JMenuItem("Undock/dock");
   
           undockedFrame = new JFrame(ident);
  @@ -1008,6 +1021,8 @@
           p.add(menuItemFocusOn);
           p.add(menuDefineAddCustomFilter);
           p.add(new JSeparator());
  +        
  +        p.add(menuItemBestFit);
   
           p.add(menuItemToggleDetails);
           p.add(menuItemToggleToolTips);
  @@ -1613,6 +1628,19 @@
                       repaint();
                   }
               });
  +    }
  +
  +    private int getMaxColumnWidth(int index) {
  +        FontMetrics metrics = getGraphics().getFontMetrics();
  +        int longestWidth = metrics.stringWidth("  " + table.getColumnName(index) + "  ")
+ (2 * table.getColumnModel().getColumnMargin());
  +         
  +        for(int i=0,j=tableModel.getRowCount();i < j; i++) {
  +            Component c = renderer.getTableCellRendererComponent(table, table.getValueAt(i,
index), false, false, i, index);
  +            if (c instanceof JLabel) {
  +                longestWidth = Math.max(longestWidth, metrics.stringWidth(((JLabel)c).getText()));
  +            }
  +        }
  +        return longestWidth + 5; 
       }
   
       void loadColorSettings(String ident) {
  
  
  

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


Mime
View raw message