KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > DiffImage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.internal;
12
13 import org.eclipse.swt.graphics.*;
14
15 import org.eclipse.jface.resource.CompositeImageDescriptor;
16 import org.eclipse.jface.resource.ImageDescriptor;
17
18 /**
19  * Combines an image with an overlay.
20  */

21 public class DiffImage extends CompositeImageDescriptor {
22
23     static final int HEIGHT= 16;
24
25     private Image fBaseImage;
26     private ImageDescriptor fOverlayImage;
27     private int fWidth;
28     private boolean fLeft= true;
29
30     public DiffImage(Image base, ImageDescriptor overlay, int w) {
31         fBaseImage= base;
32         fOverlayImage= overlay;
33         fWidth= w;
34     }
35
36     public DiffImage(Image base, ImageDescriptor overlay, int w, boolean onLeft) {
37         fBaseImage= base;
38         fOverlayImage= overlay;
39         fWidth= w;
40         fLeft= onLeft;
41     }
42
43     protected Point getSize() {
44         return new Point(fWidth, HEIGHT);
45     }
46
47     protected void drawCompositeImage(int width, int height) {
48         if (fLeft) {
49             if (fBaseImage != null) {
50                 ImageData base= fBaseImage.getImageData();
51                 if (base == null)
52                     base= DEFAULT_IMAGE_DATA;
53                 drawImage(base, fWidth - base.width, 0);
54             }
55     
56             if (fOverlayImage != null) {
57                 ImageData overlay= fOverlayImage.getImageData();
58                 if (overlay == null)
59                     overlay= DEFAULT_IMAGE_DATA;
60                 drawImage(overlay, 0, (HEIGHT - overlay.height) / 2);
61             }
62         } else {
63             if (fBaseImage != null) {
64                 ImageData base= fBaseImage.getImageData();
65                 if (base == null)
66                     base= DEFAULT_IMAGE_DATA;
67                 drawImage(base, 0, 0);
68             }
69     
70             if (fOverlayImage != null) {
71                 ImageData overlay= fOverlayImage.getImageData();
72                 if (overlay == null)
73                     overlay= DEFAULT_IMAGE_DATA;
74                 drawImage(overlay, fWidth - overlay.width, (HEIGHT - overlay.height) / 2);
75             }
76         }
77     }
78 }
79
Popular Tags