1 11 package org.eclipse.compare.internal; 12 13 import java.io.InputStream ; 14 import java.io.IOException ; 15 import java.util.ResourceBundle ; 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 30 public class ImageMergeViewer extends ContentMergeViewer { 31 32 private static final String BUNDLE_NAME= "org.eclipse.compare.internal.ImageMergeViewerResources"; 34 private Object fLeftImage; 35 private Object 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 title= Utilities.getString(getResourceBundle(), "title"); getControl().setData(CompareUI.COMPARE_VIEWER_TITLE, title); 50 } 51 52 protected void updateContent(Object ancestor, Object left, Object 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 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 input) { 77 if (canvas != null) { 78 79 InputStream 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 } 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 } 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 ex) { 112 } 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 |