~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/javahelp/jhMaster/JavaHelp/src/new/javax/help/AppendMerge.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * @(#)AppendMerge.java 1.4 06/10/30
 
3
 * 
 
4
 * Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
 
5
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
6
 * 
 
7
 * This code is free software; you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License version 2 only, as
 
9
 * published by the Free Software Foundation.  Sun designates this
 
10
 * particular file as subject to the "Classpath" exception as provided
 
11
 * by Sun in the LICENSE file that accompanied this code.
 
12
 * 
 
13
 * This code is distributed in the hope that it will be useful, but WITHOUT
 
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
15
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
16
 * version 2 for more details (a copy is included in the LICENSE file that
 
17
 * accompanied this code).
 
18
 * 
 
19
 * You should have received a copy of the GNU General Public License version
 
20
 * 2 along with this work; if not, write to the Free Software Foundation,
 
21
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
22
 * 
 
23
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 
24
 * CA 95054 USA or visit www.sun.com if you need additional information or
 
25
 * have any questions.
 
26
 */
 
27
 
 
28
package javax.help;
 
29
 
 
30
import javax.swing.tree.*;
 
31
import java.util.*;
 
32
import java.text.*;
 
33
 
 
34
/**
 
35
 * Append merge type
 
36
 *
 
37
 * @author Richard Gregor
 
38
 * @version     1.4     10/30/06
 
39
 */
 
40
public class AppendMerge extends Merge{
 
41
 
 
42
    /**
 
43
     * Constructs AppendMerge
 
44
     *
 
45
     * @param master The master NavigatorView
 
46
     * @param slave The slave NavigatorView
 
47
     */ 
 
48
    public AppendMerge(NavigatorView master, NavigatorView slave){
 
49
        super(master,slave);
 
50
 
 
51
    }
 
52
    
 
53
    /**
 
54
     * Processes append merge
 
55
     *
 
56
     * @param node The master node
 
57
     * @return Merged master node
 
58
     */
 
59
    public TreeNode processMerge(TreeNode node){
 
60
       debug("start merge");
 
61
 
 
62
       mergeNodes(node, slaveTopNode);
 
63
       return node;
 
64
    }
 
65
 
 
66
 
 
67
    /**
 
68
     * Merge Nodes. Merge two nodes according to the Append merging rules 
 
69
     *
 
70
     * @param masterNode The master node to merge with 
 
71
     * @param slaveNode The node to merge into the master
 
72
     */
 
73
    public static void mergeNodes(TreeNode master, TreeNode slave) {
 
74
       DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode)master;
 
75
       DefaultMutableTreeNode slaveNode = (DefaultMutableTreeNode)slave;
 
76
       debug("mergeNodes master=" + MergeHelpUtilities.getNodeName(masterNode) + 
 
77
             " slave=" + MergeHelpUtilities.getNodeName(slaveNode));       
 
78
       while (slaveNode.getChildCount() > 0) {
 
79
           DefaultMutableTreeNode slaveNodeChild = 
 
80
               (DefaultMutableTreeNode)slaveNode.getFirstChild();
 
81
           masterNode.add(slaveNodeChild);
 
82
           MergeHelpUtilities.mergeNodeChildren("javax.help.AppendMerge", 
 
83
                                                slaveNodeChild);
 
84
       }
 
85
    }
 
86
    
 
87
    /**
 
88
     * Merge Node Children. Merge the children of a node according to the
 
89
     * Append merging.
 
90
     *
 
91
     * @param node The parent node from which the children are merged
 
92
     */
 
93
    public static void mergeNodeChildren(TreeNode node) {
 
94
        DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode)node;
 
95
        debug("mergeNodes master=" + MergeHelpUtilities.getNodeName(masterNode));
 
96
        
 
97
        // The rules are there are no rules. Nothing else needs to be done
 
98
        // except for merging through the children
 
99
        for (int i=0; i < masterNode.getChildCount(); i++) {
 
100
            DefaultMutableTreeNode child = 
 
101
                (DefaultMutableTreeNode)masterNode.getChildAt(i);
 
102
            if (!child.isLeaf()) {
 
103
                MergeHelpUtilities.mergeNodeChildren("javax.help.AppendMerge",
 
104
                                                     child);
 
105
            }
 
106
        }
 
107
    }
 
108
 
 
109
    private static boolean debug = false;
 
110
    private static void debug(String msg){
 
111
        if (debug) {
 
112
            System.out.println("AppendMerge :"+msg);
 
113
        }
 
114
    }
 
115
}
 
116