use of com.android.tools.idea.uibuilder.lint.LintAnnotationsModel in project android by JetBrains.
the class DesignSurface method hover.
public void hover(@SwingCoordinate int x, @SwingCoordinate int y) {
ScreenView current = getHoverScreenView(x, y);
for (Layer layer : myLayers) {
if (layer instanceof ConstraintsLayer) {
// For constraint layer, set show on hover if they are above their screen view
ConstraintsLayer constraintsLayer = (ConstraintsLayer) layer;
boolean show = false;
if (constraintsLayer.getScreenView() == current) {
show = true;
}
if (constraintsLayer.isShowOnHover() != show) {
constraintsLayer.setShowOnHover(show);
repaint();
}
} else if (layer instanceof SceneLayer) {
// For constraint layer, set show on hover if they are above their screen view
SceneLayer sceneLayer = (SceneLayer) layer;
boolean show = false;
if (sceneLayer.getScreenView() == current) {
show = true;
}
if (sceneLayer.isShowOnHover() != show) {
sceneLayer.setShowOnHover(show);
repaint();
}
} else if (layer instanceof CanvasResizeLayer) {
if (((CanvasResizeLayer) layer).changeHovering(x, y)) {
repaint();
}
}
}
if (myErrorPanel.isVisible() && myRenderHasProblems) {
// TODO: we should really move this logic into the error panel itself
return;
}
// Currently, we use the hover action only to check whether we need to show a warning.
if (AndroidEditorSettings.getInstance().getGlobalState().isShowLint()) {
ScreenView currentScreenView = getCurrentScreenView();
LintAnnotationsModel lintModel = currentScreenView != null ? currentScreenView.getModel().getLintAnnotationsModel() : null;
if (lintModel != null) {
for (Layer layer : myLayers) {
String tooltip = layer.getTooltip(x, y);
if (tooltip != null) {
JBPopup lintPopup = myLintTooltipPopup.get();
if (lintPopup == null || !lintPopup.isVisible()) {
NlUsageTrackerManager.getInstance(this).logAction(LayoutEditorEvent.LayoutEditorEventType.LINT_TOOLTIP);
LintNotificationPanel lintPanel = new LintNotificationPanel(getCurrentScreenView(), lintModel);
lintPanel.selectIssueAtPoint(Coordinates.getAndroidX(getCurrentScreenView(), x), Coordinates.getAndroidY(getCurrentScreenView(), y));
Point point = new Point(x, y);
SwingUtilities.convertPointToScreen(point, this);
myLintTooltipPopup = new WeakReference<>(lintPanel.showInScreenPosition(myProject, this, point));
}
break;
}
}
}
}
}
use of com.android.tools.idea.uibuilder.lint.LintAnnotationsModel in project android by JetBrains.
the class WarningLayer method getTooltip.
@Nullable
@Override
public String getTooltip(@SwingCoordinate int mx, @SwingCoordinate int my) {
LintAnnotationsModel lintModel = myScreenView.getModel().getLintAnnotationsModel();
if (lintModel == null) {
return null;
}
// linear search through all the components with annotations
for (NlComponent component : myAnnotatedComponents) {
Icon icon = lintModel.getIssueIcon(component);
if (icon == null) {
continue;
}
int x = Coordinates.getSwingX(myScreenView, component.x);
int y = Coordinates.getSwingY(myScreenView, component.y);
int w = Coordinates.getSwingDimension(myScreenView, component.w);
if (mx > (x + w - icon.getIconWidth() - PADDING) && mx < (x + w - PADDING)) {
if (my > (y + PADDING) && my < (y + PADDING + icon.getIconHeight())) {
// TODO: show all messages?
return lintModel.getIssueMessage(component);
}
}
}
return null;
}
use of com.android.tools.idea.uibuilder.lint.LintAnnotationsModel in project android by JetBrains.
the class WarningLayer method paint.
@Override
public void paint(@NotNull Graphics2D gc) {
if (!AndroidEditorSettings.getInstance().getGlobalState().isShowLint()) {
return;
}
myAnnotatedComponents.clear();
LintAnnotationsModel lintModel = myScreenView.getModel().getLintAnnotationsModel();
if (lintModel == null) {
return;
}
for (NlComponent component : lintModel.getComponentsWithIssues()) {
if (!component.isShowing()) {
continue;
}
Icon icon = lintModel.getIssueIcon(component);
if (icon == null) {
continue;
}
int x = Coordinates.getSwingX(myScreenView, component.x);
int y = Coordinates.getSwingY(myScreenView, component.y);
int w = Coordinates.getSwingDimension(myScreenView, component.w);
// buildDisplayList the icon at the top right corner of the component
icon.paintIcon(null, gc, x + w - icon.getIconWidth() - PADDING, y + PADDING);
myAnnotatedComponents.add(component);
}
}
use of com.android.tools.idea.uibuilder.lint.LintAnnotationsModel in project android by JetBrains.
the class LintNotificationAction method actionPerformed.
/** Shows list of warnings/errors */
@Override
public void actionPerformed(AnActionEvent e) {
NlUsageTrackerManager.getInstance(mySurface).logAction(LayoutEditorEvent.LayoutEditorEventType.SHOW_LINT_MESSAGES);
ScreenView screenView = mySurface.getCurrentScreenView();
if (screenView != null) {
LintAnnotationsModel lintModel = screenView.getModel().getLintAnnotationsModel();
if (lintModel != null && lintModel.getIssueCount() > 0) {
LintNotificationPanel notificationPanel = new LintNotificationPanel(screenView, lintModel);
Object source = e.getInputEvent().getSource();
if (source instanceof JComponent) {
notificationPanel.showInBestPositionFor(e.getProject(), (JComponent) source);
} else {
notificationPanel.showInBestPositionFor(e.getProject(), e.getDataContext());
}
}
}
}
use of com.android.tools.idea.uibuilder.lint.LintAnnotationsModel in project android by JetBrains.
the class LintNotificationAction method update.
@Override
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
ScreenView screenView = mySurface.getCurrentScreenView();
int markerCount = 0;
if (screenView != null) {
LintAnnotationsModel lintModel = screenView.getModel().getLintAnnotationsModel();
if (lintModel != null) {
markerCount = lintModel.getIssueCount();
}
}
if (markerCount != myCount) {
myCount = markerCount;
Icon icon;
switch(markerCount) {
case 0:
icon = AndroidIcons.LintNotification.Lint0;
break;
case 1:
icon = AndroidIcons.LintNotification.Lint1;
break;
case 2:
icon = AndroidIcons.LintNotification.Lint2;
break;
case 3:
icon = AndroidIcons.LintNotification.Lint3;
break;
case 4:
icon = AndroidIcons.LintNotification.Lint4;
break;
case 5:
icon = AndroidIcons.LintNotification.Lint5;
break;
case 6:
icon = AndroidIcons.LintNotification.Lint6;
break;
case 7:
icon = AndroidIcons.LintNotification.Lint7;
break;
case 8:
icon = AndroidIcons.LintNotification.Lint8;
break;
case 9:
icon = AndroidIcons.LintNotification.Lint9;
break;
default:
icon = AndroidIcons.LintNotification.Lint9plus;
break;
}
presentation.setIcon(icon);
presentation.setText(markerCount == 0 ? "No Warnings" : "Show Warnings and Errors");
// Leaving action enabled, since the disabled icon currently doesn't look right.
// Instead we check in the action performed method and do nothing if the error count
// is 0.
}
}
Aggregations