You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2022/09/09 03:14:58 UTC
[logging-chainsaw] branch master updated (1cdb2d7 -> 80e7a29)
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-chainsaw.git
from 1cdb2d7 added link for standalone download
new 3ec07a6 Application-wide preferences should work now
new 80e7a29 Rework colors to load from config file
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../chainsaw/ApplicationPreferenceModelPanel.java | 284 ++++++---------------
.../java/org/apache/log4j/chainsaw/LogPanel.java | 49 +++-
src/main/java/org/apache/log4j/chainsaw/LogUI.java | 8 +-
.../apache/log4j/chainsaw/LoggerNameTreePanel.java | 2 +-
.../apache/log4j/chainsaw/color/ColorPanel.java | 126 +++++----
.../apache/log4j/chainsaw/color/RuleColorizer.java | 247 +++++++++---------
.../log4j/chainsaw/prefs/SettingsManager.java | 40 ++-
.../apache/log4j/chainsaw/prefs/default.properties | 11 +
.../log4j/chainsaw/prefs/logpanel.properties | 1 -
9 files changed, 367 insertions(+), 401 deletions(-)
[logging-chainsaw] 02/02: Rework colors to load from config file
Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-chainsaw.git
commit 80e7a29df19b3f89012761d660b83793cd95b2f2
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Thu Sep 8 23:14:50 2022 -0400
Rework colors to load from config file
---
.../chainsaw/ApplicationPreferenceModelPanel.java | 1 +
.../java/org/apache/log4j/chainsaw/LogPanel.java | 49 +++-
src/main/java/org/apache/log4j/chainsaw/LogUI.java | 8 +-
.../apache/log4j/chainsaw/LoggerNameTreePanel.java | 2 +-
.../apache/log4j/chainsaw/color/ColorPanel.java | 126 ++++++-----
.../apache/log4j/chainsaw/color/RuleColorizer.java | 247 +++++++++++----------
.../log4j/chainsaw/prefs/SettingsManager.java | 40 ++--
.../apache/log4j/chainsaw/prefs/default.properties | 11 +
.../log4j/chainsaw/prefs/logpanel.properties | 1 -
9 files changed, 292 insertions(+), 193 deletions(-)
diff --git a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
index 45e38db..d88167c 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
@@ -447,6 +447,7 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
sliderLabelMap.put(3, new JLabel(" Medium "));
sliderLabelMap.put(4, new JLabel(" Slow "));
+
confirmExit.setSelected(m_globalConfiguration.getBoolean("confirmExit", Boolean.TRUE));
showSplash.setSelected(m_globalConfiguration.getBoolean("showSplash", Boolean.TRUE));
toolTipDisplayMillis.setText(m_globalConfiguration.getInt( "toolTipDisplayMillis", 1000 ) + "");
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogPanel.java b/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
index 3b4c28b..df76989 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
@@ -143,7 +143,8 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
private ApplicationPreferenceModel applicationPreferenceModel;
private final LogPanelPreferencePanel logPanelPreferencesPanel;
private final FilterModel filterModel = new FilterModel();
- private final RuleColorizer colorizer = new RuleColorizer();
+ private RuleColorizer colorizer;
+ private final RuleColorizer m_globalColorizer;
private final RuleMediator tableRuleMediator = new RuleMediator(false);
private final RuleMediator searchRuleMediator = new RuleMediator(true);
private final EventDetailLayout detailLayout = new EventDetailLayout();
@@ -183,6 +184,7 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
private boolean isDetailPanelVisible;
private ChainsawReceiver m_receiver;
private AbstractConfiguration m_configuration;
+ private Map<String, RuleColorizer> m_allColorizers;
/**
* Creates a new LogPanel object. If a LogPanel with this identifier has
@@ -195,14 +197,18 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
final String identifier,
int cyclicBufferSize,
Map<String, RuleColorizer> allColorizers,
- final ApplicationPreferenceModel applicationPreferenceModel) {
+ final ApplicationPreferenceModel applicationPreferenceModel,
+ RuleColorizer globalRuleColorizer) {
this.identifier = identifier;
this.statusBar = statusBar;
this.applicationPreferenceModel = applicationPreferenceModel;
this.logPanelPreferencesPanel = new LogPanelPreferencePanel(preferenceModel, applicationPreferenceModel);
+ this.colorizer = globalRuleColorizer;
+ this.m_globalColorizer = globalRuleColorizer;
+ this.m_allColorizers = allColorizers;
logger.debug("creating logpanel for {}", identifier);
- m_configuration = SettingsManager.getInstance().getSettingsForReceiverTab(identifier);
+ m_configuration = SettingsManager.getInstance().getCombinedSettingsForRecevierTab(identifier);
setLayout(new BorderLayout());
@@ -709,7 +715,7 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage());
allColorizers.put(identifier, colorizer);
- colorPanel = new ColorPanel(colorizer, filterModel, allColorizers, applicationPreferenceModel);
+ colorPanel = new ColorPanel(m_globalColorizer, filterModel, allColorizers, this);
colorFrame.getContentPane().add(colorPanel);
@@ -1499,7 +1505,7 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
Color c = JColorChooser.showDialog(getRootPane(), "Choose a color", Color.red);
if (c != null) {
String expression = columnNameKeywordMap.get(colName).toString() + " " + operator + " '" + value + "'";
- colorizer.addRule(ChainsawConstants.DEFAULT_COLOR_RULE_NAME, new ColorRule(expression,
+ colorizer.addRule(new ColorRule(expression,
ExpressionRule.getRule(expression), c, ChainsawConstants.COLOR_DEFAULT_FOREGROUND));
}
}
@@ -2063,7 +2069,15 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
}
}
- colorizer.loadColorSettings(config);
+ AbstractConfiguration configuration = SettingsManager.getInstance().getSettingsForReceiverTab(identifier);
+
+ if( configuration.getBoolean( "color.rules.default", true ) ){
+ colorizer = m_globalColorizer;
+ }else{
+ setRuleColorizer(new RuleColorizer());
+ colorizer.setConfiguration(configuration);
+ colorizer.loadColorSettings();
+ }
// if (xmlFile.exists()) {
@@ -2251,6 +2265,29 @@ public class LogPanel extends DockablePanel implements ChainsawEventBatchListene
return stream;
}
+ public void setRuleColorizer(RuleColorizer newRuleColor){
+ if( newRuleColor == colorizer ){
+ return;
+ }
+
+ if( colorizer == m_globalColorizer ){
+ // Current colorizer is the global one, so set our new colorizer
+ colorizer = newRuleColor;
+ AbstractConfiguration configuration = SettingsManager.getInstance().getSettingsForReceiverTab(identifier);
+
+ colorizer.setConfiguration(configuration);
+ colorizer.setUseDefaultSettings(false);
+ m_allColorizers.put( identifier, colorizer );
+ }else{
+ m_allColorizers.remove( identifier );
+ colorizer = newRuleColor;
+ }
+ }
+
+ public RuleColorizer getCurrentRuleColorizer(){
+ return colorizer;
+ }
+
/**
* Display the panel preferences frame
*/
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUI.java b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
index d7382fb..ff90d58 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogUI.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
@@ -145,6 +145,7 @@ public class LogUI extends JFrame {
//map of tab names to rulecolorizers
private Map<String, RuleColorizer> allColorizers = new HashMap<>();
+ private RuleColorizer globalRuleColorizer = new RuleColorizer(true);
private ReceiverConfigurationPanel receiverConfigurationPanel = new ReceiverConfigurationPanel();
/**
@@ -155,6 +156,9 @@ public class LogUI extends JFrame {
super("Chainsaw");
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ globalRuleColorizer.setConfiguration(SettingsManager.getInstance().getGlobalConfiguration());
+ globalRuleColorizer.loadColorSettings();
+
if (ChainsawIcons.WINDOW_ICON != null) {
setIconImage(new ImageIcon(ChainsawIcons.WINDOW_ICON).getImage());
}
@@ -249,6 +253,7 @@ public class LogUI extends JFrame {
public static void createChainsawGUI(Action newShutdownAction) {
AbstractConfiguration config = SettingsManager.getInstance().getGlobalConfiguration();
+
if (config.getBoolean("okToRemoveSecurityManager", false)) {
// statusBar.setMessage("User has authorised removal of Java Security Manager via preferences");
System.setSecurityManager(null);
@@ -506,7 +511,6 @@ public class LogUI extends JFrame {
getToolBarAndMenus().stateChange();
RuleColorizer colorizer = new RuleColorizer();
- colorizer.loadColorSettings(ChainsawConstants.DEFAULT_COLOR_RULE_NAME);
allColorizers.put(ChainsawConstants.DEFAULT_COLOR_RULE_NAME, colorizer);
}
@@ -1627,7 +1631,7 @@ public class LogUI extends JFrame {
private void buildLogPanel(
boolean customExpression, final String ident, final List<ChainsawLoggingEvent> events, final ChainsawReceiver rx)
throws IllegalArgumentException {
- final LogPanel thisPanel = new LogPanel(getStatusBar(), ident, cyclicBufferSize, allColorizers, applicationPreferenceModel);
+ final LogPanel thisPanel = new LogPanel(getStatusBar(), ident, cyclicBufferSize, allColorizers, applicationPreferenceModel, globalRuleColorizer);
if( !customExpression && rx != null ){
thisPanel.setReceiver(rx);
diff --git a/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java b/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
index ff798d2..26a1cae 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
@@ -870,7 +870,7 @@ final class LoggerNameTreePanel extends JPanel implements LoggerNameListener {
Color c = JColorChooser.showDialog(getRootPane(), "Choose a color", Color.red);
if (c != null) {
String expression = "logger like '^" + selectedLogger + ".*'";
- colorizer.addRule(ChainsawConstants.DEFAULT_COLOR_RULE_NAME, new ColorRule(expression,
+ colorizer.addRule(new ColorRule(expression,
ExpressionRule.getRule(expression), c, ChainsawConstants.COLOR_DEFAULT_FOREGROUND));
}
}
diff --git a/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java b/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java
index 136c874..9c6484e 100644
--- a/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java
@@ -43,6 +43,7 @@ import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableModel;
import org.apache.commons.configuration2.AbstractConfiguration;
+import org.apache.log4j.chainsaw.LogPanel;
import org.apache.log4j.chainsaw.prefs.SettingsManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -61,7 +62,7 @@ public class ColorPanel extends JPanel {
private static final String DEFAULT_STATUS = "<html>Double click a rule field to edit the rule</html>";
private final String currentRuleSet = "Default";
- private RuleColorizer colorizer;
+// private RuleColorizer colorizer;
private JPanel rulesPanel;
private FilterModel filterModel;
private RulesTableModel rulesTableModel;
@@ -73,34 +74,38 @@ public class ColorPanel extends JPanel {
private final String noTab = "None";
private DefaultComboBoxModel logPanelColorizersModel;
private Map<String, RuleColorizer> allLogPanelColorizers;
- private RuleColorizer currentLogPanelColorizer;
+// private RuleColorizer currentLogPanelColorizer;
private JTable searchTable;
private DefaultTableModel searchTableModel;
private Vector<String> searchColumns;
private Vector<Vector<Color>> searchDataVector;
private Vector<Color> searchDataVectorEntry;
+ private RuleColorizer m_globalColorizer;
private JTable alternatingColorTable;
private DefaultTableModel alternatingColorTableModel;
private Vector<String> alternatingColorColumns;
private Vector<Vector<Color>> alternatingColorDataVector;
private Vector<Color> alternatingColorDataVectorEntry;
- private ApplicationPreferenceModel applicationPreferenceModel;
private JCheckBox bypassSearchColorsCheckBox;
-
- public ColorPanel(final RuleColorizer currentLogPanelColorizer, final FilterModel filterModel,
- final Map<String, RuleColorizer> allLogPanelColorizers, final ApplicationPreferenceModel applicationPreferenceModel) {
+ private JCheckBox m_globalRulesCheckbox;
+ private LogPanel m_parentLogPanel;
+ private JLabel m_rulesLabel;
+
+ public ColorPanel(final RuleColorizer globalColorizer,
+ final FilterModel filterModel,
+ final Map<String, RuleColorizer> allLogPanelColorizers,
+ final LogPanel parent) {
super(new BorderLayout());
AbstractConfiguration configuration = SettingsManager.getInstance().getGlobalConfiguration();
- this.currentLogPanelColorizer = currentLogPanelColorizer;
- this.colorizer = currentLogPanelColorizer;
this.filterModel = filterModel;
this.allLogPanelColorizers = allLogPanelColorizers;
- this.applicationPreferenceModel = applicationPreferenceModel;
+ this.m_globalColorizer = globalColorizer;
+ this.m_parentLogPanel = parent;
- currentLogPanelColorizer.addPropertyChangeListener(
+ m_parentLogPanel.getCurrentRuleColorizer().addPropertyChangeListener(
"colorrule",
evt -> updateColors());
@@ -234,8 +239,13 @@ public class ColorPanel extends JPanel {
Object selectedItem = loadPanelColorizersComboBox.getSelectedItem();
if (selectedItem != null) {
RuleColorizer sourceColorizer = allLogPanelColorizers.get(selectedItem.toString());
- colorizer.setRules(sourceColorizer.getRules());
+ RuleColorizer newColorizer = new RuleColorizer();
+ newColorizer.setRules(sourceColorizer.getRules());
+ parent.setRuleColorizer(newColorizer);
updateColors();
+ m_parentLogPanel.getCurrentRuleColorizer().addPropertyChangeListener(
+ "colorrule",
+ evt -> updateColors());
}
}
};
@@ -265,6 +275,7 @@ public class ColorPanel extends JPanel {
if (logPanelColorizersModel.getIndexOf(noTab) == -1) {
logPanelColorizersModel.addElement(noTab);
}
+ RuleColorizer currentLogPanelColorizer = m_parentLogPanel.getCurrentRuleColorizer();
for (Object o : allLogPanelColorizers.entrySet()) {
Map.Entry entry = (Map.Entry) o;
if (!entry.getValue().equals(currentLogPanelColorizer) && (logPanelColorizersModel.getIndexOf(entry.getKey()) == -1)) {
@@ -319,7 +330,7 @@ public class ColorPanel extends JPanel {
public void updateColors() {
rulesTableModel.clear();
- rulesTableModel.addDefaultRules();
+ rulesTableModel.addColorRules();
rulesTableModel.fireTableDataChanged();
}
@@ -329,8 +340,8 @@ public class ColorPanel extends JPanel {
rulesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
rulesTable.setColumnSelectionAllowed(false);
- Vector backgroundColors = colorizer.getDefaultColors();
- Vector foregroundColors = colorizer.getDefaultColors();
+ Vector backgroundColors = new Vector(RuleColorizer.getDefaultColors());
+ Vector foregroundColors = new Vector(RuleColorizer.getDefaultColors());
backgroundColors.add("Browse...");
foregroundColors.add("Browse...");
@@ -367,8 +378,8 @@ public class ColorPanel extends JPanel {
thisTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
thisTable.setColumnSelectionAllowed(false);
- Vector backgroundColors = colorizer.getDefaultColors();
- Vector foregroundColors = colorizer.getDefaultColors();
+ Vector backgroundColors = new Vector(RuleColorizer.getDefaultColors());
+ Vector foregroundColors = new Vector(RuleColorizer.getDefaultColors());
backgroundColors.add("Browse...");
foregroundColors.add("Browse...");
@@ -445,10 +456,7 @@ public class ColorPanel extends JPanel {
statusBar.setText(DEFAULT_STATUS);
//only update rules if there were no errors
- Map map = new HashMap();
- List<ColorRule> newRules = new ArrayList<>(rulesTableModel.rules());
- map.put(ruleSet, newRules);
- applyingColorizer.setRules(map);
+ applyingColorizer.setRules(rulesTableModel.rules());
} else {
statusBar.setText("Errors - see expression tooltip (color filters won't be active until errors are resolved)");
@@ -462,24 +470,24 @@ public class ColorPanel extends JPanel {
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(Box.createHorizontalGlue());
- JButton saveAsDefaultButton = new JButton(" Save as default ");
-
- saveAsDefaultButton.addActionListener(
- new AbstractAction() {
- public void actionPerformed(ActionEvent evt) {
- RuleColorizer defaultColorizer = allLogPanelColorizers.get(ChainsawConstants.DEFAULT_COLOR_RULE_NAME);
- applyRules(currentRuleSet, defaultColorizer);
- }
- });
-
- panel.add(saveAsDefaultButton);
+// JButton saveAsDefaultButton = new JButton(" Save as default ");
+//
+// saveAsDefaultButton.addActionListener(
+// new AbstractAction() {
+// public void actionPerformed(ActionEvent evt) {
+// RuleColorizer defaultColorizer = allLogPanelColorizers.get(ChainsawConstants.DEFAULT_COLOR_RULE_NAME);
+// applyRules(currentRuleSet, defaultColorizer);
+// }
+// });
+//
+// panel.add(saveAsDefaultButton);
JButton applyButton = new JButton(" Apply ");
applyButton.addActionListener(
new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
- applyRules(currentRuleSet, colorizer);
+ applyRules(currentRuleSet, m_parentLogPanel.getCurrentRuleColorizer());
saveSearchColors();
saveAlternatingColors();
saveBypassFlag();
@@ -505,19 +513,20 @@ public class ColorPanel extends JPanel {
private void saveSearchColors() {
Vector thisVector = (Vector) searchTableModel.getDataVector().get(0);
- applicationPreferenceModel.setSearchBackgroundColor((Color) thisVector.get(0));
- applicationPreferenceModel.setSearchForegroundColor((Color) thisVector.get(1));
+ AbstractConfiguration globalConfig = SettingsManager.getInstance().getGlobalConfiguration();
+ globalConfig.setProperty("searchBackgroundColor", RuleColorizer.colorToRGBString((Color) thisVector.get(0)));
+ globalConfig.setProperty("searchForegroundColor", RuleColorizer.colorToRGBString((Color) thisVector.get(1)));
}
private void saveAlternatingColors() {
Vector thisVector = (Vector) alternatingColorTableModel.getDataVector().get(0);
- applicationPreferenceModel.setAlternatingBackgroundColor((Color) thisVector.get(0));
+// applicationPreferenceModel.setAlternatingBackgroundColor((Color) thisVector.get(0));
Color alternatingColorForegroundColor = (Color) thisVector.get(1);
- applicationPreferenceModel.setAlternatingForegroundColor(alternatingColorForegroundColor);
+// applicationPreferenceModel.setAlternatingForegroundColor(alternatingColorForegroundColor);
}
private void saveBypassFlag() {
- applicationPreferenceModel.setBypassSearchColors(bypassSearchColorsCheckBox.isSelected());
+// applicationPreferenceModel.setBypassSearchColors(bypassSearchColorsCheckBox.isSelected());
}
JPanel buildUpDownPanel() {
@@ -596,9 +605,34 @@ public class ColorPanel extends JPanel {
panel.add(Box.createVerticalStrut(10));
- JLabel rulesLabel = new JLabel("Rules:");
+ m_rulesLabel = new JLabel("Rules:");
+ m_globalRulesCheckbox = new JCheckBox("Use global rules");
+
+ if( m_globalColorizer == m_parentLogPanel.getCurrentRuleColorizer() ){
+ m_globalRulesCheckbox.setSelected(true);
+ m_rulesLabel.setText("Global rules:");
+ }
+
+ m_globalRulesCheckbox.addActionListener(
+ new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ if( m_globalRulesCheckbox.isSelected() ){
+ m_parentLogPanel.setRuleColorizer( m_globalColorizer );
+ m_rulesLabel.setText( "Global rules:" );
+ }else{
+ m_parentLogPanel.setRuleColorizer(new RuleColorizer());
+ m_rulesLabel.setText("Rules:");
+ }
+ updateColors();
+ m_parentLogPanel.getCurrentRuleColorizer().addPropertyChangeListener(
+ "colorrule",
+ evt -> updateColors());
+ }
+ });
- panel.add(rulesLabel);
+ panel.add(m_globalRulesCheckbox);
+ panel.add(m_rulesLabel);
JPanel buttonPanel = new JPanel(new GridLayout(0, 2));
buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
@@ -851,7 +885,7 @@ public class ColorPanel extends JPanel {
RulesTableModel(){
m_data = new ArrayList<>();
- addDefaultRules();
+ addColorRules();
}
List<ColorRule> rules(){
@@ -890,16 +924,8 @@ public class ColorPanel extends JPanel {
}
}
- void addDefaultRules(){
- Map map = colorizer.getRules();
- for (Object o1 : map.entrySet()) {
- Map.Entry entry = (Map.Entry) o1;
- logger.debug( "entry: {}", o1 );
- //update ruleset list
- if (entry.getKey().equals(currentRuleSet)) {
- m_data.addAll( (List<ColorRule>)entry.getValue() );
- }
- }
+ void addColorRules(){
+ m_data.addAll( m_parentLogPanel.getCurrentRuleColorizer().getRules() );
}
@Override
diff --git a/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java b/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java
index aa197cf..44e17bb 100644
--- a/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java
+++ b/src/main/java/org/apache/log4j/chainsaw/color/RuleColorizer.java
@@ -31,7 +31,10 @@ import java.net.URLEncoder;
import java.util.*;
import java.util.List;
import org.apache.commons.configuration2.AbstractConfiguration;
+import org.apache.commons.configuration2.DataConfiguration;
import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEvent;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
@@ -41,25 +44,28 @@ import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEvent;
* @author Scott Deboy <sdeboy@apache.org>
*/
public class RuleColorizer implements Colorizer {
- private Map<String,List<ColorRule>> rules;
+ private static final Logger logger = LogManager.getLogger();
+
+ private List<ColorRule> rules;
private final PropertyChangeSupport colorChangeSupport =
new PropertyChangeSupport(this);
- private Map<String,List<ColorRule>> defaultRules = new HashMap<>();
- private String currentRuleSet = ChainsawConstants.DEFAULT_COLOR_RULE_NAME;
+ private List<ColorRule> defaultRules = new ArrayList<>();
private Rule findRule;
private Rule loggerRule;
+ private AbstractConfiguration m_configuration;
+ private boolean m_isGlobal;
private static final String COLORS_EXTENSION = ".colors";
- private final Color WARN_DEFAULT_COLOR = new Color(255, 255, 153);
- private final Color FATAL_OR_ERROR_DEFAULT_COLOR = new Color(255, 153, 153);
- private final Color MARKER_DEFAULT_COLOR = new Color(153, 255, 153);
+ private static final Color WARN_DEFAULT_COLOR = new Color(255, 255, 153);
+ private static final Color FATAL_OR_ERROR_DEFAULT_COLOR = new Color(255, 153, 153);
+ private static final Color MARKER_DEFAULT_COLOR = new Color(153, 255, 153);
- private final String DEFAULT_WARN_EXPRESSION = "level == WARN";
- private final String DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION = "level == FATAL || level == ERROR || exception exists";
- private final String DEFAULT_MARKER_EXPRESSION = "prop.marker exists";
+ private static final String DEFAULT_WARN_EXPRESSION = "level == WARN";
+ private static final String DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION = "level == FATAL || level == ERROR || exception exists";
+ private static final String DEFAULT_MARKER_EXPRESSION = "prop.marker exists";
- public RuleColorizer() {
+ public static List<ColorRule> defaultRules(){
List<ColorRule> rulesList = new ArrayList<>();
String expression = DEFAULT_FATAL_ERROR_EXCEPTION_EXPRESSION;
@@ -79,8 +85,17 @@ public class RuleColorizer implements Colorizer {
expression, ExpressionRule.getRule(expression), MARKER_DEFAULT_COLOR,
Color.black));
- defaultRules.put(currentRuleSet, rulesList);
- setRules(defaultRules);
+ return rulesList;
+ }
+
+ public RuleColorizer() {
+ this.rules = defaultRules();
+ m_isGlobal = false;
+ }
+
+ public RuleColorizer(boolean isGlobal){
+ this.rules = defaultRules();
+ m_isGlobal = isGlobal;
}
public void setLoggerRule(Rule loggerRule) {
@@ -101,74 +116,43 @@ public class RuleColorizer implements Colorizer {
return loggerRule;
}
- public void setRules(Map<String,List<ColorRule>> rules) {
- this.rules = rules;
+ public void setRules(List<ColorRule> rules) {
+ this.rules.clear();
+ this.rules.addAll(rules);
colorChangeSupport.firePropertyChange("colorrule", false, true);
- }
- public Map<String,List<ColorRule>> getRules() {
- return rules;
+ saveColorSettings();
}
- public List<ColorRule> getCurrentRules() {
- return rules.get(currentRuleSet);
+ public List<ColorRule> getRules() {
+ return rules;
}
- public void addRules(Map<String,List<ColorRule>> newRules) {
-
- for (Map.Entry<String,List<ColorRule>> entry : newRules.entrySet()) {
-
- if (rules.containsKey(entry.getKey())) {
- rules.get(entry.getKey()).addAll( entry.getValue() );
- } else {
- rules.put(entry.getKey(), entry.getValue());
- }
- }
+ public void addRules(List<ColorRule> newRules) {
+ rules.addAll( newRules );
colorChangeSupport.firePropertyChange("colorrule", false, true);
- }
- public void addRule(String ruleSetName, ColorRule rule) {
- if (rules.containsKey(ruleSetName)) {
- rules.get(ruleSetName).add(rule);
- } else {
- List<ColorRule> list = new ArrayList<>();
- list.add(rule);
- rules.put(ruleSetName, list);
- }
-
- colorChangeSupport.firePropertyChange("colorrule", false, true);
+ saveColorSettings();
}
- public void removeRule(String ruleSetName, String expression) {
- if (rules.containsKey(ruleSetName)) {
- List<ColorRule> list = rules.get(ruleSetName);
-
- for (int i = 0; i < list.size(); i++) {
- ColorRule rule = list.get(i);
+ public void addRule(ColorRule rule) {
+ rules.add(rule);
- if (rule.getExpression().equals(expression)) {
- list.remove(rule);
+ colorChangeSupport.firePropertyChange("colorrule", false, true);
- return;
- }
- }
- }
+ saveColorSettings();
}
- public void setCurrentRuleSet(String ruleSetName) {
- currentRuleSet = ruleSetName;
+ public void removeRule(String expression) {
+ rules.removeIf( x -> x.getExpression().equals( expression ) );
}
public Color getBackgroundColor(ChainsawLoggingEvent event) {
- if (rules.containsKey(currentRuleSet)) {
- List<ColorRule> list = rules.get(currentRuleSet);
-
- for (ColorRule rule : list) {
+ for (ColorRule rule : rules) {
- if ((rule.getBackgroundColor() != null) && (rule.evaluate(event, null))) {
- return rule.getBackgroundColor();
- }
+ if ((rule.getBackgroundColor() != null) && (rule.evaluate(event, null))) {
+ return rule.getBackgroundColor();
}
}
@@ -176,14 +160,10 @@ public class RuleColorizer implements Colorizer {
}
public Color getForegroundColor(ChainsawLoggingEvent event) {
- if (rules.containsKey(currentRuleSet)) {
- List<ColorRule> list = rules.get(currentRuleSet);
-
- for (ColorRule rule : list) {
+ for (ColorRule rule : rules) {
- if ((rule.getForegroundColor() != null) && (rule.evaluate(event, null))) {
- return rule.getForegroundColor();
- }
+ if ((rule.getForegroundColor() != null) && (rule.evaluate(event, null))) {
+ return rule.getForegroundColor();
}
}
@@ -207,65 +187,94 @@ public class RuleColorizer implements Colorizer {
colorChangeSupport.addPropertyChangeListener(propertyName, listener);
}
+ public void setConfiguration(AbstractConfiguration configuration){
+ m_configuration = configuration;
+ }
- /**
- * Save panel color settings
- */
- public void saveColorSettings(String name) {
- ObjectOutputStream o = null;
- try {
- File f = new File(SettingsManager.getInstance().getSettingsDirectory(), URLEncoder.encode(name + COLORS_EXTENSION));
-
- o = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
-
- o.writeObject(getRules());
- o.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- try {
- if (o != null) {
- o.close();
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
+ public void setUseDefaultSettings(boolean useDefaultSettings){
+ if( m_configuration == SettingsManager.getInstance().getGlobalConfiguration() ){
+ return;
}
+
+ m_configuration.setProperty( "color.rules.default", useDefaultSettings );
}
- /**
- * Load panel color settings if they exist from the given configuration - otherwise, load default color settings
- */
- public void loadColorSettings(String name){}
+ public static String colorToRGBString( Color c ){
+ return String.format( "#%02x%02x%02x",
+ c.getRed(),
+ c.getGreen(),
+ c.getBlue());
+ }
+
+ private void saveColorSettings(){
+ if( m_configuration == null ){
+ return;
+ }
+
+ DataConfiguration data = new DataConfiguration(m_configuration);
+
+ if( !m_isGlobal && m_configuration.getBoolean( "color.rules.default", true ) ){
+ // No need to save, using the default rules
+ return;
+ }
+
+ for( int x = 0; x < 32; x++ ){
+ String baseConfigKey = "color.rules(" + x + ")";
+
+ if( rules.size() <= x ){
+ break;
+ }
+
+ ColorRule rule = rules.get(x);
+
+ logger.debug( "Saving rule {}. Expression: {}", x, rule.getExpression() );
+
+ m_configuration.setProperty( baseConfigKey + ".expression", rule.getExpression() );
+ String bgColorString = colorToRGBString(rule.getBackgroundColor());
+ String fgColorString = colorToRGBString(rule.getForegroundColor());
+ data.setProperty( baseConfigKey + ".backgroundColor", bgColorString );
+ data.setProperty( baseConfigKey + ".foregroundColor", fgColorString );
+ }
+
+ logger.debug( "all keys for {}:", m_configuration );
+ java.util.Iterator<String> s = m_configuration.getKeys();
+ while( s.hasNext() ){
+ logger.debug( "found key: {}", s.next() );
+ }
+ }
- public void loadColorSettings(AbstractConfiguration configuration) {
+ public void loadColorSettings() {
// When we save/load the rule, we really need to load a map of rules
// There's no real good way to do this, so we will do this the somewhat
// dumb way and just load up to 32 color rules, since that seems like
// a good number
- // This needs to be done for each rule set, so we first need to get a
- // list of the rule sets
- String[] ruleSets = configuration.getStringArray( "color.rulesets" );
- if( ruleSets.length == 0 ){
- // Default rule set is already defined
- return;
+ List<ColorRule> newRules = new ArrayList<>();
+ AbstractConfiguration configuration = m_configuration;
+
+ DataConfiguration data = new DataConfiguration(configuration);
+
+ for( int x = 0; x < 32; x++ ){
+ String baseConfigKey = "color.rules(" + x + ")";
+ String expression;
+ Color backgroundColor;
+ Color foregroundColor;
+
+ expression = configuration.getString( baseConfigKey + ".expression" );
+ backgroundColor = data.getColor( baseConfigKey + ".backgroundColor" );
+ foregroundColor = data.getColor( baseConfigKey + ".foregroundColor" );
+
+ if( expression == null ||
+ backgroundColor == null ||
+ foregroundColor == null ){
+ continue;
+ }
+
+ Rule simpleRule = ExpressionRule.getRule(expression);
+ ColorRule rule = new ColorRule( expression, simpleRule, backgroundColor, foregroundColor );
+ newRules.add( rule );
}
- /*
- ColorRule(final String expression,
- final Rule rule,
- final Color backgroundColor,
- final Color foregroundColor)
- */
-// Map<String,List<ColorRule>> rules = new HashMap<>();
-// for( String ruleSet : ruleSets ){
-// String[] rulesForRuleSet = configuration.getStringArray( "color.rules." + ruleSet );
-// for( String individualRule : rulesForRuleSet ){
-//
-// }
-// }
-//
-// setRules(rules);
+ setRules(newRules);
}
private boolean doLoadColorSettings(String name) {
@@ -280,7 +289,7 @@ public class RuleColorizer implements Colorizer {
new BufferedInputStream(new FileInputStream(f)));
Map map = (Map) s.readObject();
- setRules(map);
+// setRules(map);
} catch (EOFException eof) { //end of file - ignore..
} catch (IOException ioe) {
ioe.printStackTrace();
@@ -301,8 +310,8 @@ public class RuleColorizer implements Colorizer {
return f.exists();
}
- public Vector getDefaultColors() {
- Vector vec = new Vector();
+ public static List<Color> getDefaultColors() {
+ List<Color> vec = new ArrayList<>();
vec.add(Color.white);
vec.add(Color.black);
diff --git a/src/main/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java b/src/main/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java
index 6fbe25a..48d903d 100644
--- a/src/main/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java
+++ b/src/main/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java
@@ -52,7 +52,7 @@ public final class SettingsManager {
private class TabSettingsData{
FileBasedConfigurationBuilder<PropertiesConfiguration> file;
- CombinedConfiguration combined;
+ AbstractConfiguration tabSettings;
}
private PropertiesConfiguration m_configuration;
@@ -74,14 +74,19 @@ public final class SettingsManager {
settingsDir.mkdir();
}
- URL defaultPrefs = this.getClass().getClassLoader()
+ FileBasedBuilderParameters fileParams = params.fileBased();
+ if( f.exists() ){
+ fileParams.setFile(f);
+ }else{
+ URL defaultPrefs = this.getClass().getClassLoader()
.getResource("org/apache/log4j/chainsaw/prefs/default.properties");
+ fileParams.setURL(defaultPrefs);
+ }
m_builder =
new FileBasedConfigurationBuilder<PropertiesConfiguration>(
PropertiesConfiguration.class)
- .configure(params.fileBased()
- .setURL(defaultPrefs)
+ .configure(fileParams
.setListDelimiterHandler(new DefaultListDelimiterHandler(','))
);
@@ -118,14 +123,21 @@ public final class SettingsManager {
return m_configuration;
}
- public AbstractConfiguration getSettingsForReceiverTab(String identifier){
- if( m_tabSettings.containsKey( identifier ) ){
- return m_tabSettings.get( identifier ).combined;
- }
-
+ public AbstractConfiguration getCombinedSettingsForRecevierTab(String identifier){
// Override combiner: nodes in the first structure take precedence over the second
CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
+ combinedConfig.addConfiguration(getSettingsForReceiverTab(identifier));
+ combinedConfig.addConfiguration(getGlobalConfiguration());
+
+ return combinedConfig;
+ }
+
+ public AbstractConfiguration getSettingsForReceiverTab(String identifier){
+ if( m_tabSettings.containsKey( identifier ) ){
+ return m_tabSettings.get( identifier ).tabSettings;
+ }
+
PropertiesConfiguration configuration = null;
// Either we don't contain the key, or we got an exception. Regardless,
@@ -154,14 +166,11 @@ public final class SettingsManager {
AbstractConfiguration config = builder.getConfiguration();
builder.getFileHandler().setFile(f);
+ data.tabSettings = config;
- combinedConfig.addConfiguration(config);
- combinedConfig.addConfiguration(getGlobalConfiguration());
-
- data.combined = combinedConfig;
m_tabSettings.put( identifier, data );
- return combinedConfig;
+ return config;
}catch( ConfigurationException ex ){}
return null;
@@ -188,6 +197,9 @@ public final class SettingsManager {
for( String key : m_tabSettings.keySet() ){
try{
+ logger.debug( "Saving {}({}) to {}", key,
+ m_tabSettings.get(key).tabSettings,
+ m_tabSettings.get(key).file.getFileHandler().getURL() );
m_tabSettings.get(key).file.save();
}catch( ConfigurationException ex ){
logger.error( "Unable to save settings for {}", key );
diff --git a/src/main/resources/org/apache/log4j/chainsaw/prefs/default.properties b/src/main/resources/org/apache/log4j/chainsaw/prefs/default.properties
index 41d3a03..1c4ec4d 100644
--- a/src/main/resources/org/apache/log4j/chainsaw/prefs/default.properties
+++ b/src/main/resources/org/apache/log4j/chainsaw/prefs/default.properties
@@ -50,3 +50,14 @@ detailPaneVisible=true
highlightSearchMatchText=true
wrapMessage=true
searchResultsVisible=true
+
+# Default color settings
+color.rules(0).expression = level == FATAL || level == ERROR || exception exists
+color.rules(0).backgroundColor = #ff9999
+color.rules(0).foregroundColor = #000000
+color.rules(1).expression = level == WARN
+color.rules(1).backgroundColor = #ffff99
+color.rules(1).foregroundColor = #000000
+color.rules(2).expression = prop.marker exists
+color.rules(2).backgroundColor = #99ff99
+color.rules(2).foregroundColor = #000000
diff --git a/src/main/resources/org/apache/log4j/chainsaw/prefs/logpanel.properties b/src/main/resources/org/apache/log4j/chainsaw/prefs/logpanel.properties
index 2c284e5..d02d4e3 100644
--- a/src/main/resources/org/apache/log4j/chainsaw/prefs/logpanel.properties
+++ b/src/main/resources/org/apache/log4j/chainsaw/prefs/logpanel.properties
@@ -35,4 +35,3 @@ logpanel.treeDividerLocation=0
logpanel.hiddenLoggers=
logpanel.hiddenExpression=
logpanel.alwaysDisplayExpression=
-
[logging-chainsaw] 01/02: Application-wide preferences should work now
Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-chainsaw.git
commit 3ec07a607e9590f2c49dab1fc2d9b63c9dff29d3
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Tue Sep 6 15:58:49 2022 -0400
Application-wide preferences should work now
---
.../chainsaw/ApplicationPreferenceModelPanel.java | 283 ++++++---------------
1 file changed, 75 insertions(+), 208 deletions(-)
diff --git a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
index db37e38..45e38db 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
@@ -35,6 +35,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import org.apache.commons.configuration2.AbstractConfiguration;
+import org.apache.commons.configuration2.event.ConfigurationEvent;
import org.apache.log4j.chainsaw.prefs.SettingsManager;
@@ -46,13 +47,13 @@ import org.apache.log4j.chainsaw.prefs.SettingsManager;
public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
private static final Logger logger = LogManager.getLogger();
- private JTextField identifierExpression;
private JTextField toolTipDisplayMillis;
private JTextField cyclicBufferSize;
- private JComboBox<String> configurationURL;
private GeneralAllPrefPanel generalAllPrefPanel;
+ private AbstractConfiguration m_globalConfiguration;
ApplicationPreferenceModelPanel() {
+ m_globalConfiguration = SettingsManager.getInstance().getGlobalConfiguration();
initComponents();
getOkButton().addActionListener(
e -> {
@@ -295,16 +296,12 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
* @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");
@@ -314,35 +311,19 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
private void initComponents() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
- configurationURL = new JComboBox(); //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());
@@ -352,7 +333,6 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
p3.add(Box.createHorizontalGlue());
Box ok4 = new Box(BoxLayout.X_AXIS);
- ok4.add(okToRemoveSecurityManager);
ok4.add(Box.createHorizontalGlue());
add(p2);
@@ -374,78 +354,8 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
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());
-// }
-// }
-// }
-// }
-// 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.");
@@ -461,107 +371,74 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
}
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);
-// }
-//
-// });
-//
-//
-// 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",
-// evt -> toolTipDisplayMillis.setText(evt.getNewValue().toString()));
-//
-// 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);
-// }
-//
-// });
-//
-//
-// 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()));
+ m_globalConfiguration.addEventListener(ConfigurationEvent.SET_PROPERTY,
+ evt -> {
+ if( evt.getPropertyName().equals( "showSplash" ) ){
+ boolean value = (Boolean) evt.getPropertyValue();
+ showSplash.setSelected(value);
+ }
+ });
+
+ m_globalConfiguration.addEventListener(ConfigurationEvent.SET_PROPERTY,
+ evt -> {
+ if( evt.getPropertyName().equals( "responsiveness" ) ){
+ int value = (Integer) evt.getPropertyValue();
+ if (value >= 1000) {
+ int newValue = (value - 750) / 1000;
+ logger.debug(
+ "Adjusting old Responsiveness value from " + value + " to "
+ + newValue);
+ value = newValue;
+ }
+
+ responsiveSlider.setValue(value);
+ }
+ });
+
+ m_globalConfiguration.addEventListener(ConfigurationEvent.SET_PROPERTY,
+ evt -> {
+ if( evt.getPropertyName().equals( "toolTipDisplayMillis" ) ){
+ toolTipDisplayMillis.setText(evt.getPropertyValue().toString());
+ }
+ });
+
+ m_globalConfiguration.addEventListener(ConfigurationEvent.SET_PROPERTY,
+ evt -> {
+ if( evt.getPropertyName().equals( "cyclicBufferSize" ) ){
+ cyclicBufferSize.setText(evt.getPropertyValue().toString());
+ }
+ });
+
+ m_globalConfiguration.addEventListener(ConfigurationEvent.SET_PROPERTY,
+ evt -> {
+ if( evt.getPropertyName().equals( "confirmExit" ) ){
+ boolean value = (Boolean) evt.getPropertyValue();
+ confirmExit.setSelected(value);
+ }
+ });
+
+ showSplash.addActionListener(e -> m_globalConfiguration.setProperty("showSplash", showSplash.isSelected()));
+ 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);
+ m_globalConfiguration.setProperty("responsiveness", value);
+ }
+ });
+
+ confirmExit.addActionListener(
+ e -> m_globalConfiguration.setProperty( "confirmExit",
+ confirmExit.isSelected()));
}
private void setupInitialValues() {
@@ -570,20 +447,10 @@ public class ApplicationPreferenceModelPanel extends AbstractPreferencePanel {
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());
+ confirmExit.setSelected(m_globalConfiguration.getBoolean("confirmExit", Boolean.TRUE));
+ showSplash.setSelected(m_globalConfiguration.getBoolean("showSplash", Boolean.TRUE));
+ toolTipDisplayMillis.setText(m_globalConfiguration.getInt( "toolTipDisplayMillis", 1000 ) + "");
+ cyclicBufferSize.setText(m_globalConfiguration.getInt( "cyclicBufferSize", 20000 ) + "");
}
}
}