KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > diff > builtin > visualizer > GraphicalDiffVisualizer


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.modules.diff.builtin.visualizer;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.io.Reader JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.NbBundle;
29
30 import org.netbeans.api.diff.Difference;
31 import org.netbeans.spi.diff.DiffVisualizer;
32 import org.openide.DialogDisplayer;
33
34 /**
35  * The default graphical visualizer of diffs.
36  *
37  * @author Martin Entlicher
38  */

39 public class GraphicalDiffVisualizer extends DiffVisualizer implements Serializable JavaDoc {
40
41     private Color JavaDoc colorAdded = DiffComponent.COLOR_ADDED;
42     private Color JavaDoc colorMissing = DiffComponent.COLOR_MISSING;
43     private Color JavaDoc colorChanged = DiffComponent.COLOR_CHANGED;
44     
45     static final long serialVersionUID =-1135210647457196211L;
46     /** Creates a new instance of BuiltInDiffVisualizer */
47     public GraphicalDiffVisualizer() {
48     }
49     
50     /**
51      * Get the display name of this diff visualizer.
52      */

53     public String JavaDoc getDisplayName() {
54         return NbBundle.getMessage(GraphicalDiffVisualizer.class, "GraphicalDiffVisualizer.displayName");
55     }
56     
57     /**
58      * Get a short description of this diff visualizer.
59      */

60     public String JavaDoc getShortDescription() {
61         return NbBundle.getMessage(GraphicalDiffVisualizer.class, "GraphicalDiffVisualizer.shortDescription");
62     }
63     
64     
65     /**
66      * Some diff visualizers may have built-in the diff calculation. In such a case
67      * the visualizer does not need any diff provider.
68      * @return true when it relies on differences supplied, false if not.
69      *
70     public boolean needsProvider() {
71         return true;
72     }
73      */

74     
75     /**
76      * Show the visual representation of the diff between two files.
77      * @param diffs The list of differences (instances of {@link Difference}).
78      * may be <code>null</code> in case that it does not need diff provider.
79      * @param fo1 the first FileObject
80      * @param fo2 the second FileObject compared with the first one.
81      * @return The TopComponent representing the diff visual representation
82      * or null, when the representation is outside the IDE.
83      *
84     public Component showDiff(List diffs, FileObject fo1, FileObject fo2) {
85         DiffComponent diff;
86         try {
87             diff = new DiffComponent(diffs, null, fo1.getMIMEType(),
88                 fo1.getName(), fo2.getName(),
89                 fo1.getPackageNameExt('/', '.'), fo2.getPackageNameExt('/', '.'),
90                 new InputStreamReader(fo1.getInputStream()),
91                 new InputStreamReader(fo2.getInputStream()));
92         } catch (FileNotFoundException fnfex) {
93             org.openide.TopManager.getDefault().notifyException(fnfex);
94             return null;
95         }
96         return diff;
97     }
98      */

99     
100     /**
101      * Show the visual representation of the diff between two sources.
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 name1 the name of the first source
105      * @param title1 the title of the first source
106      * @param r1 the first source
107      * @param name2 the name of the second source
108      * @param title2 the title of the second source
109      * @param r2 the second resource compared with the first one.
110      * @param MIMEType the mime type of these sources
111      * @return The TopComponent representing the diff visual representation
112      * or null, when the representation is outside the IDE.
113      */

114     public Component JavaDoc createView(Difference[] diffs, String JavaDoc name1, String JavaDoc title1, Reader JavaDoc r1,
115                                 String JavaDoc name2, String JavaDoc title2, Reader JavaDoc r2, String JavaDoc MIMEType) {
116         if (diffs.length == 0) {
117             DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage(GraphicalDiffVisualizer.class, "MSG_NoDifference", name1, name2)));
118         }
119         DiffComponent diff;
120         String JavaDoc componentName = name1;
121         if (name2 != null && name2.length() > 0) componentName = NbBundle.getMessage(
122                 GraphicalDiffVisualizer.class, "MSG_TwoFilesDiffTitle", componentName, name2);
123         diff = new DiffComponent(diffs, componentName, MIMEType,
124             name1, name2, title1, title2, r1, r2,
125             new Color JavaDoc[] { colorMissing, colorAdded, colorChanged });
126         return diff;
127     }
128     
129     /** Getter for property colorAdded.
130      * @return Value of property colorAdded.
131      */

132     public java.awt.Color JavaDoc getColorAdded() {
133         return colorAdded;
134     }
135     
136     /** Setter for property colorAdded.
137      * @param colorAdded New value of property colorAdded.
138      */

139     public void setColorAdded(java.awt.Color JavaDoc colorAdded) {
140         this.colorAdded = colorAdded;
141     }
142     
143     /** Getter for property colorMissing.
144      * @return Value of property colorMissing.
145      */

146     public java.awt.Color JavaDoc getColorMissing() {
147         return colorMissing;
148     }
149     
150     /** Setter for property colorMissing.
151      * @param colorMissing New value of property colorMissing.
152      */

153     public void setColorMissing(java.awt.Color JavaDoc colorMissing) {
154         this.colorMissing = colorMissing;
155     }
156     
157     /** Getter for property colorChanged.
158      * @return Value of property colorChanged.
159      */

160     public java.awt.Color JavaDoc getColorChanged() {
161         return colorChanged;
162     }
163     
164     /** Setter for property colorChanged.
165      * @param colorChanged New value of property colorChanged.
166      */

167     public void setColorChanged(java.awt.Color JavaDoc colorChanged) {
168         this.colorChanged = colorChanged;
169     }
170     
171 }
172
Popular Tags