Java Code Examples for com.intellij.util.ui.UIUtil#drawImage()
The following examples show how to use
com.intellij.util.ui.UIUtil#drawImage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphCommitCellRenderer.java From consulo with Apache License 2.0 | 6 votes |
@Override public void paintComponent(Graphics g) { super.paintComponent(g); int graphImageWidth = myGraphImage.getWidth(); if (!myReferencePainter.isLeftAligned()) { int start = Math.max(graphImageWidth, getWidth() - myReferencePainter.getSize().width); myReferencePainter.paint((Graphics2D)g, start, 0, getHeight()); } else { myReferencePainter.paint((Graphics2D)g, graphImageWidth, 0, getHeight()); } UIUtil.drawImage(g, myGraphImage.getImage(), 0, 0, null); }
Example 2
Source File: DesktopCanvasImageImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void paintIcon(Component c, Graphics g, int x, int y) { float current = JBUI.sysScale((Graphics2D)g); float old = myScaleFactor; if(current != old) { myScaleFactor = current; myImage = null; } if (myImage == null) { BufferedImage image = UIUtil.createImage(g, myWidth, myHeight, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); GraphicsUtil.setupAAPainting(graphics); DesktopCanvas2DImpl canvas2D = new DesktopCanvas2DImpl((Graphics2D)graphics); myCanvas2DConsumer.accept(canvas2D); myImage = image; } UIUtil.drawImage(g, myImage, x, y, c); }
Example 3
Source File: GlassPaneDialogWrapperPeer.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void paintComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D)g; if (shadow != null) { UIUtil.drawImage(g2, shadow, 0, 0, null); } super.paintComponent(g); }
Example 4
Source File: ImmediatePainter.java From consulo with Apache License 2.0 | 5 votes |
private void paintWithDoubleBuffering(final Graphics2D graphics, final Consumer<? super Graphics2D> painter) { final Rectangle bounds = graphics.getClipBounds(); createOrUpdateImageBuffer(myEditor.getComponent(), graphics, bounds.getSize()); UIUtil.useSafely(myImage.getGraphics(), imageGraphics -> { imageGraphics.translate(-bounds.x, -bounds.y); painter.consume(imageGraphics); }); UIUtil.drawImage(graphics, myImage, bounds.x, bounds.y, null); }
Example 5
Source File: NotificationBalloonShadowBorderProvider.java From consulo with Apache License 2.0 | 5 votes |
private static void drawLine(@Nonnull JComponent component, @Nonnull Graphics g, @Nonnull Icon icon, int fullLength, int start, int end, int step, int start2, boolean horizontal) { int length = fullLength - start - end; int count = length / step; int calcLength = step * count; int lastValue = start + calcLength; if (horizontal) { for (int i = start; i < lastValue; i += step) { icon.paintIcon(component, g, i, start2); } } else { for (int i = start; i < lastValue; i += step) { icon.paintIcon(component, g, start2, i); } } if (calcLength < length) { ImageIcon imageIcon = (ImageIcon)IconLoader.getIconSnapshot(icon); if (horizontal) { UIUtil.drawImage(g, imageIcon.getImage(), new Rectangle(lastValue, start2, length - calcLength, imageIcon.getIconHeight()), new Rectangle(0, 0, length - calcLength, imageIcon.getIconHeight()), component); } else { UIUtil.drawImage(g, imageIcon.getImage(), new Rectangle(start2, lastValue, imageIcon.getIconWidth(), length - calcLength), new Rectangle(0, 0, imageIcon.getIconWidth(), length - calcLength), component); } } }
Example 6
Source File: LabelIcon.java From consulo with Apache License 2.0 | 4 votes |
@Override public void paintIcon(Component c, Graphics g, int x, int y) { UIUtil.drawImage(g, myImage, x, y, null); }
Example 7
Source File: DesktopEditorErrorPanelUI.java From consulo with Apache License 2.0 | 4 votes |
@Override public void paint(Graphics g, JComponent c) { Rectangle componentBounds = c.getBounds(); ProperTextRange docRange = ProperTextRange.create(0, componentBounds.height); if (myCachedTrack == null || myCachedHeight != componentBounds.height) { myCachedTrack = UIUtil.createImage(c, componentBounds.width, componentBounds.height, BufferedImage.TYPE_INT_ARGB); myCachedHeight = componentBounds.height; myDirtyYPositions = docRange; paintBackground(myCachedTrack.getGraphics(), new Rectangle(0, 0, componentBounds.width, componentBounds.height)); } if (myDirtyYPositions == WHOLE_DOCUMENT) { myDirtyYPositions = docRange; } if (myDirtyYPositions != null) { final Graphics2D imageGraphics = myCachedTrack.createGraphics(); ((ApplicationEx2)Application.get()).editorPaintStart(); try { myDirtyYPositions = myDirtyYPositions.intersection(docRange); if (myDirtyYPositions == null) myDirtyYPositions = docRange; repaint(imageGraphics, componentBounds.width, myDirtyYPositions); myDirtyYPositions = null; } finally { ((ApplicationEx2)Application.get()).editorPaintFinish(); } } UIUtil.drawImage(g, myCachedTrack, null, 0, 0); if(myPanel.isSmallIconVisible()) { ErrorStripeRenderer errorStripeRenderer = myPanel.getMarkupModel().getErrorStripeRenderer(); if (errorStripeRenderer != null) { errorStripeRenderer.paint(c, g, new Rectangle(JBUI.scale(2), JBUI.scale(2), errorStripeRenderer.getSquareSize(), errorStripeRenderer.getSquareSize())); } } }
Example 8
Source File: EditorFragmentComponent.java From consulo with Apache License 2.0 | 4 votes |
private void doInit(Component anchorComponent, EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) { boolean newRendering = editor instanceof DesktopEditorImpl; int savedScrollOffset = newRendering ? 0 : editor.getScrollingModel().getHorizontalScrollOffset(); FoldingModelEx foldingModel = editor.getFoldingModel(); boolean isFoldingEnabled = foldingModel.isFoldingEnabled(); if (!showFolding) { foldingModel.setFoldingEnabled(false); } int textImageWidth; int markersImageWidth; int textImageHeight; BufferedImage textImage; BufferedImage markersImage; JComponent rowHeader; try { Document doc = editor.getDocument(); int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(Math.max(0, endLine - 1)) : doc.getTextLength(); int widthAdjustment = newRendering ? EditorUtil.getSpaceWidth(Font.PLAIN, editor) : 0; textImageWidth = Math.min(editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset) + widthAdjustment, getWidthLimit(editor)); Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0)); Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0)); int y1 = p1.y; int y2 = p2.y; textImageHeight = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1; LOG.assertTrue(textImageHeight > 0, "Height: " + textImageHeight + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2); if (savedScrollOffset > 0) { editor.getScrollingModel().scrollHorizontally(0); } textImage = UIUtil.createImage(anchorComponent == null ? editor.getContentComponent() : anchorComponent, textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB); Graphics textGraphics = textImage.getGraphics(); EditorUIUtil.setupAntialiasing(textGraphics); if (showGutter) { rowHeader = editor.getGutterComponentEx(); markersImageWidth = Math.max(1, rowHeader.getWidth()); markersImage = UIUtil.createImage(editor.getComponent(), markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB); Graphics markerGraphics = markersImage.getGraphics(); EditorUIUtil.setupAntialiasing(markerGraphics); markerGraphics.translate(0, -y1); markerGraphics.setClip(0, y1, rowHeader.getWidth(), textImageHeight); markerGraphics.setColor(getBackgroundColor(editor)); markerGraphics.fillRect(0, y1, rowHeader.getWidth(), textImageHeight); rowHeader.paint(markerGraphics); } else { markersImageWidth = 0; rowHeader = null; markersImage = null; } textGraphics.translate(0, -y1); textGraphics.setClip(0, y1, textImageWidth, textImageHeight); boolean wasVisible = editor.setCaretVisible(false); editor.getContentComponent().paint(textGraphics); if (wasVisible) { editor.setCaretVisible(true); } } finally { if (!showFolding) { foldingModel.setFoldingEnabled(isFoldingEnabled); } } if (savedScrollOffset > 0) { editor.getScrollingModel().scrollHorizontally(savedScrollOffset); } JComponent component = new JComponent() { @Override public Dimension getPreferredSize() { return new Dimension(textImageWidth + markersImageWidth, textImageHeight); } @Override protected void paintComponent(Graphics graphics) { if (markersImage != null) { UIUtil.drawImage(graphics, markersImage, 0, 0, null); UIUtil.drawImage(graphics, textImage, rowHeader.getWidth(), 0, null); } else { UIUtil.drawImage(graphics, textImage, 0, 0, null); } } }; setLayout(new BorderLayout()); add(component); setBorder(createEditorFragmentBorder(editor)); }
Example 9
Source File: AbstractExpandableItemsHandler.java From consulo with Apache License 2.0 | 4 votes |
@Override protected void paintComponent(Graphics g) { Insets insets = getInsets(); UIUtil.drawImage(g, myImage, insets.left, insets.top, null); }
Example 10
Source File: AbstractNavBarUI.java From consulo with Apache License 2.0 | 4 votes |
@Override public void doPaintNavBarItem(Graphics2D g, NavBarItem item, NavBarPanel navbar) { final boolean floating = navbar.isInFloatingMode(); boolean toolbarVisible = UISettings.getInstance().getShowMainToolbar(); final boolean selected = item.isSelected() && item.isFocused(); boolean nextSelected = item.isNextSelected() && navbar.isFocused(); ImageType type; if (floating) { type = selected ? ImageType.ACTIVE_FLOATING : nextSelected ? ImageType.NEXT_ACTIVE_FLOATING : ImageType.INACTIVE_FLOATING; } else { if (toolbarVisible) { type = selected ? ImageType.ACTIVE : nextSelected ? ImageType.NEXT_ACTIVE : ImageType.INACTIVE; } else { type = selected ? ImageType.ACTIVE_NO_TOOLBAR : nextSelected ? ImageType.NEXT_ACTIVE_NO_TOOLBAR : ImageType.INACTIVE_NO_TOOLBAR; } } // see: https://github.com/JetBrains/intellij-community/pull/1111 Map<ImageType, JBUI.ScaleContext.Cache<BufferedImage>> cache = myCache.computeIfAbsent(item, k -> new HashMap<>()); JBUI.ScaleContext.Cache<BufferedImage> imageCache = cache.computeIfAbsent(type, k -> new JBUI.ScaleContext.Cache<>((ctx) -> drawToBuffer(item, ctx, floating, toolbarVisible, selected, navbar))); BufferedImage image = imageCache.getOrProvide(JBUI.ScaleContext.create(g)); if (image == null) return; UIUtil.drawImage(g, image, 0, 0, null); final int offset = item.isFirstElement() ? getFirstElementLeftOffset() : 0; int textOffset = getElementPadding().width() + offset; if (item.needPaintIcon()) { Icon icon = item.getIcon(); if (icon != null) { int iconOffset = getElementPadding().left + offset; icon.paintIcon(item, g, iconOffset, (item.getHeight() - icon.getIconHeight()) / 2); textOffset += icon.getIconWidth(); } } item.doPaintText(g, textOffset); }