View Javadoc

1   /*
2   
3       dsh-venn-cytoscape3-app  Cytoscape3 app for venn and euler diagrams.
4       Copyright (c) 2012-2013 held jointly by the individual authors.
5   
6       This library is free software; you can redistribute it and/or modify it
7       under the terms of the GNU Lesser General Public License as published
8       by the Free Software Foundation; either version 3 of the License, or (at
9       your option) any later version.
10  
11      This library is distributed in the hope that it will be useful, but WITHOUT
12      ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
13      FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14      License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public License
17      along with this library;  if not, write to the Free Software Foundation,
18      Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
19  
20      > http://www.fsf.org/licensing/licenses/lgpl.html
21      > http://www.opensource.org/licenses/lgpl-license.php
22  
23  */
24  package org.dishevelled.venn.cytoscape3.internal;
25  
26  import static org.dishevelled.venn.cytoscape3.internal.VennDiagramsUtils.nameOf;
27  
28  import java.awt.Component;
29  
30  import javax.swing.DefaultListCellRenderer;
31  import javax.swing.JLabel;
32  import javax.swing.JList;
33  
34  import org.cytoscape.application.CyApplicationManager;
35  import org.cytoscape.group.CyGroup;
36  import org.cytoscape.model.CyNetwork;
37  
38  /**
39   * List cell renderer for <code>CyGroup</code>.
40   *
41   * @author  Michael Heuer
42   */
43  final class CyGroupListCellRenderer extends DefaultListCellRenderer //IdListCellRenderer
44  {
45      /** Application manager. */
46      private final CyApplicationManager applicationManager;
47  
48  
49      /**
50       * Create a new CyGroup list cell renderer with the specified application manager.
51       *
52       * @param applicationManager application manager, must not be null
53       */
54      CyGroupListCellRenderer(final CyApplicationManager applicationManager)
55      {
56          super();
57          if (applicationManager == null)
58          {
59              throw new IllegalArgumentException("applicationManager must not be null");
60          }
61          this.applicationManager = applicationManager;
62      }
63  
64  
65      /** {@inheritDoc} */
66      public Component getListCellRendererComponent(final JList list,
67                                                    final Object value,
68                                                    final int index,
69                                                    final boolean isSelected,
70                                                    final boolean hasFocus)
71      {
72          JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
73  
74          // alternatively, provide a BeanInfo implementation for CyNode, CyGroup that implements getName in this manner
75          if (value instanceof CyGroup)
76          {
77              CyGroup group = (CyGroup) value;
78              CyNetwork network = applicationManager.getCurrentNetwork();
79              label.setText(nameOf(group, network));
80          }
81          return label;
82      }
83  }