psmith 2003/10/02 01:28:56
Modified: src/java/org/apache/log4j/chainsaw
LogPanelPreferenceModel.java
Log:
Simplified the use of date format patterns in this model.
Added the Level's as Icon/Text property.
Revision Changes Path
1.3 +119 -88
jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
Index: LogPanelPreferenceModel.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LogPanelPreferenceModel.java 1 Oct 2003 23:35:43 -0000 1.2
+++ LogPanelPreferenceModel.java 2 Oct 2003 08:28:56 -0000 1.3
@@ -51,102 +51,133 @@
*/
package org.apache.log4j.chainsaw;
+import org.apache.log4j.chainsaw.prefs.SettingsManager;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
/**
* Used to encapsulate all the preferences for a given LogPanel
* @author Paul Smith
*/
public class LogPanelPreferenceModel {
- private final PropertyChangeSupport propertySupport = new
PropertyChangeSupport(this);
-
- private boolean useISO8601Format = true;
- private String alternateDateFormatPattern = "HH:mm:ss";
- /**
- * Returns the Date Pattern string for the alternate date formatter.
- * @return
- */
- public final String getAlternateDateFormatPattern() {
- return alternateDateFormatPattern;
- }
-
- /**
- * Configures the Date pattern to use when using the alternate
- * pattern
- * @param alternateDateFormatPattern
- */
- public final void setAlternateDateFormatPattern(String
alternateDateFormatPattern) {
- String oldVal = this.alternateDateFormatPattern;
- this.alternateDateFormatPattern = alternateDateFormatPattern;
- propertySupport.firePropertyChange("alternateDateFormatPattern",
oldVal, this.alternateDateFormatPattern);
- }
-
- /**
- * Whether to use the faster ISO8601Format object for
- * renderring dates, or not.
- * @return
- */
- public boolean isUseISO8601Format() {
- return useISO8601Format;
- }
-
- /**
- * Sets whether to use the ISO8601Format object for rendering
- * dates.
- * @param useISO8601Format
- */
- public void setUseISO8601Format(boolean useISO8601Format) {
- boolean oldVal = this.useISO8601Format;
- this.useISO8601Format = useISO8601Format;
- propertySupport.firePropertyChange("useISO8601Format", oldVal,
this.useISO8601Format);
- }
-
- /**
- * @param listener
- */
- public synchronized void addPropertyChangeListener(PropertyChangeListener
listener) {
- propertySupport.addPropertyChangeListener(listener);
- }
-
- /**
- * @param propertyName
- * @param listener
- */
- public synchronized void addPropertyChangeListener(
- String propertyName,
- PropertyChangeListener listener) {
- propertySupport.addPropertyChangeListener(propertyName, listener);
- }
-
- /**
- * @param listener
- */
- public synchronized void removePropertyChangeListener(PropertyChangeListener
listener) {
- propertySupport.removePropertyChangeListener(listener);
- }
-
- /**
- * @param propertyName
- * @param listener
- */
- public synchronized void removePropertyChangeListener(
- String propertyName,
- PropertyChangeListener listener) {
- propertySupport.removePropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Applies all the properties of another model to this model
- *
- * @param uncommitedPreferenceModel the model to copy
- * all the properties from
- */
- public void apply(LogPanelPreferenceModel that) {
- setAlternateDateFormatPattern(that.getAlternateDateFormatPattern());
- setUseISO8601Format(that.isUseISO8601Format());
-
- }
+ public static final String ISO8601 = "ISO8601";
+ public static final Collection DATE_FORMATS;
+
+ static {
+ Collection list = new ArrayList();
+
+ Properties properties = SettingsManager.getInstance().getDefaultSettings();
+ for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+
+ if (entry.getKey().toString().startsWith("DateFormat")) {
+ list.add(entry.getValue());
+ }
+ }
+
+ DATE_FORMATS = Collections.unmodifiableCollection(list);
+ }
+
+ private final PropertyChangeSupport propertySupport =
+ new PropertyChangeSupport(this);
+ private String dateFormatPattern = ISO8601;
+ private boolean levelIcons = true;
+
+ /**
+ * Returns the Date Pattern string for the alternate date formatter.
+ * @return
+ */
+ public final String getDateFormatPattern() {
+ return dateFormatPattern;
+ }
+
+ /**
+ * @param dateFormatPattern
+ */
+ public final void setDateFormatPattern(String dateFormatPattern) {
+ String oldVal = this.dateFormatPattern;
+ this.dateFormatPattern = dateFormatPattern;
+ propertySupport.firePropertyChange(
+ "dateFormatPattern", oldVal, this.dateFormatPattern);
+ }
+
+ /**
+ * @param listener
+ */
+ public synchronized void addPropertyChangeListener(
+ PropertyChangeListener listener) {
+ propertySupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * @param propertyName
+ * @param listener
+ */
+ public synchronized void addPropertyChangeListener(
+ String propertyName, PropertyChangeListener listener) {
+ propertySupport.addPropertyChangeListener(propertyName, listener);
+ }
+
+ /**
+ * @param listener
+ */
+ public synchronized void removePropertyChangeListener(
+ PropertyChangeListener listener) {
+ propertySupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * @param propertyName
+ * @param listener
+ */
+ public synchronized void removePropertyChangeListener(
+ String propertyName, PropertyChangeListener listener) {
+ propertySupport.removePropertyChangeListener(propertyName, listener);
+ }
+
+ /**
+ * Applies all the properties of another model to this model
+ *
+ * @param uncommitedPreferenceModel the model to copy
+ * all the properties from
+ */
+ public void apply(LogPanelPreferenceModel that) {
+ setDateFormatPattern(that.getDateFormatPattern());
+ setLevelIcons(that.isLevelIcons());
+ }
+
+ /**
+ * Returns true if this the fast ISO8601DateFormat object
+ * should be used instead of SimpleDateFormat
+ * @return
+ */
+ public boolean isUseISO8601Format() {
+ return getDateFormatPattern().equals(ISO8601);
+ }
+
+ /**
+ * @return
+ */
+ public boolean isLevelIcons() {
+ return levelIcons;
+ }
+
+ /**
+ * @param levelIcons
+ */
+ public void setLevelIcons(boolean levelIcons) {
+ boolean oldVal = this.levelIcons;
+ this.levelIcons = levelIcons;
+ propertySupport.firePropertyChange("levelIcons", oldVal, this.levelIcons);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]