private E findStartingNodeForDeletion(E element) {
      if (root == null) return null;

      TreeNode<E> parent = null;
      TreeNode<E> current = root;
      while (current != null) {
        if (element.compareTo(current.element) < 0) {
          parent = current;
          current = current.left;
        } else if (element.compareTo(current.element) > 0) {
          parent = current;
          current = current.right;
        } else break;
      }

      if (current == null) return null;

      if (current.left == null) {
        if (parent == null) {
          return null;
        } else {
          return parent.element;
        }
      } else {
        TreeNode<E> parentOfRightMost = current;
        TreeNode<E> rightMost = current.left;

        while (rightMost.right != null) {
          parentOfRightMost = rightMost;
          rightMost = rightMost.right;
        }
        return parentOfRightMost.element;
      }
    }
 /**
  * Performs enabled text painting.
  *
  * @param label label to process
  * @param g2d graphics context
  * @param text label text
  * @param textX text X coordinate
  * @param textY text Y coordinate
  */
 protected void paintEnabledText(
     final E label, final Graphics2D g2d, final String text, final int textX, final int textY) {
   if (drawShade) {
     g2d.setColor(label.getForeground());
     paintShadowText(g2d, text, textX, textY);
   } else {
     final int mnemIndex = label.getDisplayedMnemonicIndex();
     g2d.setColor(label.getForeground());
     SwingUtils.drawStringUnderlineCharAt(g2d, text, mnemIndex, textX, textY);
   }
 }
 /**
  * Updates painted label layout and returns clipped or full label text.
  *
  * @param label label to process
  * @param fm label font metrics
  * @param width label width
  * @param height label height
  * @return clipped or full label text
  */
 protected String layout(final E label, final FontMetrics fm, final int width, final int height) {
   final Insets insets = label.getInsets(null);
   final String text = label.getText();
   final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
   final Rectangle paintViewR = new Rectangle();
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   return layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);
 }
  @Override
  protected void collectAdditionalElementsToRename(List<Pair<PsiElement, TextRange>> stringUsages) {
    if (isReplaceAllOccurrences()) {
      for (E expression : getOccurrences()) {
        LOG.assertTrue(expression.isValid(), expression.getText());
        stringUsages.add(
            Pair.<PsiElement, TextRange>create(
                expression, new TextRange(0, expression.getTextLength())));
      }
    } else if (getExpr() != null) {
      correctExpression();
      final E expr = getExpr();
      LOG.assertTrue(expr.isValid(), expr.getText());
      stringUsages.add(
          Pair.<PsiElement, TextRange>create(expr, new TextRange(0, expr.getTextLength())));
    }

    final V localVariable = getLocalVariable();
    if (localVariable != null) {
      final PsiElement nameIdentifier = localVariable.getNameIdentifier();
      if (nameIdentifier != null) {
        int length = nameIdentifier.getTextLength();
        stringUsages.add(
            Pair.<PsiElement, TextRange>create(nameIdentifier, new TextRange(0, length)));
      }
    }
  }
 /**
  * Performs disabled text painting.
  *
  * @param label label to process
  * @param g2d graphics context
  * @param text label text
  * @param textX text X coordinate
  * @param textY text Y coordinate
  */
 protected void paintDisabledText(
     final E label, final Graphics2D g2d, final String text, final int textX, final int textY) {
   if (label.isEnabled() && drawShade) {
     g2d.setColor(label.getBackground().darker());
     paintShadowText(g2d, text, textX, textY);
   } else {
     final int accChar = label.getDisplayedMnemonicIndex();
     final Color background = label.getBackground();
     g2d.setColor(background.brighter());
     SwingUtils.drawStringUnderlineCharAt(g2d, text, accChar, textX + 1, textY + 1);
     g2d.setColor(background.darker());
     SwingUtils.drawStringUnderlineCharAt(g2d, text, accChar, textX, textY);
   }
 }
 /**
  * Removes node from tree structure. This method will have effect only if node exists.
  *
  * @param node node to remove
  * @return true if tree structure was changed by the operation, false otherwise
  */
 public boolean removeNode(final E node) {
   final boolean exists = node != null && node.getParent() != null;
   if (exists) {
     getExModel().removeNodeFromParent(node);
   }
   return exists;
 }
 /**
  * Performs label layout and returns clipped or full label text.
  *
  * @param label label to process
  * @param fm label font metrics
  * @param text label text
  * @param icon label icon
  * @param viewR rectangle limited by label insets
  * @param iconR icon rectangle dummy
  * @param textR text rectangle dummy
  * @return clipped or full label text
  */
 protected String layoutCL(
     final E label,
     final FontMetrics fm,
     final String text,
     final Icon icon,
     final Rectangle viewR,
     final Rectangle iconR,
     final Rectangle textR) {
   return SwingUtilities.layoutCompoundLabel(
       label,
       fm,
       text,
       icon,
       label.getVerticalAlignment(),
       label.getHorizontalAlignment(),
       label.getVerticalTextPosition(),
       label.getHorizontalTextPosition(),
       viewR,
       iconR,
       textR,
       label.getIconTextGap());
 }
    public boolean delete(E element) {
      if (root == null) return false;
      TreeNode<E> parent = null;
      TreeNode<E> current = root;
      while (current != null) {
        if (element.compareTo(current.element) < 0) {
          parent = current;
          current = current.left;
        } else if (element.compareTo(current.element) > 0) {
          parent = current;
          current = current.right;
        } else break;
      }
      if (current == null) return false;
      if (current.left == null) {
        if (parent == null) {
          root = current.right;
        } else {
          if (element.compareTo(parent.element) < 0) parent.left = current.right;
          else parent.right = current.right;
          balancePath(parent.element);
        }
      } else {
        TreeNode<E> parentOfRightMost = current;
        TreeNode<E> rightMost = current.left;

        while (rightMost.right != null) {
          parentOfRightMost = rightMost;
          rightMost = rightMost.right;
        }
        current.element = rightMost.element;
        if (parentOfRightMost.right == rightMost) parentOfRightMost.right = rightMost.left;
        else parentOfRightMost.left = rightMost.left;
        balancePath(parentOfRightMost.element);
      }
      size--;
      return true;
    }
 private SelectedElementInfo(@Nullable E element) {
   myElement = element;
   if (myElement != null) {
     //noinspection unchecked
     myCurrentPanel = element.getType().createElementPropertiesPanel(myElement, myContext);
     myPropertiesPanel.removeAll();
     if (myCurrentPanel != null) {
       myPropertiesPanel.add(
           BorderLayout.CENTER,
           ScrollPaneFactory.createScrollPane(myCurrentPanel.createComponent(), true));
       myCurrentPanel.reset();
       myPropertiesPanel.revalidate();
     }
   }
 }
  public boolean startsOnTheSameElement(E expr, V localVariable) {
    if (myExprMarker != null
        && myExprMarker.isValid()
        && expr != null
        && myExprMarker.getStartOffset() == expr.getTextOffset()) {
      return true;
    }

    if (myLocalMarker != null
        && myLocalMarker.isValid()
        && localVariable != null
        && myLocalMarker.getStartOffset() == localVariable.getTextOffset()) {
      return true;
    }
    return isRestart();
  }
Exemple #11
0
  /** {@inheritDoc} */
  @Override
  public Dimension getPreferredSize(final E label) {
    final String text = label.getText();
    final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    final Insets insets = label.getInsets(null);
    final Font font = label.getFont();

    final int dx = insets.left + insets.right;
    final int dy = insets.top + insets.bottom;

    if ((icon == null) && ((text == null) || ((text != null) && (font == null)))) {
      return new Dimension(dx, dy);
    } else if ((text == null) || ((icon != null) && (font == null))) {
      return new Dimension(icon.getIconWidth() + dx, icon.getIconHeight() + dy);
    } else {
      final FontMetrics fm = label.getFontMetrics(font);

      final Rectangle iconR = new Rectangle();
      final Rectangle textR = new Rectangle();
      final Rectangle viewR = new Rectangle();
      iconR.x = iconR.y = iconR.width = iconR.height = 0;
      textR.x = textR.y = textR.width = textR.height = 0;
      viewR.x = dx;
      viewR.y = dy;
      viewR.width = viewR.height = Short.MAX_VALUE;

      layoutCL(label, fm, text, icon, viewR, iconR, textR);

      final int x1 = Math.min(iconR.x, textR.x);
      final int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width);
      final int y1 = Math.min(iconR.y, textR.y);
      final int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height);
      final Dimension rv = new Dimension(x2 - x1, y2 - y1);
      rv.width += dx;
      rv.height += dy;
      return rv;
    }
  }
 @Nullable
 protected String getExpressionText(E expr) {
   return expr != null ? expr.getText() : null;
 }
Exemple #13
0
  /** {@inheritDoc} */
  @Override
  public void paint(final Graphics2D g2d, final Rectangle bounds, final E label) {
    // Applying graphics settings
    final Composite oc = LafUtils.setupAlphaComposite(g2d, transparency, transparency != null);
    final Map textHints =
        drawShade ? StyleConstants.defaultTextRenderingHints : StyleConstants.textRenderingHints;
    final Font oldFont = LafUtils.setupFont(g2d, label.getFont());
    final Map oldHints = SwingUtils.setupTextAntialias(g2d, textHints);

    // Retrieving icon & text
    final String text = label.getText();
    final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    // Painting background
    if (backgroundPainter != null) {
      backgroundPainter.paint(g2d, bounds, label);
    }

    // We don't need to go futher if there is not icon/text
    if (icon == null && text == null) {
      return;
    }

    final FontMetrics fm = label.getFontMetrics(label.getFont());
    final String clippedText = layout(label, fm, label.getWidth(), label.getHeight());

    if (icon != null) {
      icon.paintIcon(label, g2d, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      final View v = (View) label.getClientProperty(BasicHTML.propertyKey);
      if (v != null) {
        // Painting HTML label view
        v.paint(g2d, paintTextR);
      } else {
        // Painting plain label view
        final int textX = paintTextR.x;
        final int textY = paintTextR.y + fm.getAscent();
        if (label.isEnabled()) {
          paintEnabledText(label, g2d, clippedText, textX, textY);
        } else {
          paintDisabledText(label, g2d, clippedText, textX, textY);
        }
      }
    }

    SwingUtils.restoreTextAntialias(g2d, oldHints);
    LafUtils.restoreFont(g2d, oldFont);
    LafUtils.restoreComposite(g2d, oc, transparency != null);
  }
 public void reset() {
   myTitleLabel.setText("'" + myElement.getName() + "' manifest properties:");
   myManifestNotFoundLabel.setText(
       "META-INF/MANIFEST.MF file not found in '" + myElement.getName() + "'");
   updateManifest();
 }