View Javadoc

1   // $Id: SimilarTypeRenderer.java 167 2009-05-29 17:43:07Z 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 de.mindcrimeilab.xsanalyzer.model.SimilarTypeListModelEntry;
28  
29  /**
30   * @author Michael Engelhardt<me@mindcrime-ilab.de>
31   * @author $Author: agony $
32   * @version $Revision: 167 $
33   * 
34   */
35  public class SimilarTypeRenderer extends DefaultListCellRenderer implements ListCellRenderer {
36  
37      private final ListCellRenderer renderDelegate;
38  
39      public SimilarTypeRenderer() {
40          renderDelegate = new SchemaElementsRenderer();
41      }
42  
43      @Override
44      public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
45          final JLabel cell;
46  
47          if (value instanceof SimilarTypeListModelEntry) {
48              SimilarTypeListModelEntry entry = (SimilarTypeListModelEntry) value;
49  
50              cell = (JLabel) renderDelegate.getListCellRendererComponent(list, entry.getType(), index, isSelected, cellHasFocus);
51              cell.setText(cell.getText());
52              cell.setToolTipText("Computed similarity md5 sum:" + entry.getTypeSignature() + ".");
53          }
54          else {
55              cell = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
56          }
57          return cell;
58      }
59  }