Coverage Report - org.xmlhammer.gui.preferences.DocumentBuilderFactoryPreferencesPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentBuilderFactoryPreferencesPanel
93% 
100% 
1.286
 
 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  176
 public class DocumentBuilderFactoryPreferencesPanel extends PreferencesPanel {
 48  
     private static final long serialVersionUID = -7714462525621553549L;
 49  
 
 50  44
     private JTextField propertyField = null;
 51  44
         private JLabel propertyLabel = null;
 52  
 
 53  44
         private JCheckBox useDefaultFactory = null;
 54  44
         private JCheckBox coalescingField = null;
 55  44
         private JCheckBox expandEntityReferencesField = null;
 56  44
         private JCheckBox ignoringElementContentWhitespaceField = null;
 57  44
         private JCheckBox ignoreCommentsField = null;
 58  
 
 59  
         /**
 60  
          * @param name
 61  
          */
 62  
         public DocumentBuilderFactoryPreferencesPanel() {
 63  22
                 this(false);
 64  22
         }
 65  
         
 66  
         public DocumentBuilderFactoryPreferencesPanel(boolean project) {
 67  44
                 super("javax.xml.parsers.DocumentBuilderFactory", "preferences.dom", project);
 68  
                 
 69  44
         JPanel preferences = new JPanel( new FormLayout( 5, 2));
 70  
         
 71  44
         setLabel("DocumentBuilderFactory");
 72  
 
 73  44
         propertyField = new JTextField();
 74  44
         propertyLabel = new JLabel( "Property:");
 75  
         
 76  44
         preferences.add( propertyLabel, FormLayout.LEFT);
 77  44
         preferences.add( propertyField, FormLayout.RIGHT_FILL);
 78  
 
 79  44
         useDefaultFactory = new JCheckBox( "Use Default Factory Mechanism");
 80  44
         useDefaultFactory.addItemListener( new ItemListener() {
 81  44
             public void itemStateChanged( ItemEvent e) {
 82  44
                 propertyLabel.setEnabled( !useDefaultFactory.isSelected());
 83  44
                 propertyField.setEnabled( !useDefaultFactory.isSelected());
 84  44
             }
 85  
         });
 86  44
         useDefaultFactory.setToolTipText( "<html><body>Uses an ordered lookup procedure to determine the<br>DocumentBuilderFactory implementation class to load.</body></html>");
 87  
 
 88  44
         preferences.add( new JLabel(), FormLayout.LEFT);
 89  44
         preferences.add( useDefaultFactory, FormLayout.RIGHT);
 90  
 
 91  44
         preferences.add( Box.createVerticalStrut(5), FormLayout.FULL);
 92  
         
 93  44
         JPanel panel = new JPanel( new FormLayout( 5, 2));
 94  44
         panel.setBorder( new CompoundBorder( new TitledBorder( "Configuration"), new EmptyBorder( 0, 5, 5, 5)));
 95  
 
 96  44
         coalescingField = new JCheckBox( "Coalescing");
 97  44
         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  44
         expandEntityReferencesField = new JCheckBox( "Expand entity references");
 99  44
         expandEntityReferencesField.setSelected( true);
 100  44
         expandEntityReferencesField.setToolTipText( "<html><body>Specifies that the parser produced by this code will expand <br> entity reference nodes.</body></html>");
 101  44
         ignoreCommentsField = new JCheckBox( "Ignore Comments");
 102  44
         ignoreCommentsField.setToolTipText( "<html><body>Specifies that the parser produced by this code will ignore comments.</body></html>");
 103  44
         ignoringElementContentWhitespaceField = new JCheckBox( "Ignore Element Content Whitespace");
 104  44
         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  44
         panel.add( coalescingField, FormLayout.FULL);
 107  44
         panel.add( expandEntityReferencesField, FormLayout.FULL);
 108  44
         panel.add( ignoreCommentsField, FormLayout.FULL);
 109  44
         panel.add( ignoringElementContentWhitespaceField, FormLayout.FULL);
 110  
         
 111  44
         preferences.add( panel, FormLayout.FULL_FILL);
 112  
         
 113  44
         setCenterPane( preferences);
 114  44
     }
 115  
 
 116  
         public void setJAXPDocumentBuilderFactorySettings( JAXPDocumentBuilderFactory.Settings settings) {
 117  44
                 coalescingField.setSelected( settings.isCoalescing());;
 118  44
                 expandEntityReferencesField.setSelected( settings.isExpandEntityReference());
 119  44
                 ignoringElementContentWhitespaceField.setSelected( settings.isIgnoringElementContentWhitespace());
 120  44
                 ignoreCommentsField.setSelected( settings.isIgnoringComments());
 121  
 
 122  44
                 useDefaultFactory.setSelected( settings.getValue() == null);
 123  44
                 propertyField.setText( settings.getValue() == null ? "" : settings.getValue());
 124  44
         }
 125  
         
 126  
         public JAXPDocumentBuilderFactory.Settings getJAXPDocumentBuilderFactorySettings() {
 127  22
                 JAXPDocumentBuilderFactory.Settings settings = new JAXPDocumentBuilderFactory.Settings();
 128  22
                 settings.setCoalescing( coalescingField.isSelected());
 129  22
                 settings.setExpandEntityReference( expandEntityReferencesField.isSelected());
 130  22
                 settings.setIgnoringElementContentWhitespace( ignoringElementContentWhitespaceField.isSelected());
 131  22
                 settings.setIgnoringComments( ignoreCommentsField.isSelected());
 132  
 
 133  22
                 if ( !useDefaultFactory.isSelected()) { 
 134  0
                         settings.setValue( propertyField.getText());
 135  
                 }
 136  
                 
 137  22
                 return settings;
 138  
         }
 139  
         
 140  
         public void reset() {
 141  0
                 setJAXPDocumentBuilderFactorySettings( new JAXPDocumentBuilderFactory.Settings());
 142  0
         }
 143  
 
 144  
         public void setEnabled( boolean enabled) {
 145  22
                 useDefaultFactory.setEnabled( enabled);
 146  22
                 coalescingField.setEnabled( enabled);
 147  22
                 expandEntityReferencesField.setEnabled( enabled);
 148  22
                 ignoringElementContentWhitespaceField.setEnabled( enabled);
 149  22
                 ignoreCommentsField.setEnabled( enabled);
 150  
                 
 151  22
                 if ( !useDefaultFactory.isSelected()) { 
 152  0
                         propertyLabel.setEnabled( enabled);
 153  0
                         propertyField.setEnabled( enabled);
 154  
                 }
 155  22
         }
 156  
 }