KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > diff > Diff


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.api.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 import java.util.Collection JavaDoc;
27
28 import org.openide.util.Lookup;
29
30 /**
31  * This class represents a visual diff presenter, that knows how to compute the
32  * differences between files and show them to the user.
33  *
34  * @author Martin Entlicher
35  */

36 public abstract class Diff extends Object JavaDoc {
37
38     /**
39      * Get the default visual diff presenter.
40      */

41     public static Diff getDefault() {
42         return Lookup.getDefault().lookup(Diff.class);
43     }
44     
45     /**
46      * Get all visual diff presenters registered in the system.
47      */

48     public static Collection JavaDoc<? extends Diff> getAll() {
49         return Lookup.getDefault().lookup(new Lookup.Template<Diff>(Diff.class)).allInstances();
50     }
51     
52     /**
53      * Show the visual representation of the diff between two sources.
54      * @param name1 the name of the first source
55      * @param title1 the title of the first source
56      * @param r1 the first source
57      * @param name2 the name of the second source
58      * @param title2 the title of the second source
59      * @param r2 the second resource compared with the first one.
60      * @param MIMEType the mime type of these sources
61      * @return The Component representing the diff visual representation
62      * or null, when the representation is outside the IDE.
63      * @throws IOException when the reading from input streams fails.
64      */

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

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