View Javadoc

1   /*
2    * $Id: SAXParserFactoryPreferencesPanel.java,v 1.10 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  
34  import org.bounce.FormLayout;
35  import org.xmlhammer.model.jaxp.JAXPSAXParserFactory;
36  
37  /***
38   * Put comment...
39   * 
40   * @version $Revision: 1.10 $, $Date: 2007/03/07 21:56:23 $
41   * @author Edwin Dankert <edankert@gmail.com>
42   */
43  
44  public class SAXParserFactoryPreferencesPanel extends PreferencesPanel {
45      private static final long serialVersionUID = -4140066420809363167L;
46  
47      private JTextField propertyField = null;
48  	private JLabel propertyLabel = null;
49  	private JCheckBox useDefaultFactory = null;
50  	
51  	/***
52  	 * @param name
53  	 */
54  	public SAXParserFactoryPreferencesPanel() {
55  		this(false);
56  	}
57  
58  	/***
59  	 * @param name
60  	 */
61  	public SAXParserFactoryPreferencesPanel( boolean project) {
62  		super("javax.xml.parsers.SAXParserFactory", "preferences.sax", project);
63  
64          JPanel preferences = new JPanel( new FormLayout( 5, 2));
65          
66          setLabel("SAXParserFactory");
67  
68          propertyField = new JTextField();
69          propertyLabel = new JLabel( "Property:");
70          
71          preferences.add( propertyLabel, FormLayout.LEFT);
72          preferences.add( propertyField, FormLayout.RIGHT_FILL);
73  
74          useDefaultFactory = new JCheckBox( "Use Default Factory Mechanism");
75          useDefaultFactory.addItemListener( new ItemListener() {
76              public void itemStateChanged( ItemEvent e) {
77                  propertyLabel.setEnabled( !useDefaultFactory.isSelected());
78                  propertyField.setEnabled( !useDefaultFactory.isSelected());
79              }
80          });
81          useDefaultFactory.setToolTipText( "<html><body>Uses an ordered lookup procedure to determine the<br>SAXParserFactory implementation class to load.</body></html>");
82  
83          preferences.add( new JLabel(), FormLayout.LEFT);
84          preferences.add( useDefaultFactory, FormLayout.RIGHT);
85  
86          preferences.add( Box.createVerticalStrut(5), FormLayout.FULL);
87          
88          setCenterPane( preferences);
89      }
90  	
91  	public void setJAXPSAXParserFactorySettings( JAXPSAXParserFactory.Settings settings) {
92  		useDefaultFactory.setSelected( settings.getValue() == null);
93  		propertyField.setText( settings.getValue() == null ? "" : settings.getValue());
94  	}
95  	
96  	public JAXPSAXParserFactory.Settings getJAXPSAXParserFactorySettings() {
97  		JAXPSAXParserFactory.Settings settings = new JAXPSAXParserFactory.Settings();
98  		
99  		if ( !useDefaultFactory.isSelected()) { 
100 			settings.setValue( propertyField.getText());
101 		}
102 		
103 		return settings;
104 	}
105 	
106 	public void reset() {
107 		setJAXPSAXParserFactorySettings( new JAXPSAXParserFactory.Settings());
108 	}
109 
110 	public void setEnabled( boolean enabled) {
111 		useDefaultFactory.setEnabled( enabled);
112 		
113 		if ( !useDefaultFactory.isSelected()) { 
114 			propertyLabel.setEnabled( enabled);
115 			propertyField.setEnabled( enabled);
116 		}
117 	}
118 }