View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  package com.mindtree.techworks.insight.gui.preferences;
25  
26  import javax.swing.JLabel;
27  import javax.swing.JScrollPane;
28  import javax.swing.JTextField;
29  import javax.swing.JTextPane;
30  
31  import com.mindtree.techworks.insight.InsightConstants;
32  
33  /**
34  *
35  * The <code>LogPatternUIPanel</code> displays the UI for editing 
36  * log pattern definition.
37  *
38  * @see com.mindtree.techworks.insight.preferences.model.Preference
39  * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel
40  *
41  * @author  Regunath B
42  * @version 1.0, 05/02/11
43  */
44  public class LogPatternUIPanel extends AbstractPreferencesUIPanel {
45  	
46  	/**
47  	 * Used for object serialization
48  	 */
49  	private static final long serialVersionUID = -5115766011595135952L;
50  
51  	/**
52  	 * The static text for supported log4j patterns
53  	 */
54  	private static final String SUPPORTED_PATTERN = 
55  		  "<p>" +
56  		  "<i>The following variables may be used in the Pattern and their interpretation are:</i>" +
57  		  "<ul>" + 
58  		  "<li>%c - category LOGGER</li>" +
59  		  "<li>%C - Class name CLASS</li>" +
60  		  "<li>%d - date TIMESTAMP</li>" +
61  		  "<li>%l - location information FILE</li>" +
62  		  "<li>%F - location information FILE</li>" +
63  		  "<li>%L - Line number of caller LINE</li>" +
64  		  "<li>%m - application message MESSAGE</li>" +
65  		  "<li>%M - method name of caller METHOD</li>" +
66  		  "<li>%p - priority LEVEL</li>" +
67  		  "<li>%r - number of milliseconds elapsed time since start RELATIVETIME</li>" +
68  		  "<li>%t - thread name THREAD</li>" +
69  		  "<li>%x - NDC (nested diagnostic context) associated with the thread NDC" +
70  		  "<li>%n - Line Feed" +
71  		  "</li>" +
72  		  "</ul>" +
73  		  "</p>";		
74  	
75  	/**
76  	 * Constants for attribute Ids of the log4j preference 
77  	 */
78  	private static final String PRIMARY_PATTERN_ID = "primaryPattern";
79  	private static final String SECONDARY_PATTERN_ID = "secondaryPattern";
80  
81  	/**
82  	 * Pattern edit fields
83  	 */
84  	private JTextField primaryPatternField;	
85  	private JTextField secondaryPatternField;	
86  	
87  	/**
88  	 * The JEditorPane instance used to render the supported pattern details
89  	 */
90  	private JTextPane detailsPane;	
91  	
92  	
93  	/**
94  	 * No args constructor
95  	 */
96  	public LogPatternUIPanel() {
97  	}
98  
99  	/**
100 	 *  Overriden super class method
101 	 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#initializeDisplay()
102 	 */
103 	protected void initializeDisplay() {
104 		addComponent(new JLabel(InsightConstants.getLiteral("PRIMARY_PATTERN")),0,0,0,0,1,1);
105 		this.primaryPatternField = new JTextField();
106 		addComponent(primaryPatternField,1,0,1,0, 3, 1);
107 		JLabel samplePatternLabel = new JLabel(InsightConstants.getLiteral("SAMPLE_PATTERN") + 
108 				this.preference.getPreferenceAttributeById(PRIMARY_PATTERN_ID).getDefaultValue());
109 		samplePatternLabel.setFont(InsightConstants.DEFAULT_SMALL_FONT);
110 		addComponent(samplePatternLabel,2,1,0,0,1,1);
111 		
112 		addComponent(new JLabel(InsightConstants.getLiteral("SECONDARY_PATTERN")),0,2,0,0,1,1);
113 		this.secondaryPatternField = new JTextField();
114 		addComponent(secondaryPatternField,1,2,1,0, 3, 1);
115 		
116         this.detailsPane = new JTextPane();
117         detailsPane.setEditable(false);
118         detailsPane.setEnabled(false);
119         detailsPane.setContentType("text/html");
120         detailsPane.setText(SUPPORTED_PATTERN);	
121 		addComponent(new JScrollPane(detailsPane),0,3,1,1,4,1);
122 		
123 		// set the values from the Preference
124 		this.primaryPatternField.setText(this.preference.getPreferenceAttributeById(PRIMARY_PATTERN_ID).getValue());		
125 		this.secondaryPatternField.setText(this.preference.getPreferenceAttributeById(SECONDARY_PATTERN_ID).getValue());		
126 	}
127 	
128 	/**
129 	 *  Overriden super class method
130 	 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#setPreferenceValues()
131 	 */
132 	protected  void setPreferenceValues() {
133 		this.preference.getPreferenceAttributeById(PRIMARY_PATTERN_ID).setValue(this.primaryPatternField.getText());
134 		this.preference.getPreferenceAttributeById(SECONDARY_PATTERN_ID).setValue(this.secondaryPatternField.getText());
135 	}
136 
137 }