sdeboy 2003/06/01 21:23:09 Modified: src/java/org/apache/log4j/chainsaw DetailFieldSelector.java WelcomePanel.java ChainsawConstants.java LogUI.java JSortTable.java DisplayFilter.java ColumnSelector.java ColorDisplaySelector.java FileMenu.java SortExecutor.java ChainsawToolBarAndMenus.java src/java/org/apache/log4j/chainsaw/prefs SettingsManager.java Profileable.java Log: Added save support for column order and width via File-Save Settings menu. Selecting this menu item will save the column order and width for the currently active tab. Also updated column selector and manual column move support for managing the currently active sort column. Removed save/load settings from profileable since it extends SettingsListener, which already has these methods. Made the getSettingsDirectory method on SettingsManager public so serialized Java objects storing settings may save the files to the same directory (filters and other settings are now saved to this directory with new extensions). Revision Changes Path 1.2 +2 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DetailFieldSelector.java Index: DetailFieldSelector.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DetailFieldSelector.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DetailFieldSelector.java 28 Apr 2003 05:44:31 -0000 1.1 +++ DetailFieldSelector.java 2 Jun 2003 04:23:07 -0000 1.2 @@ -77,8 +77,9 @@ public class DetailFieldSelector extends JFrame { private HashMap displayFieldBoxMap = new HashMap(); - public DetailFieldSelector( + public DetailFieldSelector(String ident, final Vector columnNames, final DisplayFilter displayFilter) { + super("Select detail/tooltip columns for " + ident); setLocation(150, 150); JPanel detailFieldPanel = new JPanel(new GridLayout(0, 1)); 1.3 +6 -9 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/WelcomePanel.java Index: WelcomePanel.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/WelcomePanel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WelcomePanel.java 1 May 2003 04:12:17 -0000 1.2 +++ WelcomePanel.java 2 Jun 2003 04:23:07 -0000 1.3 @@ -59,6 +59,7 @@ import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; /** @@ -73,13 +74,12 @@ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBackground(Color.white); - URL helpURL = + final URL helpURL = getClass().getClassLoader().getResource( "org/apache/log4j/chainsaw/WelcomePanel.html"); if (helpURL != null) { - try { - JEditorPane textInfo = new JEditorPane(helpURL); + final JEditorPane textInfo = new JEditorPane(); textInfo.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); textInfo.setEditable(false); textInfo.setPreferredSize(new Dimension(320, 240)); @@ -87,12 +87,9 @@ JScrollPane pane = new JScrollPane(textInfo); pane.setBorder(null); add(pane); - } catch (IOException ioe) { - ioe.printStackTrace(); - - return; - } - //can't do much..return + try { + textInfo.setPage(helpURL); + } catch (Exception e) {e.printStackTrace();} } } } 1.6 +1 -0 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawConstants.java Index: ChainsawConstants.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawConstants.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ChainsawConstants.java 8 May 2003 04:37:07 -0000 1.5 +++ ChainsawConstants.java 2 Jun 2003 04:23:07 -0000 1.6 @@ -15,6 +15,7 @@ static final String LOWER_PANEL = "lower"; static final String UPPER_PANEL = "upper"; static final String EMPTY_STRING = ""; + static final String FILTERS_EXTENSION = ".filters"; static final String SETTINGS_EXTENSION = ".settings"; //COLUMN NAMES 1.83 +224 -76 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.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- LogUI.java 28 May 2003 16:52:50 -0000 1.82 +++ LogUI.java 2 Jun 2003 04:23:07 -0000 1.83 @@ -85,12 +85,18 @@ import java.beans.PropertyChangeListener; import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -127,10 +133,14 @@ import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import javax.swing.event.ChangeEvent; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableColumnModelEvent; +import javax.swing.event.TableColumnModelListener; +import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; @@ -155,6 +165,7 @@ private static final String TABLE_COLUMN_WIDTHS = "table.columns.widths"; private static final String LOOK_AND_FEEL = "LookAndFeel"; private static final String STATUS_BAR = "StatusBar"; + private static final String COLUMNS_EXTENSION = ".columns"; private static ChainsawSplash splash = null; ChainsawTabbledPane tabbedPane; JToolBar toolbar; @@ -462,7 +473,8 @@ } void removeWelcomePanel() { - tabbedPane.remove(tabbedPane.getComponentAt(tabbedPane.indexOfTab("Welcome"))); + tabbedPane.remove( + tabbedPane.getComponentAt(tabbedPane.indexOfTab("Welcome"))); } ChainsawStatusBar getStatusBar() { @@ -678,19 +690,23 @@ /** * Regurgitates a DisplayFilter for a specific machine identifier - * by deserializing the settings from a file. + * by deserializing the settings from a file. + * DisplayFilter serializes tool tip fields and enabled flag. * @param ident * @return */ private DisplayFilter loadDisplayFilter(String ident) { DisplayFilter d = null; ObjectInputStream s = null; - + File f = new File( + SettingsManager.getInstance().getSettingsDirectory() + + File.separator + ident + + ChainsawConstants.SETTINGS_EXTENSION); try { s = new ObjectInputStream( new BufferedInputStream( - new FileInputStream( - new File(ident + ChainsawConstants.SETTINGS_EXTENSION)))); + new FileInputStream(f + ))); d = (DisplayFilter) s.readObject(); } catch (IOException ioe) { } catch (ClassNotFoundException cnfe) { @@ -704,7 +720,7 @@ } if (d == null) { - d = new DisplayFilter(ChainsawColumns.getColumnsNames()); + d = new DisplayFilter(); } return d; @@ -762,19 +778,10 @@ } map = new HashMap(); - table = new JSortTable(); - table.setAutoCreateColumnsFromModel(false); - table.setModel(tableModel); - - int columnIndex = 0; + table = new JSortTable(tableModel); + table.getColumnModel().addColumnModelListener(new ChainsawTableColumnModelListener(table)); - for ( - Iterator iter = ChainsawColumns.getColumnsNames().iterator(); - iter.hasNext();) { - Object column = (Object) iter.next(); - TableColumn tableColumn = new TableColumn(columnIndex++); - table.addColumn(tableColumn); - } + table.setAutoCreateColumnsFromModel(false); table.setRowHeight(20); table.setShowGrid(false); @@ -784,7 +791,6 @@ final LogPanel thisPanel = new LogPanel(ident, tableModel, table, scrollToBottom, map, eventType); - // tabbedPane.add(ident, thisPanel); SwingUtilities.invokeLater( new Runnable() { public void run() { @@ -989,13 +995,13 @@ table.setDefaultRenderer(Object.class, renderer); final DetailFieldSelector detailFieldSelector = - new DetailFieldSelector( + new DetailFieldSelector(ident, new Vector(ChainsawColumns.getColumnsNames()), displayFilter); final ColumnSelector columnSelector = - new ColumnSelector( + new ColumnSelector(ident, new Vector(ChainsawColumns.getColumnsNames()), table, displayFilter); - + table.getColumnModel().addColumnModelListener(columnSelector); columnSelector.setIconImage(getIconImage()); detailFieldSelector.setIconImage(getIconImage()); @@ -1080,7 +1086,8 @@ detail = new JEditorPane(ChainsawConstants.DETAIL_CONTENT_TYPE, ""); detail.setEditable(false); - detailPaneUpdater = new DetailPaneUpdater(detail, (EventContainer) tableModel); + detailPaneUpdater = + new DetailPaneUpdater(detail, (EventContainer) tableModel); upperPanel = new JPanel(new BorderLayout()); upperPanel.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 0)); @@ -1241,7 +1248,6 @@ table.getSelectionModel().addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { - if (evt.getValueIsAdjusting()) { return; } @@ -1275,7 +1281,6 @@ } catch (Exception e) { e.printStackTrace(); detailPaneUpdater.setSelectedRow(-1); - } } } @@ -1657,14 +1662,65 @@ return profileName; } + public void saveSettings() { + saveColumnSettings(identifier, table.getColumnModel()); + } + + public void saveSettings(SaveSettingsEvent event) { + //not used..save of columns performed via tablecolumnmodellistener event callback + } + + void saveColumnSettings(String ident, TableColumnModel model) { + ObjectOutputStream o = null; + + try { + File f = + new File( + SettingsManager.getInstance().getSettingsDirectory() + + File.separator + ident + COLUMNS_EXTENSION); + o = new ObjectOutputStream( + new BufferedOutputStream(new FileOutputStream(f))); + + Enumeration e = model.getColumns(); + while (e.hasMoreElements()) { + TableColumn c = (TableColumn) e.nextElement(); + o.writeObject( + new TableColumnData( + (String) c.getHeaderValue(), c.getModelIndex(), c.getWidth())); + } + + o.flush(); + } catch (FileNotFoundException fnfe) { + } catch (IOException ioe) { + ioe.printStackTrace(); + } + + try { + if (o != null) { + o.close(); + } + } catch (IOException ioe) { + } + } + /* (non-Javadoc) * @see org.apache.log4j.chainsaw.prefs.Profileable#loadSettings(org.apache.log4j.chainsaw.prefs.LoadSettingsEvent) */ public void loadSettings(LoadSettingsEvent event) { - /** - * We configure ourselves be getting the order of the TableColumns - * and defining the widths of them - */ + File f = + new File( + SettingsManager.getInstance().getSettingsDirectory() + + File.separator + identifier + COLUMNS_EXTENSION); + + if (f.exists()) { + loadColumnSettings(identifier, table.getColumnModel()); + } else { + loadDefaultColumnSettings(event); + } + } + + void loadDefaultColumnSettings(LoadSettingsEvent event) { + String columnOrder = event.getSetting(TABLE_COLUMN_ORDER); TableColumnModel columnModel = table.getColumnModel(); @@ -1679,15 +1735,14 @@ StringTokenizer tok = new StringTokenizer(columnOrder, ","); List sortedColumnList = new ArrayList(); + //remove all columns from the table that exist in the model + //and add in the correct order to a new arraylist + //(may be a subset of possible columns) while (tok.hasMoreElements()) { String element = (String) tok.nextElement(); TableColumn column = (TableColumn) columnNameMap.get(element); - if (column == null) { - System.out.println( - "loadsettings - column " + element - + " not found in tablecolumnmap"); - } else { + if (column != null) { System.out.println( "Moving column " + element + " from index " + column.getModelIndex() + " to index " + index++); @@ -1696,6 +1751,7 @@ } } + //re-add columns to the table in the order provided from the list for (Iterator iter = sortedColumnList.iterator(); iter.hasNext();) { TableColumn element = (TableColumn) iter.next(); table.addColumn(element); @@ -1736,11 +1792,84 @@ }); } - /* (non-Javadoc) - * @see org.apache.log4j.chainsaw.prefs.Profileable#saveSettings(org.apache.log4j.chainsaw.prefs.SaveSettingsEvent) - */ - public void saveSettings(SaveSettingsEvent event) { - // TODO Auto-generated method stub + void loadColumnSettings(String ident, TableColumnModel model) { + File f = + new File( + SettingsManager.getInstance().getSettingsDirectory() + + File.separator + ident + COLUMNS_EXTENSION); + + if (f.exists()) { + + //remove columns from model - will be re-added in the correct order + for (int i=model.getColumnCount() - 1; i > -1; i--) { + model.removeColumn(model.getColumn(i)); + } + + TableColumnData temp = null; + ObjectInputStream s = null; + + try { + s = new ObjectInputStream( + new BufferedInputStream(new FileInputStream(f))); + + while (true) { + temp = (TableColumnData) s.readObject(); + + TableColumn tc = new TableColumn(temp.getIndex(), temp.getWidth()); + tc.setHeaderValue(temp.getColName()); + table.addColumn(tc); + } + } catch (IOException ioe) { + } catch (ClassNotFoundException cnfe) { + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException ioe) { + } + } + } + } else { + //error..shouldn't occur + } + } + } + + class TableColumnData implements Serializable { + private String colName; + private int index; + private int width; + + public TableColumnData(String colName, int index, int width) { + this.colName = colName; + this.index = index; + this.width = width; + } + + public String getColName() { + return colName; + } + + public int getIndex() { + return index; + } + + public int getWidth() { + return width; + } + + private void readObject(java.io.ObjectInputStream in) + throws IOException, ClassNotFoundException { + colName = (String) in.readObject(); + index = in.readInt(); + width = in.readInt(); + } + + private void writeObject(java.io.ObjectOutputStream out) + throws IOException { + out.writeObject(colName); + out.writeInt(index); + out.writeInt(width); } } @@ -1748,12 +1877,11 @@ * Thread that periodically checks if the selected row has changed, and if * it was, updates the Detail Panel with the detailed Logging information */ - class DetailPaneUpdater { + class DetailPaneUpdater { private int selectedRow = -1; private int lastRow; private final JEditorPane pane; private final EventContainer model; - private long lastUpdate = 0; public DetailPaneUpdater(JEditorPane pane, EventContainer model) { @@ -1762,11 +1890,10 @@ } public void setSelectedRow(int row) { -// if(System.currentTimeMillis()-lastUpdate<1500){ -// lastUpdate = System.currentTimeMillis(); -// return; -// } - + // if(System.currentTimeMillis()-lastUpdate<1500){ + // lastUpdate = System.currentTimeMillis(); + // return; + // } if (row == -1) { lastRow = 0; } @@ -1777,41 +1904,37 @@ } private void updateDetailPane() { - - String text = null; - - if (selectedRow != lastRow) { - if (selectedRow == -1) { - text = "Nothing selected"; + String text = null; - } else { - // TODO refactor to use a single getEvent(row) call, and use a Formatter interface for pluggable formatting - text = model.getDetailText(selectedRow); - - } - - if (!((text != null) && !text.equals(""))) { - text = "Nothing selected"; - } - - lastRow = selectedRow; + if (selectedRow != lastRow) { + if (selectedRow == -1) { + text = "Nothing selected"; + } else { + // TODO refactor to use a single getEvent(row) call, and use a Formatter interface for pluggable formatting + text = model.getDetailText(selectedRow); + } - final String text2 = text; - SwingUtilities.invokeLater( - new Runnable() { - public void run() { - pane.setText(text2); - } - }); - SwingUtilities.invokeLater( - new Runnable() { - public void run() { - pane.setCaretPosition(0); - } - }); + if (!((text != null) && !text.equals(""))) { + text = "Nothing selected"; } + lastRow = selectedRow; + + final String text2 = text; + SwingUtilities.invokeLater( + new Runnable() { + public void run() { + pane.setText(text2); + } + }); + SwingUtilities.invokeLater( + new Runnable() { + public void run() { + pane.setCaretPosition(0); + } + }); } + } } class TabIconHandler implements EventCountListener { @@ -1892,5 +2015,30 @@ public boolean isBypassed() { return bypassed; } + } + + //if columnmoved or columnremoved callback received, re-apply table's sort index based + //sort column name + class ChainsawTableColumnModelListener implements TableColumnModelListener { + private JSortTable table; + + public ChainsawTableColumnModelListener(JSortTable table) { + this.table = table; + } + + public void columnAdded(TableColumnModelEvent e) {} + + public void columnRemoved(TableColumnModelEvent e) { + table.updateSortedColumn(); + } + + public void columnMoved(TableColumnModelEvent e) { + table.updateSortedColumn(); + } + + public void columnMarginChanged(ChangeEvent e) {} + + public void columnSelectionChanged(ListSelectionEvent e) {} + } } 1.7 +12 -0 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/JSortTable.java Index: JSortTable.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/JSortTable.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JSortTable.java 28 May 2003 16:52:49 -0000 1.6 +++ JSortTable.java 2 Jun 2003 04:23:08 -0000 1.7 @@ -68,6 +68,7 @@ public class JSortTable extends JTable implements MouseListener { protected int sortedColumnIndex = -1; protected boolean sortedColumnAscending = true; + private String sortedColumn; public JSortTable() { super(); @@ -100,6 +101,16 @@ return sortedColumnIndex; } + public void updateSortedColumn() { + if (sortedColumn != null) { + try { + setSortedColumnIndex(columnModel.getColumnIndex(sortedColumn)); + } catch (IllegalArgumentException ie) {//nothing...column is not in the model + setSortedColumnIndex(-1); + } + } + } + public void setSortedColumnIndex(int index) { sortedColumnIndex = index; @@ -158,6 +169,7 @@ } sortedColumnIndex = index; + sortedColumn = colModel.getColumn(index).getHeaderValue().toString(); model.sortColumn( this, modelIndex, getSelectedRow(), sortedColumnAscending); } 1.5 +3 -6 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DisplayFilter.java Index: DisplayFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DisplayFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DisplayFilter.java 28 May 2003 07:34:57 -0000 1.4 +++ DisplayFilter.java 2 Jun 2003 04:23:08 -0000 1.5 @@ -77,12 +77,11 @@ private transient Vector filters = new Vector(); private transient DisplayFilterEntry customFilter; private transient boolean customFilterOverride = false; - private List colNames; + private List colNames = ChainsawColumns.getColumnsNames(); private Vector toolTipColumns; private Boolean toolTipsEnabled = Boolean.FALSE; - public DisplayFilter(List colNames) { - this.colNames = colNames; + public DisplayFilter() { toolTipColumns = new Vector(colNames); } @@ -122,7 +121,6 @@ while (iter.hasNext()) { DisplayFilterEntry entry = (DisplayFilterEntry) iter.next(); - if ( entry.matches( entry.getColumnName(), @@ -283,9 +281,9 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { - colNames = (List) in.readObject(); toolTipColumns = (Vector) in.readObject(); toolTipsEnabled = (Boolean) in.readObject(); + colNames = ChainsawColumns.getColumnsNames(); filterListeners = new Vector(); filters = new Vector(); customFilterOverride = false; @@ -293,7 +291,6 @@ private void writeObject(java.io.ObjectOutputStream out) throws IOException { - out.writeObject(colNames); out.writeObject(toolTipColumns); out.writeObject(toolTipsEnabled); } 1.3 +114 -104 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ColumnSelector.java Index: ColumnSelector.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ColumnSelector.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ColumnSelector.java 28 May 2003 07:34:57 -0000 1.2 +++ ColumnSelector.java 2 Jun 2003 04:23:08 -0000 1.3 @@ -53,18 +53,21 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; -import java.util.Map; +import java.util.List; import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.TableColumnModelEvent; +import javax.swing.event.TableColumnModelListener; import javax.swing.table.TableColumn; + /** * A sort of Preferences frame for the current app/panel that allows the * user to choose which Columns are worth displaying. This Frame can then be @@ -73,105 +76,112 @@ * @author Scott Deboy <[EMAIL PROTECTED]> * */ -public class ColumnSelector extends JFrame { - private HashMap displayColumnBoxMap = new HashMap(); - - public ColumnSelector( - final Vector columnNames, - final JSortTable sortTable, - final DisplayFilter displayFilter) { - setLocation(150, 150); - - JPanel columnPanel = new JPanel(new GridLayout(0, 1)); - columnPanel.setBorder( - BorderFactory.createTitledBorder("Select display columns")); - - Vector displayedColumns = new Vector(); - int modelIndex = 0; - for (Iterator iter2 = ChainsawColumns.getColumnsNames().iterator();iter2.hasNext();) { - Object column = iter2.next(); - int viewIndex = sortTable.convertColumnIndexToView(modelIndex); - if (viewIndex > -1) { - displayedColumns.add(column); - } - } - - columnPanel.setPreferredSize(new Dimension(150, 340)); - - for (int i = 0; i < columnNames.size(); i++) { - final String key = (String) columnNames.get(i); - JCheckBox box = new JCheckBox(key, displayedColumns.contains(key)); - displayColumnBoxMap.put(box, key); - box.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int sortIndex = sortTable.getSortedColumnIndex(); - String sortColumn = null; - - if (sortIndex > -1) { - sortColumn = - sortTable.getModel().getColumnName(sortIndex); - } - - Vector v = new Vector(); - Collection c = displayColumnBoxMap.entrySet(); - Iterator iter = c.iterator(); - - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - JCheckBox b = (JCheckBox) entry.getKey(); - - if (b.isSelected()) { - v.add(entry.getValue()); - } - } - - //apply ordering by using original column names order..may be some other way - Vector endVector = new Vector(); - Iterator x = columnNames.iterator(); - - while (x.hasNext()) { - String thiscol = (String) x.next(); - - if (v.contains(thiscol)) { - endVector.add(thiscol); - } - } - - int modelIndex = 0; - for (Iterator iter2 = - ChainsawColumns.getColumnsNames().iterator(); - iter2.hasNext(); - ) { - Object column = iter2.next(); - int viewIndex = - sortTable.convertColumnIndexToView(modelIndex); - if (endVector.contains(column)) { - if (viewIndex == -1) { - TableColumn tableColumn = - new TableColumn(modelIndex); - sortTable.addColumn(tableColumn); - } - } else { - if (viewIndex > -1) { - sortTable.removeColumn( - sortTable.getColumn(column)); - } - } - modelIndex++; - } - - if (sortColumn != null) { - int newIndex = endVector.indexOf(sortColumn); - - if (newIndex > -1) { - sortTable.setSortedColumnIndex(newIndex); - } - } - } - }); - columnPanel.add(box); - getContentPane().add(columnPanel); - pack(); - } - } +public class ColumnSelector extends JFrame implements TableColumnModelListener { + private final JSortTable sortTable; + private final DisplayFilter displayFilter; + private Vector checkBoxes=new Vector(); + private List columnNames = ChainsawColumns.getColumnsNames(); + +/* + * Build a vector of JCheckBoxes. + * No need to use a map to look up the column name because + * the checkbox text is the column name. + * + */ + public ColumnSelector(String ident, + final Vector columnNames, final JSortTable sortTable, + final DisplayFilter displayFilter) { + super("Select displayed columns for " + ident); + this.sortTable = sortTable; + this.displayFilter = displayFilter; + setLocation(150, 150); + + JPanel columnPanel = new JPanel(new GridLayout(0, 1)); + columnPanel.setBorder( + BorderFactory.createTitledBorder("Select display columns")); + columnPanel.setPreferredSize(new Dimension(150, 340)); + + int modelIndex = 0; + + //build displayed columns + for ( + Iterator iter2 = columnNames.iterator(); + iter2.hasNext();) { + String column = iter2.next().toString(); + + //default checkbox to displayed/undisplayed based on + //whether or not the column is displayed at construction time. + //a convertcolumnindextoview return value of -1 is not displayed. + int viewIndex = sortTable.convertColumnIndexToView(modelIndex); + final JCheckBox box = new JCheckBox(column, viewIndex > -1); + + checkBoxes.add(box); + + /* In the checkbox action, first get the current sorted column index + * and then iterate through the ChainsawConstants column list and examine + * whether or not the column is displayed in the table. + * + */ + box.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Vector v = new Vector(); + + //get the index of this column in the columnmodel + int modelIndex = columnNames.indexOf(box.getText()); + + //get the index of this column in the table + int viewIndex = sortTable.convertColumnIndexToView(modelIndex); + + //if the column is not in the table and the checkbox is now selected, + //add the column to the table + if ((viewIndex == -1) && box.isSelected()) { + TableColumn tableColumn = new TableColumn(modelIndex); + sortTable.addColumn(tableColumn); + } else { + //if the column is in the table and the checkbox is now + //NOT selected, remove the column from the table + if ((viewIndex > -1) && !box.isSelected()) { + sortTable.removeColumn(sortTable.getColumn(box.getText())); + } + } + } + }); + columnPanel.add(box); + } + + getContentPane().add(columnPanel); + pack(); + } + + public void columnAdded(TableColumnModelEvent e) { + updateState(); + } + + public void columnRemoved(TableColumnModelEvent e) { + updateState(); + } + + public void columnMoved(TableColumnModelEvent e) { + } + + public void columnMarginChanged(ChangeEvent e) { + } + + public void columnSelectionChanged(ListSelectionEvent e) { + } + + private void updateState() { + //update the selected state of each checkbox - we don't kmnow which column + //was added or removed, so go through all of them + int modelIndex = 0; + for ( + Iterator iter2 = columnNames.iterator(); + iter2.hasNext();) { + Object column = iter2.next(); + int viewIndex = sortTable.convertColumnIndexToView(modelIndex); + ((JCheckBox)checkBoxes.get(modelIndex)).setSelected(viewIndex > -1); + modelIndex++; + } + } } 1.3 +7 -5 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ColorDisplaySelector.java Index: ColorDisplaySelector.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ColorDisplaySelector.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ColorDisplaySelector.java 30 Apr 2003 23:01:58 -0000 1.2 +++ ColorDisplaySelector.java 2 Jun 2003 04:23:08 -0000 1.3 @@ -105,6 +105,8 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import org.apache.log4j.chainsaw.prefs.SettingsManager; + /** * A JFrame that represents configuration information on how @@ -117,8 +119,8 @@ ListSelectionListener { private static final String NONE_COL_NAME = "None"; private static final String LEVEL_COL_NAME = "Level"; - private static final String FILTERS_EXTENSION = ".filters"; - private static final String SETTINGS_EXTENSION = ".settings"; + private static final String COLOR_FILTERS_EXTENSION = ".colorfilters"; + private static final String DISPLAY_FILTERS_EXTENSION = ".displayfilters"; private final JList list = new JList(); private String selectedValue; private String selectedColumn; @@ -183,7 +185,7 @@ try { o = new ObjectOutputStream( new BufferedOutputStream( - new FileOutputStream(new File(title + FILTERS_EXTENSION)))); + new FileOutputStream(new File(SettingsManager.getInstance().getSettingsDirectory() + File.separator + title + ChainsawConstants.FILTERS_EXTENSION)))); o.writeObject(columnColorMap); o.writeObject(columnDisplayMap); o.flush(); @@ -205,7 +207,7 @@ o2 = new ObjectOutputStream( new BufferedOutputStream( - new FileOutputStream(new File(title + SETTINGS_EXTENSION)))); + new FileOutputStream(new File(SettingsManager.getInstance().getSettingsDirectory() + File.separator + title + ChainsawConstants.SETTINGS_EXTENSION)))); o2.writeObject(displayFilter); o2.flush(); } catch (FileNotFoundException fnfe) { @@ -566,7 +568,7 @@ try { s = new ObjectInputStream( new BufferedInputStream( - new FileInputStream(new File(title + FILTERS_EXTENSION)))); + new FileInputStream(new File(SettingsManager.getInstance().getSettingsDirectory() + File.separator + title + ChainsawConstants.FILTERS_EXTENSION)))); columnColorMap = (HashMap) s.readObject(); columnDisplayMap = (HashMap) s.readObject(); } catch (IOException ioe) { 1.8 +18 -0 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileMenu.java Index: FileMenu.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileMenu.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FileMenu.java 15 May 2003 16:13:37 -0000 1.7 +++ FileMenu.java 2 Jun 2003 04:23:08 -0000 1.8 @@ -29,6 +29,7 @@ private Action loadLog4JAction; private Action loadUtilLoggingAction; private Action saveAction; + private Action saveSettingsAction; public FileMenu(final LogUI logUI) { super("File"); @@ -41,6 +42,14 @@ JMenuItem loadLog4JFile = new JMenuItem(loadLog4JAction); JMenuItem loadUtilLoggingFile = new JMenuItem(loadUtilLoggingAction); JMenuItem saveFile = new JMenuItem(saveAction); + + saveSettingsAction = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + logUI.getCurrentLogPanel().saveSettings(); + } + }; + + exitAction = new AbstractAction() { @@ -54,8 +63,16 @@ exitAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X)); exitAction.putValue(Action.NAME, "Exit"); + saveSettingsAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK)); + saveSettingsAction.putValue(Action.SHORT_DESCRIPTION, "Saves column size and position"); + saveSettingsAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_T)); + saveSettingsAction.putValue(Action.NAME, "Save Settings"); + + JMenuItem saveSettingsFile = new JMenuItem(saveSettingsAction); + JMenuItem menuItemExit = new JMenuItem(exitAction); + add(saveSettingsFile); add(loadLog4JFile); add(loadUtilLoggingFile); add(saveFile); @@ -67,6 +84,7 @@ Action getUtilLoggingJFileOpenAction() { return loadUtilLoggingAction;} Action getFileSaveAction() { return saveAction;} Action getExitAction() { return exitAction;} + Action getSaveSettingsAction() { return saveSettingsAction;} } 1.4 +3 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/SortExecutor.java Index: SortExecutor.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/SortExecutor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SortExecutor.java 28 May 2003 16:52:50 -0000 1.3 +++ SortExecutor.java 2 Jun 2003 04:23:08 -0000 1.4 @@ -82,7 +82,9 @@ model.setSortEnabled(true); model.setCurrentSortColumn(col, ascending); - model.sort(); + if (col > -1) { + model.sort(); + } if (o == null) { table.scrollToRow( 1.29 +1 -0 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java Index: ChainsawToolBarAndMenus.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- ChainsawToolBarAndMenus.java 23 May 2003 01:09:00 -0000 1.28 +++ ChainsawToolBarAndMenus.java 2 Jun 2003 04:23:08 -0000 1.29 @@ -227,6 +227,7 @@ closeAction.setEnabled(false); } } else { + fileMenu.getSaveSettingsAction().setEnabled(true); fileMenu.getFileSaveAction().setEnabled(true); findTextField.setEnabled(true); 1.5 +1 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java Index: SettingsManager.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SettingsManager.java 15 May 2003 03:57:17 -0000 1.4 +++ SettingsManager.java 2 Jun 2003 04:23:08 -0000 1.5 @@ -200,7 +200,7 @@ } } - private File getSettingsDirectory() { + public File getSettingsDirectory() { return new File(System.getProperty("user.home"), ".chainsaw"); } 1.4 +0 -18 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/prefs/Profileable.java Index: Profileable.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/prefs/Profileable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Profileable.java 27 May 2003 05:33:22 -0000 1.3 +++ Profileable.java 2 Jun 2003 04:23:09 -0000 1.4 @@ -40,22 +40,4 @@ */ public String getProfileName(); - /** - * The ProfileManager calls this method on the implementing component - * to advise that a Profile load event has been requested, and - * provides the LoadSettingsEvent configured with all the information - * loaded from the profile. - * - * This component should take this opportunity to query the event - * and read any specific values and configure itself accordingly. - */ - public void loadSettings(LoadSettingsEvent event); - - /** - * The ProfileManager will call this method on the implementing component - * allowing this instance to modify the values in the event - * to be stored with the named profile returned from getProfileName(). - */ - public void saveSettings(SaveSettingsEvent event); - }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]