Пример #1
0
  private void paintBackgroundAndFoldingLine(Graphics g, Rectangle clipBounds) {
    Graphics2D g2d = (Graphics2D) g;
    g.setColor(getBackground());
    g.fillRect(
        clipBounds.x,
        clipBounds.y,
        Math.min(clipBounds.width, myFoldingLineX - clipBounds.x),
        clipBounds.height);
    g.setColor(getEditorComponent().getBackground());
    g.fillRect(
        Math.max(clipBounds.x, myFoldingLineX),
        clipBounds.y,
        clipBounds.width - Math.max(0, myFoldingLineX - clipBounds.x),
        clipBounds.height);

    // same as in EditorComponent.paint() method
    EditorCell deepestCell = myEditorComponent.getDeepestSelectedCell();
    if (deepestCell instanceof EditorCell_Label) {
      int selectedCellY = deepestCell.getY();
      int selectedCellHeight =
          deepestCell.getHeight() - deepestCell.getTopInset() - deepestCell.getBottomInset();
      if (g.hitClip(clipBounds.x, selectedCellY, clipBounds.width, selectedCellHeight)) {
        g.setColor(EditorSettings.getInstance().getCaretRowColor());
        g.fillRect(clipBounds.x, selectedCellY, clipBounds.width, selectedCellHeight);
        // Drawing folding line
        UIUtil.drawVDottedLine(
            g2d,
            myFoldingLineX,
            clipBounds.y,
            selectedCellY,
            getBackground(),
            EditorSettings.getInstance().getLeftHighlighterTearLineColor());
        UIUtil.drawVDottedLine(
            g2d,
            myFoldingLineX,
            selectedCellY,
            selectedCellY + selectedCellHeight,
            EditorSettings.getInstance().getCaretRowColor(),
            EditorSettings.getInstance().getLeftHighlighterTearLineColor());
        UIUtil.drawVDottedLine(
            g2d,
            myFoldingLineX,
            selectedCellY + selectedCellHeight,
            clipBounds.y + clipBounds.height,
            getBackground(),
            EditorSettings.getInstance().getLeftHighlighterTearLineColor());
        return;
      }
    }
    // Drawing folding line
    // COLORS: Remove hardcoded color
    UIUtil.drawVDottedLine(
        g2d,
        myFoldingLineX,
        clipBounds.y,
        clipBounds.y + clipBounds.height,
        getBackground(),
        Color.gray);
  }
Пример #2
0
  public LeftEditorHighlighter(@NotNull EditorComponent editorComponent, boolean rightToLeft) {
    setBackground(EditorSettings.getInstance().getLeftHighlighterBackgroundColor());
    myEditorComponent = editorComponent;
    myRightToLeft = rightToLeft;
    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseExited(MouseEvent e) {
            mouseExitedFoldingArea(e);
            mouseExitedIconsArea(e);
          }

          @Override
          public void mouseEntered(MouseEvent e) {
            if (isInFoldingArea(e)) {
              mouseMovedInFoldingArea(e);
            } else if (isInTextArea(e)) {
              mouseMovedInTextArea(e);
            } else {
              mouseMovedInIconsArea(e);
            }
          }
        });
    addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(MouseEvent e) {
            if (isInFoldingArea(e)) {
              mouseExitedIconsArea(e);
              mouseMovedInFoldingArea(e);
            } else if (isInTextArea(e)) {
              mouseExitedFoldingArea(e);
              mouseExitedIconsArea(e);
              mouseMovedInTextArea(e);
            } else {
              mouseExitedFoldingArea(e);
              mouseMovedInIconsArea(e);
            }
          }
        });
    if (MPSToolTipManager.getInstance() != null) {
      MPSToolTipManager.getInstance().registerComponent(this);
    }
    editorComponent.addRebuildListener(
        new RebuildListener() {
          @Override
          public void editorRebuilt(EditorComponent editor) {
            assert SwingUtilities.isEventDispatchThread()
                : "LeftEditorHighlighter$RebuildListener should be called in eventDispatchThread";
            for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
              painter.editorRebuilt();
            }
          }
        });
    myBracketsPainter = new BracketsPainter(this, myRightToLeft);
    myFoldingButtonsPainter = new FoldingButtonsPainter(this);

    myFoldingAreaPainters.add(myBracketsPainter);
    myFoldingAreaPainters.add(myFoldingButtonsPainter);
  }
Пример #3
0
  public SelectImageFileButton(SNode node, EditorContext editorContext) {
    this.myNode = node;
    this.myEditorContext = editorContext;
    this.setFont(EditorSettings.getInstance().getDefaultEditorFont());
    this.setBorder(new MetalBorders.ButtonBorder());

    this.setAction(
        new AbstractAction(" ... ") {
          @Override
          public void actionPerformed(ActionEvent e) {
            Component root = SwingUtilities.getRoot(SelectImageFileButton.this);
            if (root instanceof Frame) {
              Frame frame = (Frame) root;
              TreeFileChooser chooser = new TreeFileChooser();
              final Wrappers._T<String> filename = new Wrappers._T<String>(null);
              ModelAccess modelAccess = myEditorContext.getRepository().getModelAccess();
              modelAccess.runReadAction(
                  new Runnable() {
                    public void run() {
                      filename.value =
                          SPropertyOperations.getString(
                              myNode,
                              MetaAdapterFactory.getProperty(
                                  0x18bc659203a64e29L,
                                  0xa83a7ff23bde13baL,
                                  0x1095e12de6fL,
                                  0x1095e2f7e63L,
                                  "imageFile"));
                    }
                  });

              AbstractModule module = (AbstractModule) SNodeOperations.getModel(myNode).getModule();
              MacroHelper macroHelper = MacrosFactory.forModule(module);
              if (macroHelper != null) {
                filename.value = macroHelper.expandPath(filename.value);
              }
              final File baseFile = (filename.value == null ? null : new File(filename.value));

              if (baseFile != null && baseFile.exists()) {
                chooser.setInitialFile(
                    FileSystem.getInstance().getFileByPath(baseFile.getAbsolutePath()));
              }
              IFile result = chooser.showDialog(frame);
              if (result == null) {
                return;
              }
              String selectedPath = result.getPath();
              final String pathToShow =
                  (macroHelper == null ? selectedPath : macroHelper.shrinkPath(selectedPath));
              modelAccess.executeCommand(
                  new Runnable() {
                    public void run() {
                      SPropertyOperations.set(
                          SelectImageFileButton.this.myNode,
                          MetaAdapterFactory.getProperty(
                              0x18bc659203a64e29L,
                              0xa83a7ff23bde13baL,
                              0x1095e12de6fL,
                              0x1095e2f7e63L,
                              "imageFile"),
                          pathToShow);
                    }
                  });
            }
          }
        });
  }