KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > diff > VerticalFlowLayout


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.ui.diff;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.LayoutManager JavaDoc;
27
28 /**
29  * Layes components in vertical axis one by one,
30  * bottom by top.
31  *
32  * <p>Uses components preferred height
33  * but forces them fixed width.
34  *
35  * @author Petr Kuzel
36  */

37 public class VerticalFlowLayout implements LayoutManager JavaDoc {
38
39     private final Component JavaDoc parent;
40
41     /**
42      * Creates a new instance of VerticalFlowLayout
43      * @param parent <tt>parent.getWidth()</tt> defines the fixed width
44      */

45     public VerticalFlowLayout(Component JavaDoc parent) {
46         this.parent = parent;
47     }
48     
49     public void addLayoutComponent(String JavaDoc name, Component JavaDoc comp) {
50     }
51     
52     public void removeLayoutComponent(Component JavaDoc comp) {
53     }
54     
55     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc target) {
56         synchronized (target.getTreeLock()) {
57             Dimension JavaDoc dim = new Dimension JavaDoc(0, 0);
58             int nmembers = target.getComponentCount();
59             
60             for (int i = 0 ; i < nmembers ; i++) {
61                 Component JavaDoc m = target.getComponent(i);
62                 if (m.isVisible()) {
63                     Dimension JavaDoc d = m.getPreferredSize();
64                     dim.width = Math.max(dim.width, d.width);
65                     dim.height += d.height;
66                 }
67             }
68             Insets JavaDoc insets = target.getInsets();
69             dim.width += insets.left + insets.right;
70             dim.height += insets.top + insets.bottom;
71             return dim;
72         }
73     }
74     
75     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc target) {
76         synchronized (target.getTreeLock()) {
77             Dimension JavaDoc dim = new Dimension JavaDoc(0, 0);
78             int nmembers = target.getComponentCount();
79             
80             for (int i = 0 ; i < nmembers ; i++) {
81                 Component JavaDoc m = target.getComponent(i);
82                 if (m.isVisible()) {
83                     Dimension JavaDoc d = m.getMinimumSize();
84                     dim.width = Math.max(dim.width, d.width);
85                     dim.height += d.height;
86                 }
87             }
88             Insets JavaDoc insets = target.getInsets();
89             dim.width += insets.left + insets.right;
90             dim.height += insets.top + insets.bottom;
91             return dim;
92         }
93     }
94     
95     public void layoutContainer(Container JavaDoc target) {
96         
97         synchronized (target.getTreeLock()) {
98             Insets JavaDoc insets = target.getInsets();
99             int maxwidth = parent.getWidth() - (insets.left + insets.right);
100             int nmembers = target.getComponentCount();
101             int x = insets.left, y = insets.top;
102             
103             for (int i = 0 ; i < nmembers ; i++) {
104                 Component JavaDoc m = target.getComponent(i);
105                 if (m.isVisible()) {
106                     Dimension JavaDoc d = m.getPreferredSize();
107                     m.setSize(maxwidth, d.height);
108                     m.setLocation(x, y);
109                     y += d.height;
110                 }
111             }
112         }
113     }
114     
115 }
116
Popular Tags