Java Code Examples for com.intellij.util.ui.UIUtil#createImage()
The following examples show how to use
com.intellij.util.ui.UIUtil#createImage() .
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: ImageUtils.java From markdown-image-kit with MIT License | 6 votes |
/** * To buffered image buffered image. * * @param src the src * @return the buffered image */ @Nullable public static BufferedImage toBufferedImage(Image src) { if (src instanceof BufferedImage) { return (BufferedImage) src; } int w = src.getWidth(null); int h = src.getHeight(null); if (w < 0 || h < 0) { return null; } // other options int type = BufferedImage.TYPE_INT_ARGB; BufferedImage dest = UIUtil.createImage(w, h, type); Graphics2D g2 = dest.createGraphics(); g2.drawImage(src, 0, 0, null); g2.dispose(); return dest; }
Example 2
Source File: AbstractProjectViewPane.java From consulo with Apache License 2.0 | 6 votes |
@Nullable @Override public Pair<Image, Point> createDraggedImage(DnDAction action, Point dragOrigin, @Nonnull DnDDragStartBean bean) { final TreePath[] paths = getSelectionPaths(); if (paths == null) return null; final int count = paths.length; final JLabel label = new JLabel(String.format("%s item%s", count, count == 1 ? "" : "s")); label.setOpaque(true); label.setForeground(myTree.getForeground()); label.setBackground(myTree.getBackground()); label.setFont(myTree.getFont()); label.setSize(label.getPreferredSize()); final BufferedImage image = UIUtil.createImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D)image.getGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); label.paint(g2); g2.dispose(); return new Pair<>(image, new Point(-image.getWidth(null), -image.getHeight(null))); }
Example 3
Source File: DesktopStripePanelImpl.java From consulo with Apache License 2.0 | 6 votes |
public void processDropButton(final DesktopStripeButton button, JComponent buttonImage, Point screenPoint) { if (!isDroppingButton()) { final BufferedImage image = UIUtil.createImage(button.getWidth(), button.getHeight(), BufferedImage.TYPE_INT_RGB); buttonImage.paint(image.getGraphics()); myDragButton = button; myDragButtonImage = buttonImage; myPrefSize = null; } final Point point = new Point(screenPoint); SwingUtilities.convertPointFromScreen(point, this); myDropRectangle = new Rectangle(point, buttonImage.getSize()); revalidate(); repaint(); }
Example 4
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 5
Source File: SheetController.java From consulo with Apache License 2.0 | 6 votes |
/** * This method is used to show an image during message showing * @return image to show */ Image getStaticImage() { final JFrame myOffScreenFrame = new JFrame() ; myOffScreenFrame.add(mySheetPanel); myOffScreenFrame.getRootPane().setDefaultButton(myDefaultButton); final BufferedImage image = SystemInfo.isJavaVersionAtLeast(7, 0, 0) ? UIUtil.createImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT, BufferedImage.TYPE_INT_ARGB) : GraphicsUtilities.createCompatibleTranslucentImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT); Graphics g = image.createGraphics(); mySheetPanel.paint(g); g.dispose(); myOffScreenFrame.remove(mySheetPanel); myOffScreenFrame.dispose(); return image; }
Example 6
Source File: JBTabsImpl.java From consulo with Apache License 2.0 | 6 votes |
public static Image getComponentImage(TabInfo info) { JComponent cmp = info.getComponent(); BufferedImage img; if (cmp.isShowing()) { final int width = cmp.getWidth(); final int height = cmp.getHeight(); img = UIUtil.createImage(info.getComponent(), width > 0 ? width : 500, height > 0 ? height : 500, BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); cmp.paint(g); } else { img = UIUtil.createImage(info.getComponent(), 500, 500, BufferedImage.TYPE_INT_ARGB); } return img; }
Example 7
Source File: JBTabsImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void setPaintBlocked(boolean blocked, final boolean takeSnapshot) { if (blocked && !myPaintBlocked) { if (takeSnapshot) { if (getWidth() > 0 && getHeight() > 0) { myImage = UIUtil.createImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g = myImage.createGraphics(); super.paint(g); g.dispose(); } } } myPaintBlocked = blocked; if (!myPaintBlocked) { if (myImage != null) { myImage.flush(); } myImage = null; repaint(); } }
Example 8
Source File: JBTabsImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public Image startDropOver(TabInfo tabInfo, RelativePoint point) { myDropInfo = tabInfo; int index = myLayout.getDropIndexFor(point.getPoint(this)); setDropInfoIndex(index); addTab(myDropInfo, index, true, true); TabLabel label = myInfo2Label.get(myDropInfo); Dimension size = label.getPreferredSize(); label.setBounds(0, 0, size.width, size.height); BufferedImage img = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); label.paintOffscreen(g); g.dispose(); relayout(true, false); return img; }
Example 9
Source File: ZoomingDelegate.java From consulo with Apache License 2.0 | 6 votes |
public void magnify(double magnification) { if (myMagnification != magnification) { myMagnification = magnification; if (myCachedImage == null) { Rectangle bounds = myViewportComponent.getBounds(); BufferedImage image = UIUtil.createImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB); Graphics graphics = image.getGraphics(); graphics.setClip(0, 0, bounds.width, bounds.height); myViewportComponent.paint(graphics); myCachedImage = image; } } myViewportComponent.repaint(); }
Example 10
Source File: AbstractWizard.java From consulo with Apache License 2.0 | 6 votes |
public void paintIcon(Graphics g) { if (myIcon == null) { return; } final BufferedImage image = UIUtil.createImage(g, myIcon.getIconWidth(), myIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D gg = image.createGraphics(); myIcon.paintIcon(this, gg, 0, 0); final Rectangle bounds = g.getClipBounds(); int y = myIcon.getIconHeight() - 1; while (y < bounds.y + bounds.height) { g.drawImage(image, bounds.x, y, bounds.x + bounds.width, y + 1, 0, myIcon.getIconHeight() - 1, bounds.width, myIcon.getIconHeight(), this); y++; } g.drawImage(image, 0, 0, this); }
Example 11
Source File: CustomIconLoader.java From intellij-extra-icons-plugin with MIT License | 5 votes |
public static String toBase64(ImageWrapper imageWrapper) { String base64 = null; IconType iconType = imageWrapper.getIconType(); switch (iconType) { case SVG: base64 = Base64.encode(imageWrapper.getImageAsByteArray()); break; case IMG: ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { Image image = imageWrapper.getImage(); if (image instanceof JBHiDPIScaledImage) { image = ((JBHiDPIScaledImage) image).getDelegate(); } if (image instanceof ToolkitImage) { image = ((ToolkitImage) image).getBufferedImage(); } if (!(image instanceof RenderedImage)) { BufferedImage bufferedImage = UIUtil.createImage( GRAPHICS_CFG, image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB, PaintUtil.RoundingMode.ROUND); bufferedImage.getGraphics().drawImage(image, 0, 0, null); image = bufferedImage; } ImageIO.write((RenderedImage) image, "png", outputStream); } catch (IOException ex) { LOGGER.info("Can't load " + iconType + " icon: " + ex.getMessage(), ex); } base64 = Base64.encode(outputStream.toByteArray()); break; } return base64; }
Example 12
Source File: LightToolWindow.java From consulo with Apache License 2.0 | 5 votes |
private static BufferedImage drawToBuffer(boolean active, int height) { final int width = 150; BufferedImage image = UIUtil.createImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); ToolwindowPaintUtil.drawHeader(g, 0, width, height, active, true, false, false); g.dispose(); return image; }
Example 13
Source File: DockManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private MyDragSession(MouseEvent me, @Nonnull DockableContent content) { myWindow = JWindowPopupFactory.getInstance().create(null); myContent = content; Image previewImage = content.getPreviewImage(); double requiredSize = 220; double width = previewImage.getWidth(null); double height = previewImage.getHeight(null); double ratio; if (width > height) { ratio = requiredSize / width; } else { ratio = requiredSize / height; } BufferedImage buffer = UIUtil.createImage(myWindow, (int)width, (int)height, BufferedImage.TYPE_INT_ARGB); buffer.createGraphics().drawImage(previewImage, 0, 0, (int)width, (int)height, null); myDefaultDragImage = buffer.getScaledInstance((int)(width * ratio), (int)(height * ratio), Image.SCALE_SMOOTH); myDragImage = myDefaultDragImage; myWindow.getContentPane().setLayout(new BorderLayout()); myImageContainer = new JLabel(IconUtil.createImageIcon(myDragImage)); myImageContainer.setBorder(new LineBorder(Color.lightGray)); myWindow.getContentPane().add(myImageContainer, BorderLayout.CENTER); setLocationFrom(me); myWindow.setVisible(true); WindowManagerEx.getInstanceEx().setAlphaModeEnabled(myWindow, true); WindowManagerEx.getInstanceEx().setAlphaModeRatio(myWindow, 0.1f); myWindow.getRootPane().putClientProperty("Window.shadow", Boolean.FALSE); }
Example 14
Source File: GraphCommitCellRenderer.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private GraphImage getGraphImage(@Nonnull Collection<? extends PrintElement> printElements) { double maxIndex = getMaxGraphElementIndex(printElements); BufferedImage image = UIUtil.createImage((int)(PaintParameters.getNodeWidth(myGraphTable.getRowHeight()) * (maxIndex + 2)), myGraphTable.getRowHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); myPainter.draw(g2, printElements); int width = (int)(maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight())); return new GraphImage(image, width); }
Example 15
Source File: AWTIconLoaderFacade.java From consulo with Apache License 2.0 | 5 votes |
@Override public Image toImage(Icon icon, @Nullable JBUI.ScaleContext ctx) { if (icon instanceof RetrievableIcon) { icon = ((RetrievableIcon)icon).retrieveIcon(); } if (icon instanceof CachedImageIcon) { icon = ((CachedImageIcon)icon).getRealIcon(ctx); } if (icon instanceof ImageIcon) { return ((ImageIcon)icon).getImage(); } else { BufferedImage image; if (GraphicsEnvironment.isHeadless()) { // for testing purpose image = UIUtil.createImage(ctx, icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB, PaintUtil.RoundingMode.FLOOR); } else { // [tav] todo: match the screen with the provided ctx image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration() .createCompatibleImage(icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT); } Graphics2D g = image.createGraphics(); try { icon.paintIcon(null, g, 0, 0); } finally { g.dispose(); } return image; } }
Example 16
Source File: LoadingDecorator.java From consulo with Apache License 2.0 | 5 votes |
public void setVisible(final boolean visible, boolean takeSnapshot) { if (myVisible == visible) return; if (myVisible && !visible && myCurrentAlpha != -1) return; myVisible = visible; myFadeOutAnimator.reset(); if (myVisible) { setVisible(myVisible); myCurrentAlpha = -1; if (takeSnapshot && getWidth() > 0 && getHeight() > 0) { mySnapshot = UIUtil.createImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); final Graphics2D g = mySnapshot.createGraphics(); myPane.paint(g); final Component opaque = UIUtil.findNearestOpaque(this); mySnapshotBg = opaque != null ? opaque.getBackground() : UIUtil.getPanelBackground(); g.dispose(); } myProgress.resume(); myFadeOutAnimator.suspend(); } else { disposeSnapshot(); myProgress.suspend(); myFadeOutAnimator.resume(); } }
Example 17
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 18
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 19
Source File: AbstractNavBarUI.java From consulo with Apache License 2.0 | 4 votes |
private static BufferedImage drawToBuffer(NavBarItem item, JBUI.ScaleContext ctx, boolean floating, boolean toolbarVisible, boolean selected, NavBarPanel navbar) { int w = item.getWidth(); int h = item.getHeight(); int offset = (w - getDecorationOffset()); int h2 = h / 2; BufferedImage result = UIUtil.createImage(ctx, w, h, BufferedImage.TYPE_INT_ARGB, PaintUtil.RoundingMode.FLOOR); Color defaultBg = UIUtil.isUnderDarcula() ? Gray._100 : JBColor.WHITE; final Paint bg = floating ? defaultBg : null; final Color selection = UIUtil.getListSelectionBackground(true); Graphics2D g2 = result.createGraphics(); g2.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Path2D.Double shape = new Path2D.Double(); shape.moveTo(0, 0); shape.lineTo(offset, 0); shape.lineTo(w, h2); shape.lineTo(offset, h); shape.lineTo(0, h); shape.closePath(); Path2D.Double endShape = new Path2D.Double(); endShape.moveTo(offset, 0); endShape.lineTo(w, 0); endShape.lineTo(w, h); endShape.lineTo(offset, h); endShape.lineTo(w, h2); endShape.closePath(); if (bg != null && toolbarVisible) { g2.setPaint(bg); g2.fill(shape); g2.fill(endShape); } if (selected) { Path2D.Double focusShape = new Path2D.Double(); if (toolbarVisible || floating) { focusShape.moveTo(offset, 0); } else { focusShape.moveTo(0, 0); focusShape.lineTo(offset, 0); } focusShape.lineTo(w - 1, h2); focusShape.lineTo(offset, h - 1); if (!toolbarVisible && !floating) { focusShape.lineTo(0, h - 1); } g2.setColor(selection); if (floating && item.isLastElement()) { g2.fillRect(0, 0, w, h); } else { g2.fill(shape); } } if (item.isNextSelected() && navbar.isFocused()) { g2.setColor(selection); g2.fill(endShape); } if (!item.isLastElement()) { if (!selected && (!navbar.isFocused() | !item.isNextSelected())) { Icon icon = AllIcons.Ide.NavBarSeparator; icon.paintIcon(item, g2, w - icon.getIconWidth() - JBUIScale.scale(1), h2 - icon.getIconHeight() / 2); } } g2.dispose(); return result; }
Example 20
Source File: LoadingIcon.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull static LoadingIcon createEmpty(int width, int height) { return new LoadingIcon(UIUtil.createImage(width, height, Transparency.TRANSLUCENT)); }