diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java index 02f8772283c8..6f5da6059bef 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java @@ -24,10 +24,12 @@ import com.intellij.remoteServer.runtime.ServerConnection; import com.intellij.remoteServer.runtime.ServerConnectionListener; import com.intellij.remoteServer.runtime.ServerConnectionManager; import com.intellij.ui.*; -import com.intellij.ui.components.JBPanelWithEmptyText; +import com.intellij.ui.components.JBPanel; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.Alarm; import com.intellij.util.ObjectUtils; +import com.intellij.util.ui.JBSwingUtilities; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -64,7 +66,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv private final Tree myTree; private final CardLayout myPropertiesPanelLayout; private final JPanel myPropertiesPanel; - private final JBPanelWithEmptyText myMessagePanel; + private final JBPanelWithHtmlEmptyText myMessagePanel; private final Map myLogComponents = new HashMap<>(); private final DefaultTreeModel myTreeModel; @@ -95,7 +97,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT)); myPropertiesPanelLayout = new CardLayout(); myPropertiesPanel = new JPanel(myPropertiesPanelLayout); - myMessagePanel = new JBPanelWithEmptyText().withEmptyText(EMPTY_SELECTION_MESSAGE); + myMessagePanel = new JBPanelWithHtmlEmptyText().withEmptyText(EMPTY_SELECTION_MESSAGE); myPropertiesPanel.add(MESSAGE_CARD, myMessagePanel); splitter.setSecondComponent(myPropertiesPanel); getMainPanel().add(splitter, BorderLayout.CENTER); @@ -209,8 +211,14 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv } } - private void showMessageLabel(String text) { - myMessagePanel.getEmptyText().setText(text); + private void showMessageLabel(@NotNull String text) { + if (text.contains("
") && !text.startsWith("")) { + String html = "
" + text + "
"; + myMessagePanel.setEmptyText(html); + } + else { + myMessagePanel.setEmptyText(text); + } myPropertiesPanelLayout.show(myPropertiesPanel, MESSAGE_CARD); } @@ -364,4 +372,51 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv return isServerNodeMatch(serverNode, connection) && node.getDeployment().getName().equals(deploymentName); } + + private static class JBPanelWithHtmlEmptyText extends JBPanel { + private final JLabel myLabel = new JLabel(); + + public JBPanelWithHtmlEmptyText withEmptyText(@NotNull String text) { + setEmptyText(text); + return this; + } + + public void setEmptyText(@NotNull String text) { + myLabel.setText(text); + repaint(); + } + + @Override + protected Graphics getComponentGraphics(Graphics graphics) { + return JBSwingUtilities.runGlobalCGTransform(this, super.getComponentGraphics(graphics)); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + if (!UIUtil.uiChildren(this).filter(Component::isVisible).isEmpty()) { + return; + } + + myLabel.setFont(getFont()); + myLabel.setBackground(getBackground()); + myLabel.setForeground(UIUtil.getInactiveTextColor()); + + Rectangle bounds = getBounds(); + Dimension size = myLabel.getPreferredSize(); + myLabel.setBounds(0, 0, size.width, size.height); + + int x = (bounds.width - size.width) / 2; + int y = (bounds.height - size.height) / 3; // above center + + Graphics g2 = g.create(bounds.x + x, bounds.y + y, bounds.width, bounds.height); + try { + myLabel.paint(g2); + } + finally { + g2.dispose(); + } + } + } }