NXvalidate  1
 All Classes Namespaces Files Functions Variables
XMLTreeRenderer.java
Go to the documentation of this file.
1 /* NeXus - Neutron & X-ray Common Data Format
2  *
3  * NeXus file validation GUI tool.
4  *
5  * Copyright (C) 2010 Stephen Rankin
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * For further information, see <http://www.nexusformat.org/>
22  *
23  * XMLTreeRenderer.java
24  *
25  */
26 package org.nexusformat.nxvalidate;
27 
28 import java.awt.Component;
29 import java.util.ResourceBundle;
30 import javax.swing.Icon;
31 import javax.swing.ImageIcon;
32 import javax.swing.JTree;
33 import javax.swing.plaf.basic.BasicTreeUI;
34 import javax.swing.tree.DefaultTreeCellRenderer;
35 
43 public class XMLTreeRenderer extends DefaultTreeCellRenderer {
44 
45  private String badPath = "";
46  private String goodPath = "";
47  private String warnPath = "";
48  private String rootPath = "";
49  private String newPath = "";
50  private String infoPath = "";
51  private String infoGoodPath = "";
52  private String infoBadPath = "";
53  private String infoWarnPath = "";
54 
55  private ResourceBundle bundle = null;
56  private JTree tree = null;
61  public XMLTreeRenderer(String rootPath, String badPath,
62  String goodPath, String warnPath,
63  String newPath, String infoPath,
64  String infoGoodPath, String infoBadPath,
65  String infoWarnPath) {
66  this.badPath = badPath;
67  this.goodPath = goodPath;
68  this.warnPath = warnPath;
69  this.rootPath = rootPath;
70  this.newPath = newPath;
71  this.infoPath = infoPath;
72  this.infoGoodPath = infoGoodPath;
73  this.infoBadPath = infoBadPath;
74  this.infoWarnPath = infoWarnPath;
75  bundle = ResourceBundle.getBundle(
76  "org/nexusformat/nxvalidate/resources/nxvalidate");
77  }
78 
79  @Override
80  public Component getTreeCellRendererComponent(
81  JTree tree,
82  Object value,
83  boolean sel,
84  boolean expanded,
85  boolean leaf,
86  int row,
87  boolean hasFocus) {
88 
89  super.getTreeCellRendererComponent(
90  tree, value, sel,
91  expanded, leaf, row,
92  hasFocus);
93 
94  boolean validated = false;
95  this.tree = tree;
96 
97  //Add the bad node error icon and tool tip text.
98  NXNodeMapper node = (NXNodeMapper) value;
99 
100  if(node.getRoot()!=null){
101  validated = node.getRoot().getValidatedNode();
102  }
103  else{
104  validated = node.getValidatedNode();
105  }
106 
107  if(node.hasBadChildren()){
108 
109  }
110 
111  /*boolean badKids = node.checkBadChildren();
112  if (badKids) {
113  setIcon(createImageIcon("resources/dialog-warning.png", "warningIcon"));
114  }*/
115  if (node.getBadNode() && node.hasBadChildren()) {
116  setIcon(createImageIcon(infoBadPath, "errorIcon"));
117  }
118  else if(node.getBadNode() && !node.hasBadChildren()) {
119  setIcon(createImageIcon(badPath, "errorIcon"));
120  }
121  else if(node.getWarnNode() && node.hasBadChildren()){
122  setIcon(createImageIcon(infoWarnPath, "warnIcon"));
123  }
124  else if(node.getWarnNode() && !node.hasBadChildren()){
125  setIcon(createImageIcon(warnPath, "warnIcon"));
126  }
127  else if (node.isRoot()){
128  setIcon(createImageIcon(rootPath, "rootIcon"));
129  }
130  else if(!validated){
131  setIcon(createImageIcon(newPath, "newIcon"));
132  }
133  else if(node.isDocument() && node.hasBadChildren()){
134  setIcon(createImageIcon(infoPath, "infoIcon"));
135  }
136  else{
137  if(node.hasBadChildren()) {
138  setIcon(createImageIcon(infoGoodPath, "goodIcon"));
139  }
140  else{
141  setIcon(createImageIcon(goodPath, "goodIcon"));
142  }
143  }
144 
145  return this;
146  }
147 
156  public void setExpandedIcon(Icon expanded) {
157  if (tree.getUI() instanceof BasicTreeUI) {
158  ((BasicTreeUI) tree.getUI()).setExpandedIcon(expanded);
159  }
160  }
161 
170  public void setCollapsedIcon(Icon collapsed) {
171  if (tree.getUI() instanceof BasicTreeUI) {
172  ((BasicTreeUI) tree.getUI()).setCollapsedIcon(collapsed);
173  }
174  }
175 
177  protected ImageIcon createImageIcon(String path,
178  String description) {
179  java.net.URL imgURL = getClass().getResource(path);
180  if (imgURL != null) {
181  return new ImageIcon(imgURL, description);
182  } else {
183  System.err.println("Couldn't find file: " + path);
184  return null;
185  }
186  }
187 }
void setCollapsedIcon(Icon collapsed)
sets the icon for the handel of a collapsed node.
Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
boolean getWarnNode()
If a node in the reduced XML document fails one of the schematron report tests then the node can be m...
boolean hasBadChildren()
Check to see if the node has any vary bad kids, return true if it has.
boolean getBadNode()
If a node in the reduced XML document fails one of the schematron tests then the node can be marked a...
void setExpandedIcon(Icon expanded)
sets the icon for the handle of an expanded node.
boolean getValidatedNode()
If a node has been validated then we can indicate the fact with a boolean flag.
XMLTreeRenderer(String rootPath, String badPath, String goodPath, String warnPath, String newPath, String infoPath, String infoGoodPath, String infoBadPath, String infoWarnPath)
Setup a tree renderer with custom icons.
ImageIcon createImageIcon(String path, String description)
Returns an ImageIcon, or null if the path was invalid.
We need to modify the tree representing the reduced document when nodes are found to be bad (validati...