KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.InputStream JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.util.ResourceBundle JavaDoc;
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.SWTException;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.core.runtime.CoreException;
24
25 import org.eclipse.compare.*;
26 import org.eclipse.compare.contentmergeviewer.ContentMergeViewer;
27
28 /**
29  */

30 public class ImageMergeViewer extends ContentMergeViewer {
31     
32     private static final String JavaDoc BUNDLE_NAME= "org.eclipse.compare.internal.ImageMergeViewerResources"; //$NON-NLS-1$
33

34     private Object JavaDoc fLeftImage;
35     private Object JavaDoc fRightImage;
36
37     private ImageCanvas fAncestor;
38     private ImageCanvas fLeft;
39     private ImageCanvas fRight;
40     
41             
42     public ImageMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
43         super(styles, ResourceBundle.getBundle(BUNDLE_NAME), mp);
44
45         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICompareContextIds.IMAGE_COMPARE_VIEW);
46
47         buildControl(parent);
48         String JavaDoc title= Utilities.getString(getResourceBundle(), "title"); //$NON-NLS-1$
49
getControl().setData(CompareUI.COMPARE_VIEWER_TITLE, title);
50     }
51
52     protected void updateContent(Object JavaDoc ancestor, Object JavaDoc left, Object JavaDoc right) {
53         
54         setInput(fAncestor, ancestor);
55         
56         fLeftImage= left;
57         setInput(fLeft, left);
58         
59         fRightImage= right;
60         setInput(fRight, right);
61     }
62     
63     /*
64      * We can't modify the contents of either side we just return null.
65      */

66     protected byte[] getContents(boolean left) {
67         return null;
68     }
69     
70     public void createControls(Composite composite) {
71         fAncestor= new ImageCanvas(composite, SWT.NO_FOCUS);
72         fLeft= new ImageCanvas(composite, SWT.NO_FOCUS);
73         fRight= new ImageCanvas(composite, SWT.NO_FOCUS);
74     }
75
76     private static void setInput(ImageCanvas canvas, Object JavaDoc input) {
77         if (canvas != null) {
78
79             InputStream JavaDoc stream= null;
80             if (input instanceof IStreamContentAccessor) {
81                 IStreamContentAccessor sca= (IStreamContentAccessor) input;
82                 if (sca != null) {
83                     try {
84                         stream= sca.getContents();
85                     } catch (CoreException ex) {
86                         // NeedWork
87
}
88                 }
89             }
90             
91             Image image= null;
92             Display display= canvas.getDisplay();
93             if (stream != null) {
94                 try {
95                     image= new Image(display, stream);
96                 } catch (SWTException ex) {
97                     // silently ignored
98
}
99             }
100
101             canvas.setImage(image);
102             if (image != null) {
103                 canvas.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
104             } else {
105                 canvas.setBackground(null);
106             }
107             
108             if (stream != null) {
109                 try {
110                     stream.close();
111                 } catch (IOException JavaDoc ex) {
112                     // silently ignored
113
}
114             }
115         }
116     }
117     
118     protected void handleResizeAncestor(int x, int y, int width, int height) {
119         if (width > 0) {
120             fAncestor.setVisible(true);
121             fAncestor.setBounds(x, y, width, height);
122         } else {
123             fAncestor.setVisible(false);
124         }
125     }
126
127     protected void handleResizeLeftRight(int x, int y, int width1, int centerWidth, int width2, int height) {
128         fLeft.setBounds(x, y, width1, height);
129         fRight.setBounds(x+width1+centerWidth, y, width2, height);
130     }
131     
132     protected void copy(boolean leftToRight) {
133         if (leftToRight) {
134             fRightImage= fLeftImage;
135             setInput(fRight, fRightImage);
136             setRightDirty(true);
137         } else {
138             fLeftImage= fRightImage;
139             setInput(fLeft, fLeftImage);
140             setLeftDirty(true);
141         }
142     }
143 }
144
145
Popular Tags