sdeboy 2003/06/14 09:48:14 Modified: src/java/org/apache/log4j/chainsaw LogUI.java ChainsawCyclicBufferTableModel.java Added: src/java/org/apache/log4j/chainsaw ChainsawTabbedPane.java Removed: src/java/org/apache/log4j/chainsaw ChainsawTabbledPane.java AbstractChainsawTableModel.java Log: Refactoring. Compressed AbstractChainsawTableModel into the CyclicBufferModel. Renamed TabbedPane. Revision Changes Path 1.93 +2 -2 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java Index: LogUI.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v retrieving revision 1.92 retrieving revision 1.93 diff -u -r1.92 -r1.93 --- LogUI.java 10 Jun 2003 23:10:58 -0000 1.92 +++ LogUI.java 14 Jun 2003 16:48:14 -0000 1.93 @@ -180,7 +180,7 @@ private static final String STATUS_BAR = "StatusBar"; private static final String COLUMNS_EXTENSION = ".columns"; private static ChainsawSplash splash = null; - ChainsawTabbledPane tabbedPane; + ChainsawTabbedPane tabbedPane; JToolBar toolbar; private final ChainsawStatusBar statusBar = new ChainsawStatusBar(); private final Map tableModelMap = new HashMap(); @@ -368,7 +368,7 @@ getContentPane().setLayout(new BorderLayout()); - tabbedPane = new ChainsawTabbledPane(); + tabbedPane = new ChainsawTabbedPane(); tabbedPane.addChangeListener(tbms); KeyStroke ksRight = 1.14 +128 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java Index: ChainsawCyclicBufferTableModel.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ChainsawCyclicBufferTableModel.java 10 Jun 2003 19:38:19 -0000 1.13 +++ ChainsawCyclicBufferTableModel.java 14 Jun 2003 16:48:14 -0000 1.14 @@ -53,12 +53,16 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.StringTokenizer; import java.util.Vector; +import javax.swing.SwingUtilities; +import javax.swing.table.AbstractTableModel; + /** * A CyclicBuffer implementation of the EventContainer. @@ -73,16 +77,24 @@ * @author Scott Deboy <[EMAIL PROTECTED]> * */ -class ChainsawCyclicBufferTableModel extends AbstractChainsawTableModel +class ChainsawCyclicBufferTableModel extends AbstractTableModel implements EventContainer { final List unfilteredList; final List filteredList; + private Vector countListeners = new Vector(); + private boolean currentSortAscending; + private int currentSortColumn; + private DisplayFilter displayFilter; + private final FilterChangeExecutor filterExecutor; + private boolean sortEnabled; + protected final Object syncLock = 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; public ChainsawCyclicBufferTableModel(boolean isCyclic, int bufferSize) { + filterExecutor = new FilterChangeExecutor(this, syncLock); if (isCyclic) { unfilteredList = new CyclicBufferList(bufferSize); filteredList = new CyclicBufferList(bufferSize); @@ -90,6 +102,121 @@ unfilteredList = new ArrayList(); filteredList = new ArrayList(); } + } + + public void addEventCountListener(EventCountListener listener) { + countListeners.add(listener); + } + + public void filterChanged() { + SwingUtilities.invokeLater(filterExecutor); + } + + protected boolean getCurrentSortAscending() { + return currentSortAscending; + } + + protected int getCurrentSortColumn() { + return currentSortColumn; + } + + public DisplayFilter getDisplayFilter() { + return displayFilter; + } + + public boolean isSortable(int col) { + return true; + } + + public boolean isSortEnabled() { + return sortEnabled; + } + + public void notifyCountListeners() { + for (int i = 0; i < countListeners.size(); i++) { + ((EventCountListener) countListeners.get(i)).eventCountChanged( + getRowCount(), getUnfilteredRowCount()); + } + } + + public void setCurrentSortColumn(int col, boolean ascending) { + currentSortColumn = col; + currentSortAscending = ascending; + } + + public void setDisplayFilter(DisplayFilter displayFilter) { + this.displayFilter = displayFilter; + } + + public void setSortEnabled(boolean sortEnabled) { + this.sortEnabled = sortEnabled; + } + + /* (non-Javadoc) + * @see org.apache.log4j.chainsaw.EventContainer#sort() + */ + public void sort() { + synchronized (syncLock) { + Collections.sort( + getSortableCollection(), + new ColumnComparator(currentSortColumn, currentSortAscending)); + } + } + + public void sortColumn( + JSortTable table, int col, int row, boolean ascending) { + System.out.println( + "request to sort col=" + col + ", which is " + + ChainsawColumns.getColumnsNames().get(col)); + SwingUtilities.invokeLater( + new SortExecutor(this, this, table, col, row, ascending)); + } + + /** + * Escape <, > & and " as their entities. It is very + * dumb about & handling. + * @param aStr the String to escape. + * @return the escaped String + */ + String escape(String string) { + if (string == null) { + return null; + } + + final StringBuffer buf = new StringBuffer(); + + for (int i = 0; i < string.length(); i++) { + char c = string.charAt(i); + + switch (c) { + case '<': + buf.append("<"); + + break; + + case '>': + buf.append(">"); + + break; + + case '\"': + buf.append("""); + + break; + + case '&': + buf.append("&"); + + break; + + default: + buf.append(c); + + break; + } + } + + return buf.toString(); } /* (non-Javadoc) 1.1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java Index: ChainsawTabbedPane.java =================================================================== /* * @author Paul Smith <[EMAIL PROTECTED]> * */ package org.apache.log4j.chainsaw; import java.awt.Component; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JTabbedPane; /** * The only reason this class is needed is because * of a stupid 'issue' with the JTabbedPane. * * If the currently selected tab is the first tab, * and we insert a new tab at the front, then as * far as the JTabbedPane is concerned, NO STATE has * changed, as the currently selected tab index is still * the same (even though the TAB is different - go figure) * and therefore no ChangeEvent is generated and sent * to listeners. Thanks very much Sun! * * @see http://developer.java.sun.com/developer/bugParade/bugs/4253819.html * @author Paul Smith <[EMAIL PROTECTED]> * */ class ChainsawTabbedPane extends JTabbedPane { /** * */ public ChainsawTabbedPane() { super(); } /** * @param tabPlacement */ public ChainsawTabbedPane(int tabPlacement) { super(tabPlacement); setBorder(null); } /** * Returns true if this TabbedPane has an instance of the WelcomePanel * in it * @return true/false */ boolean containsWelcomePanel() { return indexOfTab("Welcome")>-1; } /** * Our custom implementation of inserting a new tab, * this method ALWAYS inserts it at the front because * we get an ArrayIndexOutOfBoundsException otherwise * under some JDK implementations. * * This method also causes a fireStateChange() to be * called so that listeners get notified of the event. * See the class level comments for the reason why... * @param name * @param component */ public void addANewTab(String name, JComponent component) { int selectedIndex = getSelectedIndex(); super.insertTab(name, null, component, null, 0); setSelectedIndex(selectedIndex+1); super.fireStateChanged(); } public void setSelectedTab(int index) { setSelectedIndex(index); getSelectedComponent().setVisible(true); getSelectedComponent().validate(); super.fireStateChanged(); } public void addANewTab(String name, JComponent component, Icon icon, String tooltip) { int selectedIndex = getSelectedIndex(); super.insertTab(name, icon, component, tooltip, 0); setSelectedIndex(selectedIndex+1); super.fireStateChanged(); } public void remove(Component component) { super.remove(component); super.fireStateChanged(); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]