001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.spi.diff;
043:
044: import java.awt.Component;
045: import java.beans.PropertyChangeListener;
046: import java.io.IOException;
047: import java.io.Reader;
048:
049: //import org.openide.util.Lookup;
050:
051: import org.netbeans.api.diff.DiffView;
052: import org.netbeans.api.diff.Difference;
053: import org.netbeans.api.diff.StreamSource;
054:
055: /**
056: * This class represents a diff visualizer. It's used as a presenter of a visual
057: * representation of the source differences to the user.
058: * <p>The registered Diff Visualizers can be obtained via {@link org.openide.util.Lookup}
059: * (e.g. you can get the default diff provider by
060: * <code>Lookup.getDefault().lookup(DiffVisualizer.class)</code>)
061: *
062: * @author Martin Entlicher
063: */
064: public abstract class DiffVisualizer extends Object {
065:
066: /*
067: public static DiffVisualizer getDefault() {
068: return (DiffVisualizer) Lookup.getDefault().lookup(DiffVisualizer.class);
069: }
070: */
071:
072: /**
073: * Show the visual representation of the diff between two sources.
074: * @param diffs The list of differences.
075: * @param name1 the name of the first source
076: * @param title1 the title of the first source
077: * @param r1 the first source
078: * @param name2 the name of the second source
079: * @param title2 the title of the second source
080: * @param r2 the second resource compared with the first one.
081: * @param MIMEType the mime type of these sources
082: * @return The Component representing the diff visual representation
083: * or null, when the representation is outside the IDE.
084: * @throws IOException when the reading from input streams fails.
085: */
086: public abstract Component createView(Difference[] diffs,
087: String name1, String title1, Reader r1, String name2,
088: String title2, Reader r2, String MIMEType)
089: throws IOException;
090:
091: /**
092: * Creates single-window diff component that does not include any navigation controls and
093: * is controlled programatically via the returned DiffView interface.
094: * <p>
095: * The StreamSource can be used to save the source content if it's modified
096: * in the view. The view should not allow source modification if StreamSource.createWriter()
097: * returns <code>null</code>.
098: *
099: * @param diffs The list of differences.
100: * @param s1 the first source
101: * @param s2 the second source
102: * @return DiffView controller interface
103: *
104: */
105: public DiffView createDiff(Difference[] diffs, StreamSource s1,
106: StreamSource s2) throws IOException {
107: final Component c = createView(diffs, s1.getName(), s1
108: .getTitle(), s1.createReader(), s2.getName(), s2
109: .getTitle(), s2.createReader(), s1.getMIMEType());
110: final int n = diffs.length;
111: return new DiffView() {
112:
113: public Component getComponent() {
114: return c;
115: }
116:
117: public int getDifferenceCount() {
118: return n;
119: }
120:
121: public boolean canSetCurrentDifference() {
122: return false;
123: }
124:
125: public void setCurrentDifference(int diffNo)
126: throws UnsupportedOperationException {
127: throw new UnsupportedOperationException();
128: }
129:
130: public int getCurrentDifference()
131: throws UnsupportedOperationException {
132: throw new UnsupportedOperationException();
133: }
134:
135: public javax.swing.JToolBar getToolBar() {
136: return null;
137: }
138:
139: public void addPropertyChangeListener(
140: PropertyChangeListener l) {
141: }
142:
143: public void removePropertyChangeListener(
144: PropertyChangeListener l) {
145: }
146:
147: };
148: }
149: }
|