All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.netbeans.api.diff.Diff Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.netbeans.api.diff;

import java.awt.Component;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;

import org.openide.util.Lookup;

/**
 * This class represents a visual diff presenter, that knows how to compute the
 * differences between files and show them to the user.
 *
 * @author  Martin Entlicher
 */
public abstract class Diff extends Object {

    /**
     * Get the default visual diff presenter.
     */
    public static Diff getDefault() {
        return Lookup.getDefault().lookup(Diff.class);
    }
    
    /**
     * Get all visual diff presenters registered in the system.
     */
    public static Collection getAll() {
        return Lookup.getDefault().lookup(new Lookup.Template(Diff.class)).allInstances();
    }
    
    /**
     * Show the visual representation of the diff between two sources.
     * @param name1 the name of the first source
     * @param title1 the title of the first source
     * @param r1 the first source
     * @param name2 the name of the second source
     * @param title2 the title of the second source
     * @param r2 the second resource compared with the first one.
     * @param MIMEType the mime type of these sources
     * @return The Component representing the diff visual representation
     *         or null, when the representation is outside the IDE.
     * @throws IOException when the reading from input streams fails.
     */
    public abstract Component createDiff(String name1, String title1,
                                         Reader r1, String name2, String title2,
                                         Reader r2, String MIMEType) throws IOException ;
    
    /**
     * Creates single-window diff component that does not include any navigation controls and
     * is controlled programatically via the returned DiffView interface.
     * 

* The StreamSource can be used to save the source content if it's modified * in the view. The view should not allow source modification if StreamSource.createWriter() * returns null. * * @param s1 the first source * @param s2 the second source * @return DiffView controller interface */ public DiffView createDiff(StreamSource s1, StreamSource s2) throws IOException { final Component c = createDiff(s1.getName(), s1.getTitle(), s1.createReader(), s2.getName(), s2.getTitle(), s2.createReader(), s1.getMIMEType()); return new DiffView() { public Component getComponent() { return c; } public int getDifferenceCount() { return 0; } public boolean canSetCurrentDifference() { return false; } public void setCurrentDifference(int diffNo) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } public int getCurrentDifference() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } public javax.swing.JToolBar getToolBar() { return null; } public void addPropertyChangeListener(PropertyChangeListener l) {} public void removePropertyChangeListener(PropertyChangeListener l) {} }; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy