http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ColumnComparator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ColumnComparator.java b/src/main/java/org/apache/log4j/chainsaw/ColumnComparator.java index cd10ec1..75a5efe 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ColumnComparator.java +++ b/src/main/java/org/apache/log4j/chainsaw/ColumnComparator.java @@ -17,161 +17,160 @@ package org.apache.log4j.chainsaw; -import java.util.Comparator; - import org.apache.log4j.helpers.Constants; import org.apache.log4j.spi.LoggingEvent; +import java.util.Comparator; + /** - * * @author Claude Duguay * @author Paul Smith <psm...@apache.org> * @author Scott Deboy <sde...@apache.org> -*/ + */ public class ColumnComparator implements Comparator { - protected int index; - protected boolean ascending; - protected String columnName; - - public ColumnComparator(String columnName, int index, boolean ascending) { - this.columnName = columnName; - this.index = index; - this.ascending = ascending; - } + protected int index; + protected boolean ascending; + protected String columnName; + + public ColumnComparator(String columnName, int index, boolean ascending) { + this.columnName = columnName; + this.index = index; + this.ascending = ascending; + } - public int compare(Object o1, Object o2) { - int sort = 1; + public int compare(Object o1, Object o2) { + int sort = 1; - if (o1 instanceof LoggingEventWrapper && o2 instanceof LoggingEventWrapper) { + if (o1 instanceof LoggingEventWrapper && o2 instanceof LoggingEventWrapper) { // TODO not everything catered for here yet... - LoggingEvent e1 = ((LoggingEventWrapper) o1).getLoggingEvent(); - LoggingEvent e2 = ((LoggingEventWrapper) o2).getLoggingEvent(); - - switch (index + 1) { - case ChainsawColumns.INDEX_LEVEL_COL_NAME: - sort = e1.getLevel().isGreaterOrEqual(e2.getLevel()) ? 1 : (-1); - - break; - - case ChainsawColumns.INDEX_LOGGER_COL_NAME: - sort = e1.getLoggerName().compareToIgnoreCase(e2.getLoggerName()); - - break; - - case ChainsawColumns.INDEX_MESSAGE_COL_NAME: - sort = - e1.getMessage().toString().compareToIgnoreCase( - e2.getMessage().toString()); - - break; - - case ChainsawColumns.INDEX_NDC_COL_NAME: - if (e1.getNDC() != null && e2.getNDC() != null) { - sort = - e1.getNDC().compareToIgnoreCase( - e2.getNDC()); - } else if (e1.getNDC() == null && e2.getNDC() == null) { - sort = 0; - } else if (e1.getNDC() == null) { - sort = -1; - } else if (e2.getNDC() == null) { - sort = 1; - } - - break; - - case ChainsawColumns.INDEX_METHOD_COL_NAME: - - if ( - (e1.locationInformationExists()) - & (e2.locationInformationExists())) { - sort = - e1.getLocationInformation().getMethodName().compareToIgnoreCase( - e2.getLocationInformation().getMethodName()); + LoggingEvent e1 = ((LoggingEventWrapper) o1).getLoggingEvent(); + LoggingEvent e2 = ((LoggingEventWrapper) o2).getLoggingEvent(); + + switch (index + 1) { + case ChainsawColumns.INDEX_LEVEL_COL_NAME: + sort = e1.getLevel().isGreaterOrEqual(e2.getLevel()) ? 1 : (-1); + + break; + + case ChainsawColumns.INDEX_LOGGER_COL_NAME: + sort = e1.getLoggerName().compareToIgnoreCase(e2.getLoggerName()); + + break; + + case ChainsawColumns.INDEX_MESSAGE_COL_NAME: + sort = + e1.getMessage().toString().compareToIgnoreCase( + e2.getMessage().toString()); + + break; + + case ChainsawColumns.INDEX_NDC_COL_NAME: + if (e1.getNDC() != null && e2.getNDC() != null) { + sort = + e1.getNDC().compareToIgnoreCase( + e2.getNDC()); + } else if (e1.getNDC() == null && e2.getNDC() == null) { + sort = 0; + } else if (e1.getNDC() == null) { + sort = -1; + } else if (e2.getNDC() == null) { + sort = 1; + } + + break; + + case ChainsawColumns.INDEX_METHOD_COL_NAME: + + if ( + (e1.locationInformationExists()) + & (e2.locationInformationExists())) { + sort = + e1.getLocationInformation().getMethodName().compareToIgnoreCase( + e2.getLocationInformation().getMethodName()); + } + + break; + + case ChainsawColumns.INDEX_CLASS_COL_NAME: + + if ( + (e1.locationInformationExists()) + & (e2.locationInformationExists())) { + sort = + e1.getLocationInformation().getClassName().compareToIgnoreCase( + e2.getLocationInformation().getClassName()); + } + + break; + + case ChainsawColumns.INDEX_FILE_COL_NAME: + + if ( + (e1.locationInformationExists()) + & (e2.locationInformationExists())) { + sort = + e1.getLocationInformation().getFileName().compareToIgnoreCase( + e2.getLocationInformation().getFileName()); + } + + break; + + case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME: + sort = (Long.compare(e1.getTimeStamp(), e2.getTimeStamp())); + break; + + case ChainsawColumns.INDEX_THREAD_COL_NAME: + sort = e1.getThreadName().compareToIgnoreCase(e2.getThreadName()); + break; + + case ChainsawColumns.INDEX_ID_COL_NAME: + int id1 = Integer.parseInt(e1.getProperty(Constants.LOG4J_ID_KEY)); + int id2 = Integer.parseInt(e2.getProperty(Constants.LOG4J_ID_KEY)); + sort = Integer.compare(id2, id1); + break; + + case ChainsawColumns.INDEX_THROWABLE_COL_NAME: + if (e1.getThrowableStrRep() != null && e2.getThrowableStrRep() != null) { + String[] s1 = e1.getThrowableStrRep(); + String[] s2 = e2.getThrowableStrRep(); + boolean foundDiff = false; + for (int i = 0; i < s1.length; i++) { + if (foundDiff || i > s2.length) { + break; + } + sort = s1[i].compareToIgnoreCase(s2[i]); + foundDiff = sort != 0; + } + } + break; + + case ChainsawColumns.INDEX_LINE_COL_NAME: + if ( + (e1.locationInformationExists()) + & (e2.locationInformationExists())) { + sort = + e1.getLocationInformation().getLineNumber().compareToIgnoreCase( + e2.getLocationInformation().getLineNumber()); + } + break; + + //other columns may be Property values - see if there is an Property value matching column name + default: + if (e1.getProperty(columnName) != null && e2.getProperty(columnName) != null) { + sort = e1.getProperty(columnName).compareToIgnoreCase(e2.getProperty(columnName)); + } + } } - break; + sort = Integer.compare(sort, 0); - case ChainsawColumns.INDEX_CLASS_COL_NAME: - - if ( - (e1.locationInformationExists()) - & (e2.locationInformationExists())) { - sort = - e1.getLocationInformation().getClassName().compareToIgnoreCase( - e2.getLocationInformation().getClassName()); + if (!ascending && (sort != 0)) { + sort = (sort < 0) ? 1 : (-1); } - break; - - case ChainsawColumns.INDEX_FILE_COL_NAME: - - if ( - (e1.locationInformationExists()) - & (e2.locationInformationExists())) { - sort = - e1.getLocationInformation().getFileName().compareToIgnoreCase( - e2.getLocationInformation().getFileName()); - } - - break; - - case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME: - sort = (Long.compare(e1.getTimeStamp(), e2.getTimeStamp())); - break; - - case ChainsawColumns.INDEX_THREAD_COL_NAME: - sort = e1.getThreadName().compareToIgnoreCase(e2.getThreadName()); - break; - - case ChainsawColumns.INDEX_ID_COL_NAME: - int id1 = Integer.parseInt(e1.getProperty(Constants.LOG4J_ID_KEY)); - int id2 = Integer.parseInt(e2.getProperty(Constants.LOG4J_ID_KEY)); - sort = Integer.compare(id2, id1); - break; - - case ChainsawColumns.INDEX_THROWABLE_COL_NAME: - if (e1.getThrowableStrRep() != null && e2.getThrowableStrRep() != null) { - String[] s1 = e1.getThrowableStrRep(); - String[] s2 = e2.getThrowableStrRep(); - boolean foundDiff = false; - for (int i = 0;i<s1.length;i++) { - if (foundDiff || i > s2.length) { - break; - } - sort = s1[i].compareToIgnoreCase(s2[i]); - foundDiff = sort != 0; - } - } - break; - - case ChainsawColumns.INDEX_LINE_COL_NAME: - if ( - (e1.locationInformationExists()) - & (e2.locationInformationExists())) { - sort = - e1.getLocationInformation().getLineNumber().compareToIgnoreCase( - e2.getLocationInformation().getLineNumber()); - } - break; - - //other columns may be Property values - see if there is an Property value matching column name - default: - if (e1.getProperty(columnName) != null && e2.getProperty(columnName) != null) { - sort = e1.getProperty(columnName).compareToIgnoreCase(e2.getProperty(columnName)); - } - } + return sort; } - - sort = Integer.compare(sort, 0); - - if (!ascending && (sort != 0)) { - sort = (sort < 0) ? 1 : (-1); - } - - return sort; - } }
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/CommonActions.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/CommonActions.java b/src/main/java/org/apache/log4j/chainsaw/CommonActions.java index 815e692..2e2da99 100644 --- a/src/main/java/org/apache/log4j/chainsaw/CommonActions.java +++ b/src/main/java/org/apache/log4j/chainsaw/CommonActions.java @@ -16,54 +16,48 @@ */ package org.apache.log4j.chainsaw; -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; - import org.apache.log4j.chainsaw.help.HelpManager; +import javax.swing.*; +import java.awt.event.ActionEvent; + /** * @author psmith - * */ -class CommonActions -{ +class CommonActions { private static CommonActions instance = null; - private static Action SHOW_RELEASE_NOTE; - - + private static Action SHOW_RELEASE_NOTE; + + private void initActions() { SHOW_RELEASE_NOTE = new AbstractAction("Release Notes") { - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { HelpManager.getInstance().setHelpURL(ChainsawConstants.RELEASE_NOTES_URL); - - }}; + + } + }; } - + static synchronized CommonActions getInstance() { - if(instance==null) { + if (instance == null) { instance = new CommonActions(); } return instance; } - + /** - * + * */ - private CommonActions() - { + private CommonActions() { initActions(); } /** * @return */ - public Action getShowReleaseNotes() - { + public Action getShowReleaseNotes() { return SHOW_RELEASE_NOTE; } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java b/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java index 10609c0..d7eeafb 100644 --- a/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java +++ b/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java @@ -10,18 +10,16 @@ */ package org.apache.log4j.chainsaw; -import java.awt.Toolkit; -import java.awt.datatransfer.StringSelection; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; - import org.apache.log4j.EnhancedPatternLayout; import org.apache.log4j.Layout; import org.apache.log4j.spi.LoggingEvent; +import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; +import java.util.List; + public class CopyEventsToClipboardAction extends AbstractAction { private static final long serialVersionUID = 1L; @@ -33,19 +31,19 @@ public class CopyEventsToClipboardAction extends AbstractAction { * useful columns before the message. Nice format for pasting into issue trackers. */ private final Layout layout = new EnhancedPatternLayout( - "[%d{ISO8601} %-5p][%20.20c][%t] %m%n"); + "[%d{ISO8601} %-5p][%20.20c][%t] %m%n"); public CopyEventsToClipboardAction(LogUI parent) { super("Copy events to clipboard"); this.logUi = parent; layout.activateOptions(); - + putValue(Action.SHORT_DESCRIPTION, - "Copies to the clipboard currently visible events to a human-readable, log-like format"); + "Copies to the clipboard currently visible events to a human-readable, log-like format"); } - - + + public void actionPerformed(ActionEvent e) { List filteredEvents = logUi.getCurrentLogPanel().getFilteredEvents(); StringBuilder writer = new StringBuilder(filteredEvents.size() * EVENTSIZE_FUDGE_FACTOR); @@ -56,7 +54,7 @@ public class CopyEventsToClipboardAction extends AbstractAction { StringSelection stringSelection = new StringSelection(writer.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, - stringSelection); + stringSelection); } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/CyclicBufferList.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/CyclicBufferList.java b/src/main/java/org/apache/log4j/chainsaw/CyclicBufferList.java index e3efe9d..802a568 100644 --- a/src/main/java/org/apache/log4j/chainsaw/CyclicBufferList.java +++ b/src/main/java/org/apache/log4j/chainsaw/CyclicBufferList.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. @@ -24,197 +24,193 @@ import java.util.List; /** - * * CyclicBuffer implementation that is Object generic, and implements the List interface. - * + * <p> * Original CyclicBuffer @author Ceki Gülcü - * + * <p> * This implementation (although there's very little change) @author Paul Smith <psm...@apache.org> - * */ public class CyclicBufferList extends AbstractList implements List { - Object[] ea; - int first; - int last; - int numElems; - int maxSize; - - /** - Instantiate a new CyclicBuffer of at most <code>maxSize</code> events. - - The <code>maxSize</code> argument must a positive integer. - - @param maxSize The maximum number of elements in the buffer. - */ - public CyclicBufferList(int maxSize) { - if (maxSize < 1) { - throw new IllegalArgumentException( - "The maxSize argument (" + maxSize + ") is not a positive integer."); + Object[] ea; + int first; + int last; + int numElems; + int maxSize; + + /** + * Instantiate a new CyclicBuffer of at most <code>maxSize</code> events. + * <p> + * The <code>maxSize</code> argument must a positive integer. + * + * @param maxSize The maximum number of elements in the buffer. + */ + public CyclicBufferList(int maxSize) { + if (maxSize < 1) { + throw new IllegalArgumentException( + "The maxSize argument (" + maxSize + ") is not a positive integer."); + } + this.maxSize = maxSize; + clear(); + } + + public CyclicBufferList() { + this(5000); } - this.maxSize = maxSize; - clear(); - } - - public CyclicBufferList() { - this(5000); - } - - /** - * Removes the element at the specified position in this list. - * Shifts any subsequent elements to the left (subtracts one from their - * indices). - * - * @param index the index of the element to removed. - * @return the element that was removed from the list. - * @throws IndexOutOfBoundsException if index out of range <tt>(index - * < 0 || index >= size())</tt>. - */ - public Object remove(int index) { - Object oldValue = ea[index]; - - List list = new ArrayList(Arrays.asList(ea)); - list.remove(index); - ea = list.toArray(ea); - numElems = ea.length; - - numElems--; - if (--last <= 0) { - last = numElems; + + /** + * Removes the element at the specified position in this list. + * Shifts any subsequent elements to the left (subtracts one from their + * indices). + * + * @param index the index of the element to removed. + * @return the element that was removed from the list. + * @throws IndexOutOfBoundsException if index out of range <tt>(index + * < 0 || index >= size())</tt>. + */ + public Object remove(int index) { + Object oldValue = ea[index]; + + List list = new ArrayList(Arrays.asList(ea)); + list.remove(index); + ea = list.toArray(ea); + numElems = ea.length; + + numElems--; + if (--last <= 0) { + last = numElems; + } + + if (first == maxSize) { + first = 0; + } + return oldValue; } - if (first == maxSize) { - first = 0; + public Object set(int index, Object element) { + Object previous = ea[index]; + ea[index] = element; + + return previous; } - return oldValue; - } - public Object set(int index, Object element) { - Object previous = ea[index]; - ea[index] = element; + /** + * Add an <code>event</code> as the last event in the buffer. + */ + public boolean add(Object event) { + ea[last] = event; - return previous; - } + if (++last == maxSize) { + last = 0; + } - /** - Add an <code>event</code> as the last event in the buffer. + if (numElems < maxSize) { + numElems++; + } else if (++first == maxSize) { + first = 0; + } - */ - public boolean add(Object event) { - ea[last] = event; + return true; + } - if (++last == maxSize) { - last = 0; + /** + * Get the <i>i</i>th oldest event currently in the buffer. If + * <em>i</em> is outside the range 0 to the number of elements + * currently in the buffer, then <code>null</code> is returned. + */ + public Object get(int i) { + if ((i < 0) || (i >= numElems)) { + return null; + } + + return ea[(first + i) % maxSize]; } - if (numElems < maxSize) { - numElems++; - } else if (++first == maxSize) { - first = 0; + public int getMaxSize() { + return maxSize; } - return true; - } + public int getLast() { + return last; + } - /** - Get the <i>i</i>th oldest event currently in the buffer. If - <em>i</em> is outside the range 0 to the number of elements - currently in the buffer, then <code>null</code> is returned. + /** + * Get the oldest (first) element in the buffer. The oldest element + * is removed from the buffer. + */ + public Object get() { + Object r = null; + if (numElems > 0) { + numElems--; + r = ea[first]; + ea[first] = null; - */ - public Object get(int i) { - if ((i < 0) || (i >= numElems)) { - return null; - } + if (++first == maxSize) { + first = 0; + } + } - return ea[(first + i) % maxSize]; - } - - public int getMaxSize() { - return maxSize; - } - - public int getLast() { - return last; - } - - /** - Get the oldest (first) element in the buffer. The oldest element - is removed from the buffer. - */ - public Object get() { - Object r = null; - - if (numElems > 0) { - numElems--; - r = ea[first]; - ea[first] = null; - - if (++first == maxSize) { - first = 0; - } + return r; } - return r; - } - - /** - Get the number of elements in the buffer. This number is - guaranteed to be in the range 0 to <code>maxSize</code> - (inclusive). - */ - public int size() { - return numElems; - } - - /** - Resize the cyclic buffer to <code>newSize</code>. - - @throws IllegalArgumentException if <code>newSize</code> is negative. - */ - public void resize(int newSize) { - if (newSize < 0) { - throw new IllegalArgumentException( - "Negative array size [" + newSize + "] not allowed."); + /** + * Get the number of elements in the buffer. This number is + * guaranteed to be in the range 0 to <code>maxSize</code> + * (inclusive). + */ + public int size() { + return numElems; } - if (newSize == numElems) { - return; // nothing to do - } + /** + * Resize the cyclic buffer to <code>newSize</code>. + * + * @throws IllegalArgumentException if <code>newSize</code> is negative. + */ + public void resize(int newSize) { + if (newSize < 0) { + throw new IllegalArgumentException( + "Negative array size [" + newSize + "] not allowed."); + } + + if (newSize == numElems) { + return; // nothing to do + } - Object[] temp = new Object[newSize]; + Object[] temp = new Object[newSize]; - int loopLen = (newSize < numElems) ? newSize : numElems; + int loopLen = (newSize < numElems) ? newSize : numElems; - for (int i = 0; i < loopLen; i++) { - temp[i] = ea[first]; - ea[first] = null; + for (int i = 0; i < loopLen; i++) { + temp[i] = ea[first]; + ea[first] = null; - if (++first == numElems) { + if (++first == numElems) { + first = 0; + } + } + + ea = temp; first = 0; - } + numElems = loopLen; + maxSize = newSize; + + if (loopLen == newSize) { + last = 0; + } else { + last = loopLen; + } } - ea = temp; - first = 0; - numElems = loopLen; - maxSize = newSize; + /* (non-Javadoc) + * @see java.util.Collection#clear() + */ + public void clear() { + ea = new Object[maxSize]; + first = 0; + last = 0; + numElems = 0; - if (loopLen == newSize) { - last = 0; - } else { - last = loopLen; } - } - /* (non-Javadoc) - * @see java.util.Collection#clear() - */ - public void clear() { - ea = new Object[maxSize]; - first = 0; - last = 0; - numElems = 0; - - } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/DockablePanel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/DockablePanel.java b/src/main/java/org/apache/log4j/chainsaw/DockablePanel.java index 8f5abfb..8053efe 100644 --- a/src/main/java/org/apache/log4j/chainsaw/DockablePanel.java +++ b/src/main/java/org/apache/log4j/chainsaw/DockablePanel.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,31 +17,30 @@ package org.apache.log4j.chainsaw; -import java.awt.Dimension; - -import javax.swing.JPanel; +import javax.swing.*; +import java.awt.*; /** * Extends the functionality of a JPanel by providing a 'docked' state. + * * @author Scott Deboy <sde...@apache.org> * @author Paul Smith <psm...@apache.org> */ public class DockablePanel extends JPanel { - private boolean isDocked = true; + private boolean isDocked = true; - public void setDocked(boolean docked) { - boolean oldVal = isDocked; - isDocked = docked; - firePropertyChange("docked", oldVal, isDocked); - } + public void setDocked(boolean docked) { + boolean oldVal = isDocked; + isDocked = docked; + firePropertyChange("docked", oldVal, isDocked); + } - public boolean isDocked() { - return isDocked; - } + public boolean isDocked() { + return isDocked; + } - public Dimension getPreferredSize() - { + public Dimension getPreferredSize() { return new Dimension(1024, 768); } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/EventBatchListener.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/EventBatchListener.java b/src/main/java/org/apache/log4j/chainsaw/EventBatchListener.java index 354bee2..a90e2db 100644 --- a/src/main/java/org/apache/log4j/chainsaw/EventBatchListener.java +++ b/src/main/java/org/apache/log4j/chainsaw/EventBatchListener.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. @@ -25,24 +25,26 @@ import java.util.List; * Implementations of this interface like to be notified * of arriving batches of LoggingEvents, but may only * be interested in those coming from a particular source - * @author Paul Smith <psm...@apache.org> * + * @author Paul Smith <psm...@apache.org> */ public interface EventBatchListener extends EventListener { - /** - * Returns the string representing the identifier - * that this instance is only interested in, or - * null if this instance is interested in ALL events from - * any identifier - * @return String identifier of the interested source - */ - String getInterestedIdentifier(); + /** + * Returns the string representing the identifier + * that this instance is only interested in, or + * null if this instance is interested in ALL events from + * any identifier + * + * @return String identifier of the interested source + */ + String getInterestedIdentifier(); - /** - * Implementations receive a list of LoggingEvent instances only if they are interested, - * that is, if the source of the eventBatch matches this instances interested identifier - * @param events List of LoggingEvent instances - * @param identifier the identifier this list of LoggingEvents is associated with - */ - void receiveEventBatch(String identifier, List<org.apache.log4j.spi.LoggingEvent> events); + /** + * Implementations receive a list of LoggingEvent instances only if they are interested, + * that is, if the source of the eventBatch matches this instances interested identifier + * + * @param events List of LoggingEvent instances + * @param identifier the identifier this list of LoggingEvents is associated with + */ + void receiveEventBatch(String identifier, List<org.apache.log4j.spi.LoggingEvent> events); } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/EventContainer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/EventContainer.java b/src/main/java/org/apache/log4j/chainsaw/EventContainer.java index 179ec96..d69fcd1 100644 --- a/src/main/java/org/apache/log4j/chainsaw/EventContainer.java +++ b/src/main/java/org/apache/log4j/chainsaw/EventContainer.java @@ -17,169 +17,180 @@ package org.apache.log4j.chainsaw; +import org.apache.log4j.rule.Rule; + import java.beans.PropertyChangeListener; import java.util.List; -import org.apache.log4j.rule.Rule; - /** * To allow pluggable TableModel implementations for Chainsaw, this interface has been factored out. - * + * <p> * This interface is still subject to change. * * @author Paul Smith <psm...@apache.org> * @author Scott Deboy <sde...@apache.org> * @author Stephen Pain - * */ public interface EventContainer extends SortTableModel, LoggerNameModel { - /** - * Adds an EventCountListener, to be notified when the # of events changes - * @param listener - */ - void addEventCountListener(EventCountListener listener); - - void addPropertyChangeListener(PropertyChangeListener l); - - void addPropertyChangeListener( - String propertyName, PropertyChangeListener l); - - /** - * Adds a NewKeyListener to be notified when unique Key (Property keys) - * arrive into this EventContainer - * @param l - */ - void addNewKeyListener(NewKeyListener l); - - /** - * Removes a listener from being notified of NewKey events. - * @param l - */ - void removeNewKeyListener(NewKeyListener l); - - /** - * Clears the model completely - * - */ - void clearModel(); - - List<LoggingEventWrapper> getMatchingEvents(Rule rule); - - /** - * Configures this model to use Cyclic or non-cyclic models. - * This method should fire a property Change event if - * it involves an actual change in the underlying model. - * - * This method does nothing if there is no change in proprty. - * @param cyclic - */ - void setCyclic(boolean cyclic); - - /** - * If this container is in Cyclic mode, returns the Size of the cyclic buffer, - * otherwise this method throws an IllegalStateException, when in unlimited - * mode, this method has no meaning. - * - * @throws IllegalStateException if this containers isCyclic() method returns false. - * @return int size of the cyclic buffer - */ - int getMaxSize(); - - /** - * Locates a row number, starting from startRow, matching the rule provided - * - * @param rule - * @param startRow - * @param searchForward - */ - int locate(Rule rule, int startRow, boolean searchForward); - - /** - * Returns a copied list of all the event in the model. - */ - List getAllEvents(); - - /** - * Returns a copied list containing the events in the model with filter applied - */ - List getFilteredEvents(); - - /** - * Returns the total number of events currently in the model (all, not just filtered) - * @return size - */ - int size(); - - /** - * Returns the vector representing the row. - */ - LoggingEventWrapper getRow(int row); - - /** - * Adds a row to the model. - * @param e event - * @return flag representing whether or not the row is being displayed (not filtered) - */ - boolean isAddRow(LoggingEventWrapper e); - - /** - * Fire appropriate table update events for the range. - */ - void fireTableEvent(int begin, int end, int count); + /** + * Adds an EventCountListener, to be notified when the # of events changes + * + * @param listener + */ + void addEventCountListener(EventCountListener listener); + + void addPropertyChangeListener(PropertyChangeListener l); + + void addPropertyChangeListener( + String propertyName, PropertyChangeListener l); + + /** + * Adds a NewKeyListener to be notified when unique Key (Property keys) + * arrive into this EventContainer + * + * @param l + */ + void addNewKeyListener(NewKeyListener l); + + /** + * Removes a listener from being notified of NewKey events. + * + * @param l + */ + void removeNewKeyListener(NewKeyListener l); + + /** + * Clears the model completely + */ + void clearModel(); + + List<LoggingEventWrapper> getMatchingEvents(Rule rule); + + /** + * Configures this model to use Cyclic or non-cyclic models. + * This method should fire a property Change event if + * it involves an actual change in the underlying model. + * <p> + * This method does nothing if there is no change in proprty. + * + * @param cyclic + */ + void setCyclic(boolean cyclic); + + /** + * If this container is in Cyclic mode, returns the Size of the cyclic buffer, + * otherwise this method throws an IllegalStateException, when in unlimited + * mode, this method has no meaning. + * + * @return int size of the cyclic buffer + * @throws IllegalStateException if this containers isCyclic() method returns false. + */ + int getMaxSize(); + + /** + * Locates a row number, starting from startRow, matching the rule provided + * + * @param rule + * @param startRow + * @param searchForward + */ + int locate(Rule rule, int startRow, boolean searchForward); + + /** + * Returns a copied list of all the event in the model. + */ + List getAllEvents(); + + /** + * Returns a copied list containing the events in the model with filter applied + */ + List getFilteredEvents(); + + /** + * Returns the total number of events currently in the model (all, not just filtered) + * + * @return size + */ + int size(); + + /** + * Returns the vector representing the row. + */ + LoggingEventWrapper getRow(int row); + + /** + * Adds a row to the model. + * + * @param e event + * @return flag representing whether or not the row is being displayed (not filtered) + */ + boolean isAddRow(LoggingEventWrapper e); + + /** + * Fire appropriate table update events for the range. + */ + void fireTableEvent(int begin, int end, int count); /** * A row was updated + * * @param row * @param checkForNewColumns */ - void fireRowUpdated(int row, boolean checkForNewColumns); - /** - * Allow a forced notification of the EventCountListeners - * - */ - void notifyCountListeners(); - - /** - * Force a re-processing of the table layout - */ - void reFilter(); - /** - * Sets the RuleMediator in operation - * @param ruleMediator - */ - void setRuleMediator(RuleMediator ruleMediator); - - /** - * Returns the index of the LoggingEventWrapper - * @param loggingEventWrapper - */ - int getRowIndex(LoggingEventWrapper loggingEventWrapper); - - /** - * Remove property from all events in container - * @param propName the property name to remove - */ - void removePropertyFromEvents(String propName); - - /** - * Evaluate all events against the find rule - * @param findRule - */ - int updateEventsWithFindRule(Rule findRule); - - /** - * Determine next row with a non-default color - * @param currentRow - * @param forward - * @return - */ - int findColoredRow(int currentRow, boolean forward); - - /** - * Return the visible search match count - * - * @return - */ - int getSearchMatchCount(); + void fireRowUpdated(int row, boolean checkForNewColumns); + + /** + * Allow a forced notification of the EventCountListeners + */ + void notifyCountListeners(); + + /** + * Force a re-processing of the table layout + */ + void reFilter(); + + /** + * Sets the RuleMediator in operation + * + * @param ruleMediator + */ + void setRuleMediator(RuleMediator ruleMediator); + + /** + * Returns the index of the LoggingEventWrapper + * + * @param loggingEventWrapper + */ + int getRowIndex(LoggingEventWrapper loggingEventWrapper); + + /** + * Remove property from all events in container + * + * @param propName the property name to remove + */ + void removePropertyFromEvents(String propName); + + /** + * Evaluate all events against the find rule + * + * @param findRule + */ + int updateEventsWithFindRule(Rule findRule); + + /** + * Determine next row with a non-default color + * + * @param currentRow + * @param forward + * @return + */ + int findColoredRow(int currentRow, boolean forward); + + /** + * Return the visible search match count + * + * @return + */ + int getSearchMatchCount(); } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/EventCountListener.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/EventCountListener.java b/src/main/java/org/apache/log4j/chainsaw/EventCountListener.java index 42d38ff..b28a9ae 100644 --- a/src/main/java/org/apache/log4j/chainsaw/EventCountListener.java +++ b/src/main/java/org/apache/log4j/chainsaw/EventCountListener.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. @@ -23,8 +23,9 @@ import java.util.EventListener; /** * Listeners can be notified when the # of events in a particular model * changes + * * @author Scott Deboy <sde...@apache.org> */ -public interface EventCountListener extends EventListener{ - void eventCountChanged(int currentCount, int totalCount); +public interface EventCountListener extends EventListener { + void eventCountChanged(int currentCount, int totalCount); } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ExpressionRuleContext.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ExpressionRuleContext.java b/src/main/java/org/apache/log4j/chainsaw/ExpressionRuleContext.java index 95f2902..cba7df2 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ExpressionRuleContext.java +++ b/src/main/java/org/apache/log4j/chainsaw/ExpressionRuleContext.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,284 +17,275 @@ package org.apache.log4j.chainsaw; -import java.awt.Point; -import java.awt.event.InputEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.DefaultListModel; -import javax.swing.JList; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.ListModel; -import javax.swing.text.JTextComponent; - import org.apache.log4j.chainsaw.filter.FilterModel; import org.apache.log4j.rule.RuleFactory; import org.apache.log4j.spi.LoggingEventFieldResolver; +import javax.swing.*; +import javax.swing.text.JTextComponent; +import java.awt.*; +import java.awt.event.*; + /** - * A popup menu which assists in building expression rules. Completes event keywords, operators and + * A popup menu which assists in building expression rules. Completes event keywords, operators and * context if available. - * + * * @author Scott Deboy <sde...@apache.org> */ public class ExpressionRuleContext extends KeyAdapter { - RuleFactory factory = RuleFactory.getInstance(); - LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance(); - JPopupMenu contextMenu = new JPopupMenu(); - JList list = new JList(); - FilterModel filterModel; - JScrollPane scrollPane = new JScrollPane(list); - final JTextComponent textComponent; - private DefaultListModel fieldModel = new DefaultListModel(); - private DefaultListModel operatorModel = new DefaultListModel(); - - public ExpressionRuleContext( - final FilterModel filterModel, final JTextComponent textComponent) { - this.filterModel = filterModel; - this.textComponent = textComponent; - fieldModel.addElement("LOGGER"); - fieldModel.addElement("LEVEL"); - fieldModel.addElement("CLASS"); - fieldModel.addElement("FILE"); - fieldModel.addElement("LINE"); - fieldModel.addElement("METHOD"); - fieldModel.addElement("MSG"); - fieldModel.addElement("NDC"); - fieldModel.addElement("EXCEPTION"); - fieldModel.addElement("TIMESTAMP"); - fieldModel.addElement("THREAD"); - fieldModel.addElement("PROP."); - - operatorModel.addElement("&&"); - operatorModel.addElement("||"); - operatorModel.addElement("!"); - operatorModel.addElement("!="); - operatorModel.addElement("=="); - operatorModel.addElement("~="); - operatorModel.addElement("LIKE"); - operatorModel.addElement("EXISTS"); - operatorModel.addElement("<"); - operatorModel.addElement(">"); - operatorModel.addElement("<="); - operatorModel.addElement(">="); - - //make long to avoid scrollbar - list.setVisibleRowCount(13); - - PopupListener popupListener = new PopupListener(); - textComponent.addMouseListener(popupListener); - - list.addKeyListener( - new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - String value = list.getSelectedValue().toString(); - String contextKey = getContextKey(); - if (contextKey != null && (!(contextKey.endsWith(".")))) { - value = "'"+value+"'"; - } - - updateField(value); - contextMenu.setVisible(false); - } - } - }); - - list.addMouseListener( - new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2) { - String value = list.getSelectedValue().toString(); - String contextKey = getContextKey(); - if (contextKey != null && (!(contextKey.endsWith(".")))) { - value = "'"+value+"'"; + RuleFactory factory = RuleFactory.getInstance(); + LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance(); + JPopupMenu contextMenu = new JPopupMenu(); + JList list = new JList(); + FilterModel filterModel; + JScrollPane scrollPane = new JScrollPane(list); + final JTextComponent textComponent; + private DefaultListModel fieldModel = new DefaultListModel(); + private DefaultListModel operatorModel = new DefaultListModel(); + + public ExpressionRuleContext( + final FilterModel filterModel, final JTextComponent textComponent) { + this.filterModel = filterModel; + this.textComponent = textComponent; + fieldModel.addElement("LOGGER"); + fieldModel.addElement("LEVEL"); + fieldModel.addElement("CLASS"); + fieldModel.addElement("FILE"); + fieldModel.addElement("LINE"); + fieldModel.addElement("METHOD"); + fieldModel.addElement("MSG"); + fieldModel.addElement("NDC"); + fieldModel.addElement("EXCEPTION"); + fieldModel.addElement("TIMESTAMP"); + fieldModel.addElement("THREAD"); + fieldModel.addElement("PROP."); + + operatorModel.addElement("&&"); + operatorModel.addElement("||"); + operatorModel.addElement("!"); + operatorModel.addElement("!="); + operatorModel.addElement("=="); + operatorModel.addElement("~="); + operatorModel.addElement("LIKE"); + operatorModel.addElement("EXISTS"); + operatorModel.addElement("<"); + operatorModel.addElement(">"); + operatorModel.addElement("<="); + operatorModel.addElement(">="); + + //make long to avoid scrollbar + list.setVisibleRowCount(13); + + PopupListener popupListener = new PopupListener(); + textComponent.addMouseListener(popupListener); + + list.addKeyListener( + new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + String value = list.getSelectedValue().toString(); + String contextKey = getContextKey(); + if (contextKey != null && (!(contextKey.endsWith(".")))) { + value = "'" + value + "'"; + } + + updateField(value); + contextMenu.setVisible(false); + } + } + }); + + list.addMouseListener( + new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + String value = list.getSelectedValue().toString(); + String contextKey = getContextKey(); + if (contextKey != null && (!(contextKey.endsWith(".")))) { + value = "'" + value + "'"; + } + + updateField(value); + contextMenu.setVisible(false); + } + } + }); + + contextMenu.insert(scrollPane, 0); + } + + private void updateField(String value) { + if (textComponent.getSelectedText() == null) { + if (!(value.endsWith("."))) { + value = value + " "; } - - updateField(value); - contextMenu.setVisible(false); - } } - }); - contextMenu.insert(scrollPane, 0); - } + textComponent.replaceSelection(value); + } - private void updateField(String value) { - if (textComponent.getSelectedText() == null) { - if (!(value.endsWith("."))) { - value = value + " "; + public void keyPressed(KeyEvent e) { + if ( + (e.getKeyCode() == KeyEvent.VK_SPACE) + && (e.getModifiers() == InputEvent.CTRL_MASK)) { + displayContext(); } } - textComponent.replaceSelection(value); - } + public void displayContext() { + String lastField = getContextKey(); - public void keyPressed(KeyEvent e) { - if ( - (e.getKeyCode() == KeyEvent.VK_SPACE) - && (e.getModifiers() == InputEvent.CTRL_MASK)) { - displayContext(); - } - } - - public void displayContext() { - String lastField = getContextKey(); - - if (lastField != null) { - ListModel model = filterModel.getContainer().getModel(lastField); - if (model == null) { - return; - } - list.setModel(model); - list.setSelectedIndex(0); - - Point p = textComponent.getCaret().getMagicCaretPosition(); - contextMenu.doLayout(); - contextMenu.show(textComponent, p.x, (p.y + (textComponent.getHeight() - 5))); - list.requestFocus(); - } else { - if (isOperatorContextValid()) { - list.setModel(operatorModel); - list.setSelectedIndex(0); - - Point p = textComponent.getCaret().getMagicCaretPosition(); - contextMenu.doLayout(); - contextMenu.show(textComponent, p.x, (p.y + (textComponent.getHeight() - 5))); - list.requestFocus(); - } else if (isFieldContextValid()) { - list.setModel(fieldModel); - list.setSelectedIndex(0); - - Point p = textComponent.getCaret().getMagicCaretPosition(); - - if (p == null) { - p = new Point( - textComponent.getLocation().x, - (textComponent.getLocation().y - textComponent.getHeight() + 5)); + if (lastField != null) { + ListModel model = filterModel.getContainer().getModel(lastField); + if (model == null) { + return; + } + list.setModel(model); + list.setSelectedIndex(0); + + Point p = textComponent.getCaret().getMagicCaretPosition(); + contextMenu.doLayout(); + contextMenu.show(textComponent, p.x, (p.y + (textComponent.getHeight() - 5))); + list.requestFocus(); + } else { + if (isOperatorContextValid()) { + list.setModel(operatorModel); + list.setSelectedIndex(0); + + Point p = textComponent.getCaret().getMagicCaretPosition(); + contextMenu.doLayout(); + contextMenu.show(textComponent, p.x, (p.y + (textComponent.getHeight() - 5))); + list.requestFocus(); + } else if (isFieldContextValid()) { + list.setModel(fieldModel); + list.setSelectedIndex(0); + + Point p = textComponent.getCaret().getMagicCaretPosition(); + + if (p == null) { + p = new Point( + textComponent.getLocation().x, + (textComponent.getLocation().y - textComponent.getHeight() + 5)); + } + contextMenu.doLayout(); + contextMenu.show(textComponent, p.x, (p.y + (textComponent.getHeight() - 5))); + list.requestFocus(); + } } - contextMenu.doLayout(); - contextMenu.show(textComponent, p.x, (p.y + (textComponent.getHeight() - 5))); - list.requestFocus(); - } } - } - - private boolean isFieldContextValid() { - String text = textComponent.getText(); - int currentPosition = textComponent.getSelectionStart(); - return ((currentPosition == 0) - || (text.charAt(currentPosition - 1) == ' ')); - } + private boolean isFieldContextValid() { + String text = textComponent.getText(); + int currentPosition = textComponent.getSelectionStart(); - private String getContextKey() { - String field = getField(); - - if (field == null) { - field = getSubField(); + return ((currentPosition == 0) + || (text.charAt(currentPosition - 1) == ' ')); } - return field; - } - - private boolean isOperatorContextValid() { - String text = textComponent.getText(); + private String getContextKey() { + String field = getField(); - int currentPosition = textComponent.getSelectionStart(); + if (field == null) { + field = getSubField(); + } - if ((currentPosition < 1) || (text.charAt(currentPosition - 1) != ' ')) { - return false; + return field; } - int lastFieldPosition = text.lastIndexOf(" ", currentPosition - 1); + private boolean isOperatorContextValid() { + String text = textComponent.getText(); - if (lastFieldPosition == -1) { - return false; - } + int currentPosition = textComponent.getSelectionStart(); - int lastFieldStartPosition = - Math.max(0, text.lastIndexOf(" ", lastFieldPosition - 1)); - String field = - text.substring(lastFieldStartPosition, lastFieldPosition).toUpperCase() - .trim(); + if ((currentPosition < 1) || (text.charAt(currentPosition - 1) != ' ')) { + return false; + } - return resolver.isField(field); + int lastFieldPosition = text.lastIndexOf(" ", currentPosition - 1); - } + if (lastFieldPosition == -1) { + return false; + } - //returns the currently active field which can be used to display a context menu - //the field returned is the left hand portion of an expression (for example, logger == ) - //logger is the field that is returned - private String getField() { - String text = textComponent.getText(); + int lastFieldStartPosition = + Math.max(0, text.lastIndexOf(" ", lastFieldPosition - 1)); + String field = + text.substring(lastFieldStartPosition, lastFieldPosition).toUpperCase() + .trim(); - int currentPosition = textComponent.getSelectionStart(); + return resolver.isField(field); - if ((currentPosition < 1) || (text.charAt(currentPosition - 1) != ' ')) { - return null; } - int symbolPosition = text.lastIndexOf(" ", currentPosition - 1); + //returns the currently active field which can be used to display a context menu + //the field returned is the left hand portion of an expression (for example, logger == ) + //logger is the field that is returned + private String getField() { + String text = textComponent.getText(); - if (symbolPosition < 0) { - return null; - } + int currentPosition = textComponent.getSelectionStart(); - int lastFieldPosition = text.lastIndexOf(" ", symbolPosition - 1); + if ((currentPosition < 1) || (text.charAt(currentPosition - 1) != ' ')) { + return null; + } - if (lastFieldPosition < 0) { - return null; - } + int symbolPosition = text.lastIndexOf(" ", currentPosition - 1); - int lastFieldStartPosition = - Math.max(0, text.lastIndexOf(" ", lastFieldPosition - 1)); - String lastSymbol = - text.substring(lastFieldPosition + 1, symbolPosition).trim(); + if (symbolPosition < 0) { + return null; + } - String lastField = - text.substring(lastFieldStartPosition, lastFieldPosition).trim(); + int lastFieldPosition = text.lastIndexOf(" ", symbolPosition - 1); - if ( - factory.isRule(lastSymbol) - && filterModel.getContainer().modelExists(lastField)) { - return lastField; - } + if (lastFieldPosition < 0) { + return null; + } - return null; - } + int lastFieldStartPosition = + Math.max(0, text.lastIndexOf(" ", lastFieldPosition - 1)); + String lastSymbol = + text.substring(lastFieldPosition + 1, symbolPosition).trim(); - //subfields allow the key portion of a field to provide context menu support - //and are available after the fieldname and a . (for example, PROP.) - private String getSubField() { - int currentPosition = textComponent.getSelectionStart(); - String text = textComponent.getText(); + String lastField = + text.substring(lastFieldStartPosition, lastFieldPosition).trim(); - if (text.substring(0, currentPosition).toUpperCase().endsWith("PROP.")) { - return "PROP."; - } - return null; - } + if ( + factory.isRule(lastSymbol) + && filterModel.getContainer().modelExists(lastField)) { + return lastField; + } - class PopupListener extends MouseAdapter { - PopupListener() { + return null; } - public void mousePressed(MouseEvent e) { - checkPopup(e); - } + //subfields allow the key portion of a field to provide context menu support + //and are available after the fieldname and a . (for example, PROP.) + private String getSubField() { + int currentPosition = textComponent.getSelectionStart(); + String text = textComponent.getText(); - public void mouseReleased(MouseEvent e) { - checkPopup(e); + if (text.substring(0, currentPosition).toUpperCase().endsWith("PROP.")) { + return "PROP."; + } + return null; } - private void checkPopup(MouseEvent e) { - if (e.isPopupTrigger()) { - displayContext(); - } + class PopupListener extends MouseAdapter { + PopupListener() { + } + + public void mousePressed(MouseEvent e) { + checkPopup(e); + } + + public void mouseReleased(MouseEvent e) { + checkPopup(e); + } + + private void checkPopup(MouseEvent e) { + if (e.isPopupTrigger()) { + displayContext(); + } + } } - } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java b/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java index 22d98ca..fc9782f 100644 --- a/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java +++ b/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.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,14 @@ package org.apache.log4j.chainsaw; +import org.apache.log4j.Logger; +import org.apache.log4j.chainsaw.helper.SwingHelper; +import org.apache.log4j.chainsaw.prefs.MRUFileList; +import org.apache.log4j.helpers.Constants; +import org.apache.log4j.spi.Decoder; +import org.apache.log4j.spi.LoggingEvent; + +import javax.swing.*; import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; @@ -25,23 +33,12 @@ import java.util.HashMap; import java.util.Map; import java.util.Vector; -import javax.swing.AbstractAction; -import javax.swing.JOptionPane; - -import org.apache.log4j.Logger; -import org.apache.log4j.chainsaw.helper.SwingHelper; -import org.apache.log4j.chainsaw.prefs.MRUFileList; -import org.apache.log4j.helpers.Constants; -import org.apache.log4j.spi.Decoder; -import org.apache.log4j.spi.LoggingEvent; - /** * Allows the user to specify a particular file to open and import the events * into a new tab. - * + * * @author Paul Smith <psm...@apache.org> * @author Scott Deboy <sde...@apache.org> - * */ class FileLoadAction extends AbstractAction { private static final Logger LOG = Logger.getLogger(FileLoadAction.class); @@ -49,7 +46,6 @@ class FileLoadAction extends AbstractAction { /** * This action must have a reference to a LogUI window so that it can append * the events it loads - * */ Decoder decoder; @@ -58,7 +54,7 @@ class FileLoadAction extends AbstractAction { private boolean remoteURL; public FileLoadAction(LogUI parent, Decoder decoder, String title, - boolean isRemoteURL) { + boolean isRemoteURL) { super(title); remoteURL = isRemoteURL; this.decoder = decoder; @@ -68,36 +64,36 @@ class FileLoadAction extends AbstractAction { /* * When the user chooses the Load action, a File chooser is presented to * allow them to find an XML file to load events from. - * + * * Any events decoded from this file are added to one of the tabs. - * + * * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { String name = ""; URL url = null; - if (!remoteURL) { + if (!remoteURL) { try { - File selectedFile = SwingHelper.promptForFile(parent, null, "Load Events from XML file or zipped XML file...", true); - if (selectedFile != null) { - url = selectedFile.toURI().toURL(); - name = selectedFile.getName(); - } + File selectedFile = SwingHelper.promptForFile(parent, null, "Load Events from XML file or zipped XML file...", true); + if (selectedFile != null) { + url = selectedFile.toURI().toURL(); + name = selectedFile.getName(); + } } catch (Exception ex) { // TODO: handle exception } } else { String urltext = JOptionPane - .showInputDialog(parent, - "<html>Please type in the <b>complete</b> URL to the remote XML source.</html>"); + .showInputDialog(parent, + "<html>Please type in the <b>complete</b> URL to the remote XML source.</html>"); if (urltext != null) { try { url = new URL(urltext); } catch (Exception ex) { JOptionPane.showMessageDialog(parent, "'" + urltext - + "' is not a valid URL."); + + "' is not a valid URL."); } } } @@ -109,11 +105,12 @@ class FileLoadAction extends AbstractAction { } /** - * Imports a URL into Chainsaw, by using the Decoder, and + * Imports a URL into Chainsaw, by using the Decoder, and * using the name value as the Application key which (usually) determines * the Tab name + * * @param name - * @param url URL to import + * @param url URL to import */ public static void importURL(final ChainsawAppenderHandler handler, final Decoder decoder, String name, URL url) { Map additionalProperties = new HashMap(); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/FileMenu.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/FileMenu.java b/src/main/java/org/apache/log4j/chainsaw/FileMenu.java index 433d2ac..06132d6 100644 --- a/src/main/java/org/apache/log4j/chainsaw/FileMenu.java +++ b/src/main/java/org/apache/log4j/chainsaw/FileMenu.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. @@ -18,27 +18,21 @@ /* * @author Paul Smith <psm...@apache.org> * -*/ + */ package org.apache.log4j.chainsaw; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.net.URL; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.KeyStroke; - import org.apache.log4j.chainsaw.icons.ChainsawIcons; import org.apache.log4j.chainsaw.osx.OSXIntegration; import org.apache.log4j.chainsaw.prefs.MRUFileList; import org.apache.log4j.xml.UtilLoggingXMLDecoder; import org.apache.log4j.xml.XMLDecoder; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.net.URL; + /** * The complete File Menu for the main GUI, containing @@ -48,101 +42,100 @@ import org.apache.log4j.xml.XMLDecoder; * @author Scott Deboy <sde...@apache.org> */ class FileMenu extends JMenu { - private Action loadConfigAction; - private Action exitAction; - private Action loadLog4JAction; - private Action loadUtilLoggingAction; - private Action remoteLog4JAction; - private Action remoteUtilLoggingAction; - private Action saveAction; - - public FileMenu(final LogUI logUI) { - super("File"); - setMnemonic(KeyEvent.VK_F); - - loadConfigAction = new AbstractAction("Load Chainsaw configuration"){ - public void actionPerformed(ActionEvent actionEvent) { - logUI.showReceiverConfiguration(); - } - }; - - loadLog4JAction = - new FileLoadAction( - logUI, new XMLDecoder(logUI), "Open log4j XML-formatted file (.xml or .zip)...", false); - - loadLog4JAction.putValue( - Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - loadLog4JAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L); - loadLog4JAction.putValue(Action.SHORT_DESCRIPTION, "Loads events from a local XMLLayout-formatted file "); - loadLog4JAction.putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.FILE_OPEN)); - - loadUtilLoggingAction = - new FileLoadAction( - logUI, new UtilLoggingXMLDecoder(logUI), - "Open util.logging XML-formatted file (.xml or .zip)...", false); - - remoteLog4JAction = - new FileLoadAction( - logUI, new XMLDecoder(logUI), "Open remote log4j XML-formatted file (.xml or .zip)...", - true); - remoteUtilLoggingAction = - new FileLoadAction( - logUI, new UtilLoggingXMLDecoder(logUI), - "Open remote util.logging XML-formatted file (.xml or .zip)...", true); - - saveAction = new FileSaveAction(logUI); - - JMenuItem loadChainsawConfig = new JMenuItem(loadConfigAction); - JMenuItem loadLog4JFile = new JMenuItem(loadLog4JAction); - JMenuItem loadUtilLoggingFile = new JMenuItem(loadUtilLoggingAction); - JMenuItem remoteLog4JFile = new JMenuItem(remoteLog4JAction); - JMenuItem remoteUtilLoggingFile = new JMenuItem(remoteUtilLoggingAction); - JMenuItem saveFile = new JMenuItem(saveAction); - - exitAction = - new AbstractAction() { - public void actionPerformed(ActionEvent e) { - logUI.exit(); - } + private Action loadConfigAction; + private Action exitAction; + private Action loadLog4JAction; + private Action loadUtilLoggingAction; + private Action remoteLog4JAction; + private Action remoteUtilLoggingAction; + private Action saveAction; + + public FileMenu(final LogUI logUI) { + super("File"); + setMnemonic(KeyEvent.VK_F); + + loadConfigAction = new AbstractAction("Load Chainsaw configuration") { + public void actionPerformed(ActionEvent actionEvent) { + logUI.showReceiverConfiguration(); + } }; - exitAction.putValue( - Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - exitAction.putValue(Action.SHORT_DESCRIPTION, "Exits the Application"); - exitAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X); - exitAction.putValue(Action.NAME, "Exit"); - - JMenuItem menuItemExit = new JMenuItem(exitAction); - - add(loadChainsawConfig); - add(loadLog4JFile); - add(loadUtilLoggingFile); - addSeparator(); - add(remoteLog4JFile); - add(remoteUtilLoggingFile); - addSeparator(); - add(saveFile); - addSeparator(); - - final JMenu mrulog4j = new JMenu("MRU..."); - - - - MRUFileList.addChangeListener(e -> buildMRUMenu(mrulog4j, logUI)); - buildMRUMenu(mrulog4j, logUI); - - add(mrulog4j); - if (!OSXIntegration.IS_OSX) { + loadLog4JAction = + new FileLoadAction( + logUI, new XMLDecoder(logUI), "Open log4j XML-formatted file (.xml or .zip)...", false); + + loadLog4JAction.putValue( + Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + loadLog4JAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L); + loadLog4JAction.putValue(Action.SHORT_DESCRIPTION, "Loads events from a local XMLLayout-formatted file "); + loadLog4JAction.putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.FILE_OPEN)); + + loadUtilLoggingAction = + new FileLoadAction( + logUI, new UtilLoggingXMLDecoder(logUI), + "Open util.logging XML-formatted file (.xml or .zip)...", false); + + remoteLog4JAction = + new FileLoadAction( + logUI, new XMLDecoder(logUI), "Open remote log4j XML-formatted file (.xml or .zip)...", + true); + remoteUtilLoggingAction = + new FileLoadAction( + logUI, new UtilLoggingXMLDecoder(logUI), + "Open remote util.logging XML-formatted file (.xml or .zip)...", true); + + saveAction = new FileSaveAction(logUI); + + JMenuItem loadChainsawConfig = new JMenuItem(loadConfigAction); + JMenuItem loadLog4JFile = new JMenuItem(loadLog4JAction); + JMenuItem loadUtilLoggingFile = new JMenuItem(loadUtilLoggingAction); + JMenuItem remoteLog4JFile = new JMenuItem(remoteLog4JAction); + JMenuItem remoteUtilLoggingFile = new JMenuItem(remoteUtilLoggingAction); + JMenuItem saveFile = new JMenuItem(saveAction); + + exitAction = + new AbstractAction() { + public void actionPerformed(ActionEvent e) { + logUI.exit(); + } + }; + + exitAction.putValue( + Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + exitAction.putValue(Action.SHORT_DESCRIPTION, "Exits the Application"); + exitAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X); + exitAction.putValue(Action.NAME, "Exit"); + + JMenuItem menuItemExit = new JMenuItem(exitAction); + + add(loadChainsawConfig); + add(loadLog4JFile); + add(loadUtilLoggingFile); addSeparator(); - add(menuItemExit); + add(remoteLog4JFile); + add(remoteUtilLoggingFile); + addSeparator(); + add(saveFile); + addSeparator(); + + final JMenu mrulog4j = new JMenu("MRU..."); + + + MRUFileList.addChangeListener(e -> buildMRUMenu(mrulog4j, logUI)); + buildMRUMenu(mrulog4j, logUI); + + add(mrulog4j); + if (!OSXIntegration.IS_OSX) { + addSeparator(); + add(menuItemExit); + } + + } - - - } - private void buildMRUMenu(final JMenu mrulog4j, final LogUI logui) { + private void buildMRUMenu(final JMenu mrulog4j, final LogUI logui) { mrulog4j.removeAll(); int counter = 1; if (MRUFileList.log4jMRU().getMRUList().size() > 0) { @@ -155,7 +148,7 @@ class FileMenu extends JMenu { public void actionPerformed(ActionEvent e) { FileLoadAction.importURL(logui.handler, - new XMLDecoder(), name, url); + new XMLDecoder(), name, url); } }); mrulog4j.add(menuItem); @@ -166,19 +159,20 @@ class FileMenu extends JMenu { mrulog4j.add(none); } } - Action getLog4JFileOpenAction() { - return loadLog4JAction; - } - Action getUtilLoggingJFileOpenAction() { - return loadUtilLoggingAction; - } + Action getLog4JFileOpenAction() { + return loadLog4JAction; + } - Action getFileSaveAction() { - return saveAction; - } + Action getUtilLoggingJFileOpenAction() { + return loadUtilLoggingAction; + } - Action getExitAction() { - return exitAction; - } + Action getFileSaveAction() { + return saveAction; + } + + Action getExitAction() { + return exitAction; + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java b/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java index 50f6a54..1e5df80 100644 --- a/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java +++ b/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.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,32 +17,20 @@ package org.apache.log4j.chainsaw; -import java.awt.Toolkit; +import org.apache.log4j.chainsaw.icons.ChainsawIcons; +import org.apache.log4j.helpers.LogLog; +import org.apache.log4j.xml.XMLLayout; + +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; -import java.io.BufferedOutputStream; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; +import java.io.*; import java.util.List; import java.util.Locale; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JFileChooser; -import javax.swing.KeyStroke; - -import org.apache.log4j.chainsaw.icons.ChainsawIcons; -import org.apache.log4j.helpers.LogLog; -import org.apache.log4j.xml.XMLLayout; - /** * Allows the user to specify a particular file to which the current tab's @@ -53,85 +41,83 @@ import org.apache.log4j.xml.XMLLayout; * @author Stephen Pain */ class FileSaveAction extends AbstractAction { - private LogUI parent; - private JFileChooser chooser = null; - - /** - * This action must have a reference to a LogUI - * in order to retrieve events to save - * - */ - public FileSaveAction(LogUI parent) { - super("Save displayed events as..."); + private LogUI parent; + private JFileChooser chooser = null; - putValue( - Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S); - putValue( - Action.SHORT_DESCRIPTION, "Saves displayed events for the current tab"); - putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.FILE_SAVE_AS)); - this.parent = parent; - } - - /* - * When the user chooses the Save action, - * a File chooser is presented to allow them to - * find an XML file to save events to. - * - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - public void actionPerformed(ActionEvent e) { + /** + * This action must have a reference to a LogUI + * in order to retrieve events to save + */ + public FileSaveAction(LogUI parent) { + super("Save displayed events as..."); - if( chooser == null ){ - chooser = new JFileChooser(); + putValue( + Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S); + putValue( + Action.SHORT_DESCRIPTION, "Saves displayed events for the current tab"); + putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.FILE_SAVE_AS)); + this.parent = parent; } - - chooser.setAcceptAllFileFilterUsed(true); - chooser.setDialogTitle("Save displayed events (XML or .zipped XML)..."); - chooser.showSaveDialog(parent); - File selectedFile = chooser.getSelectedFile(); + /* + * When the user chooses the Save action, + * a File chooser is presented to allow them to + * find an XML file to save events to. + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { - if (selectedFile != null) { - List v = parent.getCurrentLogPanel().getFilteredEvents(); + if (chooser == null) { + chooser = new JFileChooser(); + } - if (((v != null) && (v.size() == 0)) || (v == null)) { - //no events to save - return; - } + chooser.setAcceptAllFileFilterUsed(true); + chooser.setDialogTitle("Save displayed events (XML or .zipped XML)..."); + chooser.showSaveDialog(parent); + + File selectedFile = chooser.getSelectedFile(); + + if (selectedFile != null) { + List v = parent.getCurrentLogPanel().getFilteredEvents(); + + if (((v != null) && (v.size() == 0)) || (v == null)) { + //no events to save + return; + } - XMLLayout layout = new XMLLayout(); - layout.setProperties(true); - boolean saveAsZip = selectedFile.getName().toLowerCase(Locale.ENGLISH).endsWith(".zip"); - Writer writer = null; - try { - if (saveAsZip) { - ZipOutputStream zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(selectedFile))); - ZipEntry entry = new ZipEntry(selectedFile.getName().substring(0, selectedFile.getName().length() - ".zip".length()) + ".xml"); - zipOutput.putNextEntry(entry); - writer = new OutputStreamWriter(zipOutput); - } else { - writer = new BufferedWriter(new FileWriter(selectedFile)); - } - for (Object aV : v) { - LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) aV; - layout.setLocationInfo(loggingEventWrapper.getLoggingEvent().getThrowableInformation() != null); - writer.write(layout.format(loggingEventWrapper.getLoggingEvent())); - } - } catch (IOException ioe) { - LogLog.warn("Unable to save file", ioe); - } finally { - if (writer != null) { - try { - writer.flush(); - writer.close(); - } - catch (IOException e1) { - //ignore - } - } + XMLLayout layout = new XMLLayout(); + layout.setProperties(true); + boolean saveAsZip = selectedFile.getName().toLowerCase(Locale.ENGLISH).endsWith(".zip"); + Writer writer = null; + try { + if (saveAsZip) { + ZipOutputStream zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(selectedFile))); + ZipEntry entry = new ZipEntry(selectedFile.getName().substring(0, selectedFile.getName().length() - ".zip".length()) + ".xml"); + zipOutput.putNextEntry(entry); + writer = new OutputStreamWriter(zipOutput); + } else { + writer = new BufferedWriter(new FileWriter(selectedFile)); + } + for (Object aV : v) { + LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) aV; + layout.setLocationInfo(loggingEventWrapper.getLoggingEvent().getThrowableInformation() != null); + writer.write(layout.format(loggingEventWrapper.getLoggingEvent())); + } + } catch (IOException ioe) { + LogLog.warn("Unable to save file", ioe); + } finally { + if (writer != null) { + try { + writer.flush(); + writer.close(); + } catch (IOException e1) { + //ignore + } + } + } + } } - } - } }