http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java b/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java index 6df8efd..40313f1 100644 --- a/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java +++ b/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java @@ -17,25 +17,6 @@ package org.apache.log4j.chainsaw.color; -import java.awt.Color; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; - import org.apache.log4j.chainsaw.ChainsawConstants; import org.apache.log4j.chainsaw.prefs.SettingsManager; import org.apache.log4j.rule.ColorRule; @@ -43,6 +24,14 @@ import org.apache.log4j.rule.ExpressionRule; import org.apache.log4j.rule.Rule; import org.apache.log4j.spi.LoggingEvent; +import java.awt.*; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.*; +import java.net.URLEncoder; +import java.util.*; +import java.util.List; + /** * A colorizer supporting an ordered collection of ColorRules, including support for notification of @@ -51,274 +40,274 @@ import org.apache.log4j.spi.LoggingEvent; * @author Scott Deboy <sde...@apache.org> */ public class RuleColorizer implements Colorizer { - private Map rules; - private final PropertyChangeSupport colorChangeSupport = - new PropertyChangeSupport(this); - private Map defaultRules = new HashMap(); - private String currentRuleSet = ChainsawConstants.DEFAULT_COLOR_RULE_NAME; - private Rule findRule; - private Rule loggerRule; - - private static final String COLORS_EXTENSION = ".colors"; - - private final Color WARN_DEFAULT_COLOR = new Color(255, 255, 153); - private final Color FATAL_OR_ERROR_DEFAULT_COLOR = new Color(255, 153, 153); - private final Color MARKER_DEFAULT_COLOR = new Color(153, 255, 153); - - private final String DEFAULT_WARN_EXPRESSION = "level == WARN"; - private final String DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION = "level == FATAL || level == ERROR || exception exists"; - private final String DEFAULT_MARKER_EXPRESSION = "prop.marker exists"; - - public RuleColorizer() { - List rulesList = new ArrayList(); - - String expression = DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION; - rulesList.add( - new ColorRule( - expression, ExpressionRule.getRule(expression), FATAL_OR_ERROR_DEFAULT_COLOR, - Color.black)); - expression = DEFAULT_WARN_EXPRESSION; - rulesList.add( - new ColorRule( - expression, ExpressionRule.getRule(expression), WARN_DEFAULT_COLOR, - Color.black)); - - expression = DEFAULT_MARKER_EXPRESSION; - rulesList.add( - new ColorRule( - expression, ExpressionRule.getRule(expression), MARKER_DEFAULT_COLOR, - Color.black)); - - defaultRules.put(currentRuleSet, rulesList); - setRules(defaultRules); - } - - public void setLoggerRule(Rule loggerRule) { - this.loggerRule = loggerRule; - colorChangeSupport.firePropertyChange("colorrule", false, true); - } - - public void setFindRule(Rule findRule) { - this.findRule = findRule; - colorChangeSupport.firePropertyChange("colorrule", false, true); - } - - public Rule getFindRule() { - return findRule; - } - - public Rule getLoggerRule() { - return loggerRule; - } - - public void setRules(Map rules) { - this.rules = rules; - colorChangeSupport.firePropertyChange("colorrule", false, true); - } - - public Map getRules() { - return rules; - } - - public List getCurrentRules() { - return (List) rules.get(currentRuleSet); - } - - public void addRules(Map newRules) { - - for (Object o : newRules.entrySet()) { - Map.Entry entry = (Map.Entry) o; - - if (rules.containsKey(entry.getKey())) { - ((List) rules.get(entry.getKey())).addAll((List) entry.getValue()); - } else { - rules.put(entry.getKey(), entry.getValue()); - } - } - - colorChangeSupport.firePropertyChange("colorrule", false, true); - } - - public void addRule(String ruleSetName, ColorRule rule) { - if (rules.containsKey(ruleSetName)) { - ((List) rules.get(ruleSetName)).add(rule); - } else { - List list = new ArrayList(); - list.add(rule); - rules.put(ruleSetName, list); + private Map rules; + private final PropertyChangeSupport colorChangeSupport = + new PropertyChangeSupport(this); + private Map defaultRules = new HashMap(); + private String currentRuleSet = ChainsawConstants.DEFAULT_COLOR_RULE_NAME; + private Rule findRule; + private Rule loggerRule; + + private static final String COLORS_EXTENSION = ".colors"; + + private final Color WARN_DEFAULT_COLOR = new Color(255, 255, 153); + private final Color FATAL_OR_ERROR_DEFAULT_COLOR = new Color(255, 153, 153); + private final Color MARKER_DEFAULT_COLOR = new Color(153, 255, 153); + + private final String DEFAULT_WARN_EXPRESSION = "level == WARN"; + private final String DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION = "level == FATAL || level == ERROR || exception exists"; + private final String DEFAULT_MARKER_EXPRESSION = "prop.marker exists"; + + public RuleColorizer() { + List rulesList = new ArrayList(); + + String expression = DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION; + rulesList.add( + new ColorRule( + expression, ExpressionRule.getRule(expression), FATAL_OR_ERROR_DEFAULT_COLOR, + Color.black)); + expression = DEFAULT_WARN_EXPRESSION; + rulesList.add( + new ColorRule( + expression, ExpressionRule.getRule(expression), WARN_DEFAULT_COLOR, + Color.black)); + + expression = DEFAULT_MARKER_EXPRESSION; + rulesList.add( + new ColorRule( + expression, ExpressionRule.getRule(expression), MARKER_DEFAULT_COLOR, + Color.black)); + + defaultRules.put(currentRuleSet, rulesList); + setRules(defaultRules); + } + + public void setLoggerRule(Rule loggerRule) { + this.loggerRule = loggerRule; + colorChangeSupport.firePropertyChange("colorrule", false, true); + } + + public void setFindRule(Rule findRule) { + this.findRule = findRule; + colorChangeSupport.firePropertyChange("colorrule", false, true); + } + + public Rule getFindRule() { + return findRule; } - colorChangeSupport.firePropertyChange("colorrule", false, true); - } + public Rule getLoggerRule() { + return loggerRule; + } - public void removeRule(String ruleSetName, String expression) { - if (rules.containsKey(ruleSetName)) { - List list = (List) rules.get(ruleSetName); + public void setRules(Map rules) { + this.rules = rules; + colorChangeSupport.firePropertyChange("colorrule", false, true); + } + + public Map getRules() { + return rules; + } - for (int i = 0; i < list.size(); i++) { - ColorRule rule = (ColorRule) list.get(i); + public List getCurrentRules() { + return (List) rules.get(currentRuleSet); + } + + public void addRules(Map newRules) { + + for (Object o : newRules.entrySet()) { + Map.Entry entry = (Map.Entry) o; + + if (rules.containsKey(entry.getKey())) { + ((List) rules.get(entry.getKey())).addAll((List) entry.getValue()); + } else { + rules.put(entry.getKey(), entry.getValue()); + } + } - if (rule.getExpression().equals(expression)) { - list.remove(rule); + colorChangeSupport.firePropertyChange("colorrule", false, true); + } - return; + public void addRule(String ruleSetName, ColorRule rule) { + if (rules.containsKey(ruleSetName)) { + ((List) rules.get(ruleSetName)).add(rule); + } else { + List list = new ArrayList(); + list.add(rule); + rules.put(ruleSetName, list); } - } + + colorChangeSupport.firePropertyChange("colorrule", false, true); } - } - public void setCurrentRuleSet(String ruleSetName) { - currentRuleSet = ruleSetName; - } + public void removeRule(String ruleSetName, String expression) { + if (rules.containsKey(ruleSetName)) { + List list = (List) rules.get(ruleSetName); - public Color getBackgroundColor(LoggingEvent event) { - if (rules.containsKey(currentRuleSet)) { - List list = (List) rules.get(currentRuleSet); + for (int i = 0; i < list.size(); i++) { + ColorRule rule = (ColorRule) list.get(i); - for (Object aList : list) { - ColorRule rule = (ColorRule) aList; + if (rule.getExpression().equals(expression)) { + list.remove(rule); - if ((rule.getBackgroundColor() != null) && (rule.evaluate(event, null))) { - return rule.getBackgroundColor(); + return; + } } } } - return null; - } + public void setCurrentRuleSet(String ruleSetName) { + currentRuleSet = ruleSetName; + } - public Color getForegroundColor(LoggingEvent event) { - if (rules.containsKey(currentRuleSet)) { - List list = (List) rules.get(currentRuleSet); + public Color getBackgroundColor(LoggingEvent event) { + if (rules.containsKey(currentRuleSet)) { + List list = (List) rules.get(currentRuleSet); - for (Object aList : list) { - ColorRule rule = (ColorRule) aList; + for (Object aList : list) { + ColorRule rule = (ColorRule) aList; - if ((rule.getForegroundColor() != null) && (rule.evaluate(event, null))) { - return rule.getForegroundColor(); + if ((rule.getBackgroundColor() != null) && (rule.evaluate(event, null))) { + return rule.getBackgroundColor(); + } } } + + return null; } - return null; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - colorChangeSupport.addPropertyChangeListener(listener); - } + public Color getForegroundColor(LoggingEvent event) { + if (rules.containsKey(currentRuleSet)) { + List list = (List) rules.get(currentRuleSet); - public void removePropertyChangeListener(PropertyChangeListener listener) { - colorChangeSupport.removePropertyChangeListener(listener); - } + for (Object aList : list) { + ColorRule rule = (ColorRule) aList; + + if ((rule.getForegroundColor() != null) && (rule.evaluate(event, null))) { + return rule.getForegroundColor(); + } + } + } + + return null; + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + colorChangeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + colorChangeSupport.removePropertyChangeListener(listener); + } - /** - * @param propertyName - * @param listener - */ - public void addPropertyChangeListener( - String propertyName, PropertyChangeListener listener) { - colorChangeSupport.addPropertyChangeListener(propertyName, listener); - } + /** + * @param propertyName + * @param listener + */ + public void addPropertyChangeListener( + String propertyName, PropertyChangeListener listener) { + colorChangeSupport.addPropertyChangeListener(propertyName, listener); + } /** * Save panel color settings */ public void saveColorSettings(String name) { - ObjectOutputStream o = null; - try { - File f = new File(SettingsManager.getInstance().getSettingsDirectory(), URLEncoder.encode(name + COLORS_EXTENSION)); + ObjectOutputStream o = null; + try { + File f = new File(SettingsManager.getInstance().getSettingsDirectory(), URLEncoder.encode(name + COLORS_EXTENSION)); - o = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f))); + o = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f))); - o.writeObject(getRules()); - o.flush(); - } catch (IOException ioe) { - ioe.printStackTrace(); - } finally { - try { - if (o != null) { - o.close(); - } + o.writeObject(getRules()); + o.flush(); } catch (IOException ioe) { - ioe.printStackTrace(); + ioe.printStackTrace(); + } finally { + try { + if (o != null) { + o.close(); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } } - } } - /** - * Load panel color settings if they exist - otherwise, load default color settings - */ - public void loadColorSettings(String name) { - if (!doLoadColorSettings(name)) { - doLoadColorSettings(ChainsawConstants.DEFAULT_COLOR_RULE_NAME); + /** + * Load panel color settings if they exist - otherwise, load default color settings + */ + public void loadColorSettings(String name) { + if (!doLoadColorSettings(name)) { + doLoadColorSettings(ChainsawConstants.DEFAULT_COLOR_RULE_NAME); + } } - } - - private boolean doLoadColorSettings(String name) { - //first attempt to load encoded file - File f = new File(SettingsManager.getInstance().getSettingsDirectory(), URLEncoder.encode(name) + COLORS_EXTENSION); - - if (f.exists()) { - ObjectInputStream s = null; - - try { - s = new ObjectInputStream( - new BufferedInputStream(new FileInputStream(f))); - - Map map = (Map) s.readObject(); - setRules(map); - } catch (EOFException eof) { //end of file - ignore.. - }catch (IOException ioe) { - ioe.printStackTrace(); - //unable to load file - delete it - f.delete(); - } catch (ClassNotFoundException cnfe) { - cnfe.printStackTrace(); - } finally { - if (s != null) { - try { - s.close(); - } catch (IOException ioe) { - ioe.printStackTrace(); - } + + private boolean doLoadColorSettings(String name) { + //first attempt to load encoded file + File f = new File(SettingsManager.getInstance().getSettingsDirectory(), URLEncoder.encode(name) + COLORS_EXTENSION); + + if (f.exists()) { + ObjectInputStream s = null; + + try { + s = new ObjectInputStream( + new BufferedInputStream(new FileInputStream(f))); + + Map map = (Map) s.readObject(); + setRules(map); + } catch (EOFException eof) { //end of file - ignore.. + } catch (IOException ioe) { + ioe.printStackTrace(); + //unable to load file - delete it + f.delete(); + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + } } - } + return f.exists(); } - return f.exists(); - } public Vector getDefaultColors() { - Vector vec = new Vector(); - - vec.add(Color.white); - vec.add(Color.black); - //add default alternating color & search backgrounds (both foreground are black) - vec.add(ChainsawConstants.COLOR_ODD_ROW_BACKGROUND); - vec.add(ChainsawConstants.FIND_LOGGER_BACKGROUND); - - vec.add(new Color(255, 255, 225)); - vec.add(new Color(255, 225, 255)); - vec.add(new Color(225, 255, 255)); - vec.add(new Color(255, 225, 225)); - vec.add(new Color(225, 255, 225)); - vec.add(new Color(225, 225, 255)); - vec.add(new Color(225, 225, 183)); - vec.add(new Color(225, 183, 225)); - vec.add(new Color(183, 225, 225)); - vec.add(new Color(183, 225, 183)); - vec.add(new Color(183, 183, 225)); - vec.add(new Color(232, 201, 169)); - vec.add(new Color(255, 255, 153)); - vec.add(new Color(255, 153, 153)); - vec.add(new Color(189, 156, 89)); - vec.add(new Color(255, 102, 102)); - vec.add(new Color(255, 177, 61)); - vec.add(new Color(61, 255, 61)); - vec.add(new Color(153, 153, 255)); - vec.add(new Color(255, 153, 255)); - - return vec; + Vector vec = new Vector(); + + vec.add(Color.white); + vec.add(Color.black); + //add default alternating color & search backgrounds (both foreground are black) + vec.add(ChainsawConstants.COLOR_ODD_ROW_BACKGROUND); + vec.add(ChainsawConstants.FIND_LOGGER_BACKGROUND); + + vec.add(new Color(255, 255, 225)); + vec.add(new Color(255, 225, 255)); + vec.add(new Color(225, 255, 255)); + vec.add(new Color(255, 225, 225)); + vec.add(new Color(225, 255, 225)); + vec.add(new Color(225, 225, 255)); + vec.add(new Color(225, 225, 183)); + vec.add(new Color(225, 183, 225)); + vec.add(new Color(183, 225, 225)); + vec.add(new Color(183, 225, 183)); + vec.add(new Color(183, 183, 225)); + vec.add(new Color(232, 201, 169)); + vec.add(new Color(255, 255, 153)); + vec.add(new Color(255, 153, 153)); + vec.add(new Color(189, 156, 89)); + vec.add(new Color(255, 102, 102)); + vec.add(new Color(255, 177, 61)); + vec.add(new Color(61, 255, 61)); + vec.add(new Color(153, 153, 255)); + vec.add(new Color(255, 153, 255)); + + return vec; } }
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/dnd/FileDnDTarget.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/dnd/FileDnDTarget.java b/src/main/java/org/apache/log4j/chainsaw/dnd/FileDnDTarget.java index 9bd1078..731d209 100644 --- a/src/main/java/org/apache/log4j/chainsaw/dnd/FileDnDTarget.java +++ b/src/main/java/org/apache/log4j/chainsaw/dnd/FileDnDTarget.java @@ -18,36 +18,29 @@ package org.apache.log4j.chainsaw.dnd; import org.apache.log4j.Logger; + +import javax.swing.*; +import java.awt.*; import java.awt.datatransfer.DataFlavor; -import java.awt.Color; import java.awt.datatransfer.Transferable; -import java.awt.dnd.DnDConstants; -import java.awt.dnd.DropTarget; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.awt.dnd.DropTargetListener; +import java.awt.dnd.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.swing.BorderFactory; -import javax.swing.JComponent; - /** * This class provides all the functionality to work out when files are dragged onto * a particular JComponent instance, and then notifies listeners via - * the standard PropertyChangesListener semantics to indicate that a list of + * the standard PropertyChangesListener semantics to indicate that a list of * files have been dropped onto the target. - * + * <p> * If you wish to know whan the files have been dropped, subscribe to the "fileList" property change. - * - * @author psmith * + * @author psmith */ -public class FileDnDTarget implements DropTargetListener{ +public class FileDnDTarget implements DropTargetListener { /** * Logger for this class */ @@ -59,37 +52,39 @@ public class FileDnDTarget implements DropTargetListener{ private JComponent guiTarget; private Map<JComponent, DropTarget> dropTargets = new HashMap<>(); - - + + private PropertyChangeSupport propertySupport = new PropertyChangeSupport(this); + /** - * + * */ public FileDnDTarget(JComponent c) { this.guiTarget = c; } - - public void addDropTargetToComponent(JComponent c){ + + public void addDropTargetToComponent(JComponent c) { dropTargets.put(c, new DropTarget(c, this)); } - + /** * @param listener */ public void addPropertyChangeListener(PropertyChangeListener listener) { propertySupport.addPropertyChangeListener(listener); } + /** * @param propertyName * @param listener */ public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { + PropertyChangeListener listener) { propertySupport.addPropertyChangeListener(propertyName, listener); } /** - * + * */ private void decorateComponent() { // TODO work out a better way of decorating a component @@ -129,7 +124,7 @@ public class FileDnDTarget implements DropTargetListener{ LOG.debug(transferable); dtde.acceptDrop(acceptableActions); try { - List list = (List)transferable.getTransferData(DataFlavor.javaFileListFlavor); + List list = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor); LOG.debug(list); setFileList(list); dtde.getDropTargetContext().dropComplete(true); @@ -138,12 +133,13 @@ public class FileDnDTarget implements DropTargetListener{ } catch (Exception e) { LOG.error("Error with DnD", e); } - + } public void dropActionChanged(DropTargetDragEvent dtde) { //LOG.debug(dtde); } + /** * @return Returns the fileList. */ @@ -152,53 +148,55 @@ public class FileDnDTarget implements DropTargetListener{ } private boolean isDragOk(DropTargetDragEvent e) { - DataFlavor[] flavors = new DataFlavor[] { DataFlavor.javaFileListFlavor }; - DataFlavor chosen = null; + DataFlavor[] flavors = new DataFlavor[]{DataFlavor.javaFileListFlavor}; + DataFlavor chosen = null; for (DataFlavor flavor : flavors) { if (e.isDataFlavorSupported(flavor)) { chosen = flavor; break; } } - /* - * the src does not support any of the StringTransferable flavors - */ - if (chosen == null) { - return false; - } - // the actions specified when the source - // created the DragGestureRecognizer - int sa = e.getSourceActions(); - - // we're saying that these actions are necessary + /* + * the src does not support any of the StringTransferable flavors + */ + if (chosen == null) { + return false; + } + // the actions specified when the source + // created the DragGestureRecognizer + int sa = e.getSourceActions(); + + // we're saying that these actions are necessary return (sa & acceptableActions) != 0; } /** - * + * */ private void removeComponentDecoration() { this.guiTarget.setBorder(null); } + /** * @param listener */ public void removePropertyChangeListener(PropertyChangeListener listener) { propertySupport.removePropertyChangeListener(listener); } + /** * @param propertyName * @param listener */ public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { + PropertyChangeListener listener) { propertySupport.removePropertyChangeListener(propertyName, listener); } - + /** * @param fileList The fileList to set. */ - private final void setFileList(List fileList) { + private final void setFileList(List fileList) { Object oldValue = this.fileList; this.fileList = fileList; propertySupport.firePropertyChange("fileList", oldValue, this.fileList); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/filter/EventTypeEntryContainer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/filter/EventTypeEntryContainer.java b/src/main/java/org/apache/log4j/chainsaw/filter/EventTypeEntryContainer.java index 37c8885..9708856 100644 --- a/src/main/java/org/apache/log4j/chainsaw/filter/EventTypeEntryContainer.java +++ b/src/main/java/org/apache/log4j/chainsaw/filter/EventTypeEntryContainer.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. @@ -19,131 +19,128 @@ */ package org.apache.log4j.chainsaw.filter; +import javax.swing.*; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.swing.DefaultListModel; -import javax.swing.ListModel; - /** * A Container class used to hold unique LoggingEvent values * and provide them as unique ListModels. - * - * @author Paul Smith * + * @author Paul Smith */ public class EventTypeEntryContainer { - private Set<String> ColumnNames = new HashSet<>(); - private Set<String> Methods = new HashSet<>(); - private Set<String> Classes = new HashSet<>(); - private Set<String> NDCs = new HashSet<>(); - private Set Levels = new HashSet(); - private Set<String> Loggers = new HashSet<>(); - private Set<String> Threads = new HashSet<>(); - private Set<String> FileNames = new HashSet<>(); - private DefaultListModel<String> columnNameListModel = new DefaultListModel<>(); - private DefaultListModel methodListModel = new DefaultListModel(); - private DefaultListModel classesListModel = new DefaultListModel(); - private DefaultListModel propListModel = new DefaultListModel(); - private DefaultListModel ndcListModel = new DefaultListModel(); - private DefaultListModel levelListModel = new DefaultListModel(); - private DefaultListModel loggerListModel = new DefaultListModel(); - private DefaultListModel threadListModel = new DefaultListModel(); - private DefaultListModel fileNameListModel = new DefaultListModel(); - private Map modelMap = new HashMap(); - private static final String LOGGER_FIELD = "LOGGER"; - private static final String LEVEL_FIELD = "LEVEL"; - private static final String CLASS_FIELD = "CLASS"; - private static final String FILE_FIELD = "FILE"; - private static final String THREAD_FIELD = "THREAD"; - private static final String METHOD_FIELD = "METHOD"; - private static final String PROP_FIELD = "PROP."; - private static final String NDC_FIELD = "NDC"; + private Set<String> ColumnNames = new HashSet<>(); + private Set<String> Methods = new HashSet<>(); + private Set<String> Classes = new HashSet<>(); + private Set<String> NDCs = new HashSet<>(); + private Set Levels = new HashSet(); + private Set<String> Loggers = new HashSet<>(); + private Set<String> Threads = new HashSet<>(); + private Set<String> FileNames = new HashSet<>(); + private DefaultListModel<String> columnNameListModel = new DefaultListModel<>(); + private DefaultListModel methodListModel = new DefaultListModel(); + private DefaultListModel classesListModel = new DefaultListModel(); + private DefaultListModel propListModel = new DefaultListModel(); + private DefaultListModel ndcListModel = new DefaultListModel(); + private DefaultListModel levelListModel = new DefaultListModel(); + private DefaultListModel loggerListModel = new DefaultListModel(); + private DefaultListModel threadListModel = new DefaultListModel(); + private DefaultListModel fileNameListModel = new DefaultListModel(); + private Map modelMap = new HashMap(); + private static final String LOGGER_FIELD = "LOGGER"; + private static final String LEVEL_FIELD = "LEVEL"; + private static final String CLASS_FIELD = "CLASS"; + private static final String FILE_FIELD = "FILE"; + private static final String THREAD_FIELD = "THREAD"; + private static final String METHOD_FIELD = "METHOD"; + private static final String PROP_FIELD = "PROP."; + private static final String NDC_FIELD = "NDC"; + + public EventTypeEntryContainer() { + modelMap.put(LOGGER_FIELD, loggerListModel); + modelMap.put(LEVEL_FIELD, levelListModel); + modelMap.put(CLASS_FIELD, classesListModel); + modelMap.put(FILE_FIELD, fileNameListModel); + modelMap.put(THREAD_FIELD, threadListModel); + modelMap.put(METHOD_FIELD, methodListModel); + modelMap.put(NDC_FIELD, ndcListModel); + modelMap.put(PROP_FIELD, propListModel); + } + + public boolean modelExists(String fieldName) { + return fieldName != null && modelMap.keySet().contains(fieldName.toUpperCase()); + } - public EventTypeEntryContainer() { - modelMap.put(LOGGER_FIELD, loggerListModel); - modelMap.put(LEVEL_FIELD, levelListModel); - modelMap.put(CLASS_FIELD, classesListModel); - modelMap.put(FILE_FIELD, fileNameListModel); - modelMap.put(THREAD_FIELD, threadListModel); - modelMap.put(METHOD_FIELD, methodListModel); - modelMap.put(NDC_FIELD, ndcListModel); - modelMap.put(PROP_FIELD, propListModel); - } - - public boolean modelExists(String fieldName) { - return fieldName != null && modelMap.keySet().contains(fieldName.toUpperCase()); - } - - public ListModel getModel(String fieldName) { - if (fieldName != null) { - ListModel model = (ListModel)modelMap.get(fieldName.toUpperCase()); - if (model != null) { - return model; - } - } - return null; - } - - void addLevel(Object level) { - if (Levels.add(level)) { - levelListModel.addElement(level); + public ListModel getModel(String fieldName) { + if (fieldName != null) { + ListModel model = (ListModel) modelMap.get(fieldName.toUpperCase()); + if (model != null) { + return model; + } + } + return null; } - } - void addLogger(String logger) { - if (Loggers.add(logger)) { - loggerListModel.addElement(logger); + void addLevel(Object level) { + if (Levels.add(level)) { + levelListModel.addElement(level); + } } - } - void addFileName(String filename) { - if (FileNames.add(filename)) { - fileNameListModel.addElement(filename); + void addLogger(String logger) { + if (Loggers.add(logger)) { + loggerListModel.addElement(logger); + } } - } - void addThread(String thread) { - if (Threads.add(thread)) { - threadListModel.addElement(thread); + void addFileName(String filename) { + if (FileNames.add(filename)) { + fileNameListModel.addElement(filename); + } } - } - void addNDC(String ndc) { - if (NDCs.add(ndc)) { - ndcListModel.addElement(ndc); + void addThread(String thread) { + if (Threads.add(thread)) { + threadListModel.addElement(thread); + } } - } - void addColumnName(String name) { - if (ColumnNames.add(name)) { - columnNameListModel.addElement(name); + void addNDC(String ndc) { + if (NDCs.add(ndc)) { + ndcListModel.addElement(ndc); + } } - } - void addMethod(String method) { - if (Methods.add(method)) { - methodListModel.addElement(method); + void addColumnName(String name) { + if (ColumnNames.add(name)) { + columnNameListModel.addElement(name); + } } - } - void addClass(String className) { - if (Classes.add(className)) { - classesListModel.addElement(className); + void addMethod(String method) { + if (Methods.add(method)) { + methodListModel.addElement(method); + } } - } - void addProperties(Map properties) { - if(properties == null) { - return; + void addClass(String className) { + if (Classes.add(className)) { + classesListModel.addElement(className); + } } - for (Object o : properties.entrySet()) { - Map.Entry entry = (Map.Entry) o; - if (!(propListModel.contains(entry.getKey()))) { - propListModel.addElement(entry.getKey()); - } - } + + void addProperties(Map properties) { + if (properties == null) { + return; + } + for (Object o : properties.entrySet()) { + Map.Entry entry = (Map.Entry) o; + if (!(propListModel.contains(entry.getKey()))) { + propListModel.addElement(entry.getKey()); + } + } } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/filter/FilterModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/filter/FilterModel.java b/src/main/java/org/apache/log4j/chainsaw/filter/FilterModel.java index 1b1670d..a250d5f 100644 --- a/src/main/java/org/apache/log4j/chainsaw/filter/FilterModel.java +++ b/src/main/java/org/apache/log4j/chainsaw/filter/FilterModel.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,8 +17,8 @@ package org.apache.log4j.chainsaw.filter; -import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.LocationInfo; +import org.apache.log4j.spi.LoggingEvent; /** * This class is used as a Model for Filtering, and retains the unique entries that @@ -28,27 +28,27 @@ import org.apache.log4j.spi.LocationInfo; * @author Scott Deboy <sde...@apache.org> */ public class FilterModel { - private EventTypeEntryContainer eventContainer = - new EventTypeEntryContainer(); - - public void processNewLoggingEvent(LoggingEvent event) { - - eventContainer.addLevel(event.getLevel()); - eventContainer.addLogger(event.getLoggerName()); - eventContainer.addThread(event.getThreadName()); - eventContainer.addNDC(event.getNDC()); - eventContainer.addProperties(event.getProperties()); - - if (event.locationInformationExists()) { - LocationInfo info = event.getLocationInformation(); - eventContainer.addClass(info.getClassName()); - eventContainer.addMethod(info.getMethodName()); - eventContainer.addFileName(info.getFileName()); + private EventTypeEntryContainer eventContainer = + new EventTypeEntryContainer(); + + public void processNewLoggingEvent(LoggingEvent event) { + + eventContainer.addLevel(event.getLevel()); + eventContainer.addLogger(event.getLoggerName()); + eventContainer.addThread(event.getThreadName()); + eventContainer.addNDC(event.getNDC()); + eventContainer.addProperties(event.getProperties()); + + if (event.locationInformationExists()) { + LocationInfo info = event.getLocationInformation(); + eventContainer.addClass(info.getClassName()); + eventContainer.addMethod(info.getMethodName()); + eventContainer.addFileName(info.getFileName()); + } } - } - public EventTypeEntryContainer getContainer() { - return eventContainer; - } + public EventTypeEntryContainer getContainer() { + return eventContainer; + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/help/HelpLocator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/help/HelpLocator.java b/src/main/java/org/apache/log4j/chainsaw/help/HelpLocator.java index 2597d51..adcd8dc 100644 --- a/src/main/java/org/apache/log4j/chainsaw/help/HelpLocator.java +++ b/src/main/java/org/apache/log4j/chainsaw/help/HelpLocator.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,6 +17,10 @@ package org.apache.log4j.chainsaw.help; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.chainsaw.messages.MessageCenter; + import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -24,110 +28,108 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.chainsaw.messages.MessageCenter; - /** * A helper class that assists the HelpManager by serving as a collection of * Class loaders based on URL roots. - * + * * @author Paul Smith - * <psm...@apache.org> + * <psm...@apache.org> */ class HelpLocator { - private List<ClassLoader> classLoaders = new ArrayList<>(); - private static Logger logger = LogManager.getLogger(HelpLocator.class); - HelpLocator() { - } - - /** - * Adds a ClassLoader to be used as a help resource locator - */ - void installClassloaderLocator(ClassLoader cl) { - classLoaders.add(cl); - } - /** - * Adds a new locator to the current set of locators by using the passed in - * URL as a base to locate help resources. The URL SHOULD end in a '/' - * character. - */ - void installLocator(URL url) { - try { - classLoaders.add(new HelpResourceLoader(url)); - } catch (Exception e) { - MessageCenter.getInstance().getLogger().error( - "Failed to setup the resoure loaders for the Help Subsystem"); + private List<ClassLoader> classLoaders = new ArrayList<>(); + private static Logger logger = LogManager.getLogger(HelpLocator.class); + + HelpLocator() { } - } - /** - * Locates a help resource by using the internal resource locator collection. - * - * @return URL of the located resource, or null if it cannot be located. - */ - URL findResource(String name) { - URL url = null; + /** + * Adds a ClassLoader to be used as a help resource locator + */ + void installClassloaderLocator(ClassLoader cl) { + classLoaders.add(cl); + } - for (Object classLoader : classLoaders) { - ClassLoader loader = (ClassLoader) classLoader; - url = loader.getResource(name); + /** + * Adds a new locator to the current set of locators by using the passed in + * URL as a base to locate help resources. The URL SHOULD end in a '/' + * character. + */ + void installLocator(URL url) { + try { + classLoaders.add(new HelpResourceLoader(url)); + } catch (Exception e) { + MessageCenter.getInstance().getLogger().error( + "Failed to setup the resoure loaders for the Help Subsystem"); + } + } - if (url != null) { - break; - } - } + /** + * Locates a help resource by using the internal resource locator collection. + * + * @return URL of the located resource, or null if it cannot be located. + */ + URL findResource(String name) { + URL url = null; - return url; - } + for (Object classLoader : classLoaders) { + ClassLoader loader = (ClassLoader) classLoader; + url = loader.getResource(name); - private static class HelpResourceLoader extends ClassLoader { - private URL root; + if (url != null) { + break; + } + } - private HelpResourceLoader(URL root) { - this.root = root; + return url; } - /* - * (non-Javadoc) - * - * @see java.lang.ClassLoader#findResource(java.lang.String) - */ - protected URL findResource(String name) { - URL url = super.findResource(name); - - if (url != null) { - return url; - } - - try { - URL resourceURL = new URL(root, name); - URL[] urlArray = new URL[] { root, resourceURL }; - logger.debug("Looking for Help resource at:" + resourceURL.toExternalForm()); - logger.debug("urlArray=" + Arrays.asList(urlArray)); - return new URLClassLoader( - urlArray).findResource( - name); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return null; + private static class HelpResourceLoader extends ClassLoader { + private URL root; + + private HelpResourceLoader(URL root) { + this.root = root; + } + + /* + * (non-Javadoc) + * + * @see java.lang.ClassLoader#findResource(java.lang.String) + */ + protected URL findResource(String name) { + URL url = super.findResource(name); + + if (url != null) { + return url; + } + + try { + URL resourceURL = new URL(root, name); + URL[] urlArray = new URL[]{root, resourceURL}; + logger.debug("Looking for Help resource at:" + resourceURL.toExternalForm()); + logger.debug("urlArray=" + Arrays.asList(urlArray)); + return new URLClassLoader( + urlArray).findResource( + name); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + return null; + } } - } - - // public static void main(String[] args) throws Exception { - // HelpLocator locator = new HelpLocator(); - // locator.installLocator(new File(".").toURL()); - // locator.installLocator(new - // URL("http://java.sun.com/j2se/1.4.2/docs/api/")); - // String[] resources = - // new String[] { "build.properties", "java/lang/ClassLoader.html", }; - // - // for (int i = 0; i < resources.length; i++) { - // String resource = resources[i]; - // URL url = locator.findResource(resource); - // System.out.println("resource=" + resource + ", url=" + url); - // } - // } + + // public static void main(String[] args) throws Exception { + // HelpLocator locator = new HelpLocator(); + // locator.installLocator(new File(".").toURL()); + // locator.installLocator(new + // URL("http://java.sun.com/j2se/1.4.2/docs/api/")); + // String[] resources = + // new String[] { "build.properties", "java/lang/ClassLoader.html", }; + // + // for (int i = 0; i < resources.length; i++) { + // String resource = resources[i]; + // URL url = locator.findResource(resource); + // System.out.println("resource=" + resource + ", url=" + url); + // } + // } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/help/HelpManager.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/help/HelpManager.java b/src/main/java/org/apache/log4j/chainsaw/help/HelpManager.java index e5eec55..7d1e503 100644 --- a/src/main/java/org/apache/log4j/chainsaw/help/HelpManager.java +++ b/src/main/java/org/apache/log4j/chainsaw/help/HelpManager.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,16 +17,16 @@ package org.apache.log4j.chainsaw.help; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.chainsaw.ChainsawConstants; + import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; import java.net.URL; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.chainsaw.ChainsawConstants; - /** * Singleton help manager where objects can register to display @@ -36,7 +36,6 @@ import org.apache.log4j.chainsaw.ChainsawConstants; * from the help implementation (if any!) * * @author Paul Smith <psm...@apache.org> - * */ public final class HelpManager { @@ -57,13 +56,13 @@ public final class HelpManager { logger.info("Adding HelpLocator for localDocs property=" + System.getProperty("log4j.chainsaw.localDocs")); helpLocator.installLocator(new URL( - System.getProperty("log4j.chainsaw.localDocs"))); - }else if(new File("docs/api").exists()) { - File dir = new File("docs/api"); - logger.info("Detected Local JavaDocs at " + dir.toString()); - helpLocator.installLocator(dir.toURI().toURL()); + System.getProperty("log4j.chainsaw.localDocs"))); + } else if (new File("docs/api").exists()) { + File dir = new File("docs/api"); + logger.info("Detected Local JavaDocs at " + dir.toString()); + helpLocator.installLocator(dir.toURI().toURL()); } else { - logger.warn("Could not find any local JavaDocs, you might want to consider running 'ant javadoc'. The release version will be able to access Javadocs from the Apache website."); + logger.warn("Could not find any local JavaDocs, you might want to consider running 'ant javadoc'. The release version will be able to access Javadocs from the Apache website."); } } catch (Exception e) { // TODO: handle exception @@ -76,10 +75,11 @@ public final class HelpManager { /** * The current Help URL that should be displayed, and is * a PropertyChangeListener supported property. - * + * <p> * This method ALWAYS fires property change events * even if the value is the same (the oldvalue * of the event will be null) + * * @param helpURL */ public void setHelpURL(URL helpURL) { @@ -99,7 +99,7 @@ public final class HelpManager { * @param listener */ public synchronized void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { + PropertyChangeListener listener) { propertySupport.addPropertyChangeListener(propertyName, listener); } @@ -116,7 +116,7 @@ public final class HelpManager { * @param newValue */ public void firePropertyChange(String propertyName, boolean oldValue, - boolean newValue) { + boolean newValue) { propertySupport.firePropertyChange(propertyName, oldValue, newValue); } @@ -126,7 +126,7 @@ public final class HelpManager { * @param newValue */ public void firePropertyChange(String propertyName, int oldValue, - int newValue) { + int newValue) { propertySupport.firePropertyChange(propertyName, oldValue, newValue); } @@ -136,7 +136,7 @@ public final class HelpManager { * @param newValue */ public void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { + Object newValue) { propertySupport.firePropertyChange(propertyName, oldValue, newValue); } @@ -153,7 +153,7 @@ public final class HelpManager { * @param listener */ public synchronized void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { + PropertyChangeListener listener) { propertySupport.removePropertyChangeListener(propertyName, listener); } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/help/Tutorial.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/help/Tutorial.java b/src/main/java/org/apache/log4j/chainsaw/help/Tutorial.java index 653806b..8e86a2f 100644 --- a/src/main/java/org/apache/log4j/chainsaw/help/Tutorial.java +++ b/src/main/java/org/apache/log4j/chainsaw/help/Tutorial.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. @@ -31,24 +31,24 @@ import org.apache.log4j.spi.LoggerRepositoryEx; * @author Paul Smith */ public class Tutorial implements Runnable { - /* (non-Javadoc) - * @see java.lang.Runnable#run() - */ - public void run() { - Plugin p1 = new Generator("Generator 1"); - Plugin p2 = new Generator("Generator 2"); - Plugin p3 = new Generator("Generator 3"); - - LoggerRepository repo = LogManager.getLoggerRepository(); - if (repo instanceof LoggerRepositoryEx) { - PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); - pluginRegistry.addPlugin(p1); - p1.activateOptions(); - pluginRegistry.addPlugin(p2); - p2.activateOptions(); - pluginRegistry.addPlugin(p3); - p3.activateOptions(); - } - - } + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + public void run() { + Plugin p1 = new Generator("Generator 1"); + Plugin p2 = new Generator("Generator 2"); + Plugin p3 = new Generator("Generator 3"); + + LoggerRepository repo = LogManager.getLoggerRepository(); + if (repo instanceof LoggerRepositoryEx) { + PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); + pluginRegistry.addPlugin(p1); + p1.activateOptions(); + pluginRegistry.addPlugin(p2); + p2.activateOptions(); + pluginRegistry.addPlugin(p3); + p3.activateOptions(); + } + + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/helper/OkCancelPanel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/helper/OkCancelPanel.java b/src/main/java/org/apache/log4j/chainsaw/helper/OkCancelPanel.java index 1e65e06..40a6e8c 100644 --- a/src/main/java/org/apache/log4j/chainsaw/helper/OkCancelPanel.java +++ b/src/main/java/org/apache/log4j/chainsaw/helper/OkCancelPanel.java @@ -16,53 +16,48 @@ */ package org.apache.log4j.chainsaw.helper; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; - -import javax.swing.Box; -import javax.swing.JButton; -import javax.swing.JPanel; +import javax.swing.*; +import java.awt.*; public class OkCancelPanel extends JPanel { - private final JButton cancelButton = new JButton(" Cancel "); - private final JButton okButton = new JButton(" OK "); + private final JButton cancelButton = new JButton(" Cancel "); + private final JButton okButton = new JButton(" OK "); - public OkCancelPanel() { - setLayout(new GridBagLayout()); + public OkCancelPanel() { + setLayout(new GridBagLayout()); - cancelButton.setDefaultCapable(true); + cancelButton.setDefaultCapable(true); - GridBagConstraints c = new GridBagConstraints(); + GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1.0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1.0; - add(Box.createHorizontalGlue(), c); + add(Box.createHorizontalGlue(), c); - c.insets = new Insets(5, 5, 5, 5); - c.weightx = 0.0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.SOUTHEAST; + c.insets = new Insets(5, 5, 5, 5); + c.weightx = 0.0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.SOUTHEAST; - add(okButton, c); - add(cancelButton, c); + add(okButton, c); + add(cancelButton, c); // add(Box.createHorizontalStrut(6)); - } - - /** - * @return Returns the cancelButton. - */ - public final JButton getCancelButton() { - return cancelButton; - } - - /** - * @return Returns the okButton. - */ - public final JButton getOkButton() { - return okButton; - } - -} \ No newline at end of file + } + + /** + * @return Returns the cancelButton. + */ + public final JButton getCancelButton() { + return cancelButton; + } + + /** + * @return Returns the okButton. + */ + public final JButton getOkButton() { + return okButton; + } + +} http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java b/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java index f0882f1..c2eb239 100644 --- a/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java +++ b/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.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,145 +17,131 @@ package org.apache.log4j.chainsaw.helper; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.EventQueue; -import java.awt.FileDialog; -import java.awt.Frame; -import java.awt.Toolkit; +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.File; import java.util.ArrayList; import java.util.List; - import java.util.Locale; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; /** * A collection of standard utility methods for use within Swing. - * - * @author Paul Smith <psm...@apache.org> * + * @author Paul Smith <psm...@apache.org> */ public final class SwingHelper { - /** - * Centers the Component on screen. - * - * @param component - */ - public static void centerOnScreen(Component component) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - component.setLocation( - (screenSize.width / 2) - (component.getWidth() / 2), - (screenSize.height / 2) - (component.getHeight() / 2)); - } - - /** - * This method configures a standard Cancel action, bound to the ESC key, to dispose of the dialog, - * and sets the buttons action to be this action, and adds the action to the dialog's rootPane - * action map - * @param dialog - * @param cancelButton - */ - public static void configureCancelForDialog(final JDialog dialog, JButton cancelButton) { - String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY"; - int noModifiers = 0; - KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, noModifiers, false); - InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - inputMap.put(escapeKey, CANCEL_ACTION_KEY); - - Action closeAction = new AbstractAction("Cancel") { - - public void actionPerformed(ActionEvent arg0) { - dialog.dispose(); - }}; - cancelButton.setAction(closeAction); - dialog.getRootPane().getActionMap().put(CANCEL_ACTION_KEY, closeAction); - - } - - public static void invokeOnEDT(Runnable runnable) { - if (EventQueue.isDispatchThread()) { - runnable.run(); - } else { - EventQueue.invokeLater(runnable); + /** + * Centers the Component on screen. + * + * @param component + */ + public static void centerOnScreen(Component component) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + component.setLocation( + (screenSize.width / 2) - (component.getWidth() / 2), + (screenSize.height / 2) - (component.getHeight() / 2)); + } + + /** + * This method configures a standard Cancel action, bound to the ESC key, to dispose of the dialog, + * and sets the buttons action to be this action, and adds the action to the dialog's rootPane + * action map + * + * @param dialog + * @param cancelButton + */ + public static void configureCancelForDialog(final JDialog dialog, JButton cancelButton) { + String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY"; + int noModifiers = 0; + KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, noModifiers, false); + InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + inputMap.put(escapeKey, CANCEL_ACTION_KEY); + + Action closeAction = new AbstractAction("Cancel") { + + public void actionPerformed(ActionEvent arg0) { + dialog.dispose(); + } + }; + cancelButton.setAction(closeAction); + dialog.getRootPane().getActionMap().put(CANCEL_ACTION_KEY, closeAction); + + } + + public static void invokeOnEDT(Runnable runnable) { + if (EventQueue.isDispatchThread()) { + runnable.run(); + } else { + EventQueue.invokeLater(runnable); + } } - } - - public static boolean isMacOSX() { - return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("mac os x"); - } - - public static List<JButton> orderOKCancelButtons(JButton okButton, JButton cancelButton) { - List<JButton> result = new ArrayList<>(); - if (isMacOSX()) { - result.add(cancelButton); - result.add(okButton); - } else { - result.add(okButton); - result.add(cancelButton); + + public static boolean isMacOSX() { + return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("mac os x"); + } + + public static List<JButton> orderOKCancelButtons(JButton okButton, JButton cancelButton) { + List<JButton> result = new ArrayList<>(); + if (isMacOSX()) { + result.add(cancelButton); + result.add(okButton); + } else { + result.add(okButton); + result.add(cancelButton); + } + return result; } - return result; - } - public static File promptForFile(Container parent, String defaultPath, String title, boolean loadDialog) { + public static File promptForFile(Container parent, String defaultPath, String title, boolean loadDialog) { if (SwingHelper.isMacOSX()) { //use filedialog on mac Component root = SwingUtilities.getRoot(parent); Frame frame = null; if (root instanceof Frame) { - frame = (Frame) root; + frame = (Frame) root; } FileDialog fileDialog = new FileDialog(frame, title); fileDialog.setModal(true); fileDialog.setMode(loadDialog ? FileDialog.LOAD : FileDialog.SAVE); if (defaultPath != null) { - fileDialog.setDirectory(defaultPath); + fileDialog.setDirectory(defaultPath); } fileDialog.setVisible(true); String fileString = fileDialog.getFile(); if (fileString == null) { - return null; + return null; + } + if (fileDialog.getDirectory() != null) { + return new File(fileDialog.getDirectory(), fileString); + } else { + return new File(fileString); + } + } else { + + JFileChooser chooser; + if (defaultPath != null) { + chooser = new JFileChooser(defaultPath); + } else { + chooser = new JFileChooser(); + } + + chooser.setDialogTitle(title); + + chooser.setAcceptAllFileFilterUsed(true); + + int i; + if (loadDialog) { + i = chooser.showOpenDialog(parent); + } else { + i = chooser.showSaveDialog(parent); + } + + if (i != JFileChooser.APPROVE_OPTION) { + return null; } - if (fileDialog.getDirectory() != null) { - return new File(fileDialog.getDirectory(), fileString); - } else { - return new File(fileString); - } - } else { - - JFileChooser chooser; - if (defaultPath != null) { - chooser = new JFileChooser(defaultPath); - } else { - chooser = new JFileChooser(); - } - - chooser.setDialogTitle(title); - - chooser.setAcceptAllFileFilterUsed(true); - - int i; - if (loadDialog) { - i = chooser.showOpenDialog(parent); - } else { - i = chooser.showSaveDialog(parent); - } - - if (i != JFileChooser.APPROVE_OPTION) { - return null; - } return chooser.getSelectedFile(); } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/helper/TableCellEditorFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/helper/TableCellEditorFactory.java b/src/main/java/org/apache/log4j/chainsaw/helper/TableCellEditorFactory.java index 50dd1e8..aee99d9 100644 --- a/src/main/java/org/apache/log4j/chainsaw/helper/TableCellEditorFactory.java +++ b/src/main/java/org/apache/log4j/chainsaw/helper/TableCellEditorFactory.java @@ -16,45 +16,41 @@ */ package org.apache.log4j.chainsaw.helper; -import javax.swing.DefaultCellEditor; -import javax.swing.JComboBox; -import javax.swing.table.TableCellEditor; - import org.apache.log4j.Level; +import javax.swing.*; +import javax.swing.table.TableCellEditor; + /** * @author Paul Smith <psm...@apache.org> - * */ -public class TableCellEditorFactory -{ - - - /** - * Creates a TableCellEditor to be used for editing boolean values - * @return TableCellEditor - */ - public static final TableCellEditor createBooleanTableCellEditor() { - - JComboBox<Boolean> comboBox = new JComboBox<>(new Boolean[] {Boolean.TRUE, Boolean.FALSE}); - return new DefaultCellEditor(comboBox); - - } - - /** - * - */ - private TableCellEditorFactory() - { - } - - /** - * @return table cell editor - */ - public static Object createLevelTableCellEditor() - { - JComboBox<Level> comboBox = new JComboBox<>(new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL, Level.OFF, Level.ALL}); - return new DefaultCellEditor(comboBox); - } +public class TableCellEditorFactory { + + + /** + * Creates a TableCellEditor to be used for editing boolean values + * + * @return TableCellEditor + */ + public static final TableCellEditor createBooleanTableCellEditor() { + + JComboBox<Boolean> comboBox = new JComboBox<>(new Boolean[]{Boolean.TRUE, Boolean.FALSE}); + return new DefaultCellEditor(comboBox); + + } + + /** + * + */ + private TableCellEditorFactory() { + } + + /** + * @return table cell editor + */ + public static Object createLevelTableCellEditor() { + JComboBox<Level> comboBox = new JComboBox<>(new Level[]{Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL, Level.OFF, Level.ALL}); + return new DefaultCellEditor(comboBox); + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java b/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java index 747ba6a..2f31927 100644 --- a/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java +++ b/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.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. @@ -21,144 +21,141 @@ */ package org.apache.log4j.chainsaw.icons; +import javax.swing.*; import java.net.URL; -import javax.swing.Icon; -import javax.swing.ImageIcon; - /** * @author Paul Smith <psm...@apache.org> - * */ public class ChainsawIcons { - private static final String BASE_ICON_PATH = - "org/apache/log4j/chainsaw/icons/"; - public static final URL FILE_OPEN = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Open16.gif"); - public static final URL UP = - ChainsawIcons.class.getClassLoader().getResource( + private static final String BASE_ICON_PATH = + "org/apache/log4j/chainsaw/icons/"; + public static final URL FILE_OPEN = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Open16.gif"); + public static final URL UP = + ChainsawIcons.class.getClassLoader().getResource( BASE_ICON_PATH + "Up16.gif"); - public static final URL DOWN = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Down16.gif"); - public static final URL FILE_SAVE_AS = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "SaveAs16.gif"); - public static final URL PAUSE = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Pause16.gif"); - public static final URL REFRESH = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Refresh16.gif"); - public static final URL DELETE = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Delete16.gif"); - public static final URL INFO = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Information16.gif"); - public static final URL FIND = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Find16.gif"); - public static final URL ABOUT = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "About16.gif"); - public static final URL SCROLL_TO_BOTTOM = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "RowInsertAfter16.gif"); - public static final URL TOOL_TIP = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "TipOfTheDay16.gif"); - public static final URL UNDOCK = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Export16.gif"); - public static final URL DOCK = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Import16.gif"); - public static final URL PREFERENCES = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Preferences16.gif"); - public static final URL DEBUG = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Bean16.gif"); - public static final URL HELP = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Help16.gif"); - public static final Icon ICON_UP = new ImageIcon(UP); - public static final Icon ICON_DOWN = new ImageIcon(DOWN); - public static final Icon ICON_HELP = new ImageIcon(HELP); - public static final Icon ICON_PREFERENCES = new ImageIcon(PREFERENCES); - public static final Icon ICON_DOCK = new ImageIcon(DOCK); - public static final URL COPY = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Copy16.gif"); - public static final URL CUT = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Cut16.gif"); - public static final Icon ICON_COPY = new ImageIcon(COPY); - public static final Icon ICON_CUT = new ImageIcon(CUT); - public static final Icon ICON_UNDOCK = new ImageIcon(UNDOCK); - public static final Icon ICON_DEBUG = new ImageIcon(DEBUG); - public static final URL WINDOW_ICON = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Zoom16.gif"); - public static final URL UNDOCKED_ICON = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "ZoomIn16.gif"); - public static final ImageIcon ICON_LOG4J = - new ImageIcon( - ChainsawIcons.class.getClassLoader().getResource( - "org/apache/log4j/chainsaw/logo.jpg")); + public static final URL DOWN = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Down16.gif"); + public static final URL FILE_SAVE_AS = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "SaveAs16.gif"); + public static final URL PAUSE = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Pause16.gif"); + public static final URL REFRESH = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Refresh16.gif"); + public static final URL DELETE = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Delete16.gif"); + public static final URL INFO = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Information16.gif"); + public static final URL FIND = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Find16.gif"); + public static final URL ABOUT = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "About16.gif"); + public static final URL SCROLL_TO_BOTTOM = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "RowInsertAfter16.gif"); + public static final URL TOOL_TIP = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "TipOfTheDay16.gif"); + public static final URL UNDOCK = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Export16.gif"); + public static final URL DOCK = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Import16.gif"); + public static final URL PREFERENCES = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Preferences16.gif"); + public static final URL DEBUG = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Bean16.gif"); + public static final URL HELP = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Help16.gif"); + public static final Icon ICON_UP = new ImageIcon(UP); + public static final Icon ICON_DOWN = new ImageIcon(DOWN); + public static final Icon ICON_HELP = new ImageIcon(HELP); + public static final Icon ICON_PREFERENCES = new ImageIcon(PREFERENCES); + public static final Icon ICON_DOCK = new ImageIcon(DOCK); + public static final URL COPY = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Copy16.gif"); + public static final URL CUT = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Cut16.gif"); + public static final Icon ICON_COPY = new ImageIcon(COPY); + public static final Icon ICON_CUT = new ImageIcon(CUT); + public static final Icon ICON_UNDOCK = new ImageIcon(UNDOCK); + public static final Icon ICON_DEBUG = new ImageIcon(DEBUG); + public static final URL WINDOW_ICON = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Zoom16.gif"); + public static final URL UNDOCKED_ICON = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "ZoomIn16.gif"); + public static final ImageIcon ICON_LOG4J = + new ImageIcon( + ChainsawIcons.class.getClassLoader().getResource( + "org/apache/log4j/chainsaw/logo.jpg")); + + public static final URL ANIM_NET_CONNECT = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "channelexplorer_satellite.gif"); + public static final URL ANIM_RADIO_TOWER = ANIM_NET_CONNECT; + public static final URL ICON_ACTIVE_RECEIVER = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Play16.gif"); + public static final URL ICON_HOME = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Home16.gif"); + public static final URL ICON_BACK = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Back16.gif"); + public static final URL ICON_RESTART = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Redo16.gif"); + public static final URL ICON_RESTART_ALL = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Refresh16.gif"); + + + public static final URL ICON_STOP_RECEIVER = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Stop16.gif"); + public static final URL ICON_NEW_RECEIVER = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "New16.gif"); + public static final URL ICON_EDIT_RECEIVER = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Edit16.gif"); + public static final URL ICON_RESUME_RECEIVER = ICON_ACTIVE_RECEIVER; + public static final URL ICON_INACTIVE_RECEIVER = PAUSE; + public static final URL ICON_COLLAPSE = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "ZoomOut16.gif"); + + public static final ImageIcon FOCUS_ON_ICON = new ImageIcon(ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "ZoomIn24.gif")); + public static final ImageIcon IGNORE_ICON = new ImageIcon(ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "ZoomOut24.gif")); + - public static final URL ANIM_NET_CONNECT = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "channelexplorer_satellite.gif"); - public static final URL ANIM_RADIO_TOWER = ANIM_NET_CONNECT; - public static final URL ICON_ACTIVE_RECEIVER = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Play16.gif"); - public static final URL ICON_HOME = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Home16.gif"); - public static final URL ICON_BACK = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Back16.gif"); - public static final URL ICON_RESTART = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Redo16.gif"); - public static final URL ICON_RESTART_ALL = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Refresh16.gif"); + public static final URL SERVER = + ChainsawIcons.class.getClassLoader().getResource( + BASE_ICON_PATH + "Server16.gif"); - - public static final URL ICON_STOP_RECEIVER = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Stop16.gif"); - public static final URL ICON_NEW_RECEIVER = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "New16.gif"); - public static final URL ICON_EDIT_RECEIVER = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Edit16.gif"); - public static final URL ICON_RESUME_RECEIVER = ICON_ACTIVE_RECEIVER; - public static final URL ICON_INACTIVE_RECEIVER = PAUSE; - public static final URL ICON_COLLAPSE = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "ZoomOut16.gif"); + public static final ImageIcon ICON_SERVER = new ImageIcon(SERVER); - public static final ImageIcon FOCUS_ON_ICON = new ImageIcon(ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "ZoomIn24.gif")); - public static final ImageIcon IGNORE_ICON = new ImageIcon(ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "ZoomOut24.gif")); - - - public static final URL SERVER = - ChainsawIcons.class.getClassLoader().getResource( - BASE_ICON_PATH + "Server16.gif"); - - public static final ImageIcon ICON_SERVER = new ImageIcon(SERVER); - - private ChainsawIcons() { - } + private ChainsawIcons() { + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/icons/LevelIconFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/icons/LevelIconFactory.java b/src/main/java/org/apache/log4j/chainsaw/icons/LevelIconFactory.java index 1de2fda..1bac38f 100644 --- a/src/main/java/org/apache/log4j/chainsaw/icons/LevelIconFactory.java +++ b/src/main/java/org/apache/log4j/chainsaw/icons/LevelIconFactory.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,59 +17,57 @@ package org.apache.log4j.chainsaw.icons; -import java.awt.Image; +import javax.swing.*; +import javax.swing.plaf.metal.MetalLookAndFeel; +import java.awt.*; import java.net.URL; import java.util.HashMap; import java.util.Map; -import javax.swing.ImageIcon; -import javax.swing.UIManager; -import javax.swing.plaf.metal.MetalLookAndFeel; - /** */ public class LevelIconFactory { - private static final LevelIconFactory instance = new LevelIconFactory(); - private final Map<String, javax.swing.Icon> iconMap = new HashMap<>(); + private static final LevelIconFactory instance = new LevelIconFactory(); + private final Map<String, javax.swing.Icon> iconMap = new HashMap<>(); - private LevelIconFactory() { - //reuse ERROR icon for FATAL level - String[] iconFileNames = - new String[] { "Warn.gif", "Inform.gif", "Error.gif" , "Error.gif"}; - String[] iconLabels = new String[] { "WARN", "INFO", "ERROR", "FATAL" }; + private LevelIconFactory() { + //reuse ERROR icon for FATAL level + String[] iconFileNames = + new String[]{"Warn.gif", "Inform.gif", "Error.gif", "Error.gif"}; + String[] iconLabels = new String[]{"WARN", "INFO", "ERROR", "FATAL"}; - for (int i = 0; i < iconLabels.length; i++) { - URL resourceURL = UIManager.getLookAndFeel().getClass().getResource( - "icons/" + iconFileNames[i]); - if(resourceURL == null) { - resourceURL = MetalLookAndFeel.class.getResource( - "icons/" + iconFileNames[i]); - } - if(resourceURL == null) { - throw new IllegalStateException("Was unable to locate an L&F icon using either the current L&F or the cross platform L&F."); - } - - final ImageIcon icon = - new ImageIcon(resourceURL); - 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)); + for (int i = 0; i < iconLabels.length; i++) { + URL resourceURL = UIManager.getLookAndFeel().getClass().getResource( + "icons/" + iconFileNames[i]); + if (resourceURL == null) { + resourceURL = MetalLookAndFeel.class.getResource( + "icons/" + iconFileNames[i]); + } + if (resourceURL == null) { + throw new IllegalStateException("Was unable to locate an L&F icon using either the current L&F or the cross platform L&F."); + } + + final ImageIcon icon = + new ImageIcon(resourceURL); + 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)); + } + //reuse DEBUG icon for TRACE level + iconMap.put("TRACE", ChainsawIcons.ICON_DEBUG); + iconMap.put("DEBUG", ChainsawIcons.ICON_DEBUG); } - //reuse DEBUG icon for TRACE level - iconMap.put("TRACE", ChainsawIcons.ICON_DEBUG); - iconMap.put("DEBUG", ChainsawIcons.ICON_DEBUG); - } - public static final LevelIconFactory getInstance() { - return instance; - } + public static final LevelIconFactory getInstance() { + return instance; + } - public Map<String, javax.swing.Icon> getLevelToIconMap() { - return iconMap; - } + public Map<String, javax.swing.Icon> getLevelToIconMap() { + return iconMap; + } }