http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/icons/LineIconFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/icons/LineIconFactory.java b/src/main/java/org/apache/log4j/chainsaw/icons/LineIconFactory.java index a7891c4..7040f45 100644 --- a/src/main/java/org/apache/log4j/chainsaw/icons/LineIconFactory.java +++ b/src/main/java/org/apache/log4j/chainsaw/icons/LineIconFactory.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,166 +17,158 @@ package org.apache.log4j.chainsaw.icons; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Component; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; -import java.awt.RenderingHints; -import java.awt.image.BufferedImage; - -import javax.swing.Icon; -import javax.swing.ImageIcon; - import org.apache.log4j.LogManager; import org.apache.log4j.Logger; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; + /** * A simple factory/facade for creating some of the standard Icons that are based * on line drawings + * * @author Paul Smith <psm...@apache.org> * @author Scott Deboy <sde...@apache.org> - * */ public final class LineIconFactory { - private static final Logger logger = LogManager.getLogger(LineIconFactory.class); - /** - * - */ - private LineIconFactory() { - } - - public static Icon createExpandIcon() { - int size = 8; - int xOffSet = 0; - int yOffSet = 0; - try { - GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2D = - environment.createGraphics( - image); - g2D.setBackground(new Color(0,0,0,0)); - g2D.clearRect(0,0,size,size); - g2D.setStroke(new BasicStroke(1.5f)); - g2D.setRenderingHint( - RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - g2D.setColor(Color.black); - g2D.drawLine( - xOffSet, (size / 2) + yOffSet, size - xOffSet, - (size / 2) + yOffSet); - - g2D.drawLine( - xOffSet + (size/2), yOffSet, xOffSet + (size/2), - (size) + yOffSet); - - return new ImageIcon(image); - } catch (Exception e) { - logger.error("failed to create a Expand icon", e); + private static final Logger logger = LogManager.getLogger(LineIconFactory.class); + + /** + * + */ + private LineIconFactory() { } - return null; - } - public static Icon createCollapseIcon() { - int size = 8; - int xOffSet = 0; - int yOffSet = 0; - try { - GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2D = - environment.createGraphics( - image); - g2D.setBackground(new Color(0,0,0,0)); - g2D.clearRect(0,0,size,size); - g2D.setStroke(new BasicStroke(1.5f)); - g2D.setRenderingHint( - RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - g2D.setColor(Color.black); - g2D.drawLine( - xOffSet, (size / 2) + yOffSet, size - xOffSet, - (size / 2) + yOffSet); - - return new ImageIcon(image); - } catch (Exception e) { - logger.error("failed to create a Collapse icon", e); + public static Icon createExpandIcon() { + int size = 8; + int xOffSet = 0; + int yOffSet = 0; + try { + GraphicsEnvironment environment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2D = + environment.createGraphics( + image); + g2D.setBackground(new Color(0, 0, 0, 0)); + g2D.clearRect(0, 0, size, size); + g2D.setStroke(new BasicStroke(1.5f)); + g2D.setRenderingHint( + RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2D.setColor(Color.black); + g2D.drawLine( + xOffSet, (size / 2) + yOffSet, size - xOffSet, + (size / 2) + yOffSet); + + g2D.drawLine( + xOffSet + (size / 2), yOffSet, xOffSet + (size / 2), + (size) + yOffSet); + + return new ImageIcon(image); + } catch (Exception e) { + logger.error("failed to create a Expand icon", e); + } + + return null; } - return null; - } + public static Icon createCollapseIcon() { + int size = 8; + int xOffSet = 0; + int yOffSet = 0; + try { + GraphicsEnvironment environment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2D = + environment.createGraphics( + image); + g2D.setBackground(new Color(0, 0, 0, 0)); + g2D.clearRect(0, 0, size, size); + g2D.setStroke(new BasicStroke(1.5f)); + g2D.setRenderingHint( + RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2D.setColor(Color.black); + g2D.drawLine( + xOffSet, (size / 2) + yOffSet, size - xOffSet, + (size / 2) + yOffSet); + + return new ImageIcon(image); + } catch (Exception e) { + logger.error("failed to create a Collapse icon", e); + } + + return null; + } - public static Icon createCloseIcon() { - return new CloseIcon(8, 0, 0); - } + public static Icon createCloseIcon() { + return new CloseIcon(8, 0, 0); + } - public static Icon createBlankIcon() { - return new BlankIcon(16); - } + public static Icon createBlankIcon() { + return new BlankIcon(16); + } - /** + /** * A nice and simple 'X' style icon that is used to indicate a 'close' operation. * * @author Scott Deboy <sde...@apache.org> - * */ - private static class BlankIcon implements Icon { - int size; + private static class BlankIcon implements Icon { + int size; - public BlankIcon(int size) { - this.size = size; - } + public BlankIcon(int size) { + this.size = size; + } - public int getIconHeight() { - return size; - } + public int getIconHeight() { + return size; + } - public int getIconWidth() { - return size; - } + public int getIconWidth() { + return size; + } - public void paintIcon(Component c, Graphics g, int x, int y) { + public void paintIcon(Component c, Graphics g, int x, int y) { + } } - } - /** + /** * A nice and simple 'X' style icon that is used to indicate a 'close' operation. * * @author Scott Deboy <sde...@apache.org> - * */ - private static class CloseIcon implements Icon { - int size; - int xOffSet; - int yOffSet; - - public CloseIcon(int size, int xOffSet, int yOffSet) { - this.size = size; - this.xOffSet = xOffSet; - this.yOffSet = yOffSet; - } - - public int getIconHeight() { - return size; - } - - public int getIconWidth() { - return size; - } - - public void paintIcon(Component c, Graphics g, int x, int y) { - Graphics2D g2D = (Graphics2D) g; - g2D.setStroke(new BasicStroke(1.5f)); - g2D.setRenderingHint( - RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - g2D.setColor(Color.black); - g2D.drawLine( - x + xOffSet, y + yOffSet, x + size + xOffSet, y + size + yOffSet); - g2D.drawLine( - x + xOffSet, y + size + yOffSet, x + size + xOffSet, y + yOffSet); + private static class CloseIcon implements Icon { + int size; + int xOffSet; + int yOffSet; + + public CloseIcon(int size, int xOffSet, int yOffSet) { + this.size = size; + this.xOffSet = xOffSet; + this.yOffSet = yOffSet; + } + + public int getIconHeight() { + return size; + } + + public int getIconWidth() { + return size; + } + + public void paintIcon(Component c, Graphics g, int x, int y) { + Graphics2D g2D = (Graphics2D) g; + g2D.setStroke(new BasicStroke(1.5f)); + g2D.setRenderingHint( + RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2D.setColor(Color.black); + g2D.drawLine( + x + xOffSet, y + yOffSet, x + size + xOffSet, y + size + yOffSet); + g2D.drawLine( + x + xOffSet, y + size + yOffSet, x + size + xOffSet, y + yOffSet); + } } - } }
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/layout/DefaultLayoutFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/layout/DefaultLayoutFactory.java b/src/main/java/org/apache/log4j/chainsaw/layout/DefaultLayoutFactory.java index 5a17650..76fe31b 100644 --- a/src/main/java/org/apache/log4j/chainsaw/layout/DefaultLayoutFactory.java +++ b/src/main/java/org/apache/log4j/chainsaw/layout/DefaultLayoutFactory.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,75 +17,76 @@ package org.apache.log4j.chainsaw.layout; +import org.apache.log4j.LogManager; +import org.apache.log4j.PatternLayout; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; -import org.apache.log4j.LogManager; -import org.apache.log4j.PatternLayout; - /** * Factory class to load and cache Layout information from resources. - * + * * @author Paul Smith <psm...@apache.org> */ public class DefaultLayoutFactory { - private volatile static String defaultPatternLayout = null; + private volatile static String defaultPatternLayout = null; - private DefaultLayoutFactory() { - } + private DefaultLayoutFactory() { + } - public static String getDefaultPatternLayout() { - return getPatternLayout("org/apache/log4j/chainsaw/layout/DefaultDetailLayout.html"); - } - public static String getFullPatternLayout() { - return getPatternLayout("org/apache/log4j/chainsaw/layout/FullDetailLayout.html"); - } + public static String getDefaultPatternLayout() { + return getPatternLayout("org/apache/log4j/chainsaw/layout/DefaultDetailLayout.html"); + } - private static String getPatternLayout(String fileNamePath) { - StringBuffer content = new StringBuffer(); - URL defaultLayoutURL = - DefaultLayoutFactory.class.getClassLoader().getResource(fileNamePath); + public static String getFullPatternLayout() { + return getPatternLayout("org/apache/log4j/chainsaw/layout/FullDetailLayout.html"); + } - if (defaultLayoutURL == null) { - LogManager.getLogger(DefaultLayoutFactory.class).warn( - "Could not locate the default Layout for Event Details and Tooltips"); - } else { - try { - BufferedReader reader = null; + private static String getPatternLayout(String fileNamePath) { + StringBuffer content = new StringBuffer(); + URL defaultLayoutURL = + DefaultLayoutFactory.class.getClassLoader().getResource(fileNamePath); - try { - reader = - new BufferedReader( - new InputStreamReader(defaultLayoutURL.openStream())); + if (defaultLayoutURL == null) { + LogManager.getLogger(DefaultLayoutFactory.class).warn( + "Could not locate the default Layout for Event Details and Tooltips"); + } else { + try { + BufferedReader reader = null; - String line; + try { + reader = + new BufferedReader( + new InputStreamReader(defaultLayoutURL.openStream())); - while ((line = reader.readLine()) != null) { - content.append(line).append("\n"); - } - } finally { - if (reader != null) { - reader.close(); + String line; + + while ((line = reader.readLine()) != null) { + content.append(line).append("\n"); + } + } finally { + if (reader != null) { + reader.close(); + } + } + } catch (Exception e) { + content = new StringBuffer(PatternLayout.TTCC_CONVERSION_PATTERN); } - } - } catch (Exception e) { - content = new StringBuffer(PatternLayout.TTCC_CONVERSION_PATTERN); - } - String trimmedContent = content.toString().trim(); - //the default docs contain the apache license header, strip that out before displaying - String startComment = "<!--"; - String endComment = "-->"; - if (trimmedContent.startsWith(startComment)) { - int endIndex = trimmedContent.indexOf(endComment); - if (endIndex > -1) { - trimmedContent = trimmedContent.substring(endIndex + endComment.length()).trim(); + String trimmedContent = content.toString().trim(); + //the default docs contain the apache license header, strip that out before displaying + String startComment = "<!--"; + String endComment = "-->"; + if (trimmedContent.startsWith(startComment)) { + int endIndex = trimmedContent.indexOf(endComment); + if (endIndex > -1) { + trimmedContent = trimmedContent.substring(endIndex + endComment.length()).trim(); + } } + defaultPatternLayout = trimmedContent; } - defaultPatternLayout = trimmedContent; - } - return defaultPatternLayout; - } + return defaultPatternLayout; + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java b/src/main/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java index 82e0f74..1b594e6 100644 --- a/src/main/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java +++ b/src/main/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,187 +17,189 @@ package org.apache.log4j.chainsaw.layout; -import java.util.Hashtable; -import java.util.Set; - import org.apache.log4j.EnhancedPatternLayout; import org.apache.log4j.Layout; import org.apache.log4j.Logger; import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; +import java.util.Hashtable; +import java.util.Set; + /** * This layout is used for formatting HTML text for use inside * the Chainsaw Event Detail Panel, and the tooltip used * when mouse-over on a particular log event row. - * + * <p> * It relies an an internal PatternLayout to accomplish this, but ensures HTML characters * from any LoggingEvent are escaped first. * * @author Paul Smith <psm...@apache.org> */ public class EventDetailLayout extends Layout { - private final EnhancedPatternLayout patternLayout = new EnhancedPatternLayout(); - - public EventDetailLayout() { - } - - public void setConversionPattern(String conversionPattern) { - patternLayout.setConversionPattern(conversionPattern); - patternLayout.activateOptions(); - } - - public String getConversionPattern() { - return patternLayout.getConversionPattern(); - } - - /* (non-Javadoc) - * @see org.apache.log4j.Layout#getFooter() - */ - public String getFooter() { - return ""; - } - - /* (non-Javadoc) - * @see org.apache.log4j.Layout#getHeader() - */ - public String getHeader() { - return ""; - } - - // /* (non-Javadoc) - // * @see org.apache.log4j.Layout#format(java.io.Writer, org.apache.log4j.spi.LoggingEvent) - // */ - // public void format(Writer output, LoggingEvent event) - // throws IOException { - // boolean pastFirst = false; - // output.write("<html><body><table cellspacing=0 cellpadding=0>"); - // - // List columnNames = ChainsawColumns.getColumnsNames(); - // - // Vector v = ChainsawAppenderHandler.convert(event); - // - // /** - // * we need to add the ID property from the event - // */ - // v.add(event.getProperty(ChainsawConstants.LOG4J_ID_KEY)); - // - // // ListIterator iter = displayFilter.getDetailColumns().listIterator(); - // Iterator iter = columnNames.iterator(); - // String column = null; - // int index = -1; - // - // while (iter.hasNext()) { - // column = (String) iter.next(); - // index = columnNames.indexOf(column); - // - // if (index > -1) { - // if (pastFirst) { - // output.write("</td></tr>"); - // } - // - // output.write("<tr><td valign=\"top\"><b>"); - // output.write(column); - // output.write(": </b></td><td>"); - // - // - // if (index<v.size()) { - // Object o = v.get(index); - // - // if (o != null) { - // output.write(escape(o.toString())); - // } else { - // output.write("{null}"); - // } - // - // }else { - //// output.write("Invalid column " + column + " (index=" + index + ")"); - // } - // - // pastFirst = true; - // } - // } - // - // output.write("</table></body></html>"); - // } - - /** - * Escape <, > & and " as their entities. It is very - * dumb about & handling. - * @param aStr the String to escape. - * @return the escaped String - */ - private static String escape(String string) { - if (string == null) { - return ""; + private final EnhancedPatternLayout patternLayout = new EnhancedPatternLayout(); + + public EventDetailLayout() { } - final StringBuilder buf = new StringBuilder(); + public void setConversionPattern(String conversionPattern) { + patternLayout.setConversionPattern(conversionPattern); + patternLayout.activateOptions(); + } + + public String getConversionPattern() { + return patternLayout.getConversionPattern(); + } + + /* (non-Javadoc) + * @see org.apache.log4j.Layout#getFooter() + */ + public String getFooter() { + return ""; + } - for (int i = 0; i < string.length(); i++) { - char c = string.charAt(i); + /* (non-Javadoc) + * @see org.apache.log4j.Layout#getHeader() + */ + public String getHeader() { + return ""; + } + + // /* (non-Javadoc) + // * @see org.apache.log4j.Layout#format(java.io.Writer, org.apache.log4j.spi.LoggingEvent) + // */ + // public void format(Writer output, LoggingEvent event) + // throws IOException { + // boolean pastFirst = false; + // output.write("<html><body><table cellspacing=0 cellpadding=0>"); + // + // List columnNames = ChainsawColumns.getColumnsNames(); + // + // Vector v = ChainsawAppenderHandler.convert(event); + // + // /** + // * we need to add the ID property from the event + // */ + // v.add(event.getProperty(ChainsawConstants.LOG4J_ID_KEY)); + // + // // ListIterator iter = displayFilter.getDetailColumns().listIterator(); + // Iterator iter = columnNames.iterator(); + // String column = null; + // int index = -1; + // + // while (iter.hasNext()) { + // column = (String) iter.next(); + // index = columnNames.indexOf(column); + // + // if (index > -1) { + // if (pastFirst) { + // output.write("</td></tr>"); + // } + // + // output.write("<tr><td valign=\"top\"><b>"); + // output.write(column); + // output.write(": </b></td><td>"); + // + // + // if (index<v.size()) { + // Object o = v.get(index); + // + // if (o != null) { + // output.write(escape(o.toString())); + // } else { + // output.write("{null}"); + // } + // + // }else { + //// output.write("Invalid column " + column + " (index=" + index + ")"); + // } + // + // pastFirst = true; + // } + // } + // + // output.write("</table></body></html>"); + // } + + /** + * Escape <, > & and " as their entities. It is very + * dumb about & handling. + * + * @param aStr the String to escape. + * @return the escaped String + */ + private static String escape(String string) { + if (string == null) { + return ""; + } - switch (c) { - case '<': - buf.append("<"); + final StringBuilder buf = new StringBuilder(); - break; + for (int i = 0; i < string.length(); i++) { + char c = string.charAt(i); - case '>': - buf.append(">"); + switch (c) { + case '<': + buf.append("<"); - break; + break; - case '\"': - buf.append("""); + case '>': + buf.append(">"); - break; + break; - case '&': - buf.append("&"); + case '\"': + buf.append("""); - break; + break; - default: - buf.append(c); + case '&': + buf.append("&"); - break; - } + break; + + default: + buf.append(c); + + break; + } + } + + return buf.toString(); } - return buf.toString(); - } - - /** - * Takes a source event and copies it into a new LoggingEvent object - * and ensuring all the internal elements of the event are HTML safe - * @param event - * @return new LoggingEvent - */ - private static LoggingEvent copyForHTML(LoggingEvent event) { - Logger logger = Logger.getLogger(event.getLoggerName()); - String threadName = event.getThreadName(); - Object msg = escape(event.getMessage().toString()); - String ndc = event.getNDC(); + /** + * Takes a source event and copies it into a new LoggingEvent object + * and ensuring all the internal elements of the event are HTML safe + * + * @param event + * @return new LoggingEvent + */ + private static LoggingEvent copyForHTML(LoggingEvent event) { + Logger logger = Logger.getLogger(event.getLoggerName()); + String threadName = event.getThreadName(); + Object msg = escape(event.getMessage().toString()); + String ndc = event.getNDC(); // Hashtable mdc = formatMDC(event); - LocationInfo li = null; - if (event.locationInformationExists()) { - li = formatLocationInfo(event); + LocationInfo li = null; + if (event.locationInformationExists()) { + li = formatLocationInfo(event); + } + Hashtable<String, String> properties = formatProperties(event); + LoggingEvent copy = new LoggingEvent(null, + logger, event.getTimeStamp(), + event.getLevel(), + msg, + threadName, + event.getThrowableInformation(), + ndc, + li, + properties); + + return copy; } - Hashtable<String, String> properties = formatProperties(event); - LoggingEvent copy = new LoggingEvent(null, - logger, event.getTimeStamp(), - event.getLevel(), - msg, - threadName, - event.getThrowableInformation(), - ndc, - li, - properties); - - return copy; - } // /** // * @param event @@ -216,62 +218,62 @@ public class EventDetailLayout extends Layout { // return hashTable; // } - /** - * @param event - * @return - */ - private static LocationInfo formatLocationInfo(LoggingEvent event) { - LocationInfo info = event.getLocationInformation(); - LocationInfo newInfo = - new LocationInfo( - escape(info.getFileName()), escape(info.getClassName()), - escape(info.getMethodName()), escape(info.getLineNumber())); - - return newInfo; - } - - /** - * @param event - * @return - */ - private static Hashtable<String, String> formatProperties(LoggingEvent event) { - Set keySet = event.getPropertyKeySet(); - Hashtable<String, String> hashTable = new Hashtable<>(); - - for (Object key : keySet) { - Object value = event.getProperty(key.toString()); - hashTable.put(escape(key.toString()), escape(value.toString())); - } - - return hashTable; - } - - /* (non-Javadoc) + /** + * @param event + * @return + */ + private static LocationInfo formatLocationInfo(LoggingEvent event) { + LocationInfo info = event.getLocationInformation(); + LocationInfo newInfo = + new LocationInfo( + escape(info.getFileName()), escape(info.getClassName()), + escape(info.getMethodName()), escape(info.getLineNumber())); + + return newInfo; + } + + /** + * @param event + * @return + */ + private static Hashtable<String, String> formatProperties(LoggingEvent event) { + Set keySet = event.getPropertyKeySet(); + Hashtable<String, String> hashTable = new Hashtable<>(); + + for (Object key : keySet) { + Object value = event.getProperty(key.toString()); + hashTable.put(escape(key.toString()), escape(value.toString())); + } + + return hashTable; + } + + /* (non-Javadoc) * @see org.apache.log4j.Layout#ignoresThrowable() */ - public boolean ignoresThrowable() { - return false; - } - - /* (non-Javadoc) - * @see org.apache.log4j.spi.OptionHandler#activateOptions() - */ - public void activateOptions() { - } - - /* (non-Javadoc) - * @see org.apache.log4j.Layout#format(java.io.Writer, org.apache.log4j.spi.LoggingEvent) - */ - public String format(final LoggingEvent event) { - LoggingEvent newEvent = copyForHTML(event); - /** - * Layouts are not thread-safe, but are normally - * protected by the fact that their Appender is thread-safe. - * - * But here in Chainsaw there is no such guarantees. - */ - synchronized(patternLayout) { - return patternLayout.format(newEvent); - } - } + public boolean ignoresThrowable() { + return false; + } + + /* (non-Javadoc) + * @see org.apache.log4j.spi.OptionHandler#activateOptions() + */ + public void activateOptions() { + } + + /* (non-Javadoc) + * @see org.apache.log4j.Layout#format(java.io.Writer, org.apache.log4j.spi.LoggingEvent) + */ + public String format(final LoggingEvent event) { + LoggingEvent newEvent = copyForHTML(event); + /** + * Layouts are not thread-safe, but are normally + * protected by the fact that their Appender is thread-safe. + * + * But here in Chainsaw there is no such guarantees. + */ + synchronized (patternLayout) { + return patternLayout.format(newEvent); + } + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java b/src/main/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java index a95635b..38d6a38 100644 --- a/src/main/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java +++ b/src/main/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,29 +17,6 @@ package org.apache.log4j.chainsaw.layout; -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Date; -import java.util.Hashtable; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JEditorPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JToolBar; -import javax.swing.ScrollPaneConstants; -import javax.swing.WindowConstants; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - import org.apache.log4j.Logger; import org.apache.log4j.chainsaw.ChainsawConstants; import org.apache.log4j.chainsaw.JTextComponentFormatter; @@ -48,219 +25,227 @@ import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.ThrowableInformation; +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Date; +import java.util.Hashtable; + /** * An editor Pane that allows a user to Edit a Pattern Layout and preview the output it would * generate with an example LoggingEvent - * - * @author Paul Smith <psm...@apache.org> * + * @author Paul Smith <psm...@apache.org> */ public final class LayoutEditorPane extends JPanel { - private final Action copyAction; - private final Action cutAction; - private final JToolBar editorToolbar = new JToolBar(); - private final JToolBar okCancelToolbar = new JToolBar(); - private final JButton okButton = new JButton(" OK "); - private final JButton cancelButton = new JButton(" Cancel "); - - // private final JButton applyButton = new JButton(); - private final JEditorPane patternEditor = new JEditorPane("text/plain", ""); - private final JEditorPane previewer = - new JEditorPane(ChainsawConstants.DETAIL_CONTENT_TYPE, ""); - private final JScrollPane patternEditorScroll = - new JScrollPane( - ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); - private final JScrollPane previewEditorScroll = - new JScrollPane( - ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); - private LoggingEvent event; - private EventDetailLayout layout = new EventDetailLayout(); - - /** - * - */ - public LayoutEditorPane() { - super(); - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - createEvent(); - copyAction = createCopyAction(); - cutAction = createCutAction(); - initComponents(); - setupListeners(); - } - - /** - * @return - */ - private Action createCutAction() { - final Action action = - new AbstractAction("Cut", ChainsawIcons.ICON_CUT) { - public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - } - }; - - action.setEnabled(false); - - return action; - } - - /** - * @return - */ - private Action createCopyAction() { - final Action action = - new AbstractAction("Copy", ChainsawIcons.ICON_COPY) { - public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - } - }; - - action.setEnabled(false); - - return action; - } - - /** - * - */ - private void setupListeners() { - patternEditor.getDocument().addDocumentListener( - new DocumentListener() { - public void changedUpdate(DocumentEvent e) { - updatePreview(); - } - - public void insertUpdate(DocumentEvent e) { - updatePreview(); - } - - public void removeUpdate(DocumentEvent e) { - updatePreview(); - } - }); - - patternEditor.addCaretListener( + private final Action copyAction; + private final Action cutAction; + private final JToolBar editorToolbar = new JToolBar(); + private final JToolBar okCancelToolbar = new JToolBar(); + private final JButton okButton = new JButton(" OK "); + private final JButton cancelButton = new JButton(" Cancel "); + + // private final JButton applyButton = new JButton(); + private final JEditorPane patternEditor = new JEditorPane("text/plain", ""); + private final JEditorPane previewer = + new JEditorPane(ChainsawConstants.DETAIL_CONTENT_TYPE, ""); + private final JScrollPane patternEditorScroll = + new JScrollPane( + ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + private final JScrollPane previewEditorScroll = + new JScrollPane( + ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + private LoggingEvent event; + private EventDetailLayout layout = new EventDetailLayout(); + + /** + * + */ + public LayoutEditorPane() { + super(); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + createEvent(); + copyAction = createCopyAction(); + cutAction = createCutAction(); + initComponents(); + setupListeners(); + } + + /** + * @return + */ + private Action createCutAction() { + final Action action = + new AbstractAction("Cut", ChainsawIcons.ICON_CUT) { + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + } + }; + + action.setEnabled(false); + + return action; + } + + /** + * @return + */ + private Action createCopyAction() { + final Action action = + new AbstractAction("Copy", ChainsawIcons.ICON_COPY) { + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + } + }; + + action.setEnabled(false); + + return action; + } + + /** + * + */ + private void setupListeners() { + patternEditor.getDocument().addDocumentListener( + new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + updatePreview(); + } + + public void insertUpdate(DocumentEvent e) { + updatePreview(); + } + + public void removeUpdate(DocumentEvent e) { + updatePreview(); + } + }); + + patternEditor.addCaretListener( e -> updateTextActions(e.getMark() != e.getDot())); - } - - private void updatePreview() { - String pattern = patternEditor.getText(); - layout.setConversionPattern(pattern); - - previewer.setText(layout.format(event)); - } - - /** - * - */ - private void updateTextActions(boolean enabled) { - cutAction.setEnabled(enabled); - copyAction.setEnabled(enabled); - } - - /** - * - */ - private void createEvent() { - Hashtable<String, String> hashTable = new Hashtable<>(); - hashTable.put("key1", "val1"); - hashTable.put("key2", "val2"); - hashTable.put("key3", "val3"); - - LocationInfo li = - new LocationInfo( - "myfile.java", "com.mycompany.util.MyClass", "myMethod", "321"); - - ThrowableInformation tsr = new ThrowableInformation(new Exception()); - - event = new LoggingEvent("org.apache.log4j.Logger", - Logger.getLogger("com.mycompany.mylogger"), - new Date().getTime(), - org.apache.log4j.Level.DEBUG, - "The quick brown fox jumped over the lazy dog", - "Thread-1", - tsr, - "NDC string", - li, - hashTable); - - } - - /** + } + + private void updatePreview() { + String pattern = patternEditor.getText(); + layout.setConversionPattern(pattern); + + previewer.setText(layout.format(event)); + } + + /** + * + */ + private void updateTextActions(boolean enabled) { + cutAction.setEnabled(enabled); + copyAction.setEnabled(enabled); + } + + /** + * + */ + private void createEvent() { + Hashtable<String, String> hashTable = new Hashtable<>(); + hashTable.put("key1", "val1"); + hashTable.put("key2", "val2"); + hashTable.put("key3", "val3"); + + LocationInfo li = + new LocationInfo( + "myfile.java", "com.mycompany.util.MyClass", "myMethod", "321"); + + ThrowableInformation tsr = new ThrowableInformation(new Exception()); + + event = new LoggingEvent("org.apache.log4j.Logger", + Logger.getLogger("com.mycompany.mylogger"), + new Date().getTime(), + org.apache.log4j.Level.DEBUG, + "The quick brown fox jumped over the lazy dog", + "Thread-1", + tsr, + "NDC string", + li, + hashTable); + + } + + /** * */ - private void initComponents() { - editorToolbar.setFloatable(false); - okCancelToolbar.setFloatable(false); - okButton.setToolTipText("Accepts the current Pattern layout and will apply it to the Log Panel"); - cancelButton.setToolTipText("Closes this dialog and discards your changes"); - - JTextComponentFormatter.applySystemFontAndSize(previewer); - - previewer.setEditable(false); - patternEditor.setPreferredSize(new Dimension(240, 240)); - patternEditor.setMaximumSize(new Dimension(320, 240)); - previewer.setPreferredSize(new Dimension(360, 240)); - patternEditorScroll.setViewportView(patternEditor); - previewEditorScroll.setViewportView(previewer); - - patternEditor.setToolTipText("Edit the Pattern here"); - previewer.setToolTipText( - "The result of the layout of the pattern is shown here"); - - patternEditorScroll.setBorder( - BorderFactory.createTitledBorder( - BorderFactory.createEtchedBorder(), "Pattern Editor")); - previewEditorScroll.setBorder( - BorderFactory.createTitledBorder( - BorderFactory.createEtchedBorder(), "Pattern Preview")); + private void initComponents() { + editorToolbar.setFloatable(false); + okCancelToolbar.setFloatable(false); + okButton.setToolTipText("Accepts the current Pattern layout and will apply it to the Log Panel"); + cancelButton.setToolTipText("Closes this dialog and discards your changes"); + + JTextComponentFormatter.applySystemFontAndSize(previewer); + + previewer.setEditable(false); + patternEditor.setPreferredSize(new Dimension(240, 240)); + patternEditor.setMaximumSize(new Dimension(320, 240)); + previewer.setPreferredSize(new Dimension(360, 240)); + patternEditorScroll.setViewportView(patternEditor); + previewEditorScroll.setViewportView(previewer); + + patternEditor.setToolTipText("Edit the Pattern here"); + previewer.setToolTipText( + "The result of the layout of the pattern is shown here"); + + patternEditorScroll.setBorder( + BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Pattern Editor")); + previewEditorScroll.setBorder( + BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Pattern Preview")); // editorToolbar.add(new JButton(copyAction)); // editorToolbar.add(new JButton(cutAction)); - editorToolbar.add(Box.createHorizontalGlue()); - - okCancelToolbar.add(Box.createHorizontalGlue()); - okCancelToolbar.add(okButton); - okCancelToolbar.addSeparator(); - okCancelToolbar.add(cancelButton); - - // okCancelToolbar.addSeparator(); - // okCancelToolbar.add(applyButton); - add(editorToolbar); - add(patternEditorScroll); - add(previewEditorScroll); - add(okCancelToolbar); - } - - public void setConversionPattern(String pattern) { - patternEditor.setText(pattern); - } - - public String getConversionPattern() { - return patternEditor.getText(); - } - - public void addOkActionListener(ActionListener l) { - okButton.addActionListener(l); - } - - public void addCancelActionListener(ActionListener l) { - cancelButton.addActionListener(l); - } - - public static void main(String[] args) { - JDialog dialog = new JDialog((Frame) null, "Pattern Editor"); - dialog.getContentPane().add(new LayoutEditorPane()); - dialog.setResizable(true); - dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - - // dialog.pack(); - dialog.setSize(new Dimension(640, 480)); - dialog.setVisible(true); - } + editorToolbar.add(Box.createHorizontalGlue()); + + okCancelToolbar.add(Box.createHorizontalGlue()); + okCancelToolbar.add(okButton); + okCancelToolbar.addSeparator(); + okCancelToolbar.add(cancelButton); + + // okCancelToolbar.addSeparator(); + // okCancelToolbar.add(applyButton); + add(editorToolbar); + add(patternEditorScroll); + add(previewEditorScroll); + add(okCancelToolbar); + } + + public void setConversionPattern(String pattern) { + patternEditor.setText(pattern); + } + + public String getConversionPattern() { + return patternEditor.getText(); + } + + public void addOkActionListener(ActionListener l) { + okButton.addActionListener(l); + } + + public void addCancelActionListener(ActionListener l) { + cancelButton.addActionListener(l); + } + + public static void main(String[] args) { + JDialog dialog = new JDialog((Frame) null, "Pattern Editor"); + dialog.getContentPane().add(new LayoutEditorPane()); + dialog.setResizable(true); + dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + + // dialog.pack(); + dialog.setSize(new Dimension(640, 480)); + dialog.setVisible(true); + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/messages/MessageCenter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/messages/MessageCenter.java b/src/main/java/org/apache/log4j/chainsaw/messages/MessageCenter.java index f2751ee..68fb5e3 100644 --- a/src/main/java/org/apache/log4j/chainsaw/messages/MessageCenter.java +++ b/src/main/java/org/apache/log4j/chainsaw/messages/MessageCenter.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,27 +17,6 @@ package org.apache.log4j.chainsaw.messages; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeSupport; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.DefaultListCellRenderer; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JToolBar; -import javax.swing.ListCellRenderer; -import javax.swing.ListModel; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; - import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -49,204 +28,211 @@ import org.apache.log4j.chainsaw.SmallButton; import org.apache.log4j.chainsaw.icons.ChainsawIcons; import org.apache.log4j.varia.ListModelAppender; +import javax.swing.*; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeSupport; + /** * The MessageCenter is central place for all elements within Chainsaw to * notify the user of important information. - * + * <p> * This class uses log4j itself quite significantly. All user message * are sent to this classes log4j Logger (org.apache.log4j.chainsaw.message.MessageCenter). - * + * <p> * To register a message with the user, you can use the addMessage(String) style methods on * this class, or just as easily, get a handle to this class' logger, and log * it as you would normally do. - * + * <p> * All events to this logger are trapped within a Custom appender (additivity * will be switched OFF), which stores the events in a ListModel. - * + * <p> * You can invoke the setVisible() method to display all the messages * * @author Paul Smith <psm...@apache.org> - * */ public class MessageCenter { - private static final MessageCenter instance = new MessageCenter(); - private final Logger logger = Logger.getLogger(MessageCenter.class); - private Layout layout = new TTCCLayout(); - private final JList<org.apache.log4j.spi.LoggingEvent> messageList = new JList<>(); - private final ListModelAppender appender = new ListModelAppender(); - private ListCellRenderer listCellRenderer = - new LayoutListCellRenderer(layout); - private PropertyChangeSupport propertySupport = - new PropertyChangeSupport(this); - private JScrollPane pane = new JScrollPane(messageList); - private final JToolBar toolbar = new JToolBar(); - private JPopupMenu popupMenu = new JPopupMenu(); - private PopupListener popupListener = new PopupListener(popupMenu); - private Action clearAction; - private final JPanel componentPanel = new JPanel(new BorderLayout()); - - private MessageCenter() { - setupActions(); - setupComponentPanel(); - setupLogger(); - setupListeners(); - setupPopMenu(); - setupToolbar(); - } - - /** - * - */ - private void setupPopMenu() { - popupMenu.add(clearAction); - } - - /** - * - */ - private void setupToolbar() { - JButton clearButton = new SmallButton(clearAction); - clearButton.setText(null); - toolbar.add(clearButton); - - toolbar.setFloatable(false); - } - - private void setupActions() { - clearAction = - new AbstractAction("Clear") { - public void actionPerformed(ActionEvent e) { - appender.clearModel(); - } - }; - clearAction.putValue( - Action.SMALL_ICON, new ImageIcon(ChainsawIcons.DELETE)); - } - - private void setupListeners() { - propertySupport.addPropertyChangeListener( - "layout", + private static final MessageCenter instance = new MessageCenter(); + private final Logger logger = Logger.getLogger(MessageCenter.class); + private Layout layout = new TTCCLayout(); + private final JList<org.apache.log4j.spi.LoggingEvent> messageList = new JList<>(); + private final ListModelAppender appender = new ListModelAppender(); + private ListCellRenderer listCellRenderer = + new LayoutListCellRenderer(layout); + private PropertyChangeSupport propertySupport = + new PropertyChangeSupport(this); + private JScrollPane pane = new JScrollPane(messageList); + private final JToolBar toolbar = new JToolBar(); + private JPopupMenu popupMenu = new JPopupMenu(); + private PopupListener popupListener = new PopupListener(popupMenu); + private Action clearAction; + private final JPanel componentPanel = new JPanel(new BorderLayout()); + + private MessageCenter() { + setupActions(); + setupComponentPanel(); + setupLogger(); + setupListeners(); + setupPopMenu(); + setupToolbar(); + } + + /** + * + */ + private void setupPopMenu() { + popupMenu.add(clearAction); + } + + /** + * + */ + private void setupToolbar() { + JButton clearButton = new SmallButton(clearAction); + clearButton.setText(null); + toolbar.add(clearButton); + + toolbar.setFloatable(false); + } + + private void setupActions() { + clearAction = + new AbstractAction("Clear") { + public void actionPerformed(ActionEvent e) { + appender.clearModel(); + } + }; + clearAction.putValue( + Action.SMALL_ICON, new ImageIcon(ChainsawIcons.DELETE)); + } + + private void setupListeners() { + propertySupport.addPropertyChangeListener( + "layout", evt -> { - Layout newLayout = (Layout) evt.getNewValue(); - messageList.setCellRenderer(new LayoutListCellRenderer(newLayout)); + Layout newLayout = (Layout) evt.getNewValue(); + messageList.setCellRenderer(new LayoutListCellRenderer(newLayout)); }); - messageList.addMouseListener(popupListener); + messageList.addMouseListener(popupListener); - appender.getModel().addListDataListener( - new ListDataListener() { - public void contentsChanged(ListDataEvent e) { - updateActions(); - } + appender.getModel().addListDataListener( + new ListDataListener() { + public void contentsChanged(ListDataEvent e) { + updateActions(); + } - public void intervalAdded(ListDataEvent e) { - updateActions(); - } + public void intervalAdded(ListDataEvent e) { + updateActions(); + } - public void intervalRemoved(ListDataEvent e) { - updateActions(); - } - }); - } - - /** - * - */ - private void updateActions() { - clearAction.putValue( - "enabled", - (appender.getModel().getSize() > 0) ? Boolean.TRUE : Boolean.FALSE); - } - - private void setupLogger() { - logger.addAppender(appender); - logger.setAdditivity(true); - logger.setLevel(Boolean.getBoolean("log4j.debug")?Level.DEBUG:Level.INFO); - } - - private void setupComponentPanel() { - messageList.setModel(appender.getModel()); - messageList.setCellRenderer(listCellRenderer); - - componentPanel.add(this.toolbar, BorderLayout.NORTH); - componentPanel.add(this.pane, BorderLayout.CENTER); - } - - public final JComponent getGUIComponent() { - return componentPanel; - } - - public ListModel<org.apache.log4j.spi.LoggingEvent> getModel() { - return messageList.getModel(); - } - - public static MessageCenter getInstance() { - return instance; - } - - public void addMessage(String message) { - logger.info(message); - } - - - /** - * @return Returns the layout used by the MessageCenter. - */ - public final Layout getLayout() { - return layout; - } - - /** - * @param layout Sets the layout to be used by the MessageCenter . - */ - public final void setLayout(Layout layout) { - Layout oldValue = this.layout; - this.layout = layout; - propertySupport.firePropertyChange("layout", oldValue, this.layout); - } - - /** - * Returns the logger that can be used to log - * messages to display within the Message Center. - * @return logger - */ - public final Logger getLogger() { - return this.logger; - } - - /** - * This class simply renders an event by delegating the effort to a - * Log4j layout instance. - * - * @author Paul Smith <psm...@apache.org> - */ - private static class LayoutListCellRenderer extends DefaultListCellRenderer { - private Layout layout; + public void intervalRemoved(ListDataEvent e) { + updateActions(); + } + }); + } + + /** + * + */ + private void updateActions() { + clearAction.putValue( + "enabled", + (appender.getModel().getSize() > 0) ? Boolean.TRUE : Boolean.FALSE); + } + + private void setupLogger() { + logger.addAppender(appender); + logger.setAdditivity(true); + logger.setLevel(Boolean.getBoolean("log4j.debug") ? Level.DEBUG : Level.INFO); + } + + private void setupComponentPanel() { + messageList.setModel(appender.getModel()); + messageList.setCellRenderer(listCellRenderer); + + componentPanel.add(this.toolbar, BorderLayout.NORTH); + componentPanel.add(this.pane, BorderLayout.CENTER); + } + + public final JComponent getGUIComponent() { + return componentPanel; + } + + public ListModel<org.apache.log4j.spi.LoggingEvent> getModel() { + return messageList.getModel(); + } + + public static MessageCenter getInstance() { + return instance; + } + + public void addMessage(String message) { + logger.info(message); + } + + + /** + * @return Returns the layout used by the MessageCenter. + */ + public final Layout getLayout() { + return layout; + } /** - * @param layout + * @param layout Sets the layout to be used by the MessageCenter . */ - public LayoutListCellRenderer(Layout layout) { - super(); - this.layout = layout; + public final void setLayout(Layout layout) { + Layout oldValue = this.layout; + this.layout = layout; + propertySupport.firePropertyChange("layout", oldValue, this.layout); } - /* (non-Javadoc) - * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) + /** + * Returns the logger that can be used to log + * messages to display within the Message Center. + * + * @return logger */ - public Component getListCellRendererComponent( - JList list, Object value, int index, boolean isSelected, - boolean cellHasFocus) { - value = layout.format(((LoggingEventWrapper) value).getLoggingEvent()); + public final Logger getLogger() { + return this.logger; + } - Component c = - super.getListCellRendererComponent( - list, value, index, isSelected, cellHasFocus); - c.setBackground( - ((index % 2) == 0) ? ChainsawConstants.COLOR_EVEN_ROW_BACKGROUND - : ChainsawConstants.COLOR_ODD_ROW_BACKGROUND); + /** + * This class simply renders an event by delegating the effort to a + * Log4j layout instance. + * + * @author Paul Smith <psm...@apache.org> + */ + private static class LayoutListCellRenderer extends DefaultListCellRenderer { + private Layout layout; + + /** + * @param layout + */ + public LayoutListCellRenderer(Layout layout) { + super(); + this.layout = layout; + } - return c; + /* (non-Javadoc) + * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) + */ + public Component getListCellRendererComponent( + JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + value = layout.format(((LoggingEventWrapper) value).getLoggingEvent()); + + Component c = + super.getListCellRendererComponent( + list, value, index, isSelected, cellHasFocus); + c.setBackground( + ((index % 2) == 0) ? ChainsawConstants.COLOR_EVEN_ROW_BACKGROUND + : ChainsawConstants.COLOR_ODD_ROW_BACKGROUND); + + return c; + } } - } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java b/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java index f4e13ce..8ac570b 100644 --- a/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java +++ b/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java @@ -16,33 +16,33 @@ */ package org.apache.log4j.chainsaw.osx; +import org.apache.log4j.Logger; +import org.apache.log4j.chainsaw.LogUI; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import org.apache.log4j.Logger; -import org.apache.log4j.chainsaw.LogUI; - /** - * This class adds dynamic hooks into OSX version of Java so that various + * This class adds dynamic hooks into OSX version of Java so that various * Mac-specific UI guidelines are adhered to. - * + * <p> * This class uses reflection to build the necessary hooks so that there is no compile-time * dependency on a Mac SDK. - * - * @see "http://developer.apple.com/documentation/Java/index.html" - * @author psmith * + * @author psmith + * @see "http://developer.apple.com/documentation/Java/index.html" */ public class OSXIntegration { public static final boolean IS_OSX = System.getProperty("os.name").startsWith("Mac OS X"); private static final Logger LOG = Logger.getLogger(OSXIntegration.class); private static Object applicationInstance; + public static final void init(final LogUI logui) { LOG.info("OSXIntegration.init() called"); - if(!IS_OSX) { + if (!IS_OSX) { LOG.info("Not OSX, ignoring..."); return; } @@ -50,44 +50,45 @@ public class OSXIntegration { Class applicationClazz = Class.forName("com.apple.eawt.Application"); Class listenerClass = Class.forName("com.apple.eawt.ApplicationListener"); applicationInstance = applicationClazz.newInstance(); - + // now register that we want that Preferences menu Method enablePreferenceMethod = applicationClazz.getMethod("setEnabledPreferencesMenu", boolean.class); enablePreferenceMethod.invoke(applicationInstance, Boolean.TRUE); - - + + // no About menu for us for now. Method enableAboutMethod = applicationClazz.getMethod("setEnabledAboutMenu", boolean.class); enableAboutMethod.invoke(applicationInstance, Boolean.TRUE); - + // Need to create a Proxy object to represent an anonymous impl of the ApplicationListener class - Object listenerProxy = Proxy.newProxyInstance(OSXIntegration.class.getClassLoader(), - new Class[] {listenerClass}, - new InvocationHandler() { + Object listenerProxy = Proxy.newProxyInstance(OSXIntegration.class.getClassLoader(), + new Class[]{listenerClass}, + new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - switch (method.getName()) { - case "handlePreferences": - LOG.info("handlePreferences(...) called"); - logui.showApplicationPreferences(); - break; - case "handleQuit": - setHandled(args[0], logui.exit() ? Boolean.TRUE : Boolean.FALSE); + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + switch (method.getName()) { + case "handlePreferences": + LOG.info("handlePreferences(...) called"); + logui.showApplicationPreferences(); + break; + case "handleQuit": + setHandled(args[0], logui.exit() ? Boolean.TRUE : Boolean.FALSE); - break; - case "handleAbout": - logui.showAboutBox(); - setHandled(args[0], Boolean.TRUE); - break; - } + break; + case "handleAbout": + logui.showAboutBox(); + setHandled(args[0], Boolean.TRUE); + break; + } // TODO think about File Open/Save options - return null; - } + return null; + } - private void setHandled(Object event, Boolean val) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - Method handleMethod = event.getClass().getMethod("setHandled", boolean.class); - handleMethod.invoke(event, val); - }}); + private void setHandled(Object event, Boolean val) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + Method handleMethod = event.getClass().getMethod("setHandled", boolean.class); + handleMethod.invoke(event, val); + } + }); // register the proxy object via the addApplicationListener method, cross fingers... Method registerListenerMethod = applicationClazz.getMethod("addApplicationListener", listenerClass); registerListenerMethod.invoke(applicationInstance, listenerProxy); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java b/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java index b2357bb..d7579ff 100644 --- a/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java +++ b/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,81 +20,80 @@ package org.apache.log4j.chainsaw.plugins; import org.apache.log4j.plugins.Plugin; import org.apache.log4j.spi.LoggerRepository; -import java.awt.LayoutManager; - -import javax.swing.JPanel; +import javax.swing.*; +import java.awt.*; /** */ public abstract class GUIPluginSkeleton extends JPanel implements Plugin { - private LoggerRepository loggerRepository; - private boolean active; + private LoggerRepository loggerRepository; + private boolean active; - /** - * - */ - public GUIPluginSkeleton() { - super(); - } + /** + * + */ + public GUIPluginSkeleton() { + super(); + } - /** - * @param isDoubleBuffered - */ - public GUIPluginSkeleton(boolean isDoubleBuffered) { - super(isDoubleBuffered); - } + /** + * @param isDoubleBuffered + */ + public GUIPluginSkeleton(boolean isDoubleBuffered) { + super(isDoubleBuffered); + } - /** - * @param layout - */ - public GUIPluginSkeleton(LayoutManager layout) { - super(layout); - } + /** + * @param layout + */ + public GUIPluginSkeleton(LayoutManager layout) { + super(layout); + } - /** - * @param layout - * @param isDoubleBuffered - */ - public GUIPluginSkeleton(LayoutManager layout, boolean isDoubleBuffered) { - super(layout, isDoubleBuffered); - } + /** + * @param layout + * @param isDoubleBuffered + */ + public GUIPluginSkeleton(LayoutManager layout, boolean isDoubleBuffered) { + super(layout, isDoubleBuffered); + } - /* (non-Javadoc) - * @see org.apache.log4j.plugins.Plugin#getLoggerRepository() - */ - public LoggerRepository getLoggerRepository() { - return this.loggerRepository; - } + /* (non-Javadoc) + * @see org.apache.log4j.plugins.Plugin#getLoggerRepository() + */ + public LoggerRepository getLoggerRepository() { + return this.loggerRepository; + } - /* (non-Javadoc) - * @see org.apache.log4j.plugins.Plugin#setLoggerRepository(org.apache.log4j.spi.LoggerRepository) - */ - public void setLoggerRepository(LoggerRepository repository) { - this.loggerRepository = repository; - } + /* (non-Javadoc) + * @see org.apache.log4j.plugins.Plugin#setLoggerRepository(org.apache.log4j.spi.LoggerRepository) + */ + public void setLoggerRepository(LoggerRepository repository) { + this.loggerRepository = repository; + } - /* (non-Javadoc) - * @see org.apache.log4j.plugins.Plugin#isActive() - */ - public boolean isActive() { - return active; - } + /* (non-Javadoc) + * @see org.apache.log4j.plugins.Plugin#isActive() + */ + public boolean isActive() { + return active; + } - /* (non-Javadoc) - * @see org.apache.log4j.plugins.Plugin#isEquivalent(org.apache.log4j.plugins.Plugin) - */ - public boolean isEquivalent(Plugin testPlugin) { - // TODO Auto-generated method stub - return false; - } + /* (non-Javadoc) + * @see org.apache.log4j.plugins.Plugin#isEquivalent(org.apache.log4j.plugins.Plugin) + */ + public boolean isEquivalent(Plugin testPlugin) { + // TODO Auto-generated method stub + return false; + } - /** - * @param active The active to set. - */ - public final void setActive(boolean active) { - boolean oldValue = this.active; - this.active = active; - firePropertyChange("active", oldValue, this.active); - } + /** + * @param active The active to set. + */ + public final void setActive(boolean active) { + boolean oldValue = this.active; + this.active = active; + firePropertyChange("active", oldValue, this.active); + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java b/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java index a96dd15..9ffabd1 100644 --- a/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java +++ b/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java @@ -16,83 +16,81 @@ */ package org.apache.log4j.chainsaw.plugins; +import org.apache.log4j.chainsaw.prefs.SettingsManager; + import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.chainsaw.prefs.SettingsManager; - /** * A factory class to create a Classloader that can refenerence jars/classes/resources * within a users plugin directory. - * + * <p> * Currently a work in progress to see if this allows external jars required by * some 3rd party vendors for things like the JMSReceiver. - * - * @author psmith * - * + * @author psmith */ public class PluginClassLoaderFactory { - private final ClassLoader pluginClassLoader; + private final ClassLoader pluginClassLoader; private static final PluginClassLoaderFactory instance = new PluginClassLoaderFactory(); - - private PluginClassLoaderFactory() { - this.pluginClassLoader= PluginClassLoaderFactory.create(new File(SettingsManager.getInstance().getSettingsDirectory() + File.separator + "plugins")); - } - + private PluginClassLoaderFactory() { + this.pluginClassLoader = PluginClassLoaderFactory.create(new File(SettingsManager.getInstance().getSettingsDirectory() + File.separator + "plugins")); + + } + public static PluginClassLoaderFactory getInstance() { - return instance; + return instance; } - + public ClassLoader getClassLoader() { - return this.pluginClassLoader; + return this.pluginClassLoader; } - + /** * Creates a Classloader that will be able to access any of the classes found * in any .JAR file contained within the specified directory path, PLUS * the actual Plugin directory itself, so it acts like the WEB-INF/classes directory, * any class file in the directory will be accessible - * + * * @param pluginDirectory - * @throws IllegalArgumentException if the pluginDirectory is null, does not exist, or cannot be read - * @throws RuntimeException if turning a File into a URL failed, which would be very unexpected * @return + * @throws IllegalArgumentException if the pluginDirectory is null, does not exist, or cannot be read + * @throws RuntimeException if turning a File into a URL failed, which would be very unexpected */ private static final ClassLoader create(File pluginDirectory) { - if(pluginDirectory == null || !pluginDirectory.exists() || !pluginDirectory.canRead()) { - return PluginClassLoaderFactory.class.getClassLoader(); + if (pluginDirectory == null || !pluginDirectory.exists() || !pluginDirectory.canRead()) { + return PluginClassLoaderFactory.class.getClassLoader(); } - + String[] strings = pluginDirectory.list((dir, name) -> name.toUpperCase().endsWith(".JAR")); - - + + List<URL> list = new ArrayList<>(); // add the plugin directory as a resource loading path try { - list.add(pluginDirectory.toURI().toURL()); - } catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } - if (strings !=null) { + list.add(pluginDirectory.toURI().toURL()); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + if (strings != null) { for (String name : strings) { File file = new File(pluginDirectory, name); try { list.add(file.toURI().toURL()); System.out.println("Added " + file.getAbsolutePath() - + " to Plugin class loader list"); + + " to Plugin class loader list"); } catch (Exception e) { System.err.println("Failed to retrieve the URL for file: " - + file.getAbsolutePath()); + + file.getAbsolutePath()); throw new RuntimeException(e.getMessage()); } } - } + } ClassLoader parent = PluginClassLoaderFactory.class.getClassLoader(); URL[] urls = (URL[]) list.toArray(new URL[list.size()]); return new URLClassLoader(urls, parent); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/prefs/AbstractSettingsEvent.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/AbstractSettingsEvent.java b/src/main/java/org/apache/log4j/chainsaw/prefs/AbstractSettingsEvent.java index 9277c28..7dc6d2e 100644 --- a/src/main/java/org/apache/log4j/chainsaw/prefs/AbstractSettingsEvent.java +++ b/src/main/java/org/apache/log4j/chainsaw/prefs/AbstractSettingsEvent.java @@ -21,23 +21,22 @@ import java.util.EventObject; /** * @author psmith - * */ class AbstractSettingsEvent extends EventObject { - - private final File settingsLocation; - - - /** - * @param source - */ - public AbstractSettingsEvent(Object source, File settingsLocation) { - super(source); - this.settingsLocation = settingsLocation; - - } - public File getSettingsLocation() { - return this.settingsLocation; - } + private final File settingsLocation; + + + /** + * @param source + */ + public AbstractSettingsEvent(Object source, File settingsLocation) { + super(source); + this.settingsLocation = settingsLocation; + + } + + public File getSettingsLocation() { + return this.settingsLocation; + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/prefs/LoadSettingsEvent.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/LoadSettingsEvent.java b/src/main/java/org/apache/log4j/chainsaw/prefs/LoadSettingsEvent.java index 2a848da..0b5849e 100644 --- a/src/main/java/org/apache/log4j/chainsaw/prefs/LoadSettingsEvent.java +++ b/src/main/java/org/apache/log4j/chainsaw/prefs/LoadSettingsEvent.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,63 +16,60 @@ */ package org.apache.log4j.chainsaw.prefs; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Properties; +import java.util.*; /** * @author Paul Smith <psm...@apache.org> - * */ public class LoadSettingsEvent extends SettingsEvent { - LoadSettingsEvent(Object source, Properties properties) { - super(source); - this.properties = properties; - } + LoadSettingsEvent(Object source, Properties properties) { + super(source); + this.properties = properties; + } + + public String getSetting(String key) { + return properties.getProperty(key); + } + + public boolean asBoolean(String key) { + return Boolean.valueOf(getSetting(key)); + } + + public int asInt(String key) { + String val = getSetting(key); + try { + return Integer.parseInt(val); + } catch (NumberFormatException e) { + e.printStackTrace(); + throw new RuntimeException( + "An error occurred retrieving the Integer value of the setting '" + + key + + "'"); + } + + } + + private final Properties properties; + + /** + * Returns an unmodifiable Collection of values whose + * setting key begins (String.startsWith()) the specified + * string. + * + * @param string + */ + public Collection getSettingsStartingWith(String string) { + Collection c = new ArrayList(); - public String getSetting(String key) { - return properties.getProperty(key); - } - - public boolean asBoolean(String key) { - return Boolean.valueOf(getSetting(key)); - } - - public int asInt(String key) { - String val = getSetting(key); - try { - return Integer.parseInt(val); - } catch (NumberFormatException e) { - e.printStackTrace(); - throw new RuntimeException( - "An error occurred retrieving the Integer value of the setting '" - + key - + "'"); - } + for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) { + Map.Entry<Object, Object> entry = objectObjectEntry; + if (entry.getKey().toString().startsWith(string)) { + c.add(entry.getValue()); + } + } - } - private final Properties properties; - /** - * Returns an unmodifiable Collection of values whose - * setting key begins (String.startsWith()) the specified - * string. - * @param string - */ - public Collection getSettingsStartingWith(String string) - { - Collection c = new ArrayList(); + return Collections.unmodifiableCollection(c); - for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) { - Map.Entry<Object, Object> entry = objectObjectEntry; - if (entry.getKey().toString().startsWith(string)) { - c.add(entry.getValue()); - } - } - - return Collections.unmodifiableCollection(c); - - } + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileList.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileList.java b/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileList.java index f93f163..bc7f425 100644 --- a/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileList.java +++ b/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileList.java @@ -16,6 +16,12 @@ */ package org.apache.log4j.chainsaw.prefs; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomDriver; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; import java.io.Reader; import java.net.URL; import java.util.ArrayList; @@ -23,56 +29,49 @@ import java.util.Collections; import java.util.EventListener; import java.util.List; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.EventListenerList; - -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomDriver; - -public class MRUFileList{ +public class MRUFileList { private static MRUFileList log4jList = new MRUFileList(); private static final int DEFAULT_MRU_SIZE = 5; - + private List<URL> fileList = new ArrayList<>(); private int size = DEFAULT_MRU_SIZE; - + private static transient EventListenerList listeners = new EventListenerList(); - + private MRUFileList() { - + } - - public static void addChangeListener(ChangeListener listener){ + + public static void addChangeListener(ChangeListener listener) { listeners.add(ChangeListener.class, listener); } + public static void removeChangeListener(ChangeListener listener) { listeners.remove(ChangeListener.class, listener); } - + /** * Call this method when something opens a log file, this method - * adds the URL to the list of known URL's, automatically + * adds the URL to the list of known URL's, automatically * rolling the list to ensure the list maintains the * size property - * - * + * * @param url */ public void opened(URL url) { // first remove any existence of the URL already, make sure we don't have dupes fileList.remove(url); // now make sure we obey the size property, leaving room for 1 more to be added at the front - while(fileList.size()>=size) { - fileList.remove(fileList.size()-1); + while (fileList.size() >= size) { + fileList.remove(fileList.size() - 1); } fileList.add(0, url); fireChangeEvent(); } - + private static void fireChangeEvent() { - + ChangeEvent event = null; EventListener[] eventListeners = listeners.getListeners(ChangeListener.class); for (EventListener eventListener : eventListeners) { @@ -86,7 +85,7 @@ public class MRUFileList{ /** * Returns an <b>unmodifiable</b> List of the MRU opened file list within Chainsaw - * + * * @return */ public List getMRUList() { @@ -96,17 +95,18 @@ public class MRUFileList{ public static MRUFileList log4jMRU() { return log4jList; } - + public static void loadLog4jMRUListFromXML(String xml) { XStream xstream = new XStream(new DomDriver()); log4jList = (MRUFileList) xstream.fromXML(xml); fireChangeEvent(); } + public static void loadLog4jMRUListFromReader(Reader reader) { XStream xstream = new XStream(new DomDriver()); log4jList = (MRUFileList) xstream.fromXML(reader); fireChangeEvent(); - + } - // TODO Auto-generated method stub + // TODO Auto-generated method stub } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileListPreferenceSaver.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileListPreferenceSaver.java b/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileListPreferenceSaver.java index 750fbba..09ac62d 100644 --- a/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileListPreferenceSaver.java +++ b/src/main/java/org/apache/log4j/chainsaw/prefs/MRUFileListPreferenceSaver.java @@ -16,31 +16,32 @@ */ package org.apache.log4j.chainsaw.prefs; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomDriver; + import java.io.File; import java.io.FileReader; import java.io.FileWriter; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomDriver; - /** * Loads/Saves the MRU lists from preferences - * - * @author psmith * + * @author psmith */ -public class MRUFileListPreferenceSaver implements SettingsListener{ +public class MRUFileListPreferenceSaver implements SettingsListener { private static final MRUFileListPreferenceSaver instance = new MRUFileListPreferenceSaver(); - + public static final MRUFileListPreferenceSaver getInstance() { return instance; } - private MRUFileListPreferenceSaver() {} - + + private MRUFileListPreferenceSaver() { + } + public void loadSettings(LoadSettingsEvent event) { File file = getMRULocation(SettingsManager.getInstance().getSettingsDirectory()); - if(file.exists()) { + if (file.exists()) { try { MRUFileList.loadLog4jMRUListFromReader(new FileReader(file)); } catch (Exception e) { @@ -48,7 +49,7 @@ public class MRUFileListPreferenceSaver implements SettingsListener{ e.printStackTrace(); } } - + } public void saveSettings(SaveSettingsEvent event) { @@ -64,6 +65,7 @@ public class MRUFileListPreferenceSaver implements SettingsListener{ e.printStackTrace(); } } + private File getMRULocation(File dir) { File file = new File(dir, "mru.xml"); return file; http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/prefs/ProfileManager.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/ProfileManager.java b/src/main/java/org/apache/log4j/chainsaw/prefs/ProfileManager.java index 1456da8..0bfaa9f 100644 --- a/src/main/java/org/apache/log4j/chainsaw/prefs/ProfileManager.java +++ b/src/main/java/org/apache/log4j/chainsaw/prefs/ProfileManager.java @@ -20,26 +20,27 @@ import java.util.Properties; /** * @author Paul Smith <psm...@apache.org> - * */ public class ProfileManager { - - private static final ProfileManager instance = new ProfileManager(); - - public static final ProfileManager getInstance() { return instance;} - - public void configure(Profileable p) { - Properties props = new Properties(SettingsManager.getInstance().getDefaultSettings()); - LoadSettingsEvent event = new LoadSettingsEvent(this, props); - p.loadSettings(event); - } - - public void configure(Profileable p, String profileName) { - throw new UnsupportedOperationException("Not implemented as yet"); - } - - private ProfileManager() { - - - } + + private static final ProfileManager instance = new ProfileManager(); + + public static final ProfileManager getInstance() { + return instance; + } + + public void configure(Profileable p) { + Properties props = new Properties(SettingsManager.getInstance().getDefaultSettings()); + LoadSettingsEvent event = new LoadSettingsEvent(this, props); + p.loadSettings(event); + } + + public void configure(Profileable p, String profileName) { + throw new UnsupportedOperationException("Not implemented as yet"); + } + + private ProfileManager() { + + + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/prefs/Profileable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/Profileable.java b/src/main/java/org/apache/log4j/chainsaw/prefs/Profileable.java index 414f65c..097f7c5 100644 --- a/src/main/java/org/apache/log4j/chainsaw/prefs/Profileable.java +++ b/src/main/java/org/apache/log4j/chainsaw/prefs/Profileable.java @@ -17,24 +17,23 @@ package org.apache.log4j.chainsaw.prefs; /** - * A component implementing this interface is interested in being able to + * A component implementing this interface is interested in being able to * configure itself. - * + * <p> * Since this interface extends SettingsListener, the component * will receive Load and Save settings events as described * in SettingsManager - * - * @see org.apache.log4j.chainsaw.prefs.SettingsManager - * @author Paul Smith <psm...@apache.org> * + * @author Paul Smith <psm...@apache.org> + * @see org.apache.log4j.chainsaw.prefs.SettingsManager */ public interface Profileable extends SettingsListener { - /** - * Must be able to provide a name which is used to determine at a minimum, - * the default profile name prefix for this component. - */ + /** + * Must be able to provide a name which is used to determine at a minimum, + * the default profile name prefix for this component. + */ String getNamespace(); - + }