View Javadoc

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