KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > merge > builtin > visualizer > GraphicalMergeVisualizer


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.merge.builtin.visualizer;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 //import java.awt.event.ActionListener;
25
import java.io.IOException JavaDoc;
26 import java.io.Serializable JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import org.openide.util.NbBundle;
31 import org.openide.util.WeakListeners;
32 import org.openide.windows.TopComponent;
33
34 import org.netbeans.api.diff.Difference;
35 import org.netbeans.api.diff.StreamSource;
36 import org.netbeans.spi.diff.MergeVisualizer;
37
38 /**
39  * The default graphical visualizer of merge conflicts.
40  *
41  * @author Martin Entlicher
42  */

43 public class GraphicalMergeVisualizer extends MergeVisualizer implements Serializable JavaDoc {
44     
45     private Color JavaDoc colorUnresolvedConflict = new java.awt.Color JavaDoc(255, 160, 180);
46     private Color JavaDoc colorResolvedConflict = new java.awt.Color JavaDoc(180, 255, 180);
47     private Color JavaDoc colorOtherConflict = new java.awt.Color JavaDoc(160, 200, 255);
48     
49     /** The currently opened merge dialog. */
50     private MergeDialogComponent merge;
51     
52     static final long serialVersionUID =-2175410667258166512L;
53     /** Creates a new instance of GraphicalMergeVisualizer */
54     public GraphicalMergeVisualizer() {
55         merge = null;
56         //System.out.println("Created a new GraphicalMergeVisualizer() = "+this);
57
}
58     
59     /**
60      * Get the display name of this merge visualizer.
61      */

62     public String JavaDoc getDisplayName() {
63         return NbBundle.getMessage(GraphicalMergeVisualizer.class, "GraphicalMergeVisualizer.displayName");
64     }
65     
66     /**
67      * Get a short description of this merge visualizer.
68      */

69     public String JavaDoc getShortDescription() {
70         return NbBundle.getMessage(GraphicalMergeVisualizer.class, "GraphicalMergeVisualizer.shortDescription");
71     }
72     
73     /**
74      * Show the visual representation of the merging process of two sources.
75      * The result of the merging process can be saved into a Writer even
76      * before all conflicts are actually resolved.
77      *
78      * @param diffs The list of conflicts.
79      * @param source1 the source of the first file
80      * @param source2 the source of the second file
81      * @param result the information about the result source
82      * @return The Component representing the diff visual representation
83      * or null, when the representation is outside the IDE.
84      * @throws IOException when the reading from input streams fails.
85      */

86     public Component JavaDoc createView(Difference[] diffs, StreamSource source1,
87                                 StreamSource source2, StreamSource result) throws IOException JavaDoc {
88         synchronized (this) {
89             //System.out.println("createView(): merge = "+merge);
90
if (merge == null) {
91                 Set JavaDoc opened = TopComponent.getRegistry().getOpened();
92                 for (Iterator JavaDoc it = opened.iterator(); it.hasNext(); ) {
93                     Object JavaDoc component = it.next();
94                     if (component instanceof MergeDialogComponent) {
95                         merge = (MergeDialogComponent) component;
96                         break;
97                     }
98                 }
99                 if (merge == null) {
100                     merge = new MergeDialogComponent();
101                 }
102             }
103         }
104         if (!merge.isOpened()) merge.open();
105         
106         MergePanel panel = new MergePanel();
107         MergeControl control = new MergeControl(panel);
108         control.initialize(diffs, source1, source2, result,
109                            colorUnresolvedConflict, colorResolvedConflict,
110                            colorOtherConflict);
111         merge.addVetoableChangeListener(WeakListeners.vetoableChange(control, merge));
112         merge.addMergePanel(panel);
113         return merge;
114     }
115     
116     /** Getter for property colorUnresolvedConflict.
117      * @return Value of property colorUnresolvedConflict.
118      */

119     public java.awt.Color JavaDoc getColorUnresolvedConflict() {
120         return colorUnresolvedConflict;
121     }
122     
123     /** Setter for property colorUnresolvedConflict.
124      * @param colorUnresolvedConflict New value of property colorUnresolvedConflict.
125      */

126     public void setColorUnresolvedConflict(java.awt.Color JavaDoc colorUnresolvedConflict) {
127         this.colorUnresolvedConflict = colorUnresolvedConflict;
128     }
129     
130     /** Getter for property colorResolvedConflict.
131      * @return Value of property colorResolvedConflict.
132      */

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

140     public void setColorResolvedConflict(java.awt.Color JavaDoc colorResolvedConflict) {
141         this.colorResolvedConflict = colorResolvedConflict;
142     }
143     
144     /** Getter for property colorOtherConflict.
145      * @return Value of property colorOtherConflict.
146      */

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

154     public void setColorOtherConflict(java.awt.Color JavaDoc colorOtherConflict) {
155         this.colorOtherConflict = colorOtherConflict;
156     }
157     
158 }
159
Popular Tags