Esempio n. 1
0
 /**
  * Gets the normalised version of a string
  *
  * @param s The string to normalise
  * @return The normalised string
  */
 public String getNormalisedString(String s) {
   switch (this) {
     case REPLACE:
       return s.replaceAll("\\t|\\n|\\r", " ");
     case COLLAPSE:
       return REPLACE.getNormalisedString(s).replaceAll("\\s+", " ").trim();
     case PRESERVE:
     default:
       return s;
   }
 }
Esempio n. 2
0
  /** Code completion. */
  private void complete() {
    if (selected()) return;

    // find first character
    final int caret = editor.pos(), startPos = editor.completionStart();
    final String prefix = string(substring(editor.text(), startPos, caret));
    if (prefix.isEmpty()) return;

    // find insertion candidates
    final TreeMap<String, String> tmp = new TreeMap<>();
    for (final Entry<String, String> entry : REPLACE.entrySet()) {
      final String key = entry.getKey();
      if (key.startsWith(prefix)) tmp.put(key, entry.getValue());
    }

    if (tmp.size() == 1) {
      // insert single candidate
      complete(tmp.values().iterator().next(), startPos);
    } else if (!tmp.isEmpty()) {
      // show popup menu
      final JPopupMenu pm = new JPopupMenu();
      final ActionListener al =
          new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
              complete(ae.getActionCommand().replaceAll("^.*?\\] ", ""), startPos);
            }
          };

      for (final Entry<String, String> entry : tmp.entrySet()) {
        final JMenuItem mi = new JMenuItem("[" + entry.getKey() + "] " + entry.getValue());
        pm.add(mi);
        mi.addActionListener(al);
      }
      pm.addSeparator();
      final JMenuItem mi = new JMenuItem(Text.INPUT + Text.COLS + prefix);
      mi.setEnabled(false);
      pm.add(mi);

      final int[] cursor = rend.cursor();
      pm.show(this, cursor[0], cursor[1]);

      // highlight first entry
      final MenuElement[] me = {pm, (JMenuItem) pm.getComponent(0)};
      MenuSelectionManager.defaultManager().setSelectedPath(me);
    }
  }
 public TextCommandServiceImpl(Node node) {
   this.node = node;
   this.hazelcast = node.factory;
   this.logger = node.getLogger(this.getClass().getName());
   this.parallelExecutor = this.node.executorManager.newParallelExecutor(40);
   textCommandProcessors[GET.getValue()] = new GetCommandProcessor(this, true);
   textCommandProcessors[PARTIAL_GET.getValue()] = new GetCommandProcessor(this, false);
   textCommandProcessors[SET.getValue()] = new SetCommandProcessor(this);
   textCommandProcessors[ADD.getValue()] = new SetCommandProcessor(this);
   textCommandProcessors[REPLACE.getValue()] = new SetCommandProcessor(this);
   textCommandProcessors[GET_END.getValue()] = new NoOpCommandProcessor(this);
   textCommandProcessors[DELETE.getValue()] = new DeleteCommandProcessor(this);
   textCommandProcessors[QUIT.getValue()] = new SimpleCommandProcessor(this);
   textCommandProcessors[STATS.getValue()] = new StatsCommandProcessor(this);
   textCommandProcessors[UNKNOWN.getValue()] = new ErrorCommandProcessor(this);
   textCommandProcessors[ERROR_CLIENT.getValue()] = new ErrorCommandProcessor(this);
   textCommandProcessors[ERROR_SERVER.getValue()] = new ErrorCommandProcessor(this);
   textCommandProcessors[HTTP_GET.getValue()] = new HttpGetCommandProcessor(this);
   textCommandProcessors[HTTP_POST.getValue()] = new HttpPostCommandProcessor(this);
   textCommandProcessors[HTTP_PUT.getValue()] = new HttpPostCommandProcessor(this);
   textCommandProcessors[HTTP_DELETE.getValue()] = new HttpDeleteCommandProcessor(this);
   textCommandProcessors[NO_OP.getValue()] = new NoOpCommandProcessor(this);
 }