psmith 2003/09/04 23:07:26
Modified: src/java/org/apache/log4j/chainsaw
TableColorizingRenderer.java
Added: src/java/org/apache/log4j/chainsaw/icons
LevelIconFactory.java
Log:
Refactored some code into a separate class for sharing.
Revision Changes Path
1.1
jakarta-log4j/src/java/org/apache/log4j/chainsaw/icons/LevelIconFactory.java
Index: LevelIconFactory.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.icons;
import org.apache.log4j.Level;
import java.awt.Image;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
/**
*/
public class LevelIconFactory {
private static final LevelIconFactory instance = new LevelIconFactory();
private final Map iconMap = new HashMap();
private LevelIconFactory() {
String[] iconFileNames =
new String[] { "Warn.gif", "Inform.gif", "Error.gif" };
String[] iconLabels = new String[] { "WARN", "INFO", "ERROR" };
Level[] levels = new Level[] { Level.WARN, Level.INFO, Level.ERROR };
for (int i = 0; i < iconLabels.length; i++) {
final ImageIcon icon =
new ImageIcon(
UIManager.getLookAndFeel().getClass().getResource(
"icons/" + iconFileNames[i]));
double scalex = .5;
double scaley = .5;
final int newWidth = (int) (scalex * icon.getIconWidth());
final int newHeight = (int) (scaley * icon.getIconHeight());
Image iconImage =
icon.getImage().getScaledInstance(
newWidth, newHeight, Image.SCALE_SMOOTH);
iconMap.put(iconLabels[i], new ImageIcon(iconImage));
}
iconMap.put("DEBUG", ChainsawIcons.ICON_DEBUG);
}
public static final LevelIconFactory getInstance() {
return instance;
}
public Map getLevelToIconMap() {
return iconMap;
}
}
1.3 +9 -38
jakarta-log4j/src/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
Index: TableColorizingRenderer.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TableColorizingRenderer.java 3 Sep 2003 05:42:02 -0000 1.2
+++ TableColorizingRenderer.java 5 Sep 2003 06:07:26 -0000 1.3
@@ -49,34 +49,28 @@
package org.apache.log4j.chainsaw;
-import org.apache.log4j.chainsaw.icons.ChainsawIcons;
-import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
-import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
-import org.apache.log4j.chainsaw.prefs.SettingsListener;
-import org.apache.log4j.helpers.ISO8601DateFormat;
-import org.apache.log4j.spi.LoggingEvent;
-
import java.awt.Color;
import java.awt.Component;
-import java.awt.Image;
-
import java.text.DateFormat;
-
import java.util.Calendar;
import java.util.Date;
-import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.Icon;
-import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
-import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
+import org.apache.log4j.chainsaw.icons.LevelIconFactory;
+import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
+import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
+import org.apache.log4j.chainsaw.prefs.SettingsListener;
+import org.apache.log4j.helpers.ISO8601DateFormat;
+import org.apache.log4j.spi.LoggingEvent;
+
/**
* A specific TableCellRenderer that colourizes a particular cell based on
@@ -91,7 +85,7 @@
implements SettingsListener {
private static final DateFormat DATE_FORMATTER =
new ISO8601DateFormat(Calendar.getInstance().getTimeZone());
- private Map iconMap = new HashMap();
+ private Map iconMap = LevelIconFactory.getInstance().getLevelToIconMap();
private ColorFilter colorFilter;
private JTable table;
private Color background = new Color(255, 255, 254);
@@ -112,30 +106,7 @@
levelComponent.setOpaque(true);
levelComponent.setHorizontalAlignment(JLabel.CENTER);
- // Image warningImage =
((IconUIResource)UIManager.getIcon("OptionPane.warningIcon")).getImage().getScaledInstance(16,16,
Image.SCALE_FAST);
- String[] iconFileNames =
- new String[] { "Warn.gif", "Inform.gif", "Error.gif" };
- String[] iconLabels = new String[] { "WARN", "INFO", "ERROR" };
-
- for (int i = 0; i < iconLabels.length; i++) {
- final ImageIcon icon =
- new ImageIcon(
- UIManager.getLookAndFeel().getClass().getResource(
- "icons/" + iconFileNames[i]));
- double scalex = .5;
- double scaley = .5;
- final int newWidth = (int) (scalex * icon.getIconWidth());
- final int newHeight = (int) (scaley * icon.getIconHeight());
- Image iconImage =
- icon.getImage().getScaledInstance(
- newWidth, newHeight, Image.SCALE_SMOOTH);
- iconMap.put(iconLabels[i], new ImageIcon(iconImage));
- }
-
- /**
- * finally, add the debug icon...
- */
- iconMap.put("DEBUG", ChainsawIcons.ICON_DEBUG);
+
levelComponent.setText("");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]