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.hierarchyviewer.actions;
     18 
     19 import com.android.ddmuilib.ImageLoader;
     20 import com.android.hierarchyviewer.HierarchyViewerApplication;
     21 import com.android.hierarchyviewerlib.HierarchyViewerDirector;
     22 import com.android.hierarchyviewerlib.actions.ImageAction;
     23 import com.android.hierarchyviewerlib.models.PixelPerfectModel;
     24 import com.android.hierarchyviewerlib.models.PixelPerfectModel.IImageChangeListener;
     25 
     26 import org.eclipse.jface.action.Action;
     27 import org.eclipse.jface.resource.ImageDescriptor;
     28 import org.eclipse.swt.SWT;
     29 import org.eclipse.swt.graphics.Image;
     30 import org.eclipse.swt.widgets.Display;
     31 
     32 public class ShowOverlayAction extends Action implements ImageAction, IImageChangeListener {
     33 
     34     private static ShowOverlayAction sAction;
     35 
     36     private Image mImage;
     37 
     38     private ShowOverlayAction() {
     39         super("Show In &Loupe", Action.AS_CHECK_BOX);
     40         setAccelerator(SWT.MOD1 + 'L');
     41         ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class);
     42         mImage = imageLoader.loadImage("show-overlay.png", Display.getDefault()); //$NON-NLS-1$
     43         setImageDescriptor(ImageDescriptor.createFromImage(mImage));
     44         setToolTipText("Show the overlay in the loupe view");
     45         setEnabled(PixelPerfectModel.getModel().getOverlayImage() != null);
     46         PixelPerfectModel.getModel().addImageChangeListener(this);
     47     }
     48 
     49     public static ShowOverlayAction getAction() {
     50         if (sAction == null) {
     51             sAction = new ShowOverlayAction();
     52         }
     53         return sAction;
     54     }
     55 
     56     @Override
     57     public void run() {
     58         HierarchyViewerApplication.getMainWindow().showOverlayInLoupe(sAction.isChecked());
     59     }
     60 
     61     public Image getImage() {
     62         return mImage;
     63     }
     64 
     65     public void crosshairMoved() {
     66         // pass
     67     }
     68 
     69     public void treeChanged() {
     70         // pass
     71     }
     72 
     73     public void imageChanged() {
     74         // pass
     75     }
     76 
     77     public void imageLoaded() {
     78         Display.getDefault().syncExec(new Runnable() {
     79             public void run() {
     80                 Image overlayImage = PixelPerfectModel.getModel().getOverlayImage();
     81                 setEnabled(overlayImage != null);
     82             }
     83         });
     84     }
     85 
     86     public void overlayChanged() {
     87         Display.getDefault().syncExec(new Runnable() {
     88             public void run() {
     89                 setEnabled(PixelPerfectModel.getModel().getOverlayImage() != null);
     90             }
     91         });
     92     }
     93 
     94     public void overlayTransparencyChanged() {
     95         // pass
     96     }
     97 
     98     public void selectionChanged() {
     99         // pass
    100     }
    101 
    102     public void zoomChanged() {
    103         // pass
    104     }
    105 }
    106