Home | History | Annotate | Download | only in actions
      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 SaveTreeViewAction extends TreeViewEnabledAction implements ImageAction {
     29 
     30     private static SaveTreeViewAction sAction;
     31 
     32     private Image mImage;
     33 
     34     private Shell mShell;
     35 
     36     private SaveTreeViewAction(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 tree view as a PNG image");
     44     }
     45 
     46     public static SaveTreeViewAction getAction(Shell shell) {
     47         if (sAction == null) {
     48             sAction = new SaveTreeViewAction(shell);
     49         }
     50         return sAction;
     51     }
     52 
     53     @Override
     54     public void run() {
     55         HierarchyViewerDirector.getDirector().saveTreeView(mShell);
     56     }
     57 
     58     @Override
     59     public Image getImage() {
     60         return mImage;
     61     }
     62 }
     63