View Javadoc

1   // $Id$
2   /*
3    * xsAnalyzer - XML schema analyzing tool. Copyright (C) 2008 Michael Engelhardt
4    * 
5    * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6    * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7    * version.
8    * 
9    * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11   * 
12   * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
13   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14   */
15  /**
16   * 
17   */
18  package de.mindcrimeilab.xsanalyzer.ui.renderer;
19  
20  import java.awt.Component;
21  import java.util.Map;
22  
23  import javax.swing.DefaultListCellRenderer;
24  import javax.swing.JLabel;
25  import javax.swing.JList;
26  import javax.swing.ListCellRenderer;
27  import javax.xml.namespace.QName;
28  
29  import org.apache.xerces.xs.XSObjectList;
30  
31  /**
32   * 
33   * @author Michael Engelhardt<me@mindcrime-ilab.de>
34   * @author $Author$
35   * @version $Revision$
36   * 
37   */
38  public class QNameRenderer extends DefaultListCellRenderer implements ListCellRenderer {
39  
40      /*
41       * (non-Javadoc)
42       * 
43       * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int,
44       * boolean, boolean)
45       */
46      @Override
47      public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
48          final JLabel cell = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
49          if (value instanceof Map.Entry) {
50              final QName qname = ((Map.Entry<QName, XSObjectList>) value).getKey();
51              cell.setText(qname.getLocalPart() + ",<" + qname.getNamespaceURI() + ">");
52          }
53          return cell;
54      }
55  }