示例#1
0
  private void recalculateIconRenderersWidth() {
    myLineToRenderersMap.clear();
    for (EditorMessageIconRenderer renderer : myIconRenderers) {
      int yCoordinate = getIconCoordinate(renderer);
      if (yCoordinate < 0) {
        continue;
      }
      List<IconRendererLayoutConstraint> renderersForLine = myLineToRenderersMap.get(yCoordinate);
      if (renderersForLine == null) {
        renderersForLine = new SortedList(myIconRenderersComparator);
        myLineToRenderersMap.put(yCoordinate, renderersForLine);
      }
      renderersForLine.add(new IconRendererLayoutConstraint(renderer));
    }

    myIconRenderersWidth = MIN_ICON_RENDERERS_WIDTH;
    myMaxIconHeight = 0;
    int[] sortedYCoordinates = myLineToRenderersMap.keys();
    Arrays.sort(sortedYCoordinates);

    int initialOffset = getIconRenderersOffset();
    for (int y : sortedYCoordinates) {
      List<IconRendererLayoutConstraint> row = myLineToRenderersMap.get(y);
      assert row.size() != 0;
      int maxIconHeight = 0;
      for (IconRendererLayoutConstraint rendererConstraint : row) {
        maxIconHeight =
            Math.max(maxIconHeight, rendererConstraint.getIconRenderer().getIcon().getIconHeight());
      }
      myMaxIconHeight = Math.max(myMaxIconHeight, maxIconHeight);
      int offset = initialOffset + LEFT_GAP;
      for (Iterator<IconRendererLayoutConstraint> it = row.iterator(); it.hasNext(); ) {
        IconRendererLayoutConstraint rendererConstraint = it.next();
        rendererConstraint.setX(offset);
        offset += rendererConstraint.getIconRenderer().getIcon().getIconWidth();
        if (it.hasNext()) {
          offset += GAP_BETWEEN_ICONS;
        }
      }
      myIconRenderersWidth = Math.max(myIconRenderersWidth, offset - initialOffset);
    }
  }
示例#2
0
 @Override
 public int compare(
     IconRendererLayoutConstraint constraint1, IconRendererLayoutConstraint constraint2) {
   if (constraint1 == constraint2) {
     return 0;
   }
   EditorMessageIconRenderer renderer1 = constraint1.getIconRenderer();
   EditorMessageIconRenderer renderer2 = constraint2.getIconRenderer();
   if (renderer1.getType() != renderer2.getType()) {
     return renderer1.getType().getWeight() - renderer2.getType().getWeight();
   }
   jetbrains.mps.openapi.editor.cells.EditorCell anchorCell1 = getAnchorCell(renderer1);
   jetbrains.mps.openapi.editor.cells.EditorCell anchorCell2 = getAnchorCell(renderer2);
   // [++] Debugging assertion
   if (anchorCell1 == anchorCell2
       && renderer1 instanceof EditorMessage
       && renderer2 instanceof EditorMessage) {
     EditorMessage editorMessage1 = (EditorMessage) renderer1;
     EditorMessage editorMessage2 = (EditorMessage) renderer2;
     assert false
         : "Two EditorMessages with same type are attached to the same EditorCell: m1 = "
             + editorMessage1
             + ", m2 = "
             + editorMessage2
             + "; owner1 = "
             + editorMessage1.getOwner()
             + ", owner2 = "
             + editorMessage2.getOwner();
   }
   // [--] Debugging assertion
   if (anchorCell1 != null) {
     if (anchorCell2 == null) {
       return 1;
     } else {
       return anchorCell1.getX() - anchorCell2.getX();
     }
   } else if (anchorCell2 != null) {
     return -1;
   }
   return 0;
 }