http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java index dc11119..eac5b1e 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java +++ b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.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. @@ -16,20 +16,18 @@ */ package org.apache.log4j.chainsaw; -import java.awt.Color; +import javax.swing.*; +import java.awt.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.ArrayList; import java.util.List; import java.util.Vector; -import javax.swing.UIManager; - /** * Encapsulates the Chainsaw Application wide properties * * @author Paul Smith <psm...@apache.org> - * */ public class ApplicationPreferenceModel { @@ -53,13 +51,13 @@ public class ApplicationPreferenceModel { private transient final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this); - + private int tabPlacement = 3; - + /** * If not 'empty', this property will be used as the URL to load log4j configuration at startup */ - private Vector<String> configurationURLs=new Vector<>(); + private Vector<String> configurationURLs = new Vector<>(); private String configurationURL = ""; @@ -68,8 +66,8 @@ public class ApplicationPreferenceModel { */ private transient String bypassConfigurationURL = null; /** - * this means for Receivers that require optional jars that can't be delivered - * by the Web start classloader, we need to be able to remove the SecurityManager in place + * this means for Receivers that require optional jars that can't be delivered + * by the Web start classloader, we need to be able to remove the SecurityManager in place */ private boolean okToRemoveSecurityManager = false; private static final int CONFIGURATION_URL_ENTRY_COUNT = 10; @@ -77,7 +75,7 @@ public class ApplicationPreferenceModel { private boolean defaultColumnsSet; private boolean bypassSearchColors = false; - /** + /** * @param listener */ public void addPropertyChangeListener(PropertyChangeListener listener) { @@ -89,7 +87,7 @@ public class ApplicationPreferenceModel { * @param listener */ public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { + PropertyChangeListener listener) { propertySupport.addPropertyChangeListener(propertyName, listener); } @@ -99,7 +97,7 @@ public class ApplicationPreferenceModel { * @param newValue */ private void firePropertyChange(String propertyName, boolean oldValue, - boolean newValue) { + boolean newValue) { propertySupport.firePropertyChange(propertyName, oldValue, newValue); } @@ -109,7 +107,7 @@ public class ApplicationPreferenceModel { * @param newValue */ private void firePropertyChange(String propertyName, int oldValue, - int newValue) { + int newValue) { propertySupport.firePropertyChange(propertyName, oldValue, newValue); } @@ -119,7 +117,7 @@ public class ApplicationPreferenceModel { * @param newValue */ private void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { + Object newValue) { propertySupport.firePropertyChange(propertyName, oldValue, newValue); } @@ -145,7 +143,7 @@ public class ApplicationPreferenceModel { return showNoReceiverWarning; } - + public final String getIdentifierExpression() { return identifierExpression; } @@ -155,7 +153,7 @@ public class ApplicationPreferenceModel { cyclicBufferSize = newCyclicBufferSize; firePropertyChange("cyclicBufferSize", oldCyclicBufferSize, newCyclicBufferSize); } - + public final int getCyclicBufferSize() { return cyclicBufferSize; } @@ -165,13 +163,13 @@ public class ApplicationPreferenceModel { toolTipDisplayMillis = newToolTipDisplayMillis; firePropertyChange("toolTipDisplayMillis", oldToolTipDisplayMillis, newToolTipDisplayMillis); } - + public final int getToolTipDisplayMillis() { return toolTipDisplayMillis; } public final void setIdentifierExpression(String newIdentifierExpression) { - String oldIdentifierExpression=identifierExpression; + String oldIdentifierExpression = identifierExpression; this.identifierExpression = newIdentifierExpression; firePropertyChange("identifierExpression", oldIdentifierExpression, newIdentifierExpression); } @@ -180,7 +178,7 @@ public class ApplicationPreferenceModel { * @param newShowNoReceiverWarning The showNoReceiverWarning to set. */ public final void setShowNoReceiverWarning(boolean newShowNoReceiverWarning) { - boolean oldShowNoReceiverWarning=showNoReceiverWarning; + boolean oldShowNoReceiverWarning = showNoReceiverWarning; this.showNoReceiverWarning = newShowNoReceiverWarning; firePropertyChange("showNoReceiverWarning", oldShowNoReceiverWarning, newShowNoReceiverWarning); } @@ -188,54 +186,54 @@ public class ApplicationPreferenceModel { /** * Takes another model and copies all the values into this model + * * @param model */ - public void apply(ApplicationPreferenceModel model) - { - setIdentifierExpression(model.getIdentifierExpression()); - setShowNoReceiverWarning(model.isShowNoReceiverWarning() || (model.getConfigurationURL() == null || model.getConfigurationURL().trim().equals(""))); - setResponsiveness(model.getResponsiveness()); - setTabPlacement(model.getTabPlacement()); - setStatusBar(model.isStatusBar()); - setToolbar(model.isToolbar()); - setReceivers(model.isReceivers()); - if (model.getLookAndFeelClassName() != null && !model.getLookAndFeelClassName().trim().equals("")) { - setLookAndFeelClassName(model.getLookAndFeelClassName()); - } else { - //ensure current look and feel is selected - setLookAndFeelClassName(UIManager.getLookAndFeel().getClass().getName()); - } - setConfirmExit(model.isConfirmExit()); - setShowSplash(model.isShowSplash()); - setToolTipDisplayMillis(model.getToolTipDisplayMillis()); - setCyclicBufferSize(model.getCyclicBufferSize()); - Vector<String> configurationURLs = model.getConfigurationURLs(); - if (configurationURLs != null) { - setConfigurationURLs(configurationURLs); - } - //only set current config URL if bypass is null - if (model.getBypassConfigurationURL() == null) { - setConfigurationURL(model.getConfigurationURL()); - } - setLastUsedVersion(model.getLastUsedVersion()); - setOkToRemoveSecurityManager(model.isOkToRemoveSecurityManager()); - Color searchForeground = model.getSearchForegroundColor(); - Color searchBackground = model.getSearchBackgroundColor(); - if (searchForeground != null && searchBackground != null) { - setSearchBackgroundColor(searchBackground); - setSearchForegroundColor(searchForeground); - } - - Color alternatingForeground = model.getAlternatingColorForegroundColor(); - Color alternatingBackground = model.getAlternatingColorBackgroundColor(); - if (alternatingForeground != null && alternatingBackground != null) { - setAlternatingBackgroundColor(alternatingBackground); - setAlternatingForegroundColor(alternatingForeground); - } - if (model.isDefaultColumnsSet()) { - setDefaultColumnNames(model.getDefaultColumnNames()); - } - setBypassSearchColors(model.isBypassSearchColors()); + public void apply(ApplicationPreferenceModel model) { + setIdentifierExpression(model.getIdentifierExpression()); + setShowNoReceiverWarning(model.isShowNoReceiverWarning() || (model.getConfigurationURL() == null || model.getConfigurationURL().trim().equals(""))); + setResponsiveness(model.getResponsiveness()); + setTabPlacement(model.getTabPlacement()); + setStatusBar(model.isStatusBar()); + setToolbar(model.isToolbar()); + setReceivers(model.isReceivers()); + if (model.getLookAndFeelClassName() != null && !model.getLookAndFeelClassName().trim().equals("")) { + setLookAndFeelClassName(model.getLookAndFeelClassName()); + } else { + //ensure current look and feel is selected + setLookAndFeelClassName(UIManager.getLookAndFeel().getClass().getName()); + } + setConfirmExit(model.isConfirmExit()); + setShowSplash(model.isShowSplash()); + setToolTipDisplayMillis(model.getToolTipDisplayMillis()); + setCyclicBufferSize(model.getCyclicBufferSize()); + Vector<String> configurationURLs = model.getConfigurationURLs(); + if (configurationURLs != null) { + setConfigurationURLs(configurationURLs); + } + //only set current config URL if bypass is null + if (model.getBypassConfigurationURL() == null) { + setConfigurationURL(model.getConfigurationURL()); + } + setLastUsedVersion(model.getLastUsedVersion()); + setOkToRemoveSecurityManager(model.isOkToRemoveSecurityManager()); + Color searchForeground = model.getSearchForegroundColor(); + Color searchBackground = model.getSearchBackgroundColor(); + if (searchForeground != null && searchBackground != null) { + setSearchBackgroundColor(searchBackground); + setSearchForegroundColor(searchForeground); + } + + Color alternatingForeground = model.getAlternatingColorForegroundColor(); + Color alternatingBackground = model.getAlternatingColorBackgroundColor(); + if (alternatingForeground != null && alternatingBackground != null) { + setAlternatingBackgroundColor(alternatingBackground); + setAlternatingForegroundColor(alternatingForeground); + } + if (model.isDefaultColumnsSet()) { + setDefaultColumnNames(model.getDefaultColumnNames()); + } + setBypassSearchColors(model.isBypassSearchColors()); } //use a lighter version of search color as the delta color @@ -243,58 +241,58 @@ public class ApplicationPreferenceModel { float factor = 1.3F; Color search = getSearchBackgroundColor(); - return new Color(boundColorValue((int)(search.getRed() * factor)), - boundColorValue((int)(search.getGreen() * factor)), - boundColorValue((int)(search.getBlue() * factor))); + return new Color(boundColorValue((int) (search.getRed() * factor)), + boundColorValue((int) (search.getGreen() * factor)), + boundColorValue((int) (search.getBlue() * factor))); } private int boundColorValue(int colorValue) { - return Math.min(Math.max(0, colorValue), 255); + return Math.min(Math.max(0, colorValue), 255); } /** * @return Returns the responsiveness. */ - public final int getResponsiveness() - { - return responsiveness; + public final int getResponsiveness() { + return responsiveness; } + /** * @param newValue The responsiveness to set. */ - public final void setResponsiveness(int newValue) - { - int oldvalue = responsiveness; - - if (newValue >= 1000) { - responsiveness = (newValue - 750) / 1000; - } else { - responsiveness = newValue; - } - firePropertyChange("responsiveness", oldvalue, responsiveness); + public final void setResponsiveness(int newValue) { + int oldvalue = responsiveness; + + if (newValue >= 1000) { + responsiveness = (newValue - 750) / 1000; + } else { + responsiveness = newValue; + } + firePropertyChange("responsiveness", oldvalue, responsiveness); } /** * @param i */ public void setTabPlacement(int i) { - int oldValue = this.tabPlacement; - this.tabPlacement = i; - firePropertyChange("tabPlacement",oldValue,this.tabPlacement); + int oldValue = this.tabPlacement; + this.tabPlacement = i; + firePropertyChange("tabPlacement", oldValue, this.tabPlacement); } + /** * @return Returns the tabPlacement. */ public final int getTabPlacement() { - return tabPlacement; + return tabPlacement; } /** * @return Returns the statusBar. */ public final boolean isStatusBar() { - return statusBar; + return statusBar; } public Vector<String> getConfigurationURLs() { @@ -311,9 +309,9 @@ public class ApplicationPreferenceModel { * @param statusBar The statusBar to set. */ public final void setStatusBar(boolean statusBar) { - boolean oldValue = this.statusBar; - this.statusBar = statusBar; - firePropertyChange("statusBar", oldValue, this.statusBar); + boolean oldValue = this.statusBar; + this.statusBar = statusBar; + firePropertyChange("statusBar", oldValue, this.statusBar); } public void setAlternatingForegroundColor(Color alternatingColorForegroundColor) { @@ -355,92 +353,94 @@ public class ApplicationPreferenceModel { /** * @return Returns the receivers. */ - public final boolean isReceivers() - { - return receivers; + public final boolean isReceivers() { + return receivers; } + /** * @param receivers The receivers to set. */ - public final void setReceivers(boolean receivers) - { - boolean oldValue = this.receivers; - this.receivers = receivers; - firePropertyChange("receivers", oldValue, this.receivers); + public final void setReceivers(boolean receivers) { + boolean oldValue = this.receivers; + this.receivers = receivers; + firePropertyChange("receivers", oldValue, this.receivers); } + /** * @return Returns the toolbar. */ - public final boolean isToolbar() - { - return toolbar; + public final boolean isToolbar() { + return toolbar; } + /** * @param toolbar The toolbar to set. */ - public final void setToolbar(boolean toolbar) - { - boolean oldValue = this.toolbar; - this.toolbar = toolbar; - firePropertyChange("toolbar", oldValue, this.toolbar); + public final void setToolbar(boolean toolbar) { + boolean oldValue = this.toolbar; + this.toolbar = toolbar; + firePropertyChange("toolbar", oldValue, this.toolbar); } + /** * @return Returns the lookAndFeelClassName. */ public final String getLookAndFeelClassName() { - return lookAndFeelClassName; + return lookAndFeelClassName; } /** * @param lookAndFeelClassName The lookAndFeelClassName to set. */ public final void setLookAndFeelClassName(String lookAndFeelClassName) { - String oldValue = this.lookAndFeelClassName; - this.lookAndFeelClassName = lookAndFeelClassName; - firePropertyChange("lookAndFeelClassName", oldValue, this.lookAndFeelClassName); + String oldValue = this.lookAndFeelClassName; + this.lookAndFeelClassName = lookAndFeelClassName; + firePropertyChange("lookAndFeelClassName", oldValue, this.lookAndFeelClassName); } /** * @return Returns the confirmExit. */ public final boolean isConfirmExit() { - return confirmExit; + return confirmExit; } /** * @param confirmExit The confirmExit to set. */ public final void setConfirmExit(boolean confirmExit) { - boolean oldValue = this.confirmExit; - this.confirmExit = confirmExit; - firePropertyChange("confirmExit", oldValue, this.confirmExit); + boolean oldValue = this.confirmExit; + this.confirmExit = confirmExit; + firePropertyChange("confirmExit", oldValue, this.confirmExit); } /** * @return Returns the showSplash. */ public final boolean isShowSplash() { - return showSplash; + return showSplash; } + /** * @param showSplash The showSplash to set. */ public final void setShowSplash(boolean showSplash) { - boolean oldValue = this.showSplash; - this.showSplash = showSplash; - firePropertyChange("showSplash", oldValue,this.showSplash); + boolean oldValue = this.showSplash; + this.showSplash = showSplash; + firePropertyChange("showSplash", oldValue, this.showSplash); } + /** * @return Returns the configurationURL. */ - public final String getConfigurationURL() - { + public final String getConfigurationURL() { return this.configurationURL; } public final String getBypassConfigurationURL() { return bypassConfigurationURL; } + /* Set to null to un-bypass */ @@ -455,10 +455,9 @@ public class ApplicationPreferenceModel { /** * @param configurationURL The configurationURL to set. */ - public final void setConfigurationURL(String configurationURL) - { + public final void setConfigurationURL(String configurationURL) { //don't add empty entries, but allow the current configuration URL to be set to an empty string - Object oldValue = this.bypassConfigurationURL != null? this.bypassConfigurationURL:this.configurationURL; + Object oldValue = this.bypassConfigurationURL != null ? this.bypassConfigurationURL : this.configurationURL; bypassConfigurationURL = null; if (configurationURL == null || configurationURL.trim().equals("")) { this.configurationURL = ""; @@ -467,65 +466,66 @@ public class ApplicationPreferenceModel { } //add entry to MRU list if (!configurationURLs.contains(configurationURL)) { - if (configurationURLs.size() == CONFIGURATION_URL_ENTRY_COUNT) { - configurationURLs.remove(CONFIGURATION_URL_ENTRY_COUNT - 1); - } - configurationURLs.add(0, configurationURL); + if (configurationURLs.size() == CONFIGURATION_URL_ENTRY_COUNT) { + configurationURLs.remove(CONFIGURATION_URL_ENTRY_COUNT - 1); + } + configurationURLs.add(0, configurationURL); } - this.configurationURL = configurationURL; - firePropertyChange("configurationURL", oldValue, this.configurationURL); + this.configurationURL = configurationURL; + firePropertyChange("configurationURL", oldValue, this.configurationURL); } + /** * @return Returns the lastUsedVersion. */ - public final String getLastUsedVersion() - { + public final String getLastUsedVersion() { return this.lastUsedVersion; } + /** * @param lastUsedVersion The lastUsedVersion to set. */ - public final void setLastUsedVersion(String lastUsedVersion) - { + public final void setLastUsedVersion(String lastUsedVersion) { String oldValue = this.lastUsedVersion; this.lastUsedVersion = lastUsedVersion; firePropertyChange("lastUsedVersion", oldValue, this.lastUsedVersion); } - /** - * @return ok to remove security manager flag - */ - public final boolean isOkToRemoveSecurityManager() { - return this.okToRemoveSecurityManager; - } - /** - * @param okToRemoveSecurityManager The okToRemoveSecurityManager to set. - */ - public final void setOkToRemoveSecurityManager(boolean okToRemoveSecurityManager) { - boolean oldValue = this.okToRemoveSecurityManager; + /** + * @return ok to remove security manager flag + */ + public final boolean isOkToRemoveSecurityManager() { + return this.okToRemoveSecurityManager; + } + + /** + * @param okToRemoveSecurityManager The okToRemoveSecurityManager to set. + */ + public final void setOkToRemoveSecurityManager(boolean okToRemoveSecurityManager) { + boolean oldValue = this.okToRemoveSecurityManager; this.okToRemoveSecurityManager = okToRemoveSecurityManager; firePropertyChange("okToRemoveSecurityManager", oldValue, this.okToRemoveSecurityManager); - } + } - public void setDefaultColumnNames(List defaultColumnNames) { - defaultColumnsSet = true; - this.defaultColumnNames.clear(); - this.defaultColumnNames.addAll(defaultColumnNames); - } + public void setDefaultColumnNames(List defaultColumnNames) { + defaultColumnsSet = true; + this.defaultColumnNames.clear(); + this.defaultColumnNames.addAll(defaultColumnNames); + } - public boolean isDefaultColumnsSet() { - return defaultColumnsSet; - } + public boolean isDefaultColumnsSet() { + return defaultColumnsSet; + } - public List getDefaultColumnNames() { - return defaultColumnNames; - } + public List getDefaultColumnNames() { + return defaultColumnNames; + } - public void setBypassSearchColors(boolean bypassSearchColors) { - this.bypassSearchColors = bypassSearchColors; - } + public void setBypassSearchColors(boolean bypassSearchColors) { + this.bypassSearchColors = bypassSearchColors; + } - public boolean isBypassSearchColors() { - return bypassSearchColors; - } + public boolean isBypassSearchColors() { + return bypassSearchColors; + } }
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java index 9e440c6..beb86dc 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java +++ b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.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,630 +17,608 @@ package org.apache.log4j.chainsaw; -import java.awt.Dimension; -import java.awt.FlowLayout; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.chainsaw.helper.SwingHelper; +import org.apache.log4j.chainsaw.osx.OSXIntegration; + +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeModel; +import java.awt.*; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; - import java.util.Locale; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; -import javax.swing.DefaultComboBoxModel; -import javax.swing.InputVerifier; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JSlider; -import javax.swing.JTextField; -import javax.swing.SwingConstants; -import javax.swing.UIManager; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeModel; - -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.chainsaw.helper.SwingHelper; -import org.apache.log4j.chainsaw.osx.OSXIntegration; /** * A panel used by the user to modify any application-wide preferences. * * @author Paul Smith <psm...@apache.org> - * */ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel { - private ApplicationPreferenceModel committedPreferenceModel; - private ApplicationPreferenceModel uncommittedPreferenceModel = - new ApplicationPreferenceModel(); - private JTextField identifierExpression; - private JTextField toolTipDisplayMillis; - private JTextField cyclicBufferSize; - private JComboBox<String> configurationURL; - private final Logger logger; - private GeneralAllPrefPanel generalAllPrefPanel; + private ApplicationPreferenceModel committedPreferenceModel; + private ApplicationPreferenceModel uncommittedPreferenceModel = + new ApplicationPreferenceModel(); + private JTextField identifierExpression; + private JTextField toolTipDisplayMillis; + private JTextField cyclicBufferSize; + private JComboBox<String> configurationURL; + private final Logger logger; + private GeneralAllPrefPanel generalAllPrefPanel; ApplicationPreferenceModelPanel(ApplicationPreferenceModel model) { - this.committedPreferenceModel = model; - logger = LogManager.getLogger(ApplicationPreferenceModelPanel.class); - initComponents(); - getOkButton().addActionListener( + this.committedPreferenceModel = model; + logger = LogManager.getLogger(ApplicationPreferenceModelPanel.class); + initComponents(); + getOkButton().addActionListener( e -> { - uncommittedPreferenceModel.setConfigurationURL((String)configurationURL.getSelectedItem()); - uncommittedPreferenceModel.setIdentifierExpression( - identifierExpression.getText()); + uncommittedPreferenceModel.setConfigurationURL((String) configurationURL.getSelectedItem()); + uncommittedPreferenceModel.setIdentifierExpression( + identifierExpression.getText()); try { int millis = Integer.parseInt(toolTipDisplayMillis.getText()); if (millis >= 0) { uncommittedPreferenceModel.setToolTipDisplayMillis(millis); } - } catch (NumberFormatException nfe) {} + } catch (NumberFormatException nfe) { + } try { int bufferSize = Integer.parseInt(cyclicBufferSize.getText()); if (bufferSize >= 0) { uncommittedPreferenceModel.setCyclicBufferSize(bufferSize); } - } catch (NumberFormatException nfe) {} - committedPreferenceModel.apply(uncommittedPreferenceModel); - hidePanel(); + } catch (NumberFormatException nfe) { + } + committedPreferenceModel.apply(uncommittedPreferenceModel); + hidePanel(); }); - getCancelButton().addActionListener( + getCancelButton().addActionListener( e -> { - uncommittedPreferenceModel.apply(committedPreferenceModel); - hidePanel(); + uncommittedPreferenceModel.apply(committedPreferenceModel); + 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); + 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(System.out::println); - panel.setOkCancelActionListener( + model.addPropertyChangeListener(System.out::println); + panel.setOkCancelActionListener( e -> System.exit(1)); - f.setSize(640, 480); - f.setVisible(true); - } + f.setSize(640, 480); + f.setVisible(true); + } - /** - * Ensures this panels DISPLAYED model is in sync with - * the model initially passed to the constructor. - * - */ - public void updateModel() { - this.uncommittedPreferenceModel.apply(committedPreferenceModel); - } + /** + * 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); + /* (non-Javadoc) + * @see org.apache.log4j.chainsaw.AbstractPreferencePanel#createTreeModel() + */ + protected TreeModel createTreeModel() { + final DefaultMutableTreeNode rootNode = + new DefaultMutableTreeNode("Preferences"); + DefaultTreeModel model = new DefaultTreeModel(rootNode); - generalAllPrefPanel = new GeneralAllPrefPanel(); - DefaultMutableTreeNode general = - new DefaultMutableTreeNode(generalAllPrefPanel); + generalAllPrefPanel = new GeneralAllPrefPanel(); + DefaultMutableTreeNode general = + new DefaultMutableTreeNode(generalAllPrefPanel); - DefaultMutableTreeNode visuals = - new DefaultMutableTreeNode(new VisualsPrefPanel()); + DefaultMutableTreeNode visuals = + new DefaultMutableTreeNode(new VisualsPrefPanel()); - rootNode.add(general); - rootNode.add(visuals); + rootNode.add(general); + rootNode.add(visuals); - return model; - } + return model; + } public class VisualsPrefPanel extends BasicPrefPanel { - private final JRadioButton topPlacement = new JRadioButton(" Top "); - private final JRadioButton bottomPlacement = new JRadioButton(" Bottom "); - private final JCheckBox statusBar = new JCheckBox(" Show Status bar "); - private final JCheckBox toolBar = new JCheckBox(" Show Toolbar "); - private final JCheckBox receivers = new JCheckBox(" Show Receivers "); - private UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels(); - private final ButtonGroup lookAndFeelGroup = new ButtonGroup(); - - private VisualsPrefPanel() { - super("Visuals"); - - //Nimbus has major issues with colors in tables..just remove it from the list.. - //only use this if nimbus was found.. - UIManager.LookAndFeelInfo[] newLookAndFeels = new UIManager.LookAndFeelInfo[lookAndFeels.length]; - boolean useNewLookAndFeels = false; - int j = 0; - for (UIManager.LookAndFeelInfo lookAndFeel : lookAndFeels) { - if (lookAndFeel.getClassName().toLowerCase(Locale.ENGLISH).contains("nimbus")) { - useNewLookAndFeels = true; - } else { - newLookAndFeels[j++] = lookAndFeel; + private final JRadioButton topPlacement = new JRadioButton(" Top "); + private final JRadioButton bottomPlacement = new JRadioButton(" Bottom "); + private final JCheckBox statusBar = new JCheckBox(" Show Status bar "); + private final JCheckBox toolBar = new JCheckBox(" Show Toolbar "); + private final JCheckBox receivers = new JCheckBox(" Show Receivers "); + private UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels(); + private final ButtonGroup lookAndFeelGroup = new ButtonGroup(); + + private VisualsPrefPanel() { + super("Visuals"); + + //Nimbus has major issues with colors in tables..just remove it from the list.. + //only use this if nimbus was found.. + UIManager.LookAndFeelInfo[] newLookAndFeels = new UIManager.LookAndFeelInfo[lookAndFeels.length]; + boolean useNewLookAndFeels = false; + int j = 0; + for (UIManager.LookAndFeelInfo lookAndFeel : lookAndFeels) { + if (lookAndFeel.getClassName().toLowerCase(Locale.ENGLISH).contains("nimbus")) { + useNewLookAndFeels = true; + } else { + newLookAndFeels[j++] = lookAndFeel; + } } + if (useNewLookAndFeels) { + UIManager.LookAndFeelInfo[] replacedLookAndFeels = new UIManager.LookAndFeelInfo[lookAndFeels.length - 1]; + System.arraycopy(newLookAndFeels, 0, replacedLookAndFeels, 0, newLookAndFeels.length - 1); + lookAndFeels = replacedLookAndFeels; + } + + setupComponents(); + setupListeners(); + setupInitialValues(); } - if (useNewLookAndFeels) { - UIManager.LookAndFeelInfo[] replacedLookAndFeels = new UIManager.LookAndFeelInfo[lookAndFeels.length - 1]; - System.arraycopy(newLookAndFeels, 0, replacedLookAndFeels, 0, newLookAndFeels.length - 1); - lookAndFeels = replacedLookAndFeels; - } - - setupComponents(); - setupListeners(); - setupInitialValues(); - } - /** - * - */ - private void setupListeners() { - topPlacement.addActionListener( - e -> uncommittedPreferenceModel.setTabPlacement(SwingConstants.TOP)); - bottomPlacement.addActionListener( - e -> uncommittedPreferenceModel.setTabPlacement(SwingConstants.BOTTOM)); + /** + * + */ + private void setupListeners() { + topPlacement.addActionListener( + e -> uncommittedPreferenceModel.setTabPlacement(SwingConstants.TOP)); + bottomPlacement.addActionListener( + e -> uncommittedPreferenceModel.setTabPlacement(SwingConstants.BOTTOM)); - statusBar.addActionListener( - e -> uncommittedPreferenceModel.setStatusBar(statusBar.isSelected())); + statusBar.addActionListener( + e -> uncommittedPreferenceModel.setStatusBar(statusBar.isSelected())); - toolBar.addActionListener( - e -> uncommittedPreferenceModel.setToolbar(toolBar.isSelected())); + toolBar.addActionListener( + e -> uncommittedPreferenceModel.setToolbar(toolBar.isSelected())); - receivers.addActionListener( - e -> uncommittedPreferenceModel.setReceivers(receivers.isSelected())); + receivers.addActionListener( + e -> uncommittedPreferenceModel.setReceivers(receivers.isSelected())); - uncommittedPreferenceModel.addPropertyChangeListener( - "tabPlacement", - evt -> { - int value = (Integer) evt.getNewValue(); + uncommittedPreferenceModel.addPropertyChangeListener( + "tabPlacement", + evt -> { + int value = (Integer) evt.getNewValue(); - configureTabPlacement(value); - }); + configureTabPlacement(value); + }); - uncommittedPreferenceModel.addPropertyChangeListener( - "statusBar", - evt -> statusBar.setSelected( - (Boolean) evt.getNewValue())); + uncommittedPreferenceModel.addPropertyChangeListener( + "statusBar", + evt -> statusBar.setSelected( + (Boolean) evt.getNewValue())); - uncommittedPreferenceModel.addPropertyChangeListener( - "toolbar", - evt -> toolBar.setSelected((Boolean) evt.getNewValue())); + uncommittedPreferenceModel.addPropertyChangeListener( + "toolbar", + evt -> toolBar.setSelected((Boolean) evt.getNewValue())); - uncommittedPreferenceModel.addPropertyChangeListener( - "receivers", - evt -> receivers.setSelected( - (Boolean) evt.getNewValue())); + uncommittedPreferenceModel.addPropertyChangeListener( + "receivers", + evt -> receivers.setSelected( + (Boolean) evt.getNewValue())); - uncommittedPreferenceModel.addPropertyChangeListener( - "lookAndFeelClassName", - evt -> { - String lf = evt.getNewValue().toString(); + uncommittedPreferenceModel.addPropertyChangeListener( + "lookAndFeelClassName", + evt -> { + String lf = evt.getNewValue().toString(); - Enumeration enumeration = lookAndFeelGroup.getElements(); + Enumeration enumeration = lookAndFeelGroup.getElements(); - while (enumeration.hasMoreElements()) { - JRadioButton button = (JRadioButton) enumeration.nextElement(); + while (enumeration.hasMoreElements()) { + JRadioButton button = (JRadioButton) enumeration.nextElement(); - if (button.getName()!=null && button.getName().equals(lf)) { - button.setSelected(true); + if (button.getName() != null && button.getName().equals(lf)) { + button.setSelected(true); - break; - } - } - }); - } + break; + } + } + }); + } - /** - * - */ - private void setupComponents() { - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - JPanel tabPlacementBox = new JPanel(); - tabPlacementBox.setLayout(new BoxLayout(tabPlacementBox, BoxLayout.Y_AXIS)); - - tabPlacementBox.setBorder(BorderFactory.createTitledBorder(" Tab Placement ")); - - ButtonGroup tabPlacementGroup = new ButtonGroup(); - - tabPlacementGroup.add(topPlacement); - tabPlacementGroup.add(bottomPlacement); - - tabPlacementBox.add(topPlacement); - tabPlacementBox.add(bottomPlacement); - - /** - * If we're OSX, we're 'not allowed' to change the tab placement... - */ - if(OSXIntegration.IS_OSX) { - tabPlacementBox.setEnabled(false); - topPlacement.setEnabled(false); - bottomPlacement.setEnabled(false); - } - - add(tabPlacementBox); - add(statusBar); - add(receivers); - add(toolBar); - - JPanel lfPanel = new JPanel(); - lfPanel.setLayout(new BoxLayout(lfPanel, BoxLayout.Y_AXIS)); - lfPanel.setBorder(BorderFactory.createTitledBorder(" Look & Feel ")); - - for (final UIManager.LookAndFeelInfo lfInfo : lookAndFeels) { - final JRadioButton lfItem = new JRadioButton(" " + lfInfo.getName() + " "); - lfItem.setName(lfInfo.getClassName()); - lfItem.addActionListener( + /** + * + */ + private void setupComponents() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + JPanel tabPlacementBox = new JPanel(); + tabPlacementBox.setLayout(new BoxLayout(tabPlacementBox, BoxLayout.Y_AXIS)); + + tabPlacementBox.setBorder(BorderFactory.createTitledBorder(" Tab Placement ")); + + ButtonGroup tabPlacementGroup = new ButtonGroup(); + + tabPlacementGroup.add(topPlacement); + tabPlacementGroup.add(bottomPlacement); + + tabPlacementBox.add(topPlacement); + tabPlacementBox.add(bottomPlacement); + + /** + * If we're OSX, we're 'not allowed' to change the tab placement... + */ + if (OSXIntegration.IS_OSX) { + tabPlacementBox.setEnabled(false); + topPlacement.setEnabled(false); + bottomPlacement.setEnabled(false); + } + + add(tabPlacementBox); + add(statusBar); + add(receivers); + add(toolBar); + + JPanel lfPanel = new JPanel(); + lfPanel.setLayout(new BoxLayout(lfPanel, BoxLayout.Y_AXIS)); + lfPanel.setBorder(BorderFactory.createTitledBorder(" Look & Feel ")); + + for (final UIManager.LookAndFeelInfo lfInfo : lookAndFeels) { + final JRadioButton lfItem = new JRadioButton(" " + lfInfo.getName() + " "); + lfItem.setName(lfInfo.getClassName()); + lfItem.addActionListener( e -> uncommittedPreferenceModel.setLookAndFeelClassName( - lfInfo.getClassName())); - lookAndFeelGroup.add(lfItem); - lfPanel.add(lfItem); + lfInfo.getClassName())); + lookAndFeelGroup.add(lfItem); + lfPanel.add(lfItem); + } + + try { + final Class gtkLF = + Class.forName("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); + final JRadioButton lfIGTK = new JRadioButton(" GTK+ 2.0 "); + lfIGTK.addActionListener( + e -> uncommittedPreferenceModel.setLookAndFeelClassName( + gtkLF.getName())); + lookAndFeelGroup.add(lfIGTK); + lfPanel.add(lfIGTK); + } catch (Exception e) { + logger.debug("Can't find new GTK L&F, might be Windows, or <JDK1.4.2"); + } + + add(lfPanel); + + add( + new JLabel( + "<html>Look and Feel change will apply the next time you start Chainsaw.<br>" + + "If this value is not set, the default L&F of your system is used.</html>")); } - try { - final Class gtkLF = - Class.forName("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); - final JRadioButton lfIGTK = new JRadioButton(" GTK+ 2.0 "); - lfIGTK.addActionListener( - e -> uncommittedPreferenceModel.setLookAndFeelClassName( - gtkLF.getName())); - lookAndFeelGroup.add(lfIGTK); - lfPanel.add(lfIGTK); - } catch (Exception e) { - logger.debug("Can't find new GTK L&F, might be Windows, or <JDK1.4.2"); - } - - add(lfPanel); - - add( - new JLabel( - "<html>Look and Feel change will apply the next time you start Chainsaw.<br>" + - "If this value is not set, the default L&F of your system is used.</html>")); - } - private void configureTabPlacement(int value) { - switch (value) { - case SwingConstants.TOP: - topPlacement.setSelected(true); + private void configureTabPlacement(int value) { + switch (value) { + case SwingConstants.TOP: + topPlacement.setSelected(true); - break; + break; - case SwingConstants.BOTTOM: - bottomPlacement.setSelected(true); + case SwingConstants.BOTTOM: + bottomPlacement.setSelected(true); - break; + break; - default: - break; + default: + break; + } } - } - private void setupInitialValues() { - statusBar.setSelected(uncommittedPreferenceModel.isStatusBar()); - receivers.setSelected(uncommittedPreferenceModel.isReceivers()); - toolBar.setSelected(uncommittedPreferenceModel.isToolbar()); - configureTabPlacement(uncommittedPreferenceModel.getTabPlacement()); - Enumeration e = lookAndFeelGroup.getElements(); - while(e.hasMoreElements()) { - JRadioButton radioButton = (JRadioButton)e.nextElement(); - if(radioButton.getText().equals(uncommittedPreferenceModel.getLookAndFeelClassName())) { - radioButton.setSelected(true); - break; + + private void setupInitialValues() { + statusBar.setSelected(uncommittedPreferenceModel.isStatusBar()); + receivers.setSelected(uncommittedPreferenceModel.isReceivers()); + toolBar.setSelected(uncommittedPreferenceModel.isToolbar()); + configureTabPlacement(uncommittedPreferenceModel.getTabPlacement()); + Enumeration e = lookAndFeelGroup.getElements(); + while (e.hasMoreElements()) { + JRadioButton radioButton = (JRadioButton) e.nextElement(); + if (radioButton.getText().equals(uncommittedPreferenceModel.getLookAndFeelClassName())) { + radioButton.setSelected(true); + break; + } } } } - } - - /** - * @author psmith - * - */ - public class GeneralAllPrefPanel extends BasicPrefPanel { - private final JCheckBox showNoReceiverWarning = - new JCheckBox(" Prompt me on startup if there are no Receivers defined "); - private final JCheckBox showSplash = new JCheckBox(" Show Splash screen at startup "); - private final JSlider responsiveSlider = - new JSlider(SwingConstants.HORIZONTAL, 1, 4, 2); - private final JCheckBox confirmExit = new JCheckBox(" Confirm Exit "); - Dictionary<Integer, JLabel> sliderLabelMap = new Hashtable<>(); - - private final JCheckBox okToRemoveSecurityManager = new JCheckBox(" Ok to remove SecurityManager "); - - public GeneralAllPrefPanel() { - super("General"); - - GeneralAllPrefPanel.this.initComponents(); - } - private void initComponents() { - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - configurationURL = new JComboBox<>(new DefaultComboBoxModel<>(committedPreferenceModel.getConfigurationURLs())); - configurationURL.setEditable(true); - configurationURL.setPrototypeDisplayValue("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - configurationURL.setPreferredSize(new Dimension(375, 13)); - - identifierExpression = new JTextField(30); - toolTipDisplayMillis = new JTextField(8); - cyclicBufferSize = new JTextField(8); - Box p = new Box(BoxLayout.X_AXIS); - - p.add(showNoReceiverWarning); - p.add(Box.createHorizontalGlue()); - - confirmExit.setToolTipText("If set, you prompt to confirm Chainsaw exit"); - okToRemoveSecurityManager.setToolTipText("You will need to tick this to be able to load Receivers/Plugins that require external dependancies."); - setupInitialValues(); - setupListeners(); - - initSliderComponent(); - add(responsiveSlider); - - JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - p1.add(new JLabel(" Tab name/event routing expression ")); - p1.add(Box.createHorizontalStrut(5)); - p1.add(identifierExpression); - add(p1); - add(p); - - Box p2 = new Box(BoxLayout.X_AXIS); - p2.add(confirmExit); - p2.add(Box.createHorizontalGlue()); - - Box p3 = new Box(BoxLayout.X_AXIS); - p3.add(showSplash); - p3.add(Box.createHorizontalGlue()); - - Box ok4 = new Box(BoxLayout.X_AXIS); - ok4.add(okToRemoveSecurityManager); - ok4.add(Box.createHorizontalGlue()); - - add(p2); - add(p3); - add(ok4); - - JPanel p4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - p4.add(new JLabel(" ToolTip Display (millis) ")); - p4.add(Box.createHorizontalStrut(5)); - p4.add(toolTipDisplayMillis); - add(p4); - - JPanel p5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - p5.add(new JLabel(" Cyclic buffer size ")); - p5.add(Box.createHorizontalStrut(5)); - p5.add(cyclicBufferSize); - p5.add(Box.createHorizontalStrut(5)); - p5.add(new JLabel(" (effective on restart) ")); - add(p5); - - Box p6 = new Box(BoxLayout.Y_AXIS); - - Box configURLPanel = new Box(BoxLayout.X_AXIS); - JLabel configLabel = new JLabel(" Auto Config URL "); - configURLPanel.add(configLabel); - configURLPanel.add(Box.createHorizontalStrut(5)); - - configURLPanel.add(configurationURL); - configURLPanel.add(Box.createHorizontalGlue()); - - p6.add(configURLPanel); - - JButton browseButton = new JButton(" Open File... "); - browseButton.addActionListener(e -> browseForConfiguration()); - Box browsePanel = new Box(BoxLayout.X_AXIS); - browsePanel.add(Box.createHorizontalGlue()); - browsePanel.add(browseButton); - p6.add(Box.createVerticalStrut(5)); - p6.add(browsePanel); - p6.add(Box.createVerticalGlue()); - add(p6); - - configurationURL.setToolTipText("A complete and valid URL identifying the location of a valid log4 xml configuration file to auto-configure Receivers and other Plugins"); - configurationURL.setInputVerifier(new InputVerifier() { - - public boolean verify(JComponent input) - { - try { - String selectedItem = (String)configurationURL.getSelectedItem(); - if (selectedItem != null && !(selectedItem.trim().equals(""))) { - new URL(selectedItem); + /** + * @author psmith + */ + public class GeneralAllPrefPanel extends BasicPrefPanel { + private final JCheckBox showNoReceiverWarning = + new JCheckBox(" Prompt me on startup if there are no Receivers defined "); + private final JCheckBox showSplash = new JCheckBox(" Show Splash screen at startup "); + private final JSlider responsiveSlider = + new JSlider(SwingConstants.HORIZONTAL, 1, 4, 2); + private final JCheckBox confirmExit = new JCheckBox(" Confirm Exit "); + Dictionary<Integer, JLabel> sliderLabelMap = new Hashtable<>(); + + private final JCheckBox okToRemoveSecurityManager = new JCheckBox(" Ok to remove SecurityManager "); + + public GeneralAllPrefPanel() { + super("General"); + + GeneralAllPrefPanel.this.initComponents(); + } + + private void initComponents() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + configurationURL = new JComboBox<>(new DefaultComboBoxModel<>(committedPreferenceModel.getConfigurationURLs())); + configurationURL.setEditable(true); + configurationURL.setPrototypeDisplayValue("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + configurationURL.setPreferredSize(new Dimension(375, 13)); + + identifierExpression = new JTextField(30); + toolTipDisplayMillis = new JTextField(8); + cyclicBufferSize = new JTextField(8); + Box p = new Box(BoxLayout.X_AXIS); + + p.add(showNoReceiverWarning); + p.add(Box.createHorizontalGlue()); + + confirmExit.setToolTipText("If set, you prompt to confirm Chainsaw exit"); + okToRemoveSecurityManager.setToolTipText("You will need to tick this to be able to load Receivers/Plugins that require external dependancies."); + setupInitialValues(); + setupListeners(); + + initSliderComponent(); + add(responsiveSlider); + + JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + p1.add(new JLabel(" Tab name/event routing expression ")); + p1.add(Box.createHorizontalStrut(5)); + p1.add(identifierExpression); + add(p1); + add(p); + + Box p2 = new Box(BoxLayout.X_AXIS); + p2.add(confirmExit); + p2.add(Box.createHorizontalGlue()); + + Box p3 = new Box(BoxLayout.X_AXIS); + p3.add(showSplash); + p3.add(Box.createHorizontalGlue()); + + Box ok4 = new Box(BoxLayout.X_AXIS); + ok4.add(okToRemoveSecurityManager); + ok4.add(Box.createHorizontalGlue()); + + add(p2); + add(p3); + add(ok4); + + JPanel p4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + p4.add(new JLabel(" ToolTip Display (millis) ")); + p4.add(Box.createHorizontalStrut(5)); + p4.add(toolTipDisplayMillis); + add(p4); + + JPanel p5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + p5.add(new JLabel(" Cyclic buffer size ")); + p5.add(Box.createHorizontalStrut(5)); + p5.add(cyclicBufferSize); + p5.add(Box.createHorizontalStrut(5)); + p5.add(new JLabel(" (effective on restart) ")); + add(p5); + + Box p6 = new Box(BoxLayout.Y_AXIS); + + Box configURLPanel = new Box(BoxLayout.X_AXIS); + JLabel configLabel = new JLabel(" Auto Config URL "); + configURLPanel.add(configLabel); + configURLPanel.add(Box.createHorizontalStrut(5)); + + configURLPanel.add(configurationURL); + configURLPanel.add(Box.createHorizontalGlue()); + + p6.add(configURLPanel); + + JButton browseButton = new JButton(" Open File... "); + browseButton.addActionListener(e -> browseForConfiguration()); + Box browsePanel = new Box(BoxLayout.X_AXIS); + browsePanel.add(Box.createHorizontalGlue()); + browsePanel.add(browseButton); + p6.add(Box.createVerticalStrut(5)); + p6.add(browsePanel); + p6.add(Box.createVerticalGlue()); + add(p6); + + configurationURL.setToolTipText("A complete and valid URL identifying the location of a valid log4 xml configuration file to auto-configure Receivers and other Plugins"); + configurationURL.setInputVerifier(new InputVerifier() { + + public boolean verify(JComponent input) { + try { + String selectedItem = (String) configurationURL.getSelectedItem(); + if (selectedItem != null && !(selectedItem.trim().equals(""))) { + new URL(selectedItem); + } + } catch (Exception e) { + return false; + } + return true; + } + }); + String configToDisplay = committedPreferenceModel.getBypassConfigurationURL() != null ? committedPreferenceModel.getBypassConfigurationURL() : committedPreferenceModel.getConfigurationURL(); + configurationURL.setSelectedItem(configToDisplay); + } + + public void browseForConfiguration() { + String defaultPath = "."; + if (configurationURL.getItemCount() > 0) { + Object selectedItem = configurationURL.getSelectedItem(); + if (selectedItem != null) { + File currentConfigurationPath = new File(selectedItem.toString()).getParentFile(); + if (currentConfigurationPath != null) { + defaultPath = currentConfigurationPath.getPath(); + //FileDialog will not navigate to this location unless we remove the prefixing protocol and slash + //at least on winxp + if (defaultPath.toLowerCase(Locale.ENGLISH).startsWith("file:\\")) { + defaultPath = defaultPath.substring("file:\\".length()); + } + } } - } catch (Exception e) { - return false; } - return true; - }}); - String configToDisplay = committedPreferenceModel.getBypassConfigurationURL() != null?committedPreferenceModel.getBypassConfigurationURL():committedPreferenceModel.getConfigurationURL(); - configurationURL.setSelectedItem(configToDisplay); - } + File selectedFile = SwingHelper.promptForFile(this, defaultPath, "Select a Chainsaw configuration file", true); + if (selectedFile != null) { + try { + String newConfigurationFile = selectedFile.toURI().toURL().toExternalForm(); + if (!committedPreferenceModel.getConfigurationURLs().contains(newConfigurationFile)) { + configurationURL.addItem(newConfigurationFile); + } + configurationURL.setSelectedItem(newConfigurationFile); + } catch (MalformedURLException e1) { + e1.printStackTrace(); + } + } + } - public void browseForConfiguration() { - String defaultPath = "."; - if (configurationURL.getItemCount() > 0) { - Object selectedItem = configurationURL.getSelectedItem(); - if (selectedItem != null) { - File currentConfigurationPath = new File(selectedItem.toString()).getParentFile(); - if (currentConfigurationPath != null) { - defaultPath = currentConfigurationPath.getPath(); - //FileDialog will not navigate to this location unless we remove the prefixing protocol and slash - //at least on winxp - if (defaultPath.toLowerCase(Locale.ENGLISH).startsWith("file:\\")) { - defaultPath = defaultPath.substring("file:\\".length()); - } - } - } - } - File selectedFile = SwingHelper.promptForFile(this, defaultPath, "Select a Chainsaw configuration file", true); - if (selectedFile != null) { - try - { - String newConfigurationFile = selectedFile.toURI().toURL().toExternalForm(); - if (!committedPreferenceModel.getConfigurationURLs().contains(newConfigurationFile)) { - configurationURL.addItem(newConfigurationFile); - } - configurationURL.setSelectedItem(newConfigurationFile); - } - catch (MalformedURLException e1) - { - e1.printStackTrace(); - } - } - } - - private void initSliderComponent() { - responsiveSlider.setToolTipText( - "Adjust to set the responsiveness of the app. How often the view is updated."); - responsiveSlider.setSnapToTicks(true); - responsiveSlider.setLabelTable(sliderLabelMap); - responsiveSlider.setPaintLabels(true); - responsiveSlider.setPaintTrack(true); - - responsiveSlider.setBorder(BorderFactory.createTitledBorder(" Responsiveness ")); - - // responsiveSlider.setAlignmentY(0); - // responsiveSlider.setAlignmentX(0); - } + private void initSliderComponent() { + responsiveSlider.setToolTipText( + "Adjust to set the responsiveness of the app. How often the view is updated."); + responsiveSlider.setSnapToTicks(true); + responsiveSlider.setLabelTable(sliderLabelMap); + responsiveSlider.setPaintLabels(true); + responsiveSlider.setPaintTrack(true); - private void setupListeners() { - uncommittedPreferenceModel.addPropertyChangeListener( - "showNoReceiverWarning", - evt -> showNoReceiverWarning.setSelected( - (Boolean) evt.getNewValue())); - - uncommittedPreferenceModel.addPropertyChangeListener("showSplash", evt -> { - boolean value = (Boolean) evt.getNewValue(); - showSplash.setSelected(value); - }); - - uncommittedPreferenceModel.addPropertyChangeListener("okToRemoveSecurityManager", evt -> { -boolean newValue = (Boolean) evt.getNewValue(); -if(newValue) { -okToRemoveSecurityManager.setSelected(newValue); -}else { -okToRemoveSecurityManager.setSelected(false); -} + responsiveSlider.setBorder(BorderFactory.createTitledBorder(" Responsiveness ")); + + // responsiveSlider.setAlignmentY(0); + // responsiveSlider.setAlignmentX(0); + } + + private void setupListeners() { + uncommittedPreferenceModel.addPropertyChangeListener( + "showNoReceiverWarning", + evt -> showNoReceiverWarning.setSelected( + (Boolean) evt.getNewValue())); + + uncommittedPreferenceModel.addPropertyChangeListener("showSplash", evt -> { + boolean value = (Boolean) evt.getNewValue(); + showSplash.setSelected(value); + }); - }); - - - uncommittedPreferenceModel.addPropertyChangeListener( - "identifierExpression", - evt -> identifierExpression.setText(evt.getNewValue().toString())); - - uncommittedPreferenceModel.addPropertyChangeListener( - "responsiveness", - evt -> { - int value = (Integer) evt.getNewValue(); - - if (value >= 1000) { - int newValue = (value - 750) / 1000; - logger.debug( - "Adjusting old Responsiveness value from " + value + " to " - + newValue); - value = newValue; + uncommittedPreferenceModel.addPropertyChangeListener("okToRemoveSecurityManager", evt -> { + boolean newValue = (Boolean) evt.getNewValue(); + if (newValue) { + okToRemoveSecurityManager.setSelected(newValue); + } else { + okToRemoveSecurityManager.setSelected(false); } - responsiveSlider.setValue(value); - }); + }); + + + uncommittedPreferenceModel.addPropertyChangeListener( + "identifierExpression", + evt -> identifierExpression.setText(evt.getNewValue().toString())); + + uncommittedPreferenceModel.addPropertyChangeListener( + "responsiveness", + evt -> { + int value = (Integer) evt.getNewValue(); + + if (value >= 1000) { + int newValue = (value - 750) / 1000; + logger.debug( + "Adjusting old Responsiveness value from " + value + " to " + + newValue); + value = newValue; + } + + responsiveSlider.setValue(value); + }); - uncommittedPreferenceModel.addPropertyChangeListener( - "toolTipDisplayMillis", + uncommittedPreferenceModel.addPropertyChangeListener( + "toolTipDisplayMillis", evt -> toolTipDisplayMillis.setText(evt.getNewValue().toString())); - uncommittedPreferenceModel.addPropertyChangeListener( - "cyclicBufferSize", + uncommittedPreferenceModel.addPropertyChangeListener( + "cyclicBufferSize", evt -> cyclicBufferSize.setText(evt.getNewValue().toString())); - showNoReceiverWarning.addActionListener( - e -> uncommittedPreferenceModel.setShowNoReceiverWarning( - showNoReceiverWarning.isSelected())); - - showSplash.addActionListener(e -> uncommittedPreferenceModel.setShowSplash(showSplash.isSelected())); - - okToRemoveSecurityManager.addActionListener(e -> { - - if(okToRemoveSecurityManager.isSelected() && JOptionPane.showConfirmDialog(okToRemoveSecurityManager, "By ticking this option, you are authorizing Chainsaw to remove Java's Security Manager.\n\n" + - "This is required under Java Web Start so that it can access Jars/classes locally. Without this, Receivers like JMSReceiver + DBReceiver that require" + - " specific driver jars will NOT be able to be run. \n\n" + - "By ticking this, you are saying that this is ok.", "Please Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - uncommittedPreferenceModel.setOkToRemoveSecurityManager(true); - }else { - uncommittedPreferenceModel.setOkToRemoveSecurityManager(false); - } + showNoReceiverWarning.addActionListener( + e -> uncommittedPreferenceModel.setShowNoReceiverWarning( + showNoReceiverWarning.isSelected())); - }); - - - responsiveSlider.getModel().addChangeListener( - e -> { - if (responsiveSlider.getValueIsAdjusting()) { - /** - * We'll wait until it stops. - */ - } else { - int value = responsiveSlider.getValue(); + showSplash.addActionListener(e -> uncommittedPreferenceModel.setShowSplash(showSplash.isSelected())); - if (value == 0) { - value = 1; - } + okToRemoveSecurityManager.addActionListener(e -> { - logger.debug("Adjust responsiveness to " + value); - uncommittedPreferenceModel.setResponsiveness(value); + if (okToRemoveSecurityManager.isSelected() && JOptionPane.showConfirmDialog(okToRemoveSecurityManager, "By ticking this option, you are authorizing Chainsaw to remove Java's Security Manager.\n\n" + + "This is required under Java Web Start so that it can access Jars/classes locally. Without this, Receivers like JMSReceiver + DBReceiver that require" + + " specific driver jars will NOT be able to be run. \n\n" + + "By ticking this, you are saying that this is ok.", "Please Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + uncommittedPreferenceModel.setOkToRemoveSecurityManager(true); + } else { + uncommittedPreferenceModel.setOkToRemoveSecurityManager(false); } - }); - uncommittedPreferenceModel.addPropertyChangeListener( - "confirmExit", - evt -> { - boolean value = (Boolean) evt.getNewValue(); - confirmExit.setSelected(value); - }); - - uncommittedPreferenceModel.addPropertyChangeListener("configurationURL", evt -> { - String value = evt.getNewValue().toString(); - configurationURL.setSelectedItem(value); - }); - confirmExit.addActionListener( - e -> uncommittedPreferenceModel.setConfirmExit( - confirmExit.isSelected())); - } + }); + - private void setupInitialValues() { - sliderLabelMap.put(1, new JLabel(" Fastest ")); - sliderLabelMap.put(2, new JLabel(" Fast ")); - sliderLabelMap.put(3, new JLabel(" Medium ")); - sliderLabelMap.put(4, new JLabel(" Slow ")); - - // - showNoReceiverWarning.setSelected( - uncommittedPreferenceModel.isShowNoReceiverWarning()); - identifierExpression.setText( - uncommittedPreferenceModel.getIdentifierExpression()); - - confirmExit.setSelected(uncommittedPreferenceModel.isConfirmExit()); - okToRemoveSecurityManager.setSelected(uncommittedPreferenceModel.isOkToRemoveSecurityManager()); - showNoReceiverWarning.setSelected(uncommittedPreferenceModel.isShowNoReceiverWarning()); - showSplash.setSelected(uncommittedPreferenceModel.isShowSplash()); - identifierExpression.setText(uncommittedPreferenceModel.getIdentifierExpression()); - toolTipDisplayMillis.setText(uncommittedPreferenceModel.getToolTipDisplayMillis()+""); - cyclicBufferSize.setText(uncommittedPreferenceModel.getCyclicBufferSize() + ""); - configurationURL.setSelectedItem(uncommittedPreferenceModel.getConfigurationURL()); + responsiveSlider.getModel().addChangeListener( + e -> { + if (responsiveSlider.getValueIsAdjusting()) { + /** + * We'll wait until it stops. + */ + } else { + int value = responsiveSlider.getValue(); + + if (value == 0) { + value = 1; + } + + logger.debug("Adjust responsiveness to " + value); + uncommittedPreferenceModel.setResponsiveness(value); + } + }); + + uncommittedPreferenceModel.addPropertyChangeListener( + "confirmExit", + evt -> { + boolean value = (Boolean) evt.getNewValue(); + confirmExit.setSelected(value); + }); + + uncommittedPreferenceModel.addPropertyChangeListener("configurationURL", evt -> { + String value = evt.getNewValue().toString(); + configurationURL.setSelectedItem(value); + }); + confirmExit.addActionListener( + e -> uncommittedPreferenceModel.setConfirmExit( + confirmExit.isSelected())); + } + + private void setupInitialValues() { + sliderLabelMap.put(1, new JLabel(" Fastest ")); + sliderLabelMap.put(2, new JLabel(" Fast ")); + sliderLabelMap.put(3, new JLabel(" Medium ")); + sliderLabelMap.put(4, new JLabel(" Slow ")); + + // + showNoReceiverWarning.setSelected( + uncommittedPreferenceModel.isShowNoReceiverWarning()); + identifierExpression.setText( + uncommittedPreferenceModel.getIdentifierExpression()); + + confirmExit.setSelected(uncommittedPreferenceModel.isConfirmExit()); + okToRemoveSecurityManager.setSelected(uncommittedPreferenceModel.isOkToRemoveSecurityManager()); + showNoReceiverWarning.setSelected(uncommittedPreferenceModel.isShowNoReceiverWarning()); + showSplash.setSelected(uncommittedPreferenceModel.isShowSplash()); + identifierExpression.setText(uncommittedPreferenceModel.getIdentifierExpression()); + toolTipDisplayMillis.setText(uncommittedPreferenceModel.getToolTipDisplayMillis() + ""); + cyclicBufferSize.setText(uncommittedPreferenceModel.getCyclicBufferSize() + ""); + configurationURL.setSelectedItem(uncommittedPreferenceModel.getConfigurationURL()); + } } - } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelSaver.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelSaver.java b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelSaver.java index dc7156c..21c082c 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelSaver.java +++ b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelSaver.java @@ -16,34 +16,32 @@ */ package org.apache.log4j.chainsaw; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; - import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; - import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent; import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent; import org.apache.log4j.chainsaw.prefs.SettingsListener; import org.apache.log4j.chainsaw.prefs.SettingsManager; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + /** * Helper class that helps delegate the work of loading and saving the values * of the ApplicationPreferenceModel, allowing that class to remain a simple * bean. - * + * <p> * The Model passed to this class' constructor is the instance of the ApplicationPreference * that will be saved, and will have properties modified by loading from the * 'chainsaw.settings.xml' file in the .chainsaw directory of the user's home directory. - * - * @author psmith * + * @author psmith */ public class ApplicationPreferenceModelSaver implements SettingsListener { private final ApplicationPreferenceModel model; - + /** * @param model */ @@ -58,7 +56,7 @@ public class ApplicationPreferenceModelSaver implements SettingsListener { if (file.exists()) { FileReader reader = new FileReader(file); ApplicationPreferenceModel loadedModel = (ApplicationPreferenceModel) stream - .fromXML(reader); + .fromXML(reader); model.apply(loadedModel); reader.close(); } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/BasicPrefPanel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/BasicPrefPanel.java b/src/main/java/org/apache/log4j/chainsaw/BasicPrefPanel.java index 68ec03a..707b23e 100644 --- a/src/main/java/org/apache/log4j/chainsaw/BasicPrefPanel.java +++ b/src/main/java/org/apache/log4j/chainsaw/BasicPrefPanel.java @@ -16,38 +16,38 @@ */ package org.apache.log4j.chainsaw; -import javax.swing.JPanel; +import javax.swing.*; /** * 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 * + * @author Paul Smith */ public abstract class BasicPrefPanel extends JPanel { - private String title; + 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; + } - 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(); - } + public String toString() { + return getTitle(); + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java index 4828747..8e8cb83 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java +++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java @@ -16,27 +16,17 @@ */ package org.apache.log4j.chainsaw; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Point; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JEditorPane; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingUtilities; -import javax.swing.event.HyperlinkEvent; - import org.apache.log4j.Logger; import org.apache.log4j.chainsaw.help.HelpManager; +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import java.awt.*; + /** * A simple About box telling people stuff about this project - * + * * @author Paul Smith <psm...@apache.org> - * */ class ChainsawAbout extends JDialog { private static final Logger LOG = Logger.getLogger(ChainsawAbout.class); @@ -44,11 +34,11 @@ class ChainsawAbout extends JDialog { private final JEditorPane editPane = new JEditorPane("text/html", ""); private final JScrollPane scrollPane = new JScrollPane(editPane, - ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); private final String url = ChainsawAbout.class.getName().replace('.', '/') - + ".html"; + + ".html"; private boolean sleep = false; @@ -75,12 +65,12 @@ class ChainsawAbout extends JDialog { editPane.setEditable(false); editPane.addHyperlinkListener( - e -> { - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - HelpManager.getInstance().setHelpURL(e.getURL()); - } - }); - + e -> { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + HelpManager.getInstance().setHelpURL(e.getURL()); + } + }); + setSize(320, 240); new Thread(new Scroller()).start(); scrollPane.getViewport().setViewPosition(new Point(0, 0)); @@ -97,13 +87,13 @@ class ChainsawAbout extends JDialog { synchronized (guard) { guard.wait(); } - SwingUtilities.invokeLater(() -> scrollPane.getViewport().setViewPosition( - new Point(0, 0))); + SwingUtilities.invokeLater(() -> scrollPane.getViewport().setViewPosition( + new Point(0, 0))); continue; } SwingUtilities.invokeLater(() -> scrollPane.getViewport().setViewPosition( - new Point(0, scrollPane.getViewport() - .getViewPosition().y + 1))); + new Point(0, scrollPane.getViewport() + .getViewPosition().y + 1))); Thread.sleep(100); } catch (Exception e) { LOG.error("Error during scrolling", e); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java index 6c8bcb4..4e88310 100755 --- a/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java +++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.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. @@ -16,162 +16,166 @@ */ package org.apache.log4j.chainsaw; -import java.net.InetAddress; -import java.net.UnknownHostException; - import org.apache.log4j.Appender; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.helpers.Constants; import org.apache.log4j.helpers.OptionConverter; import org.apache.log4j.spi.LoggingEvent; +import java.net.InetAddress; +import java.net.UnknownHostException; + /** * ChainsawAppender receives LoggingEvents from the local * Log4J environment, and appends them into a model that * can be used inside a Swing GUI + * * @author Paul Smith * @version 1.0 */ public class ChainsawAppender - extends AppenderSkeleton{ - - private Appender appender; - - /** - * The in-JVM singleton instance of the ChainsawAppender. - * - * If somehow Log4j initialises more than one, then the first one to - * initialise wins! - */ - private static ChainsawAppender sSharedAppender = null; - - /** - * The classname of the viewer to create to view the events. - */ - private String viewerClassname; - private String hostname = "localhost"; - private String application = "app"; - - /** - * Constructor, initialises the singleton instance of the appender - */ - public ChainsawAppender() { - super(false); - synchronized (ChainsawAppender.class) { - if (sSharedAppender == null) { - sSharedAppender = this; - } + extends AppenderSkeleton { + + private Appender appender; + + /** + * The in-JVM singleton instance of the ChainsawAppender. + * <p> + * If somehow Log4j initialises more than one, then the first one to + * initialise wins! + */ + private static ChainsawAppender sSharedAppender = null; + + /** + * The classname of the viewer to create to view the events. + */ + private String viewerClassname; + private String hostname = "localhost"; + private String application = "app"; + + /** + * Constructor, initialises the singleton instance of the appender + */ + public ChainsawAppender() { + super(false); + synchronized (ChainsawAppender.class) { + if (sSharedAppender == null) { + sSharedAppender = this; + } + } } - } - - /** - * Return the singleton instance of the ChainsawAppender, it should only - * be initialised once. - * @return the One and only instance of the ChainsawAppender that is - * allowed to be referenced by the GUI - */ - static ChainsawAppender getInstance() { - return sSharedAppender; - } - - /** - * This appender does not require layout and so return false - * @return false and only false - */ - public boolean requiresLayout() { - return false; - } - - public Appender getAppender() { - return appender; - } - - public void setAppender(Appender appender) { - this.appender = appender; - } - - /** - * Appends the event - * @param aEvent the LoggingEvent to append - */ - protected void append(LoggingEvent aEvent) { - if (hostname != null) { - aEvent.setProperty(Constants.HOSTNAME_KEY, hostname); - } - - if (application != null) { - aEvent.setProperty(Constants.APPLICATION_KEY, application); - } - - appender.doAppend(aEvent); - } - - /** - * Instantiates and activates an instance of a ChainsawViewer - * to view the contents of this appender. - */ - public void activateOptions() { - if (viewerClassname == null) { - viewerClassname = "org.apache.log4j.chainsaw.DefaultViewer"; + + /** + * Return the singleton instance of the ChainsawAppender, it should only + * be initialised once. + * + * @return the One and only instance of the ChainsawAppender that is + * allowed to be referenced by the GUI + */ + static ChainsawAppender getInstance() { + return sSharedAppender; } - - ChainsawViewer viewer = - (ChainsawViewer) OptionConverter.instantiateByClassName(viewerClassname, - ChainsawViewer.class, null); - - if (viewer != null) { - viewer.activateViewer(this); + + /** + * This appender does not require layout and so return false + * + * @return false and only false + */ + public boolean requiresLayout() { + return false; + } + + public Appender getAppender() { + return appender; } - try { - hostname = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException uhe) { - try { - hostname = InetAddress.getLocalHost().getHostAddress(); - } catch (UnknownHostException uhe2) { - } + + public void setAppender(Appender appender) { + this.appender = appender; + } + + /** + * Appends the event + * + * @param aEvent the LoggingEvent to append + */ + protected void append(LoggingEvent aEvent) { + if (hostname != null) { + aEvent.setProperty(Constants.HOSTNAME_KEY, hostname); + } + + if (application != null) { + aEvent.setProperty(Constants.APPLICATION_KEY, application); + } + + appender.doAppend(aEvent); + } + + /** + * Instantiates and activates an instance of a ChainsawViewer + * to view the contents of this appender. + */ + public void activateOptions() { + if (viewerClassname == null) { + viewerClassname = "org.apache.log4j.chainsaw.DefaultViewer"; + } + + ChainsawViewer viewer = + (ChainsawViewer) OptionConverter.instantiateByClassName(viewerClassname, + ChainsawViewer.class, null); + + if (viewer != null) { + viewer.activateViewer(this); + } + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException uhe) { + try { + hostname = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException uhe2) { + } + } + } + + /** + * Close does nothing + */ + public void close() { + } + + /** + * Sets the viewer class to use to view the events. The class must + * implement the ChainsawViewer interface. + * + * @param classname The class name of the viewer class. + */ + public void setViewerClass(String classname) { + viewerClassname = classname; + } + + /** + * Gets the viewer class to use to view the events. + * + * @return The class name of the viewer class. + */ + public String getViewerClass() { + return viewerClassname; + } + + /** + * The <b>Application</b> option takes a string value which should be the + * name of the application getting logged + */ + public void setApplication(String lapp) { + this.application = lapp; + } + + /** + * Returns value of the <b>Application</b> option. + */ + public String getApplication() { + return application; } - } - - /** - * Close does nothing - */ - public void close() { - } - - /** - * Sets the viewer class to use to view the events. The class must - * implement the ChainsawViewer interface. - * - * @param classname The class name of the viewer class. - */ - public void setViewerClass(String classname) { - viewerClassname = classname; - } - - /** - * Gets the viewer class to use to view the events. - * - * @return The class name of the viewer class. - */ - public String getViewerClass() { - return viewerClassname; - } - - /** - * The <b>Application</b> option takes a string value which should be the - * name of the application getting logged - */ - public void setApplication(String lapp) { - this.application = lapp; - } - - /** - * Returns value of the <b>Application</b> option. - */ - public String getApplication() { - return application; - } }