Source Code Cross Referenced for MergePanel.java in  » IDE-Netbeans » diff » org » netbeans » modules » merge » builtin » visualizer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » diff » org.netbeans.modules.merge.builtin.visualizer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.merge.builtin.visualizer;
0043:
0044:        import java.awt.event.ActionEvent;
0045:        import java.awt.event.ActionListener;
0046:        import java.awt.event.FocusEvent;
0047:        import java.awt.event.FocusListener;
0048:        import java.awt.Dimension;
0049:        import java.beans.PropertyChangeEvent;
0050:        import java.beans.PropertyChangeListener;
0051:        import java.util.*;
0052:        import java.io.*;
0053:        import javax.swing.*;
0054:        import javax.swing.text.*;
0055:        import org.netbeans.modules.diff.builtin.visualizer.*;
0056:
0057:        import org.openide.actions.CopyAction;
0058:        import org.openide.actions.SaveAction;
0059:        import org.openide.util.actions.ActionPerformer;
0060:        import org.openide.util.actions.CallbackSystemAction;
0061:        import org.openide.util.actions.SystemAction;
0062:
0063:        import org.netbeans.modules.diff.builtin.visualizer.LinesComponent;
0064:        import org.netbeans.editor.EditorUI;
0065:        import org.netbeans.editor.ext.ExtCaret;
0066:        import org.openide.text.CloneableEditorSupport;
0067:
0068:        /**
0069:         * This class displays two editor panes with two files and marks the differences
0070:         * by a different color.
0071:         * @author  Martin Entlicher
0072:         */
0073:        public class MergePanel extends javax.swing.JPanel implements 
0074:                java.awt.event.ActionListener, javax.swing.event.CaretListener {
0075:
0076:            public static final String ACTION_FIRST_CONFLICT = "firstConflict"; // NOI18N
0077:            public static final String ACTION_LAST_CONFLICT = "lastConflict"; // NOI18N
0078:            public static final String ACTION_PREVIOUS_CONFLICT = "previousConflict"; // NOI18N
0079:            public static final String ACTION_NEXT_CONFLICT = "nextConflict"; // NOI18N
0080:            public static final String ACTION_ACCEPT_RIGHT = "acceptRight"; // NOI18N
0081:            //public static final String ACTION_ACCEPT_RIGHT_AND_NEXT = "acceptRightAndNext"; // NOI18N
0082:            public static final String ACTION_ACCEPT_LEFT = "acceptLeft"; // NOI18N
0083:            //public static final String ACTION_ACCEPT_LEFT_AND_NEXT = "acceptLeftAndNext"; // NOI18N
0084:
0085:            public static final String PROP_CAN_BE_SAVED = "canBeSaved"; // NOI18N
0086:            public static final String PROP_CAN_NOT_BE_SAVED = "canNotBeSaved"; // NOI18N
0087:
0088:            //    private AbstractDiff diff = null;
0089:            private int totalHeight = 0;
0090:            private int totalLines = 0;
0091:
0092:            private int horizontalScroll1ChangedValue = -1;
0093:            private int horizontalScroll2ChangedValue = -1;
0094:            private int horizontalScroll3ChangedValue = -1;
0095:            private int verticalScroll1ChangedValue = -1;
0096:            private int verticalScroll3ChangedValue = -1;
0097:
0098:            private LinesComponent linesComp1;
0099:            private LinesComponent linesComp2;
0100:            private LinesComponent linesComp3;
0101:
0102:            /**
0103:             * Line numbers in the result document. The indexes are "physical" document line numbers,
0104:             * and values are "logical" document line numbers. If there is a space inserted (a conflict),
0105:             * the corresponding document content is not defined and logical document line numbers
0106:             * do not grow.
0107:             * If the conflict starts from the beginning of the file, the logical line numbers are '0',
0108:             * if the conflict is in the middle of the file, the logical line numbers are euqal to
0109:             * the last logical line before this conflict.
0110:             * The line numbers start from '1'.
0111:             */
0112:            private int[] resultLineNumbers;
0113:
0114:            private int numConflicts;
0115:            private int numUnresolvedConflicts;
0116:            private int currentConflictPos;
0117:            private List<Integer> resolvedLeftConflictsLineNumbers = new ArrayList<Integer>();
0118:            private List<Integer> resolvedRightConflictsLineNumbers = new ArrayList<Integer>();
0119:
0120:            private ArrayList<ActionListener> controlListeners = new ArrayList<ActionListener>();
0121:
0122:            private SystemAction[] systemActions = new SystemAction[] {
0123:                    SaveAction.get(SaveAction.class), null,
0124:                    CloseMergeViewAction.get(CloseMergeViewAction.class) };
0125:
0126:            static final long serialVersionUID = 3683458237532937983L;
0127:            private static final String PLAIN_TEXT_MIME = "text/plain";
0128:
0129:            /** Creates new DiffComponent from AbstractDiff object*/
0130:            public MergePanel() {
0131:                //        this.diff = diff;
0132:                initComponents();
0133:                // TODO Get icons for these buttons
0134:                firstConflictButton.setVisible(false);
0135:                lastConflictButton.setVisible(false);
0136:                prevConflictButton
0137:                        .setIcon(new ImageIcon(
0138:                                org.openide.util.Utilities
0139:                                        .loadImage(
0140:                                                "org/netbeans/modules/diff/builtin/visualizer/prev.gif",
0141:                                                true)));
0142:                nextConflictButton
0143:                        .setIcon(new ImageIcon(
0144:                                org.openide.util.Utilities
0145:                                        .loadImage(
0146:                                                "org/netbeans/modules/diff/builtin/visualizer/next.gif",
0147:                                                true)));
0148:                //prevConflictButton.setIcon(new ImageIcon(getClass().getResource("/org/netbeans/modules/diff/builtin/visualizer/prev.gif")));
0149:                //nextConflictButton.setIcon(new ImageIcon(getClass().getResource("/org/netbeans/modules/diff/builtin/visualizer/next.gif")));
0150:                //setTitle(org.openide.util.NbBundle.getBundle(DiffComponent.class).getString("DiffComponent.title"));
0151:                //setName(org.openide.util.NbBundle.getMessage(MergePanel.class, "MergePanel.title"));
0152:                //HelpCtx.setHelpIDString (getRootPane (), DiffComponent.class.getName ());
0153:                initActions();
0154:                diffSplitPane.setResizeWeight(0.5);
0155:                mergeSplitPane.setResizeWeight(0.5);
0156:                putClientProperty("PersistenceType", "Never");
0157:                jEditorPane1.getAccessibleContext().setAccessibleName(
0158:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0159:                                "ACS_EditorPane1A11yName")); // NOI18N
0160:                jEditorPane1.getAccessibleContext().setAccessibleDescription(
0161:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0162:                                "ACS_EditorPane1A11yDescr")); // NOI18N
0163:                jEditorPane2.getAccessibleContext().setAccessibleName(
0164:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0165:                                "ACS_EditorPane2A11yName")); // NOI18N
0166:                jEditorPane2.getAccessibleContext().setAccessibleDescription(
0167:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0168:                                "ACS_EditorPane2A11yDescr")); // NOI18N
0169:                jEditorPane3.getAccessibleContext().setAccessibleName(
0170:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0171:                                "ACS_EditorPane3A11yName")); // NOI18N
0172:                jEditorPane3.getAccessibleContext().setAccessibleDescription(
0173:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0174:                                "ACS_EditorPane3A11yDescr")); // NOI18N
0175:            }
0176:
0177:            public void addNotify() {
0178:                super .addNotify();
0179:
0180:                jEditorPane1
0181:                        .putClientProperty(
0182:                                "HighlightsLayerExcludes",
0183:                                "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$"); //NOI18N
0184:                jEditorPane2
0185:                        .putClientProperty(
0186:                                "HighlightsLayerExcludes",
0187:                                "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$"); //NOI18N
0188:                jEditorPane3
0189:                        .putClientProperty(
0190:                                "HighlightsLayerExcludes",
0191:                                "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$"); //NOI18N
0192:            }
0193:
0194:            /** This method is called from within the constructor to
0195:             * initialize the form.
0196:             * WARNING: Do NOT modify this code. The content of this method is
0197:             * always regenerated by the FormEditor.
0198:             */
0199:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0200:            private void initComponents() {
0201:                java.awt.GridBagConstraints gridBagConstraints;
0202:
0203:                setLayout(new java.awt.GridBagLayout());
0204:
0205:                commandPanel.setLayout(new java.awt.GridBagLayout());
0206:
0207:                firstConflictButton.setPreferredSize(new java.awt.Dimension(24,
0208:                        24));
0209:                firstConflictButton.addActionListener(this );
0210:                commandPanel.add(firstConflictButton,
0211:                        new java.awt.GridBagConstraints());
0212:
0213:                prevConflictButton.setToolTipText(org.openide.util.NbBundle
0214:                        .getMessage(MergePanel.class,
0215:                                "MergePanel.prevButton.toolTipText")); // NOI18N
0216:                prevConflictButton.setMargin(new java.awt.Insets(1, 1, 0, 1));
0217:                prevConflictButton
0218:                        .setMaximumSize(new java.awt.Dimension(24, 24));
0219:                prevConflictButton
0220:                        .setMinimumSize(new java.awt.Dimension(24, 24));
0221:                prevConflictButton.setPreferredSize(new java.awt.Dimension(24,
0222:                        24));
0223:                prevConflictButton.addActionListener(this );
0224:                gridBagConstraints = new java.awt.GridBagConstraints();
0225:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0226:                gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 1);
0227:                commandPanel.add(prevConflictButton, gridBagConstraints);
0228:
0229:                nextConflictButton.setToolTipText(org.openide.util.NbBundle
0230:                        .getMessage(MergePanel.class,
0231:                                "MergePanel.nextButton.toolTipText")); // NOI18N
0232:                nextConflictButton.setMargin(new java.awt.Insets(1, 1, 0, 1));
0233:                nextConflictButton
0234:                        .setMaximumSize(new java.awt.Dimension(24, 24));
0235:                nextConflictButton
0236:                        .setMinimumSize(new java.awt.Dimension(24, 24));
0237:                nextConflictButton.setPreferredSize(new java.awt.Dimension(24,
0238:                        24));
0239:                nextConflictButton.addActionListener(this );
0240:                gridBagConstraints = new java.awt.GridBagConstraints();
0241:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0242:                gridBagConstraints.insets = new java.awt.Insets(0, 1, 0, 1);
0243:                commandPanel.add(nextConflictButton, gridBagConstraints);
0244:
0245:                lastConflictButton.setPreferredSize(new java.awt.Dimension(24,
0246:                        24));
0247:                lastConflictButton.addActionListener(this );
0248:                gridBagConstraints = new java.awt.GridBagConstraints();
0249:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0250:                gridBagConstraints.insets = new java.awt.Insets(0, 1, 0, 2);
0251:                commandPanel.add(lastConflictButton, gridBagConstraints);
0252:
0253:                org.openide.awt.Mnemonics.setLocalizedText(statusLabel,
0254:                        "jLabel1");
0255:                gridBagConstraints = new java.awt.GridBagConstraints();
0256:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0257:                gridBagConstraints.weightx = 1.0;
0258:                gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 1);
0259:                commandPanel.add(statusLabel, gridBagConstraints);
0260:
0261:                gridBagConstraints = new java.awt.GridBagConstraints();
0262:                gridBagConstraints.gridy = 0;
0263:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0264:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0265:                gridBagConstraints.weightx = 1.0;
0266:                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
0267:                add(commandPanel, gridBagConstraints);
0268:
0269:                editorPanel.setPreferredSize(new java.awt.Dimension(700, 600));
0270:                editorPanel.setLayout(new java.awt.GridBagLayout());
0271:
0272:                mergeSplitPane.setDividerSize(4);
0273:                mergeSplitPane
0274:                        .setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
0275:
0276:                diffSplitPane.setDividerSize(4);
0277:
0278:                filePanel1.setLayout(new java.awt.GridBagLayout());
0279:
0280:                leftCommandPanel.setLayout(new java.awt.GridBagLayout());
0281:
0282:                org.openide.awt.Mnemonics.setLocalizedText(acceptLeftButton,
0283:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0284:                                "MergePanel.acceptLeftButton.text")); // NOI18N
0285:                acceptLeftButton
0286:                        .setToolTipText(org.openide.util.NbBundle.getBundle(
0287:                                MergePanel.class).getString(
0288:                                "ACS_MergePanel.acceptLeftButton.textA11yDesc")); // NOI18N
0289:                acceptLeftButton.addActionListener(this );
0290:                gridBagConstraints = new java.awt.GridBagConstraints();
0291:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
0292:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0293:                gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 1);
0294:                leftCommandPanel.add(acceptLeftButton, gridBagConstraints);
0295:
0296:                org.openide.awt.Mnemonics.setLocalizedText(
0297:                        acceptAndNextLeftButton, org.openide.util.NbBundle
0298:                                .getMessage(MergePanel.class,
0299:                                        "MergePanel.acceptAndNextLeftButton")); // NOI18N
0300:                acceptAndNextLeftButton
0301:                        .setToolTipText(org.openide.util.NbBundle
0302:                                .getBundle(MergePanel.class)
0303:                                .getString(
0304:                                        "ACS_MergePanel.acceptAndNextLeftButtonA11yDesc")); // NOI18N
0305:                acceptAndNextLeftButton.addActionListener(this );
0306:                gridBagConstraints = new java.awt.GridBagConstraints();
0307:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0308:                gridBagConstraints.weightx = 1.0;
0309:                gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 2);
0310:                leftCommandPanel.add(acceptAndNextLeftButton,
0311:                        gridBagConstraints);
0312:
0313:                gridBagConstraints = new java.awt.GridBagConstraints();
0314:                gridBagConstraints.gridy = 0;
0315:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0316:                gridBagConstraints.weightx = 1.0;
0317:                filePanel1.add(leftCommandPanel, gridBagConstraints);
0318:
0319:                jEditorPane1.addCaretListener(this );
0320:                jScrollPane1.setViewportView(jEditorPane1);
0321:
0322:                gridBagConstraints = new java.awt.GridBagConstraints();
0323:                gridBagConstraints.gridy = 1;
0324:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0325:                gridBagConstraints.weightx = 1.0;
0326:                gridBagConstraints.weighty = 1.0;
0327:                filePanel1.add(jScrollPane1, gridBagConstraints);
0328:
0329:                org.openide.awt.Mnemonics.setLocalizedText(fileLabel1,
0330:                        "jLabel1");
0331:                gridBagConstraints = new java.awt.GridBagConstraints();
0332:                gridBagConstraints.gridy = 2;
0333:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0334:                gridBagConstraints.weightx = 1.0;
0335:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
0336:                filePanel1.add(fileLabel1, gridBagConstraints);
0337:
0338:                diffSplitPane.setLeftComponent(filePanel1);
0339:
0340:                filePanel2.setLayout(new java.awt.GridBagLayout());
0341:
0342:                rightCommandPanel.setLayout(new java.awt.GridBagLayout());
0343:
0344:                org.openide.awt.Mnemonics.setLocalizedText(acceptRightButton,
0345:                        org.openide.util.NbBundle.getMessage(MergePanel.class,
0346:                                "MergePanel.acceptRightButton.text")); // NOI18N
0347:                acceptRightButton
0348:                        .setToolTipText(org.openide.util.NbBundle
0349:                                .getBundle(MergePanel.class)
0350:                                .getString(
0351:                                        "ACS_MergePanel.acceptRightButton.textA11yDesc")); // NOI18N
0352:                acceptRightButton.addActionListener(this );
0353:                gridBagConstraints = new java.awt.GridBagConstraints();
0354:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0355:                gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 1);
0356:                rightCommandPanel.add(acceptRightButton, gridBagConstraints);
0357:
0358:                org.openide.awt.Mnemonics.setLocalizedText(
0359:                        acceptAndNextRightButton, org.openide.util.NbBundle
0360:                                .getMessage(MergePanel.class,
0361:                                        "MergePanel.acceptAndNextRightButton")); // NOI18N
0362:                acceptAndNextRightButton
0363:                        .setToolTipText(org.openide.util.NbBundle
0364:                                .getBundle(MergePanel.class)
0365:                                .getString(
0366:                                        "ACS_MergePanel.acceptAndNextRightButtonA11yDesc")); // NOI18N
0367:                acceptAndNextRightButton.addActionListener(this );
0368:                gridBagConstraints = new java.awt.GridBagConstraints();
0369:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
0370:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0371:                gridBagConstraints.weightx = 1.0;
0372:                gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 2);
0373:                rightCommandPanel.add(acceptAndNextRightButton,
0374:                        gridBagConstraints);
0375:
0376:                gridBagConstraints = new java.awt.GridBagConstraints();
0377:                gridBagConstraints.gridy = 0;
0378:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0379:                gridBagConstraints.weightx = 1.0;
0380:                filePanel2.add(rightCommandPanel, gridBagConstraints);
0381:
0382:                jEditorPane2.addCaretListener(this );
0383:                jScrollPane2.setViewportView(jEditorPane2);
0384:
0385:                gridBagConstraints = new java.awt.GridBagConstraints();
0386:                gridBagConstraints.gridy = 1;
0387:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0388:                gridBagConstraints.weightx = 1.0;
0389:                gridBagConstraints.weighty = 1.0;
0390:                filePanel2.add(jScrollPane2, gridBagConstraints);
0391:
0392:                org.openide.awt.Mnemonics.setLocalizedText(fileLabel2,
0393:                        "jLabel2");
0394:                gridBagConstraints = new java.awt.GridBagConstraints();
0395:                gridBagConstraints.gridy = 2;
0396:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0397:                gridBagConstraints.weightx = 1.0;
0398:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
0399:                filePanel2.add(fileLabel2, gridBagConstraints);
0400:
0401:                diffSplitPane.setRightComponent(filePanel2);
0402:
0403:                mergeSplitPane.setLeftComponent(diffSplitPane);
0404:
0405:                resultPanel.setLayout(new java.awt.GridBagLayout());
0406:
0407:                resultScrollPane.setViewportView(jEditorPane3);
0408:
0409:                gridBagConstraints = new java.awt.GridBagConstraints();
0410:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0411:                gridBagConstraints.weightx = 1.0;
0412:                gridBagConstraints.weighty = 1.0;
0413:                resultPanel.add(resultScrollPane, gridBagConstraints);
0414:
0415:                org.openide.awt.Mnemonics.setLocalizedText(resultLabel,
0416:                        "jLabel1");
0417:                gridBagConstraints = new java.awt.GridBagConstraints();
0418:                gridBagConstraints.gridy = 1;
0419:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0420:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
0421:                resultPanel.add(resultLabel, gridBagConstraints);
0422:
0423:                mergeSplitPane.setRightComponent(resultPanel);
0424:
0425:                gridBagConstraints = new java.awt.GridBagConstraints();
0426:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0427:                gridBagConstraints.weightx = 1.0;
0428:                gridBagConstraints.weighty = 1.0;
0429:                editorPanel.add(mergeSplitPane, gridBagConstraints);
0430:
0431:                gridBagConstraints = new java.awt.GridBagConstraints();
0432:                gridBagConstraints.gridy = 1;
0433:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0434:                gridBagConstraints.weightx = 1.0;
0435:                gridBagConstraints.weighty = 1.0;
0436:                add(editorPanel, gridBagConstraints);
0437:            }
0438:
0439:            // Code for dispatching events from components to event handlers.
0440:
0441:            public void actionPerformed(java.awt.event.ActionEvent evt) {
0442:                if (evt.getSource() == firstConflictButton) {
0443:                    MergePanel.this .firstConflictButtonActionPerformed(evt);
0444:                } else if (evt.getSource() == prevConflictButton) {
0445:                    MergePanel.this .prevConflictButtonActionPerformed(evt);
0446:                } else if (evt.getSource() == nextConflictButton) {
0447:                    MergePanel.this .nextConflictButtonActionPerformed(evt);
0448:                } else if (evt.getSource() == lastConflictButton) {
0449:                    MergePanel.this .lastConflictButtonActionPerformed(evt);
0450:                } else if (evt.getSource() == acceptLeftButton) {
0451:                    MergePanel.this .acceptLeftButtonActionPerformed(evt);
0452:                } else if (evt.getSource() == acceptAndNextLeftButton) {
0453:                    MergePanel.this .acceptAndNextLeftButtonActionPerformed(evt);
0454:                } else if (evt.getSource() == acceptRightButton) {
0455:                    MergePanel.this .acceptRightButtonActionPerformed(evt);
0456:                } else if (evt.getSource() == acceptAndNextRightButton) {
0457:                    MergePanel.this 
0458:                            .acceptAndNextRightButtonActionPerformed(evt);
0459:                }
0460:            }
0461:
0462:            public void caretUpdate(javax.swing.event.CaretEvent evt) {
0463:                if (evt.getSource() == jEditorPane1) {
0464:                    MergePanel.this .jEditorPane1CaretUpdate(evt);
0465:                } else if (evt.getSource() == jEditorPane2) {
0466:                    MergePanel.this .jEditorPane2CaretUpdate(evt);
0467:                }
0468:            }// </editor-fold>//GEN-END:initComponents
0469:
0470:            private void firstConflictButtonActionPerformed(
0471:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firstConflictButtonActionPerformed
0472:                // Add your handling code here:
0473:                fireControlActionCommand(ACTION_FIRST_CONFLICT);
0474:            }//GEN-LAST:event_firstConflictButtonActionPerformed
0475:
0476:            private void prevConflictButtonActionPerformed(
0477:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevConflictButtonActionPerformed
0478:                // Add your handling code here:
0479:                fireControlActionCommand(ACTION_PREVIOUS_CONFLICT);
0480:            }//GEN-LAST:event_prevConflictButtonActionPerformed
0481:
0482:            private void nextConflictButtonActionPerformed(
0483:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextConflictButtonActionPerformed
0484:                // Add your handling code here:
0485:                fireControlActionCommand(ACTION_NEXT_CONFLICT);
0486:            }//GEN-LAST:event_nextConflictButtonActionPerformed
0487:
0488:            private void lastConflictButtonActionPerformed(
0489:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lastConflictButtonActionPerformed
0490:                // Add your handling code here:
0491:                fireControlActionCommand(ACTION_LAST_CONFLICT);
0492:            }//GEN-LAST:event_lastConflictButtonActionPerformed
0493:
0494:            private void acceptRightButtonActionPerformed(
0495:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptRightButtonActionPerformed
0496:                // Add your handling code here:
0497:                fireControlActionCommand(ACTION_ACCEPT_RIGHT);
0498:            }//GEN-LAST:event_acceptRightButtonActionPerformed
0499:
0500:            private void acceptAndNextRightButtonActionPerformed(
0501:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptAndNextRightButtonActionPerformed
0502:                // Add your handling code here:
0503:                fireControlActionCommand(ACTION_ACCEPT_RIGHT);
0504:                fireControlActionCommand(ACTION_NEXT_CONFLICT);
0505:            }//GEN-LAST:event_acceptAndNextRightButtonActionPerformed
0506:
0507:            private void acceptAndNextLeftButtonActionPerformed(
0508:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptAndNextLeftButtonActionPerformed
0509:                // Add your handling code here:
0510:                fireControlActionCommand(ACTION_ACCEPT_LEFT);
0511:                fireControlActionCommand(ACTION_NEXT_CONFLICT);
0512:            }//GEN-LAST:event_acceptAndNextLeftButtonActionPerformed
0513:
0514:            private void acceptLeftButtonActionPerformed(
0515:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptLeftButtonActionPerformed
0516:                // Add your handling code here:
0517:                fireControlActionCommand(ACTION_ACCEPT_LEFT);
0518:            }//GEN-LAST:event_acceptLeftButtonActionPerformed
0519:
0520:            private void jEditorPane1CaretUpdate(
0521:                    javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jEditorPane1CaretUpdate
0522:            // Add your handling code here:
0523:            /*      int pos = evt.getDot();
0524:             int line = org.openide.text.NbDocument.findLineNumber((StyledDocument) jEditorPane1.getDocument(), pos);
0525:             StyledDocument linesDoc = (StyledDocument)jEditorPane1.getDocument();
0526:             int numLines = org.openide.text.NbDocument.findLineNumber(linesDoc, linesDoc.getEndPosition().getOffset());
0527:             if (line <= numLines) {
0528:             jEditorPane1.setCaretPosition(org.openide.text.NbDocument.findLineOffset(linesDoc, line));
0529:             }
0530:             */
0531:
0532:            }//GEN-LAST:event_jEditorPane1CaretUpdate
0533:
0534:            private void jEditorPane2CaretUpdate(
0535:                    javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jEditorPane2CaretUpdate
0536:            // Add your handling code here:
0537:            /*      int pos = evt.getDot();
0538:             int line = org.openide.text.NbDocument.findLineNumber((StyledDocument) jEditorPane2.getDocument(), pos);
0539:             StyledDocument linesDoc = (StyledDocument)jEditorPane2.getDocument();
0540:             int numLines = org.openide.text.NbDocument.findLineNumber(linesDoc, linesDoc.getEndPosition().getOffset());
0541:             if (line <= numLines) {
0542:             jEditorPane2.setCaretPosition(org.openide.text.NbDocument.findLineOffset(linesDoc, line));
0543:             }
0544:             */
0545:
0546:            }//GEN-LAST:event_jEditorPane2CaretUpdate
0547:
0548:            public void setNumConflicts(int numConflicts) {
0549:                this .numConflicts = numConflicts;
0550:                this .numUnresolvedConflicts = numConflicts;
0551:            }
0552:
0553:            public int getNumUnresolvedConflicts() {
0554:                return numUnresolvedConflicts;
0555:            }
0556:
0557:            /**
0558:             * Instruct view to move to given line. It actually
0559:             * moves when AWT processes posted event.
0560:             */
0561:            public void setCurrentLine(final int line, final int diffLength,
0562:                    final int conflictPos, final int resultLine) {
0563:                if (line > 0) {
0564:                    SwingUtilities.invokeLater(new Runnable() {
0565:                        public void run() {
0566:                            showLine12(line, diffLength);
0567:                            showLine3(resultLine, diffLength);
0568:                            if (conflictPos >= 0)
0569:                                MergePanel.this .currentConflictPos = conflictPos;
0570:                            updateStatusLine();
0571:                            updateAcceptButtons(line);
0572:                        }
0573:                    });
0574:                }
0575:            }
0576:
0577:            public void setNeedsSaveState(boolean needsSave) {
0578:                firePropertyChange((needsSave) ? PROP_CAN_BE_SAVED
0579:                        : PROP_CAN_NOT_BE_SAVED, null, null);
0580:            }
0581:
0582:            public synchronized void addControlActionListener(
0583:                    ActionListener listener) {
0584:                controlListeners.add(listener);
0585:            }
0586:
0587:            public synchronized void removeControlActionListener(
0588:                    ActionListener listener) {
0589:                controlListeners.remove(listener);
0590:            }
0591:
0592:            private void updateStatusLine() {
0593:                statusLabel.setText(org.openide.util.NbBundle.getMessage(
0594:                        MergePanel.class, "MergePanel.statusLine", Integer
0595:                                .toString(currentConflictPos + 1), Integer
0596:                                .toString(numConflicts), Integer
0597:                                .toString(numUnresolvedConflicts)));
0598:            }
0599:
0600:            private void updateAcceptButtons(int linePos) {
0601:                Integer conflictPos = new Integer(linePos);
0602:                boolean left = resolvedLeftConflictsLineNumbers
0603:                        .contains(conflictPos);
0604:                boolean right = resolvedRightConflictsLineNumbers
0605:                        .contains(conflictPos);
0606:                acceptLeftButton.setEnabled(!left);
0607:                acceptAndNextLeftButton.setEnabled(!left);
0608:                acceptRightButton.setEnabled(!right);
0609:                acceptAndNextRightButton.setEnabled(!right);
0610:            }
0611:
0612:            private void fireControlActionCommand(String command) {
0613:                ArrayList<ActionListener> listeners;
0614:                synchronized (this ) {
0615:                    listeners = new ArrayList<ActionListener>(controlListeners);
0616:                }
0617:                ActionEvent evt = new ActionEvent(this , 0, command);
0618:                for (ActionListener l : listeners) {
0619:                    l.actionPerformed(evt);
0620:                }
0621:            }
0622:
0623:            private void jScrollBar1AdjustmentValueChanged(
0624:                    java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_jScrollBar1AdjustmentValueChanged
0625:                // Add your handling code here:
0626:            }//GEN-LAST:event_jScrollBar1AdjustmentValueChanged
0627:
0628:            private void closeButtonActionPerformed(
0629:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
0630:                // Add your handling code here:
0631:                exitForm(null);
0632:            }//GEN-LAST:event_closeButtonActionPerformed
0633:
0634:            /** Exit the Application */
0635:            private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
0636:            /*        try {
0637:             org.netbeans.editor.Settings.setValue(null, org.netbeans.editor.SettingsNames.LINE_NUMBER_VISIBLE, lineNumbersVisible);
0638:             } catch (Throwable exc) {
0639:             // editor module not found
0640:             }
0641:             //System.out.println("exitForm() called.");
0642:             //diff.closing();
0643:             //close();
0644:             //dispose ();
0645:             for(Iterator it = closeListeners.iterator(); it.hasNext(); ) {
0646:             ((TopComponentCloseListener) it.next()).closing();
0647:             }
0648:             */
0649:
0650:            }//GEN-LAST:event_exitForm
0651:
0652:            public void setSystemActions(SystemAction[] actions) {
0653:                this .systemActions = actions;
0654:            }
0655:
0656:            public SystemAction[] getSystemActions() {
0657:                return systemActions;
0658:            }
0659:
0660:            private void initActions() {
0661:                jEditorPane1.addFocusListener(new FocusListener() {
0662:                    public void focusGained(FocusEvent e) {
0663:                        editorActivated(jEditorPane1);
0664:                    }
0665:
0666:                    public void focusLost(FocusEvent e) {
0667:                        editorDeactivated(jEditorPane1);
0668:                    }
0669:                });
0670:                jEditorPane2.addFocusListener(new FocusListener() {
0671:                    public void focusGained(FocusEvent e) {
0672:                        editorActivated(jEditorPane2);
0673:                    }
0674:
0675:                    public void focusLost(FocusEvent e) {
0676:                        editorDeactivated(jEditorPane2);
0677:                    }
0678:                });
0679:                jEditorPane3.addFocusListener(new FocusListener() {
0680:                    public void focusGained(FocusEvent e) {
0681:                        editorActivated(jEditorPane3);
0682:                    }
0683:
0684:                    public void focusLost(FocusEvent e) {
0685:                        editorDeactivated(jEditorPane3);
0686:                    }
0687:                });
0688:            }
0689:
0690:            private Hashtable<JEditorPane, Hashtable<Object, Action>> kitActions;
0691:            /** Listener for copy action enabling  */
0692:            private PropertyChangeListener copyL;
0693:            private PropertyChangeListener copyP;
0694:
0695:            private Action getAction(String s, JEditorPane editor) {
0696:                if (kitActions == null) {
0697:                    kitActions = new Hashtable<JEditorPane, Hashtable<Object, Action>>();
0698:                }
0699:                Hashtable<Object, Action> actions = kitActions.get(editor);
0700:                if (actions == null) {
0701:                    EditorKit kit = editor.getEditorKit();
0702:                    if (kit == null) {
0703:                        return null;
0704:                    }
0705:
0706:                    Action[] a = kit.getActions();
0707:                    actions = new Hashtable<Object, Action>(a.length);
0708:                    int k = a.length;
0709:                    for (int i = 0; i < k; i++)
0710:                        actions.put(a[i].getValue(Action.NAME), a[i]);
0711:                    kitActions.put(editor, actions);
0712:                }
0713:                return actions.get(s);
0714:            }
0715:
0716:            private void editorActivated(final JEditorPane editor) {
0717:                //System.out.println("editor("+editor+") activated.");
0718:                final Action copy = getAction(DefaultEditorKit.copyAction,
0719:                        editor);
0720:                if (copy != null) {
0721:                    final CallbackSystemAction sysCopy = ((CallbackSystemAction) SystemAction
0722:                            .get(CopyAction.class));
0723:                    final ActionPerformer perf = new ActionPerformer() {
0724:                        public void performAction(SystemAction action) {
0725:                            copy
0726:                                    .actionPerformed(new ActionEvent(editor, 0,
0727:                                            "")); // NOI18N
0728:                        }
0729:                    };
0730:                    sysCopy.setActionPerformer(copy.isEnabled() ? perf : null);
0731:                    PropertyChangeListener copyListener;
0732:                    copy
0733:                            .addPropertyChangeListener(copyListener = new PropertyChangeListener() {
0734:                                public void propertyChange(
0735:                                        PropertyChangeEvent evt) {
0736:                                    if ("enabled".equals(evt.getPropertyName())) { // NOI18N
0737:                                        if (((Boolean) evt.getNewValue())
0738:                                                .booleanValue()) {
0739:                                            sysCopy.setActionPerformer(perf);
0740:                                        } else if (sysCopy.getActionPerformer() == perf) {
0741:                                            sysCopy.setActionPerformer(null);
0742:                                        }
0743:                                    }
0744:                                }
0745:                            });
0746:                    if (editor.equals(jEditorPane1))
0747:                        copyL = copyListener;
0748:                    else
0749:                        copyP = copyListener;
0750:                }
0751:            }
0752:
0753:            private void editorDeactivated(JEditorPane editor) {
0754:                //System.out.println("editorDeactivated ("+editor+")");
0755:                Action copy = getAction(DefaultEditorKit.copyAction, editor);
0756:                PropertyChangeListener copyListener;
0757:                if (editor.equals(jEditorPane1))
0758:                    copyListener = copyL;
0759:                else
0760:                    copyListener = copyP;
0761:                if (copy != null) {
0762:                    copy.removePropertyChangeListener(copyListener);
0763:                }
0764:            }
0765:
0766:            public void open() {
0767:                javax.swing.SwingUtilities.invokeLater(new Runnable() {
0768:                    public void run() {
0769:                        diffSplitPane.setDividerLocation(0.5);
0770:                        mergeSplitPane.setDividerLocation(0.5);
0771:                        openPostProcess();
0772:                    }
0773:                });
0774:            }
0775:
0776:            protected void openPostProcess() {
0777:                javax.swing.SwingUtilities.invokeLater(new Runnable() {
0778:                    public void run() {
0779:                        initGlobalSizes();
0780:                        //showLine(1, 0);
0781:                        addChangeListeners();
0782:                        /*                javax.swing.SwingUtilities.invokeLater(new Runnable() {
0783:                         public void run() {
0784:                         initGlobalSizes(); // do that again to be sure that components are initialized.
0785:                         javax.swing.SwingUtilities.invokeLater(new Runnable() {
0786:                         public void run() {
0787:                         syncFont(); // Components have to be fully initialized before font syncing
0788:                         addChangeListeners();
0789:                         }
0790:                         });
0791:                         }
0792:                         });
0793:                         */
0794:                    }
0795:                });
0796:            }
0797:
0798:            /*
0799:            public void removeNotify() {
0800:                System.out.println("removeNotify() called");
0801:                exitForm(null);
0802:                super.removeNotify();
0803:            }
0804:             */
0805:            private void initGlobalSizes() {
0806:                StyledDocument doc1 = (StyledDocument) jEditorPane1
0807:                        .getDocument();
0808:                StyledDocument doc2 = (StyledDocument) jEditorPane2
0809:                        .getDocument();
0810:                int numLines1 = org.openide.text.NbDocument.findLineNumber(
0811:                        doc1, doc1.getEndPosition().getOffset());
0812:                int numLines2 = org.openide.text.NbDocument.findLineNumber(
0813:                        doc2, doc2.getEndPosition().getOffset());
0814:                int numLines = Math.max(numLines1, numLines2);
0815:                if (numLines < 1)
0816:                    numLines = 1;
0817:                this .totalLines = numLines;
0818:                //        int totHeight = editorPanel1.getSize().height;
0819:                int totHeight = jEditorPane1.getSize().height;
0820:                //        int value = editorPanel2.getSize().height;
0821:                int value = jEditorPane2.getSize().height;
0822:                if (value > totHeight)
0823:                    totHeight = value;
0824:                this .totalHeight = totHeight;
0825:            }
0826:
0827:            private void showLine12(int line, int diffLength) {
0828:                assert SwingUtilities.isEventDispatchThread();
0829:                //System.out.println("showLine("+line+", "+diffLength+")");
0830:                this .linesComp1.setActiveLine(line);
0831:                this .linesComp2.setActiveLine(line);
0832:                linesComp1.repaint();
0833:                linesComp2.repaint();
0834:                int padding = 5;
0835:                if (line <= 5)
0836:                    padding = line / 2;
0837:                int off1, off2;
0838:                int ypos;
0839:                int viewHeight = jViewport1.getExtentSize().height;
0840:                java.awt.Point p1, p2;
0841:                initGlobalSizes(); // The window might be resized in the mean time.
0842:                p1 = jViewport1.getViewPosition();
0843:                p2 = jViewport2.getViewPosition();
0844:                ypos = (totalHeight * (line - padding - 1)) / (totalLines + 1);
0845:                int viewSize = jViewport1.getViewRect().y;
0846:                if (ypos < p1.y
0847:                        || ypos + ((diffLength + padding) * totalHeight)
0848:                                / totalLines > p1.y + viewHeight) {
0849:                    //System.out.println("resetting posision=" + ypos);
0850:                    p1.y = ypos;
0851:                    p2.y = ypos;
0852:                    setViewPosition(p1, p2);
0853:                }
0854:                off1 = org.openide.text.NbDocument.findLineOffset(
0855:                        (StyledDocument) jEditorPane1.getDocument(), line);
0856:                off2 = org.openide.text.NbDocument.findLineOffset(
0857:                        (StyledDocument) jEditorPane2.getDocument(), line);
0858:                jEditorPane1.setCaretPosition(off1);
0859:                jEditorPane2.setCaretPosition(off2);
0860:                //D.deb("off1 = "+off1+", off2 = "+off2+", totalHeight = "+totalHeight+", totalLines = "+totalLines+", ypos = "+ypos);
0861:                //System.out.println("off1 = "+off1+", off2 = "+off2+", totalHeight = "+totalHeight+", totalLines = "+totalLines+", ypos = "+ypos);
0862:            }
0863:
0864:            private void showLine3(int line, int diffLength) {
0865:                linesComp3.setActiveLine(line);
0866:                linesComp3.repaint();
0867:            }
0868:
0869:            private void setViewPosition(java.awt.Point p1, java.awt.Point p2) {
0870:                assert SwingUtilities.isEventDispatchThread();
0871:                jViewport1.setViewPosition(p1);
0872:                jViewport1.repaint(jViewport1.getViewRect());
0873:                jViewport2.setViewPosition(p2);
0874:                jViewport2.repaint(jViewport2.getViewRect());
0875:            }
0876:
0877:            private void joinScrollBars() {
0878:                final JScrollBar scrollBarH1 = jScrollPane1
0879:                        .getHorizontalScrollBar();
0880:                final JScrollBar scrollBarV1 = jScrollPane1
0881:                        .getVerticalScrollBar();
0882:                final JScrollBar scrollBarH2 = jScrollPane2
0883:                        .getHorizontalScrollBar();
0884:                final JScrollBar scrollBarV2 = jScrollPane2
0885:                        .getVerticalScrollBar();
0886:                final JScrollBar scrollBarH3 = resultScrollPane
0887:                        .getHorizontalScrollBar();
0888:                final JScrollBar scrollBarV3 = resultScrollPane
0889:                        .getVerticalScrollBar();
0890:                scrollBarV1.getModel().addChangeListener(
0891:                        new javax.swing.event.ChangeListener() {
0892:                            public void stateChanged(
0893:                                    javax.swing.event.ChangeEvent e) {
0894:                                int value = scrollBarV1.getValue();
0895:                                int oldValue = scrollBarV2.getValue();
0896:                                if (oldValue != value) {
0897:                                    scrollBarV2.setValue(value);
0898:                                    //                    System.out.println("setting v2=" + value);
0899:                                    //                    Thread.dumpStack();
0900:                                }
0901:                                // TODO use a better algorithm to adjust scrollbars, if there are large changes, this will not work optimally.
0902:                                if (value == verticalScroll1ChangedValue)
0903:                                    return;
0904:                                int max1 = scrollBarV1.getMaximum();
0905:                                int max2 = scrollBarV3.getMaximum();
0906:                                int ext1 = scrollBarV1.getModel().getExtent();
0907:                                int ext2 = scrollBarV3.getModel().getExtent();
0908:                                if (max1 == ext1)
0909:                                    verticalScroll3ChangedValue = 0;
0910:                                else
0911:                                    verticalScroll3ChangedValue = (value * (max2 - ext2))
0912:                                            / (max1 - ext1);
0913:                                verticalScroll1ChangedValue = -1;
0914:                                scrollBarV3
0915:                                        .setValue(verticalScroll3ChangedValue);
0916:                            }
0917:                        });
0918:                //jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
0919:                // The vertical scroll bar must be there for mouse wheel to work correctly.
0920:                // However it's not necessary to be seen (but must be visible so that the wheel will work).
0921:                jScrollPane1.getVerticalScrollBar().setPreferredSize(
0922:                        new Dimension(0, 0));
0923:                scrollBarV2.getModel().addChangeListener(
0924:                        new javax.swing.event.ChangeListener() {
0925:                            public void stateChanged(
0926:                                    javax.swing.event.ChangeEvent e) {
0927:                                int value = scrollBarV2.getValue();
0928:                                int oldValue = scrollBarV1.getValue();
0929:                                if (oldValue != value) {
0930:                                    scrollBarV1.setValue(value);
0931:                                    //                    System.out.println("setting v1 to=" + value);
0932:                                }
0933:                            }
0934:                        });
0935:                /* don't not let the result source vertical scrolling to influence the diff panels.
0936:                scrollBarV3.getModel().addChangeListener(new javax.swing.event.ChangeListener()  {
0937:                    public void stateChanged(javax.swing.event.ChangeEvent e) {
0938:                        int value = scrollBarV3.getValue();
0939:                        if (value == verticalScroll3ChangedValue) return ;
0940:                        int max1 = scrollBarV3.getMaximum();
0941:                        int max2 = scrollBarV1.getMaximum();
0942:                        int ext1 = scrollBarV3.getModel().getExtent();
0943:                        int ext2 = scrollBarV1.getModel().getExtent();
0944:                        if (max1 == ext1) verticalScroll1ChangedValue = 0;
0945:                        else verticalScroll1ChangedValue = (value*(max2 - ext2))/(max1 - ext1);
0946:                        verticalScroll3ChangedValue = -1;
0947:                        scrollBarV1.setValue(verticalScroll1ChangedValue);
0948:                    }
0949:                });
0950:                 */
0951:                scrollBarH1.getModel().addChangeListener(
0952:                        new javax.swing.event.ChangeListener() {
0953:                            public void stateChanged(
0954:                                    javax.swing.event.ChangeEvent e) {
0955:                                int value = scrollBarH1.getValue();
0956:                                //                System.out.println("stateChangedH1:value = "+value+", horizontalScroll1ChangedValue = "+horizontalScroll1ChangedValue);
0957:                                if (value == horizontalScroll1ChangedValue)
0958:                                    return;
0959:                                int max1 = scrollBarH1.getMaximum();
0960:                                int max2 = scrollBarH2.getMaximum();
0961:                                int ext1 = scrollBarH1.getModel().getExtent();
0962:                                int ext2 = scrollBarH2.getModel().getExtent();
0963:                                if (max1 == ext1)
0964:                                    horizontalScroll2ChangedValue = 0;
0965:                                else
0966:                                    horizontalScroll2ChangedValue = (value * (max2 - ext2))
0967:                                            / (max1 - ext1);
0968:                                horizontalScroll1ChangedValue = -1;
0969:                                //                System.out.println("H1 value = "+value+" => H2 value = "+horizontalScroll2ChangedValue+"\t\tmax1 = "+max1+", max2 = "+max2);
0970:                                scrollBarH2
0971:                                        .setValue(horizontalScroll2ChangedValue);
0972:                            }
0973:                        });
0974:                scrollBarH2.getModel().addChangeListener(
0975:                        new javax.swing.event.ChangeListener() {
0976:                            public void stateChanged(
0977:                                    javax.swing.event.ChangeEvent e) {
0978:                                int value = scrollBarH2.getValue();
0979:                                //                System.out.println("stateChangedH2:value = "+value+", horizontalScroll2ChangedValue = "+horizontalScroll2ChangedValue);
0980:                                if (value == horizontalScroll2ChangedValue)
0981:                                    return;
0982:                                int max1 = scrollBarH1.getMaximum();
0983:                                int max2 = scrollBarH2.getMaximum();
0984:                                int max3 = scrollBarH3.getMaximum();
0985:                                int ext1 = scrollBarH1.getModel().getExtent();
0986:                                int ext2 = scrollBarH2.getModel().getExtent();
0987:                                int ext3 = scrollBarH3.getModel().getExtent();
0988:                                if (max2 == ext2) {
0989:                                    horizontalScroll1ChangedValue = 0;
0990:                                    horizontalScroll3ChangedValue = 0;
0991:                                } else {
0992:                                    horizontalScroll1ChangedValue = (value * (max1 - ext1))
0993:                                            / (max2 - ext2);
0994:                                    horizontalScroll3ChangedValue = (value * (max3 - ext3))
0995:                                            / (max2 - ext2);
0996:                                }
0997:                                horizontalScroll2ChangedValue = -1;
0998:                                //                System.out.println("H2 value = "+value+" => H1 value = "+horizontalScroll1ChangedValue+"\t\tmax1 = "+max1+", max2 = "+max2);
0999:                                scrollBarH1
1000:                                        .setValue(horizontalScroll1ChangedValue);
1001:                                scrollBarH3
1002:                                        .setValue(horizontalScroll3ChangedValue);
1003:                            }
1004:                        });
1005:                scrollBarH3.getModel().addChangeListener(
1006:                        new javax.swing.event.ChangeListener() {
1007:                            public void stateChanged(
1008:                                    javax.swing.event.ChangeEvent e) {
1009:                                int value = scrollBarH3.getValue();
1010:                                //                System.out.println("stateChangedH1:value = "+value+", horizontalScroll1ChangedValue = "+horizontalScroll1ChangedValue);
1011:                                if (value == horizontalScroll3ChangedValue)
1012:                                    return;
1013:                                int max1 = scrollBarH1.getMaximum();
1014:                                int max2 = scrollBarH2.getMaximum();
1015:                                int max3 = scrollBarH3.getMaximum();
1016:                                int ext1 = scrollBarH1.getModel().getExtent();
1017:                                int ext2 = scrollBarH2.getModel().getExtent();
1018:                                int ext3 = scrollBarH3.getModel().getExtent();
1019:                                if (max3 == ext3) {
1020:                                    horizontalScroll1ChangedValue = 0;
1021:                                    horizontalScroll2ChangedValue = 0;
1022:                                } else {
1023:                                    horizontalScroll1ChangedValue = (value * (max1 - ext1))
1024:                                            / (max3 - ext3);
1025:                                    horizontalScroll2ChangedValue = (value * (max2 - ext2))
1026:                                            / (max3 - ext3);
1027:                                }
1028:                                horizontalScroll3ChangedValue = -1;
1029:                                //                System.out.println("H1 value = "+value+" => H2 value = "+horizontalScroll2ChangedValue+"\t\tmax1 = "+max1+", max2 = "+max2);
1030:                                scrollBarH1
1031:                                        .setValue(horizontalScroll1ChangedValue);
1032:                                scrollBarH2
1033:                                        .setValue(horizontalScroll2ChangedValue);
1034:                            }
1035:                        });
1036:                diffSplitPane.setDividerLocation(0.5);
1037:                mergeSplitPane.setDividerLocation(0.5);
1038:            }
1039:
1040:            private String strCharacters(char c, int num) {
1041:                StringBuffer s = new StringBuffer();
1042:                while (num-- > 0) {
1043:                    s.append(c);
1044:                }
1045:                return s.toString();
1046:            }
1047:
1048:            private void customizeEditor(JEditorPane editor) {
1049:                EditorKit kit = editor.getEditorKit();
1050:                /*
1051:                try {
1052:                    org.netbeans.editor.Settings.setValue(null, org.netbeans.editor.SettingsNames.LINE_NUMBER_VISIBLE, Boolean.FALSE);
1053:                } catch (Throwable exc) {
1054:                    // editor module not found
1055:                }
1056:                 */
1057:                StyledDocument doc;
1058:                Document document = editor.getDocument();
1059:                /*        StyledDocument docLines = new DefaultStyledDocument();
1060:                 textLines.setStyledDocument(docLines);
1061:                 */
1062:                try {
1063:                    doc = (StyledDocument) editor.getDocument();
1064:                } catch (ClassCastException e) {
1065:                    doc = new DefaultStyledDocument();
1066:                    try {
1067:                        doc.insertString(0, document.getText(0, document
1068:                                .getLength()), null);
1069:                    } catch (BadLocationException ble) {
1070:                        // leaving the document empty
1071:                    }
1072:                    editor.setDocument(doc);
1073:                }
1074:                //int lastOffset = doc.getEndPosition().getOffset();
1075:                //int numLines = org.openide.text.NbDocument.findLineNumber(doc, lastOffset);
1076:                //int numLength = Integer.toString(numLines).length();
1077:                //        textLines.setForeground(numForegroundColor);
1078:                //        textLines.setBackground(numBackgroundColor);
1079:                /*
1080:                for (int line = 0; line <= numLines; line++) {
1081:                    int offset = org.openide.text.NbDocument.findLineOffset(doc, line);
1082:                    String lineStr = Integer.toString(line+1);
1083:                    if (lineStr.length() < numLength) lineStr = strCharacters(' ', numLength - lineStr.length()) + lineStr;
1084:                    //lineStr = " "+lineStr+" "; // NOI18N
1085:                    try {
1086:                        if (line < numLines) lineStr += "\n"; // NOI18N
1087:                        docLines.insertString(docLines.getLength(), lineStr, null);
1088:                    } catch (BadLocationException e) {
1089:                        E.deb("Internal ERROR: "+e.getMessage()); // NOI18N
1090:                    }
1091:                }
1092:                 */
1093:                //        joinScrollBars();
1094:            }
1095:
1096:            private void addChangeListeners() {
1097:                jEditorPane1.addPropertyChangeListener("font",
1098:                        new java.beans.PropertyChangeListener() {
1099:                            public void propertyChange(
1100:                                    java.beans.PropertyChangeEvent evt) {
1101:                                //System.out.println("1:evt = "+evt+", Property NAME = "+evt.getPropertyName());
1102:                                javax.swing.SwingUtilities
1103:                                        .invokeLater(new Runnable() {
1104:                                            public void run() {
1105:                                                initGlobalSizes();
1106:                                                linesComp1.changedAll();
1107:                                            }
1108:                                        });
1109:                            }
1110:                        });
1111:                jEditorPane2.addPropertyChangeListener("font",
1112:                        new java.beans.PropertyChangeListener() {
1113:                            public void propertyChange(
1114:                                    java.beans.PropertyChangeEvent evt) {
1115:                                //System.out.println("2:evt = "+evt+", Property NAME = "+evt.getPropertyName());
1116:                                javax.swing.SwingUtilities
1117:                                        .invokeLater(new Runnable() {
1118:                                            public void run() {
1119:                                                initGlobalSizes();
1120:                                                linesComp2.changedAll();
1121:                                            }
1122:                                        });
1123:                            }
1124:                        });
1125:                jEditorPane3.addPropertyChangeListener("font",
1126:                        new java.beans.PropertyChangeListener() {
1127:                            public void propertyChange(
1128:                                    java.beans.PropertyChangeEvent evt) {
1129:                                //System.out.println("2:evt = "+evt+", Property NAME = "+evt.getPropertyName());
1130:                                javax.swing.SwingUtilities
1131:                                        .invokeLater(new Runnable() {
1132:                                            public void run() {
1133:                                                initGlobalSizes();
1134:                                                linesComp3.changedAll();
1135:                                            }
1136:                                        });
1137:                            }
1138:                        });
1139:            }
1140:
1141:            public void setSource1(Reader r) throws IOException {
1142:                //D.deb("setFile("+url+")"); // NOI18N
1143:                //System.out.println("setFile1("+url+")");
1144:                EditorKit kit = jEditorPane1.getEditorKit();
1145:                if (kit == null)
1146:                    throw new IOException("Missing Editor Kit"); // NOI18N
1147:                Document doc = kit.createDefaultDocument();
1148:                if (!(doc instanceof  StyledDocument)) {
1149:                    doc = new DefaultStyledDocument(new StyleContext());
1150:                    kit = new StyledEditorKit();
1151:                    jEditorPane1.setEditorKit(kit);
1152:                }
1153:                try {
1154:                    kit.read(r, doc, 0);
1155:                } catch (javax.swing.text.BadLocationException e) {
1156:                    throw new IOException(
1157:                            "Can not locate the beginning of the document."); // NOI18N
1158:                } finally {
1159:                    r.close();
1160:                }
1161:                kit.install(jEditorPane1);
1162:                jEditorPane1.setDocument(doc);
1163:                //jEditorPane1.setPage(url);
1164:                jEditorPane1.setEditable(false);
1165:                customizeEditor(jEditorPane1);
1166:                linesComp1 = new LinesComponent(jEditorPane1);
1167:                jScrollPane1.setRowHeaderView(linesComp1);
1168:                jViewport1 = jScrollPane1.getViewport();
1169:            }
1170:
1171:            public void setSource2(Reader r) throws IOException {
1172:                //D.deb("setFile("+url+")"); // NOI18N
1173:                EditorKit kit = jEditorPane2.getEditorKit();
1174:                if (kit == null)
1175:                    throw new IOException("Missing Editor Kit"); // NOI18N
1176:                Document doc = kit.createDefaultDocument();
1177:                if (!(doc instanceof  StyledDocument)) {
1178:                    doc = new DefaultStyledDocument(new StyleContext());
1179:                    kit = new StyledEditorKit();
1180:                    jEditorPane2.setEditorKit(kit);
1181:                }
1182:                try {
1183:                    kit.read(r, doc, 0);
1184:                } catch (javax.swing.text.BadLocationException e) {
1185:                    throw new IOException(
1186:                            "Can not locate the beginning of the document."); // NOI18N
1187:                } finally {
1188:                    r.close();
1189:                }
1190:                kit.install(jEditorPane2);
1191:                jEditorPane2.setDocument(doc);
1192:                //jEditorPane2.setPage(url);
1193:                jEditorPane2.setEditable(false);
1194:
1195:                customizeEditor(jEditorPane2);
1196:                linesComp2 = new LinesComponent(jEditorPane2);
1197:                jScrollPane2.setRowHeaderView(linesComp2);
1198:                jViewport2 = jScrollPane2.getViewport();
1199:                // add scrollbar listeners..
1200:                joinScrollBars();
1201:            }
1202:
1203:            public void setResultSource(Reader r) throws IOException {
1204:                EditorKit kit = jEditorPane3.getEditorKit();
1205:                if (kit == null)
1206:                    throw new IOException("Missing Editor Kit"); // NOI18N
1207:                Document doc = kit.createDefaultDocument();
1208:                if (!(doc instanceof  StyledDocument)) {
1209:                    doc = new DefaultStyledDocument(new StyleContext());
1210:                    kit = new StyledEditorKit();
1211:                    jEditorPane3.setEditorKit(kit);
1212:                }
1213:                try {
1214:                    kit.read(r, doc, 0);
1215:                } catch (javax.swing.text.BadLocationException e) {
1216:                    throw new IOException(
1217:                            "Can not locate the beginning of the document."); // NOI18N
1218:                } finally {
1219:                    r.close();
1220:                }
1221:                kit.install(jEditorPane3);
1222:                jEditorPane3.setDocument(doc);
1223:                //jEditorPane2.setPage(url);
1224:                jEditorPane3.setEditable(false);
1225:                customizeEditor(jEditorPane3);
1226:                linesComp3 = new LinesComponent(jEditorPane3);
1227:                resultScrollPane.setRowHeaderView(linesComp3);
1228:                resultLineNumbers = new int[1];
1229:                assureResultLineNumbersLength(org.openide.text.NbDocument
1230:                        .findLineNumber((StyledDocument) doc, doc
1231:                                .getEndPosition().getOffset()) + 1);
1232:                for (int i = 0; i < resultLineNumbers.length; i++)
1233:                    resultLineNumbers[i] = i;
1234:            }
1235:
1236:            private static final int EXTRA_CAPACITY = 5;
1237:
1238:            private void assureResultLineNumbersLength(int length) {
1239:                if (length > resultLineNumbers.length) {
1240:                    int[] newrln = new int[length + EXTRA_CAPACITY];
1241:                    System.arraycopy(resultLineNumbers, 0, newrln, 0,
1242:                            resultLineNumbers.length);
1243:                    resultLineNumbers = newrln;
1244:                }
1245:            }
1246:
1247:            /**
1248:             * Copy a part of first document into the result document.
1249:             * @param line1 The starting line in the first source
1250:             * @param line2 The ending line in the first source or <code>null</code>
1251:             *              when the part ends at the end of the document
1252:             * @param line3 The starting line in the result
1253:             */
1254:            public void copySource1ToResult(int line1, int line2, int line3) {
1255:                StyledDocument doc1 = (StyledDocument) jEditorPane1
1256:                        .getDocument();
1257:                StyledDocument doc2 = (StyledDocument) jEditorPane3
1258:                        .getDocument();
1259:                try {
1260:                    copy(doc1, line1, line2, doc2, line3);
1261:                } catch (BadLocationException e) {
1262:                    org.openide.ErrorManager.getDefault().notify(e);
1263:                }
1264:            }
1265:
1266:            /**
1267:             * Copy a part of second document into the result document.
1268:             * @param line1 The starting line in the second source
1269:             * @param line2 The ending line in the second source or <code>null</code>
1270:             *              when the part ends at the end of the document
1271:             * @param line3 The starting line in the result
1272:             */
1273:            public void copySource2ToResult(int line1, int line2, int line3) {
1274:                StyledDocument doc1 = (StyledDocument) jEditorPane2
1275:                        .getDocument();
1276:                StyledDocument doc2 = (StyledDocument) jEditorPane3
1277:                        .getDocument();
1278:                try {
1279:                    copy(doc1, line1, line2, doc2, line3);
1280:                } catch (BadLocationException e) {
1281:                    org.openide.ErrorManager.getDefault().notify(e);
1282:                }
1283:            }
1284:
1285:            /** Copies a part of one document into another. */
1286:            private void copy(StyledDocument doc1, int line1, int line2,
1287:                    StyledDocument doc2, int line3) throws BadLocationException {
1288:                int offset1 = org.openide.text.NbDocument.findLineOffset(doc1,
1289:                        line1 - 1);
1290:                int offset2 = (line2 >= 0) ? org.openide.text.NbDocument
1291:                        .findLineOffset(doc1, line2) : (doc1.getLength() - 1);
1292:                if (offset1 >= offset2)
1293:                    return;
1294:                int offset3 = org.openide.text.NbDocument.findLineOffset(doc2,
1295:                        line3 - 1);
1296:                int length = offset2 - offset1;
1297:                if (line2 < 0)
1298:                    length++;
1299:                String text = doc1.getText(offset1, length);
1300:                //System.out.println("copy: offset1 = "+offset1+", offset2 = "+offset2);
1301:                //System.out.println(">> copy text: at "+offset3+" <<\n"+text+">>  <<");
1302:                doc2.insertString(offset3, text, null);
1303:                // Adjust the line numbers
1304:                if (line2 < 0)
1305:                    line2 = org.openide.text.NbDocument.findLineNumber(doc1,
1306:                            doc1.getLength());
1307:                int numLines = line2 - line1 + 1;
1308:                //System.out.println("copy("+line1+", "+line2+", "+line3+"): resultLineNumbers.length = "+resultLineNumbers.length);
1309:                assureResultLineNumbersLength(line3 + numLines);
1310:                if (resultLineNumbers[line3] == 0 && line3 > 0)
1311:                    resultLineNumbers[line3] = resultLineNumbers[line3 - 1] + 1;
1312:                int resultLine = resultLineNumbers[line3];
1313:                //System.out.println("resultLine = rln["+line3+"] = "+resultLine);
1314:                //System.out.println("insertNumbers("+line3+", "+resultLine+", "+numLines+")");
1315:                linesComp3.insertNumbers(line3 - 1, resultLine, numLines);
1316:                linesComp3.changedAll();
1317:                for (int i = 0; i < numLines; i++)
1318:                    resultLineNumbers[line3 + i] = resultLine + i;
1319:            }
1320:
1321:            /**
1322:             * Replace a part of result with a part of the first source.
1323:             * @param line1 The starting line in the first source
1324:             * @param line2 The ending line in the first source or <code>null</code>
1325:             *              when the part ends at the end of the document
1326:             * @param line3 The starting line in the result
1327:             * @param line4 The ending line in the result
1328:             */
1329:            public void replaceSource1InResult(int line1, int line2, int line3,
1330:                    int line4) {
1331:                //System.out.println("replaceSource1InResult("+line1+", "+line2+", "+line3+", "+line4+")");
1332:                Integer conflictLine = new Integer((line1 > 0) ? line1 : 1);
1333:                // If trying to resolve the conflict twice simply return .
1334:                if (resolvedLeftConflictsLineNumbers.contains(conflictLine))
1335:                    return;
1336:                StyledDocument doc1 = (StyledDocument) jEditorPane1
1337:                        .getDocument();
1338:                StyledDocument doc2 = (StyledDocument) jEditorPane3
1339:                        .getDocument();
1340:                try {
1341:                    replace(doc1, line1, line2, doc2, line3, line4);
1342:                } catch (BadLocationException e) {
1343:                    org.openide.ErrorManager.getDefault().notify(e);
1344:                }
1345:                if (resolvedRightConflictsLineNumbers.contains(conflictLine)) {
1346:                    resolvedRightConflictsLineNumbers.remove(conflictLine);
1347:                } else {
1348:                    // We've resolved the conflict.
1349:                    numUnresolvedConflicts--;
1350:                    updateStatusLine();
1351:                }
1352:                resolvedLeftConflictsLineNumbers.add(conflictLine);
1353:                updateAcceptButtons(line1);
1354:            }
1355:
1356:            /**
1357:             * Replace a part of result with a part of the second source.
1358:             * @param line1 The starting line in the second source
1359:             * @param line2 The ending line in the second source or <code>null</code>
1360:             *              when the part ends at the end of the document
1361:             * @param line3 The starting line in the result
1362:             * @param line4 The ending line in the result
1363:             */
1364:            public void replaceSource2InResult(int line1, int line2, int line3,
1365:                    int line4) {
1366:                //System.out.println("replaceSource2InResult("+line1+", "+line2+", "+line3+", "+line4+")");
1367:                Integer conflictLine = new Integer((line1 > 0) ? line1 : 1);
1368:                // If trying to resolve the conflict twice simply return .
1369:                if (resolvedRightConflictsLineNumbers.contains(conflictLine))
1370:                    return;
1371:                StyledDocument doc1 = (StyledDocument) jEditorPane2
1372:                        .getDocument();
1373:                StyledDocument doc2 = (StyledDocument) jEditorPane3
1374:                        .getDocument();
1375:                try {
1376:                    replace(doc1, line1, line2, doc2, line3, line4);
1377:                } catch (BadLocationException e) {
1378:                    org.openide.ErrorManager.getDefault().notify(e);
1379:                }
1380:                if (resolvedLeftConflictsLineNumbers.contains(conflictLine)) {
1381:                    resolvedLeftConflictsLineNumbers.remove(conflictLine);
1382:                } else {
1383:                    // We've resolved the conflict.
1384:                    numUnresolvedConflicts--;
1385:                    updateStatusLine();
1386:                }
1387:                resolvedRightConflictsLineNumbers.add(conflictLine);
1388:                updateAcceptButtons(line1);
1389:            }
1390:
1391:            private void replace(StyledDocument doc1, int line1, int line2,
1392:                    StyledDocument doc2, int line3, int line4)
1393:                    throws BadLocationException {
1394:                //dumpResultLineNumbers();
1395:                //System.out.println("replace("+line1+", "+line2+", "+line3+", "+line4+")");
1396:                int offset1 = (line1 > 0) ? org.openide.text.NbDocument
1397:                        .findLineOffset(doc1, line1 - 1) : 0;
1398:                int offset2 = (line2 >= 0) ? org.openide.text.NbDocument
1399:                        .findLineOffset(doc1, line2) : (doc1.getLength() - 1);
1400:                int offset3 = (line3 > 0) ? org.openide.text.NbDocument
1401:                        .findLineOffset(doc2, line3 - 1) : 0;
1402:                int offset4 = (line4 >= 0) ? org.openide.text.NbDocument
1403:                        .findLineOffset(doc2, line4) : (doc2.getLength() - 1);
1404:                //System.out.println("replace: offsets = "+offset1+", "+offset2+", "+offset3+", "+offset4);
1405:                int length = offset2 - offset1;
1406:                if (line2 < 0)
1407:                    length++;
1408:                String text = doc1.getText(offset1, length);
1409:                doc2.remove(offset3, offset4 - offset3);
1410:                doc2.insertString(offset3, text, null);
1411:                // Adjust the line numbers
1412:                assureResultLineNumbersLength(line4);
1413:                //int lineDiff;
1414:                int physicalLineDiff = line2 - line1 - (line4 - line3);
1415:                if (physicalLineDiff > 0) {
1416:                    System.arraycopy(resultLineNumbers, line4 + 1,
1417:                            resultLineNumbers, line4 + physicalLineDiff + 1,
1418:                            resultLineNumbers.length - line4 - physicalLineDiff
1419:                                    - 1);
1420:                    //System.out.println("arraycopy("+line4+", "+(line4 + physicalLineDiff)+")");
1421:                    //dumpResultLineNumbers();
1422:                }
1423:                int lineDiff = (resultLineNumbers[line3] <= resultLineNumbers[line3 - 1]) ? (line2
1424:                        - line1 + 1)
1425:                        : (line2 - line1 - (line4 - line3));
1426:                //if (resultLineNumbers[line3] <= resultLineNumbers[line3 - 1]) {
1427:                // There are no line numbers defined.
1428:                //lineDiff = line2 - line1 + 1;
1429:                int n = resultLineNumbers[line3 - 1];
1430:                for (int i = line3; i <= line4 + physicalLineDiff; i++) {
1431:                    resultLineNumbers[i] = ++n;
1432:                }
1433:                /*
1434:                for (int i = line4 + lineDiff + 1; i < resultLineNumbers.length; i++) {
1435:                    if (resultLineNumbers[i] != 0) resultLineNumbers[i] += lineDiff;
1436:                    else break;
1437:                }
1438:                 */
1439:                //lineDiff = line2 - line1 + 1;
1440:                //System.out.println("insertNumbers("+line3+", "+resultLineNumbers[line3]+", "+(line2 - line1 + 1)+")");
1441:                linesComp3.insertNumbers(line3 - 1, resultLineNumbers[line3],
1442:                        line2 - line1 + 1);
1443:                linesComp3.changedAll();
1444:                //dumpResultLineNumbers();
1445:                //} else {
1446:                //    lineDiff = line2 - line1 - (line4 - line3);
1447:                //}
1448:                if (physicalLineDiff < 0) {
1449:                    System.arraycopy(resultLineNumbers, line4 + 1,
1450:                            resultLineNumbers, line4 + physicalLineDiff + 1,
1451:                            resultLineNumbers.length - line4 - 1);
1452:                    //System.out.println("arraycopy("+line4+", "+(line4 + physicalLineDiff)+")");
1453:                    //dumpResultLineNumbers();
1454:                }
1455:                adjustLineNumbers(line4 + physicalLineDiff + 1, lineDiff);
1456:
1457:                // #65970 workaround, resultLineNumbers content must be primitive only raising
1458:                int line = -1;
1459:                for (int i = 0; i < resultLineNumbers.length; i++) {
1460:                    if (resultLineNumbers[i] < line) {
1461:                        resultLineNumbers[i] = line;
1462:                    }
1463:                    line = resultLineNumbers[i];
1464:                }
1465:            }
1466:
1467:            /*
1468:            private void dumpResultLineNumbers() {
1469:                System.out.print("resultLineNum[] = ");
1470:                boolean was = false;
1471:                for (int i = 0; i < resultLineNumbers.length; i++) {
1472:                    if (resultLineNumbers[i] == 0 && was) break;
1473:                    if (resultLineNumbers[i] != 0) was = true;
1474:                    System.out.print(resultLineNumbers[i]+", ");
1475:                }
1476:                System.out.println("");
1477:                try {
1478:                    Thread.currentThread().sleep(1000);
1479:                } catch (InterruptedException iex) {}
1480:            }
1481:             */
1482:
1483:            private void adjustLineNumbers(int startLine, int shift) {
1484:                //System.out.println("adjustLineNumbers("+startLine+", "+shift+")");
1485:                int end = resultLineNumbers.length;
1486:                while (end > 0 && resultLineNumbers[end - 1] == 0)
1487:                    end--;
1488:                int startSetLine = -1;
1489:                int endSetLine = -1;
1490:                //resultLineNumbers[startLine] += shift;
1491:                for (int i = startLine; i < end; i++) {
1492:                    resultLineNumbers[i] += shift;
1493:                    if (resultLineNumbers[i] <= resultLineNumbers[i - 1]) {
1494:                        if (startSetLine > 0) {
1495:                            //System.out.println("insertNumbers("+startSetLine+", "+resultLineNumbers[startSetLine]+", "+(i - startSetLine)+")");
1496:                            linesComp3.insertNumbers(startSetLine - 1,
1497:                                    resultLineNumbers[startSetLine], i
1498:                                            - startSetLine);
1499:                            linesComp3.changedAll();
1500:                            //dumpResultLineNumbers();
1501:                            startSetLine = -1;
1502:                        }
1503:                        if (endSetLine < 0) {
1504:                            endSetLine = i;
1505:                        }
1506:                    } else {
1507:                        if (endSetLine > 0) {
1508:                            //System.out.println("removeNumbers("+endSetLine+", "+(i - endSetLine)+")");
1509:                            linesComp3.removeNumbers(endSetLine - 1, i
1510:                                    - endSetLine);
1511:                            linesComp3.changedAll();
1512:                            //dumpResultLineNumbers();
1513:                            endSetLine = -1;
1514:                        }
1515:                        if (startSetLine < 0) {
1516:                            startSetLine = i;
1517:                        }
1518:                    }
1519:                }
1520:                if (startSetLine > 0) {
1521:                    //System.out.println("insertNumbers("+startSetLine+", "+resultLineNumbers[startSetLine]+", "+(end - startSetLine)+" (END))");
1522:                    linesComp3
1523:                            .insertNumbers(startSetLine - 1,
1524:                                    resultLineNumbers[startSetLine], end
1525:                                            - startSetLine);
1526:                    linesComp3.shrink(end - 1);
1527:                    linesComp3.changedAll();
1528:                    //dumpResultLineNumbers();
1529:                }
1530:                if (endSetLine > 0) {
1531:                    //System.out.println("removeNumbers("+endSetLine+", "+(end - endSetLine)+" (END))");
1532:                    linesComp3.removeNumbers(endSetLine - 1, end - endSetLine);
1533:                    linesComp3.shrink(end - 1);
1534:                    linesComp3.changedAll();
1535:                    //dumpResultLineNumbers();
1536:                }
1537:            }
1538:
1539:            public void setSource1Title(String title) {
1540:                fileLabel1.setText(title);
1541:            }
1542:
1543:            public void setSource2Title(String title) {
1544:                fileLabel2.setText(title);
1545:            }
1546:
1547:            public void setResultSourceTitle(String title) {
1548:                resultLabel.setText(title);
1549:            }
1550:
1551:            public void setStatusLabel(String status) {
1552:                statusLabel.setText(status);
1553:            }
1554:
1555:            public void setMimeType1(String mime) {
1556:                EditorKit kit = CloneableEditorSupport.getEditorKit(mime);
1557:                jEditorPane1.setEditorKit(kit);
1558:                //Document doc = jEditorPane1.getDocument();
1559:                //if (!(doc instanceof StyledDocument)) jEditorPane1.setDocument(new DefaultStyledDocument());
1560:            }
1561:
1562:            public void setMimeType2(String mime) {
1563:                EditorKit kit = CloneableEditorSupport.getEditorKit(mime);
1564:                jEditorPane2.setEditorKit(kit);
1565:                //Document doc = jEditorPane2.getDocument();
1566:                //if (!(doc instanceof StyledDocument)) jEditorPane2.setDocument(new DefaultStyledDocument());
1567:            }
1568:
1569:            public void setMimeType3(String mime) {
1570:                EditorKit kit = CloneableEditorSupport.getEditorKit(mime);
1571:                jEditorPane3.setEditorKit(kit);
1572:            }
1573:
1574:            /*
1575:            public void setDocument1(Document doc) {
1576:                if (doc != null) {
1577:                    jEditorPane1.setDocument(doc);
1578:                }
1579:            }
1580:             */
1581:
1582:            public void setResultDocument(Document doc) {
1583:                if (doc != null) {
1584:                    jEditorPane3.setDocument(doc);
1585:                    jEditorPane3.setEditable(false);
1586:                    linesComp3 = new LinesComponent(jEditorPane3);
1587:                    resultScrollPane.setRowHeaderView(linesComp3);
1588:                }
1589:            }
1590:
1591:            /*
1592:             * Whether all conflicts are resolved and the panel can be closed.
1593:             * @return <code>true</code> when the panel can be closed, <code>false</code> otherwise.
1594:             *
1595:            public boolean canClose() {
1596:                return true;
1597:            }
1598:             */
1599:
1600:            /**
1601:             * Write the result content into the given writer. Skip all unresolved conflicts.
1602:             * @param w The writer to write the result into.
1603:             * @throws IOException When the writing process fails.
1604:             */
1605:            public void writeResult(Writer w, boolean stripLastNewline)
1606:                    throws IOException {
1607:                //System.out.println("writeResult()");
1608:                /*
1609:                try {
1610:                    jEditorPane3.getEditorKit().write(w, jEditorPane3.getDocument(),
1611:                                                      0, jEditorPane3.getDocument().getLength());
1612:                } catch (BadLocationException blex) {
1613:                    throw new IOException(blex.getLocalizedMessage());
1614:                }
1615:                 */
1616:                int end = resultLineNumbers.length;
1617:                while (end > 0 && resultLineNumbers[end - 1] == 0)
1618:                    end--;
1619:                int startSetLine = -1;
1620:                StyledDocument doc = (StyledDocument) jEditorPane3
1621:                        .getDocument();
1622:                try {
1623:                    for (int i = 1; i < end; i++) {
1624:                        if (resultLineNumbers[i] <= resultLineNumbers[i - 1]) {
1625:                            if (startSetLine > 0) {
1626:                                //System.out.println("write("+startSetLine+", "+i+")");
1627:                                int offsetStart = org.openide.text.NbDocument
1628:                                        .findLineOffset(doc, startSetLine - 1);
1629:                                int offsetEnd = org.openide.text.NbDocument
1630:                                        .findLineOffset(doc, i - 1);
1631:                                //System.out.println("  Have text(<l="+(startSetLine-1)+",off="+offsetStart+";l="+(i-1)+",off="+offsetEnd+">), length = "+doc.getLength());
1632:                                try {
1633:                                    //System.out.println("'"+doc.getText(offsetStart, offsetEnd - offsetStart)+"'");
1634:                                    writeText(w, doc.getText(offsetStart,
1635:                                            offsetEnd - offsetStart));
1636:                                } catch (BadLocationException blex) {
1637:                                    throw new IOException(blex
1638:                                            .getLocalizedMessage());
1639:                                }
1640:                                //dumpResultLineNumbers();
1641:                                startSetLine = -1;
1642:                            }
1643:                        } else {
1644:                            if (startSetLine < 0) {
1645:                                startSetLine = i;
1646:                            }
1647:                        }
1648:                    }
1649:                    if (startSetLine > 0) {
1650:                        //System.out.println("write("+startSetLine+", "+end+" (END))");
1651:                        int offsetStart = org.openide.text.NbDocument
1652:                                .findLineOffset(doc, startSetLine - 1);
1653:                        int offsetEnd = doc.getLength();
1654:                        try {
1655:                            String text = doc.getText(offsetStart, offsetEnd
1656:                                    - offsetStart);
1657:                            if (stripLastNewline && text.endsWith("\n")) {
1658:                                text = text.substring(0, text.length() - 1);
1659:                            }
1660:                            writeText(w, text);
1661:                        } catch (BadLocationException blex) {
1662:                            throw new IOException(blex.getLocalizedMessage());
1663:                        }
1664:                        //dumpResultLineNumbers();
1665:                    }
1666:                } finally {
1667:                    w.close();
1668:                }
1669:            }
1670:
1671:            private void writeText(Writer w, String text) throws IOException {
1672:                text = text.replaceAll("\n", System
1673:                        .getProperty("line.separator"));
1674:                w.write(text);
1675:            }
1676:
1677:            private void setHighlight(final StyledDocument doc,
1678:                    final int line1, final int line2, final java.awt.Color color) {
1679:                if (!SwingUtilities.isEventDispatchThread()) {
1680:                    SwingUtilities.invokeLater(new Runnable() {
1681:                        public void run() {
1682:                            setHighlight(doc, line1, line2, color);
1683:                        }
1684:                    });
1685:                }
1686:                //System.out.println("setHighlight(): <"+line1+", "+line2+">, color = "+color); // NOI18N
1687:                //Style s = doc.addStyle("diff-style("+color+"):1500", null); // NOI18N
1688:                //      SimpleAttributeSet attrSet = new SimpleAttributeSet();
1689:                //      attrSet.addAttribute(StyleConstants.ColorConstants.Background, java.awt.Color.green);
1690:                //s.addAttribute(StyleConstants.ColorConstants.Background, color);
1691:                Style s = doc.getStyle("diff-style(" + color + "):1500");
1692:                //if (s == null) s = doc.getLogicalStyle(offset);
1693:                if (s == null) {
1694:                    //System.out.println("setHighlight(): logical style is NULL"); // NOI18N
1695:                    s = doc.addStyle("diff-style(" + color + "):1500", null); // NOI18N
1696:                    s.addAttribute(StyleConstants.ColorConstants.Background,
1697:                            color);
1698:                }
1699:                for (int line = line1 - 1; line < line2; line++) {
1700:                    if (line < 0)
1701:                        continue;
1702:                    int offset = org.openide.text.NbDocument.findLineOffset(
1703:                            doc, line);
1704:                    //System.out.println("setHighlight(): I got offset = "+offset); // NOI18N
1705:                    if (offset >= 0) {
1706:                        /*
1707:                        Style ls = doc.getLogicalStyle(offset);
1708:                        //if (ls != null) ls.addAttributes(s.copyAttributes());
1709:                        if (ls == null) {
1710:                            ls = s;//new javax.swing.text.StyleContext.NamedStyle("diff-style("+color+"):1500", null);
1711:                        } else {
1712:                            //ls.addAttributes(s.copyAttributes());
1713:                        }
1714:                        ls.removeAttribute(StyleConstants.ColorConstants.Background);
1715:                        ls.addAttribute(StyleConstants.ColorConstants.Background, color);
1716:                         */
1717:                        doc.setLogicalStyle(offset, s);
1718:                        //doc.setParagraphAttributes(offset, 1, s, false);
1719:                    }
1720:                }
1721:                //doc.setParagraphAttributes(offset, 100, s, true);
1722:            }
1723:
1724:            private void unhighlight(StyledDocument doc) {
1725:                int endOffset = doc.getEndPosition().getOffset();
1726:                int endLine = org.openide.text.NbDocument.findLineNumber(doc,
1727:                        endOffset);
1728:                Style s = doc.addStyle("diff-style(white):1500", null); // NOI18N
1729:                s.addAttribute(StyleConstants.ColorConstants.Background,
1730:                        java.awt.Color.white);
1731:                for (int line = 0; line <= endLine; line++) {
1732:                    int offset = org.openide.text.NbDocument.findLineOffset(
1733:                            doc, line);
1734:                    doc.setLogicalStyle(offset, s);
1735:                }
1736:            }
1737:
1738:            public void unhighlightAll() {
1739:                unhighlight((StyledDocument) jEditorPane1.getDocument());
1740:                unhighlight((StyledDocument) jEditorPane2.getDocument());
1741:            }
1742:
1743:            public void highlightRegion1(int line1, int line2,
1744:                    java.awt.Color color) {
1745:                StyledDocument doc = (StyledDocument) jEditorPane1
1746:                        .getDocument();
1747:                setHighlight(doc, line1, line2, color);
1748:            }
1749:
1750:            public void highlightRegion2(int line1, int line2,
1751:                    java.awt.Color color) {
1752:                StyledDocument doc = (StyledDocument) jEditorPane2
1753:                        .getDocument();
1754:                setHighlight(doc, line1, line2, color);
1755:            }
1756:
1757:            public void highlightRegion3(int line1, int line2,
1758:                    java.awt.Color color) {
1759:                StyledDocument doc = (StyledDocument) jEditorPane3
1760:                        .getDocument();
1761:                setHighlight(doc, line1, line2, color);
1762:            }
1763:
1764:            public void unhighlightRegion3(int line1, int line2) {
1765:                StyledDocument doc = (StyledDocument) jEditorPane3
1766:                        .getDocument();
1767:                setHighlight(doc, line1, line2, jEditorPane3.getBackground());
1768:            }
1769:
1770:            private void addEmptyLines(StyledDocument doc, int line,
1771:                    int numLines) {
1772:                int lastOffset = doc.getEndPosition().getOffset();
1773:                int totLines = org.openide.text.NbDocument.findLineNumber(doc,
1774:                        lastOffset);
1775:                //int totLines = doc.getDefaultRootElement().getElementIndex(lastOffset);
1776:                int offset = lastOffset;
1777:                if (line <= totLines) {
1778:                    offset = org.openide.text.NbDocument.findLineOffset(doc,
1779:                            line);
1780:                    //offset = doc.getDefaultRootElement().getElement(line).getStartOffset();
1781:                }
1782:                //int endOffset = doc.getEndPosition().getOffset();
1783:                //if (offset > endOffset) offset = endOffset;
1784:                String insStr = strCharacters('\n', numLines);
1785:                //System.out.println("addEmptyLines = '"+insStr+"'");
1786:                try {
1787:                    doc.insertString(offset, insStr, null);
1788:                } catch (BadLocationException e) {
1789:                    org.openide.ErrorManager.getDefault().notify(e);
1790:                }
1791:                //initScrollBars();
1792:            }
1793:
1794:            public void addEmptyLines1(int line, int numLines) {
1795:                StyledDocument doc = (StyledDocument) jEditorPane1
1796:                        .getDocument();
1797:                //System.out.println("addEmptyLines1: line = "+line+", numLines = "+numLines); // NOI18N
1798:                addEmptyLines(doc, line, numLines);
1799:                linesComp1.addEmptyLines(line, numLines);
1800:            }
1801:
1802:            public void addEmptyLines2(int line, int numLines) {
1803:                StyledDocument doc = (StyledDocument) jEditorPane2
1804:                        .getDocument();
1805:                //System.out.println("addEmptyLines2: line = "+line+", numLines = "+numLines); // NOI18N
1806:                addEmptyLines(doc, line, numLines);
1807:                linesComp2.addEmptyLines(line, numLines);
1808:            }
1809:
1810:            public void addEmptyLines3(int line, int numLines) {
1811:                StyledDocument doc = (StyledDocument) jEditorPane3
1812:                        .getDocument();
1813:                //System.out.println("addEmptyLines3: line = "+line+", numLines = "+numLines); // NOI18N
1814:                addEmptyLines(doc, line - 1, numLines);
1815:                linesComp3.addEmptyLines(line - 1, numLines);
1816:                assureResultLineNumbersLength(line + numLines);
1817:                if (resultLineNumbers[line] == 0 && line > 0)
1818:                    resultLineNumbers[line] = resultLineNumbers[line - 1];
1819:                int resultLine = resultLineNumbers[line];
1820:                for (int i = 1; i < numLines; i++)
1821:                    resultLineNumbers[line + i] = resultLine;
1822:            }
1823:
1824:            private javax.swing.JViewport jViewport1;
1825:            private javax.swing.JViewport jViewport2;
1826:
1827:            // Variables declaration - do not modify//GEN-BEGIN:variables
1828:            final javax.swing.JButton acceptAndNextLeftButton = new javax.swing.JButton();
1829:            final javax.swing.JButton acceptAndNextRightButton = new javax.swing.JButton();
1830:            final javax.swing.JButton acceptLeftButton = new javax.swing.JButton();
1831:            final javax.swing.JButton acceptRightButton = new javax.swing.JButton();
1832:            final javax.swing.JPanel commandPanel = new javax.swing.JPanel();
1833:            final javax.swing.JSplitPane diffSplitPane = new javax.swing.JSplitPane();
1834:            final javax.swing.JPanel editorPanel = new javax.swing.JPanel();
1835:            final javax.swing.JLabel fileLabel1 = new javax.swing.JLabel();
1836:            final javax.swing.JLabel fileLabel2 = new javax.swing.JLabel();
1837:            final javax.swing.JPanel filePanel1 = new javax.swing.JPanel();
1838:            final javax.swing.JPanel filePanel2 = new javax.swing.JPanel();
1839:            final javax.swing.JButton firstConflictButton = new javax.swing.JButton();
1840:            final javax.swing.JEditorPane jEditorPane1 = new DEditorPane();
1841:            final javax.swing.JEditorPane jEditorPane2 = new DEditorPane();
1842:            final javax.swing.JEditorPane jEditorPane3 = new DEditorPane();
1843:            final javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
1844:            final javax.swing.JScrollPane jScrollPane2 = new javax.swing.JScrollPane();
1845:            final javax.swing.JButton lastConflictButton = new javax.swing.JButton();
1846:            final javax.swing.JPanel leftCommandPanel = new javax.swing.JPanel();
1847:            final javax.swing.JSplitPane mergeSplitPane = new javax.swing.JSplitPane();
1848:            final javax.swing.JButton nextConflictButton = new javax.swing.JButton();
1849:            final javax.swing.JButton prevConflictButton = new javax.swing.JButton();
1850:            final javax.swing.JLabel resultLabel = new javax.swing.JLabel();
1851:            final javax.swing.JPanel resultPanel = new javax.swing.JPanel();
1852:            final javax.swing.JScrollPane resultScrollPane = new javax.swing.JScrollPane();
1853:            final javax.swing.JPanel rightCommandPanel = new javax.swing.JPanel();
1854:            final javax.swing.JLabel statusLabel = new javax.swing.JLabel();
1855:            // End of variables declaration//GEN-END:variables
1856:
1857:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.