2 * Copyright 2004-2005 Alexey Efimov
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.intellij.images.editor.actions;
18 import com.intellij.openapi.actionSystem.AnActionEvent;
19 import com.intellij.openapi.actionSystem.ToggleAction;
20 import com.intellij.openapi.project.DumbAware;
21 import org.intellij.images.editor.ImageEditor;
22 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
23 import org.intellij.images.ui.ImageComponentDecorator;
26 * Toggle grid lines over image.
28 * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
29 * @see ImageEditor#setGridVisible
31 public final class ToggleGridAction extends ToggleAction implements DumbAware {
32 public boolean isSelected(AnActionEvent e) {
33 ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
34 return decorator != null && decorator.isGridVisible();
37 public void setSelected(AnActionEvent e, boolean state) {
38 ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
39 if (decorator != null) {
40 decorator.setGridVisible(state);
44 public void update(final AnActionEvent e) {
46 ImageEditorActionUtil.setEnabled(e);
47 e.getPresentation().setText(isSelected(e) ? "Hide Grid" : "Show Grid");