use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class InspectorTreeMouseListener method calculateTooltip.
private void calculateTooltip(MouseEvent event) {
final Point p = event.getPoint();
final int row = tree.getClosestRowForLocation(p.x, p.y);
final TreeCellRenderer r = tree.getCellRenderer();
if (r == null) {
return;
}
if (row == -1) {
clearTooltip();
return;
}
final TreePath path = tree.getPathForRow(row);
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
lastHover = node;
final Component rComponent = r.getTreeCellRendererComponent(tree, node, tree.isRowSelected(row), tree.isExpanded(row), tree.getModel().isLeaf(node), row, true);
final Rectangle pathBounds = tree.getPathBounds(path);
if (pathBounds == null) {
// Something went wrong and the path isn't really visible.
return;
}
p.translate(-pathBounds.x, -pathBounds.y);
if (rComponent == null) {
clearTooltip();
return;
}
String tooltip = null;
final DiagnosticsTreeCellRenderer renderer = (DiagnosticsTreeCellRenderer) rComponent;
final DiagnosticsNode diagnostic = TreeUtils.maybeGetDiagnostic(node);
if (diagnostic != null) {
if (diagnostic.hasTooltip()) {
tooltip = diagnostic.getTooltip();
}
final Icon icon = renderer.getIconAt(p.x);
if (icon != null) {
if (icon == panel.defaultIcon) {
tooltip = "default value";
}
} else {
if (diagnostic.getShowName()) {
final int fragmentIndex = renderer.findFragmentAt(p.x);
if (fragmentIndex == 0) {
// The name fragment is being hovered over.
// Set property description in tooltip.
// TODO (pq):
// * consider tooltips for values
// * consider rich navigation hovers (w/ styling and navigable docs)
final CompletableFuture<String> propertyDoc = diagnostic.getPropertyDoc();
final String doc = propertyDoc.getNow(null);
if (doc != null) {
tooltip = doc;
} else {
tooltip = "Loading dart docs...";
diagnostic.safeWhenComplete(propertyDoc, (String tip, Throwable th) -> {
if (th != null) {
FlutterUtils.warn(LOG, th);
}
if (lastHover == node) {
// We are still hovering of the same node so show the user the tooltip.
renderer.setToolTipText(tip);
}
});
}
} else {
if (diagnostic.isEnumProperty()) {
// We can display a better tooltip as we have access to introspection
// via the observatory service.
diagnostic.safeWhenComplete(diagnostic.getValueProperties(), (properties, th) -> {
if (properties == null || lastHover != node) {
return;
}
renderer.setToolTipText("Allowed values:\n" + Joiner.on('\n').join(properties.keySet()));
});
} else {
renderer.setToolTipText(diagnostic.getTooltip());
}
}
}
}
}
renderer.setToolTipText(tooltip);
}
use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class InspectorTreeUI method paintHorizontalPartOfLeg.
@Override
protected void paintHorizontalPartOfLeg(final Graphics g, final Rectangle clipBounds, final Insets insets, final Rectangle bounds, final TreePath path, final int row, final boolean isExpanded, final boolean hasBeenExpanded, final boolean isLeaf) {
if (path.getPathCount() < 2) {
// to more of an emphasis of lines for nodes with multiple children.
return;
}
if (path.getPathCount() >= 2) {
final Object treeNode = path.getPathComponent(path.getPathCount() - 2);
if (treeNode instanceof DefaultMutableTreeNode) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode;
if (node.getChildCount() < 2) {
return;
}
}
}
boolean dashed = false;
final DiagnosticsNode diagnosticsNode = maybeGetDiagnostic((DefaultMutableTreeNode) path.getLastPathComponent());
if (diagnosticsNode != null) {
if (diagnosticsNode.isProperty()) {
// as part of ascii art tree display.
return;
}
// nodes are rendered using dashed lines.
if (diagnosticsNode.getStyle() == DiagnosticsTreeStyle.offstage) {
dashed = true;
}
}
final int depth = path.getPathCount() - 1;
if ((depth == 0 || (depth == 1 && !isRootVisible())) && !getShowsRootHandles()) {
return;
}
final int lineY = bounds.y + bounds.height / 2;
final int leafChildLineInset = 4;
if (leftToRight) {
int leftX = bounds.x - getRightChildIndent();
int nodeX = bounds.x - getHorizontalLegBuffer();
leftX = getRowX(row, depth - 1) - getRightChildIndent() + insets.left;
nodeX = isLeaf ? getRowX(row, depth) - leafChildLineInset : getRowX(row, depth - 1);
nodeX += insets.left;
if (clipBounds.intersects(leftX, lineY, nodeX - leftX, 1)) {
g.setColor(JBColor.GRAY);
if (dashed) {
drawDashedHorizontalLine(g, lineY, leftX, nodeX - 1);
} else {
paintHorizontalLine(g, tree, lineY, leftX, nodeX - 1);
}
}
}
// TODO(jacobr): implement RTL case.
}
use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class FlutterConsoleLogManager method handleFlutterErrorEvent.
public void handleFlutterErrorEvent(@NotNull Event event) {
final CompletableFuture<InspectorService.ObjectGroup> objectGroup = getCreateInspectorGroup();
if (objectGroup == null) {
return;
}
try {
final ExtensionData extensionData = event.getExtensionData();
final JsonObject jsonObject = extensionData.getJson().getAsJsonObject();
final DiagnosticsNode diagnosticsNode = new DiagnosticsNode(jsonObject, objectGroup, app, false, null);
// Send analytics for the diagnosticsNode.
if (isFirstErrorForFrame()) {
final String errorId = FlutterErrorHelper.getAnalyticsId(diagnosticsNode);
if (errorId != null) {
FlutterInitializer.getAnalytics().sendEvent("flutter-error", errorId, // Note: this can be null from tests.
app.getProject() == null ? null : FlutterSdk.getFlutterSdk(app.getProject()));
}
}
if (FlutterSettings.getInstance().isShowStructuredErrors()) {
queueLength.incrementAndGet();
queue.add(() -> {
try {
processFlutterErrorEvent(diagnosticsNode);
} catch (Throwable t) {
LOG.warn(t);
} finally {
queueLength.decrementAndGet();
synchronized (queueLength) {
queueLength.notifyAll();
}
}
});
}
} catch (Throwable t) {
LOG.warn(t);
}
}
Aggregations