ToggleStateAction extends ToggleAction { @Override public void setSelected(@NotNull AnActionEvent event, boolean selected) { ImageView image = getImageView(); if (image == null) { return; } int[] states = image.getDrawableState(); int state = myState.getIntValue(); if (selected) { assert !Ints.contains(states, state); image.setImageState(ArrayUtil.append(states, state), false); } else { assert Ints.contains(states, state); int i = Ints.indexOf(states, state); image.setImageState(ArrayUtil.remove(states, i), false); } SceneManager manager = mySurface.getSceneManager(); if (manager == null) { return; } manager.requestRender(); } ToggleStateAction(@NotNull State state, @NotNull DesignSurface surface); @Override boolean isSelected(@NotNull AnActionEvent event); @Override void setSelected(@NotNull AnActionEvent event, boolean selected); @Override boolean displayTextInToolbar();  }
@Test public void setSelectedImageIsPressed() { ImageView image = mockImage(new int[]{State.PRESSED.getIntValue()}); ToggleAction action = new ToggleStateAction(State.PRESSED, mockSurface(image)); action.setSelected(new AnActionEvent(null, dataId -> null, "sdsd", action.getTemplatePresentation(), ActionManager.getInstance(), -1), false); Mockito.verify(image).setImageState(new int[0], false); }
@Test public void setSelectedImageIsNotPressed() { ImageView image = mockImage(new int[0]); ToggleAction action = new ToggleStateAction(State.PRESSED, mockSurface(image)); action.setSelected(new AnActionEvent(null, dataId -> null, "sdsd", action.getTemplatePresentation(), ActionManager.getInstance(), -1), true); Mockito.verify(image).setImageState(new int[]{State.PRESSED.getIntValue()}, false); }