Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2013 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.ide.eclipse.adt.internal.editors.draw9patch.ui;
     18 
     19 import com.android.ide.eclipse.adt.internal.editors.draw9patch.graphics.NinePatchedImage;
     20 
     21 import org.eclipse.swt.SWT;
     22 import org.eclipse.swt.custom.SashForm;
     23 import org.eclipse.swt.dnd.DND;
     24 import org.eclipse.swt.dnd.DropTarget;
     25 import org.eclipse.swt.dnd.DropTargetListener;
     26 import org.eclipse.swt.dnd.FileTransfer;
     27 import org.eclipse.swt.dnd.Transfer;
     28 import org.eclipse.swt.layout.FillLayout;
     29 import org.eclipse.swt.widgets.Composite;
     30 
     31 /**
     32  * Image editor pane.
     33  */
     34 public class ImageEditorPanel extends Composite implements ImageViewer.UpdateListener,
     35         StatusPanel.StatusChangedListener {
     36 
     37     private static final int WEIGHT_VIEWER = 3;
     38     private static final int WEIGHT_PREVIEW = 1;
     39 
     40     private final ImageViewer mImageViewer;
     41     private final StretchesViewer mStretchesViewer;
     42 
     43     public ImageViewer getImageViewer() {
     44         return mImageViewer;
     45     }
     46 
     47     public ImageEditorPanel(Composite parent, int style) {
     48         super(parent, style);
     49 
     50         setLayout(new FillLayout());
     51         SashForm sashForm = new SashForm(this, SWT.HORIZONTAL);
     52 
     53         mImageViewer = new ImageViewer(sashForm, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
     54         mImageViewer.addUpdateListener(this);
     55 
     56         mStretchesViewer = new StretchesViewer(sashForm, SWT.BORDER);
     57 
     58         sashForm.setWeights(new int[] {
     59                 WEIGHT_VIEWER, WEIGHT_PREVIEW
     60         });
     61     }
     62 
     63     @Override
     64     public void zoomChanged(int zoom) {
     65         mImageViewer.setZoom(zoom);
     66     }
     67 
     68     @Override
     69     public void scaleChanged(int scale) {
     70         mStretchesViewer.setScale(scale);
     71     }
     72 
     73     @Override
     74     public void lockVisibilityChanged(boolean visible) {
     75         mImageViewer.setShowLock(visible);
     76     }
     77 
     78     @Override
     79     public void patchesVisibilityChanged(boolean visible) {
     80         mImageViewer.setShowPatchesArea(visible);
     81     }
     82 
     83     @Override
     84     public void badPatchesVisibilityChanged(boolean visible) {
     85         mImageViewer.setShowBadPatchesArea(visible);
     86     }
     87 
     88     @Override
     89     public void contentAreaVisibilityChanged(boolean visible) {
     90         mStretchesViewer.setShowContentArea(visible);
     91     }
     92 
     93     @Override
     94     public void update(NinePatchedImage image) {
     95         mStretchesViewer.updatePreview(image);
     96     }
     97 }
     98