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); }
/** * 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); } }
@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))); } } }
@NotNull @Override public String getGroupDisplayName() { if (myEP == null) { return getTool().getGroupDisplayName(); } else { String groupDisplayName = myEP.getGroupDisplayName(); return groupDisplayName == null ? getTool().getGroupDisplayName() : groupDisplayName; } }
@NotNull @Override public String[] getGroupPath() { if (myEP == null) { return getTool().getGroupPath(); } else { String[] path = myEP.getGroupPath(); return path == null ? getTool().getGroupPath() : path; } }
@Override protected URL getDescriptionUrl() { Application app = ApplicationManager.getApplication(); if (myEP == null || app.isUnitTestMode() || app.isHeadlessEnvironment()) { return super.getDescriptionUrl(); } String fileName = getDescriptionFileName(); if (fileName == null) return null; return myEP.getLoaderForClass().getResource("/inspectionDescriptions/" + fileName); }
@NotNull public T getTool() { if (myTool == null) { //noinspection unchecked if (ApplicationManager.getApplication().isUnitTestMode()) { instantated = new Throwable(); } myTool = (T) myEP.instantiateTool(); if (!myTool.getShortName().equals(myEP.getShortName())) { LOG.error( "Short name not matched for " + myTool.getClass() + ": getShortName() = " + myTool.getShortName() + "; ep.shortName = " + myEP.getShortName()); } } return myTool; }
/** * 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; }
protected final boolean areSelectedItemsRemovable(@NotNull ListSelectionModel selectionMode) { int minSelectionIndex = selectionMode.getMinSelectionIndex(); int maxSelectionIndex = selectionMode.getMaxSelectionIndex(); if (minSelectionIndex < 0 || maxSelectionIndex < 0) { return false; } List<T> items = getItems(); for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) { if (itemEditor.isRemovable(items.get(i))) { return true; } } return false; }
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(); }
/** {@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; } }
@NotNull @Override public HighlightDisplayLevel getDefaultLevel() { return myEP == null ? getTool().getDefaultLevel() : myEP.getDefaultLevel(); }
@Nullable protected String getExpressionText(E expr) { return expr != null ? expr.getText() : null; }
@NotNull @Override public String getShortName() { return myEP != null ? myEP.getShortName() : getTool().getShortName(); }
@Override public T createElement() { return ReflectionUtil.newInstance(itemEditor.getItemClass()); }
/** {@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); }
/** * Returns the value currently selected. * * @return the value currently selected */ public E getValue() { ImageIcon icon = (ImageIcon) getSelectedItem(); return E.valueOf(enumeration, icon.getDescription()); }
/** * Sets the value selected. * * @param value the value to make selected */ public void setValue(E value) { ImageIcon icon = icons[value.ordinal()]; setSelectedItem(icon); }
public void reset() { myTitleLabel.setText("'" + myElement.getName() + "' manifest properties:"); myManifestNotFoundLabel.setText( "META-INF/MANIFEST.MF file not found in '" + myElement.getName() + "'"); updateManifest(); }