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.modules.diff.builtin.visualizer;
043:
044: import java.awt.Color;
045: import java.awt.Component;
046: import java.io.Reader;
047: import java.io.Serializable;
048:
049: import org.openide.NotifyDescriptor;
050: import org.openide.util.NbBundle;
051:
052: import org.netbeans.api.diff.Difference;
053: import org.netbeans.spi.diff.DiffVisualizer;
054: import org.openide.DialogDisplayer;
055:
056: /**
057: * The default graphical visualizer of diffs.
058: *
059: * @author Martin Entlicher
060: */
061: public class GraphicalDiffVisualizer extends DiffVisualizer implements
062: Serializable {
063:
064: private Color colorAdded = DiffComponent.COLOR_ADDED;
065: private Color colorMissing = DiffComponent.COLOR_MISSING;
066: private Color colorChanged = DiffComponent.COLOR_CHANGED;
067:
068: static final long serialVersionUID = -1135210647457196211L;
069:
070: /** Creates a new instance of BuiltInDiffVisualizer */
071: public GraphicalDiffVisualizer() {
072: }
073:
074: /**
075: * Get the display name of this diff visualizer.
076: */
077: public String getDisplayName() {
078: return NbBundle.getMessage(GraphicalDiffVisualizer.class,
079: "GraphicalDiffVisualizer.displayName");
080: }
081:
082: /**
083: * Get a short description of this diff visualizer.
084: */
085: public String getShortDescription() {
086: return NbBundle.getMessage(GraphicalDiffVisualizer.class,
087: "GraphicalDiffVisualizer.shortDescription");
088: }
089:
090: /**
091: * Some diff visualizers may have built-in the diff calculation. In such a case
092: * the visualizer does not need any diff provider.
093: * @return true when it relies on differences supplied, false if not.
094: *
095: public boolean needsProvider() {
096: return true;
097: }
098: */
099:
100: /**
101: * Show the visual representation of the diff between two files.
102: * @param diffs The list of differences (instances of {@link Difference}).
103: * may be <code>null</code> in case that it does not need diff provider.
104: * @param fo1 the first FileObject
105: * @param fo2 the second FileObject compared with the first one.
106: * @return The TopComponent representing the diff visual representation
107: * or null, when the representation is outside the IDE.
108: *
109: public Component showDiff(List diffs, FileObject fo1, FileObject fo2) {
110: DiffComponent diff;
111: try {
112: diff = new DiffComponent(diffs, null, fo1.getMIMEType(),
113: fo1.getName(), fo2.getName(),
114: fo1.getPackageNameExt('/', '.'), fo2.getPackageNameExt('/', '.'),
115: new InputStreamReader(fo1.getInputStream()),
116: new InputStreamReader(fo2.getInputStream()));
117: } catch (FileNotFoundException fnfex) {
118: org.openide.TopManager.getDefault().notifyException(fnfex);
119: return null;
120: }
121: return diff;
122: }
123: */
124:
125: /**
126: * Show the visual representation of the diff between two sources.
127: * @param diffs The list of differences (instances of {@link Difference}).
128: * may be <code>null</code> in case that it does not need diff provider.
129: * @param name1 the name of the first source
130: * @param title1 the title of the first source
131: * @param r1 the first source
132: * @param name2 the name of the second source
133: * @param title2 the title of the second source
134: * @param r2 the second resource compared with the first one.
135: * @param MIMEType the mime type of these sources
136: * @return The TopComponent representing the diff visual representation
137: * or null, when the representation is outside the IDE.
138: */
139: public Component createView(Difference[] diffs, String name1,
140: String title1, Reader r1, String name2, String title2,
141: Reader r2, String MIMEType) {
142: if (diffs.length == 0) {
143: DialogDisplayer.getDefault().notify(
144: new NotifyDescriptor.Message(NbBundle.getMessage(
145: GraphicalDiffVisualizer.class,
146: "MSG_NoDifference", name1, name2)));
147: }
148: DiffComponent diff;
149: String componentName = name1;
150: if (name2 != null && name2.length() > 0)
151: componentName = NbBundle.getMessage(
152: GraphicalDiffVisualizer.class,
153: "MSG_TwoFilesDiffTitle", componentName, name2);
154: diff = new DiffComponent(diffs, componentName, MIMEType, name1,
155: name2, title1, title2, r1, r2, new Color[] {
156: colorMissing, colorAdded, colorChanged });
157: return diff;
158: }
159:
160: /** Getter for property colorAdded.
161: * @return Value of property colorAdded.
162: */
163: public java.awt.Color getColorAdded() {
164: return colorAdded;
165: }
166:
167: /** Setter for property colorAdded.
168: * @param colorAdded New value of property colorAdded.
169: */
170: public void setColorAdded(java.awt.Color colorAdded) {
171: this .colorAdded = colorAdded;
172: }
173:
174: /** Getter for property colorMissing.
175: * @return Value of property colorMissing.
176: */
177: public java.awt.Color getColorMissing() {
178: return colorMissing;
179: }
180:
181: /** Setter for property colorMissing.
182: * @param colorMissing New value of property colorMissing.
183: */
184: public void setColorMissing(java.awt.Color colorMissing) {
185: this .colorMissing = colorMissing;
186: }
187:
188: /** Getter for property colorChanged.
189: * @return Value of property colorChanged.
190: */
191: public java.awt.Color getColorChanged() {
192: return colorChanged;
193: }
194:
195: /** Setter for property colorChanged.
196: * @param colorChanged New value of property colorChanged.
197: */
198: public void setColorChanged(java.awt.Color colorChanged) {
199: this.colorChanged = colorChanged;
200: }
201:
202: }
|