Example #1
0
 /**
  * Display the dialog. <br>
  * Editable by default. Null metadata arguments are not permissable
  */
 public static void displayDialog(ClientFrame parent) {
   MetadataDialog md = new MetadataDialog(parent);
   md.pack();
   md.setSize(Utils.getScreenSize(0.65f, 0.85f));
   Utils.centerInScreen(md);
   md.tabPane.setSelectedIndex(0); // always reset to first tab
   md.setVisible(true);
 } // displayDialog()
Example #2
0
  private PreferenceDialog(ClientFrame parent) {
    super(parent, Utils.getLocalString(TITLE), true);
    this.parent = parent;

    tabPane = new JTabbedPane(JTabbedPane.TOP);

    setHeaderText(Utils.getText(Utils.getLocalString(HEADER_LOCATION)));
    setContentPane(tabPane);
    createDefaultContentBorder(tabPane);
    addTwoButtons(makeCancelButton(), makeOKButton(), false, true);
    setHelpID(dip.misc.Help.HelpID.Preferences);
  } // AboutDialog()
Example #3
0
  /** Do the work (import text) */
  public void run() {
    isInProgress = true;

    try {
      final String text = getGameInfo();

      if (!isInProgress) {
        return;
      }

      // see if game is registered
      if (text.length() == 0 || text.indexOf(NOT_REGISTERED) >= 0) {
        fic.flocImportUnregistered();
        return;
      }

      // game is registered
      if (fic.flocTextImportComplete(text)) {
        // now, process into a World object
        fic.flocImportMessage(Utils.getLocalString(CREATING_WORLD));

        JudgeImport ji = new JudgeImport(orderFactory, new StringReader(text), null);

        if (!isInProgress) {
          return;
        }

        fic.flocWorldImportComplete(ji.getWorld());
      }
    } catch (IOException e) {
      fic.flocImportException(e);
    } catch (Exception e) {
      // do nothing (catches any thread-abort errors)
    }
  } // run()
Example #4
0
 /** Show the Preferences dialog. */
 public static void displayDialog(ClientFrame parent) {
   PreferenceDialog pd = new PreferenceDialog(parent);
   pd.createPanels();
   pd.pack();
   pd.setSize(new Dimension(450, 550));
   Utils.centerInScreen(pd);
   pd.setVisible(true);
 } // displayDialog()
Example #5
0
  /** Creates the dialog */
  private MetadataDialog(ClientFrame parent) {
    super(parent, Utils.getLocalString(TITLE), true);
    this.clientFrame = parent;

    mmd = clientFrame.getMapMetadata();
    if (mmd == null) {
      propertyListener = new IconColorListener();
      clientFrame.addPropertyChangeListener(propertyListener);
    }

    makeTabPanel();
    setTabIcons();

    setHeaderText(Utils.getText(Utils.getLocalString(HEADER_LOCATION)));
    createDefaultContentBorder(tabPane);
    setContentPane(tabPane);
    addTwoButtons(makeCancelButton(), makeOKButton(), false, true);
    setHelpID(dip.misc.Help.HelpID.Dialog_Metadata);
  } // MetadataDialog()
Example #6
0
  /**
   * Determines if the given border allows a given action.
   *
   * <p>Please note that this uses the superclass for any passed GUIOrder object. (e.g.,
   * dip.order.Hold for dip.gui.order.GUIHold)
   *
   * <p>GUIOrder.BORDER_INVALID is appended to the StringBuffer, if 'false' is returned.
   */
  public static boolean checkBorder(
      GUIOrder guiOrder, Location location, Unit.Type unitType, Phase phase, StringBuffer sb) {
    Class baseClass = guiOrder.getClass().getSuperclass();
    Border border = location.getProvince().getTransit(location, unitType, phase, baseClass);
    if (border != null) {
      sb.append(
          Utils.getLocalString(
              GUIOrder.BORDER_INVALID, guiOrder.getFullName(), border.getDescription()));
      return false;
    }

    return true;
  } // checkBorder()
Example #7
0
  /**
   * Parse a Location from the given text.
   *
   * <p>This will never return null.
   */
  private Location parseLocation(final ParseContext pc, final String text) throws OrderException {
    final String replaceFrom[] = {".", ","};
    final String replaceTo[] = {"", ""};
    final String locationText = Coast.normalize(Utils.replaceAll(text, replaceFrom, replaceTo));

    final Location loc = pc.map.parseLocation(locationText);

    if (loc == null) {
      throw new OrderException(
          "Invalid location \"" + locationText + "\" in order: " + pc.orderText);
    }

    return loc;
  } // parseLocation()
Example #8
0
    public PlayerPanel(Power power) {
      this.power = power;

      notes.setBorder(new EtchedBorder());

      for (int i = 0; i < email.length; i++) {
        email[i] = Utils.createEmailTextField(COLUMNS);
      }

      // layout
      int w1[] = {BORDER, 0, 5, 0, 15, 0, 5, 0, BORDER};
      int h1[] = {BORDER, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 10, 0, 5, 0, BORDER};

      HIGLayout layout = new HIGLayout(w1, h1);
      layout.setColumnWeight(5, 1);
      layout.setRowWeight(12, 1);
      this.setLayout(layout);

      HIGConstraints c = new HIGConstraints();

      this.add(new JLabel(Utils.getLocalString(PDF_NAME)), c.rcwh(2, 2, 1, 1, "r"));
      this.add(name, c.rcwh(2, 4, 1, 1, "l"));

      this.add(new JLabel(Utils.getLocalString(PDF_URI)), c.rcwh(4, 2, 1, 1, "r"));
      this.add(uri, c.rcwh(4, 4, 1, 1, "l"));

      this.add(new JLabel(Utils.getLocalString(PDF_NOTES)), c.rcwh(10, 2, 1, 1, "l"));
      this.add(makeScrollPane(notes), c.rcwh(12, 2, 7, 1, "lrtb"));

      for (int i = 0; i < email.length; i++) {
        int row = 2 + (i * 2);
        this.add(
            new JLabel(Utils.getLocalString(PDF_EMAIL) + " " + String.valueOf(i + 1)),
            c.rcwh(row, 6, 1, 1, "r"));
        this.add(email[i], c.rcwh(row, 8, 1, 1, "l"));
      }
    } // PlayerPanel()
Example #9
0
  /**
   * Get the game information.
   *
   * <p>Returns the imported text.
   */
  private String getGameInfo() throws IOException {
    final StringBuffer gameInformation = new StringBuffer(16384);

    URL u = null;
    BufferedReader reader = null;
    try {
      u =
          new URL(
              "http://www.floc.net/observer.py?judge="
                  + judgeName
                  + "&game="
                  + gameName
                  + "&page=history&history_from=0&history_to=999999");

      fic.flocImportMessage(Utils.getLocalString(READING_CONTACT));

      // output is in HTML, so using the HTML editor kit parser removes
      // HTML cruft.
      //
      reader = new BufferedReader(new InputStreamReader(u.openStream()));

      if (!isInProgress) {
        return "";
      }

      ParserDelegator parser = new ParserDelegator();
      parser.parse(
          reader,
          new HTMLEditorKit.ParserCallback() {
            public void handleText(char[] text, int pos) {
              if (!isInProgress) {
                gameInformation.setLength(0); // abort!
                return;
              }

              fic.flocImportMessage(Utils.getLocalString(READING_FROM_NET));
              gameInformation.append(text);
              gameInformation.append("\n");
            } // handleText()
          },
          false);
    } finally {
      if (reader != null) {
        reader.close();
      }
    }

    return gameInformation.toString();
  } // getGameInfo()
Example #10
0
  /** Make the tab panel */
  private void makeTabPanel() {
    // create tabbed pane
    tabPane = new JTabbedPane();

    // first tab is Game info
    World world = clientFrame.getWorld();
    tabPane.add(Utils.getLocalString(TAB_GAME_PANEL), makeGamePanel(world.getGameMetadata()));

    // all other tabs are by Power name
    Power[] powers = world.getMap().getPowers();
    for (int i = 0; i < powers.length; i++) {
      tabPane.add(
          powers[i].getName(), makePlayerPanel(powers[i], world.getPlayerMetadata(powers[i])));
    }
  } // makeTabPanel()
Example #11
0
  /** Makes the phase; throws an exception if we cannot. */
  private Phase makePhase(String phaseType, String seasonType, String year) throws IOException {
    phaseType = (phaseType == null) ? "Movement" : phaseType;

    StringBuffer sb = new StringBuffer();
    sb.append(phaseType);
    sb.append(' ');
    sb.append(seasonType);
    sb.append(' ');
    sb.append(year);

    try {
      return Phase.parse(sb.toString());
    } catch (Exception e) {
      throw new IOException(Utils.getLocalString(PP_UNKNOWN_PHASE, sb.toString()));
    }
  } // makePhase()
Example #12
0
    public GamePanel() {
      notes.setBorder(new EtchedBorder());

      // layout
      int w1[] = {BORDER, 10, 0, 5, 0, 10, 5, 0, BORDER};
      int h1[] = {BORDER, 0, 20, 0, 5, 0, 10, 0, 10, 0, 10, 0, 30, 0, 10, 0, 10, 0, BORDER};

      HIGLayout layout = new HIGLayout(w1, h1);
      layout.setColumnWeight(8, 1);
      this.setLayout(layout);

      HIGConstraints c = new HIGConstraints();

      this.add(new JLabel(Utils.getLocalString(GDF_GAME_NAME)), c.rcwh(2, 3, 1, 1, "r"));
      this.add(gameName, c.rcwh(2, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_NOTES)), c.rcwh(4, 8, 1, 1, "l"));
      this.add(makeScrollPane(notes), c.rcwh(6, 8, 1, 14, "lrtb"));

      this.add(new JLabel(Utils.getLocalString(GDF_COMMENT)), c.rcwh(6, 3, 1, 1, "r"));
      this.add(comment, c.rcwh(6, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_GAME_URI)), c.rcwh(8, 3, 1, 1, "r"));
      this.add(gameURI, c.rcwh(8, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_GAME_ID)), c.rcwh(10, 3, 1, 1, "r"));
      this.add(gameID, c.rcwh(10, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_JUDGE_NAME)), c.rcwh(12, 3, 1, 1, "r"));
      this.add(judgeName, c.rcwh(12, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_MOD_NAME)), c.rcwh(14, 3, 1, 1, "r"));
      this.add(modName, c.rcwh(14, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_MOD_EMAIL)), c.rcwh(16, 3, 1, 1, "r"));
      this.add(modEmail, c.rcwh(16, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_MOD_URI)), c.rcwh(18, 3, 1, 1, "r"));
      this.add(modURI, c.rcwh(18, 5, 1, 1, "lr"));
    } // GamePanel()
Example #13
0
  @Override
  public boolean setLocation(StateInfo stateInfo, Location location, StringBuffer sb) {
    if (testLocation(stateInfo, location, sb)) {
      currentLocNum++;

      src = new Location(location.getProvince(), location.getCoast());
      power = stateInfo.getPosition().getSupplyCenterOwner(location.getProvince());

      // srcUnitType: already defined
      assert (srcUnitType != null);

      sb.setLength(0);
      sb.append(Utils.getLocalString(GUIOrder.COMPLETE, getFullName()));
      return true;
    }

    return false;
  } // setLocation()
Example #14
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 #15
0
  private class PlayerPanel extends JPanel {
    /** */
    private static final long serialVersionUID = 1L;

    private JTextPane notes = new JTextPane();
    private JTextField name = new JTextField(COLUMNS);
    private JTextField uri = Utils.createURITextField(COLUMNS);
    private JTextField[] email = new JTextField[4];
    private Power power = null;

    public PlayerPanel(Power power) {
      this.power = power;

      notes.setBorder(new EtchedBorder());

      for (int i = 0; i < email.length; i++) {
        email[i] = Utils.createEmailTextField(COLUMNS);
      }

      // layout
      int w1[] = {BORDER, 0, 5, 0, 15, 0, 5, 0, BORDER};
      int h1[] = {BORDER, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 10, 0, 5, 0, BORDER};

      HIGLayout layout = new HIGLayout(w1, h1);
      layout.setColumnWeight(5, 1);
      layout.setRowWeight(12, 1);
      this.setLayout(layout);

      HIGConstraints c = new HIGConstraints();

      this.add(new JLabel(Utils.getLocalString(PDF_NAME)), c.rcwh(2, 2, 1, 1, "r"));
      this.add(name, c.rcwh(2, 4, 1, 1, "l"));

      this.add(new JLabel(Utils.getLocalString(PDF_URI)), c.rcwh(4, 2, 1, 1, "r"));
      this.add(uri, c.rcwh(4, 4, 1, 1, "l"));

      this.add(new JLabel(Utils.getLocalString(PDF_NOTES)), c.rcwh(10, 2, 1, 1, "l"));
      this.add(makeScrollPane(notes), c.rcwh(12, 2, 7, 1, "lrtb"));

      for (int i = 0; i < email.length; i++) {
        int row = 2 + (i * 2);
        this.add(
            new JLabel(Utils.getLocalString(PDF_EMAIL) + " " + String.valueOf(i + 1)),
            c.rcwh(row, 6, 1, 1, "r"));
        this.add(email[i], c.rcwh(row, 8, 1, 1, "l"));
      }
    } // PlayerPanel()

    /** Returns the Power associated with this PlayerPanel */
    public Power getPower() {
      return power;
    } // getPower()

    /** Get the panel values from the given PlayerMetadata object. */
    public void read(PlayerMetadata pmd) {
      notes.setText(pmd.getNotes());
      name.setText(pmd.getName());
      uri.setText(n2e(pmd.getURI()));

      String[] tmpEmail = pmd.getEmailAddresses();
      for (int i = 0; i < email.length; i++) {
        if (i < tmpEmail.length) {
          email[i].setText(n2e(tmpEmail[i]));
        } else {
          email[i].setText("");
        }
      }
    } // read()

    /** Write the panel values to the given PlayerMetadata object. */
    public void write(PlayerMetadata pmd) {
      pmd.setName(name.getText());
      pmd.setURI(convertURI(uri.getText()));
      pmd.setNotes(notes.getText());

      String[] tmpEmail = new String[email.length];
      for (int i = 0; i < email.length; i++) {
        tmpEmail[i] = email[i].getText().trim();
      }

      pmd.setEmailAddresses(tmpEmail);
    } // write()
  } // inner class PlayerPanel
Example #16
0
  private class GamePanel extends JPanel {
    /** */
    private static final long serialVersionUID = 1L;

    private JTextPane notes = new JTextPane();
    private JTextField comment = new JTextField(COLUMNS_LONG);
    private JTextField gameName = new JTextField(COLUMNS_LONG);
    private JTextField modName = new JTextField(COLUMNS_LONG);
    private JTextField modEmail = Utils.createEmailTextField(COLUMNS_LONG);
    private JTextField modURI = Utils.createURITextField(COLUMNS_LONG);
    private JTextField judgeName = new JTextField(COLUMNS);
    private JTextField gameURI = Utils.createURITextField(COLUMNS_LONG);
    private JTextField gameID = new JTextField(COLUMNS);

    public GamePanel() {
      notes.setBorder(new EtchedBorder());

      // layout
      int w1[] = {BORDER, 10, 0, 5, 0, 10, 5, 0, BORDER};
      int h1[] = {BORDER, 0, 20, 0, 5, 0, 10, 0, 10, 0, 10, 0, 30, 0, 10, 0, 10, 0, BORDER};

      HIGLayout layout = new HIGLayout(w1, h1);
      layout.setColumnWeight(8, 1);
      this.setLayout(layout);

      HIGConstraints c = new HIGConstraints();

      this.add(new JLabel(Utils.getLocalString(GDF_GAME_NAME)), c.rcwh(2, 3, 1, 1, "r"));
      this.add(gameName, c.rcwh(2, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_NOTES)), c.rcwh(4, 8, 1, 1, "l"));
      this.add(makeScrollPane(notes), c.rcwh(6, 8, 1, 14, "lrtb"));

      this.add(new JLabel(Utils.getLocalString(GDF_COMMENT)), c.rcwh(6, 3, 1, 1, "r"));
      this.add(comment, c.rcwh(6, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_GAME_URI)), c.rcwh(8, 3, 1, 1, "r"));
      this.add(gameURI, c.rcwh(8, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_GAME_ID)), c.rcwh(10, 3, 1, 1, "r"));
      this.add(gameID, c.rcwh(10, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_JUDGE_NAME)), c.rcwh(12, 3, 1, 1, "r"));
      this.add(judgeName, c.rcwh(12, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_MOD_NAME)), c.rcwh(14, 3, 1, 1, "r"));
      this.add(modName, c.rcwh(14, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_MOD_EMAIL)), c.rcwh(16, 3, 1, 1, "r"));
      this.add(modEmail, c.rcwh(16, 5, 1, 1, "lr"));

      this.add(new JLabel(Utils.getLocalString(GDF_MOD_URI)), c.rcwh(18, 3, 1, 1, "r"));
      this.add(modURI, c.rcwh(18, 5, 1, 1, "lr"));
    } // GamePanel()

    /** Get the panel values from the given GameMetadata object. */
    public void read(GameMetadata gmd) {
      notes.setText(gmd.getNotes());
      comment.setText(gmd.getComment());
      gameName.setText(gmd.getGameName());
      modName.setText(n2e(gmd.getModeratorName()));
      modEmail.setText(n2e(gmd.getModeratorEmail()));
      modURI.setText(n2e(gmd.getModeratorURI()));
      judgeName.setText(n2e(gmd.getJudgeName()));
      gameURI.setText(n2e(gmd.getGameURI()));
      gameID.setText(gmd.getGameID());
    } // read()

    /** Set GameMetadata object from the entered panel values. */
    public void write(GameMetadata gmd) {
      gmd.setNotes(notes.getText());
      gmd.setComment(comment.getText());
      gmd.setGameName(gameName.getText());
      gmd.setGameID(gameID.getText());
      gmd.setGameURI(convertURI(gameURI.getText()));

      gmd.setJudgeName((judgeName.getText().length() == 0) ? null : judgeName.getText());

      gmd.setModeratorName((modName.getText().length() == 0) ? null : modName.getText());
      gmd.setModeratorEmail((modEmail.getText().length() == 0) ? null : modEmail.getText());
      gmd.setModeratorURI(convertURI(modURI.getText()));
    } // write()
  } // inner class GamePanel
Example #17
0
  @Override
  public boolean testLocation(StateInfo stateInfo, Location location, StringBuffer sb) {
    sb.setLength(0);

    if (isComplete()) {
      sb.append(Utils.getLocalString(GUIOrder.COMPLETE, getFullName()));
      return false;
    }

    Position position = stateInfo.getPosition();
    Province province = location.getProvince();

    if (province.hasSupplyCenter()) {
      Power SCOwner = position.getSupplyCenterOwner(province);

      // general screening, applicable to all build options
      //
      if (SCOwner == null) {
        sb.append(Utils.getLocalString(NOBUILD_UNOWNED_SC));
        return false;
      }

      if (position.hasUnit(province)) {
        sb.append(Utils.getLocalString(NOBUILD_UNIT_PRESENT));
        return false;
      }

      if (!stateInfo.canIssueOrder(SCOwner)) {
        sb.append(Utils.getLocalString(NOBUILD_SC_NOT_CONTROLLED));
        return false;
      }

      // indicate if we have no builds available
      //
      Adjustment.AdjustmentInfo adjInfo = stateInfo.getAdjustmenInfoMap().get(SCOwner);
      if (adjInfo.getAdjustmentAmount() <= 0) {
        sb.append(Utils.getLocalString(NOBUILD_NO_BUILDS_AVAILABLE, SCOwner.getName()));
        return false;
      }

      // build-option-specific, based upon RuleOptions
      //
      RuleOptions ruleOpts = stateInfo.getRuleOptions();
      if (ruleOpts.getOptionValue(RuleOptions.OPTION_BUILDS)
          == RuleOptions.VALUE_BUILDS_ANY_OWNED) {
        return checkBuildUnit(stateInfo, province, location, sb);
      } else if (ruleOpts.getOptionValue(RuleOptions.OPTION_BUILDS)
          == RuleOptions.VALUE_BUILDS_ANY_IF_HOME_OWNED) {
        // check if we have ONE owned home supply center before buidling
        // in a non-home supply center.
        //
        if (SCOwner != position.getSupplyCenterHomePower(province)
            && !position.hasAnOwnedHomeSC(SCOwner)) {
          sb.append(Utils.getLocalString(NOBUILD_NEED_ONE_OWNED_SC));
          return false; // failed
        }

        // we (probably) can build here
        return checkBuildUnit(stateInfo, province, location, sb);
      } else {
        // build only in owned HOME supply centers
        //
        if (SCOwner == position.getSupplyCenterHomePower(province)) {
          // we (probably) can build here
          return checkBuildUnit(stateInfo, province, location, sb);
        }

        // build failure.
        sb.append(Utils.getLocalString(NOBUILD_NOT_OWNED_HOME_SC));
        return false;
      }
    } else {
      sb.append(Utils.getLocalString(NOBUILD_MUST_BE_AN_OWNED_SC));
      return false;
    }

    // NO return here: thus we must appropriately exit within an if/else block above.
  } // testLocation()