@Override
    public int compare(EntityListElement o1, EntityListElement o2) {
      CombatEntity entity1 = o1.getEntity();
      CombatEntity entity2 = o2.getEntity();

      boolean inCombat1 = isInCombat(entity1);
      boolean inCombat2 = isInCombat(entity2);

      if (inCombat1 && !inCombat2) {
        return -1;
      }

      if (!inCombat1 && inCombat2) {
        return 1;
      }

      String name1 = entity1.getShortName();
      String name2 = entity2.getShortName();

      int result = STR_CMP.compare(name1, name2);
      if (result != 0) {
        return result;
      }

      // Be as exact as possible, so entities with the same name will be
      // ordered in the same order always.
      return Integer.compare(System.identityHashCode(entity1), System.identityHashCode(entity2));
    }
  private void jEntityListKeyPressed(
      java.awt.event.KeyEvent evt) { // GEN-FIRST:event_jEntityListKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_DELETE && worldModel != null) {
      EntityListElement selected = jEntityList.getSelectedValue();
      if (selected != null) {
        if (isInCombat(selected.getEntity())) {
          if (!ExaltedDialogHelper.askYesNoQuestion(
              getParentWindow(),
              CONFIRM_REMOVE_FROM_COMBAT_CAPTION.toString(),
              CONFIRM_REMOVE_FROM_COMBAT_TEXT.format(selected.getEntity().getShortName()),
              false)) {
            return;
          }

          worldModel.getCombatModel().getPositionModel().removeEntity(selected.getEntity());
        }
        worldModel.hideEntity(selected.getEntity());
      }
    }
  } // GEN-LAST:event_jEntityListKeyPressed
  private void selectInEntityList(CombatEntity entity) {
    if (entity == null) {
      jEntityList.clearSelection();
      return;
    }

    EntityListElement selected = jEntityList.getSelectedValue();
    if (selected != null && Objects.equals(entity, selected.getEntity())) {
      return;
    }

    ListModel<EntityListElement> model = jEntityList.getModel();
    int entityCount = model.getSize();
    for (int i = 0; i < entityCount; i++) {
      CombatEntity current = model.getElementAt(i).getEntity();
      if (Objects.equals(current, entity)) {
        jEntityList.setSelectedIndex(i);
        jEntityList.ensureIndexIsVisible(i);
        break;
      }
    }
  }