• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.hierarchyviewerlib.actions;
18 
19 import com.android.ddmuilib.ImageLoader;
20 import com.android.hierarchyviewerlib.HierarchyViewerDirector;
21 
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.swt.widgets.Shell;
27 
28 public class SavePixelPerfectAction extends PixelPerfectEnabledAction implements ImageAction {
29 
30     private static SavePixelPerfectAction sAction;
31 
32     private Image mImage;
33 
34     private Shell mShell;
35 
SavePixelPerfectAction(Shell shell)36     private SavePixelPerfectAction(Shell shell) {
37         super("&Save as PNG");
38         this.mShell = shell;
39         setAccelerator(SWT.MOD1 + 'S');
40         ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class);
41         mImage = imageLoader.loadImage("save.png", Display.getDefault()); //$NON-NLS-1$
42         setImageDescriptor(ImageDescriptor.createFromImage(mImage));
43         setToolTipText("Save the screenshot as a PNG image");
44     }
45 
getAction(Shell shell)46     public static SavePixelPerfectAction getAction(Shell shell) {
47         if (sAction == null) {
48             sAction = new SavePixelPerfectAction(shell);
49         }
50         return sAction;
51     }
52 
53     @Override
run()54     public void run() {
55         HierarchyViewerDirector.getDirector().savePixelPerfect(mShell);
56     }
57 
getImage()58     public Image getImage() {
59         return mImage;
60     }
61 }
62