void () { initMnemonics(); initTree(myPsiTree); TreeCellRenderer renderer = myPsiTree.getCellRenderer(); myPsiTree.setCellRenderer((tree, value, selected, expanded, leaf, row, hasFocus) -> { Component c = renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); if (userObject instanceof ViewerNodeDescriptor descriptor) { Object element = descriptor.getElement(); if (c instanceof NodeRenderer nodeRenderer) { nodeRenderer.setToolTipText(getElementDescription(element)); } if (element instanceof PsiElement psiElement && FileContextUtil.getFileContext(psiElement.getContainingFile()) != null || element instanceof ViewerTreeStructure.Inject) { TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT); c.setBackground(attr.getBackgroundColor()); } } } return c; }); myPsiTree.addTreeSelectionListener(new MyPsiTreeSelectionListener()); JPanel panelWrapper = new JPanel(new BorderLayout()); panelWrapper.add(myTabs.getComponent()); myTreeSplit.add(panelWrapper, JSplitPane.RIGHT); JPanel referencesPanel = new JPanel(new BorderLayout()); referencesPanel.add(myRefs); referencesPanel.setBorder(IdeBorderFactory.createBorder()); myTabs.addTab(new TabInfo(referencesPanel).setText(DevPsiViewerBundle.message("tab.title.references"))); myTabs.addTab(new TabInfo(myBlockTree.getComponent()).setText(DevPsiViewerBundle.message("tab.title.block.structure"))); myTabs.addTab(new TabInfo(myStubTree.getComponent()).setText(DevPsiViewerBundle.message("tab.title.stub.structure"))); PsiViewerSettings settings = PsiViewerSettings.getSettings(); int tabIndex = settings.lastSelectedTabIndex; TabInfo defaultInfo = tabIndex < myTabs.getTabCount() ? myTabs.getTabAt(tabIndex) : null; if (defaultInfo != null) { myTabs.select(defaultInfo, false); } myTabs.setSelectionChangeHandler((tab, focus, el) -> { settings.lastSelectedTabIndex = myTabs.getIndexOf(tab); return el.run(); }); GoToListener listener = new GoToListener(); myRefs.addKeyListener(listener); myRefs.addMouseListener(listener); myRefs.getSelectionModel().addListSelectionListener(listener); myRefs.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); PsiElement[] elements = myRefsResolvedCache.get(getPsiElement()); if (elements == null || elements.length <= index || elements[index] == null) { comp.setForeground(JBColor.RED); } return comp; } }); myEditor.getSettings().setFoldingOutlineShown(false); myEditor.getDocument().addDocumentListener(myEditorListener, getDisposable()); myEditor.getSelectionModel().addSelectionListener(myEditorListener); myEditor.getCaretModel().addCaretListener(myEditorListener); FocusTraversalPolicy oldPolicy = getPeer().getWindow().getFocusTraversalPolicy(); getPeer().getWindow().setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() { @Override public Component getInitialComponent(@NotNull Window window) { return myEditor.getComponent(); } }); Disposer.register(getDisposable(), () -> getPeer().getWindow().setFocusTraversalPolicy(oldPolicy)); VirtualFile file = myExternalDocument ? FileDocumentManager.getInstance().getFile(myEditor.getDocument()) : null; Language curLanguage = LanguageUtil.getLanguageForPsi(myProject, file); String type = curLanguage != null ? curLanguage.getDisplayName() : settings.type; PsiViewerSourceWrapper lastUsed = null; mySourceWrappers.addAll(PsiViewerSourceWrapper.getExtensionBasedWrappers()); List<PsiViewerSourceWrapper> fileTypeBasedWrappers = PsiViewerSourceWrapper.getFileTypeBasedWrappers(); for (PsiViewerSourceWrapper wrapper : fileTypeBasedWrappers) { mySourceWrappers.addAll(fileTypeBasedWrappers); if (lastUsed == null && wrapper.getText().equals(type) || curLanguage != null && wrapper.myFileType == curLanguage.getAssociatedFileType()) { lastUsed = wrapper; } } myFileTypeComboBox.setModel(new CollectionComboBoxModel<>(new ArrayList<>(mySourceWrappers), lastUsed)); myFileTypeComboBox.setRenderer(SimpleListCellRenderer.create((label, value, index) -> { if (value != null) { label.setText(value.getText()); label.setIcon(value.getIcon()); } })); ComboboxSpeedSearch search1 = new ComboboxSpeedSearch(myFileTypeComboBox, null) { @Override protected String getElementText(Object element) { return element instanceof PsiViewerSourceWrapper ? ((PsiViewerSourceWrapper)element).getText() : null; } }; search1.setupListeners(); myFileTypeComboBox.addActionListener(__ -> { updateDialectsCombo(null); updateExtensionsCombo(); updateEditor(); }); myDialectComboBox.addActionListener(__ -> updateEditor()); ComboboxSpeedSearch search = new ComboboxSpeedSearch(myDialectComboBox, null) { @Override protected String getElementText(Object element) { return element instanceof Language ? ((Language)element).getDisplayName() : "<default>"; } }; search.setupListeners(); myFileTypeComboBox.addFocusListener(new AutoExpandFocusListener(myFileTypeComboBox)); if (!myExternalDocument && lastUsed == null && !mySourceWrappers.isEmpty()) { myFileTypeComboBox.setSelectedIndex(0); } myDialectComboBox.setRenderer(SimpleListCellRenderer.create(DevPsiViewerBundle.message("label.none"), value -> value.getDisplayName())); myDialectComboBox.addFocusListener(new AutoExpandFocusListener(myDialectComboBox)); myExtensionComboBox.setRenderer(SimpleListCellRenderer.create("", value -> "." + value)); //NON-NLS myExtensionComboBox.addFocusListener(new AutoExpandFocusListener(myExtensionComboBox)); myShowWhiteSpacesBox.addActionListener(__ -> { myTreeStructure.setShowWhiteSpaces(myShowWhiteSpacesBox.isSelected()); myStructureTreeModel.invalidateAsync(); }); myShowTreeNodesCheckBox.addActionListener(__ -> { myTreeStructure.setShowTreeNodes(myShowTreeNodesCheckBox.isSelected()); myStructureTreeModel.invalidateAsync(); }); myShowWhiteSpacesBox.setSelected(settings.showWhiteSpaces); myTreeStructure.setShowWhiteSpaces(settings.showWhiteSpaces); myShowTreeNodesCheckBox.setSelected(settings.showTreeNodes); myTreeStructure.setShowTreeNodes(settings.showTreeNodes); myTextPanel.setLayout(new BorderLayout()); myTextPanel.add(myEditor.getComponent(), BorderLayout.CENTER); updateDialectsCombo(settings.dialect); updateExtensionsCombo(); registerCustomKeyboardActions(); Dimension size = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject); if (size == null) { DimensionService.getInstance().setSize(getDimensionServiceKey(), JBUI.size(800, 600), myProject); } myTextSplit.setDividerLocation(settings.textDividerLocation); myTreeSplit.setDividerLocation(settings.treeDividerLocation); updateEditor(); super.init(); }