gt:     if (getPiece() != null) {
context: /*
   * $Id$
   *
   * Copyright (c) 2000-2003 by Rodney Kinney
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
   * License (LGPL) as published by the Free Software Foundation.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Library General Public License for more details.
   *
   * You should have received a copy of the GNU Library General Public
   * License along with this library; if not, copies are available
   * at http://www.opensource.org.
   */
  package VASSAL.build.widget;
  
  import java.awt.Color;
  import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.Font;
  import java.awt.FontMetrics;
  import java.awt.Graphics;
  import java.awt.Point;
  import java.awt.dnd.DnDConstants;
  import java.awt.dnd.DragGestureEvent;
  import java.awt.dnd.DragGestureListener;
  import java.awt.dnd.DragSource;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import javax.swing.JPanel;
  import javax.swing.JPopupMenu;
  import javax.swing.KeyStroke;
  import javax.swing.event.PopupMenuEvent;
  import javax.swing.event.PopupMenuListener;
  
  import VASSAL.build.Buildable;
  import VASSAL.build.Builder;
  import VASSAL.build.Configurable;
  import VASSAL.build.GameModule;
  import VASSAL.build.GpIdSupport;
  import VASSAL.build.Widget;
  import VASSAL.build.module.Map;
  import VASSAL.build.module.documentation.HelpFile;
  import VASSAL.build.module.documentation.HelpWindow;
  import VASSAL.build.module.documentation.HelpWindowExtension;
  import VASSAL.build.module.map.MenuDisplayer;
  import VASSAL.build.module.map.PieceMover.AbstractDragHandler;
  import VASSAL.command.AddPiece;
  import VASSAL.command.Command;
  import VASSAL.configure.Configurer;
  import VASSAL.counters.BasicPiece;
  import VASSAL.counters.Decorator;
  import VASSAL.counters.DragBuffer;
  import VASSAL.counters.GamePiece;
  import VASSAL.counters.KeyBuffer;
  import VASSAL.counters.PieceCloner;
  import VASSAL.counters.PieceDefiner;
  import VASSAL.counters.PlaceMarker;
  import VASSAL.counters.Properties;
  import VASSAL.i18n.ComponentI18nData;
  
  /**
   * A Component that displays a GamePiece.
   *
   * Can be added to any Widget but cannot contain any children Keyboard input on
   * a PieceSlot is forwarded to the {@link GamePiece#keyEvent} method for the
   * PieceSlot's GamePiece. Clicking on a PieceSlot initiates a drag
   */
  public class PieceSlot extends Widget implements MouseListener, KeyListener {
    public static final String GP_ID = "gpid";
    protected GamePiece c;
    protected GamePiece expanded;
    protected String name;
    protected String pieceDefinition;
    protected static Font FONT = new Font("Dialog", 0, 12);
    protected JPanel panel;
    protected int width, height;
    protected String gpId = ""; // Unique PieceSlot Id
    protected GpIdSupport gpidSupport;
  
    public PieceSlot() {
      panel = new PieceSlot.Panel(this);
      panel.addMouseListener(this);
      panel.addKeyListener(this);
    }
  
    public PieceSlot(PieceSlot piece) {
      this();
      copyFrom(piece);
    }
  
    public PieceSlot(CardSlot card) {
      this((PieceSlot) card);
    }
  
    protected void copyFrom(PieceSlot piece) {
      c = piece.c;
      name = piece.name;
      pieceDefinition = piece.pieceDefinition;
      gpidSupport = piece.gpidSupport;
      gpId = piece.gpId;
    }
  
    public class Panel extends JPanel {
      private static final long serialVersionUID = 1L;
      protected PieceSlot pieceSlot;
  
      public Panel(PieceSlot slot) {
        super();
        setFocusTraversalKeysEnabled(false);
        pieceSlot = slot;
      }
  
      public PieceSlot getPieceSlot() {
        return pieceSlot;
      }
  
      public void paint(Graphics g) {
        PieceSlot.this.paint(g);
      }
  
      public Dimension getPreferredSize() {
        return PieceSlot.this.getPreferredSize();
      }
    }
  
    public PieceSlot(GamePiece p) {
      this();
      setPiece(p);
    }
  
    public void setPiece(GamePiece p) {
      c = p;
      clearExpandedPiece();
      if (c != null) {
        final Dimension size = panel.getSize();
        c.setPosition(new Point(size.width / 2, size.height / 2));
        name = Decorator.getInnermost(c).getName();
      }
      panel.revalidate();
      panel.repaint();
      pieceDefinition = c == null ? null :
        GameModule.getGameModule().encode(new AddPiece(c));
    }
  
    /**
     * Return defined GamePiece with prototypes fully expanded.
     *
     * @return expanded piece
     */
    protected GamePiece getExpandedPiece() {
      if (expanded == null) {
        final GamePiece p = getPiece();
        if (p != null) {  // Possible when PlaceMarker is building
          expanded = PieceCloner.getInstance().clonePiece(p);
        }
      }
      return expanded;
    }
  
    protected void clearExpandedPiece() {
      expanded = null;
    }
  
    /**
     * Return defined GamePiece with prototypes unexpanded.
     *
     * @return unexpanded piece
     */
    public GamePiece getPiece() {
      if (c == null && pieceDefinition != null) {
        final AddPiece comm =
          (AddPiece) GameModule.getGameModule().decode(pieceDefinition);
        if (comm == null) {
          System.err.println("Couldn't build piece " + pieceDefinition);
          pieceDefinition = null;
        }
        else {
          c = comm.getTarget();
          c.setState(comm.getState());
  
          final Dimension size = panel.getSize();
          c.setPosition(new Point(size.width / 2, size.height / 2));
        }
      }
  
      if (c != null) {
        c.setProperty(Properties.PIECE_ID, getGpId());
      }
  
      return c;
    }
  
    public void paint(Graphics g) {
      final Dimension size = panel.getSize();
  
      final Color c = g.getColor();
      g.setColor(Color.WHITE);
      g.fillRect(0, 0, size.width, size.height);
      g.setColor(c);
  
      if (getExpandedPiece() == null) {
        final FontMetrics fm = g.getFontMetrics();
        g.drawRect(0, 0, size.width - 1, size.height - 1);
        g.setFont(FONT);
        g.drawString(" nil ",
          size.width/2 - fm.stringWidth(" nil ")/2,
          size.height/2
        );
      }
      else {
        getExpandedPiece().draw(g, size.width / 2, size.height / 2, panel, 1.0);
  
        // NB: The piece, not the expanded piece, receives events, so we check
        // the piece, not the expanded piece, for its selection status.
        if (Boolean.TRUE.equals(getPiece().getProperty(Properties.SELECTED))) {
          BasicPiece.getHighlighter().draw(getExpandedPiece(), g,
            size.width / 2, size.height / 2, panel, 1.0);
        }
      }
    }
  
    public Dimension getPreferredSize() {
      if (c != null && panel.getGraphics() != null) {
  //      c.draw(panel.getGraphics(), 0, 0, panel, 1.0);
        return c.boundingBox().getSize();
      }
      else {
        return new Dimension(width, height);
      }
    }
  
    public void mousePressed(MouseEvent e) {
      KeyBuffer.getBuffer().clear();
      Map.clearActiveMap();
  