View Javadoc

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