You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2018/03/13 07:04:52 UTC
[24/27] logging-chainsaw git commit: Reformat code for consistency
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
index a33b3e3..2f79cc5 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
@@ -17,23 +17,6 @@
package org.apache.log4j.chainsaw;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.ProgressMonitor;
-import javax.swing.event.EventListenerList;
-import javax.swing.table.AbstractTableModel;
-
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.color.RuleColorizer;
@@ -43,12 +26,20 @@ import org.apache.log4j.rule.Rule;
import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import javax.swing.*;
+import javax.swing.event.EventListenerList;
+import javax.swing.table.AbstractTableModel;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.*;
+
/**
* A CyclicBuffer implementation of the EventContainer.
- *
+ * <p>
* NOTE: This implementation prevents duplicate rows from being added to the model.
- *
+ * <p>
* Ignoring duplicates was added to support receivers which may attempt to deliver the same
* event more than once but can be safely ignored (for example, the database receiver
* when set to retrieve in a loop).
@@ -56,88 +47,87 @@ import org.apache.log4j.spi.LoggingEvent;
* @author Paul Smith <psmith@apache.org>
* @author Scott Deboy <sdeboy@apache.org>
* @author Stephen Pain
- *
*/
class ChainsawCyclicBufferTableModel extends AbstractTableModel
- implements EventContainer, PropertyChangeListener {
-
- private static final int DEFAULT_CAPACITY = 5000;
- //cyclic field used internally in this class, but not exposed via the eventcontainer
- private boolean cyclic = true;
- private int cyclicBufferSize;
- //original list of LoggingEventWrapper instances
- List unfilteredList;
- //filtered list of LoggingEventWrapper instances
- List filteredList;
- private boolean currentSortAscending;
- private int currentSortColumn;
- private final EventListenerList eventListenerList = new EventListenerList();
- private final List<String> columnNames = new ArrayList<>(ChainsawColumns.getColumnsNames());
- private boolean sortEnabled = false;
- private boolean reachedCapacity = false;
- private final Logger logger = LogManager.getLogger(ChainsawCyclicBufferTableModel.class);
-
- // protected final Object syncLock = new Object();
- private final LoggerNameModel loggerNameModelDelegate = new LoggerNameModelSupport();
- private final Object mutex = new Object();
-
- //because we may be using a cyclic buffer, if an ID is not provided in the property,
- //use and increment this row counter as the ID for each received row
- int uniqueRow;
- private final Set uniquePropertyKeys = new HashSet();
- private Rule ruleMediator;
- private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
- private RuleColorizer colorizer;
- private final String tableModelName;
-
- public ChainsawCyclicBufferTableModel(int cyclicBufferSize, RuleColorizer colorizer, String tableModelName) {
- propertySupport.addPropertyChangeListener("cyclic", new ModelChanger());
- this.cyclicBufferSize = cyclicBufferSize;
- this.colorizer = colorizer;
- this.tableModelName = tableModelName;
-
- unfilteredList = new CyclicBufferList(cyclicBufferSize);
- filteredList = new CyclicBufferList(cyclicBufferSize);
- }
-
- /* (non-Javadoc)
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent evt) {
- if (evt.getSource() instanceof Rule) {
- if (evt.getSource() == ruleMediator && evt.getPropertyName().equals("findRule")) {
- if (((RuleMediator) evt.getSource()).isFindRuleRequired()) {
- //only refilter if find rule is required
- reFilter();
- }
- } else {
- reFilter();
- }
+ implements EventContainer, PropertyChangeListener {
+
+ private static final int DEFAULT_CAPACITY = 5000;
+ //cyclic field used internally in this class, but not exposed via the eventcontainer
+ private boolean cyclic = true;
+ private int cyclicBufferSize;
+ //original list of LoggingEventWrapper instances
+ List unfilteredList;
+ //filtered list of LoggingEventWrapper instances
+ List filteredList;
+ private boolean currentSortAscending;
+ private int currentSortColumn;
+ private final EventListenerList eventListenerList = new EventListenerList();
+ private final List<String> columnNames = new ArrayList<>(ChainsawColumns.getColumnsNames());
+ private boolean sortEnabled = false;
+ private boolean reachedCapacity = false;
+ private final Logger logger = LogManager.getLogger(ChainsawCyclicBufferTableModel.class);
+
+ // protected final Object syncLock = new Object();
+ private final LoggerNameModel loggerNameModelDelegate = new LoggerNameModelSupport();
+ private final Object mutex = new Object();
+
+ //because we may be using a cyclic buffer, if an ID is not provided in the property,
+ //use and increment this row counter as the ID for each received row
+ int uniqueRow;
+ private final Set uniquePropertyKeys = new HashSet();
+ private Rule ruleMediator;
+ private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
+ private RuleColorizer colorizer;
+ private final String tableModelName;
+
+ public ChainsawCyclicBufferTableModel(int cyclicBufferSize, RuleColorizer colorizer, String tableModelName) {
+ propertySupport.addPropertyChangeListener("cyclic", new ModelChanger());
+ this.cyclicBufferSize = cyclicBufferSize;
+ this.colorizer = colorizer;
+ this.tableModelName = tableModelName;
+
+ unfilteredList = new CyclicBufferList(cyclicBufferSize);
+ filteredList = new CyclicBufferList(cyclicBufferSize);
}
- }
- public List<LoggingEventWrapper> getMatchingEvents(Rule rule) {
- List<LoggingEventWrapper> list = new ArrayList<>();
- List unfilteredCopy;
- synchronized (mutex) {
- unfilteredCopy = new ArrayList(unfilteredList);
+ /* (non-Javadoc)
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (evt.getSource() instanceof Rule) {
+ if (evt.getSource() == ruleMediator && evt.getPropertyName().equals("findRule")) {
+ if (((RuleMediator) evt.getSource()).isFindRuleRequired()) {
+ //only refilter if find rule is required
+ reFilter();
+ }
+ } else {
+ reFilter();
+ }
+ }
}
- for (Object anUnfilteredCopy : unfilteredCopy) {
- LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) anUnfilteredCopy;
+ public List<LoggingEventWrapper> getMatchingEvents(Rule rule) {
+ List<LoggingEventWrapper> list = new ArrayList<>();
+ List unfilteredCopy;
+ synchronized (mutex) {
+ unfilteredCopy = new ArrayList(unfilteredList);
+ }
- if (rule.evaluate(loggingEventWrapper.getLoggingEvent(), null)) {
- list.add(loggingEventWrapper);
- }
- }
+ for (Object anUnfilteredCopy : unfilteredCopy) {
+ LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) anUnfilteredCopy;
+
+ if (rule.evaluate(loggingEventWrapper.getLoggingEvent(), null)) {
+ list.add(loggingEventWrapper);
+ }
+ }
- return list;
- }
+ return list;
+ }
- public void reFilter() {
- final int previousSize;
- final int newSize;
- synchronized (mutex) {
+ public void reFilter() {
+ final int previousSize;
+ final int newSize;
+ synchronized (mutex) {
//post refilter with newValue of TRUE (filtering is about to begin)
propertySupport.firePropertyChange("refilter", Boolean.FALSE, Boolean.TRUE);
previousSize = filteredList.size();
@@ -155,251 +145,251 @@ class ChainsawCyclicBufferTableModel extends AbstractTableModel
Iterator iter = unfilteredList.iterator();
LoggingEventWrapper lastEvent = null;
while (iter.hasNext()) {
- LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) iter.next();
-
- if (ruleMediator.evaluate(loggingEventWrapper.getLoggingEvent(), null)) {
- loggingEventWrapper.setDisplayed(true);
- filteredList.add(loggingEventWrapper);
- updateEventMillisDelta(loggingEventWrapper, lastEvent);
- lastEvent = loggingEventWrapper;
- } else {
- loggingEventWrapper.setDisplayed(false);
- }
+ LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) iter.next();
+
+ if (ruleMediator.evaluate(loggingEventWrapper.getLoggingEvent(), null)) {
+ loggingEventWrapper.setDisplayed(true);
+ filteredList.add(loggingEventWrapper);
+ updateEventMillisDelta(loggingEventWrapper, lastEvent);
+ lastEvent = loggingEventWrapper;
+ } else {
+ loggingEventWrapper.setDisplayed(false);
+ }
}
}
newSize = filteredList.size();
- }
- SwingHelper.invokeOnEDT(() -> {
- if (newSize > 0) {
- if (previousSize == newSize) {
- //same - update all
- fireTableRowsUpdated(0, newSize - 1);
- } else if (previousSize > newSize) {
- //less now..update and delete difference
- fireTableRowsUpdated(0, newSize - 1);
+ }
+ SwingHelper.invokeOnEDT(() -> {
+ if (newSize > 0) {
+ if (previousSize == newSize) {
+ //same - update all
+ fireTableRowsUpdated(0, newSize - 1);
+ } else if (previousSize > newSize) {
+ //less now..update and delete difference
+ fireTableRowsUpdated(0, newSize - 1);
//swing bug exposed by variable height rows when calling fireTableRowsDeleted..use tabledatacchanged
-fireTableDataChanged();
- } else if (previousSize < newSize) {
- //more now..update and insert difference
-if (previousSize > 0) {
- fireTableRowsUpdated(0, previousSize - 1);
-}
- fireTableRowsInserted(Math.max(0, previousSize), newSize - 1);
- }
- } else {
- //no rows to show
- fireTableDataChanged();
- }
- notifyCountListeners();
+ fireTableDataChanged();
+ } else if (previousSize < newSize) {
+ //more now..update and insert difference
+ if (previousSize > 0) {
+ fireTableRowsUpdated(0, previousSize - 1);
+ }
+ fireTableRowsInserted(Math.max(0, previousSize), newSize - 1);
+ }
+ } else {
+ //no rows to show
+ fireTableDataChanged();
+ }
+ notifyCountListeners();
//post refilter with newValue of FALSE (filtering is complete)
-SwingHelper.invokeOnEDT(() -> propertySupport.firePropertyChange("refilter", Boolean.TRUE, Boolean.FALSE));
- });
- }
-
- public int locate(Rule rule, int startLocation, boolean searchForward) {
- List filteredListCopy;
- synchronized (mutex) {
- filteredListCopy = new ArrayList(filteredList);
- }
- if (searchForward) {
- for (int i = startLocation; i < filteredListCopy.size(); i++) {
- if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
- return i;
- }
- }
- //if there was no match, start at row zero and go to startLocation
- for (int i = 0; i < startLocation; i++) {
- if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
- return i;
- }
- }
- } else {
- for (int i = startLocation; i > -1; i--) {
- if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
- return i;
- }
- }
- //if there was no match, start at row list.size() - 1 and go to startLocation
- for (int i = filteredListCopy.size() - 1; i > startLocation; i--) {
- if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
- return i;
- }
- }
- }
-
- return -1;
- }
-
- /**
- * @param l
- */
- public void removeLoggerNameListener(LoggerNameListener l) {
- loggerNameModelDelegate.removeLoggerNameListener(l);
- }
-
- /**
- * @param loggerName
- * @return
- */
- public boolean addLoggerName(String loggerName) {
- return loggerNameModelDelegate.addLoggerName(loggerName);
- }
-
- public String toString() {
- return "ChainsawCyclicBufferTableModel{" +
- "name='" + tableModelName + '\'' +
- '}';
- }
-
- public void reset() {
- loggerNameModelDelegate.reset();
- }
-
- /**
- * @param l
- */
- public void addLoggerNameListener(LoggerNameListener l) {
- loggerNameModelDelegate.addLoggerNameListener(l);
- }
-
- /**
- * @return
- */
- public Collection getLoggerNames() {
- return loggerNameModelDelegate.getLoggerNames();
- }
-
- public void addEventCountListener(EventCountListener listener) {
- eventListenerList.add(EventCountListener.class, listener);
- }
-
- public boolean isSortable(int col) {
- return true;
- }
-
- public void notifyCountListeners() {
- EventCountListener[] listeners = eventListenerList.getListeners(EventCountListener.class);
-
- int filteredListSize;
- int unfilteredListSize;
- synchronized (mutex) {
- filteredListSize = filteredList.size();
- unfilteredListSize = unfilteredList.size();
- }
- for (EventCountListener listener : listeners) {
- listener.eventCountChanged(
- filteredListSize, unfilteredListSize);
- }
- }
-
- /**
- * Changes the underlying display rule in use. If there was
- * a previous Rule defined, this Model removes itself as a listener
- * from the old rule, and adds itself to the new rule (if the new Rule is not Null).
- *
- * In any case, the model ensures the Filtered list is made up to date in a separate thread.
- */
- public void setRuleMediator(RuleMediator ruleMediator) {
- if (this.ruleMediator != null) {
- this.ruleMediator.removePropertyChangeListener(this);
- }
-
- this.ruleMediator = ruleMediator;
-
- if (this.ruleMediator != null) {
- this.ruleMediator.addPropertyChangeListener(this);
- }
- reFilter();
- }
-
- /* (non-Javadoc)
+ SwingHelper.invokeOnEDT(() -> propertySupport.firePropertyChange("refilter", Boolean.TRUE, Boolean.FALSE));
+ });
+ }
+
+ public int locate(Rule rule, int startLocation, boolean searchForward) {
+ List filteredListCopy;
+ synchronized (mutex) {
+ filteredListCopy = new ArrayList(filteredList);
+ }
+ if (searchForward) {
+ for (int i = startLocation; i < filteredListCopy.size(); i++) {
+ if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
+ return i;
+ }
+ }
+ //if there was no match, start at row zero and go to startLocation
+ for (int i = 0; i < startLocation; i++) {
+ if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
+ return i;
+ }
+ }
+ } else {
+ for (int i = startLocation; i > -1; i--) {
+ if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
+ return i;
+ }
+ }
+ //if there was no match, start at row list.size() - 1 and go to startLocation
+ for (int i = filteredListCopy.size() - 1; i > startLocation; i--) {
+ if (rule.evaluate(((LoggingEventWrapper) filteredListCopy.get(i)).getLoggingEvent(), null)) {
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * @param l
+ */
+ public void removeLoggerNameListener(LoggerNameListener l) {
+ loggerNameModelDelegate.removeLoggerNameListener(l);
+ }
+
+ /**
+ * @param loggerName
+ * @return
+ */
+ public boolean addLoggerName(String loggerName) {
+ return loggerNameModelDelegate.addLoggerName(loggerName);
+ }
+
+ public String toString() {
+ return "ChainsawCyclicBufferTableModel{" +
+ "name='" + tableModelName + '\'' +
+ '}';
+ }
+
+ public void reset() {
+ loggerNameModelDelegate.reset();
+ }
+
+ /**
+ * @param l
+ */
+ public void addLoggerNameListener(LoggerNameListener l) {
+ loggerNameModelDelegate.addLoggerNameListener(l);
+ }
+
+ /**
+ * @return
+ */
+ public Collection getLoggerNames() {
+ return loggerNameModelDelegate.getLoggerNames();
+ }
+
+ public void addEventCountListener(EventCountListener listener) {
+ eventListenerList.add(EventCountListener.class, listener);
+ }
+
+ public boolean isSortable(int col) {
+ return true;
+ }
+
+ public void notifyCountListeners() {
+ EventCountListener[] listeners = eventListenerList.getListeners(EventCountListener.class);
+
+ int filteredListSize;
+ int unfilteredListSize;
+ synchronized (mutex) {
+ filteredListSize = filteredList.size();
+ unfilteredListSize = unfilteredList.size();
+ }
+ for (EventCountListener listener : listeners) {
+ listener.eventCountChanged(
+ filteredListSize, unfilteredListSize);
+ }
+ }
+
+ /**
+ * Changes the underlying display rule in use. If there was
+ * a previous Rule defined, this Model removes itself as a listener
+ * from the old rule, and adds itself to the new rule (if the new Rule is not Null).
+ * <p>
+ * In any case, the model ensures the Filtered list is made up to date in a separate thread.
+ */
+ public void setRuleMediator(RuleMediator ruleMediator) {
+ if (this.ruleMediator != null) {
+ this.ruleMediator.removePropertyChangeListener(this);
+ }
+
+ this.ruleMediator = ruleMediator;
+
+ if (this.ruleMediator != null) {
+ this.ruleMediator.addPropertyChangeListener(this);
+ }
+ reFilter();
+ }
+
+ /* (non-Javadoc)
* @see org.apache.log4j.chainsaw.EventContainer#sort()
*/
- public void sort() {
- boolean sort;
- final int filteredListSize;
- synchronized (mutex) {
- filteredListSize = filteredList.size();
- sort = (sortEnabled && filteredListSize > 0);
- if (sort) {
- //reset display (used to ensure row height is updated)
- LoggingEventWrapper lastEvent = null;
- for (Object aFilteredList : filteredList) {
- LoggingEventWrapper e = (LoggingEventWrapper) aFilteredList;
- e.setDisplayed(true);
- updateEventMillisDelta(e, lastEvent);
- lastEvent = e;
- }
- filteredList.sort(new ColumnComparator(
+ public void sort() {
+ boolean sort;
+ final int filteredListSize;
+ synchronized (mutex) {
+ filteredListSize = filteredList.size();
+ sort = (sortEnabled && filteredListSize > 0);
+ if (sort) {
+ //reset display (used to ensure row height is updated)
+ LoggingEventWrapper lastEvent = null;
+ for (Object aFilteredList : filteredList) {
+ LoggingEventWrapper e = (LoggingEventWrapper) aFilteredList;
+ e.setDisplayed(true);
+ updateEventMillisDelta(e, lastEvent);
+ lastEvent = e;
+ }
+ filteredList.sort(new ColumnComparator(
getColumnName(currentSortColumn), currentSortColumn,
currentSortAscending));
+ }
+ }
+ if (sort) {
+ SwingHelper.invokeOnEDT(() -> fireTableRowsUpdated(0, Math.max(filteredListSize - 1, 0)));
}
- }
- if (sort) {
- SwingHelper.invokeOnEDT(() -> fireTableRowsUpdated(0, Math.max(filteredListSize - 1, 0)));
- }
- }
-
- public boolean isSortEnabled() {
- return sortEnabled;
- }
-
- public void sortColumn(int col, boolean ascending) {
- logger.debug("request to sort col=" + col);
- currentSortAscending = ascending;
- currentSortColumn = col;
- sortEnabled = true;
- sort();
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#clear()
- */
- public void clearModel() {
- reachedCapacity = false;
-
- synchronized (mutex) {
- unfilteredList.clear();
- filteredList.clear();
- uniqueRow = 0;
- }
-
- SwingHelper.invokeOnEDT(this::fireTableDataChanged);
-
- notifyCountListeners();
- loggerNameModelDelegate.reset();
- }
-
- public List getAllEvents() {
- synchronized (mutex) {
- return new ArrayList(unfilteredList);
- }
- }
-
-
- public List getFilteredEvents() {
-
- synchronized (mutex) {
- return new ArrayList(filteredList);
- }
- }
-
- public int getRowIndex(LoggingEventWrapper loggingEventWrapper) {
- synchronized (mutex) {
- return filteredList.indexOf(loggingEventWrapper);
- }
- }
+ }
+
+ public boolean isSortEnabled() {
+ return sortEnabled;
+ }
+
+ public void sortColumn(int col, boolean ascending) {
+ logger.debug("request to sort col=" + col);
+ currentSortAscending = ascending;
+ currentSortColumn = col;
+ sortEnabled = true;
+ sort();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.log4j.chainsaw.EventContainer#clear()
+ */
+ public void clearModel() {
+ reachedCapacity = false;
+
+ synchronized (mutex) {
+ unfilteredList.clear();
+ filteredList.clear();
+ uniqueRow = 0;
+ }
+
+ SwingHelper.invokeOnEDT(this::fireTableDataChanged);
+
+ notifyCountListeners();
+ loggerNameModelDelegate.reset();
+ }
+
+ public List getAllEvents() {
+ synchronized (mutex) {
+ return new ArrayList(unfilteredList);
+ }
+ }
+
+
+ public List getFilteredEvents() {
+
+ synchronized (mutex) {
+ return new ArrayList(filteredList);
+ }
+ }
+
+ public int getRowIndex(LoggingEventWrapper loggingEventWrapper) {
+ synchronized (mutex) {
+ return filteredList.indexOf(loggingEventWrapper);
+ }
+ }
public void removePropertyFromEvents(String propName) {
//first remove the event from any displayed events, so we can fire row updated event
List filteredListCopy;
List unfilteredListCopy;
- synchronized(mutex) {
+ synchronized (mutex) {
filteredListCopy = new ArrayList(filteredList);
unfilteredListCopy = new ArrayList(unfilteredList);
}
- for (int i=0;i<filteredListCopy.size();i++) {
- LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper)filteredListCopy.get(i);
+ for (int i = 0; i < filteredListCopy.size(); i++) {
+ LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) filteredListCopy.get(i);
Object result = loggingEventWrapper.removeProperty(propName);
if (result != null) {
fireRowUpdated(i, false);
@@ -415,7 +405,7 @@ SwingHelper.invokeOnEDT(() -> propertySupport.firePropertyChange("refilter", Boo
public int updateEventsWithFindRule(Rule findRule) {
int count = 0;
List unfilteredListCopy;
- synchronized(mutex) {
+ synchronized (mutex) {
unfilteredListCopy = new ArrayList(unfilteredList);
}
for (Object anUnfilteredListCopy : unfilteredListCopy) {
@@ -435,289 +425,287 @@ SwingHelper.invokeOnEDT(() -> propertySupport.firePropertyChange("refilter", Boo
filteredListCopy = new ArrayList(filteredList);
}
if (searchForward) {
- for (int i = startLocation; i < filteredListCopy.size(); i++) {
- LoggingEventWrapper event = (LoggingEventWrapper)filteredListCopy.get(i);
- if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
+ for (int i = startLocation; i < filteredListCopy.size(); i++) {
+ LoggingEventWrapper event = (LoggingEventWrapper) filteredListCopy.get(i);
+ if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
!event.getColorRuleForeground().equals(ChainsawConstants.COLOR_DEFAULT_FOREGROUND)) {
- return i;
+ return i;
+ }
}
- }
- //searching forward, no colorized event was found - now start at row zero and go to startLocation
- for (int i = 0; i < startLocation; i++) {
- LoggingEventWrapper event = (LoggingEventWrapper)filteredListCopy.get(i);
- if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
+ //searching forward, no colorized event was found - now start at row zero and go to startLocation
+ for (int i = 0; i < startLocation; i++) {
+ LoggingEventWrapper event = (LoggingEventWrapper) filteredListCopy.get(i);
+ if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
!event.getColorRuleForeground().equals(ChainsawConstants.COLOR_DEFAULT_FOREGROUND)) {
- return i;
+ return i;
+ }
}
- }
} else {
- for (int i = startLocation; i > -1; i--) {
- LoggingEventWrapper event = (LoggingEventWrapper)filteredListCopy.get(i);
- if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
- !event.getColorRuleForeground().equals(ChainsawConstants.COLOR_DEFAULT_FOREGROUND)) {
- return i;
+ for (int i = startLocation; i > -1; i--) {
+ LoggingEventWrapper event = (LoggingEventWrapper) filteredListCopy.get(i);
+ if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
+ !event.getColorRuleForeground().equals(ChainsawConstants.COLOR_DEFAULT_FOREGROUND)) {
+ return i;
+ }
}
- }
- //searching backward, no colorized event was found - now start at list.size() - 1 and go to startLocation
- for (int i = filteredListCopy.size() - 1; i > startLocation; i--) {
- LoggingEventWrapper event = (LoggingEventWrapper)filteredListCopy.get(i);
- if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
- !event.getColorRuleForeground().equals(ChainsawConstants.COLOR_DEFAULT_FOREGROUND)) {
- return i;
+ //searching backward, no colorized event was found - now start at list.size() - 1 and go to startLocation
+ for (int i = filteredListCopy.size() - 1; i > startLocation; i--) {
+ LoggingEventWrapper event = (LoggingEventWrapper) filteredListCopy.get(i);
+ if (!event.getColorRuleBackground().equals(ChainsawConstants.COLOR_DEFAULT_BACKGROUND) ||
+ !event.getColorRuleForeground().equals(ChainsawConstants.COLOR_DEFAULT_FOREGROUND)) {
+ return i;
+ }
}
- }
}
- return -1;
+ return -1;
}
- public int getSearchMatchCount() {
- int searchMatchCount = 0;
- synchronized(mutex) {
- for (Object aFilteredList : filteredList) {
- LoggingEventWrapper wrapper = (LoggingEventWrapper) aFilteredList;
- if (wrapper.isSearchMatch() && wrapper.isDisplayed()) {
- searchMatchCount++;
+ public int getSearchMatchCount() {
+ int searchMatchCount = 0;
+ synchronized (mutex) {
+ for (Object aFilteredList : filteredList) {
+ LoggingEventWrapper wrapper = (LoggingEventWrapper) aFilteredList;
+ if (wrapper.isSearchMatch() && wrapper.isDisplayed()) {
+ searchMatchCount++;
+ }
}
}
+ return searchMatchCount;
}
- return searchMatchCount;
- }
- public int getColumnCount() {
- return columnNames.size();
- }
-
- public String getColumnName(int column) {
- return columnNames.get(column);
- }
-
- public LoggingEventWrapper getRow(int row) {
- synchronized (mutex) {
- if (row < filteredList.size() && row > -1) {
- return (LoggingEventWrapper) filteredList.get(row);
- }
+ public int getColumnCount() {
+ return columnNames.size();
}
- return null;
- }
-
- public int getRowCount() {
- synchronized (mutex) {
- return filteredList.size();
+ public String getColumnName(int column) {
+ return columnNames.get(column);
}
- }
- public Object getValueAt(int rowIndex, int columnIndex) {
- LoggingEvent event = null;
+ public LoggingEventWrapper getRow(int row) {
+ synchronized (mutex) {
+ if (row < filteredList.size() && row > -1) {
+ return (LoggingEventWrapper) filteredList.get(row);
+ }
+ }
- synchronized (mutex) {
- if (rowIndex < filteredList.size() && rowIndex > -1) {
- event = ((LoggingEventWrapper) filteredList.get(rowIndex)).getLoggingEvent();
- }
+ return null;
}
- if (event == null) {
- return null;
+ public int getRowCount() {
+ synchronized (mutex) {
+ return filteredList.size();
+ }
}
- LocationInfo info = null;
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ LoggingEvent event = null;
- if (event.locationInformationExists()) {
- info = event.getLocationInformation();
- }
+ synchronized (mutex) {
+ if (rowIndex < filteredList.size() && rowIndex > -1) {
+ event = ((LoggingEventWrapper) filteredList.get(rowIndex)).getLoggingEvent();
+ }
+ }
+
+ if (event == null) {
+ return null;
+ }
+
+ LocationInfo info = null;
+
+ if (event.locationInformationExists()) {
+ info = event.getLocationInformation();
+ }
- switch (columnIndex + 1) {
- case ChainsawColumns.INDEX_ID_COL_NAME:
+ switch (columnIndex + 1) {
+ case ChainsawColumns.INDEX_ID_COL_NAME:
- Object id = event.getProperty(Constants.LOG4J_ID_KEY);
+ Object id = event.getProperty(Constants.LOG4J_ID_KEY);
- if (id != null) {
- return id;
- }
+ if (id != null) {
+ return id;
+ }
- return rowIndex;
+ return rowIndex;
- case ChainsawColumns.INDEX_LEVEL_COL_NAME:
- return event.getLevel();
+ case ChainsawColumns.INDEX_LEVEL_COL_NAME:
+ return event.getLevel();
- case ChainsawColumns.INDEX_LOG4J_MARKER_COL_NAME:
- return event.getProperty(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE);
+ case ChainsawColumns.INDEX_LOG4J_MARKER_COL_NAME:
+ return event.getProperty(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE);
- case ChainsawColumns.INDEX_MILLIS_DELTA_COL_NAME:
- return event.getProperty(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE);
+ case ChainsawColumns.INDEX_MILLIS_DELTA_COL_NAME:
+ return event.getProperty(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE);
- case ChainsawColumns.INDEX_LOGGER_COL_NAME:
- return event.getLoggerName();
+ case ChainsawColumns.INDEX_LOGGER_COL_NAME:
+ return event.getLoggerName();
- case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME:
- return new Date(event.getTimeStamp());
+ case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME:
+ return new Date(event.getTimeStamp());
- case ChainsawColumns.INDEX_MESSAGE_COL_NAME:
- return event.getRenderedMessage();
+ case ChainsawColumns.INDEX_MESSAGE_COL_NAME:
+ return event.getRenderedMessage();
- case ChainsawColumns.INDEX_NDC_COL_NAME:
- return event.getNDC();
+ case ChainsawColumns.INDEX_NDC_COL_NAME:
+ return event.getNDC();
- case ChainsawColumns.INDEX_THREAD_COL_NAME:
- return event.getThreadName();
+ case ChainsawColumns.INDEX_THREAD_COL_NAME:
+ return event.getThreadName();
- case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
- return event.getThrowableStrRep();
+ case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
+ return event.getThrowableStrRep();
- case ChainsawColumns.INDEX_CLASS_COL_NAME:
- return ((info == null) || ("?".equals(info.getClassName()))) ? "" : info.getClassName();
+ case ChainsawColumns.INDEX_CLASS_COL_NAME:
+ return ((info == null) || ("?".equals(info.getClassName()))) ? "" : info.getClassName();
- case ChainsawColumns.INDEX_FILE_COL_NAME:
- return ((info == null) || ("?".equals(info.getFileName()))) ? "" : info.getFileName();
+ case ChainsawColumns.INDEX_FILE_COL_NAME:
+ return ((info == null) || ("?".equals(info.getFileName()))) ? "" : info.getFileName();
- case ChainsawColumns.INDEX_LINE_COL_NAME:
- return ((info == null) || ("?".equals(info.getLineNumber()))) ? "" : info.getLineNumber();
+ case ChainsawColumns.INDEX_LINE_COL_NAME:
+ return ((info == null) || ("?".equals(info.getLineNumber()))) ? "" : info.getLineNumber();
- case ChainsawColumns.INDEX_METHOD_COL_NAME:
- return ((info == null) || ("?".equals(info.getMethodName()))) ? "" : info.getMethodName();
+ case ChainsawColumns.INDEX_METHOD_COL_NAME:
+ return ((info == null) || ("?".equals(info.getMethodName()))) ? "" : info.getMethodName();
- default:
+ default:
- if (columnIndex < columnNames.size()) {
- //case may not match..try case sensitive and fall back to case-insensitive
- String result = event.getProperty(columnNames.get(columnIndex).toString());
- if (result == null) {
- String lowerColName = columnNames.get(columnIndex).toString().toLowerCase(Locale.ENGLISH);
- Set<Map.Entry> entrySet = event.getProperties().entrySet();
- for (Object anEntrySet : entrySet) {
- Map.Entry thisEntry = (Map.Entry) anEntrySet;
- if (thisEntry.getKey().toString().equalsIgnoreCase(lowerColName)) {
- result = thisEntry.getValue().toString();
+ if (columnIndex < columnNames.size()) {
+ //case may not match..try case sensitive and fall back to case-insensitive
+ String result = event.getProperty(columnNames.get(columnIndex).toString());
+ if (result == null) {
+ String lowerColName = columnNames.get(columnIndex).toString().toLowerCase(Locale.ENGLISH);
+ Set<Map.Entry> entrySet = event.getProperties().entrySet();
+ for (Object anEntrySet : entrySet) {
+ Map.Entry thisEntry = (Map.Entry) anEntrySet;
+ if (thisEntry.getKey().toString().equalsIgnoreCase(lowerColName)) {
+ result = thisEntry.getValue().toString();
+ }
+ }
+ }
+ if (result != null) {
+ return result;
+ }
}
- }
}
- if (result != null) {
- return result;
- }
- }
+ return "";
}
- return "";
- }
- public boolean isAddRow(LoggingEventWrapper loggingEventWrapper) {
- Object id = loggingEventWrapper.getLoggingEvent().getProperty(Constants.LOG4J_ID_KEY);
+ public boolean isAddRow(LoggingEventWrapper loggingEventWrapper) {
+ Object id = loggingEventWrapper.getLoggingEvent().getProperty(Constants.LOG4J_ID_KEY);
- //only set the property if it doesn't already exist
- if (id == null) {
- id = ++uniqueRow;
- loggingEventWrapper.setProperty(Constants.LOG4J_ID_KEY, id.toString());
- }
+ //only set the property if it doesn't already exist
+ if (id == null) {
+ id = ++uniqueRow;
+ loggingEventWrapper.setProperty(Constants.LOG4J_ID_KEY, id.toString());
+ }
- loggingEventWrapper.updateColorRuleColors(colorizer.getBackgroundColor(loggingEventWrapper.getLoggingEvent()), colorizer.getForegroundColor(loggingEventWrapper.getLoggingEvent()));
- Rule findRule = colorizer.getFindRule();
- if (findRule != null) {
- loggingEventWrapper.evaluateSearchRule(colorizer.getFindRule());
- }
+ loggingEventWrapper.updateColorRuleColors(colorizer.getBackgroundColor(loggingEventWrapper.getLoggingEvent()), colorizer.getForegroundColor(loggingEventWrapper.getLoggingEvent()));
+ Rule findRule = colorizer.getFindRule();
+ if (findRule != null) {
+ loggingEventWrapper.evaluateSearchRule(colorizer.getFindRule());
+ }
- boolean rowAdded = false;
+ boolean rowAdded = false;
- /**
+ /**
* If we're in cyclic mode and over budget on the size, the addition of a new event will
* cause the oldest event to fall off the cliff. We need to remove that events ID from the
* Set so we are not keeping track of IDs for all events ever received (we'd run out of
* memory...)
*/
- synchronized(mutex) {
- if (cyclic) {
- CyclicBufferList bufferList = (CyclicBufferList) unfilteredList;
- if (bufferList.size() == bufferList.getMaxSize()) {
- reachedCapacity = true;
+ synchronized (mutex) {
+ if (cyclic) {
+ CyclicBufferList bufferList = (CyclicBufferList) unfilteredList;
+ if (bufferList.size() == bufferList.getMaxSize()) {
+ reachedCapacity = true;
+ }
+ }
+ int unfilteredSize = unfilteredList.size();
+ LoggingEventWrapper lastLoggingEventWrapper = null;
+ if (unfilteredSize > 0) {
+ lastLoggingEventWrapper = (LoggingEventWrapper) unfilteredList.get(unfilteredSize - 1);
+ }
+ unfilteredList.add(loggingEventWrapper);
+ if ((ruleMediator == null) || (ruleMediator.evaluate(loggingEventWrapper.getLoggingEvent(), null))) {
+ loggingEventWrapper.setDisplayed(true);
+ updateEventMillisDelta(loggingEventWrapper, lastLoggingEventWrapper);
+ filteredList.add(loggingEventWrapper);
+ rowAdded = true;
+ } else {
+ loggingEventWrapper.setDisplayed(false);
}
}
- int unfilteredSize = unfilteredList.size();
- LoggingEventWrapper lastLoggingEventWrapper = null;
- if (unfilteredSize > 0) {
- lastLoggingEventWrapper = (LoggingEventWrapper) unfilteredList.get(unfilteredSize - 1);
- }
- unfilteredList.add(loggingEventWrapper);
- if ((ruleMediator == null) || (ruleMediator.evaluate(loggingEventWrapper.getLoggingEvent(), null))) {
- loggingEventWrapper.setDisplayed(true);
- updateEventMillisDelta(loggingEventWrapper, lastLoggingEventWrapper);
- filteredList.add(loggingEventWrapper);
- rowAdded = true;
- } else {
- loggingEventWrapper.setDisplayed(false);
- }
- }
- checkForNewColumn(loggingEventWrapper);
+ checkForNewColumn(loggingEventWrapper);
- return rowAdded;
- }
+ return rowAdded;
+ }
private void updateEventMillisDelta(LoggingEventWrapper loggingEventWrapper, LoggingEventWrapper lastLoggingEventWrapper) {
- if (lastLoggingEventWrapper != null) {
- loggingEventWrapper.setPreviousDisplayedEventTimestamp(lastLoggingEventWrapper.getLoggingEvent().getTimeStamp());
- } else {
- //delta to same event = 0
- loggingEventWrapper.setPreviousDisplayedEventTimestamp(loggingEventWrapper.getLoggingEvent().getTimeStamp());
- }
- }
-
- private void checkForNewColumn(LoggingEventWrapper loggingEventWrapper)
- {
- /**
- * Is this a new Property key we haven't seen before? Remember that now MDC has been merged
- * into the Properties collection
- */
- boolean newColumn = uniquePropertyKeys.addAll(loggingEventWrapper.getPropertyKeySet());
-
- if (newColumn) {
+ if (lastLoggingEventWrapper != null) {
+ loggingEventWrapper.setPreviousDisplayedEventTimestamp(lastLoggingEventWrapper.getLoggingEvent().getTimeStamp());
+ } else {
+ //delta to same event = 0
+ loggingEventWrapper.setPreviousDisplayedEventTimestamp(loggingEventWrapper.getLoggingEvent().getTimeStamp());
+ }
+ }
+
+ private void checkForNewColumn(LoggingEventWrapper loggingEventWrapper) {
/**
- * If so, we should add them as columns and notify listeners.
+ * Is this a new Property key we haven't seen before? Remember that now MDC has been merged
+ * into the Properties collection
*/
- for (Object o : loggingEventWrapper.getPropertyKeySet()) {
- String key = o.toString().toUpperCase();
-
- //add all keys except the 'log4jid' key (columnNames is all-caps)
- if (!columnNames.contains(key) && !(Constants.LOG4J_ID_KEY.equalsIgnoreCase(key))) {
- columnNames.add(key);
- logger.debug("Adding col '" + key + "', columnNames=" + columnNames);
- fireNewKeyColumnAdded(
- new NewKeyEvent(
- this, columnNames.indexOf(key), key, loggingEventWrapper.getLoggingEvent().getProperty(key)));
- }
- }
- }
- }
-
- public void fireTableEvent(final int begin, final int end, final int count) {
- SwingHelper.invokeOnEDT(() -> {
-if (cyclic) {
-if (!reachedCapacity) {
+ boolean newColumn = uniquePropertyKeys.addAll(loggingEventWrapper.getPropertyKeySet());
+
+ if (newColumn) {
+ /**
+ * If so, we should add them as columns and notify listeners.
+ */
+ for (Object o : loggingEventWrapper.getPropertyKeySet()) {
+ String key = o.toString().toUpperCase();
+
+ //add all keys except the 'log4jid' key (columnNames is all-caps)
+ if (!columnNames.contains(key) && !(Constants.LOG4J_ID_KEY.equalsIgnoreCase(key))) {
+ columnNames.add(key);
+ logger.debug("Adding col '" + key + "', columnNames=" + columnNames);
+ fireNewKeyColumnAdded(
+ new NewKeyEvent(
+ this, columnNames.indexOf(key), key, loggingEventWrapper.getLoggingEvent().getProperty(key)));
+ }
+ }
+ }
+ }
+
+ public void fireTableEvent(final int begin, final int end, final int count) {
+ SwingHelper.invokeOnEDT(() -> {
+ if (cyclic) {
+ if (!reachedCapacity) {
//if we didn't loop and it's the 1st time, insert
-if ((begin + count) < cyclicBufferSize) {
-fireTableRowsInserted(begin, end);
-} else {
+ if ((begin + count) < cyclicBufferSize) {
+ fireTableRowsInserted(begin, end);
+ } else {
//we did loop - insert and then update rows
//rows are zero-indexed, subtract 1 from cyclicbuffersize for the event notification
-fireTableRowsInserted(begin, cyclicBufferSize - 1);
-fireTableRowsUpdated(0, cyclicBufferSize - 1);
-reachedCapacity = true;
-}
-} else {
-fireTableRowsUpdated(0, cyclicBufferSize - 1);
-}
-} else {
-fireTableRowsInserted(begin, end);
-}
-});
- }
+ fireTableRowsInserted(begin, cyclicBufferSize - 1);
+ fireTableRowsUpdated(0, cyclicBufferSize - 1);
+ reachedCapacity = true;
+ }
+ } else {
+ fireTableRowsUpdated(0, cyclicBufferSize - 1);
+ }
+ } else {
+ fireTableRowsInserted(begin, end);
+ }
+ });
+ }
public void fireRowUpdated(int row, boolean checkForNewColumns) {
LoggingEventWrapper loggingEventWrapper = getRow(row);
- if (loggingEventWrapper != null)
- {
+ if (loggingEventWrapper != null) {
loggingEventWrapper.updateColorRuleColors(colorizer.getBackgroundColor(loggingEventWrapper.getLoggingEvent()), colorizer.getForegroundColor(loggingEventWrapper.getLoggingEvent()));
Rule findRule = colorizer.getFindRule();
if (findRule != null) {
- loggingEventWrapper.evaluateSearchRule(colorizer.getFindRule());
+ loggingEventWrapper.evaluateSearchRule(colorizer.getFindRule());
}
fireTableRowsUpdated(row, row);
@@ -729,146 +717,146 @@ fireTableRowsInserted(begin, end);
}
/**
- * @param e
- */
- private void fireNewKeyColumnAdded(NewKeyEvent e) {
- NewKeyListener[] listeners =
+ * @param e
+ */
+ private void fireNewKeyColumnAdded(NewKeyEvent e) {
+ NewKeyListener[] listeners =
eventListenerList.getListeners(NewKeyListener.class);
- for (NewKeyListener listener : listeners) {
- listener.newKeyAdded(e);
- }
- }
-
- /**
- * @return
- */
- public int getMaxSize() {
- return cyclicBufferSize;
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#addNewKeyListener(org.apache.log4j.chainsaw.NewKeyListener)
- */
- public void addNewKeyListener(NewKeyListener l) {
- eventListenerList.add(NewKeyListener.class, l);
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#removeNewKeyListener(org.apache.log4j.chainsaw.NewKeyListener)
- */
- public void removeNewKeyListener(NewKeyListener l) {
- eventListenerList.remove(NewKeyListener.class, l);
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#isCellEditable(int, int)
- */
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- if (getColumnName(columnIndex).equalsIgnoreCase(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE)) {
- return true;
- }
-
- return columnIndex < columnNames.size() && super.isCellEditable(rowIndex, columnIndex);
-
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#setCyclic(boolean)
- */
- public void setCyclic(final boolean cyclic) {
- if (this.cyclic == cyclic) {
- return;
- }
-
- final boolean old = this.cyclic;
- this.cyclic = cyclic;
- propertySupport.firePropertyChange("cyclic", old, cyclic);
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#addPropertyChangeListener(java.beans.PropertyChangeListener)
- */
- public void addPropertyChangeListener(PropertyChangeListener l) {
- propertySupport.addPropertyChangeListener(l);
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
- */
- public void addPropertyChangeListener(
- String propertyName, PropertyChangeListener l) {
- propertySupport.addPropertyChangeListener(propertyName, l);
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.chainsaw.EventContainer#size()
- */
- public int size() {
- synchronized(mutex) {
- return unfilteredList.size();
- }
- }
-
- private class ModelChanger implements PropertyChangeListener {
+ for (NewKeyListener listener : listeners) {
+ listener.newKeyAdded(e);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public int getMaxSize() {
+ return cyclicBufferSize;
+ }
+
/* (non-Javadoc)
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ * @see org.apache.log4j.chainsaw.EventContainer#addNewKeyListener(org.apache.log4j.chainsaw.NewKeyListener)
*/
- public void propertyChange(PropertyChangeEvent arg0) {
- Thread thread =
- new Thread(
- () -> {
- ProgressMonitor monitor = null;
-
- int index = 0;
-
- try {
- synchronized (mutex) {
- monitor =
- new ProgressMonitor(
- null, "Switching models...",
- "Transferring between data structures, please wait...", 0,
- unfilteredList.size() + 1);
- monitor.setMillisToDecideToPopup(250);
- monitor.setMillisToPopup(100);
- logger.debug(
- "Changing Model, isCyclic is now " + cyclic);
-
- List newUnfilteredList;
- List newFilteredList;
-
- if (cyclic) {
- newUnfilteredList = new CyclicBufferList(cyclicBufferSize);
- newFilteredList = new CyclicBufferList(cyclicBufferSize);
- } else {
- newUnfilteredList = new ArrayList(cyclicBufferSize);
- newFilteredList = new ArrayList(cyclicBufferSize);
- }
-
- int increment = 0;
-
- for (Object anUnfilteredList : unfilteredList) {
- LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) anUnfilteredList;
- newUnfilteredList.add(loggingEventWrapper);
- monitor.setProgress(index++);
- }
+ public void addNewKeyListener(NewKeyListener l) {
+ eventListenerList.add(NewKeyListener.class, l);
+ }
- unfilteredList = newUnfilteredList;
- filteredList = newFilteredList;
- }
+ /* (non-Javadoc)
+ * @see org.apache.log4j.chainsaw.EventContainer#removeNewKeyListener(org.apache.log4j.chainsaw.NewKeyListener)
+ */
+ public void removeNewKeyListener(NewKeyListener l) {
+ eventListenerList.remove(NewKeyListener.class, l);
+ }
- monitor.setNote("Refiltering...");
- reFilter();
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#isCellEditable(int, int)
+ */
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ if (getColumnName(columnIndex).equalsIgnoreCase(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE)) {
+ return true;
+ }
+
+ return columnIndex < columnNames.size() && super.isCellEditable(rowIndex, columnIndex);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.log4j.chainsaw.EventContainer#setCyclic(boolean)
+ */
+ public void setCyclic(final boolean cyclic) {
+ if (this.cyclic == cyclic) {
+ return;
+ }
+
+ final boolean old = this.cyclic;
+ this.cyclic = cyclic;
+ propertySupport.firePropertyChange("cyclic", old, cyclic);
+ }
- monitor.setProgress(index++);
- } finally {
- monitor.close();
- }
+ /* (non-Javadoc)
+ * @see org.apache.log4j.chainsaw.EventContainer#addPropertyChangeListener(java.beans.PropertyChangeListener)
+ */
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ propertySupport.addPropertyChangeListener(l);
+ }
- logger.debug("Model Change completed");
- });
- thread.setPriority(Thread.MIN_PRIORITY + 1);
- thread.start();
+ /* (non-Javadoc)
+ * @see org.apache.log4j.chainsaw.EventContainer#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+ */
+ public void addPropertyChangeListener(
+ String propertyName, PropertyChangeListener l) {
+ propertySupport.addPropertyChangeListener(propertyName, l);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.log4j.chainsaw.EventContainer#size()
+ */
+ public int size() {
+ synchronized (mutex) {
+ return unfilteredList.size();
+ }
+ }
+
+ private class ModelChanger implements PropertyChangeListener {
+ /* (non-Javadoc)
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent arg0) {
+ Thread thread =
+ new Thread(
+ () -> {
+ ProgressMonitor monitor = null;
+
+ int index = 0;
+
+ try {
+ synchronized (mutex) {
+ monitor =
+ new ProgressMonitor(
+ null, "Switching models...",
+ "Transferring between data structures, please wait...", 0,
+ unfilteredList.size() + 1);
+ monitor.setMillisToDecideToPopup(250);
+ monitor.setMillisToPopup(100);
+ logger.debug(
+ "Changing Model, isCyclic is now " + cyclic);
+
+ List newUnfilteredList;
+ List newFilteredList;
+
+ if (cyclic) {
+ newUnfilteredList = new CyclicBufferList(cyclicBufferSize);
+ newFilteredList = new CyclicBufferList(cyclicBufferSize);
+ } else {
+ newUnfilteredList = new ArrayList(cyclicBufferSize);
+ newFilteredList = new ArrayList(cyclicBufferSize);
+ }
+
+ int increment = 0;
+
+ for (Object anUnfilteredList : unfilteredList) {
+ LoggingEventWrapper loggingEventWrapper = (LoggingEventWrapper) anUnfilteredList;
+ newUnfilteredList.add(loggingEventWrapper);
+ monitor.setProgress(index++);
+ }
+
+ unfilteredList = newUnfilteredList;
+ filteredList = newFilteredList;
+ }
+
+ monitor.setNote("Refiltering...");
+ reFilter();
+
+ monitor.setProgress(index++);
+ } finally {
+ monitor.close();
+ }
+
+ logger.debug("Model Change completed");
+ });
+ thread.setPriority(Thread.MIN_PRIORITY + 1);
+ thread.start();
+ }
}
- }
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawEventBatch.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawEventBatch.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawEventBatch.java
index bf1a538..b71a1d1 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawEventBatch.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawEventBatch.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,61 +17,58 @@
package org.apache.log4j.chainsaw;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.apache.log4j.spi.LoggingEvent;
+import java.util.*;
+
/**
* A container class that contains a group of events split up
* into branches based on Identifiers
+ *
* @author Paul Smith <psmith@apache.org>
* @author Scott Deboy <sdeboy@apache.org>
- *
*/
class ChainsawEventBatch {
- private Map<String, List<LoggingEvent>> identEventMap = new HashMap<>();
+ private Map<String, List<LoggingEvent>> identEventMap = new HashMap<>();
- ChainsawEventBatch() {
- }
+ ChainsawEventBatch() {
+ }
- /**
- * @param ident
- * @param e
- */
- void addEvent(String ident, LoggingEvent e) {
- List<LoggingEvent> events = identEventMap.get(ident);
+ /**
+ * @param ident
+ * @param e
+ */
+ void addEvent(String ident, LoggingEvent e) {
+ List<LoggingEvent> events = identEventMap.get(ident);
- if (events == null) {
- events = new ArrayList<>();
- identEventMap.put(ident, events);
- }
+ if (events == null) {
+ events = new ArrayList<>();
+ identEventMap.put(ident, events);
+ }
- events.add(e);
- }
+ events.add(e);
+ }
- /**
- * Returns an iterator of Identifier strings that this payload contains.
- *
- * The values returned from this iterator can be used to query the
- *
- * @return Iterator
- */
- Iterator<String> identifierIterator() {
- return identEventMap.keySet().iterator();
- }
+ /**
+ * Returns an iterator of Identifier strings that this payload contains.
+ * <p>
+ * The values returned from this iterator can be used to query the
+ *
+ * @return Iterator
+ */
+ Iterator<String> identifierIterator() {
+ return identEventMap.keySet().iterator();
+ }
- /**
- * Returns a Collection of LoggingEvent objects that
- * are bound to the identifier
- * @param identifier
- * @return Collection of LoggingEvent instances
- */
- List<LoggingEvent> entrySet(String identifier) {
- return identEventMap.get(identifier);
- }
+ /**
+ * Returns a Collection of LoggingEvent objects that
+ * are bound to the identifier
+ *
+ * @param identifier
+ * @return Collection of LoggingEvent instances
+ */
+ List<LoggingEvent> entrySet(String identifier) {
+ return identEventMap.get(identifier);
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawSplash.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawSplash.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawSplash.java
index ee0e882..bf494a3 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawSplash.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawSplash.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,77 +18,67 @@
/*
* @author Paul Smith <psmith@apache.org>
*
-*/
+ */
package org.apache.log4j.chainsaw;
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.Font;
-import java.awt.Frame;
-import java.awt.GraphicsEnvironment;
+import org.apache.log4j.chainsaw.icons.ChainsawIcons;
+
+import javax.swing.*;
+import java.awt.*;
import java.util.HashSet;
import java.util.Set;
-import javax.swing.BorderFactory;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JWindow;
-import javax.swing.SwingConstants;
-
-import org.apache.log4j.chainsaw.icons.ChainsawIcons;
-
/**
* A simple splash screen to be used at startup, while everything get's initialized.
- * @author Paul Smith <psmith@apache.org>
*
+ * @author Paul Smith <psmith@apache.org>
*/
class ChainsawSplash extends JWindow {
- ChainsawSplash(Frame owner) {
- super(owner);
-
- Container container = getContentPane();
- JPanel panel = new JPanel(new BorderLayout());
- JLabel logo = new JLabel(ChainsawIcons.ICON_LOG4J);
-
- JLabel text = new JLabel("Chainsaw v2", SwingConstants.CENTER);
- Font textFont = null;
- String[] preferredFontNames =
- new String[] { "Arial", "Helvetica", "SansSerif" };
-
- Set<String> availableFontNames = new HashSet<>();
- Font[] allFonts =
- GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
-
- for (Font allFont : allFonts) {
- availableFontNames.add(allFont.getName());
- }
-
- for (String preferredFontName : preferredFontNames) {
- if (availableFontNames.contains(preferredFontName)) {
- textFont = new Font(preferredFontName, Font.PLAIN, 12);
-
- System.out.println("Using font=" + textFont.getName());
-
- break;
- }
- }
-
- if (textFont == null) {
- System.out.println("Using basic font");
- textFont = text.getFont();
+ ChainsawSplash(Frame owner) {
+ super(owner);
+
+ Container container = getContentPane();
+ JPanel panel = new JPanel(new BorderLayout());
+ JLabel logo = new JLabel(ChainsawIcons.ICON_LOG4J);
+
+ JLabel text = new JLabel("Chainsaw v2", SwingConstants.CENTER);
+ Font textFont = null;
+ String[] preferredFontNames =
+ new String[]{"Arial", "Helvetica", "SansSerif"};
+
+ Set<String> availableFontNames = new HashSet<>();
+ Font[] allFonts =
+ GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
+
+ for (Font allFont : allFonts) {
+ availableFontNames.add(allFont.getName());
+ }
+
+ for (String preferredFontName : preferredFontNames) {
+ if (availableFontNames.contains(preferredFontName)) {
+ textFont = new Font(preferredFontName, Font.PLAIN, 12);
+
+ System.out.println("Using font=" + textFont.getName());
+
+ break;
+ }
+ }
+
+ if (textFont == null) {
+ System.out.println("Using basic font");
+ textFont = text.getFont();
+ }
+
+ text.setFont(textFont.deriveFont(16f).deriveFont(Font.BOLD));
+ text.setBackground(Color.white);
+ text.setForeground(Color.black);
+ text.setBorder(BorderFactory.createLoweredBevelBorder());
+ panel.add(logo, BorderLayout.CENTER);
+ panel.add(text, BorderLayout.SOUTH);
+ panel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
+
+ container.add(panel);
+ pack();
}
-
- text.setFont(textFont.deriveFont(16f).deriveFont(Font.BOLD));
- text.setBackground(Color.white);
- text.setForeground(Color.black);
- text.setBorder(BorderFactory.createLoweredBevelBorder());
- panel.add(logo, BorderLayout.CENTER);
- panel.add(text, BorderLayout.SOUTH);
- panel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
-
- container.add(panel);
- pack();
- }
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java
index df536c4..4bc83d5 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawStatusBar.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,267 +17,256 @@
package org.apache.log4j.chainsaw;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.text.NumberFormat;
-
-import javax.swing.BorderFactory;
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.SwingConstants;
-import javax.swing.SwingUtilities;
-import javax.swing.border.Border;
-
import org.apache.log4j.chainsaw.icons.ChainsawIcons;
import org.apache.log4j.chainsaw.messages.MessageCenter;
+import javax.swing.*;
+import javax.swing.border.Border;
+import java.awt.*;
+import java.text.NumberFormat;
+
/**
* A general purpose status bar for all Frame windows
*
* @author Paul Smith <psmith@apache.org>
- *
*/
public class ChainsawStatusBar extends JPanel {
- private static final int DELAY_PERIOD = 5000;
- private static final String DEFAULT_MSG = "Welcome to Chainsaw v2!";
- private final JLabel statusMsg = new JLabel(DEFAULT_MSG);
- private final JLabel searchMatchLabel = new JLabel("", SwingConstants.CENTER);
- private final JLabel pausedLabel = new JLabel("", SwingConstants.CENTER);
- private final JLabel lineSelectionLabel = new JLabel("", SwingConstants.CENTER);
- private final JLabel eventCountLabel = new JLabel("", SwingConstants.CENTER);
- private final JLabel receivedEventLabel = new JLabel("", SwingConstants.CENTER);
- private final JLabel receivedConnectionlabel = new JLabel("", SwingConstants.CENTER);
- private volatile long lastReceivedConnection = System.currentTimeMillis();
- private final Thread connectionThread;
- private final Icon pausedIcon = new ImageIcon(ChainsawIcons.PAUSE);
- private final Icon netConnectIcon =
- new ImageIcon(ChainsawIcons.ANIM_NET_CONNECT);
- private final NumberFormat nf = NumberFormat.getNumberInstance();
- private final Border statusBarComponentBorder =
- BorderFactory.createLineBorder(statusMsg.getBackground().darker());
- private final LogUI logUI;
+ private static final int DELAY_PERIOD = 5000;
+ private static final String DEFAULT_MSG = "Welcome to Chainsaw v2!";
+ private final JLabel statusMsg = new JLabel(DEFAULT_MSG);
+ private final JLabel searchMatchLabel = new JLabel("", SwingConstants.CENTER);
+ private final JLabel pausedLabel = new JLabel("", SwingConstants.CENTER);
+ private final JLabel lineSelectionLabel = new JLabel("", SwingConstants.CENTER);
+ private final JLabel eventCountLabel = new JLabel("", SwingConstants.CENTER);
+ private final JLabel receivedEventLabel = new JLabel("", SwingConstants.CENTER);
+ private final JLabel receivedConnectionlabel = new JLabel("", SwingConstants.CENTER);
+ private volatile long lastReceivedConnection = System.currentTimeMillis();
+ private final Thread connectionThread;
+ private final Icon pausedIcon = new ImageIcon(ChainsawIcons.PAUSE);
+ private final Icon netConnectIcon =
+ new ImageIcon(ChainsawIcons.ANIM_NET_CONNECT);
+ private final NumberFormat nf = NumberFormat.getNumberInstance();
+ private final Border statusBarComponentBorder =
+ BorderFactory.createLineBorder(statusMsg.getBackground().darker());
+ private final LogUI logUI;
public ChainsawStatusBar(LogUI logUI) {
- setLayout(new GridBagLayout());
- this.logUI = logUI;
- nf.setMaximumFractionDigits(0);
- nf.setMinimumFractionDigits(0);
- nf.setGroupingUsed(false);
-
- JPanel statusMsgPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 2));
-
- statusMsgPanel.add(statusMsg);
- statusMsgPanel.setBorder(statusBarComponentBorder);
-
- pausedLabel.setBorder(statusBarComponentBorder);
- pausedLabel.setMinimumSize(
- new Dimension(pausedIcon.getIconWidth(), pausedIcon.getIconHeight()));
-
- pausedLabel.setToolTipText(
- "Shows whether the current Log panel is paused or not");
-
- receivedEventLabel.setBorder(statusBarComponentBorder);
- receivedEventLabel.setToolTipText(
- "Indicates whether Chainsaw is receiving events, and how fast it is processing them");
- receivedEventLabel.setMinimumSize(
- new Dimension(
- receivedEventLabel.getFontMetrics(receivedEventLabel.getFont())
- .stringWidth("99999999999.9/s") + 5,
- (int) receivedEventLabel.getPreferredSize().getHeight()));
-
- eventCountLabel.setBorder(statusBarComponentBorder);
- eventCountLabel.setToolTipText("<# viewable events>:<# total events>");
- eventCountLabel.setMinimumSize(
- new Dimension(
- eventCountLabel.getFontMetrics(eventCountLabel.getFont())
- .stringWidth("Filtered/Total: 999999999999:999999999999") + 5,
- (int) eventCountLabel.getPreferredSize().getHeight()));
-
- searchMatchLabel.setBorder(statusBarComponentBorder);
- searchMatchLabel.setToolTipText("<# viewable events>:<# total events>");
- searchMatchLabel.setMinimumSize(
- new Dimension(
- searchMatchLabel.getFontMetrics(eventCountLabel.getFont()).stringWidth("Find matches: 999999999999") + 5,
- (int) searchMatchLabel.getPreferredSize().getHeight()));
-
- receivedConnectionlabel.setBorder(statusBarComponentBorder);
- receivedConnectionlabel.setToolTipText(
- "Indicates whether Chainsaw has received a remote connection");
- receivedConnectionlabel.setMinimumSize(
- new Dimension(
- netConnectIcon.getIconWidth() + 4,
- (int) receivedConnectionlabel.getPreferredSize().getHeight()));
-
- lineSelectionLabel.setBorder(statusBarComponentBorder);
- lineSelectionLabel.setMinimumSize(
- new Dimension(
- lineSelectionLabel.getFontMetrics(lineSelectionLabel.getFont())
- .stringWidth("999999999"),
- (int) lineSelectionLabel.getPreferredSize().getHeight()));
- lineSelectionLabel.setToolTipText(
- "The current line # selected");
-
- JComponent[] toFix =
- new JComponent[] {
- searchMatchLabel, eventCountLabel,
- receivedConnectionlabel, lineSelectionLabel, receivedEventLabel,
- pausedLabel
- };
+ setLayout(new GridBagLayout());
+ this.logUI = logUI;
+ nf.setMaximumFractionDigits(0);
+ nf.setMinimumFractionDigits(0);
+ nf.setGroupingUsed(false);
+
+ JPanel statusMsgPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 2));
+
+ statusMsgPanel.add(statusMsg);
+ statusMsgPanel.setBorder(statusBarComponentBorder);
+
+ pausedLabel.setBorder(statusBarComponentBorder);
+ pausedLabel.setMinimumSize(
+ new Dimension(pausedIcon.getIconWidth(), pausedIcon.getIconHeight()));
+
+ pausedLabel.setToolTipText(
+ "Shows whether the current Log panel is paused or not");
+
+ receivedEventLabel.setBorder(statusBarComponentBorder);
+ receivedEventLabel.setToolTipText(
+ "Indicates whether Chainsaw is receiving events, and how fast it is processing them");
+ receivedEventLabel.setMinimumSize(
+ new Dimension(
+ receivedEventLabel.getFontMetrics(receivedEventLabel.getFont())
+ .stringWidth("99999999999.9/s") + 5,
+ (int) receivedEventLabel.getPreferredSize().getHeight()));
+
+ eventCountLabel.setBorder(statusBarComponentBorder);
+ eventCountLabel.setToolTipText("<# viewable events>:<# total events>");
+ eventCountLabel.setMinimumSize(
+ new Dimension(
+ eventCountLabel.getFontMetrics(eventCountLabel.getFont())
+ .stringWidth("Filtered/Total: 999999999999:999999999999") + 5,
+ (int) eventCountLabel.getPreferredSize().getHeight()));
+
+ searchMatchLabel.setBorder(statusBarComponentBorder);
+ searchMatchLabel.setToolTipText("<# viewable events>:<# total events>");
+ searchMatchLabel.setMinimumSize(
+ new Dimension(
+ searchMatchLabel.getFontMetrics(eventCountLabel.getFont()).stringWidth("Find matches: 999999999999") + 5,
+ (int) searchMatchLabel.getPreferredSize().getHeight()));
+
+ receivedConnectionlabel.setBorder(statusBarComponentBorder);
+ receivedConnectionlabel.setToolTipText(
+ "Indicates whether Chainsaw has received a remote connection");
+ receivedConnectionlabel.setMinimumSize(
+ new Dimension(
+ netConnectIcon.getIconWidth() + 4,
+ (int) receivedConnectionlabel.getPreferredSize().getHeight()));
+
+ lineSelectionLabel.setBorder(statusBarComponentBorder);
+ lineSelectionLabel.setMinimumSize(
+ new Dimension(
+ lineSelectionLabel.getFontMetrics(lineSelectionLabel.getFont())
+ .stringWidth("999999999"),
+ (int) lineSelectionLabel.getPreferredSize().getHeight()));
+ lineSelectionLabel.setToolTipText(
+ "The current line # selected");
+
+ JComponent[] toFix =
+ new JComponent[]{
+ searchMatchLabel, eventCountLabel,
+ receivedConnectionlabel, lineSelectionLabel, receivedEventLabel,
+ pausedLabel
+ };
for (JComponent aToFix : toFix) {
aToFix.setPreferredSize(aToFix.getMinimumSize());
aToFix.setMaximumSize(aToFix.getMinimumSize());
}
- statusMsg.setMinimumSize(pausedLabel.getPreferredSize());
- statusMsg.setToolTipText("Shows messages from Chainsaw");
-
- GridBagConstraints c = new GridBagConstraints();
- c.insets = new Insets(2, 2, 2, 2);
- c.weightx = 1.0;
- c.weighty = 1.0;
- c.ipadx = 2;
- c.ipady = 2;
- c.gridx = 0;
- c.gridy = 0;
- c.fill = GridBagConstraints.BOTH;
- c.anchor = GridBagConstraints.WEST;
-
- add(statusMsgPanel, c);
-
- c.weightx = 0.0;
- c.weighty = 0.0;
- c.gridx = 1;
- add(receivedConnectionlabel, c);
-
- c.weightx = 0.0;
- c.weighty = 0.0;
- c.gridx = 2;
- add(lineSelectionLabel, c);
-
- c.weightx = 0.0;
- c.weighty = 0.0;
- c.gridx = 3;
- add(searchMatchLabel, c);
-
- c.weightx = 0.0;
- c.weighty = 0.0;
- c.gridx = 4;
- add(eventCountLabel, c);
-
- c.weightx = 0.0;
- c.weighty = 0.0;
- c.gridx = 5;
- add(receivedEventLabel, c);
-
- c.weightx = 0.0;
- c.weighty = 0.0;
- c.gridx = 6;
-
- add(pausedLabel, c);
-
- connectionThread =
- new Thread(
- () -> {
- while (true) {
- try {
- Thread.sleep(DELAY_PERIOD);
- } catch (InterruptedException e) {
- }
-
- Icon icon = null;
-
- if (
- (System.currentTimeMillis() - lastReceivedConnection) < DELAY_PERIOD) {
- icon = netConnectIcon;
- }
-
- final Icon theIcon = icon;
- SwingUtilities.invokeLater(
- () -> receivedConnectionlabel.setIcon(theIcon));
- }
- });
- connectionThread.start();
- }
-
- void setDataRate(final double dataRate) {
- SwingUtilities.invokeLater(
- () -> receivedEventLabel.setText(nf.format(dataRate) + "/s"));
- }
-
- /**
- * Indicates a new connection has been established between
- * Chainsaw and some remote host
- * @param source
- */
- void remoteConnectionReceived(String source) {
- lastReceivedConnection = System.currentTimeMillis();
- MessageCenter.getInstance().getLogger().info("Connection received from " + source);
- connectionThread.interrupt();
-
- // TODO and maybe play a sound?
- }
-
- /**
- * Called when the paused state of the LogPanel has been updated
- * @param isPaused
- * @param tabName
- */
- void setPaused(final boolean isPaused, String tabName) {
- if (tabName.equals(logUI.getActiveTabName())) {
- Runnable runnable =
- () -> {
- pausedLabel.setIcon(isPaused ? pausedIcon : null);
- pausedLabel.setToolTipText(
- isPaused ? "This Log panel is currently paused"
- : "This Log panel is not paused");
- };
- SwingUtilities.invokeLater(runnable);
+ statusMsg.setMinimumSize(pausedLabel.getPreferredSize());
+ statusMsg.setToolTipText("Shows messages from Chainsaw");
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.insets = new Insets(2, 2, 2, 2);
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.ipadx = 2;
+ c.ipady = 2;
+ c.gridx = 0;
+ c.gridy = 0;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.WEST;
+
+ add(statusMsgPanel, c);
+
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridx = 1;
+ add(receivedConnectionlabel, c);
+
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridx = 2;
+ add(lineSelectionLabel, c);
+
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridx = 3;
+ add(searchMatchLabel, c);
+
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridx = 4;
+ add(eventCountLabel, c);
+
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridx = 5;
+ add(receivedEventLabel, c);
+
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridx = 6;
+
+ add(pausedLabel, c);
+
+ connectionThread =
+ new Thread(
+ () -> {
+ while (true) {
+ try {
+ Thread.sleep(DELAY_PERIOD);
+ } catch (InterruptedException e) {
+ }
+
+ Icon icon = null;
+
+ if (
+ (System.currentTimeMillis() - lastReceivedConnection) < DELAY_PERIOD) {
+ icon = netConnectIcon;
+ }
+
+ final Icon theIcon = icon;
+ SwingUtilities.invokeLater(
+ () -> receivedConnectionlabel.setIcon(theIcon));
+ }
+ });
+ connectionThread.start();
}
- }
- void setSelectedLine(
- final int selectedLine, final int lineCount, final int total, String tabName) {
- if (tabName.equals(logUI.getActiveTabName())) {
+ void setDataRate(final double dataRate) {
SwingUtilities.invokeLater(
+ () -> receivedEventLabel.setText(nf.format(dataRate) + "/s"));
+ }
+
+ /**
+ * Indicates a new connection has been established between
+ * Chainsaw and some remote host
+ *
+ * @param source
+ */
+ void remoteConnectionReceived(String source) {
+ lastReceivedConnection = System.currentTimeMillis();
+ MessageCenter.getInstance().getLogger().info("Connection received from " + source);
+ connectionThread.interrupt();
+
+ // TODO and maybe play a sound?
+ }
+
+ /**
+ * Called when the paused state of the LogPanel has been updated
+ *
+ * @param isPaused
+ * @param tabName
+ */
+ void setPaused(final boolean isPaused, String tabName) {
+ if (tabName.equals(logUI.getActiveTabName())) {
+ Runnable runnable =
+ () -> {
+ pausedLabel.setIcon(isPaused ? pausedIcon : null);
+ pausedLabel.setToolTipText(
+ isPaused ? "This Log panel is currently paused"
+ : "This Log panel is not paused");
+ };
+ SwingUtilities.invokeLater(runnable);
+ }
+ }
+
+ void setSelectedLine(
+ final int selectedLine, final int lineCount, final int total, String tabName) {
+ if (tabName.equals(logUI.getActiveTabName())) {
+ SwingUtilities.invokeLater(
() -> {
- lineSelectionLabel.setText(selectedLine+"");
- eventCountLabel.setText("Filtered/Total: " + lineCount + ":" + total);
+ lineSelectionLabel.setText(selectedLine + "");
+ eventCountLabel.setText("Filtered/Total: " + lineCount + ":" + total);
});
+ }
+ }
+
+ void setSearchMatchCount(int searchMatchCount, String tabName) {
+ if (tabName.equals(logUI.getActiveTabName())) {
+ if (searchMatchCount == 0) {
+ searchMatchLabel.setText("");
+ } else {
+ searchMatchLabel.setText("Find matches: " + searchMatchCount);
+ }
+ }
}
- }
-
- void setSearchMatchCount(int searchMatchCount, String tabName) {
- if (tabName.equals(logUI.getActiveTabName())) {
- if (searchMatchCount == 0) {
- searchMatchLabel.setText("");
- } else {
- searchMatchLabel.setText("Find matches: " + searchMatchCount);
- }
- }
- }
-
- void setNothingSelected() {
- SwingUtilities.invokeLater(
+
+ void setNothingSelected() {
+ SwingUtilities.invokeLater(
() -> lineSelectionLabel.setText(""));
- }
+ }
- void clear() {
- setMessage(DEFAULT_MSG);
- setNothingSelected();
- SwingUtilities.invokeLater(
+ void clear() {
+ setMessage(DEFAULT_MSG);
+ setNothingSelected();
+ SwingUtilities.invokeLater(
() -> receivedEventLabel.setText(""));
- }
+ }
- public void setMessage(final String msg) {
- SwingUtilities.invokeLater(
+ public void setMessage(final String msg) {
+ SwingUtilities.invokeLater(
() -> statusMsg.setText(" " + msg));
- }
+ }
}