View Javadoc

1   /*
2    * $Id: CheckBoxNode.java,v 1.3 2006/09/07 13:37:36 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.overview;
24  
25  import java.awt.event.ItemEvent;
26  import java.awt.event.ItemListener;
27  import java.util.ArrayList;
28  
29  import javax.swing.Icon;
30  import javax.swing.ImageIcon;
31  import javax.swing.JCheckBox;
32  
33  import org.bounce.image.ImageLoader;
34  
35  
36  public class CheckBoxNode implements OverviewNode, ItemListener {
37  	private static final ImageIcon UNSELECTED_ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/elcl16/disabled_co.gif");
38  	private static final ImageIcon SELECTED_ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/elcl16/enabled_co.gif");
39  
40  	private ArrayList<OverviewNode> empty = new ArrayList<OverviewNode>();
41  	private JCheckBox check     = null;
42  	private OverviewNode parent = null;
43      private String error        = null;
44  
45      public CheckBoxNode( OverviewNode parent, JCheckBox check) {
46          this.parent = parent;
47          this.check = check;
48          
49          check.addItemListener( this);
50      }
51      public String getNodeName() {
52          return check.getText();
53      }
54  
55      public ArrayList<OverviewNode> getChildNodes() {
56          return empty;
57      }
58  
59      public OverviewNode getParentNode() {
60          return parent;
61      }
62  
63      public Icon getNodeIcon() {
64      	if ( check.isSelected()) { 
65      		return SELECTED_ICON;
66      	}
67  
68      	return UNSELECTED_ICON;
69      }
70  
71      public void itemStateChanged( ItemEvent e) {
72      	OverviewNode node = parent;
73      	
74      	while ( node != null && !(node.getParentNode() instanceof OverviewTreeModel)) {
75      		node = node.getParentNode();
76      	}
77      	
78  		if ( node != null) {
79      		((OverviewTreeModel)node.getParentNode()).nodeChanged( this);
80      	}
81      }
82      
83      public void setError(String error) {
84          this.error = error;
85      }
86      
87      public String getError() {
88          return error;
89      }
90  }