001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.gui;
017:
018: import java.awt.GridBagConstraints;
019: import java.awt.Insets;
020:
021: /**
022: * GBCF Grib Bag Constraints Factory. This class exists mostly
023: * for tidying up code that used the exsivly verbose GridBagConstraints
024: * object, hence the shortened class name.
025: * By default a two column equal with table is assumed, to support other
026: * column layouts use the constructor that take an array of column wieghts
027: * Factory class for generating constraints for a equal width column table.
028: * the table is similar to the following table rendered in HTML
029: * <table border="2">
030: * <tr>
031: * <td>data</td><td>data</td>
032: * </tr>
033: * <tr>
034: * <td colspan="2">data</td>
035: * </tr>
036: * <tr>
037: * <td>data</td><td>data</td>
038: * </tr>
039: * <tr>
040: * <td>data</td><td>data</td>
041: * </tr>
042: * <table>
043: * @author not attributable
044: * @version 1.0
045: */
046: public class GBCF {
047:
048: protected Insets insets = new Insets(1, 4, 1, 4);
049: protected Insets noinsets = new Insets(0, 0, 0, 0);
050: protected double[] columnWeights = new double[] { 0.5, 0.5 };
051:
052: public GBCF() {
053:
054: }
055:
056: /**
057: * to support more than two columns or vary the column wieghtings
058: * @param columnWeights double[]
059: */
060: public GBCF(double[] columnWeights) {
061: this .columnWeights = columnWeights;
062: }
063:
064: /**
065: *
066: * @param row int the 0 indexed row
067: * @param col int the 0 indexed column
068: * @param span boolean does cell span both columns
069: * @return GridBagConstraints
070: */
071: public GridBagConstraints getCell(int row, int col) {
072: return new GridBagConstraints(col, //gridx
073: row, //gridy
074: 1, //gridwidth
075: 1, //gridheight
076: columnWeights[col],//weightx
077: 0.0, //weithty
078: GridBagConstraints.WEST, // anchor
079: GridBagConstraints.NONE, //fill
080: insets, // insets
081: 1, //ipadx
082: 1 //ipady
083: );
084: }
085:
086: /**
087: *
088: * @param row int the 0 indexed row
089: * @param first boolean is this the first column or the second
090: * @param span boolean does cell span both columns
091: * @return GridBagConstraints
092: */
093: public GridBagConstraints getSpan(int row) {
094: return new GridBagConstraints(0, //gridx
095: row, //gridy
096: 2, //gridwidth
097: 1, //gridheight
098: columnWeights[0],//weightx
099: 0.0, //weithty
100: GridBagConstraints.WEST, // anchor
101: GridBagConstraints.NONE, //fill
102: insets, // insets
103: 1, //ipadx
104: 1 //ipady
105: );
106: }
107:
108: public GridBagConstraints getVertGlue(int row) {
109: return new GridBagConstraints(0, //gridx
110: row, //gridy
111: 2, //gridwidth
112: 1, //gridheight
113: columnWeights[0],//weightx
114: 1.0, //weithty
115: GridBagConstraints.NORTHWEST, // anchor
116: GridBagConstraints.NONE, //fill
117: noinsets, // insets
118: 0, //ipadx
119: 0 //ipady
120: );
121: }
122: }
|