1 // $Id: XSParticleRenderer.java 165 2009-05-28 21:46:38Z agony $
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
22 import javax.swing.DefaultListCellRenderer;
23 import javax.swing.JLabel;
24 import javax.swing.JList;
25 import javax.swing.ListCellRenderer;
26
27 import org.apache.xerces.xs.XSParticle;
28
29 /**
30 * @author Michael Engelhardt<me@mindcrime-ilab.de>
31 * @author $Author: agony $
32 * @version $Revision: 165 $
33 *
34 */
35 public class XSParticleRenderer implements ListCellRenderer {
36
37 private final ListCellRenderer listCellRendererDelegate = new DefaultListCellRenderer();
38
39 /*
40 * (non-Javadoc)
41 *
42 * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean,
43 * boolean)
44 */
45 @Override
46 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
47
48 JLabel cell = (JLabel) listCellRendererDelegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
49
50 if (value instanceof XSParticle) {
51 XSParticle particle = (XSParticle) value;
52 StringBuilder sb = new StringBuilder();
53 sb.append(particle.getName());
54 sb.append(":");
55 sb.append(", <");
56 sb.append(particle.getNamespace());
57 sb.append(">");
58 cell.setText(sb.toString());
59 }
60
61 return cell;
62 }
63
64 }