View Javadoc

1   /*
2    * $Id: PreferencesPanel.java,v 1.13 2007/07/04 19:42:50 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  package org.xmlhammer.gui.preferences;
23  
24  import java.awt.BorderLayout;
25  import java.awt.event.ItemEvent;
26  import java.awt.event.ItemListener;
27  
28  import javax.swing.JCheckBox;
29  import javax.swing.JComponent;
30  import javax.swing.JPanel;
31  import javax.swing.JSeparator;
32  import javax.swing.border.EmptyBorder;
33  
34  import org.xmlhammer.gui.util.preferences.HelpEnabledPreferencesPage;
35  
36  /***
37   * Generic Preferences Panel.
38   * 
39   * @version $Revision: 1.13 $, $Date: 2007/07/04 19:42:50 $
40   * @author Edwin Dankert <edankert@gmail.com>
41   */
42  
43  public abstract class PreferencesPanel extends HelpEnabledPreferencesPage {
44  	private static final long serialVersionUID = 6877164067547749433L;
45      
46      private JCheckBox projectSpecificCheck = null;
47      private JComponent centerPanel = null;
48      private String helpID = null;
49  
50  	/***
51  	 * Constructs a new Input Panel.
52  	 */
53  	public PreferencesPanel(String title, String helpID) {
54  		this(title, helpID, false);
55  	}
56  	
57  	public PreferencesPanel(String title, String helpID, boolean project) {
58  		super(title);
59          
60          this.helpID = helpID;
61          
62          centerPanel = new JPanel(new BorderLayout(10, 10));
63  
64          if ( project) {
65      		projectSpecificCheck = new JCheckBox( "Project Specific Settings");
66      		
67      		projectSpecificCheck.addItemListener( new ItemListener(){
68      			public void itemStateChanged( ItemEvent e) {
69      				setEnabled( projectSpecificCheck.isSelected());
70      			}
71      		});
72      		
73              JPanel checkPanel = new JPanel( new BorderLayout());
74              checkPanel.add( projectSpecificCheck, BorderLayout.NORTH);
75      
76              JPanel separatorPanel = new JPanel( new BorderLayout());
77      		separatorPanel.add( new JSeparator(), BorderLayout.SOUTH);
78      		separatorPanel.setBorder( new EmptyBorder( 5, 0, 0, 0));
79  		
80      		checkPanel.add( separatorPanel, BorderLayout.SOUTH);
81  
82      		JPanel northPanel = new JPanel( new BorderLayout());
83      		northPanel.add( checkPanel, BorderLayout.SOUTH);
84  		
85              centerPanel.add( northPanel, BorderLayout.NORTH);
86          }
87          
88          super.setCenterPane(centerPanel);
89  	}
90  	
91  	public void setProjectSpecific( boolean selected) {
92  		setEnabled( selected);
93  		projectSpecificCheck.setSelected( selected);		
94  	}
95  	
96  	public boolean isProjectSpecific() {
97  		if ( projectSpecificCheck != null) {
98  			return projectSpecificCheck.isSelected();		
99  		}
100 
101 		return false;		
102 	}
103 	
104     protected JComponent getCenterPane() {
105         return centerPanel;
106     }
107 
108     protected void setCenterPane(JComponent component) {
109         this.centerPanel = component;
110 		super.getCenterPane().add(centerPanel, BorderLayout.CENTER);
111 	}
112     
113     public String getHelpID() {
114         return helpID;
115     }
116 }