Crossfire JXClient, Trunk  R20561
CharacterCellRenderer.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2010 Nicolas Weeger.
19  */
20 
21 package com.realtime.crossfire.jxclient.gui.list;
22 
23 import java.awt.BorderLayout;
24 import java.awt.Component;
25 import javax.swing.JList;
26 import javax.swing.JPanel;
27 import org.jetbrains.annotations.NotNull;
28 
33 public class CharacterCellRenderer extends JPanel implements GUIListCellRenderer<GUICharacter> {
34 
38  private static final long serialVersionUID = 1;
39 
43  private final GUICharacter template;
44 
50  public CharacterCellRenderer(@NotNull final GUICharacter template) {
51  super(new BorderLayout());
52  setOpaque(false);
53  this.template = template;
54  add(template, BorderLayout.CENTER);
55  }
56 
60  @Override
61  public Component getListCellRendererComponent(@NotNull final JList<? extends GUICharacter> list, @NotNull final GUICharacter value, final int index, final boolean isSelected, final boolean cellHasFocus) {
62  template.setIndex(value.getIndex());
63  template.setSelected(isSelected);
64  return this;
65  }
66 
67 }
Component getListCellRendererComponent(@NotNull final JList<? extends GUICharacter > list, @NotNull final GUICharacter value, final int index, final boolean isSelected, final boolean cellHasFocus)
A ListCellRenderer that implements resizing after screen resolution changes.
CharacterCellRenderer(@NotNull final GUICharacter template)
Creates a new instance.