KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > ToolLayout


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sshtools.ui.awt;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.LayoutManager JavaDoc;
26
27
28 class ToolLayout
29       implements LayoutManager JavaDoc {
30     private Separator separator;
31
32     ToolLayout(Separator separator) {
33       this.separator = separator;
34     }
35
36     public void removeLayoutComponent(Component JavaDoc comp) {
37     }
38
39     public void layoutContainer(Container JavaDoc parent) {
40       int c = parent.getComponentCount();
41       Dimension JavaDoc s = new Dimension JavaDoc();
42       Component JavaDoc comp;
43       int x = 0;
44       int w = 0;
45       for (int i = 0; i < c; i++) {
46         comp = parent.getComponent(i);
47         if (comp == separator) {
48           w = parent.getSize().width;
49           comp.setBounds(0,
50                          parent.getSize().height -
51                          separator.getPreferredSize().height, w,
52                          separator.getPreferredSize().height);
53         }
54         else {
55           w = comp.getPreferredSize().width;
56           comp.setBounds(x, 0, w,
57                          parent.getSize().height -
58                          separator.getPreferredSize().height);
59           x += w;
60         }
61       }
62     }
63
64     public void addLayoutComponent(String JavaDoc name, Component JavaDoc comp) {
65     }
66
67     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc parent) {
68       int c = parent.getComponentCount();
69       Dimension JavaDoc s = new Dimension JavaDoc();
70       Component JavaDoc comp;
71       for (int i = 0; i < c; i++) {
72         comp = parent.getComponent(i);
73         s.width += comp.getMinimumSize().width;
74         s.height = Math.max(s.height, comp.getMinimumSize().height);
75       }
76       s.height += separator.getMinimumSize().height;
77       return s;
78     }
79
80     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc parent) {
81       int c = parent.getComponentCount();
82       Dimension JavaDoc s = new Dimension JavaDoc();
83       Component JavaDoc comp;
84       for (int i = 0; i < c; i++) {
85         comp = parent.getComponent(i);
86         s.width += comp.getPreferredSize().width;
87         s.height = Math.max(s.height, comp.getPreferredSize().height);
88       }
89       s.height += separator.getPreferredSize().height;
90       return s;
91     }
92
93   }
Popular Tags