KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > layoutdesign > support > SwingLayoutUtils


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.form.layoutdesign.support;
21
22 import java.util.*;
23 import org.netbeans.modules.form.layoutdesign.LayoutComponent;
24
25 /**
26  * Utilities for swing layout support.
27  *
28  * @author Jan Stola
29  */

30 public class SwingLayoutUtils {
31     /** The default resizability of the component is not known. */
32     public static final int STATUS_UNKNOWN = -1;
33     /** The component is not resizable by default. */
34     public static final int STATUS_NON_RESIZABLE = 0;
35     /** The component is resizable by default. */
36     public static final int STATUS_RESIZABLE = 1;
37     
38     /**
39      * Contains class names of non-resizable components e.g.
40      * components that are non-resizable unless one (or more) of
41      * minimumSize, preferredSize or maximumSize properties is changed.
42      */

43     private static Set nonResizableComponents = new HashSet();
44     static {
45         nonResizableComponents.addAll(
46             Arrays.asList(new String JavaDoc[] {
47                 "javax.swing.JLabel", // NOI18N
48
"javax.swing.JButton", // NOI18N
49
"javax.swing.JToggleButton", // NOI18N
50
"javax.swing.JCheckBox", // NOI18N
51
"javax.swing.JRadioButton", // NOI18N
52
"javax.swing.JList", // NOI18N
53
})
54         );
55     }
56
57     /**
58      * Contains class names of resizable components e.g.
59      * components that are resizable unless one (or more) of
60      * minimumSize, preferredSize or maximumSize properties is changed.
61      */

62     private static Set resizableComponents = new HashSet();
63     static {
64         resizableComponents.addAll(
65             Arrays.asList(new String JavaDoc[] {
66                 "javax.swing.JComboBox", // NOI18N
67
"javax.swing.JTextField", // NOI18N
68
"javax.swing.JTextArea", // NOI18N
69
"javax.swing.JTabbedPane", // NOI18N
70
"javax.swing.JScrollPane", // NOI18N
71
"javax.swing.JSplitPane", // NOI18N
72
"javax.swing.JFormattedTextField", // NOI18N
73
"javax.swing.JPasswordField", // NOI18N
74
"javax.swing.JSpinner", // NOI18N
75
"javax.swing.JSeparator", // NOI18N
76
"javax.swing.JTextPane", // NOI18N
77
"javax.swing.JEditorPane", // NOI18N
78
"javax.swing.JInternalFrame", // NOI18N
79
"javax.swing.JLayeredPane", // NOI18N
80
"javax.swing.JDesktopPane" // NOI18N
81
})
82         );
83     }
84
85     /**
86      * Determines whether the given class represents component
87      * that is resizable (by default) or not.
88      *
89      * @param componentClass <code>Class</code> object corresponding
90      * to component we are interested in.
91      * @return <code>STATUS_RESIZABLE</code>, <code>STATUS_NON_RESIZABLE</code>
92      * or <code>STATUS_UNKNOWN</code>.
93      */

94     public static int getResizableStatus(Class JavaDoc componentClass) {
95         String JavaDoc className = componentClass.getName();
96         if (resizableComponents.contains(className)) return STATUS_RESIZABLE;
97         if (nonResizableComponents.contains(className)) return STATUS_NON_RESIZABLE;
98         return STATUS_UNKNOWN;
99     }
100
101     public static Map createLinkSizeGroups(LayoutComponent layoutComponent, int dimension) {
102         
103         Map linkSizeGroup = new HashMap();
104         
105         if (layoutComponent.isLayoutContainer()) {
106             Iterator i = layoutComponent.getSubcomponents();
107             
108             while (i.hasNext()) {
109                 LayoutComponent lc = (LayoutComponent)i.next();
110                 if (lc != null) {
111                     if (lc.isLinkSized(dimension)) {
112                         String JavaDoc cid = lc.getId();
113                         Integer JavaDoc id = new Integer JavaDoc(lc.getLinkSizeId(dimension));
114                         List l = (List)linkSizeGroup.get(id);
115                         if (l == null) {
116                             l = new ArrayList();
117                             l.add(cid);
118                             linkSizeGroup.put(id, l);
119                         } else {
120                             l.add(cid);
121                         }
122                     }
123                 }
124             }
125         }
126         return linkSizeGroup;
127     }
128     
129 }
130
Popular Tags