⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optioninfo.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
/**
 * The contents of this file are subject to the OAA  Community Research
 * License Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License
 * at http://www.ai.sri.com/~oaa/.  Software distributed under the License
 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * rights and limitations under the License.  Portions of the software are
 * Copyright (c) SRI International, 1999-2003.  All rights reserved.
 * "OAA" is a registered trademark, and "Open Agent Architecture" is a
 * trademark, of SRI International, a California nonprofit public benefit
 * corporation.
*/

package com.sri.oaa2.agt.startit;

import java.io.*;
import java.util.*;

public class OptionInfo {

  public final static int INVALID = 0;
  public final static int TOGGLE = 1;
  public final static int MENU = 2;
  public final static int TEXT = 3;
  public final static int TEXT_MENU = 4;
  public final static int TOGGLE_TEXT = 5;
  public final static int TOGGLE_TEXT_MENU = 6;

  protected final int type;
  protected String tag;
  protected String label = "";
  protected String falseLabel = "No";
  protected String falseValue = "";
  protected String trueLabel = "Yes";
  protected String trueValue = "";
  protected String prefix = "";
  protected String value = "";
  protected boolean set = false;
  protected boolean hidden = false;
  protected boolean devOption = false;
  protected int size = 0; // 0 means unlimited size
  protected Vector options = new Vector();
  protected MenuOption defaultOption;
  protected MenuOption currentOption;

  private final static String FALSE_LABEL = "false-label";
  private final static String FALSE_VALUE = "false-value";
  private final static String TRUE_LABEL = "true-label";
  private final static String TRUE_VALUE = "true-value";
  private final static String PREFIX = "prefix";
  private final static String OPTION = "option";
  private final static String DEFAULT = "default";
  private final static String VALUE = "value";
  private final static String SET = "set";
  private final static String SIZE = "size";
  private final static String LINE = "line";
  private final static String HIDE = "hide";
  private final static String DEV = "dev";
  private final static String END = "end";

  // If we have to issue a warning about how lines in menus aren't
  // supported, let's do it only once
  private static boolean warnedAboutLines = false;

  public OptionInfo(int t, String g) {
    type = t;
    tag = g;
  }

  public OptionInfo(ConfigReader reader) {
    String token;

    String t = reader.getFirstToken();
    tag = reader.getNextToken();
    label = reader.getRest();

    if (t.equals("toggle")) type = TOGGLE;
    else if (t.equals("menu")) type = MENU;
    else if (t.equals("text")) type = TEXT;
    else if (t.equals("text-menu")) type = TEXT_MENU;
    else if (t.equals("toggle-text")) type = TOGGLE_TEXT;
    else if (t.equals("toggle-text-menu")) type = TOGGLE_TEXT_MENU;
    else {
      type = INVALID;
      return;
    }

    while (reader.readLine()) {
      token = reader.getFirstToken();
      if (token.equals(FALSE_LABEL)) {
	falseLabel = reader.getRest();
      }
      else if (token.equals(FALSE_VALUE)) {
	falseValue = reader.getRest();
      }
      else if (token.equals(TRUE_LABEL)) {
	trueLabel = reader.getRest();
      }
      else if (token.equals(TRUE_VALUE)) {
	trueValue = reader.getRest();
      }
      else if (token.equals(PREFIX)) {
	prefix = reader.getRest();
      }
      else if (token.equals(VALUE)) {
	value = reader.getRest();
      }
      else if (token.equals(SET)) {
	set = true;
      }
      else if (token.equals(OPTION)) {
	if (type == MENU) {
	  MenuOption mop = new MenuOption(reader.getNextToken(),
					  reader.getRest());
	  if (options.size() == 0) currentOption = mop;
	  options.add(mop);
	}
	else {
	  options.add(reader.getRest());
	}
      }
      else if (token.equals(DEFAULT)) {
	if (type == MENU) {
	  defaultOption = new MenuOption(reader.getNextToken(),
					 reader.getRest());
	  currentOption = defaultOption;
	  options.add(currentOption);
	}
	else {
	  options.add(reader.getRest());
	}
      }
      else if (token.equals(SIZE)) {
	size = new Integer(reader.getRest()).intValue();
      }
      else if (token.equals(HIDE)) {
	hidden = true;
      }
      else if (token.equals(DEV)) {
	devOption = true;
      }
      else if (token.equals(LINE)) {
	if (!warnedAboutLines) {
	  reader.printWarning("lines in menus not implemented");
	  warnedAboutLines = true;
	}
      }
      else if (token.equals(END)) {
	return;
      }
      else {
	reader.printWarning("unknown option keyword: " + token);
      }
    }
  }

  public String getValue() {
    switch(type) {
    case TOGGLE:
      return set ? trueValue : falseValue;
    case MENU:
      return currentOption.value;
    case TEXT:
    case TEXT_MENU:
      return prefix + value;
    case TOGGLE_TEXT:
    case TOGGLE_TEXT_MENU:
      return set ? (prefix + value) : falseValue;
    }
    return "";
  }

  public class MenuOption {
    String label, value;
    public MenuOption(String v, String l) {
      label = l;
      value = v;
    }
    public String toString() { return label; }
    public String getValue() { return value; }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -