Graphstream rendering disappears sporadically when displayed in an IntelliJ docked panel

I am integrating graphstream (www.graphstream-project.org) into JetBrains MPS (i.e. IntelliJ). The graphs are displayed in the IntelliJ "tool window" (sidebars, see screenshot).

built in MPS

If the panel is in "floating" mode (not docked), this works without problems (just like when using a streaming stream offline, that is, in a JFrame). But in the "docked" mode (as in the screenshot), the graph disappears in some cases, i.e. The tool window shows an empty white area.

I couldn't reproduce what exactly is causing the problem, but it looks like it's an interface. Sometimes resizing a docked panel or showing a tooltip in some completely unrelated part of IntelliJ triggers a "fade", sometimes not. The graph is always redisplayed if it is focused again (for example, clicking an empty white area).

I feel like this is a bug in IntelliJ, but I would appreciate any ideas how to investigate the problem further (where I could start debugging, etc.).

Code is short version: there is one JPanel

containing an instance DefaultView

created with a graph using Viewer.getDefaultView()

. This is passed to the MPS / IntelliJ API.

Complete code:

// construct the graph
Graph graph = new SingleGraph("Graph");
graph.addAttribute("ui.quality");
graph.addAttribute("ui.antialias");

// ... calls to graph.addNode(), graph.addEdge() to generate some content

// construct Viewer and ViewPanel (ViewPanel extends JPanel)
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
ViewPanel viewPanel = viewer.getDefaultView();

// ViewPanel is added to another JPanel as the latter will include a toolbar later
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, viewPanel);

// The panel is returned to MPS, which uses the IntelliJ API to
// create respective tool window. This part is not under my control.
// If you think it is relevant please mention it.
return panel;

      

/editing:

Upon further investigation of this issue, I discovered that there must be something causing the erroneous behavior. In the beginning everything works fine, but after a while everything behaves strangely and continues to do so until I re-create the IntelliJ tool window. I made a short video clip to illustrate this, see YouTube .

I don't know what the trigger might be. I am guessing there is some race condition / thread related issue.

+3


source to share


1 answer


I could find out that only picture deletion happens if paintComponent()

on thread ViewPanel

is called in context ToolWindowsPane.paintChildren()

. In most cases it paintComponent()

is called differently (fewer methods on the stack, especially none ToolWindowsPane

).

ToolWindowsPane.paintChildren()

seems to be called every time the tooltip is displayed somewhere in IntelliJ for example. So the dirty hack to get around the problem was to implement a custom one ViewPanel

with overridden paintComponent

. It was easy because DefaultView

the data stream could be expanded.



The following code loops through the call hierarchy and issues as needed repaint()

. This solved the problem, but causes additional rendering effort, which however does not seem to be a problem in my case.

public class CustomView extends DefaultView { 

  public CustomView(Viewer viewer, String identifier, GraphRenderer graphRenderer) { 
    super(viewer, identifier, graphRenderer); 
  } 

  @Override 
  public void paintComponent(Graphics g) {  
    StackTraceElement[] stackElements = Thread.currentThread().getStackTrace(); 
    for (int i = 0; i < stackElements.length; i++) { 
      if (stackElements[i].getClassName().equals(ToolWindowsPane.class.getName())) { 
        repaint(); 
        break; 
      } 
    } 
    super.paintComponent(g); 
  } 

}

      

+1


source







All Articles