KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > diff > DiffVisualizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.diff;
21
22 import java.awt.Component JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.Reader JavaDoc;
26
27 //import org.openide.util.Lookup;
28

29 import org.netbeans.api.diff.DiffView;
30 import org.netbeans.api.diff.Difference;
31 import org.netbeans.api.diff.StreamSource;
32
33 /**
34  * This class represents a diff visualizer. It's used as a presenter of a visual
35  * representation of the source differences to the user.
36  * <p>The registered Diff Visualizers can be obtained via {@link org.openide.util.Lookup}
37  * (e.g. you can get the default diff provider by
38  * <code>Lookup.getDefault().lookup(DiffVisualizer.class)</code>)
39  *
40  * @author Martin Entlicher
41  */

42 public abstract class DiffVisualizer extends Object JavaDoc {
43
44     /*
45     public static DiffVisualizer getDefault() {
46         return (DiffVisualizer) Lookup.getDefault().lookup(DiffVisualizer.class);
47     }
48      */

49     
50     /**
51      * Show the visual representation of the diff between two sources.
52      * @param diffs The list of differences.
53      * @param name1 the name of the first source
54      * @param title1 the title of the first source
55      * @param r1 the first source
56      * @param name2 the name of the second source
57      * @param title2 the title of the second source
58      * @param r2 the second resource compared with the first one.
59      * @param MIMEType the mime type of these sources
60      * @return The Component representing the diff visual representation
61      * or null, when the representation is outside the IDE.
62      * @throws IOException when the reading from input streams fails.
63      */

64     public abstract Component JavaDoc createView(Difference[] diffs, String JavaDoc name1, String JavaDoc title1,
65                                          Reader JavaDoc r1, String JavaDoc name2, String JavaDoc title2,
66                                          Reader JavaDoc r2, String JavaDoc MIMEType) throws IOException JavaDoc ;
67
68     /**
69      * Creates single-window diff component that does not include any navigation controls and
70      * is controlled programatically via the returned DiffView interface.
71      * <p>
72      * The StreamSource can be used to save the source content if it's modified
73      * in the view. The view should not allow source modification if StreamSource.createWriter()
74      * returns <code>null</code>.
75      *
76      * @param diffs The list of differences.
77      * @param s1 the first source
78      * @param s2 the second source
79      * @return DiffView controller interface
80      *
81      */

82     public DiffView createDiff(Difference[] diffs, StreamSource s1, StreamSource s2) throws IOException JavaDoc {
83         final Component JavaDoc c = createView(diffs, s1.getName(), s1.getTitle(), s1.createReader(),
84                                        s2.getName(), s2.getTitle(), s2.createReader(),
85                                        s1.getMIMEType());
86         final int n = diffs.length;
87         return new DiffView() {
88             
89             public Component JavaDoc getComponent() {
90                 return c;
91             }
92     
93             public int getDifferenceCount() {
94                 return n;
95             }
96     
97             public boolean canSetCurrentDifference() {
98                 return false;
99             }
100
101             public void setCurrentDifference(int diffNo) throws UnsupportedOperationException JavaDoc {
102                 throw new UnsupportedOperationException JavaDoc();
103             }
104     
105             public int getCurrentDifference() throws UnsupportedOperationException JavaDoc {
106                 throw new UnsupportedOperationException JavaDoc();
107             }
108             
109             public javax.swing.JToolBar JavaDoc getToolBar() {
110                 return null;
111             }
112    
113             public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {}
114     
115             public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {}
116     
117         };
118     }
119 }
120
Popular Tags