Example #1
1
  private String toBlockedSequence(String sequence) {
    char[] chars = sequence.toCharArray();
    StringBuilder sb = new StringBuilder();
    boolean modStart = false;
    int count = 0;
    for (char c : chars) {
      String singleLetter = String.valueOf(c);
      if (singleLetter.equals(ComplexProtein.START_MODIFICATION_DECORATOR)) {
        modStart = true;
      } else if (singleLetter.equals(ComplexProtein.END_MODIFICATION_DECORATOR)) {
        modStart = false;
        count++;
      } else {
        if (!modStart) {
          count++;
        }
      }

      sb.append(singleLetter);

      if (count == AMINO_ACID_COUNT_PER_BLOCK) {
        sb.append(" ");
        count = 0;
      }
    }

    return sb.toString();
  }
Example #2
1
 private String escapePrintfChars(String str) {
   if (str == null) return "";
   StringBuilder sb = new StringBuilder();
   for (int ci = 0; ci < str.length(); ci++) {
     char ch = str.charAt(ci);
     if (ch == '%') {
       sb.append('%');
     }
     sb.append(ch);
   }
   return sb.toString();
 }
Example #3
1
 /**
  * Return a copy of the string with all reserved regexp chars escaped by backslash.
  *
  * @param str the string to add escapes to
  * @return String return a string with escapes or "" if str is null
  */
 private String escapeReservedChars(String str) {
   if (str == null) return "";
   StringBuilder sb = new StringBuilder();
   for (int ci = 0; ci < str.length(); ci++) {
     char ch = str.charAt(ci);
     if (RESERVED_STRING.indexOf(ch) >= 0) {
       sb.append('\\');
     }
     sb.append(ch);
   }
   return escapePrintfChars(sb.toString());
 }
Example #4
1
 String getEnabledCiphers() {
   StringBuilder sb = new StringBuilder();
   for (Entry e : data) {
     if (e.enabled) {
       sb.append(e.cipher);
       sb.append(',');
     }
   }
   if (sb.length() == 0) {
     return sb.toString();
   } else {
     return sb.substring(0, sb.length() - 1);
   }
 }
  /**
   * Creates a String representation of the given object.
   *
   * @param certificate to print
   * @return the String representation
   */
  private String toString(Object certificate) {
    final StringBuilder sb = new StringBuilder();
    sb.append("<html><body>\n");

    if (certificate instanceof X509Certificate) {
      renderX509(sb, (X509Certificate) certificate);
    } else {
      sb.append("<pre>\n");
      sb.append(certificate.toString());
      sb.append("</pre>\n");
    }

    sb.append("</body></html>");
    return sb.toString();
  }
  /** 選択されている行をコピーする。 */
  public void copyRow() {

    StringBuilder sb = new StringBuilder();
    int numRows = view.getTable().getSelectedRowCount();
    int[] rowsSelected = view.getTable().getSelectedRows();
    int numColumns = view.getTable().getColumnCount();

    for (int i = 0; i < numRows; i++) {
      if (tableModel.getObject(rowsSelected[i]) != null) {
        StringBuilder s = new StringBuilder();
        for (int col = 0; col < numColumns; col++) {
          Object o = view.getTable().getValueAt(rowsSelected[i], col);
          if (o != null) {
            s.append(o.toString());
          }
          s.append(",");
        }
        if (s.length() > 0) {
          s.setLength(s.length() - 1);
        }
        sb.append(s.toString()).append("\n");
      }
    }
    if (sb.length() > 0) {
      StringSelection stsel = new StringSelection(sb.toString());
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stsel, stsel);
    }
  }
  public void showItem() {

    if (!this.editorPanel.getViewer().isLanguageFunctionAvailable()) {

      return;
    }

    this.highlight =
        this.editorPanel
            .getEditor()
            .addHighlight(this.position, this.position + this.word.length(), null, true);

    final FindSynonymsActionHandler _this = this;

    QTextEditor editor = this.editorPanel.getEditor();

    Rectangle r = null;

    try {

      r = editor.modelToView(this.position);

    } catch (Exception e) {

      // BadLocationException!
      Environment.logError("Location: " + this.position + " is not valid", e);

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      return;
    }

    int y = r.y;

    // Show a panel of all the items.
    final QPopup p = this.popup;

    p.setOpaque(false);

    Synonyms syns = null;

    try {

      syns = this.projectViewer.getSynonymProvider().getSynonyms(this.word);

    } catch (Exception e) {

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      Environment.logError("Unable to lookup synonyms for: " + word, e);

      return;
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("ed"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 2));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("s"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 1));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    StringBuilder sb = new StringBuilder();

    if (syns.words.size() > 0) {

      sb.append("6px");

      for (int i = 0; i < syns.words.size(); i++) {

        if (sb.length() > 0) {

          sb.append(", ");
        }

        sb.append("p, 3px, [p,90px], 5px");
      }
      /*
                if (syns.words.size () > 0)
                {

                    sb.append (",5px");

                }
      */
    } else {

      sb.append("6px, p, 6px");
    }

    FormLayout summOnly = new FormLayout("3px, fill:380px:grow, 3px", sb.toString());
    PanelBuilder pb = new PanelBuilder(summOnly);

    CellConstraints cc = new CellConstraints();

    int ind = 2;

    Map<String, String> names = new HashMap();
    names.put(Synonyms.ADJECTIVE + "", "Adjectives");
    names.put(Synonyms.NOUN + "", "Nouns");
    names.put(Synonyms.VERB + "", "Verbs");
    names.put(Synonyms.ADVERB + "", "Adverbs");
    names.put(Synonyms.OTHER + "", "Other");

    if (syns.words.size() == 0) {

      JLabel l = new JLabel("No synonyms found.");
      l.setFont(l.getFont().deriveFont(Font.ITALIC));

      pb.add(l, cc.xy(2, 2));
    }

    // Determine what type of word we are looking for.
    for (Synonyms.Part i : syns.words) {

      JLabel l = new JLabel(names.get(i.type + ""));

      l.setFont(l.getFont().deriveFont(Font.ITALIC));
      l.setFont(l.getFont().deriveFont((float) UIUtils.getEditorFontSize(10)));
      l.setBorder(
          new CompoundBorder(
              new MatteBorder(0, 0, 1, 0, Environment.getBorderColor()),
              new EmptyBorder(0, 0, 3, 0)));

      pb.add(l, cc.xy(2, ind));

      ind += 2;

      HTMLEditorKit kit = new HTMLEditorKit();
      HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();

      JTextPane t = new JTextPane(doc);
      t.setEditorKit(kit);
      t.setEditable(false);
      t.setOpaque(false);

      StringBuilder buf =
          new StringBuilder(
              "<style>a { text-decoration: none; } a:hover { text-decoration: underline; }</style><span style='color: #000000; font-size: "
                  + ((int) UIUtils.getEditorFontSize(10) /*t.getFont ().getSize () + 2*/)
                  + "pt; font-family: "
                  + t.getFont().getFontName()
                  + ";'>");

      for (int x = 0; x < i.words.size(); x++) {

        String w = (String) i.words.get(x);

        buf.append("<a class='x' href='http://" + w + "'>" + w + "</a>");

        if (x < (i.words.size() - 1)) {

          buf.append(", ");
        }
      }

      buf.append("</span>");

      t.setText(buf.toString());

      t.addHyperlinkListener(
          new HyperlinkAdapter() {

            public void hyperlinkUpdate(HyperlinkEvent ev) {

              if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

                QTextEditor ed = _this.editorPanel.getEditor();

                ed.replaceText(
                    _this.position, _this.position + _this.word.length(), ev.getURL().getHost());

                ed.removeHighlight(_this.highlight);

                _this.popup.setVisible(false);

                _this.projectViewer.fireProjectEvent(
                    ProjectEvent.SYNONYM, ProjectEvent.REPLACE, ev.getURL().getHost());
              }
            }
          });

      // Annoying that we have to do this but it prevents the text from being too small.

      t.setSize(new Dimension(380, Short.MAX_VALUE));

      JScrollPane sp = new JScrollPane(t);

      t.setCaretPosition(0);

      sp.setOpaque(false);
      sp.getVerticalScrollBar().setValue(0);
      /*
                  sp.setPreferredSize (t.getPreferredSize ());
                  sp.setMaximumSize (new Dimension (380,
                                                    75));
      */
      sp.getViewport().setOpaque(false);
      sp.setOpaque(false);
      sp.setBorder(null);
      sp.getViewport().setBackground(Color.WHITE);
      sp.setAlignmentX(Component.LEFT_ALIGNMENT);

      pb.add(sp, cc.xy(2, ind));

      ind += 2;
    }

    JPanel pan = pb.getPanel();
    pan.setOpaque(true);
    pan.setBackground(Color.WHITE);

    this.popup.setContent(pan);

    // r.y -= this.editorPanel.getScrollPane ().getVerticalScrollBar ().getValue ();

    Point po = SwingUtilities.convertPoint(editor, r.x, r.y, this.editorPanel);

    r.x = po.x;
    r.y = po.y;

    // Subtract the insets of the editorPanel.
    Insets ins = this.editorPanel.getInsets();

    r.x -= ins.left;
    r.y -= ins.top;

    this.editorPanel.showPopupAt(this.popup, r, "above", true);
  }
Example #8
0
  protected String consume(BufferedReader br) throws Exception {
    StringBuilder ret = new StringBuilder();

    int ch;
    while ((ch = br.read()) != -1) ret.appendCodePoint(ch);

    return ret.toString();
  }
Example #9
0
  private <T extends Enum<T>> String getPropertyValue(T algo) {
    StringBuilder strb = new StringBuilder();

    for (T it : active.algos(algo)) {
      strb.append(it.name());
      strb.append(';');
    }
    return strb.toString();
  }
Example #10
0
 public static String getLines(String s) {
   StringBuilder sb = new StringBuilder();
   int index = 0;
   for (int i = 1; index != -1; i++) {
     sb.append(i + "\n");
     index = s.indexOf("\n", index + 1);
   }
   return sb.toString();
 }
Example #11
0
  private void end(StringBuilder ans, Pretty pretty, String indent) {
    if (endEncloser == null) return;
    if (!pretty.pretty) ans.append(endEncloser);
    else {
      Utilities.assureEndsWithNewLine(ans);
      ans.append(indent + endEncloser);
      if (pretty.comments && endComment.length() > 0) ans.append("#" + endComment);

      Utilities.assureEndsWithNewLine(ans);
    }
  }
  /**
   * Converts the byte array to hex string.
   *
   * @param raw the data.
   * @return the hex string.
   */
  private String getHex(byte[] raw) {
    if (raw == null) return null;

    StringBuilder hex = new StringBuilder(2 * raw.length);
    Formatter f = new Formatter(hex);
    try {
      for (byte b : raw) f.format("%02x", b);
    } finally {
      f.close();
    }
    return hex.toString();
  }
Example #13
0
 private void start(StringBuilder ans, Pretty pretty, String indent) {
   if (startEncloser == null) return;
   if (!pretty.pretty) {
     ans.append(startEncloser);
   } else {
     String comment;
     if (pretty.comments && startComment.length() > 0) comment = " #" + startComment;
     else comment = "";
     ans.append(indent + startEncloser + comment);
     Utilities.assureEndsWithNewLine(ans);
   }
 }
Example #14
0
 public static String inputStreamReaderToString(InputStreamReader in) throws Exception {
   StringBuilder sb = new StringBuilder();
   char[] buf = new char[1025];
   while (in.ready()) {
     sb.append((new String(buf, 0, in.read(buf, 0, 1024))).replaceAll("\r\n", "\n"));
   }
   in.close();
   String tmp = sb.toString();
   while (tmp.contains("\r\n")) {
     tmp = tmp.replaceAll("\r\n", "\n");
   }
   return tmp;
 }
Example #15
0
 public String cutToLine(String str, int lineChars) {
   String eol = "\n";
   str = str.replace("\n", "%{EOL}");
   StringBuilder builder = new StringBuilder();
   int pointer = 0;
   for (char c : str.toCharArray()) {
     if ((++pointer % lineChars) == 0) {
       builder.append(eol);
     }
     builder.append(c);
   }
   return builder.toString();
 }
Example #16
0
 private String generateOverviewText() throws InsufficientDataException {
   StringBuilder sb = new StringBuilder();
   final String team = config.getTeam();
   double total = checkTotal();
   final String nl = System.getProperty("line.separator");
   for (Entry<String, Row> entry : rows.entrySet()) {
     double hours = Double.parseDouble(entry.getValue().hoursTF.getText());
     double fraction = hours / total;
     if (fraction < 0.004) continue;
     String line = team + ", " + decimalFormat.format(fraction) + ", " + entry.getKey();
     sb.append(line + nl);
   }
   return sb.toString();
 }
Example #17
0
  public void nick_name(String msg) {
    try {
      String name = msg.substring(13);
      this.setName(name);
      Vector v = father.onlineList;
      boolean isRepeatedName = false;
      int size = v.size();
      for (int i = 0; i < size; i++) {
        ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
        if (tempSat.getName().equals(name)) {
          isRepeatedName = true;
          break;
        }
      }
      if (isRepeatedName == true) {
        dout.writeUTF("<#NAME_REPEATED#>");
        din.close();
        dout.close();
        sc.close();
        flag = false;
      } else {
        v.add(this);
        father.refreshList();
        String nickListMsg = "";
        StringBuilder nickListMsgSb = new StringBuilder();
        size = v.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
          nickListMsgSb.append("!");
          nickListMsgSb.append(tempSat.getName());
        }
        nickListMsgSb.append("<#NICK_LIST#>");
        nickListMsg = nickListMsgSb.toString();
        Vector tempv = father.onlineList;
        size = tempv.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i);
          tempSat.dout.writeUTF(nickListMsg);
          if (tempSat != this) {
            tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online....");
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
    private String addWhiteSpace(Document doc, int offset) throws BadLocationException {
      StringBuilder whiteSpace = new StringBuilder("\n");
      Element rootElement = doc.getDefaultRootElement();
      int line = rootElement.getElementIndex(offset);
      int i = rootElement.getElement(line).getStartOffset();

      while (true) {
        String temp = doc.getText(i, 1);

        if (temp.equals(" ") || temp.equals("\t")) {
          whiteSpace.append(temp);
          i++;
        } else break;
      }

      return whiteSpace.toString();
    }
 /**
  * Calculates the hash of the certificate known as the "thumbprint" and returns it as a string
  * representation.
  *
  * @param cert The certificate to hash.
  * @param algorithm The hash algorithm to use.
  * @return The SHA-1 hash of the certificate.
  * @throws CertificateException
  */
 private static String getThumbprint(X509Certificate cert, String algorithm)
     throws CertificateException {
   MessageDigest digest;
   try {
     digest = MessageDigest.getInstance(algorithm);
   } catch (NoSuchAlgorithmException e) {
     throw new CertificateException(e);
   }
   byte[] encodedCert = cert.getEncoded();
   StringBuilder sb = new StringBuilder(encodedCert.length * 2);
   Formatter f = new Formatter(sb);
   try {
     for (byte b : digest.digest(encodedCert)) f.format("%02x", b);
   } finally {
     f.close();
   }
   return sb.toString();
 }
  void assertSorted(String expected) {
    Iterator<String> keys = mySortedParent.keySet().iterator();
    StringBuilder result = new StringBuilder();
    while (keys.hasNext()) {
      String each = keys.next();
      result.append(each);
      int count = mySortedParent.get(each);
      if (count > 1) {
        result.append(" (").append(count).append(")");
      }

      if (keys.hasNext()) {
        result.append("\n");
      }
    }

    Assert.assertEquals(expected, result.toString());
    mySortedParent.clear();
  }
 /**
  * Add a field.
  *
  * @param sb StringBuilder to append to
  * @param field name of the certificate field
  * @param value to print
  */
 private void addField(StringBuilder sb, String field, String value) {
   sb.append("<tr>")
       .append("<td style='margin-left: 5pt; margin-right: 25pt;")
       .append(" white-space: nowrap'>")
       .append(field)
       .append("</td>")
       .append("<td>")
       .append(value)
       .append("</td>")
       .append("</tr>\n");
 }
  /**
   * Appends an HTML representation of the given X509Certificate.
   *
   * @param sb StringBuilder to append to
   * @param certificate to print
   */
  private void renderX509(StringBuilder sb, X509Certificate certificate) {
    X500Principal issuer = certificate.getIssuerX500Principal();
    X500Principal subject = certificate.getSubjectX500Principal();

    sb.append("<table cellspacing='1' cellpadding='1'>\n");

    // subject
    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO"));
    try {
      for (Rdn name : new LdapName(subject.getName()).getRdns()) {
        String nameType = name.getType();
        String lblKey = "service.gui.CERT_INFO_" + nameType;
        String lbl = R.getI18NString(lblKey);

        if ((lbl == null) || ("!" + lblKey + "!").equals(lbl)) lbl = nameType;

        final String value;
        Object nameValue = name.getValue();

        if (nameValue instanceof byte[]) {
          byte[] nameValueAsByteArray = (byte[]) nameValue;

          value = getHex(nameValueAsByteArray) + " (" + new String(nameValueAsByteArray) + ")";
        } else value = nameValue.toString();

        addField(sb, lbl, value);
      }
    } catch (InvalidNameException ine) {
      addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"), subject.getName());
    }

    // issuer
    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_BY"));
    try {
      for (Rdn name : new LdapName(issuer.getName()).getRdns()) {
        String nameType = name.getType();
        String lblKey = "service.gui.CERT_INFO_" + nameType;
        String lbl = R.getI18NString(lblKey);

        if ((lbl == null) || ("!" + lblKey + "!").equals(lbl)) lbl = nameType;

        final String value;
        Object nameValue = name.getValue();

        if (nameValue instanceof byte[]) {
          byte[] nameValueAsByteArray = (byte[]) nameValue;

          value = getHex(nameValueAsByteArray) + " (" + new String(nameValueAsByteArray) + ")";
        } else value = nameValue.toString();

        addField(sb, lbl, value);
      }
    } catch (InvalidNameException ine) {
      addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"), issuer.getName());
    }

    // validity
    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_VALIDITY"));
    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_ISSUED_ON"),
        certificate.getNotBefore().toString());
    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_EXPIRES_ON"),
        certificate.getNotAfter().toString());

    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_FINGERPRINTS"));
    try {
      String sha1String = getThumbprint(certificate, "SHA1");
      String md5String = getThumbprint(certificate, "MD5");

      addField(sb, "SHA1:", sha1String);
      addField(sb, "MD5:", md5String);
    } catch (CertificateException e) {
      // do nothing as we cannot show this value
    }

    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_CERT_DETAILS"));

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_SER_NUM"),
        certificate.getSerialNumber().toString());

    addField(
        sb, R.getI18NString("service.gui.CERT_INFO_VER"), String.valueOf(certificate.getVersion()));

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_SIGN_ALG"),
        String.valueOf(certificate.getSigAlgName()));

    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY_INFO"));

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_ALG"),
        certificate.getPublicKey().getAlgorithm());

    if (certificate.getPublicKey().getAlgorithm().equals("RSA")) {
      RSAPublicKey key = (RSAPublicKey) certificate.getPublicKey();

      addField(
          sb,
          R.getI18NString("service.gui.CERT_INFO_PUB_KEY"),
          R.getI18NString(
              "service.gui.CERT_INFO_KEY_BYTES_PRINT",
              new String[] {
                String.valueOf(key.getModulus().toByteArray().length - 1),
                key.getModulus().toString(16)
              }));

      addField(
          sb, R.getI18NString("service.gui.CERT_INFO_EXP"), key.getPublicExponent().toString());

      addField(
          sb,
          R.getI18NString("service.gui.CERT_INFO_KEY_SIZE"),
          R.getI18NString(
              "service.gui.CERT_INFO_KEY_BITS_PRINT",
              new String[] {String.valueOf(key.getModulus().bitLength())}));
    } else if (certificate.getPublicKey().getAlgorithm().equals("DSA")) {
      DSAPublicKey key = (DSAPublicKey) certificate.getPublicKey();

      addField(sb, "Y:", key.getY().toString(16));
    }

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_SIGN"),
        R.getI18NString(
            "service.gui.CERT_INFO_KEY_BYTES_PRINT",
            new String[] {
              String.valueOf(certificate.getSignature().length), getHex(certificate.getSignature())
            }));

    sb.append("</table>\n");
  }
 public static String getNextName(String base) {
   StringBuilder sb = new StringBuilder();
   sb.append(base);
   sb.append(nextEntryNumber++);
   return sb.toString();
 }
 /**
  * Add a title.
  *
  * @param sb StringBuilder to append to
  * @param title to print
  */
 private void addTitle(StringBuilder sb, String title) {
   sb.append("<tr><td colspan='2'")
       .append(" style='margin-top: 5pt; white-space: nowrap'><p><b>")
       .append(title)
       .append("</b></p></td></tr>\n");
 }
Example #25
0
  public void setNotation(String notation) {
    if (null == notation || notation.length() == 0) {
      notFiringOnChange = true;
      sequenceTextArea.setText("");
      connectionTableModel.setupEmptyData(CONNECTION_TABLE_ROW_COUNT);
      annotationTableModel.setupEmptyData(ANNOTATION_TABLE_ROW_COUNT);
      notFiringOnChange = false;
      return;
    }

    notFiringOnChange = true;
    try {
      ComplexProtein cp = ComplexProtein.convert(notation);
      List<String> sequences = cp.getSequences();
      if (null != sequences && !sequences.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (String seq : sequences) {
          if (sb.length() > 0) {
            sb.append(ComplexProtein.SEQUENCE_SEPARATOR_SYMBOL);
            sb.append("\n");
          }
          sb.append(toBlockedSequence(seq));
          sb.append("\n");
        }
        sequenceTextArea.setText(sb.toString());

        List<PeptideConnection> conList = cp.getConnections();
        if (null != conList && !conList.isEmpty()) {
          if (conList.size() >= CONNECTION_TABLE_ROW_COUNT) {
            connectionTableModel.setData(conList);
          } else {
            List<PeptideConnection> l = new ArrayList<PeptideConnection>();
            l.addAll(conList);
            for (int i = 0; i < CONNECTION_TABLE_ROW_COUNT - conList.size(); i++) {
              l.add(new PeptideConnection());
            }
            connectionTableModel.setData(l);
          }
        } else {
          connectionTableModel.setupEmptyData(CONNECTION_TABLE_ROW_COUNT);
        }

        List<SequenceAnnotation> annList = cp.getAnnotations();
        if (null != annList && !annList.isEmpty()) {
          if (annList.size() >= ANNOTATION_TABLE_ROW_COUNT) {
            annotationTableModel.setData(annList);
          } else {
            List<SequenceAnnotation> l = new ArrayList<SequenceAnnotation>();
            l.addAll(annList);
            for (int i = 0; i < ANNOTATION_TABLE_ROW_COUNT - annList.size(); i++) {
              l.add(new SequenceAnnotation());
            }
            annotationTableModel.setData(l);
          }
        } else {
          annotationTableModel.setupEmptyData(ANNOTATION_TABLE_ROW_COUNT);
        }

      } else {
        sequenceTextArea.setText("");
        connectionTableModel.setupEmptyData(CONNECTION_TABLE_ROW_COUNT);
        annotationTableModel.setupEmptyData(ANNOTATION_TABLE_ROW_COUNT);
      }
    } catch (Exception ex) {
      Logger.getLogger(ProteinEditor.class.getName()).log(Level.SEVERE, null, ex);
      ExceptionHandler.handleException(ex);
    }
    notFiringOnChange = false;
  }
  /**
   * 検索を実行する。
   *
   * @param text キーワード
   */
  private void find(String text) {

    Log.outputFuncLog(Log.LOG_LEVEL_0, Log.FUNCTIONLOG_KIND_INFORMATION, "患者検索", text);

    // 全角スペースをkill
    text = text.replaceAll(" ", " ");

    PatientSearchSpec spec = new PatientSearchSpec();

    if (isDate(text)) {
      spec.setCode(PatientSearchSpec.DATE_SEARCH);
      spec.setDigit(text);

    } else if (StringTool.startsWithKatakana(text)) {
      spec.setCode(PatientSearchSpec.KANA_SEARCH);
      spec.setName(text);

    } else if (StringTool.startsWithHiragana(text)) {
      text = StringTool.hiraganaToKatakana(text);
      spec.setCode(PatientSearchSpec.KANA_SEARCH);
      spec.setName(text);

    } else if (isNameAddress(text)) {
      spec.setCode(PatientSearchSpec.NAME_SEARCH);
      spec.setName(text);

    } else {

      if (Project.getBoolean("zero.paddings.id.search", false)) {
        int len = text.length();
        int paddings = Project.getInt("patient.id.length", 0) - len;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < paddings; i++) {
          sb.append("0");
        }
        sb.append(text);
        text = sb.toString();
      }

      spec.setCode(PatientSearchSpec.DIGIT_SEARCH);
      spec.setDigit(text);
    }

    final PatientSearchSpec searchSpec = spec;

    SimpleWorker worker =
        new SimpleWorker<Collection, Void>() {

          @Override
          protected Collection doInBackground() throws Exception {
            PatientDelegater pdl = new PatientDelegater();
            Collection result = pdl.getPatients(searchSpec);
            return result;
          }

          @Override
          protected void succeeded(Collection result) {

            List<PatientModel> list = (List<PatientModel>) result;

            if (list != null && list.size() > 0) {

              // minagawa^ 仮保存カルテ取得対応
              /*
              boolean sorted = true;
              for (int i=0; i < COLUMN_NAMES.length; i++) {
                  if (sorter.getSortingStatus(i)==0) {
                      sorted = false;
                      break;
                  }
              }

              if (!sorted) {

                  switch (sortItem) {
                      case 0:
                          Comparator c = new Comparator<PatientModel>() {

                              @Override
                              public int compare(PatientModel o1, PatientModel o2) {
                                  return o1.getPatientId().compareTo(o2.getPatientId());
                              }
                          };
                          Collections.sort(list, c);
                          break;
                      case 1:
                        Comparator c2 = new Comparator<PatientModel>() {

                          @Override
                           public int compare(PatientModel p1, PatientModel p2) {
                              String kana1 = p1.getKanaName();
                              String kana2 = p2.getKanaName();
                              if (kana1 != null && kana2 != null) {
                                  return p1.getKanaName().compareTo(p2.getKanaName());
                              } else if (kana1 != null && kana2 == null) {
                                  return -1;
                              } else if (kana1 == null && kana2 != null) {
                                  return 1;
                              } else {
                                  return 0;
                              }
                          }
                        };
                      Collections.sort(list, c2);
                      break;
                  }
              }
              */
              sortList(list);
              // minagawa$

              tableModel.setDataProvider(list);
              Log.outputFuncLog(
                  Log.LOG_LEVEL_0,
                  Log.FUNCTIONLOG_KIND_INFORMATION,
                  "患者数:",
                  String.valueOf(list.size()));
            } else {
              tableModel.clear();
              Log.outputFuncLog(Log.LOG_LEVEL_0, Log.FUNCTIONLOG_KIND_INFORMATION, "患者数:", "0");
            }
            updateStatusLabel();
          }

          @Override
          protected void failed(Throwable cause) {}

          @Override
          protected void startProgress() {
            doStartProgress();
          }

          @Override
          protected void stopProgress() {
            doStopProgress();
          }
        };

    worker.execute();
  }
Example #27
0
  void insertButton_actionPerformed(ActionEvent e) {
    Object selected = paramComboBox.getSelectedItem();
    ConfigParamDescr descr;
    String key;
    int type = 0;
    String format = "";
    if (selected instanceof ConfigParamDescr) {
      descr = (ConfigParamDescr) selected;
      key = descr.getKey();
      type = descr.getType();
      switch (type) {
        case ConfigParamDescr.TYPE_STRING:
        case ConfigParamDescr.TYPE_URL:
        case ConfigParamDescr.TYPE_BOOLEAN:
          format = "%s";
          break;
        case ConfigParamDescr.TYPE_INT:
        case ConfigParamDescr.TYPE_LONG:
        case ConfigParamDescr.TYPE_POS_INT:
          NumericPaddingDialog dialog = new NumericPaddingDialog();
          Point pos = this.getLocationOnScreen();
          dialog.setLocation(pos.x, pos.y);
          dialog.pack();
          dialog.setVisible(true);
          StringBuilder fbuf = new StringBuilder("%");
          int width = dialog.getPaddingSize();
          boolean is_zero = dialog.useZero();
          if (width > 0) {
            fbuf.append(".");
            if (is_zero) {
              fbuf.append(0);
            }
            fbuf.append(width);
          }
          if (type == ConfigParamDescr.TYPE_LONG) {
            fbuf.append("ld");
          } else {
            fbuf.append("d");
          }
          format = fbuf.toString();
          break;
        case ConfigParamDescr.TYPE_YEAR:
          if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) {
            format = "%02d";
          } else {
            format = "%d";
          }
          break;
        case ConfigParamDescr.TYPE_RANGE:
        case ConfigParamDescr.TYPE_NUM_RANGE:
        case ConfigParamDescr.TYPE_SET:
          format = "%s";
          break;
      }
      if (selectedPane == 0) {
        insertParameter(descr, format, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        int pos = formatTextArea.getCaretPosition();
        formatTextArea.insert(format, pos);

        pos = parameterTextArea.getCaretPosition();
        parameterTextArea.insert(", " + key, pos);
      }
    } else {
      key = selected.toString();
      format =
          escapePrintfChars(
              (String)
                  JOptionPane.showInputDialog(
                      this,
                      "Enter the string you wish to input",
                      "String Literal Input",
                      JOptionPane.OK_CANCEL_OPTION));
      if (StringUtil.isNullString(format)) {
        return;
      }
      if (selectedPane == 0) {
        insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        formatTextArea.insert(format, formatTextArea.getCaretPosition());
      }
    }
  }
 /**
  * Sets the subject in the label.
  *
  * @param word the new subject that jumps over the lazy dog
  */
 public void setSubject(String word) {
   StringBuilder text = new StringBuilder(prefix);
   text.append(word);
   text.append(suffix);
   label.setText(text.toString());
 }
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append((int) _dim.getWidth());
   sb.append(' ');
   sb.append((int) _dim.getHeight());
   sb.append(' ');
   sb.append(_loc.x);
   sb.append(' ');
   sb.append(_loc.y);
   sb.append(' ');
   sb.append(_currentStrategyIndex);
   return sb.toString();
 }