Exemplo n.º 1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     TextDocument ta = (TextDocument) td.getComponentAt(td.getSelectedIndex());
     Pattern pn = Pattern.compile(tf1.getText());
     Matcher mt = pn.matcher(ta.getText());
     if (e.getSource() == jb2) { // 取代
       ta.setText(mt.replaceAll(tf2.getText()));
     } else if (e.getSource() == jb1) { // 尋找
       Highlighter hl = ta.getHighlighter();
       hl.removeAllHighlights();
       while (mt.find()) {
         try {
           hl.addHighlight(
               mt.start(), mt.end(), new DefaultHighlighter.DefaultHighlightPainter(null));
         } catch (Exception ex) {
         }
       } // 開啟及關閉介面
     } else if (e.getSource() == replace_searchMenuItem) {
       System.out.println("Replace/Search is show:" + !show);
       if (show) {
         getContentPane().remove(jp);
         show = false;
       } else {
         getContentPane().add(jp, BorderLayout.SOUTH);
         show = true;
       }
       validate(); // 刷新容器
     }
   } else if (e.getSource() == replace_searchMenuItem) {
     JOptionPane.showMessageDialog(
         null, "尚無檔案,無法使用!", "Repace/Search error", JOptionPane.ERROR_MESSAGE);
   }
 }
Exemplo n.º 2
0
  public void _sendString(String text) {
    if (writeCommand == null) return;

    /* intercept sessions -i and deliver it to a listener within armitage */
    if (sessionListener != null) {
      Matcher m = interact.matcher(text);
      if (m.matches()) {
        sessionListener.actionPerformed(new ActionEvent(this, 0, m.group(1)));
        return;
      }
    }

    Map read = null;

    try {
      synchronized (this) {
        if (window != null && echo) {
          window.append(window.getPromptText() + text);
        }
      }

      if ("armitage.push".equals(writeCommand)) {
        read = (Map) connection.execute(writeCommand, new Object[] {session, text});
      } else {
        connection.execute(writeCommand, new Object[] {session, text});
        read = readResponse();
      }
      processRead(read);

      fireSessionWroteEvent(text);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 3
0
 public boolean accept(File f) {
   if (f == null) {
     return false;
   }
   if (f.isDirectory()) {
     return true;
   }
   return pattern.matcher(f.getName()).matches();
 }
Exemplo n.º 4
0
 public synchronized String format(String message) {
   Matcher matcher = variablePattern.matcher(message);
   while (matcher.find()) {
     String variable = matcher.group();
     variable = variable.substring(1);
     if (variable.startsWith("{") && variable.endsWith("}"))
       variable = variable.substring(1, variable.length() - 1);
     String value = variables.get(variable);
     if (value == null) value = "";
     message =
         message.replaceFirst(Pattern.quote(matcher.group()), Matcher.quoteReplacement(value));
   }
   matcher = colorPattern.matcher(message);
   while (matcher.find())
     message =
         message.substring(0, matcher.start()) + "\247" + message.substring(matcher.end() - 1);
   return message;
 }
Exemplo n.º 5
0
  void findRemoveDirectives(boolean clean) {
    // if ( clean ) editor.startCompoundEdit();

    Sketch sketch = editor.getSketch();
    for (int i = 0; i < sketch.getCodeCount(); i++) {
      SketchCode code = sketch.getCode(i);
      String program = code.getProgram();
      StringBuffer buffer = new StringBuffer();

      Matcher m = pjsPattern.matcher(program);
      while (m.find()) {
        String mm = m.group();

        // TODO this urgently needs tests ..

        /* remove framing */
        mm = mm.replaceAll("^\\/\\*\\s*@pjs", "").replaceAll("\\s*\\*\\/\\s*$", "");
        /* fix multiline nice formatting */
        mm = mm.replaceAll("[\\s]*([^;\\s\\n\\r]+)[\\s]*,[\\s]*[\\n\\r]+", "$1,");
        /* fix multiline version without semicolons */
        mm = mm.replaceAll("[\\s]*([^;\\s\\n\\r]+)[\\s]*[\\n\\r]+", "$1;");
        mm = mm.replaceAll("\n", " ").replaceAll("\r", " ");

        // System.out.println(mm);

        if (clean) {
          m.appendReplacement(buffer, "");
        } else {
          String[] directives = mm.split(";");
          for (String d : directives) {
            // System.out.println(d);
            parseDirective(d);
          }
        }
      }

      if (clean) {
        m.appendTail(buffer);

        // TODO: not working!
        code.setProgram(buffer.toString());
        code.setModified(true);
      }
    }

    if (clean) {
      // editor.stopCompoundEdit();
      editor.setText(sketch.getCurrentCode().getProgram());
      sketch.setModified(false);
      sketch.setModified(true);
    }
  }
Exemplo n.º 6
0
  /**
   * Handles info messages resulting from a query execution.
   *
   * @param msg info message
   * @return true if error was found
   */
  private boolean error(final String msg) {
    final String line = msg.replaceAll("[\\r\\n].*", "");
    Matcher m = XQERROR.matcher(line);
    int el, ec = 2;
    if (!m.matches()) {
      m = XMLERROR.matcher(line);
      if (!m.matches()) return true;
      el = Integer.parseInt(m.group(1));
      errFile = getEditor().file.path();
    } else {
      el = Integer.parseInt(m.group(1));
      ec = Integer.parseInt(m.group(2));
      errFile = m.group(3);
    }

    final EditorArea edit = find(IO.get(errFile), false);
    if (edit == null) return true;

    // find approximate error position
    final int ll = edit.last.length;
    int ep = ll;
    for (int e = 1, l = 1, c = 1; e < ll; ++c, e += cl(edit.last, e)) {
      if (l > el || l == el && c == ec) {
        ep = e;
        break;
      }
      if (edit.last[e] == '\n') {
        ++l;
        c = 0;
      }
    }
    if (ep < ll && Character.isLetterOrDigit(cp(edit.last, ep))) {
      while (ep > 0 && Character.isLetterOrDigit(cp(edit.last, ep - 1))) ep--;
    }
    edit.error(ep);
    errPos = ep;
    return true;
  }
Exemplo n.º 7
0
 private String htmlize(String msg) {
   StringBuilder sb = new StringBuilder();
   Pattern patMsgCat = Pattern.compile("\\[(.+?)\\].*");
   msg = msg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
   for (String line : msg.split(lineSep)) {
     Matcher m = patMsgCat.matcher(line);
     String cls = "normal";
     if (m.matches()) {
       cls = m.group(1);
     }
     line = "<span class='" + cls + "'>" + line + "</span>";
     sb.append(line).append("<br>");
   }
   return sb.toString();
 }
Exemplo n.º 8
0
 private static List<String> loadAccounts(String fileName) {
   List<String> accounts = new ArrayList<String>();
   try {
     Pattern pattern = Pattern.compile("[\\w]{1,16}");
     BufferedReader reader = new BufferedReader(new FileReader(new File(fileName)));
     String line;
     while ((line = reader.readLine()) != null) {
       Matcher matcher = pattern.matcher(line);
       if (!matcher.find()) continue;
       String username = matcher.group();
       if (!matcher.find()) continue;
       String password = matcher.group();
       accounts.add(username + ":" + password);
     }
     reader.close();
   } catch (Exception exception) {
     throw new RuntimeException(exception);
   }
   System.out.println("Loaded " + accounts.size() + " accounts.");
   return accounts;
 }
Exemplo n.º 9
0
  void openButton_actionPerformed(ActionEvent e) {
    String name = nameTextField.getText().trim();
    if (mode == ProfileChooser.MODE_OPEN) { // open
      if (name.equals("")) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notSelect"));
        return;
      }

      UniProfile prof = isSameProfile(name);
      if (prof == null) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notExist") + ": " + name);
        return;
      }

      values = new Object[1];
      values[0] = prof;
    } else { // save as 或 save
      if (name.equals("")) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notName"));
        return;
      }

      String tmpName = name;
      Pattern pattern = Pattern.compile(".+\\.prf");
      Matcher matcher = pattern.matcher(tmpName);
      if (!matcher.find()) {
        tmpName += ".prf";
      }

      UniProfile pf = isSameProfile(tmpName);
      if (pf != null) { // 存 在 相 同 的 名 字 的profile ( pf )
        if (view.initor.mdb.getSchNumOnProfName(pf.getProfileName()) > 0) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("EditProfileDialog.error.hasSch"));
          return;
        }

        if (JOptionPane.showConfirmDialog( // 提示信息更换
                (Dialog) bakable,
                SanBootView.res.getString("ProfileChooser.confirmmsg1"),
                SanBootView.res.getString("common.confirm"),
                JOptionPane.OK_CANCEL_OPTION)
            == JOptionPane.CANCEL_OPTION) {
          return;
        } else {
          values = new Object[2];
          values[0] = pf;
          values[1] = saveAsProfile;
        }
      } else { // 不 存 在 相 同 的 名 字
        String pname = ResourceCenter.PROFILE_DIR + name + ".prf";

        if (pname.indexOf("\"") >= 0
            || pname.indexOf("'") >= 0
            || pname.indexOf(' ') >= 0
            || pname.indexOf('\t') >= 0) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("ProfileChooser.errmsg.badname"));
          return;
        }

        if (pname.getBytes().length >= 1000) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("ProfileChooser.errmsg.tooLargePname"));
          return;
        }

        values = new Object[1];
        saveAsProfile.setProfileName(pname);
        values[0] = saveAsProfile;
      }
    }

    dispose();
  }