Ejemplo n.º 1
2
 @NotNull
 public static String getLibraryName(@NotNull Library library) {
   final String result = library.getName();
   if (result != null) {
     return result;
   }
   String[] endingsToStrip = {"/", "!", ".jar"};
   StringBuilder buffer = new StringBuilder();
   for (OrderRootType type : OrderRootType.getAllTypes()) {
     for (String url : library.getUrls(type)) {
       buffer.setLength(0);
       buffer.append(url);
       for (String ending : endingsToStrip) {
         if (buffer.lastIndexOf(ending) == buffer.length() - ending.length()) {
           buffer.setLength(buffer.length() - ending.length());
         }
       }
       final int i = buffer.lastIndexOf(PATH_SEPARATOR);
       if (i < 0 || i >= buffer.length() - 1) {
         continue;
       }
       String candidate = buffer.substring(i + 1);
       if (!StringUtil.isEmpty(candidate)) {
         return candidate;
       }
     }
   }
   assert false;
   return "unknown-lib";
 }
Ejemplo n.º 2
1
  /** 選択されている行をコピーする。 */
  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);
    }
  }
Ejemplo n.º 3
1
        @Override
        protected Transferable createTransferable(JComponent c) {
          if (!(c instanceof XDebuggerTree)) {
            return null;
          }
          XDebuggerTree tree = (XDebuggerTree) c;
          //noinspection deprecation
          TreePath[] selectedPaths = tree.getSelectionPaths();
          if (selectedPaths == null || selectedPaths.length == 0) {
            return null;
          }

          StringBuilder plainBuf = new StringBuilder();
          StringBuilder htmlBuf = new StringBuilder();
          htmlBuf.append("<html>\n<body>\n<ul>\n");
          TextTransferable.ColoredStringBuilder coloredTextContainer =
              new TextTransferable.ColoredStringBuilder();
          for (TreePath path : selectedPaths) {
            htmlBuf.append("  <li>");
            Object node = path.getLastPathComponent();
            if (node != null) {
              if (node instanceof XDebuggerTreeNode) {
                ((XDebuggerTreeNode) node).appendToComponent(coloredTextContainer);
                coloredTextContainer.appendTo(plainBuf, htmlBuf);
              } else {
                String text = node.toString();
                plainBuf.append(text);
                htmlBuf.append(text);
              }
            }
            plainBuf.append('\n');
            htmlBuf.append("</li>\n");
          }

          // remove the last newline
          plainBuf.setLength(plainBuf.length() - 1);
          htmlBuf.append("</ul>\n</body>\n</html>");
          return new TextTransferable(htmlBuf.toString(), plainBuf.toString());
        }
    private void updateText(Rectangle clip) {
      FontMetrics fontMetrics =
          ((EditorImpl) getEditor())
              .getFontMetrics(
                  myTextAttributes != null ? myTextAttributes.getFontType() : Font.PLAIN);
      Insets insets = getInsets();
      int maxLineWidth = getWidth() - (insets != null ? insets.left + insets.right : 0);

      myDocumentTextBuilder.setLength(0);

      boolean singleLineMode = getHeight() / (float) getEditor().getLineHeight() < 1.1f;
      if (singleLineMode) {
        appendAbbreviated(
            myDocumentTextBuilder,
            myRawText,
            0,
            myRawText.length(),
            fontMetrics,
            maxLineWidth,
            true);
      } else {
        int lineHeight = getEditor().getLineHeight();
        int firstVisibleLine = clip.y / lineHeight;
        float visibleLinesCountFractional = clip.height / (float) lineHeight;
        int linesToAppend = 1 + (int) visibleLinesCountFractional;

        LineTokenizer lt = new LineTokenizer(myRawText);
        for (int line = 0; !lt.atEnd() && line < firstVisibleLine; lt.advance(), line++) {
          myDocumentTextBuilder.append('\n');
        }

        for (int line = 0; !lt.atEnd() && line < linesToAppend; lt.advance(), line++) {
          int start = lt.getOffset();
          int end = start + lt.getLength();
          appendAbbreviated(
              myDocumentTextBuilder, myRawText, start, end, fontMetrics, maxLineWidth, false);
          if (lt.getLineSeparatorLength() > 0) {
            myDocumentTextBuilder.append('\n');
          }
        }
      }

      setTextToEditor(myDocumentTextBuilder.toString());
    }
 private void clearLog() {
   log.setLength(0);
 }