This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 121525
Collapse All | Expand All

(-)graph/lib/src/org/netbeans/api/visual/widget/Widget.java (+33 lines)
Lines 335-340 Link Here
335
    }
335
    }
336
336
337
    /**
337
    /**
338
     * Reorders children within the child Widget array. Assists with z-order
339
     * operations on child Widgets.
340
     *
341
     * Child Widgets of parent are reordered in Array per the provided List of 
342
     * Integer
343
     *  
344
     * @param permutation List<Integer> consisting of new order. Each array slot
345
     * contains Integer value pointing to the old Objects index
346
     */
347
    public final void orderChildren(List<Integer> permutation) {
348
      
349
        assert permutation != null;
350
351
        if (parentWidget == null)
352
            return;
353
        List<Widget> widgets = parentWidget.children;
354
        
355
        assert permutation.size() == widgets.size();
356
        
357
        List<Widget> newOrder = new ArrayList<Widget>();
358
        for ( int j = 0 ; j < widgets.size(); j++) {
359
          Integer oldIndex = permutation.get(j);
360
          newOrder.add(widgets.get(oldIndex.intValue()));
361
        }
362
        
363
        widgets.clear();
364
        widgets.addAll(newOrder);
365
        
366
        revalidate ();
367
        parentWidget.revalidate ();
368
    }
369
    
370
    /**
338
     * Brings the widget to the front. Means: the widget becomes the last child in the list of children of the parent widget.
371
     * Brings the widget to the front. Means: the widget becomes the last child in the list of children of the parent widget.
339
     */
372
     */
340
    public final void bringToFront () {
373
    public final void bringToFront () {
(-)graph/lib/src/org/netbeans/api/visual/widget/WidgetSupport.java (+101 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.api.visual.widget;
42
43
import java.util.ArrayList;
44
import java.util.List;
45
46
/**
47
 * Added support methods for a given Widget
48
 * 
49
 * @author cpalmer
50
 */
51
public final class WidgetSupport {
52
53
    private WidgetSupport() {
54
      
55
    }
56
    /**
57
     * Brings the widget 1 slot backward in the parent Widget child array. 
58
     * Means: the widget is moving towards the first child in the list of children 
59
     * of the parent widget.
60
     * @param parentWidget Widget that contains Widget childWidget
61
     * @param childWidget Widget that is sent backwards in the list of children
62
     */
63
    public static final void bringBackward (Widget parentWidget,Widget childWidget) {
64
        if (parentWidget == null)
65
            return;
66
        List<Widget> children = parentWidget.getChildren();
67
        int i = children.indexOf (childWidget);
68
69
        if (i <= 0)
70
            return;
71
        
72
       List<Integer> permutation = new ArrayList<Integer>();
73
       for ( int j = 0; j < children.size() ; j++ ) {
74
         permutation.add(Integer.valueOf(j));
75
       }
76
       permutation.add(i-1,permutation.remove(i));
77
       childWidget.orderChildren(permutation);
78
    }
79
    /**
80
     * Brings the widget 1 slot forward in the parent Widget child array. 
81
     * Means: the widget is moving towards the last child in the list of children 
82
     * of the parent widget.
83
     * @param parentWidget Widget that contains Widget childWidget
84
     * @param childWidget Widget that is brought forward in the list of children
85
     */
86
    public static final void bringForward (Widget parentWidget,Widget childWidget) {
87
        List<Widget> children = parentWidget.getChildren();
88
        int i = children.indexOf (childWidget);
89
        if (i < 0 || i == (children.size()-1) )
90
            return;
91
92
        List<Integer> permutation = new ArrayList<Integer>();
93
        for ( int j = 0; j < children.size() ; j++ ) {
94
          permutation.add(Integer.valueOf(j));
95
        }
96
        permutation.add(i+1,permutation.remove(i));
97
        childWidget.orderChildren(permutation);
98
    }
99
    
100
  
101
}

Return to bug 121525