View Javadoc

1   /*
2    * $Id: DocumentBuilderFactoryPreferencesPanel.java,v 1.8 2007/03/07 21:56:23 edankert Exp $
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  
22  
23  package org.xmlhammer.gui.preferences;
24  
25  import java.awt.event.ItemEvent;
26  import java.awt.event.ItemListener;
27  
28  import javax.swing.Box;
29  import javax.swing.JCheckBox;
30  import javax.swing.JLabel;
31  import javax.swing.JPanel;
32  import javax.swing.JTextField;
33  import javax.swing.border.CompoundBorder;
34  import javax.swing.border.EmptyBorder;
35  import javax.swing.border.TitledBorder;
36  
37  import org.bounce.FormLayout;
38  import org.xmlhammer.model.jaxp.JAXPDocumentBuilderFactory;
39  
40  /***
41   * Put comment...
42   * 
43   * @version $Revision: 1.8 $, $Date: 2007/03/07 21:56:23 $
44   * @author Edwin Dankert <edankert@gmail.com>
45   */
46  
47  public class DocumentBuilderFactoryPreferencesPanel extends PreferencesPanel {
48      private static final long serialVersionUID = -7714462525621553549L;
49  
50      private JTextField propertyField = null;
51  	private JLabel propertyLabel = null;
52  
53  	private JCheckBox useDefaultFactory = null;
54  	private JCheckBox coalescingField = null;
55  	private JCheckBox expandEntityReferencesField = null;
56  	private JCheckBox ignoringElementContentWhitespaceField = null;
57  	private JCheckBox ignoreCommentsField = null;
58  
59  	/***
60  	 * @param name
61  	 */
62  	public DocumentBuilderFactoryPreferencesPanel() {
63  		this(false);
64  	}
65  	
66  	public DocumentBuilderFactoryPreferencesPanel(boolean project) {
67  		super("javax.xml.parsers.DocumentBuilderFactory", "preferences.dom", project);
68  		
69          JPanel preferences = new JPanel( new FormLayout( 5, 2));
70          
71          setLabel("DocumentBuilderFactory");
72  
73          propertyField = new JTextField();
74          propertyLabel = new JLabel( "Property:");
75          
76          preferences.add( propertyLabel, FormLayout.LEFT);
77          preferences.add( propertyField, FormLayout.RIGHT_FILL);
78  
79          useDefaultFactory = new JCheckBox( "Use Default Factory Mechanism");
80          useDefaultFactory.addItemListener( new ItemListener() {
81              public void itemStateChanged( ItemEvent e) {
82                  propertyLabel.setEnabled( !useDefaultFactory.isSelected());
83                  propertyField.setEnabled( !useDefaultFactory.isSelected());
84              }
85          });
86          useDefaultFactory.setToolTipText( "<html><body>Uses an ordered lookup procedure to determine the<br>DocumentBuilderFactory implementation class to load.</body></html>");
87  
88          preferences.add( new JLabel(), FormLayout.LEFT);
89          preferences.add( useDefaultFactory, FormLayout.RIGHT);
90  
91          preferences.add( Box.createVerticalStrut(5), FormLayout.FULL);
92          
93          JPanel panel = new JPanel( new FormLayout( 5, 2));
94          panel.setBorder( new CompoundBorder( new TitledBorder( "Configuration"), new EmptyBorder( 0, 5, 5, 5)));
95  
96          coalescingField = new JCheckBox( "Coalescing");
97          coalescingField.setToolTipText( "<html><body>Specifies that the parser produced by this code will convert CDATA <br> nodes to Text nodes and append it to the adjacent <br> (if any) text node.</body></html>");
98          expandEntityReferencesField = new JCheckBox( "Expand entity references");
99          expandEntityReferencesField.setSelected( true);
100         expandEntityReferencesField.setToolTipText( "<html><body>Specifies that the parser produced by this code will expand <br> entity reference nodes.</body></html>");
101         ignoreCommentsField = new JCheckBox( "Ignore Comments");
102         ignoreCommentsField.setToolTipText( "<html><body>Specifies that the parser produced by this code will ignore comments.</body></html>");
103         ignoringElementContentWhitespaceField = new JCheckBox( "Ignore Element Content Whitespace");
104         ignoringElementContentWhitespaceField.setToolTipText( "<html><body>Specifies that the parsers created by this factory must <br> eliminate whitespace in element content <br> (sometimes known loosely as 'ignorable whitespace') <br> when parsing XML documents (see XML Rec 2.10). <br> Note that only whitespace which is directly contained within <br> element content that has an element only content model <br> (see XML Rec 3.2.1) will be eliminated. Due to reliance on <br> the content model this setting requires the parser <br> to be in validating mode.</body></html>");
105         
106         panel.add( coalescingField, FormLayout.FULL);
107         panel.add( expandEntityReferencesField, FormLayout.FULL);
108         panel.add( ignoreCommentsField, FormLayout.FULL);
109         panel.add( ignoringElementContentWhitespaceField, FormLayout.FULL);
110         
111         preferences.add( panel, FormLayout.FULL_FILL);
112         
113         setCenterPane( preferences);
114     }
115 
116 	public void setJAXPDocumentBuilderFactorySettings( JAXPDocumentBuilderFactory.Settings settings) {
117 		coalescingField.setSelected( settings.isCoalescing());;
118 		expandEntityReferencesField.setSelected( settings.isExpandEntityReference());
119 		ignoringElementContentWhitespaceField.setSelected( settings.isIgnoringElementContentWhitespace());
120 		ignoreCommentsField.setSelected( settings.isIgnoringComments());
121 
122 		useDefaultFactory.setSelected( settings.getValue() == null);
123 		propertyField.setText( settings.getValue() == null ? "" : settings.getValue());
124 	}
125 	
126 	public JAXPDocumentBuilderFactory.Settings getJAXPDocumentBuilderFactorySettings() {
127 		JAXPDocumentBuilderFactory.Settings settings = new JAXPDocumentBuilderFactory.Settings();
128 		settings.setCoalescing( coalescingField.isSelected());
129 		settings.setExpandEntityReference( expandEntityReferencesField.isSelected());
130 		settings.setIgnoringElementContentWhitespace( ignoringElementContentWhitespaceField.isSelected());
131 		settings.setIgnoringComments( ignoreCommentsField.isSelected());
132 
133 		if ( !useDefaultFactory.isSelected()) { 
134 			settings.setValue( propertyField.getText());
135 		}
136 		
137 		return settings;
138 	}
139 	
140 	public void reset() {
141 		setJAXPDocumentBuilderFactorySettings( new JAXPDocumentBuilderFactory.Settings());
142 	}
143 
144 	public void setEnabled( boolean enabled) {
145 		useDefaultFactory.setEnabled( enabled);
146 		coalescingField.setEnabled( enabled);
147 		expandEntityReferencesField.setEnabled( enabled);
148 		ignoringElementContentWhitespaceField.setEnabled( enabled);
149 		ignoreCommentsField.setEnabled( enabled);
150 		
151 		if ( !useDefaultFactory.isSelected()) { 
152 			propertyLabel.setEnabled( enabled);
153 			propertyField.setEnabled( enabled);
154 		}
155 	}
156 }