psmith 2003/12/11 14:31:29 Modified: src/java/org/apache/log4j/chainsaw ChainsawToolBarAndMenus.java LogUI.java LogPanelPreferencePanel.java LogPanel.java ApplicationPreferenceModel.java Added: src/java/org/apache/log4j/chainsaw AbstractPreferencePanel.java ApplicationPreferenceModelPanel.java BasicPrefPanel.java Log: Refactored the LogPanelPreferencePanel so that we can have a common preference style panel. Added an application-wide Preference panel to expose a GUI for the user to tweak the ApplicationPreferenceModel. Currently there is a bug where the "ShowNoReceiver" checkbox is not tracking with the models actual value, but if you uncheck it and exit Chainsaw, the correct value is saved. The next time you start Chainsaw the warning dialog is not displayed as per the models value, but the checkbox is still ticked. Revision Changes Path 1.21 +12 -1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java Index: ChainsawToolBarAndMenus.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ChainsawToolBarAndMenus.java 3 Dec 2003 02:28:44 -0000 1.20 +++ ChainsawToolBarAndMenus.java 11 Dec 2003 22:31:28 -0000 1.21 @@ -440,6 +440,15 @@ showColorPanelAction.getValue(Action.SHORT_DESCRIPTION).toString()); JMenuItem menuUndock = new JMenuItem(undockAction); + + JMenuItem showAppPrefs = new JMenuItem("Show Application-wide Preferences..."); + + showAppPrefs.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + logui.showApplicationPreferences(); + }}); toggleDetailMenuItem.setAction(toggleDetailPaneAction); toggleDetailMenuItem.setSelected(true); @@ -578,7 +587,9 @@ viewMenu.add(tabMenu); viewMenu.add(responsiveNess); viewMenu.add(lookAndFeelMenu); - + viewMenu.addSeparator(); + viewMenu.add(showAppPrefs); + JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('H'); 1.49 +33 -6 jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java Index: LogUI.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- LogUI.java 11 Dec 2003 05:45:59 -0000 1.48 +++ LogUI.java 11 Dec 2003 22:31:29 -0000 1.49 @@ -159,6 +159,8 @@ private static final String LOOK_AND_FEEL = "LookAndFeel"; private static final String STATUS_BAR = "StatusBar"; static final String COLUMNS_EXTENSION = ".columns"; + private final JFrame preferencesFrame = new JFrame(); + private static ChainsawSplash splash; private URL configURLToUse; private boolean noReceiversDefined; @@ -166,7 +168,8 @@ private ChainsawTabbedPane tabbedPane; private JToolBar toolbar; private ChainsawStatusBar statusBar; - private ApplicationPreferenceModel appPreferenceModel = new ApplicationPreferenceModel(); + private final ApplicationPreferenceModel applicationPreferenceModel = new ApplicationPreferenceModel(); + private final ApplicationPreferenceModelPanel applicationPreferenceModelPanel = new ApplicationPreferenceModelPanel(applicationPreferenceModel); private final Map tableModelMap = new HashMap(); private final Map tableMap = new HashMap(); private final List filterableColumns = new ArrayList(); @@ -317,7 +320,20 @@ toolbar = getToolBarAndMenus().getToolbar(); setJMenuBar(getToolBarAndMenus().getMenubar()); setTabbedPane(new ChainsawTabbedPane()); - + preferencesFrame.setTitle("'Application-wide Preferences"); + preferencesFrame.setIconImage( + ((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage()); + preferencesFrame.getContentPane().add(applicationPreferenceModelPanel); + + preferencesFrame.setSize(640, 480); + + applicationPreferenceModelPanel.setOkCancelActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + preferencesFrame.setVisible(false); + } + }); + } /** @@ -376,7 +392,7 @@ public void activateViewer() { welcomePanel = new WelcomePanel(this); - appPreferenceModel.addPropertyChangeListener("identifierExpression", new PropertyChangeListener() { + applicationPreferenceModel.addPropertyChangeListener("identifierExpression", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { handler.setIdentifierExpression(evt.getNewValue().toString()); } @@ -732,7 +748,7 @@ }); getSettingsManager().addSettingsListener(this); - getSettingsManager().addSettingsListener(appPreferenceModel); + getSettingsManager().addSettingsListener(applicationPreferenceModel); getSettingsManager().addSettingsListener(getToolBarAndMenus()); getSettingsManager().loadSettings(); @@ -745,7 +761,7 @@ initializationLock.notifyAll(); } - if (noReceiversDefined && appPreferenceModel.isShowNoReceiverWarning()) { + if (noReceiversDefined && applicationPreferenceModel.isShowNoReceiverWarning()) { showNoReceiversWarningPanel(); } @@ -939,7 +955,7 @@ dialog.dispose(); - appPreferenceModel.setShowNoReceiverWarning(!noReceiversWarningPanel.isDontWarnMeAgain()); + applicationPreferenceModel.setShowNoReceiverWarning(!noReceiversWarningPanel.isDontWarnMeAgain()); if (noReceiversWarningPanel.getModel().isManualMode()) { toggleReceiversPanel(); } else if (noReceiversWarningPanel.getModel().isSimpleReceiverMode()) { @@ -1045,6 +1061,10 @@ return statusBar; } + void showApplicationPreferences() { + applicationPreferenceModelPanel.updateModel(); + preferencesFrame.show(); + } void showAboutBox() { if (aboutBox == null) { aboutBox = new ChainsawAbout(this); @@ -1656,5 +1676,12 @@ public void eventCountChanged(int currentCount, int totalCount) { this.currentCount = currentCount; } + } + /** + * @return Returns the applicationPreferenceModel. + */ + public final ApplicationPreferenceModel getApplicationPreferenceModel() + { + return applicationPreferenceModel; } } 1.11 +20 -149 jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java Index: LogPanelPreferencePanel.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- LogPanelPreferencePanel.java 4 Dec 2003 21:28:48 -0000 1.10 +++ LogPanelPreferencePanel.java 11 Dec 2003 22:31:29 -0000 1.11 @@ -49,8 +49,6 @@ package org.apache.log4j.chainsaw; -import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; @@ -67,9 +65,7 @@ import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.DefaultListModel; -import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; @@ -77,24 +73,15 @@ import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTextField; -import javax.swing.JTree; import javax.swing.ListCellRenderer; -import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.DefaultTreeSelectionModel; import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; -import org.apache.log4j.chainsaw.icons.ChainsawIcons; import org.apache.log4j.helpers.LogLog; @@ -103,7 +90,7 @@ * * @author Paul Smith */ -public class LogPanelPreferencePanel extends JPanel { +public class LogPanelPreferencePanel extends AbstractPreferencePanel { /** * */ @@ -114,127 +101,29 @@ } private final LogPanelPreferenceModel committedPreferenceModel; - private final JLabel titleLabel = new JLabel("Selected Pref Panel"); - private final JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); - private final JPanel selectedPrefPanel = new JPanel(new BorderLayout(0, 3)); private final LogPanelPreferenceModel uncommittedPreferenceModel = new LogPanelPreferenceModel(); - private ActionListener okCancelListener; - private Component currentlyDisplayedPanel = null; private JTextField loggerPrecision = new JTextField(5); public LogPanelPreferencePanel(LogPanelPreferenceModel model) { this.committedPreferenceModel = model; initComponents(); - } - - /** - * Setup and layout for the components - */ - private void initComponents() { - // setBorder(BorderFactory.createLineBorder(Color.red)); - setLayout(new BorderLayout(5, 5)); - setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); - - final JTree prefTree = new JTree(createTreeModel()); - prefTree.setRootVisible(false); - - DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); - renderer.setLeafIcon(ChainsawIcons.ICON_PREFERENCES); - prefTree.setCellRenderer(renderer); - - final JScrollPane treeScroll = new JScrollPane(prefTree); - - treeScroll.setPreferredSize(new Dimension(200, 240)); - - titleLabel.setFont(titleLabel.getFont().deriveFont(16.0f)); - titleLabel.setBorder(BorderFactory.createEtchedBorder()); - titleLabel.setBackground(Color.white); - titleLabel.setOpaque(true); - - selectedPrefPanel.add(titleLabel, BorderLayout.NORTH); - - mainPanel.add(treeScroll, BorderLayout.WEST); - mainPanel.add(selectedPrefPanel, BorderLayout.CENTER); - - add(mainPanel, BorderLayout.CENTER); - - JButton okButton = new JButton("OK"); - - okButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - uncommittedPreferenceModel.setLoggerPrecision(loggerPrecision.getText()); - committedPreferenceModel.apply(uncommittedPreferenceModel); - hidePanel(); - } - }); - - JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - hidePanel(); - } - }); - - Box buttonBox = Box.createHorizontalBox(); - buttonBox.add(Box.createHorizontalGlue()); - buttonBox.add(okButton); - buttonBox.add(Box.createHorizontalStrut(5)); - buttonBox.add(cancelButton); - - add(buttonBox, BorderLayout.SOUTH); - - DefaultTreeSelectionModel treeSelectionModel = - new DefaultTreeSelectionModel(); - treeSelectionModel.setSelectionMode( - TreeSelectionModel.SINGLE_TREE_SELECTION); - prefTree.setSelectionModel(treeSelectionModel); - prefTree.addTreeSelectionListener( - new TreeSelectionListener() { - public void valueChanged(TreeSelectionEvent e) { - TreePath path = e.getNewLeadSelectionPath(); - DefaultMutableTreeNode node = - (DefaultMutableTreeNode) path.getLastPathComponent(); - setDisplayedPrefPanel((JComponent) node.getUserObject()); - } - }); - - // ensure the first pref panel is selected and displayed - DefaultMutableTreeNode root = - (DefaultMutableTreeNode) prefTree.getModel().getRoot(); - DefaultMutableTreeNode firstNode = - (DefaultMutableTreeNode) root.getFirstChild(); - prefTree.setSelectionPath(new TreePath(firstNode.getPath())); - } - - /** - * Ensures a specific panel is displayed in the spot where - * preferences can be selected. - * - * @param panel - */ - protected void setDisplayedPrefPanel(JComponent panel) { - if (currentlyDisplayedPanel != null) { - selectedPrefPanel.remove(currentlyDisplayedPanel); - } - - selectedPrefPanel.add(panel, BorderLayout.CENTER); - currentlyDisplayedPanel = panel; - titleLabel.setText(panel.toString()); - selectedPrefPanel.revalidate(); - selectedPrefPanel.repaint(); - } - - public void setOkCancelActionListener(ActionListener l) { - this.okCancelListener = l; - } - - public void hidePanel() { - if (okCancelListener != null) { - okCancelListener.actionPerformed(null); - } + + getOkButton().addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + uncommittedPreferenceModel.setLoggerPrecision(loggerPrecision.getText()); + committedPreferenceModel.apply(uncommittedPreferenceModel); + hidePanel(); + } + }); + + getCancelButton().addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + hidePanel(); + } + }); } /** @@ -246,7 +135,7 @@ this.uncommittedPreferenceModel.apply(committedPreferenceModel); } - private TreeModel createTreeModel() { + protected TreeModel createTreeModel() { final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Preferences"); DefaultTreeModel model = new DefaultTreeModel(rootNode); @@ -294,24 +183,12 @@ } /** - * All of the Preferences panels used in this class extend from - * this, it is used to provide standard L&F required by all. - * @author Paul Smith - * - */ - private static class BasicPrefPanel extends JPanel { - private BasicPrefPanel() { - // setBorder(BorderFactory.createLineBorder(Color.red)); - } - } - - /** * Provides preference gui's for all the Formatting options * available for the columns etc. */ private class FormattingPanel extends BasicPrefPanel { private FormattingPanel() { - super(); + super("Formatting"); this.initComponents(); } @@ -515,9 +392,6 @@ add(Box.createVerticalGlue()); } - public String toString() { - return "Formatting"; - } } /** @@ -579,6 +453,7 @@ */ public class ColumnSelectorPanel extends BasicPrefPanel { ColumnSelectorPanel() { + super("Columns"); initComponents(); } @@ -632,10 +507,6 @@ add(columnBox); add(Box.createVerticalGlue()); - } - - public String toString() { - return "Columns"; } } } 1.30 +46 -34 jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java Index: LogPanel.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- LogPanel.java 8 Dec 2003 06:00:20 -0000 1.29 +++ LogPanel.java 11 Dec 2003 22:31:29 -0000 1.30 @@ -197,7 +197,9 @@ final Map columnDisplayMap = new HashMap(); final Map colorDisplayMap = new HashMap(); final Map columnNameKeywordMap = new HashMap(); - + final JMenuItem menuItemFocusOn = + new JMenuItem("Focus on"); + // final ColorDisplaySelector colorDisplaySelector; ScrollToBottom scrollToBottom; private final LogPanelLoggerTreeModel logTreeModel = @@ -504,35 +506,7 @@ table.addMouseMotionListener( - new MouseMotionAdapter() { - int currentRow = -1; - - public void mouseMoved(MouseEvent evt) { - currentPoint = evt.getPoint(); - - if (tooltipsEnabled) { - int row = table.rowAtPoint(evt.getPoint()); - - if ((row == currentRow) || (row == -1)) { - return; - } - - currentRow = row; - - LoggingEvent event = tableModel.getRow(currentRow); - Layout layout = getToolTipLayout(); - - if (event != null) { - StringBuffer buf = new StringBuffer(); - buf.append(layout.getHeader()).append(layout.format(event)) - .append(layout.getFooter()); - table.setToolTipText(buf.toString()); - } - } else { - table.setToolTipText(null); - } - } - }); + new TableColumnDetailMouseListener(table, tableModel)); //HACK - fix the way columns are sized..should be saved off and loaded later table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); @@ -907,9 +881,9 @@ }); menuItemToggleToolTips.setIcon(new ImageIcon(ChainsawIcons.TOOL_TIP)); - final JMenuItem menuDefineCustomFilter = - new JMenuItem("Focus on"); - menuDefineCustomFilter.addActionListener( + + + menuItemFocusOn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { if (currentPoint != null) { @@ -1029,7 +1003,7 @@ } }); p.add(clearFocusAction); - p.add(menuDefineCustomFilter); + p.add(menuItemFocusOn); p.add(menuDefineAddCustomFilter); p.add(new JSeparator()); @@ -1855,6 +1829,44 @@ */ public final LogPanelPreferenceModel getPreferenceModel() { return preferenceModel; + } + + private final class TableColumnDetailMouseListener extends MouseMotionAdapter + { + int currentRow = -1; + private final JSortTable table; + private final EventContainer tableModel; + private TableColumnDetailMouseListener(JSortTable table, EventContainer tableModel) + { + super(); + this.table = table; + this.tableModel = tableModel; + } + public void mouseMoved(MouseEvent evt) { + currentPoint = evt.getPoint(); + + if (tooltipsEnabled) { + int row = table.rowAtPoint(evt.getPoint()); + + if ((row == currentRow) || (row == -1)) { + return; + } + + currentRow = row; + + LoggingEvent event = tableModel.getRow(currentRow); + Layout layout = getToolTipLayout(); + + if (event != null) { + StringBuffer buf = new StringBuffer(); + buf.append(layout.getHeader()).append(layout.format(event)) + .append(layout.getFooter()); + table.setToolTipText(buf.toString()); + } + } else { + table.setToolTipText(null); + } + } } private abstract class RefinementFocusRule extends AbstractRule { 1.3 +11 -0 jakarta-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java Index: ApplicationPreferenceModel.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ApplicationPreferenceModel.java 11 Dec 2003 05:45:59 -0000 1.2 +++ ApplicationPreferenceModel.java 11 Dec 2003 22:31:29 -0000 1.3 @@ -199,4 +199,15 @@ event.saveSetting("showNoReceiverWarning", isShowNoReceiverWarning()); event.saveSetting("identifierExpression", getIdentifierExpression()); } + + /** + * Takes another model and copies all the values into this model + * @param uncommittedPreferenceModel + */ + public void apply(ApplicationPreferenceModel model) + { + setIdentifierExpression(model.getIdentifierExpression()); + setShowNoReceiverWarning(model.isShowNoReceiverWarning()); + + } } 1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java Index: AbstractPreferencePanel.java =================================================================== /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "log4j" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation. For more information on the * Apache Software Foundation, please see <http://www.apache.org/>. * */package org.apache.log4j.chainsaw; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeSelectionModel; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import org.apache.log4j.chainsaw.icons.ChainsawIcons; /** * Some basic plumbing for Preference related dialogs. * * Sub classes have the following responsibilities: * * <ul> * <li>Must call this this classes initComponents() method from * within the sub-classes constructor, this method laysout the * panel and calls the abstract createTreeModel method to initialise the * tree of Panels. * <li>Must override createTreeModel() method to return a TreeModel whose * TreeNodes getUserObject() method will return a JComponent that is displayed * as the selected editable Preference panel. This JComponent's .toString() method is * used as the title of the preference panel * </ul> * * @author Paul Smith <[EMAIL PROTECTED]> * */ public abstract class AbstractPreferencePanel extends JPanel { private final JLabel titleLabel = new JLabel("Selected Pref Panel"); private final JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); private final JPanel selectedPrefPanel = new JPanel(new BorderLayout(0, 3)); private final JButton okButton = new JButton("OK"); private final JButton cancelButton = new JButton("Cancel"); private ActionListener okCancelListener; private Component currentlyDisplayedPanel = null; /** * Setup and layout for the components */ protected void initComponents() { // setBorder(BorderFactory.createLineBorder(Color.red)); setLayout(new BorderLayout(5, 5)); setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); final JTree prefTree = new JTree(createTreeModel()); prefTree.setRootVisible(false); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); renderer.setLeafIcon(ChainsawIcons.ICON_PREFERENCES); prefTree.setCellRenderer(renderer); final JScrollPane treeScroll = new JScrollPane(prefTree); treeScroll.setPreferredSize(new Dimension(200, 240)); titleLabel.setFont(titleLabel.getFont().deriveFont(16.0f)); titleLabel.setBorder(BorderFactory.createEtchedBorder()); titleLabel.setBackground(Color.white); titleLabel.setOpaque(true); selectedPrefPanel.add(titleLabel, BorderLayout.NORTH); mainPanel.add(treeScroll, BorderLayout.WEST); mainPanel.add(selectedPrefPanel, BorderLayout.CENTER); add(mainPanel, BorderLayout.CENTER); Box buttonBox = Box.createHorizontalBox(); buttonBox.add(Box.createHorizontalGlue()); buttonBox.add(okButton); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(cancelButton); add(buttonBox, BorderLayout.SOUTH); DefaultTreeSelectionModel treeSelectionModel = new DefaultTreeSelectionModel(); treeSelectionModel.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION); prefTree.setSelectionModel(treeSelectionModel); prefTree.addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getNewLeadSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); setDisplayedPrefPanel((JComponent) node.getUserObject()); } }); // ensure the first pref panel is selected and displayed DefaultMutableTreeNode root = (DefaultMutableTreeNode) prefTree.getModel().getRoot(); DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode) root.getFirstChild(); prefTree.setSelectionPath(new TreePath(firstNode.getPath())); } /** * @return */ protected abstract TreeModel createTreeModel(); /** * Ensures a specific panel is displayed in the spot where * preferences can be selected. * * @param panel */ protected void setDisplayedPrefPanel(JComponent panel) { if (currentlyDisplayedPanel != null) { selectedPrefPanel.remove(currentlyDisplayedPanel); } selectedPrefPanel.add(panel, BorderLayout.CENTER); currentlyDisplayedPanel = panel; String title = panel.toString(); titleLabel.setText(title); selectedPrefPanel.revalidate(); selectedPrefPanel.repaint(); } public void setOkCancelActionListener(ActionListener l) { this.okCancelListener = l; } public void hidePanel() { if (okCancelListener != null) { okCancelListener.actionPerformed(null); } } /** * @return Returns the cancelButton. */ protected final JButton getCancelButton() { return cancelButton; } /** * @return Returns the okButton. */ protected final JButton getOkButton() { return okButton; } } 1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java Index: ApplicationPreferenceModelPanel.java =================================================================== /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "log4j" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation. For more information on the * Apache Software Foundation, please see <http://www.apache.org/>. * */package org.apache.log4j.chainsaw; import org.apache.log4j.helpers.LogLog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; /** * A panel used by the user to modify any application-wide preferences. * * @author Paul Smith <[EMAIL PROTECTED]> * */ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel { private ApplicationPreferenceModel committedPreferenceModel; private ApplicationPreferenceModel uncommittedPreferenceModel = new ApplicationPreferenceModel(); ApplicationPreferenceModelPanel(ApplicationPreferenceModel model) { this.committedPreferenceModel = model; initComponents(); getOkButton().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { committedPreferenceModel.apply(uncommittedPreferenceModel); hidePanel(); } }); getCancelButton().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hidePanel(); } }); } public static void main(String[] args) { JFrame f = new JFrame("App Preferences Panel Test Bed"); ApplicationPreferenceModel model = new ApplicationPreferenceModel(); ApplicationPreferenceModelPanel panel = new ApplicationPreferenceModelPanel(model); f.getContentPane().add(panel); model.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { LogLog.warn(evt.toString()); } }); panel.setOkCancelActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(1); } }); f.setSize(640, 480); f.show(); } /** * Ensures this panels DISPLAYED model is in sync with * the model initially passed to the constructor. * */ public void updateModel() { this.uncommittedPreferenceModel.apply(committedPreferenceModel); } /* (non-Javadoc) * @see org.apache.log4j.chainsaw.AbstractPreferencePanel#createTreeModel() */ protected TreeModel createTreeModel() { final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode( "Preferences"); DefaultTreeModel model = new DefaultTreeModel(rootNode); DefaultMutableTreeNode general = new DefaultMutableTreeNode( new GeneralAllPrefPanel()); rootNode.add(general); return model; } /** * @author psmith * */ public class GeneralAllPrefPanel extends BasicPrefPanel { private final JCheckBox showNoReceiverWarning = new JCheckBox( "Prompt me on startup if there are no Receivers defined"); /** * @param title */ public GeneralAllPrefPanel() { super("General"); GeneralAllPrefPanel.this.initComponents(); } private void initComponents() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); showNoReceiverWarning.setSelected( uncommittedPreferenceModel.isShowNoReceiverWarning()); showNoReceiverWarning.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { uncommittedPreferenceModel.setShowNoReceiverWarning( showNoReceiverWarning.isSelected()); } }); add(showNoReceiverWarning); } } } 1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/BasicPrefPanel.java Index: BasicPrefPanel.java =================================================================== /* */ package org.apache.log4j.chainsaw; import javax.swing.JPanel; /** * All of the Preferences panels used in this class extend from * this, it is used to provide standard L&F required by all. * @author Paul Smith * */ public abstract class BasicPrefPanel extends JPanel { private String title; protected BasicPrefPanel(String title) { // setBorder(BorderFactory.createLineBorder(Color.red)); this.title = title; } /** * @return Returns the title. */ public final String getTitle() { return title; } /** * @param title The title to set. */ public final void setTitle(String title) { this.title = title; } public String toString() { return getTitle(); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]