KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > ALayoutCollection


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.util.*;
17 import java.awt.*;
18
19 import org.compiere.util.Log;
20
21 /**
22  * Collection of Components ordered based on ALayoutConstraint
23  *
24  * @author Jorg Janke
25  * @version $Id: ALayoutCollection.java,v 1.2 2002/06/15 02:43:57 jjanke Exp $
26  */

27 class ALayoutCollection extends HashMap
28 {
29     /**
30      * Create Collection
31      */

32     public ALayoutCollection()
33     {
34         super();
35     } // ALayoutCollection
36

37     /**
38      * Add a Component.
39      * If constraint is null, it is added to the last row as additional column
40      * @param constraint
41      * @param component
42      * @return component
43      * @throws IllegalArgumentException if component is not a Component
44      */

45     public Object JavaDoc put (Object JavaDoc constraint, Object JavaDoc component)
46     {
47         if (!(component instanceof Component))
48             throw new IllegalArgumentException JavaDoc ("ALayoutCollection can only add Component values");
49
50         if (constraint != null
51                 && !containsKey(constraint)
52                 && constraint instanceof ALayoutConstraint)
53         {
54         // Log.trace(this,Log.l6_Database, "ALayoutCollection.put", constraint.toString());
55
return super.put (constraint, component);
56         }
57
58         // We need to create constraint
59
if (super.size() == 0)
60         {
61         // Log.trace(this,Log.l6_Database, "ALayoutCollection.put - first");
62
return super.put(new ALayoutConstraint(0,0), component);
63         }
64
65         // Add to end of list
66
int row = getMaxRow();
67         if (row == -1)
68             row = 0;
69         int col = getMaxCol(row) + 1;
70         ALayoutConstraint next = new ALayoutConstraint(row, col);
71     // Log.trace(this,Log.l6_Database, "ALayoutCollection.put - addEnd", next.toString());
72
return super.put(next, component);
73     } // put
74

75     /**
76      * Get Maximum Row Number
77      * @return max row no - or -1 if no row
78      */

79     public int getMaxRow ()
80     {
81         int maxRow = -1;
82         //
83
Iterator i = keySet().iterator();
84         while (i.hasNext())
85         {
86             ALayoutConstraint c = (ALayoutConstraint)i.next();
87             maxRow = Math.max(maxRow, c.getRow());
88         }
89         return maxRow;
90     } // getMaxRow
91

92     /**
93      * Get Maximum Column Number
94      * @return max col no - or -1 if no column
95      */

96     public int getMaxCol ()
97     {
98         int maxCol = -1;
99         //
100
Iterator i = keySet().iterator();
101         while (i.hasNext())
102         {
103             ALayoutConstraint c = (ALayoutConstraint)i.next();
104             maxCol = Math.max(maxCol, c.getCol());
105         }
106         return maxCol;
107     } // getMaxCol
108

109     /**
110      * Get Maximum Column Number for Row
111      * @param row
112      * @return max col no for row - or -1 if no col in row
113      */

114     public int getMaxCol (int row)
115     {
116         int maxCol = -1;
117         //
118
Iterator i = keySet().iterator();
119         while (i.hasNext())
120         {
121             ALayoutConstraint c = (ALayoutConstraint)i.next();
122             if (c.getRow() == row)
123                 maxCol = Math.max(maxCol, c.getCol());
124         }
125         return maxCol;
126     } // getMaxCol
127

128 } // ALayoutCollection
129
Popular Tags