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.merge.builtin.visualizer;
043:
044: import java.awt.Color;
045: import java.awt.Component; //import java.awt.event.ActionListener;
046: import java.io.IOException;
047: import java.io.Serializable;
048: import java.util.Iterator;
049: import java.util.Set;
050:
051: import org.openide.util.NbBundle;
052: import org.openide.util.WeakListeners;
053: import org.openide.windows.TopComponent;
054:
055: import org.netbeans.api.diff.Difference;
056: import org.netbeans.api.diff.StreamSource;
057: import org.netbeans.spi.diff.MergeVisualizer;
058:
059: /**
060: * The default graphical visualizer of merge conflicts.
061: *
062: * @author Martin Entlicher
063: */
064: public class GraphicalMergeVisualizer extends MergeVisualizer implements
065: Serializable {
066:
067: private Color colorUnresolvedConflict = new java.awt.Color(255,
068: 160, 180);
069: private Color colorResolvedConflict = new java.awt.Color(180, 255,
070: 180);
071: private Color colorOtherConflict = new java.awt.Color(160, 200, 255);
072:
073: /** The currently opened merge dialog. */
074: private MergeDialogComponent merge;
075:
076: static final long serialVersionUID = -2175410667258166512L;
077:
078: /** Creates a new instance of GraphicalMergeVisualizer */
079: public GraphicalMergeVisualizer() {
080: merge = null;
081: //System.out.println("Created a new GraphicalMergeVisualizer() = "+this);
082: }
083:
084: /**
085: * Get the display name of this merge visualizer.
086: */
087: public String getDisplayName() {
088: return NbBundle.getMessage(GraphicalMergeVisualizer.class,
089: "GraphicalMergeVisualizer.displayName");
090: }
091:
092: /**
093: * Get a short description of this merge visualizer.
094: */
095: public String getShortDescription() {
096: return NbBundle.getMessage(GraphicalMergeVisualizer.class,
097: "GraphicalMergeVisualizer.shortDescription");
098: }
099:
100: /**
101: * Show the visual representation of the merging process of two sources.
102: * The result of the merging process can be saved into a Writer even
103: * before all conflicts are actually resolved.
104: *
105: * @param diffs The list of conflicts.
106: * @param source1 the source of the first file
107: * @param source2 the source of the second file
108: * @param result the information about the result source
109: * @return The Component representing the diff visual representation
110: * or null, when the representation is outside the IDE.
111: * @throws IOException when the reading from input streams fails.
112: */
113: public Component createView(Difference[] diffs,
114: StreamSource source1, StreamSource source2,
115: StreamSource result) throws IOException {
116: synchronized (this ) {
117: //System.out.println("createView(): merge = "+merge);
118: if (merge == null) {
119: Set opened = TopComponent.getRegistry().getOpened();
120: for (Iterator it = opened.iterator(); it.hasNext();) {
121: Object component = it.next();
122: if (component instanceof MergeDialogComponent) {
123: merge = (MergeDialogComponent) component;
124: break;
125: }
126: }
127: if (merge == null) {
128: merge = new MergeDialogComponent();
129: }
130: }
131: }
132: if (!merge.isOpened())
133: merge.open();
134:
135: MergePanel panel = new MergePanel();
136: MergeControl control = new MergeControl(panel);
137: control.initialize(diffs, source1, source2, result,
138: colorUnresolvedConflict, colorResolvedConflict,
139: colorOtherConflict);
140: merge.addVetoableChangeListener(WeakListeners.vetoableChange(
141: control, merge));
142: merge.addMergePanel(panel);
143: return merge;
144: }
145:
146: /** Getter for property colorUnresolvedConflict.
147: * @return Value of property colorUnresolvedConflict.
148: */
149: public java.awt.Color getColorUnresolvedConflict() {
150: return colorUnresolvedConflict;
151: }
152:
153: /** Setter for property colorUnresolvedConflict.
154: * @param colorUnresolvedConflict New value of property colorUnresolvedConflict.
155: */
156: public void setColorUnresolvedConflict(
157: java.awt.Color colorUnresolvedConflict) {
158: this .colorUnresolvedConflict = colorUnresolvedConflict;
159: }
160:
161: /** Getter for property colorResolvedConflict.
162: * @return Value of property colorResolvedConflict.
163: */
164: public java.awt.Color getColorResolvedConflict() {
165: return colorResolvedConflict;
166: }
167:
168: /** Setter for property colorResolvedConflict.
169: * @param colorResolvedConflict New value of property colorResolvedConflict.
170: */
171: public void setColorResolvedConflict(
172: java.awt.Color colorResolvedConflict) {
173: this .colorResolvedConflict = colorResolvedConflict;
174: }
175:
176: /** Getter for property colorOtherConflict.
177: * @return Value of property colorOtherConflict.
178: */
179: public java.awt.Color getColorOtherConflict() {
180: return colorOtherConflict;
181: }
182:
183: /** Setter for property colorOtherConflict.
184: * @param colorOtherConflict New value of property colorOtherConflict.
185: */
186: public void setColorOtherConflict(java.awt.Color colorOtherConflict) {
187: this.colorOtherConflict = colorOtherConflict;
188: }
189:
190: }
|