Example #1
0
  /** Places a unit in the desired area. */
  @Override
  public void updateDOM(MapInfo mapInfo) {
    // if we are not displayable, we exit, after remove the order (if
    // it was created)
    if (!GUIOrderUtils.isDisplayable(power, mapInfo)) {
      removeFromDOM(mapInfo);
      return;
    }

    // determine if any change has occured. If no change has occured,
    // we will not change the DOM.
    //
    // we have nothing (yet) to check for change; isDependent() == false.
    // so just return if we have not been drawn.
    if (group != null) {
      return;
    }

    // there has been a change, if we are at this point.
    //

    // if we've not yet been created, we will create; if we've
    // already been created, we must remove the existing elements
    // in our group
    if (group == null) {
      // create group
      group =
          (SVGGElement)
              mapInfo
                  .getDocument()
                  .createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_G_TAG);

      mapInfo.getPowerSVGGElement(power, LAYER_HIGHEST).appendChild(group);
    } else {
      // remove group children
      GUIOrderUtils.deleteChildren(group);
    }

    // now, render the order
    // (no highlight + shadow required here)
    // no offset required
    //
    SVGElement[] elements = drawOrder(mapInfo);
    for (int i = 0; i < elements.length; i++) {
      group.appendChild(elements[i]);
    }

    // draw 'failed' marker, if appropriate.
    if (!mapInfo.getTurnState().isOrderSuccessful(this)) {
      SVGElement useElement = GUIOrderUtils.createFailedOrderSymbol(mapInfo, failPt.x, failPt.y);
      group.appendChild(useElement);
    }
  } // updateDOM()
Example #2
0
  /**
   * All build options require that appropriate units are built in appropriate places (e.g., armies
   * can't go in the water, fleets can't go in landlocked provinces, fleets must have coasts
   * specified if required, etc.). This method takes care of that.
   *
   * <p>returns false if we cannot build here.
   */
  private boolean checkBuildUnit(
      StateInfo stateInfo, Province province, Location loc, StringBuffer sb) {
    if (srcUnitType == null) {
      sb.append(Utils.getLocalString(NOBUILD_NO_UNIT_SELECTED));
      return false;
    }

    if (srcUnitType.equals(Unit.Type.ARMY)) {
      if (province.isSea()) {
        sb.append(Utils.getLocalString(NOBUILD_NO_ARMY_IN_SEA));
        return false;
      } else {
        // check borders
        if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
          return false;
        }

        sb.append(Utils.getLocalString(BUILD_ARMY_OK));
        return true;
      }
    } else if (srcUnitType.equals(Unit.Type.FLEET)) {
      if (province.isLandLocked()) {
        sb.append(Utils.getLocalString(NOBUILD_FLEET_LANDLOCKED));
        return false;
      } else {
        // check borders
        if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
          return false;
        }

        sb.append(Utils.getLocalString(BUILD_FLEET_OK));
        return true;
      }
    } else if (srcUnitType.equals(Unit.Type.WING)) {
      // check borders
      if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
        return false;
      }

      sb.append(Utils.getLocalString(BUILD_WING_OK));
      return true;
    }

    // this should not occur.
    sb.append("** Unknown unit type! **");
    return false;
  } // checkBuildUnit()
Example #3
0
 @Override
 public void removeFromDOM(MapInfo mapInfo) {
   if (group != null) {
     SVGGElement powerGroup = mapInfo.getPowerSVGGElement(power, LAYER_HIGHEST);
     GUIOrderUtils.removeChild(powerGroup, group);
     group = null;
   }
 } // removeFromDOM()