ShowOverlayAction.java revision 97b0639645d9c387cdd9884272e053c467a240da
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.hierarchyviewer.actions;
18
19import com.android.ddmuilib.ImageLoader;
20import com.android.hierarchyviewer.HierarchyViewerApplication;
21import com.android.hierarchyviewerlib.HierarchyViewerDirector;
22
23import org.eclipse.jface.action.Action;
24import org.eclipse.jface.resource.ImageDescriptor;
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.graphics.Image;
27import org.eclipse.swt.widgets.Display;
28
29public class ShowOverlayAction extends Action implements ImageAction {
30
31    private static ShowOverlayAction action;
32
33    private Image image;
34
35    private ShowOverlayAction() {
36        super("Show In &Loupe", Action.AS_CHECK_BOX);
37        setAccelerator(SWT.MOD1 + 'L');
38        ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class);
39        image = imageLoader.loadImage("show-overlay.png", Display.getDefault());
40        setImageDescriptor(ImageDescriptor.createFromImage(image));
41        setToolTipText("Show the overlay in the loupe view");
42    }
43
44    public static ShowOverlayAction getAction() {
45        if (action == null) {
46            action = new ShowOverlayAction();
47        }
48        return action;
49    }
50
51    @Override
52    public void run() {
53        HierarchyViewerApplication.getApp().showOverlayInLoupe(action.isChecked());
54    }
55
56    public Image getImage() {
57        return image;
58    }
59}
60