gt:   protected KeyCommand[] getKeyCommands() {
context: /*
   * $Id: BasicPiece.java 4664 2008-12-17 21:43:29Z uckelman $
   *
   * 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.counters;
  
  import java.awt.Component;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.Image;
  import java.awt.Point;
  import java.awt.Rectangle;
  import java.awt.Shape;
  import java.awt.event.InputEvent;
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import javax.swing.Box;
  import javax.swing.BoxLayout;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JPopupMenu;
  import javax.swing.JTextField;
  import javax.swing.KeyStroke;
  
  import VASSAL.build.GameModule;
  import VASSAL.build.module.Chatter;
  import VASSAL.build.module.GlobalOptions;
  import VASSAL.build.module.Map;
  import VASSAL.build.module.documentation.HelpFile;
  import VASSAL.build.module.map.boardPicker.Board;
  import VASSAL.build.module.map.boardPicker.board.mapgrid.Zone;
  import VASSAL.command.AddPiece;
  import VASSAL.command.ChangePiece;
  import VASSAL.command.Command;
  import VASSAL.command.RemovePiece;
  import VASSAL.i18n.Localization;
  import VASSAL.i18n.PieceI18nData;
  import VASSAL.i18n.Resources;
  import VASSAL.i18n.TranslatablePiece;
  import VASSAL.tools.SequenceEncoder;
  import VASSAL.tools.image.ImageUtils;
  import VASSAL.tools.imageop.ScaledImagePainter;
  
  /**
   * Basic class for representing a physical component of the game Can be a counter, a card, or an overlay
   */
  public class BasicPiece implements TranslatablePiece, StateMergeable {
    public static final String ID = "piece;";
    private static Highlighter highlighter;
    /**
     * Return information about the current location of the piece through getProperty():
     * 
     * LocationName - Current Location Name of piece as displayed in Chat Window CurrentX - Current X position CurrentY -
     * Current Y position CurrentMap - Current Map name or "" if not on a map CurrentBoard - Current Board name or "" if
     * not on a map CurrentZone - If the current map has a multi-zoned grid, then return the name of the Zone the piece is
     * in, or "" if the piece is not in any zone, or not on a map
     */
    public static final String LOCATION_NAME = "LocationName";
    public static final String CURRENT_MAP = "CurrentMap";
    public static final String CURRENT_BOARD = "CurrentBoard";
    public static final String CURRENT_ZONE = "CurrentZone";
    public static final String CURRENT_X = "CurrentX";
    public static final String CURRENT_Y = "CurrentY";
    public static final String OLD_LOCATION_NAME = "OldLocationName";
    public static final String OLD_MAP = "OldMap";
    public static final String OLD_BOARD = "OldBoard";
    public static final String OLD_ZONE = "OldZone";
    public static final String OLD_X = "OldX";
    public static final String OLD_Y = "OldY";
    public static final String BASIC_NAME = "BasicName";
    public static final String PIECE_NAME = "PieceName";
    public static final String DECK_NAME = "DeckName";
    public static Font POPUP_MENU_FONT = new Font("Dialog", 0, 11);
    protected JPopupMenu popup;
    protected Rectangle imageBounds;
    protected ScaledImagePainter imagePainter = new ScaledImagePainter();
    private Map map;
    private KeyCommand[] commands;
    private Stack parent;
    private Point pos = new Point(0, 0);
    private String id;
    private java.util.Map<Object, Object> props;
    /** @deprecated Moved into own traits, retained for backward compatibility */
    @Deprecated
    private char cloneKey;
    /** @deprecated Moved into own traits, retained for backward compatibility */
    @Deprecated
    private char deleteKey;
    /**
     * @deprecated Replaced by
     * @{link #srcOp}.
     */
    @Deprecated
    protected Image image;
    protected String imageName;
    private String commonName;
  
    public BasicPiece() {
      this(ID + ";;;;");
    }
  
    public BasicPiece(String type) {
      mySetType(type);
    }
  
    public void mySetType(String type) {
      final SequenceEncoder.Decoder st = new SequenceEncoder.Decoder(type, ';');
      st.nextToken();
      cloneKey = st.nextChar('\0');
      deleteKey = st.nextChar('\0');
      imageName = st.nextToken();
      commonName = st.nextToken();
      imagePainter.setImageName(imageName);
      commands = null;
    }
  
    public String getType() {
      final SequenceEncoder se =
        new SequenceEncoder(cloneKey > 0 ? String.valueOf(cloneKey) : "", ';');
      return ID + se.append(deleteKey > 0 ? String.valueOf(deleteKey) : "")
                    .append(imageName)
                    .append(commonName).getValue();
    }
  
    public void setMap(Map map) {
      if (map != this.map) {
        commands = null;
        this.map = map;
      }
    }
  
    public Map getMap() {
      return getParent() == null ? map : getParent().getMap();
    }
  
    public Object getProperty(Object key) {
      if (BASIC_NAME.equals(key)) {
        return getName();
      }
      else
          return getPublicProperty(key);
    }
    
    /*
     * Properties visible in a masked unit
     */
    public Object getPublicProperty(Object key) {
      if (Properties.KEY_COMMANDS.equals(key)) {
        return getKeyCommands();
      }
      else if (LOCATION_NAME.equals(key)) {
        return getMap() == null ? "" : getMap().locationName(getPosition());
      }
      else if (PIECE_NAME.equals(key)) {
        return Decorator.getOutermost(this).getName();
      }
      else if (CURRENT_MAP.equals(key)) {
        return getMap() == null ? "" : getMap().getConfigureName();
      }
      else if (DECK_NAME.equals(key)) {
        return getParent() instanceof Deck ? ((Deck) getParent()).getDeckName() : "";
      }
      else if (CURRENT_BOARD.equals(key)) {
        if (getMap() != null) {
          final Board b = getMap().findBoard(getPosition());
          if (b != null) {
            return b.getName();
          }
        }
        return "";
      }
      else if (CURRENT_ZONE.equals(key)) {
        if (getMap() != null) {
          final Zone z = getMap().findZone(getPosition());
          if (z != null) {
            return z.getName();
          }
        }
        return "";
      }
      else if (CURRENT_X.equals(key)) {
        return String.valueOf(getPosition().x);
      }
      else if (CURRENT_Y.equals(key)) {
        return String.valueOf(getPosition().y);
      }
      else if (Properties.VISIBLE_STATE.equals(key)) {
        return "";
      }
      Object prop = props == null ? null : props.get(key);
      if (prop == null) {
        final Map map = getMap();
        final Zone zone = (map == null ? null : map.findZone(getPosition()));
        if (zone != null) {
          prop = zone.getProperty(key);
        }
        else if (map != null) {
          prop = map.getProperty(key);
        }
        else {
          prop = GameModule.getGameModule().getProperty(key);
        }
      }
      return prop;
    }
  
    public Object getLocalizedProperty(Object key) {
      if (BASIC_NAME.equals(key)) {
        return getLocalizedName();
      }
      else {
        return getLocalizedPublicProperty(key);
      }
    }
    
    /*
     * Properties visible in a masked unit
     */
    public Object getLocalizedPublicProperty(Object key) {
      if (Properties.KEY_COMMANDS.equals(key)) {
        return getProperty(key);
      }
      else if (LOCATION_NAME.equals(key)) {
        return getMap() == null ? "" : getMap().localizedLocationName(getPosition());
      }
      else if (PIECE_NAME.equals(key)) {
        return Decorator.getOutermost(this).getName();
      }
      else if (BASIC_NAME.equals(key)) {
        return getLocalizedName();
      }
      else if (CURRENT_MAP.equals(key)) {
        return getMap() == null ? "" : getMap().getLocalizedConfigureName();
      }
      else if (DECK_NAME.equals(key)) {
        return getParent() instanceof Deck ? ((Deck) getParent()).getLocalizedDeckName() : "";
      }
      else if (CURRENT_BOARD.equals(key)) {
        if (getMap() != null) {
          final Board b = getMap().findBoard(getPosition());
          if (b != null) {
            return b.getLocalizedName();
          }
        }
        return "";
      }
      else if (CURRENT_ZONE.equals(key)) {
        if (getMap() != null) {
          final Zone z = getMap().findZone(getPosition());
          if (z != null) {
            return z.getLocalizedName();
          }
        }
        return "";
      }
      else if (CURRENT_X.equals(key)) {
        return getProperty(key);
      }
      else if (CURRENT_Y.equals(key)) {
        return getProperty(key);
      }
      else if (Properties.VISIBLE_STATE.equals(key)) {
        return getProperty(key);
      }
      Object prop = props == null ? null : props.get(key);
      if (prop == null) {
        final Map map = getMap();
        final Zone zone = (map == null ? null : map.findZone(getPosition()));
        if (zone != null) {
          prop = zone.getLocalizedProperty(key);
        }
        else if (map != null) {
          prop = map.getLocalizedProperty(key);
        }
        else {
          prop = GameModule.getGameModule().getLocalizedProperty(key);
        }
      }
      return prop;
    }
  
    public void setProperty(Object key, Object val) {
      if (props == null) {
        props = new HashMap<Object, Object>();
      }
      if (val == null) {
        props.remove(key);
      }
      else {
        props.put(key, val);
      }
    }
  
    protected Object prefsValue(String s) {
      return GameModule.getGameModule().getPrefs().getValue(s);
    }
  
    public void draw(Graphics g, int x, int y, Component obs, double zoom) {
      if (imageBounds == null) {
        imageBounds = boundingBox();
      }
      imagePainter.draw(g, x + (int) (zoom * imageBounds.x), y + (int) (zoom * imageBounds.y), zoom, obs);
    }
  
  