@Override
 protected void initializeSubCommands() {
   Cmd bt = mCommandMap.get("bluetooth");
   bt.setHelp(R.string.chat_help_bt_state, null);
   bt.AddSubCmd("on", R.string.chat_help_bt_on, null);
   bt.AddSubCmd("off", R.string.chat_help_bt_off, null);
 }
Exemple #2
0
  public static void main(String[] args) throws FileNotFoundException {
    Scanner scanner;
    String s;
    Stack<Double> stack = new Stack<>();

    if (args.length > 0) {
      scanner = new Scanner(new FileInputStream(args[0]));
    } else {
      scanner = new Scanner(System.in);
    }

    Map<String, Double> varMap = new HashMap<>();
    CommandFactory singleton = CommandFactory.getInst();

    while (scanner.hasNextLine()) {
      s = scanner.nextLine();
      String[] str = s.split(" ");
      Cmd kom = singleton.getCommandByName(str[0]);
      if (kom != null) {
        try {
          kom.exec(stack, varMap, str);
        } catch (NumberFormatException e) {
          System.out.println("Введена неизвестная команда");
        }
      } else {
        System.out.println("Команда не найдена");
      }
    }
  }
Exemple #3
0
 public static Cmd match(int type) {
   for (Cmd each : Cmd.values()) {
     if (type == each.getType()) {
       return each;
     }
   }
   throw new UndefinedCmdException(type);
 }
 /**
  * Returns a nice formated String of the Commands this class handles
  *
  * @return
  */
 protected final String getCommandsAsString() {
   String res = "";
   for (Cmd c : mCommandMap.values()) {
     res += c.getName();
     if (c.getAlias().length > 0) {
       res += " (";
       for (String s : c.getAlias()) {
         res += s + ", ";
       }
       res = res.substring(0, res.length() - 2) + ")";
     }
     res += ", ";
   }
   return res;
 }
  public Cmd getCommand(String name) {
    Cmd cmd = mCommandMap.get(name);

    if (cmd != null) {
      return cmd;
    } else {
      for (Cmd c : mCommandMap.values()) {
        for (String a : c.getAlias()) {
          if (a.equals(name)) {
            return c;
          }
        }
      }
    }

    return null;
  }
  CommandHandlerBase(MainService mainService, int cmdType, Object... commands) {
    if (sMainService == null) {
      sMainService = mainService;
      sSettingsMgr = SettingsManager.getSettingsManager(sContext);
      sContext = mainService.getBaseContext();
      Cmd.setContext(sContext);
    }
    mCommandMap = new HashMap<String, Cmd>();
    for (Object o : commands) {
      Cmd c = (Cmd) o;
      mCommandMap.put(c.getName(), c);
    }
    mCmdType = cmdType;
    mAnswerTo = null;

    initializeSubCommands();
  }
  public Syntax internalDeepCopy(Token start, Token end) {
    Syntax copy =
        new DotMethodCallExp(
            start,
            end,
            (methodName == null ? null : (Id) methodName.internalDeepCopy(start, end)),
            (subpat == null ? null : (Cmd) subpat.internalDeepCopy(start, end)));

    return copy;
  }
  /**
   * Request a help String array from the command The String is formated with your internal
   * BOLD/ITALIC/etc Tags
   *
   * @return Help String array, null if there is no help available
   */
  public String[] help() {
    ArrayList<String> res = new ArrayList<String>();

    for (Cmd c : mCommandMap.values()) {
      if (c.getHelp() != null) {
        res.add(c.getHelp());
      }
      for (SubCmd sc : c.getSubCmds()) {
        if (sc.getHelp() != null) {
          res.add(sc.getHelp());
        }
      }
    }

    if (res.size() > 0) {
      return res.toArray(new String[res.size()]);
    } else {
      return null;
    }
  }
  public Syntax internalDeepCopy(Token start, Token end) {
    Syntax copy =
        new ClsPatDef(
            start,
            end,
            (id == null ? null : (Id) id.internalDeepCopy(start, end)),
            (List<Id>) (deepCopyList(formals, start, end)),
            (body == null ? null : (Cmd) body.internalDeepCopy(start, end)));

    return copy;
  }
Exemple #10
0
 @Override
 public void exec(List<String> parameter) {
   try {
     if (Cmd.isInteger(parameter.get(0))) {
       SetKeys.GUI_TOOLTIP_FONT_SIZE.setValue(
           Utility.pixelSizeToGLSize(0, Integer.parseInt(parameter.get(0)))[1]);
     } else {
       SetKeys.GUI_TOOLTIP_FONT_SIZE.setValue(Float.parseFloat(parameter.get(0)));
     }
   } catch (Exception e) {
     Logger.error(
         "Unable to change setting (gui_tooltip_font_size): illegel parameter 0 ("
             + parameter.get(0)
             + ")",
         "CommandExecuter.exec");
     return;
   }
 }
Exemple #11
0
 // ---------------------------------------------------------------------
 @Override
 void set(String p, String v) {
   TextView w = (TextView) widget;
   String[] opt = Cmd.qsplit(v);
   if (p.equals("caption") || p.equals("text")) w.setText(Util.remquotes(v));
   else if (p.equals("alignment")) {
     if (0 == opt.length) {
       JConsoleApp.theWd.error("set alignment requires 1 argument: " + id + " " + p);
       return;
     }
     if (opt[0].equals("left")) w.setGravity(Gravity.LEFT);
     else if (opt[0].equals("right")) w.setGravity(Gravity.RIGHT);
     else if (opt[0].equals("center")) w.setGravity(Gravity.CENTER);
     else {
       JConsoleApp.theWd.error("set alignment requires left, right or center: " + id + " " + p);
       return;
     }
   } else super.set(p, v);
 }
Exemple #12
0
 // ---------------------------------------------------------------------
 JTextView(String n, String s, Form f, Pane p) {
   super(n, s, f, p);
   type = "static";
   TextView w = new TextView(f.activity);
   widget = (View) w;
   String qn = n;
   String[] opt = Cmd.qsplit(s);
   if (JConsoleApp.theWd.invalidopt(n, opt, "staticbox left right center")) return;
   if (1
       < (Util.sacontains(opt, "left") ? 1 : 0)
           + (Util.sacontains(opt, "right") ? 1 : 0)
           + (Util.sacontains(opt, "center") ? 1 : 0)) {
     JConsoleApp.theWd.error("conflicting child style: " + n + " " + Util.sajoinstr(opt, " "));
     return;
   }
   childStyle(opt);
   if (!Util.sacontains(opt, "staticbox")) w.setText(qn);
   if (Util.sacontains(opt, "left")) w.setGravity(Gravity.LEFT);
   else if (Util.sacontains(opt, "right")) w.setGravity(Gravity.RIGHT);
   else if (Util.sacontains(opt, "center")) w.setGravity(Gravity.CENTER);
 }
Exemple #13
0
 @Override
 public void setupOptions() {
   super.setupOptions();
   options.addOption("d", "destination", true, "destination (queue or topic) name");
   options.addOption(null, "host", true, "set server hostname");
   options.addOption("p", "password", true, "broker password for connection");
   options.addOption(null, "port", true, "set server port");
   options.addOption("u", "user", true, "broker username for connection");
   options.addOption(null, "url", true, "broker connection url");
   options.addOption(
       null, "sleep", true, "sleep for the specified number of milliseconds between each message");
   options.addOption(null, "percent", false, "show progress percentage");
   options.addOption("b", "batch", true, "set batch size");
   options.addOption(
       null,
       "length",
       true,
       "length of internally-generated message, in characters (default 500)");
   options.addOption(null, "properties", true, "add header properties");
   options.addOption(
       null, "durable", true, "enable durable subscription with specified client ID");
   options.addOption(null, "format", true, "display format: none|short|long|text");
 }
 protected void runInternal() throws Exception {
   target.execute();
 }
 public boolean isMatchingCmd(String cmdName, String input) {
   Cmd cmd = getCommand(input);
   return cmd != null && cmd.getName().equals(cmdName);
 }
Exemple #16
0
 @Override
 protected void initializeSubCommands() {
   Cmd cmd = mCommandMap.get("cmd");
   cmd.setHelp(0, null);
   cmd.AddSubCmd("subCmd", 0, null);
 }