@Override protected JPanel processFiles(@NotNull List<Element> fileElements, final JPanel context) { final Ref<EditorWindow> windowRef = new Ref<EditorWindow>(); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { windowRef.set(context == null ? createEditorWindow() : findWindowWith(context)); } }); final EditorWindow window = windowRef.get(); LOG.assertTrue(window != null); VirtualFile focusedFile = null; for (int i = 0; i < fileElements.size(); i++) { final Element file = fileElements.get(i); if (i == 0) { EditorTabbedContainer tabbedPane = window.getTabbedPane(); if (tabbedPane != null) { try { int limit = Integer.parseInt( file.getParentElement() .getAttributeValue( JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString(), String.valueOf(JBTabsImpl.DEFAULT_MAX_TAB_WIDTH))); UIUtil.putClientProperty( tabbedPane.getComponent(), JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY, limit); } catch (NumberFormatException e) { // ignore } } } try { final FileEditorManagerImpl fileEditorManager = getManager(); Element historyElement = file.getChild(HistoryEntry.TAG); final HistoryEntry entry = HistoryEntry.createLight(fileEditorManager.getProject(), historyElement); final VirtualFile virtualFile = entry.getFile(); if (virtualFile == null) throw new InvalidDataException("No file exists: " + entry.getFilePointer().getUrl()); Document document = ApplicationManager.getApplication() .runReadAction( new Computable<Document>() { @Override public Document compute() { return virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null; } }); final boolean isCurrentInTab = Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue(); Boolean pin = Boolean.valueOf(file.getAttributeValue(PINNED)); fileEditorManager.openFileImpl4( window, virtualFile, entry, isCurrentInTab, isCurrentInTab, pin, i); if (isCurrentInTab) { focusedFile = virtualFile; } if (document != null) { // This is just to make sure document reference is kept on stack till this point // so that document is available for folding state deserialization in HistoryEntry // constructor // and that document will be created only once during file opening document.putUserData(DUMMY_KEY, null); } updateProgress(); } catch (InvalidDataException e) { if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(e); } } } if (focusedFile != null) { getManager().addSelectionRecord(focusedFile, window); } return window.myPanel; }
@Override public void dispose() { UIUtil.putClientProperty(myScrollBar, BUTTONLESS_SCROLL_BAR_UI_MAXI_THUMB, null); }
@Nullable private Point createToolTipImage(@NotNull KeyType key) { UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, true); Pair<Component, Rectangle> rendererAndBounds = getCellRendererAndBounds(key); UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, null); if (rendererAndBounds == null) return null; JComponent renderer = ObjectUtils.tryCast(rendererAndBounds.first, JComponent.class); if (renderer == null) return null; if (renderer.getClientProperty(DISABLE_EXPANDABLE_HANDLER) != null) return null; if (UIUtil.getClientProperty((JComponent) rendererAndBounds.getFirst(), USE_RENDERER_BOUNDS) == Boolean.TRUE) { rendererAndBounds.getSecond().translate(renderer.getX(), renderer.getY()); rendererAndBounds.getSecond().setSize(renderer.getSize()); } myKeyItemBounds = rendererAndBounds.second; Rectangle cellBounds = myKeyItemBounds; Rectangle visibleRect = getVisibleRect(key); if (cellBounds.y < visibleRect.y) return null; int cellMaxY = cellBounds.y + cellBounds.height; int visMaxY = visibleRect.y + visibleRect.height; if (cellMaxY > visMaxY) return null; int cellMaxX = cellBounds.x + cellBounds.width; int visMaxX = visibleRect.x + visibleRect.width; Point location = new Point(visMaxX, cellBounds.y); SwingUtilities.convertPointToScreen(location, myComponent); Rectangle screen = !Registry.is("ide.expansion.hints.on.all.screens") ? ScreenUtil.getScreenRectangle(location) : ScreenUtil.getAllScreensRectangle(); int borderWidth = isPaintBorder() ? 1 : 0; int width = Math.min(screen.width + screen.x - location.x - borderWidth, cellMaxX - visMaxX); int height = cellBounds.height; if (width <= 0 || height <= 0) return null; Dimension size = getImageSize(width, height); myImage = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = myImage.createGraphics(); g.setClip(null); doFillBackground(height, width, g); g.translate(cellBounds.x - visMaxX, 0); doPaintTooltipImage(renderer, cellBounds, g, key); CustomLineBorder border = null; if (borderWidth > 0) { border = new CustomLineBorder(getBorderColor(), borderWidth, 0, borderWidth, borderWidth); location.y -= borderWidth; size.width += borderWidth; size.height += borderWidth + borderWidth; } g.dispose(); myRendererPane.remove(renderer); myTipComponent.setBorder(border); myTipComponent.setPreferredSize(size); return location; }
TranslucencyThumbPainter(ErrorStripePainter painter, JScrollBar bar) { myPainter = painter; myScrollBar = bar; UIUtil.putClientProperty(myScrollBar, BUTTONLESS_SCROLL_BAR_UI_MAXI_THUMB, this); }
public JBLabel setCopyable(boolean copyable) { if (copyable ^ myEditorPane != null) { if (myEditorPane == null) { final JLabel ellipsisLabel = new JBLabel("..."); myIconLabel = new JLabel(getIcon()); myEditorPane = new JEditorPane() { @Override public void paint(Graphics g) { Dimension size = getSize(); boolean paintEllipsis = getPreferredSize().width > size.width && !myMultiline; if (!paintEllipsis) { super.paint(g); } else { Dimension ellipsisSize = ellipsisLabel.getPreferredSize(); int endOffset = size.width - ellipsisSize.width; try { // do not paint half of the letter endOffset = modelToView(viewToModel(new Point(endOffset, 0)) - 1).x; } catch (BadLocationException ignore) { } Shape oldClip = g.getClip(); g.clipRect(0, 0, endOffset, size.height); super.paint(g); g.setClip(oldClip); g.translate(endOffset, 0); ellipsisLabel.setSize(ellipsisSize); ellipsisLabel.paint(g); g.translate(-endOffset, 0); } } }; myEditorPane.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (myEditorPane == null) return; int caretPosition = myEditorPane.getCaretPosition(); myEditorPane.setSelectionStart(caretPosition); myEditorPane.setSelectionEnd(caretPosition); } }); myEditorPane.setContentType("text/html"); myEditorPane.setEditable(false); myEditorPane.setBackground(UIUtil.TRANSPARENT_COLOR); myEditorPane.setOpaque(false); myEditorPane.setBorder(null); myEditorPane.setText(getText()); checkMultiline(); myEditorPane.setCaretPosition(0); UIUtil.putClientProperty( myEditorPane, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Collections.singleton(ellipsisLabel)); updateStyle(myEditorPane); setLayout(new BorderLayout(getIconTextGap(), 0)); add(myIconLabel, BorderLayout.WEST); add(myEditorPane, BorderLayout.CENTER); } else { removeAll(); myEditorPane = null; myIconLabel = null; } } return this; }