KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > layoutdesign > FakeLayoutMapper


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;
21
22 import java.awt.Dimension JavaDoc;
23 import java.awt.Rectangle JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import org.netbeans.modules.form.FormModel;
26
27 /**
28  * VisualMapper implementation for layout tests. Works based on explicitly set
29  * bounds and baseline positions.
30  */

31
32 public class FakeLayoutMapper implements VisualMapper, LayoutConstants {
33
34     private FormModel fm = null;
35     private HashMap JavaDoc contInterior = null;
36     private HashMap JavaDoc baselinePosition = null;
37     private HashMap JavaDoc prefPaddingInParent = null;
38     private HashMap JavaDoc prefPadding = null;
39     private HashMap JavaDoc compBounds = null;
40     private HashMap JavaDoc compMinSize = null;
41     private HashMap JavaDoc compPrefSize = null;
42     private HashMap JavaDoc hasExplicitPrefSize = null;
43     
44     public FakeLayoutMapper(FormModel fm,
45                             HashMap JavaDoc contInterior,
46                             HashMap JavaDoc baselinePosition,
47                             HashMap JavaDoc prefPaddingInParent,
48                             HashMap JavaDoc compBounds,
49                             HashMap JavaDoc compMinSize,
50                             HashMap JavaDoc compPrefSize,
51                             HashMap JavaDoc hasExplicitPrefSize,
52                             HashMap JavaDoc prefPadding) {
53         this.fm = fm;
54         this.contInterior = contInterior;
55         this.baselinePosition = baselinePosition;
56         this.prefPaddingInParent = prefPaddingInParent;
57         this.compBounds = compBounds;
58         this.compMinSize = compMinSize;
59         this.compPrefSize = compPrefSize;
60         this.hasExplicitPrefSize = hasExplicitPrefSize;
61         this.prefPadding = prefPadding;
62     }
63     
64     // -------
65

66     public Rectangle JavaDoc getComponentBounds(String JavaDoc componentId) {
67         return (Rectangle JavaDoc) compBounds.get(componentId);
68     }
69
70     public Rectangle JavaDoc getContainerInterior(String JavaDoc componentId) {
71         return (Rectangle JavaDoc) contInterior.get(componentId);
72     }
73
74     public Dimension JavaDoc getComponentMinimumSize(String JavaDoc componentId) {
75         return (Dimension JavaDoc) compMinSize.get(componentId);
76     }
77
78     public Dimension JavaDoc getComponentPreferredSize(String JavaDoc componentId) {
79         return (Dimension JavaDoc) compPrefSize.get(componentId);
80     }
81
82     public boolean hasExplicitPreferredSize(String JavaDoc componentId) {
83         return ((Boolean JavaDoc) hasExplicitPrefSize.get(componentId)).booleanValue();
84     }
85
86     public int getBaselinePosition(String JavaDoc componentId, int width, int height) {
87         String JavaDoc id = componentId + "-" + width + "-" + height; //NOI18N
88
return ((Integer JavaDoc) baselinePosition.get(id)).intValue();
89     }
90
91     public int getPreferredPadding(String JavaDoc comp1Id,
92                                    String JavaDoc comp2Id,
93                                    int dimension,
94                                    int comp2Alignment,
95                                    int paddingType)
96     {
97         String JavaDoc id = comp1Id + "-" + comp2Id + "-" + dimension + "-" + comp2Alignment + "-" + paddingType; //NOI18N
98
Integer JavaDoc pad = (Integer JavaDoc) prefPadding.get(id);
99         return pad != null ? pad.intValue() : 6;
100     }
101
102     public int getPreferredPaddingInParent(String JavaDoc parentId,
103                                            String JavaDoc compId,
104                                            int dimension,
105                                            int compAlignment)
106     {
107         String JavaDoc id = parentId + "-" + compId + "-" + dimension + "-" + compAlignment; //NOI18N
108
Integer JavaDoc pad = (Integer JavaDoc) prefPaddingInParent.get(id);
109         return pad != null ? pad.intValue() : 10;
110     }
111
112     public boolean[] getComponentResizability(String JavaDoc compId, boolean[] resizability) {
113         resizability[0] = resizability[1] = true;
114         return resizability;
115     }
116
117     public void rebuildLayout(String JavaDoc contId) {
118     }
119     
120 }
121
Popular Tags