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.hierarchyviewerlib.actions;
18
19import com.android.ddmuilib.ImageLoader;
20import com.android.hierarchyviewerlib.HierarchyViewerDirector;
21
22import org.eclipse.jface.resource.ImageDescriptor;
23import org.eclipse.swt.SWT;
24import org.eclipse.swt.graphics.Image;
25import org.eclipse.swt.widgets.Display;
26import org.eclipse.swt.widgets.Shell;
27
28public class CapturePSDAction extends TreeViewEnabledAction implements ImageAction {
29
30    private static CapturePSDAction sAction;
31
32    private Image mImage;
33
34    private Shell mShell;
35
36    private CapturePSDAction(Shell shell) {
37        super("&Capture Layers");
38        this.mShell = shell;
39        setAccelerator(SWT.MOD1 + 'C');
40        ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class);
41        mImage = imageLoader.loadImage("capture-psd.png", Display.getDefault()); //$NON-NLS-1$
42        setImageDescriptor(ImageDescriptor.createFromImage(mImage));
43        setToolTipText("Capture the window layers as a photoshop document");
44    }
45
46    public static CapturePSDAction getAction(Shell shell) {
47        if (sAction == null) {
48            sAction = new CapturePSDAction(shell);
49        }
50        return sAction;
51    }
52
53    @Override
54    public void run() {
55        HierarchyViewerDirector.getDirector().capturePSD(mShell);
56    }
57
58    @Override
59    public Image getImage() {
60        return mImage;
61    }
62}
63