Esempio n. 1
0
 protected void paintWithColor(Graphics g, EditorCell cell, Color color) {
   int x = cell.getX() + cell.getLeftInset();
   int y = cell.getY();
   int width = cell.getWidth() - cell.getLeftInset() - cell.getRightInset() - 1;
   int height = cell.getHeight() - cell.getTopInset() - cell.getBottomInset() - 1;
   g.setColor(color);
   g.drawRect(x, y, width, height);
   color = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() / 5);
   g.setColor(color);
   g.fillRect(x, y, width, height);
 }
Esempio n. 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;
 }
Esempio n. 3
0
  public static void showCreateNewRootMenu(
      @NotNull jetbrains.mps.openapi.editor.EditorContext editorContext,
      @Nullable Setter<SNode> newRootHandler,
      @Nullable Condition<SConcept> conceptsFilter) {
    final EditorCell selectedCell = editorContext.getSelectedCell();
    int x = selectedCell.getX();
    int y = selectedCell.getY();
    if (selectedCell instanceof EditorCell_Label) {
      y += selectedCell.getHeight();
    }
    Component editorComponent = ((EditorContext) editorContext).getNodeEditorComponent();
    final DataContext dataContext = DataManager.getInstance().getDataContext(editorComponent, x, y);
    final SModel model = selectedCell.getSNode().getModel();

    if (conceptsFilter == null) {
      conceptsFilter = Condition.TRUE_CONDITION;
    }

    BaseGroup group = new BaseGroup("");
    Set<SLanguage> modelLanguages =
        new SLanguageHierarchy(SModelOperations.getAllLanguageImports(model)).getExtended();
    SLanguage[] languages = modelLanguages.toArray(new SLanguage[modelLanguages.size()]);
    Arrays.sort(languages, new ToStringComparator());
    for (SLanguage language : languages) {
      boolean hasChildren = false;
      for (SAbstractConcept ac : language.getConcepts()) {
        if (!(ac instanceof SConcept)) {
          continue;
        }
        final SConcept concept = (SConcept) ac;
        if (concept.isRootable() && conceptsFilter.met(concept)) {
          group.add(new AddNewRootAction(model, concept, newRootHandler));
          hasChildren = true;
        }
      }

      if (hasChildren) {
        group.addSeparator();
      }
    }

    ListPopup popup =
        JBPopupFactory.getInstance()
            .createActionGroupPopup(
                IdeBundle.message("title.popup.new.element"),
                group,
                dataContext,
                JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                false);
    //    popup.showInBestPositionFor(dataContext);
    popup.show(new RelativePoint(editorComponent, new Point(x, y)));
  }
Esempio n. 4
0
  @Override
  public void paint(Graphics g, ParentSettings parentSettings) {
    ParentSettings settings = isSelectionPaintedOnAncestor(parentSettings);
    if (!settings.isSelectionPainted()) {
      settings = (paintBackground(g, parentSettings));
    }
    paintSelectionIfRequired(g, parentSettings);
    paintContent(g, parentSettings);

    for (EditorCell child : this) {
      if (g.hitClip(child.getX(), child.getY(), child.getWidth(), child.getHeight())) {
        ((jetbrains.mps.nodeEditor.cells.EditorCell) child).paint(g, settings);
      }
    }
    paintDecorations(g);
  }
Esempio n. 5
0
 @Override
 public void paintSelection(
     Graphics g, Color c, boolean drawBorder, ParentSettings parentSettings) {
   List<? extends EditorCell> selectionCells = myCellLayout.getSelectionCells(this);
   if (selectionCells != null) {
     ParentSettings selection = isSelectionPaintedOnAncestor(parentSettings);
     for (EditorCell cell : selectionCells) {
       if (g.hitClip(cell.getX(), cell.getY(), cell.getWidth(), cell.getHeight())) {
         ((jetbrains.mps.nodeEditor.cells.EditorCell) cell).paintSelection(g, c, false, selection);
       }
     }
   } else {
     List<Rectangle> selection = myCellLayout.getSelectionBounds(this);
     g.setColor(c);
     for (Rectangle part : selection) {
       g.fillRect(part.x, part.y, part.width, part.height);
     }
   }
 }